@@ -98,59 +98,39 @@ private function setRequestOptions()
98
98
99
99
/**
100
100
* Initiate a payment request to Paystack
101
- * @return Unicodeveloper\Paystack\Paystack
102
101
*/
103
102
public function makePaymentRequest ()
104
- {
105
- $ this ->setResponse ('/transaction/initialize ' );
106
-
107
- return $ this ;
108
- }
109
-
110
- /**
111
- * Make the client request and get the response
112
- * @param string $relativeUrl
113
- * @return Unicodeveloper\Paystack\Paystack
114
- */
115
- public function setResponse ($ relativeUrl )
116
103
{
117
104
$ data = [
118
105
"amount " => intval (request ()->amount ),
119
106
"reference " => request ()->reference ,
120
107
"email " => request ()->email
121
108
];
122
109
123
- $ this ->response = $ this ->client ->post ($ this ->baseUrl . $ relativeUrl , [
124
- 'body ' => json_encode ($ data )
125
- ]);
110
+ $ this ->setHttpResponse ('/transaction/initialize ' , 'POST ' , $ data );
126
111
127
112
return $ this ;
128
113
}
129
114
130
- private function setGetResponse ($ relativeUrl , $ body = [])
131
- {
132
- $ this ->response = $ this ->client ->get ($ this ->baseUrl . $ relativeUrl , $ body );
133
115
134
- return $ this ;
135
- }
116
+ private function setHttpResponse ($ relativeUrl , $ method , $ body = []){
136
117
137
- private function setPostResponse ($ relativeUrl , $ body = [])
138
- {
139
- $ this ->response = $ this ->client ->post ($ this ->baseUrl . $ relativeUrl , $ body );
118
+ if (is_null ($ method )){
140
119
141
- return $ this ;
142
- }
120
+ throw new isNullException ("Empty method not allowed " );
143
121
144
- private function setPutResponse ($ relativeUrl , $ body = [])
145
- {
146
- $ this ->response = $ this ->client ->put ($ this ->baseUrl . $ relativeUrl , $ body );
122
+ }else {
123
+
124
+ $ this ->response = $ this ->client ->{strtolower ($ method )}($ this ->baseUrl . $ relativeUrl , $ body );
125
+
126
+ return $ this ;
127
+
128
+ }
147
129
148
- return $ this ;
149
130
}
150
131
151
132
/**
152
133
* Get the authorization url from the callback response
153
- * @return Unicodeveloper\Paystack\Paystack
154
134
*/
155
135
public function getAuthorizationUrl ()
156
136
{
@@ -216,7 +196,6 @@ public function getPaymentData()
216
196
217
197
/**
218
198
* Fluent method to redirect to Paystack Payment Page
219
- * @return Illuminate\Support\Redirect
220
199
*/
221
200
public function redirectNow ()
222
201
{
@@ -249,7 +228,7 @@ public function getAllCustomers()
249
228
{
250
229
$ this ->setRequestOptions ();
251
230
252
- return $ this ->setGetResponse ("/customer " , [])->getData ();
231
+ return $ this ->setHttpResponse ("/customer " , ' GET ' , [])->getData ();
253
232
}
254
233
255
234
/**
@@ -260,7 +239,7 @@ public function getAllPlans()
260
239
{
261
240
$ this ->setRequestOptions ();
262
241
263
- return $ this ->setGetResponse ("/plan " , [])->getData ();
242
+ return $ this ->setHttpResponse ("/plan " , ' GET ' , [])->getData ();
264
243
}
265
244
266
245
/**
@@ -271,7 +250,7 @@ public function getAllTransactions()
271
250
{
272
251
$ this ->setRequestOptions ();
273
252
274
- return $ this ->setGetResponse ("/transaction " , [])->getData ();
253
+ return $ this ->setHttpResponse ("/transaction " , ' GET ' , [])->getData ();
275
254
}
276
255
277
256
/**
@@ -309,7 +288,7 @@ public function createPlan(){
309
288
310
289
$ this ->setRequestOptions ();
311
290
312
- $ this ->response = $ this -> setPostResponse ("/plan " , $ data );
291
+ $ this ->setHttpResponse ("/plan " , ' POST ' , $ data );
313
292
314
293
}
315
294
@@ -322,7 +301,7 @@ public function fetchPlan($plan_code){
322
301
323
302
$ this ->setRequestOptions ();
324
303
325
- return $ this ->setGetResponse ('/plan/ ' . $ plan_code , [])->getResponse ();
304
+ return $ this ->setHttpResponse ('/plan/ ' . $ plan_code, ' GET ' , [])->getResponse ();
326
305
327
306
}
328
307
@@ -345,7 +324,7 @@ public function updatePlan($plan_code){
345
324
346
325
$ this ->setRequestOptions ();
347
326
348
- return $ this ->setPutResponse ('/plan/ ' . $ plan_code , $ data )->getResponse ();
327
+ return $ this ->setHttpResponse ('/plan/ ' . $ plan_code, ' PUT ' , $ data )->getResponse ();
349
328
350
329
}
351
330
@@ -366,7 +345,7 @@ public function createCustomer(){
366
345
367
346
$ this ->setRequestOptions ();
368
347
369
- $ this ->setPostResponse ('/customer ' , $ data );
348
+ $ this ->setHttpResponse ('/customer ' , ' POST ' , $ data );
370
349
371
350
}
372
351
@@ -379,7 +358,7 @@ public function fetchCustomer($customer_id){
379
358
380
359
$ this ->setRequestOptions ();
381
360
382
- return $ this ->setGetResponse ('/customer/ ' . $ customer_id , [])->getResponse ();
361
+ return $ this ->setHttpResponse ('/customer/ ' . $ customer_id, ' GET ' , [])->getResponse ();
383
362
384
363
}
385
364
@@ -401,7 +380,7 @@ public function updateCustomer($customer_id){
401
380
402
381
$ this ->setRequestOptions ();
403
382
404
- return $ this ->setPutResponse ('/customer/ ' . $ customer_id , $ data )->getResponse ();
383
+ return $ this ->setHttpResponse ('/customer/ ' . $ customer_id, ' PUT ' , $ data )->getResponse ();
405
384
406
385
}
407
386
@@ -419,7 +398,7 @@ public function exportTransactions(){
419
398
420
399
$ this ->setRequestOptions ();
421
400
422
- return $ this ->setGetResponse ('/transaction/export ' , $ data )->getResponse ();
401
+ return $ this ->setHttpResponse ('/transaction/export ' , ' GET ' , $ data )->getResponse ();
423
402
424
403
}
425
404
@@ -437,7 +416,7 @@ public function createSubscription(){
437
416
438
417
$ this ->setRequestOptions ();
439
418
440
- $ this ->setPostResponse ('/subscription ' , $ data );
419
+ $ this ->setHttpResponse ('/subscription ' , ' POST ' , $ data );
441
420
}
442
421
443
422
/**
@@ -453,7 +432,7 @@ public function enableSubscription(){
453
432
454
433
$ this ->setRequestOptions ();
455
434
456
- return $ this ->setPostResponse ('/subscription/enable ' , $ data )->getResponse ();
435
+ return $ this ->setHttpResponse ('/subscription/enable ' , ' POST ' , $ data )->getResponse ();
457
436
458
437
}
459
438
@@ -470,7 +449,7 @@ public function disableSubscription(){
470
449
471
450
$ this ->setRequestOptions ();
472
451
473
- return $ this ->setPostResponse ('/subscription/disable ' , $ data )->getResponse ();
452
+ return $ this ->setHttpResponse ('/subscription/disable ' , ' POST ' , $ data )->getResponse ();
474
453
475
454
}
476
455
@@ -483,7 +462,7 @@ public function fetchSubscription($subscription_id){
483
462
484
463
$ this ->setRequestOptions ();
485
464
486
- return $ this ->setGetResponse ('/subscription/ ' .$ subscription_id , [])->getResponse ();
465
+ return $ this ->setHttpResponse ('/subscription/ ' .$ subscription_id, ' GET ' , [])->getResponse ();
487
466
488
467
}
489
468
@@ -501,7 +480,7 @@ public function createPage(){
501
480
502
481
$ this ->setRequestOptions ();
503
482
504
- $ this ->setPostResponse ('/page ' , $ data );
483
+ $ this ->setHttpResponse ('/page ' , ' POST ' , $ data );
505
484
506
485
}
507
486
@@ -513,7 +492,7 @@ public function getAllPages(){
513
492
514
493
$ this ->setRequestOptions ();
515
494
516
- return $ this ->setGetResponse ('/page ' , [])->getResponse ();
495
+ return $ this ->setHttpResponse ('/page ' , ' GET ' , [])->getResponse ();
517
496
518
497
}
519
498
@@ -526,7 +505,7 @@ public function fetchPage($page_id){
526
505
527
506
$ this ->setRequestOptions ();
528
507
529
- return $ this ->setGetResponse ('/page/ ' .$ page_id , [])->getResponse ();
508
+ return $ this ->setHttpResponse ('/page/ ' .$ page_id, ' GET ' , [])->getResponse ();
530
509
531
510
}
532
511
@@ -545,7 +524,7 @@ public function updatePage($page_id){
545
524
546
525
$ this ->setRequestOptions ();
547
526
548
- return $ this ->setGetResponse ('/page/ ' .$ page_id , $ data )->getResponse ();
527
+ return $ this ->setHttpResponse ('/page/ ' .$ page_id, ' PUT ' , $ data )->getResponse ();
549
528
550
529
}
551
530
0 commit comments