@@ -98,59 +98,39 @@ private function setRequestOptions()
9898
9999 /**
100100 * Initiate a payment request to Paystack
101- * @return Unicodeveloper\Paystack\Paystack
102101 */
103102 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 )
116103 {
117104 $ data = [
118105 "amount " => intval (request ()->amount ),
119106 "reference " => request ()->reference ,
120107 "email " => request ()->email
121108 ];
122109
123- $ this ->response = $ this ->client ->post ($ this ->baseUrl . $ relativeUrl , [
124- 'body ' => json_encode ($ data )
125- ]);
110+ $ this ->setHttpResponse ('/transaction/initialize ' , 'POST ' , $ data );
126111
127112 return $ this ;
128113 }
129114
130- private function setGetResponse ($ relativeUrl , $ body = [])
131- {
132- $ this ->response = $ this ->client ->get ($ this ->baseUrl . $ relativeUrl , $ body );
133115
134- return $ this ;
135- }
116+ private function setHttpResponse ($ relativeUrl , $ method , $ body = []){
136117
137- private function setPostResponse ($ relativeUrl , $ body = [])
138- {
139- $ this ->response = $ this ->client ->post ($ this ->baseUrl . $ relativeUrl , $ body );
118+ if (is_null ($ method )){
140119
141- return $ this ;
142- }
120+ throw new isNullException ("Empty method not allowed " );
143121
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+ }
147129
148- return $ this ;
149130 }
150131
151132 /**
152133 * Get the authorization url from the callback response
153- * @return Unicodeveloper\Paystack\Paystack
154134 */
155135 public function getAuthorizationUrl ()
156136 {
@@ -216,7 +196,6 @@ public function getPaymentData()
216196
217197 /**
218198 * Fluent method to redirect to Paystack Payment Page
219- * @return Illuminate\Support\Redirect
220199 */
221200 public function redirectNow ()
222201 {
@@ -249,7 +228,7 @@ public function getAllCustomers()
249228 {
250229 $ this ->setRequestOptions ();
251230
252- return $ this ->setGetResponse ("/customer " , [])->getData ();
231+ return $ this ->setHttpResponse ("/customer " , ' GET ' , [])->getData ();
253232 }
254233
255234 /**
@@ -260,7 +239,7 @@ public function getAllPlans()
260239 {
261240 $ this ->setRequestOptions ();
262241
263- return $ this ->setGetResponse ("/plan " , [])->getData ();
242+ return $ this ->setHttpResponse ("/plan " , ' GET ' , [])->getData ();
264243 }
265244
266245 /**
@@ -271,7 +250,7 @@ public function getAllTransactions()
271250 {
272251 $ this ->setRequestOptions ();
273252
274- return $ this ->setGetResponse ("/transaction " , [])->getData ();
253+ return $ this ->setHttpResponse ("/transaction " , ' GET ' , [])->getData ();
275254 }
276255
277256 /**
@@ -309,7 +288,7 @@ public function createPlan(){
309288
310289 $ this ->setRequestOptions ();
311290
312- $ this ->response = $ this -> setPostResponse ("/plan " , $ data );
291+ $ this ->setHttpResponse ("/plan " , ' POST ' , $ data );
313292
314293 }
315294
@@ -322,7 +301,7 @@ public function fetchPlan($plan_code){
322301
323302 $ this ->setRequestOptions ();
324303
325- return $ this ->setGetResponse ('/plan/ ' . $ plan_code , [])->getResponse ();
304+ return $ this ->setHttpResponse ('/plan/ ' . $ plan_code, ' GET ' , [])->getResponse ();
326305
327306 }
328307
@@ -345,7 +324,7 @@ public function updatePlan($plan_code){
345324
346325 $ this ->setRequestOptions ();
347326
348- return $ this ->setPutResponse ('/plan/ ' . $ plan_code , $ data )->getResponse ();
327+ return $ this ->setHttpResponse ('/plan/ ' . $ plan_code, ' PUT ' , $ data )->getResponse ();
349328
350329 }
351330
@@ -366,7 +345,7 @@ public function createCustomer(){
366345
367346 $ this ->setRequestOptions ();
368347
369- $ this ->setPostResponse ('/customer ' , $ data );
348+ $ this ->setHttpResponse ('/customer ' , ' POST ' , $ data );
370349
371350 }
372351
@@ -379,7 +358,7 @@ public function fetchCustomer($customer_id){
379358
380359 $ this ->setRequestOptions ();
381360
382- return $ this ->setGetResponse ('/customer/ ' . $ customer_id , [])->getResponse ();
361+ return $ this ->setHttpResponse ('/customer/ ' . $ customer_id, ' GET ' , [])->getResponse ();
383362
384363 }
385364
@@ -401,7 +380,7 @@ public function updateCustomer($customer_id){
401380
402381 $ this ->setRequestOptions ();
403382
404- return $ this ->setPutResponse ('/customer/ ' . $ customer_id , $ data )->getResponse ();
383+ return $ this ->setHttpResponse ('/customer/ ' . $ customer_id, ' PUT ' , $ data )->getResponse ();
405384
406385 }
407386
@@ -419,7 +398,7 @@ public function exportTransactions(){
419398
420399 $ this ->setRequestOptions ();
421400
422- return $ this ->setGetResponse ('/transaction/export ' , $ data )->getResponse ();
401+ return $ this ->setHttpResponse ('/transaction/export ' , ' GET ' , $ data )->getResponse ();
423402
424403 }
425404
@@ -437,7 +416,7 @@ public function createSubscription(){
437416
438417 $ this ->setRequestOptions ();
439418
440- $ this ->setPostResponse ('/subscription ' , $ data );
419+ $ this ->setHttpResponse ('/subscription ' , ' POST ' , $ data );
441420 }
442421
443422 /**
@@ -453,7 +432,7 @@ public function enableSubscription(){
453432
454433 $ this ->setRequestOptions ();
455434
456- return $ this ->setPostResponse ('/subscription/enable ' , $ data )->getResponse ();
435+ return $ this ->setHttpResponse ('/subscription/enable ' , ' POST ' , $ data )->getResponse ();
457436
458437 }
459438
@@ -470,7 +449,7 @@ public function disableSubscription(){
470449
471450 $ this ->setRequestOptions ();
472451
473- return $ this ->setPostResponse ('/subscription/disable ' , $ data )->getResponse ();
452+ return $ this ->setHttpResponse ('/subscription/disable ' , ' POST ' , $ data )->getResponse ();
474453
475454 }
476455
@@ -483,7 +462,7 @@ public function fetchSubscription($subscription_id){
483462
484463 $ this ->setRequestOptions ();
485464
486- return $ this ->setGetResponse ('/subscription/ ' .$ subscription_id , [])->getResponse ();
465+ return $ this ->setHttpResponse ('/subscription/ ' .$ subscription_id, ' GET ' , [])->getResponse ();
487466
488467 }
489468
@@ -501,7 +480,7 @@ public function createPage(){
501480
502481 $ this ->setRequestOptions ();
503482
504- $ this ->setPostResponse ('/page ' , $ data );
483+ $ this ->setHttpResponse ('/page ' , ' POST ' , $ data );
505484
506485 }
507486
@@ -513,7 +492,7 @@ public function getAllPages(){
513492
514493 $ this ->setRequestOptions ();
515494
516- return $ this ->setGetResponse ('/page ' , [])->getResponse ();
495+ return $ this ->setHttpResponse ('/page ' , ' GET ' , [])->getResponse ();
517496
518497 }
519498
@@ -526,7 +505,7 @@ public function fetchPage($page_id){
526505
527506 $ this ->setRequestOptions ();
528507
529- return $ this ->setGetResponse ('/page/ ' .$ page_id , [])->getResponse ();
508+ return $ this ->setHttpResponse ('/page/ ' .$ page_id, ' GET ' , [])->getResponse ();
530509
531510 }
532511
@@ -545,7 +524,7 @@ public function updatePage($page_id){
545524
546525 $ this ->setRequestOptions ();
547526
548- return $ this ->setGetResponse ('/page/ ' .$ page_id , $ data )->getResponse ();
527+ return $ this ->setHttpResponse ('/page/ ' .$ page_id, ' PUT ' , $ data )->getResponse ();
549528
550529 }
551530
0 commit comments