diff --git a/src/Paystack.php b/src/Paystack.php
index 2208a39..162e2a3 100644
--- a/src/Paystack.php
+++ b/src/Paystack.php
@@ -102,36 +102,40 @@ private function setRequestOptions()
/**
* Initiate a payment request to Paystack
+ * Included the option to pass the payload to this method for situations
+ * when the payload is built on the fly (not passed to the controller from a view)
* @return Paystack
*/
- public function makePaymentRequest()
- {
- $data = [
- "amount" => intval(request()->amount),
- "reference" => request()->reference,
- "email" => request()->email,
- "plan" => request()->plan,
- "first_name" => request()->first_name,
- "last_name" => request()->last_name,
- "callback_url" => request()->callback_url,
- /*
- * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
- * form need an input field:
- *array must be set up as: $array = [ 'custom_fields' => [
- * ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
- * ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
- * .
- * .
- * .
- * ]
- *
- * ]
- */
- 'metadata' => request()->metadata
- ];
-
- // Remove the fields which were not sent (value would be null)
- array_filter($data);
+ public function makePaymentRequest( $data = null)
+ {
+ if ( $data == null ) {
+ $data = [
+ "amount" => intval(request()->amount),
+ "reference" => request()->reference,
+ "email" => request()->email,
+ "plan" => request()->plan,
+ "first_name" => request()->first_name,
+ "last_name" => request()->last_name,
+ "callback_url" => request()->callback_url,
+ /*
+ * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
+ * form need an input field:
+ *array must be set up as: $array = [ 'custom_fields' => [
+ * ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
+ * ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
+ * .
+ * .
+ * .
+ * ]
+ *
+ * ]
+ */
+ 'metadata' => request()->metadata
+ ];
+
+ // Remove the fields which were not sent (value would be null)
+ array_filter($data);
+ }
$this->setHttpResponse('/transaction/initialize', 'POST', $data);
@@ -172,6 +176,21 @@ public function getAuthorizationUrl()
return $this;
}
+
+ /**
+ * Get the authorization callback response
+ * In situations where Laravel serves as an backend for a detached UI, the api cannot redirect
+ * and might need to take different actions based on the success or not of the transaction
+ * @return array
+ */
+ public function getAuthorizationResponse($data)
+ {
+ $this->makePaymentRequest($data);
+
+ $this->url = $this->getResponse()['data']['authorization_url'];
+
+ return $this->getResponse();
+ }
/**
* Hit Paystack Gateway to Verify that the transaction is valid