From bb9598736a40015d96656251fb9a26fdc9e4c0d6 Mon Sep 17 00:00:00 2001 From: Olusegun Ayeni Date: Fri, 18 Jun 2021 16:42:13 +0100 Subject: [PATCH 1/2] add split feature and allow package to support php 8 and laravel 8 --- README.md | 14 ++++++ composer.json | 108 ++++++++++++++++++++++++++--------------------- src/Paystack.php | 30 +++++++++++-- 3 files changed, 101 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index a6f1caf..bf99db7 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,13 @@ Route::post('/pay', [ 'as' => 'pay' ]); ``` +OR + +```php +// Laravel 8 +Route::post('/pay', [App\Http\Controllers\PaymentController::class, 'redirectToGateway'])->name('pay'); +``` + ```php Route::get('/payment/callback', 'PaymentController@handleGatewayCallback'); @@ -161,6 +168,13 @@ Route::get('payment/callback', [ ]); ``` +OR + +```php +// Laravel 8 +Route::get('/payment/callback', [App\Http\Controllers\PaymentController::class, 'handleGatewayCallback']); +``` + ```php request()->last_name, "callback_url" => request()->callback_url, "currency" => (request()->currency != "" ? request()->currency : "NGN"), - + /* Paystack allows for transactions to be split into a subaccount - The following lines trap the subaccount ID - as well as the ammount to charge the subaccount (if overriden in the form) @@ -132,11 +132,35 @@ public function makePaymentRequest( $data = null) */ "subaccount" => request()->subaccount, "transaction_charge" => request()->transaction_charge, - + + /** + * Paystack allows for transaction to be split into multi accounts(subaccounts) + * The following lines trap the split ID handling the split + * More details here: https://paystack.com/docs/payments/multi-split-payments/#using-transaction-splits-with-payments + */ + "split_code" => request()->split_code, + + /** + * Paystack allows transaction to be split into multi account(subaccounts) on the fly without predefined split + * form need an input field: + * array must be set up as: + * $split = [ + * "type" => "percentage", + * "currency" => "KES", + * "subaccounts" => [ + * { "subaccount" => "ACCT_li4p6kte2dolodo", "share" => 10 }, + * { "subaccount" => "ACCT_li4p6kte2dolodo", "share" => 30 }, + * ], + * "bearer_type" => "all", + * "main_account_share": 70, + * ] + * More details here: https://paystack.com/docs/payments/multi-split-payments/#dynamic-splits + */ + "split" => request()->split, /* * 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 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"], From e47e4247ae826a4d60cc715a272b961cb9437c0a Mon Sep 17 00:00:00 2001 From: Olusegun Ayeni Date: Fri, 18 Jun 2021 16:58:42 +0100 Subject: [PATCH 2/2] add documentation to readme --- README.md | 20 ++++++++++++++++++++ src/Paystack.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf99db7..c2b3b57 100644 --- a/README.md +++ b/README.md @@ -344,6 +344,23 @@ paystack()->updateSubAccount(); A sample form will look like so: +```php + "percentage", + "currency" => "KES", + "subaccounts" => [ + [ "subaccount" => "ACCT_li4p6kte2dolodo", "share" => 10 ], + [ "subaccount" => "ACCT_li4p6kte2dolodo", "share" => 30 ], + ], + "bearer_type" => "all", + "main_account_share" => 70 +]; +?> +``` + ```html
@@ -361,6 +378,9 @@ A sample form will look like so: {{-- For other necessary things you want to add to your payload. it is optional though --}} {{-- required --}} + + {{-- to support transaction split. more details https://paystack.com/docs/payments/multi-split-payments/#using-transaction-splits-with-payments --}} + {{-- to support dynamic transaction split. More details https://paystack.com/docs/payments/multi-split-payments/#dynamic-splits --}} {{ csrf_field() }} {{-- works only when using laravel 5.1, 5.2 --}} {{-- employ this in place of csrf_field only in laravel 5.0 --}} diff --git a/src/Paystack.php b/src/Paystack.php index db2404f..1a298a7 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -152,7 +152,7 @@ public function makePaymentRequest( $data = null) * { "subaccount" => "ACCT_li4p6kte2dolodo", "share" => 30 }, * ], * "bearer_type" => "all", - * "main_account_share": 70, + * "main_account_share" => 70, * ] * More details here: https://paystack.com/docs/payments/multi-split-payments/#dynamic-splits */