@@ -102,36 +102,40 @@ private function setRequestOptions()
102
102
103
103
/**
104
104
* Initiate a payment request to Paystack
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
-
133
- // Remove the fields which were not sent (value would be null)
134
- array_filter ($ data );
109
+ public function makePaymentRequest ( $ data = null )
110
+ {
111
+ if ( $ data == null ) {
112
+ $ data = [
113
+ "amount " => intval (request ()->amount ),
114
+ "reference " => request ()->reference ,
115
+ "email " => request ()->email ,
116
+ "plan " => request ()->plan ,
117
+ "first_name " => request ()->first_name ,
118
+ "last_name " => request ()->last_name ,
119
+ "callback_url " => request ()->callback_url ,
120
+ /*
121
+ * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
122
+ * form need an input field: <input type="hidden" name="metadata" value="{{ json_encode($array) }}" >
123
+ *array must be set up as: $array = [ 'custom_fields' => [
124
+ * ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
125
+ * ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
126
+ * .
127
+ * .
128
+ * .
129
+ * ]
130
+ *
131
+ * ]
132
+ */
133
+ 'metadata ' => request ()->metadata
134
+ ];
135
+
136
+ // Remove the fields which were not sent (value would be null)
137
+ array_filter ($ data );
138
+ }
135
139
136
140
$ this ->setHttpResponse ('/transaction/initialize ' , 'POST ' , $ data );
137
141
@@ -172,6 +176,21 @@ public function getAuthorizationUrl()
172
176
173
177
return $ this ;
174
178
}
179
+
180
+ /**
181
+ * Get the authorization callback response
182
+ * In situations where Laravel serves as an backend for a detached UI, the api cannot redirect
183
+ * and might need to take different actions based on the success or not of the transaction
184
+ * @return array
185
+ */
186
+ public function getAuthorizationResponse ($ data )
187
+ {
188
+ $ this ->makePaymentRequest ($ data );
189
+
190
+ $ this ->url = $ this ->getResponse ()['data ' ]['authorization_url ' ];
191
+
192
+ return $ this ->getResponse ();
193
+ }
175
194
176
195
/**
177
196
* Hit Paystack Gateway to Verify that the transaction is valid
0 commit comments