From eec5ecd960cdc96b961d4e33284df58fae1fa0fc Mon Sep 17 00:00:00 2001 From: Ibidapo Adeolu Date: Tue, 1 Feb 2022 12:53:31 +0100 Subject: [PATCH] Add option for controller I added an option for user to provide the data (request data) from controller instead of a form. This adds some levels of security to the data and also ability to provide default values. --- README.md | 22 ++++++++++++++++++++++ src/Paystack.php | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c2b3b57..38eac4b 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,28 @@ class PaymentController extends Controller } ``` +```php +/** + * In the case where you need to pass the data from your + * controller instead of a form + * Make sure to send: + * required: email, amount, reference, orderID(probably) + * optionally: currency, description, metadata + * e.g: + * + */ +$data = array( + "amount" => 700 * 100, + "reference" => '4g4g5485g8545jg8gj', + "email" => 'user@mail.com', + "currency" => "NGN", + "orderID" => 23456, + ); + +return Paystack::getAuthorizationUrl($data)->redirectNow(); + +``` + Let me explain the fluent methods this package provides a bit here. ```php /** diff --git a/src/Paystack.php b/src/Paystack.php index 1a298a7..c1a5ea7 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -109,7 +109,7 @@ private function setRequestOptions() * @return Paystack */ - public function makePaymentRequest( $data = null) + public function makePaymentRequest($data = null) { if ( $data == null ) { @@ -205,9 +205,9 @@ private function setHttpResponse($relativeUrl, $method, $body = []) * Get the authorization url from the callback response * @return Paystack */ - public function getAuthorizationUrl() + public function getAuthorizationUrl($data = null) { - $this->makePaymentRequest(); + $this->makePaymentRequest($data); $this->url = $this->getResponse()['data']['authorization_url'];