@@ -100,38 +100,43 @@ private function setRequestOptions()
100
100
);
101
101
}
102
102
103
- /**
104
- * Initiate a payment request to Paystack
103
+
104
+ /**
105
+ * Included the option to pass the payload to this method for situations
106
+ * when the payload is built on the fly (not passed to the controller from a view)
105
107
* @return Paystack
106
108
*/
107
- public function makePaymentRequest ()
108
- {
109
- $ data = [
110
- "amount " => intval (request ()->amount ),
111
- "reference " => request ()->reference ,
112
- "email " => request ()->email ,
113
- "plan " => request ()->plan ,
114
- "first_name " => request ()->first_name ,
115
- "last_name " => request ()->last_name ,
116
- "callback_url " => request ()->callback_url ,
117
- /*
118
- * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
119
- * form need an input field: <input type="hidden" name="metadata" value="{{ json_encode($array) }}" >
120
- *array must be set up as: $array = [ 'custom_fields' => [
121
- * ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
122
- * ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
123
- * .
124
- * .
125
- * .
126
- * ]
127
- *
128
- * ]
129
- */
130
- 'metadata ' => request ()->metadata
131
- ];
132
109
133
- // Remove the fields which were not sent (value would be null)
134
- array_filter ($ data );
110
+ public function makePaymentRequest ( $ data = null )
111
+ {
112
+ if ( $ data == null ) {
113
+ $ data = [
114
+ "amount " => intval (request ()->amount ),
115
+ "reference " => request ()->reference ,
116
+ "email " => request ()->email ,
117
+ "plan " => request ()->plan ,
118
+ "first_name " => request ()->first_name ,
119
+ "last_name " => request ()->last_name ,
120
+ "callback_url " => request ()->callback_url ,
121
+ /*
122
+ * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
123
+ * form need an input field: <input type="hidden" name="metadata" value="{{ json_encode($array) }}" >
124
+ *array must be set up as: $array = [ 'custom_fields' => [
125
+ * ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
126
+ * ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
127
+ * .
128
+ * .
129
+ * .
130
+ * ]
131
+ *
132
+ * ]
133
+ */
134
+ 'metadata ' => request ()->metadata
135
+ ];
136
+
137
+ // Remove the fields which were not sent (value would be null)
138
+ array_filter ($ data );
139
+ }
135
140
136
141
$ this ->setHttpResponse ('/transaction/initialize ' , 'POST ' , $ data );
137
142
@@ -172,6 +177,21 @@ public function getAuthorizationUrl()
172
177
173
178
return $ this ;
174
179
}
180
+
181
+ /**
182
+ * Get the authorization callback response
183
+ * In situations where Laravel serves as an backend for a detached UI, the api cannot redirect
184
+ * and might need to take different actions based on the success or not of the transaction
185
+ * @return array
186
+ */
187
+ public function getAuthorizationResponse ($ data )
188
+ {
189
+ $ this ->makePaymentRequest ($ data );
190
+
191
+ $ this ->url = $ this ->getResponse ()['data ' ]['authorization_url ' ];
192
+
193
+ return $ this ->getResponse ();
194
+ }
175
195
176
196
/**
177
197
* Hit Paystack Gateway to Verify that the transaction is valid
@@ -370,6 +390,7 @@ public function createCustomer()
370
390
371
391
$ this ->setRequestOptions ();
372
392
$ this ->setHttpResponse ('/customer ' , 'POST ' , $ data );
393
+ return $ this ->setHttpResponse ('/customer ' , 'POST ' , $ data )->getResponse ();
373
394
}
374
395
375
396
/**
@@ -434,6 +455,44 @@ public function createSubscription()
434
455
$ this ->setHttpResponse ('/subscription ' , 'POST ' , $ data );
435
456
}
436
457
458
+ /**
459
+ * Get all the subscriptions made on Paystack.
460
+ *
461
+ * @return array
462
+ */
463
+ public function getAllSubscriptions ()
464
+ {
465
+ $ this ->setRequestOptions ();
466
+
467
+ return $ this ->setHttpResponse ("/subscription " , 'GET ' , [])->getData ();
468
+ }
469
+
470
+ /**
471
+ * Get customer subscriptions
472
+ *
473
+ * @param integer $customer_id
474
+ * @return array
475
+ */
476
+ public function getCustomerSubscriptions ($ customer_id )
477
+ {
478
+ $ this ->setRequestOptions ();
479
+
480
+ return $ this ->setHttpResponse ('/subscription?customer= ' . $ customer_id , 'GET ' , [])->getData ();
481
+ }
482
+
483
+ /**
484
+ * Get plan subscriptions
485
+ *
486
+ * @param integer $plan_id
487
+ * @return array
488
+ */
489
+ public function getPlanSubscriptions ($ plan_id )
490
+ {
491
+ $ this ->setRequestOptions ();
492
+
493
+ return $ this ->setHttpResponse ('/subscription?plan= ' . $ plan_id , 'GET ' , [])->getData ();
494
+ }
495
+
437
496
/**
438
497
* Enable a subscription using the subscription code and token
439
498
* @return array
0 commit comments