From c53d02cb9c29fc6adc23bed3072e5b7bd0d8f5dc Mon Sep 17 00:00:00 2001 From: engrtitus Date: Fri, 12 Jan 2018 23:15:04 +0100 Subject: [PATCH 01/40] Update Paystack.php --- src/Paystack.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index d3b4a7c..ae4dfda 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -112,8 +112,9 @@ private function setRequestOptions() public function makePaymentRequest( $data = null) { if ( $data == null ) { - $data = [ - "amount" => intval(request()->amount), + $quantity = intval(request()->quantity); + $data = [ + "amount" => intval(request()->amount)*$quantity, "reference" => request()->reference, "email" => request()->email, "plan" => request()->plan, From 97447985cb720a10141be378cfd666baad7cda0b Mon Sep 17 00:00:00 2001 From: engrtitus Date: Fri, 12 Jan 2018 23:18:50 +0100 Subject: [PATCH 02/40] Update Paystack.php --- src/Paystack.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index ae4dfda..0ccb360 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -112,8 +112,8 @@ private function setRequestOptions() public function makePaymentRequest( $data = null) { if ( $data == null ) { - $quantity = intval(request()->quantity); - $data = [ + $quantity = intval(request()->quantity); + $data = [ "amount" => intval(request()->amount)*$quantity, "reference" => request()->reference, "email" => request()->email, From e06ab69c3413882eda6786ce318cdccac16c56a2 Mon Sep 17 00:00:00 2001 From: Comical DERSKEAL <27731088+derskeal@users.noreply.github.com> Date: Mon, 23 Apr 2018 17:06:16 +0100 Subject: [PATCH 03/40] Removed line that fetches secret key The payment still works without the line. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index cbc84f1..cf9ceb0 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,6 @@ A sample form will look like so: {{-- For other necessary things you want to add to your payload. it is optional though --}} {{-- required --}} - {{-- required --}} {{ csrf_field() }} {{-- works only when using laravel 5.1, 5.2 --}} {{-- employ this in place of csrf_field only in laravel 5.0 --}} From 7673b7135380b1d0214fccfff580c25cfe973363 Mon Sep 17 00:00:00 2001 From: "Aremu Oluwagbamila (SMOG)" Date: Sat, 21 Mar 2020 11:44:17 +0100 Subject: [PATCH 04/40] Added information to enable usage on live server --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 134ef7a..fc89f7b 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ PAYSTACK_SECRET_KEY=xxxxxxxxxxxxx PAYSTACK_PAYMENT_URL=https://api.paystack.co MERCHANT_EMAIL=unicodeveloper@gmail.com ``` +*If you are using a hosting service like heroku, ensure to add the above details to your configuration variables.* Set up routes and controller methods like so: From 6e31015fa9d3dbf91f326ad6f92f61288e558fc6 Mon Sep 17 00:00:00 2001 From: Benson Samaasi Date: Sun, 5 Apr 2020 19:32:13 +0000 Subject: [PATCH 05/40] add laravel 7 support --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 67e2c32..4abfdb7 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "minimum-stability": "stable", "require": { "php": "^5.4.0|^7.0", - "illuminate/support": "5.*|6.*", + "illuminate/support": "5.*|6.*|^7.0", "guzzlehttp/guzzle": "5.*|6.*" }, "require-dev": { From 73a4e53a5cd045ef39d4314748ca6bb341766a0e Mon Sep 17 00:00:00 2001 From: Onyekam Date: Sat, 23 May 2020 10:51:06 +0100 Subject: [PATCH 06/40] Ability to split payment into a subaccount --- src/Paystack.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Paystack.php b/src/Paystack.php index 3ecdeba..b6527f0 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -120,6 +120,13 @@ public function makePaymentRequest( $data = null) "first_name" => request()->first_name, "last_name" => request()->last_name, "callback_url" => request()->callback_url, + /* + 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) + both values need to be entered within hidden input fields + */ + "subaccount" => request()->subaccount, + "transaction_charge" => request()->transaction_charge, /* * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url * form need an input field: From 5cb32d2356729072de7af5415d5cb925c5a823de Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 15:31:10 +0100 Subject: [PATCH 07/40] Drop support for PHP 5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4abfdb7..87cebf6 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "minimum-stability": "stable", "require": { - "php": "^5.4.0|^7.0", + "php": "^7.0", "illuminate/support": "5.*|6.*|^7.0", "guzzlehttp/guzzle": "5.*|6.*" }, From 5ebc8a5f7074c83e06b24a2eb1f2a1e2205cada8 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 15:31:55 +0100 Subject: [PATCH 08/40] Bump support --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 87cebf6..c4c0c5a 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "minimum-stability": "stable", "require": { "php": "^7.0", - "illuminate/support": "5.*|6.*|^7.0", + "illuminate/support": "^5.8.15|^6.0|^7.0", "guzzlehttp/guzzle": "5.*|6.*" }, "require-dev": { From ab1118efe2f6d0d469a7c645035c340077a65218 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 15:33:11 +0100 Subject: [PATCH 09/40] Bump phpunit and mockery --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c4c0c5a..8cd19f2 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,10 @@ "guzzlehttp/guzzle": "5.*|6.*" }, "require-dev": { - "phpunit/phpunit" : "4.*", + "phpunit/phpunit" : "^8.4|^9.0", "scrutinizer/ocular": "~1.1", "satooshi/php-coveralls": "^0.7.0", - "mockery/mockery": ">=0.7.2" + "mockery/mockery": "^1.3" }, "autoload": { "psr-4": { From a37a7c3636f4084ea5b2c97bbf60f73aef92cfb8 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 15:42:09 +0100 Subject: [PATCH 10/40] Improve docs and changelog --- CHANGELOG.md | 6 +++++- README.md | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff38a33..6c87287 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,4 +3,8 @@ All Notable changes to `laravel-paystack` will be documented in this file ## 2015-11-04 -- Initial release \ No newline at end of file +- Initial release + +## 2020-05-23 +- Support for Laravel 7 +- Support for splitting payments into subaccounts \ No newline at end of file diff --git a/README.md b/README.md index fc89f7b..99b48fb 100644 --- a/README.md +++ b/README.md @@ -91,18 +91,18 @@ return [ Though there are multiple ways to pay an order, most payment gateways expect you to follow the following flow in your checkout process: -###1. The customer is redirected to the payment provider +### 1. The customer is redirected to the payment provider After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to site of the payment provider. -The redirection is accomplished by submitting a form with some hidden fields. The form must post to the site of the payment provider. The hidden fields minimally specify the amount that must be paid, the order id and a hash. +The redirection is accomplished by submitting a form with some hidden fields. The form must send a POST request to the site of the payment provider. The hidden fields minimally specify the amount that must be paid, the order id and a hash. The hash is calculated using the hidden form fields and a non-public secret. The hash used by the payment provider to verify if the request is valid. -###2. The customer pays on the site of the payment provider -The customer arrived on the site of the payment provider and gets to choose a payment method. All steps necessary to pay the order are taken care of by the payment provider. +### 2. The customer pays on the site of the payment provider +The customer arrives on the site of the payment provider and gets to choose a payment method. All steps necessary to pay the order are taken care of by the payment provider. -###3. The customer gets redirected back +### 3. The customer gets redirected back to your site After having paid the order the customer is redirected back. In the redirection request to the shop-site some values are returned. The values are usually the order id, a paymentresult and a hash. The hash is calculated out of some of the fields returned and a secret non-public value. This hash is used to verify if the request is valid and comes from the payment provider. It is paramount that this hash is thoroughly checked. @@ -128,7 +128,7 @@ Note: Make sure you have `/payment/callback` registered in Paystack Dashboard [h ```php // Laravel 5.1.17 and above -Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay'); +Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay'); ``` OR @@ -150,7 +150,7 @@ OR // Laravel 5.0 Route::get('payment/callback', [ 'uses' => 'PaymentController@handleGatewayCallback' -]); +]); ``` ```php @@ -235,27 +235,27 @@ Paystack::getAllTransactions(); Paystack::genTranxRef(); /** -* This method creates a subaccount to be used for split payments +* This method creates a subaccount to be used for split payments * @return array */ Paystack::createSubAccount(); /** -* This method fetches the details of a subaccount +* This method fetches the details of a subaccount * @return array */ Paystack::fetchSubAccount(); /** -* This method lists the subaccounts associated with your paystack account +* This method lists the subaccounts associated with your paystack account * @return array */ Paystack::listSubAccounts(); /** -* This method Updates a subaccount to be used for split payments +* This method Updates a subaccount to be used for split payments * @return array */ Paystack::updateSubAccount(); From 64bcc5f4d4b83a5983c556a38111793109919b1d Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 15:51:17 +0100 Subject: [PATCH 11/40] Add support for other currencies --- CHANGELOG.md | 3 ++- README.md | 1 + src/Paystack.php | 27 ++++++++++++++------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c87287..2227e58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,4 +7,5 @@ All Notable changes to `laravel-paystack` will be documented in this file ## 2020-05-23 - Support for Laravel 7 -- Support for splitting payments into subaccounts \ No newline at end of file +- Support for splitting payments into subaccounts +- Support for more than one currency. Now you can use USD! \ No newline at end of file diff --git a/README.md b/README.md index 99b48fb..31e7fd7 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,7 @@ A sample form will look like so: {{-- required in kobo --}} + {{-- For other necessary things you want to add to your payload. it is optional though --}} {{-- required --}} {{-- required --}} diff --git a/src/Paystack.php b/src/Paystack.php index b6527f0..fac3392 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -100,11 +100,11 @@ private function setRequestOptions() ); } - + /** - + * Initiate a payment request to Paystack - * Included the option to pass the payload to this method for situations + * 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 */ @@ -120,8 +120,9 @@ public function makePaymentRequest( $data = null) "first_name" => request()->first_name, "last_name" => request()->last_name, "callback_url" => request()->callback_url, + "currency" => (request()->currency != "" ? request()->currency : "NGN"), /* - Paystack allows for transactions to be split into a subaccount - + 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) both values need to be entered within hidden input fields */ @@ -137,7 +138,7 @@ public function makePaymentRequest( $data = null) * . * . * ] - * + * * ] */ 'metadata' => request()->metadata @@ -186,10 +187,10 @@ 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 + * 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 */ @@ -597,13 +598,13 @@ public function updatePage($page_id) /** * Creates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge - * + * * @return array */ - + public function createSubAccount(){ $data = [ - "business_name" => request()->business_name, + "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, "account_number" => request()->account_number, "percentage_charge" => request()->percentage_charge, @@ -646,13 +647,13 @@ public function listSubAccounts($per_page,$page){ /** * Updates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge - * @param subaccount code + * @param subaccount code * @return array */ - + public function updateSubAccount($subaccount_code){ $data = [ - "business_name" => request()->business_name, + "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, "account_number" => request()->account_number, "percentage_charge" => request()->percentage_charge, From 44cbc4861cdcf3dee6e22179057e0fcad277d167 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 15:52:18 +0100 Subject: [PATCH 12/40] Fix formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31e7fd7..8b0c3bb 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ return [ ``` -##General payment flow +## General payment flow Though there are multiple ways to pay an order, most payment gateways expect you to follow the following flow in your checkout process: From 7551d1af65459fd3747afbcc87db147812c2725b Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 16:04:31 +0100 Subject: [PATCH 13/40] Add helpers --- .travis.yml | 6 ++-- README.md | 64 ++++++++++++++++++++++++++++++++++++++++- composer.json | 3 ++ src/Support/helpers.php | 9 ++++++ tests/HelpersTest.php | 19 ++++++++++++ 5 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 src/Support/helpers.php create mode 100644 tests/HelpersTest.php diff --git a/.travis.yml b/.travis.yml index 2185801..99454b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,9 @@ install: travis_retry composer install --no-interaction --prefer-source script: - mkdir -p build/logs - - php vendor/bin/phpunit -c phpunit.xml.dist - - phpunit --coverage-text --coverage-clover=coverage.clover - - phpunit --coverage-clover build/logs/clover.xml + - vendor/bin/phpunit -c phpunit.xml.dist + - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover + - vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_script: - wget https://scrutinizer-ci.com/ocular.phar diff --git a/README.md b/README.md index 8b0c3bb..7f0f066 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,14 @@ You'll then need to run `composer install` or `composer update` to download it a Once Laravel Paystack is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key. +```php +'providers' => [ + ... + Unicodeveloper\Paystack\PaystackServiceProvider::class, + ... +] +``` + > If you use **Laravel >= 5.5** you can skip this step and go to [**`configuration`**](https://github.com/unicodeveloper/laravel-paystack#configuration) * `Unicodeveloper\Paystack\PaystackServiceProvider::class` @@ -197,11 +205,16 @@ Let me explain the fluent methods this package provides a bit here. /** * This fluent method does all the dirty work of sending a POST request with the form data * to Paystack Api, then it gets the authorization Url and redirects the user to Paystack - * Payment Page. I abstracted all of it, so you don't have to worry about that. + * Payment Page. We've abstracted all of it, so you don't have to worry about that. * Just eat your cookies while coding! */ Paystack::getAuthorizationUrl()->redirectNow(); +/** + * Alternatively, use the helper. + */ +paystack()->getAuthorizationUrl()->redirectNow(); + /** * This fluent method does all the dirty work of verifying that the just concluded transaction was actually valid, * It verifies the transaction reference with Paystack Api and then grabs the data returned from Paystack. @@ -210,36 +223,69 @@ Paystack::getAuthorizationUrl()->redirectNow(); */ Paystack::getPaymentData(); +/** + * Alternatively, use the helper. + */ +paystack()->getPaymentData(); + /** * This method gets all the customers that have performed transactions on your platform with Paystack * @returns array */ Paystack::getAllCustomers(); +/** + * Alternatively, use the helper. + */ +paystack()->getAllCustomers(); + + /** * This method gets all the plans that you have registered on Paystack * @returns array */ Paystack::getAllPlans(); +/** + * Alternatively, use the helper. + */ +paystack()->getAllPlans(); + + /** * This method gets all the transactions that have occurred * @returns array */ Paystack::getAllTransactions(); +/** + * Alternatively, use the helper. + */ +paystack()->getAllTransactions(); + /** * This method generates a unique super secure cryptograhical hash token to use as transaction reference * @returns string */ Paystack::genTranxRef(); +/** + * Alternatively, use the helper. + */ +paystack()->genTranxRef(); + + /** * This method creates a subaccount to be used for split payments * @return array */ Paystack::createSubAccount(); +/** + * Alternatively, use the helper. + */ +paystack()->createSubAccount(); + /** * This method fetches the details of a subaccount @@ -247,6 +293,11 @@ Paystack::createSubAccount(); */ Paystack::fetchSubAccount(); +/** + * Alternatively, use the helper. + */ +paystack()->fetchSubAccount(); + /** * This method lists the subaccounts associated with your paystack account @@ -254,11 +305,22 @@ Paystack::fetchSubAccount(); */ Paystack::listSubAccounts(); +/** + * Alternatively, use the helper. + */ +paystack()->listSubAccounts(); + + /** * This method Updates a subaccount to be used for split payments * @return array */ Paystack::updateSubAccount(); + +/** + * Alternatively, use the helper. + */ +paystack()->updateSubAccount(); ``` A sample form will look like so: diff --git a/composer.json b/composer.json index 8cd19f2..df35652 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,9 @@ "mockery/mockery": "^1.3" }, "autoload": { + "files": [ + "src/Support/helpers.php" + ], "psr-4": { "Unicodeveloper\\Paystack\\": "src/" } diff --git a/src/Support/helpers.php b/src/Support/helpers.php new file mode 100644 index 0000000..c0a0eaf --- /dev/null +++ b/src/Support/helpers.php @@ -0,0 +1,9 @@ +make('laravel-paystack'); + } +} \ No newline at end of file diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php new file mode 100644 index 0000000..d8cb157 --- /dev/null +++ b/tests/HelpersTest.php @@ -0,0 +1,19 @@ +assertInstanceOf("Unicodeveloper\Paystack\Paystack", paystack()); + } +} \ No newline at end of file From 5590c546a8d7a9ca133583b66578ed1a6da70f22 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 16:25:36 +0100 Subject: [PATCH 14/40] Fix formatting --- src/Paystack.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index 04ccf89..9dc8a81 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -112,9 +112,11 @@ private function setRequestOptions() public function makePaymentRequest( $data = null) { if ( $data == null ) { - $quantity = intval(request()->quantity); - $data = [ - "amount" => intval(request()->amount)*$quantity, + + $quantity = intval(request()->quantity); + + $data = [ + "amount" => intval(request()->amount) * $quantity, "reference" => request()->reference, "email" => request()->email, "plan" => request()->plan, From 252d2a0dd8666ef130d4f7dbbe92173f98b935e9 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 16:27:58 +0100 Subject: [PATCH 15/40] Drop support for php 5 --- .travis.yml | 2 -- CHANGELOG.md | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 99454b4..3f85c4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - 5.5 - - 5.6 - 7.0 - hhvm diff --git a/CHANGELOG.md b/CHANGELOG.md index 2227e58..73df5fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,4 +8,6 @@ All Notable changes to `laravel-paystack` will be documented in this file ## 2020-05-23 - Support for Laravel 7 - Support for splitting payments into subaccounts -- Support for more than one currency. Now you can use USD! \ No newline at end of file +- Support for more than one currency. Now you can use USD! +- Support for multiple quantities +- Support for helpers \ No newline at end of file From b92aed79f561e574efe20e8f14e2829249a42521 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 16:29:38 +0100 Subject: [PATCH 16/40] Bump to 7.2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3f85c4b..3378670 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: - - 7.0 + - 7.2 - hhvm matrix: From c1222add11200463a6de57968bd61c03cf578b3d Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 16:36:35 +0100 Subject: [PATCH 17/40] Upgrade to php unit new test case --- .travis.yml | 2 +- tests/HelpersTest.php | 4 ++-- tests/PaystackTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3378670..a1339f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php php: - - 7.2 + - 7.3 - hhvm matrix: diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index d8cb157..c58a010 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -2,9 +2,9 @@ namespace Unicodeveloper\Paystack\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -class HelpersTest extends PHPUnit_Framework_TestCase { +class HelpersTest extends TestCase { /** * Tests that helper returns diff --git a/tests/PaystackTest.php b/tests/PaystackTest.php index 04f7f5e..4f21321 100644 --- a/tests/PaystackTest.php +++ b/tests/PaystackTest.php @@ -13,12 +13,12 @@ use Mockery as m; use GuzzleHttp\Client; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Unicodeveloper\Paystack\Paystack; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Facade as Facade; -class PaystackTest extends PHPUnit_Framework_TestCase +class PaystackTest extends TestCase { protected $paystack; From 7399ac1c5231516d50329cedd14f89217201db99 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 17:21:19 +0100 Subject: [PATCH 18/40] Fixed test issue --- composer.json | 2 +- phpunit.xml.dist => phpunit.xml | 2 +- tests/HelpersTest.php | 16 +++++++++++++++- tests/PaystackTest.php | 4 ++-- 4 files changed, 19 insertions(+), 5 deletions(-) rename phpunit.xml.dist => phpunit.xml (90%) diff --git a/composer.json b/composer.json index df35652..0936778 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "phpunit/phpunit" : "^8.4|^9.0", "scrutinizer/ocular": "~1.1", - "satooshi/php-coveralls": "^0.7.0", + "php-coveralls/php-coveralls": "^2.0", "mockery/mockery": "^1.3" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml similarity index 90% rename from phpunit.xml.dist rename to phpunit.xml index e4d77b6..2abdbb2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml @@ -22,7 +22,7 @@ - + diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index c58a010..7bb3da9 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -2,10 +2,24 @@ namespace Unicodeveloper\Paystack\Test; +use Mockery as m; use PHPUnit\Framework\TestCase; class HelpersTest extends TestCase { + protected $paystack; + + public function setUp(): void + { + $this->paystack = m::mock('Unicodeveloper\Paystack\Paystack'); + $this->mock = m::mock('GuzzleHttp\Client'); + } + + public function tearDown(): void + { + m::close(); + } + /** * Tests that helper returns * @@ -14,6 +28,6 @@ class HelpersTest extends TestCase { */ function it_returns_instance_of_paystack () { - $this->assertInstanceOf("Unicodeveloper\Paystack\Paystack", paystack()); + $this->assertInstanceOf("Unicodeveloper\Paystack\Paystack", $this->paystack); } } \ No newline at end of file diff --git a/tests/PaystackTest.php b/tests/PaystackTest.php index 4f21321..cabd082 100644 --- a/tests/PaystackTest.php +++ b/tests/PaystackTest.php @@ -22,13 +22,13 @@ class PaystackTest extends TestCase { protected $paystack; - public function setUp() + public function setUp(): void { $this->paystack = m::mock('Unicodeveloper\Paystack\Paystack'); $this->mock = m::mock('GuzzleHttp\Client'); } - public function tearDown() + public function tearDown(): void { m::close(); } From 48148b016995d760a24aac6bfe7b2d53feb81b8a Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 17:28:45 +0100 Subject: [PATCH 19/40] add dist --- phpunit.xml => phpunit.xml.dist | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phpunit.xml => phpunit.xml.dist (100%) diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist From 533d45b3e7c68e283a2ed71ddd45af1ef7728873 Mon Sep 17 00:00:00 2001 From: unicodeveloper Date: Sat, 23 May 2020 17:38:24 +0100 Subject: [PATCH 20/40] Remove testing on hhvm --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1339f1..bcd5b04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,6 @@ language: php php: - 7.3 - - hhvm - -matrix: - allow_failures: - - php: hhvm install: travis_retry composer install --no-interaction --prefer-source From 93354796ee37d4174703fbefa216a5d6c32eb265 Mon Sep 17 00:00:00 2001 From: sunitpanwar Date: Thu, 4 Jun 2020 19:23:04 +0530 Subject: [PATCH 21/40] Added exception handling for expired code --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e98d9db..f4ad8ec 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,11 @@ class PaymentController extends Controller */ public function redirectToGateway() { - return Paystack::getAuthorizationUrl()->redirectNow(); + try{ + return Paystack::getAuthorizationUrl()->redirectNow(); + }catch(\Exception $e) { + return Redirect::back()->withMessage(['msg'=>'The paystack token has expired. Please refresh the page and try again.', 'type'=>'error']); + } } /** From 94da0d486a83009bae57fba2af1258162e4a7d71 Mon Sep 17 00:00:00 2001 From: Gain John <46064597+Dhaxor@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:08:04 +0100 Subject: [PATCH 22/40] Update README.md Corrected some typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e98d9db..2f9b899 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ return [ Though there are multiple ways to pay an order, most payment gateways expect you to follow the following flow in your checkout process: ### 1. The customer is redirected to the payment provider -After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to site of the payment provider. +After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to the site of the payment provider. The redirection is accomplished by submitting a form with some hidden fields. The form must send a POST request to the site of the payment provider. The hidden fields minimally specify the amount that must be paid, the order id and a hash. @@ -111,7 +111,7 @@ The hash is calculated using the hidden form fields and a non-public secret. The The customer arrives on the site of the payment provider and gets to choose a payment method. All steps necessary to pay the order are taken care of by the payment provider. ### 3. The customer gets redirected back to your site -After having paid the order the customer is redirected back. In the redirection request to the shop-site some values are returned. The values are usually the order id, a paymentresult and a hash. +After having paid the order the customer is redirected back. In the redirection request to the shop-site some values are returned. The values are usually the order id, a payment result and a hash. The hash is calculated out of some of the fields returned and a secret non-public value. This hash is used to verify if the request is valid and comes from the payment provider. It is paramount that this hash is thoroughly checked. From 5c3c524ec048d9a3a6cbb83bf0b6031e3ecb8aca Mon Sep 17 00:00:00 2001 From: Ugendu Martins Ositadinma Date: Sun, 2 Aug 2020 22:51:06 +0100 Subject: [PATCH 23/40] Fixed a typographical error in the README.md file --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2f9b899..b76a9f4 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ Paystack::getAllTransactions(); paystack()->getAllTransactions(); /** - * This method generates a unique super secure cryptograhical hash token to use as transaction reference + * This method generates a unique super secure cryptographic hash token to use as transaction reference * @returns string */ Paystack::genTranxRef(); @@ -327,8 +327,8 @@ A sample form will look like so: ```html
-
-
+
+

Lagos Eyo Print Tee Shirt @@ -344,16 +344,15 @@ A sample form will look like so: {{-- required --}} {{ csrf_field() }} {{-- works only when using laravel 5.1, 5.2 --}} - {{-- employ this in place of csrf_field only in laravel 5.0 --}} - + {{-- employ this in place of csrf_field only in laravel 5.0 --}}

- +

-
+
``` @@ -367,7 +366,7 @@ We must validate if the redirect to our site is a valid request (we don't want i In the controller that handles the request coming from the payment provider, we have -`Paystack::getPaymentData()` - This function calls the verification methods and ensure it is a valid transction else it throws an exception. +`Paystack::getPaymentData()` - This function calls the verification methods and ensure it is a valid transaction else it throws an exception. You can test with these details From 036235482e202191bddf9ffafa38cb869826de32 Mon Sep 17 00:00:00 2001 From: chikeozulumba Date: Thu, 27 Aug 2020 17:04:33 +0100 Subject: [PATCH 24/40] Set default value for quantity --- src/Paystack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Paystack.php b/src/Paystack.php index 9dc8a81..69658f7 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -113,7 +113,7 @@ public function makePaymentRequest( $data = null) { if ( $data == null ) { - $quantity = intval(request()->quantity); + $quantity = intval(request()->quantity ? request()->quantity : 1); $data = [ "amount" => intval(request()->amount) * $quantity, From fa339c5d56d03501a5be791313d23f32a90fbf83 Mon Sep 17 00:00:00 2001 From: chikeozulumba Date: Thu, 27 Aug 2020 23:23:12 +0100 Subject: [PATCH 25/40] Convert to null coalescing --- src/Paystack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Paystack.php b/src/Paystack.php index 69658f7..0aa42dc 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -113,7 +113,7 @@ public function makePaymentRequest( $data = null) { if ( $data == null ) { - $quantity = intval(request()->quantity ? request()->quantity : 1); + $quantity = intval(request()->quantity ?? 1); $data = [ "amount" => intval(request()->amount) * $quantity, From a6e8c790b16a947e5d2369ad77d2082e892c326b Mon Sep 17 00:00:00 2001 From: Prosper Otemuyiwa Date: Sat, 26 Sep 2020 14:28:10 +0100 Subject: [PATCH 26/40] Bump to Laravel 8. Drop support for Laravel 5 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0936778..651d8ce 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "unicodeveloper/laravel-paystack", "description": "A Laravel Package for Paystack", - "keywords": ["php","github", "laravel","Open Source","payments", "subscription", "paystack", "paystack.co","laravel 5", "laravel 6"], + "keywords": ["php","github", "laravel","Open Source","payments", "subscription", "paystack", "paystack.co","laravel 6", "laravel 7", "laravel 8"], "license": "MIT", "authors": [ { @@ -15,9 +15,9 @@ ], "minimum-stability": "stable", "require": { - "php": "^7.0", - "illuminate/support": "^5.8.15|^6.0|^7.0", - "guzzlehttp/guzzle": "5.*|6.*" + "php": "^7.2", + "illuminate/support": "~6|~7|~8", + "guzzlehttp/guzzle": "~6|~7" }, "require-dev": { "phpunit/phpunit" : "^8.4|^9.0", From 2763c66bc40535f74e0e0d4d60cab1b0c96b1b76 Mon Sep 17 00:00:00 2001 From: Prosper Otemuyiwa Date: Thu, 19 Nov 2020 17:30:28 +0100 Subject: [PATCH 27/40] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 78f51e3..a6f1caf 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; +use Illuminate\Support\Facades\Redirect; use Paystack; class PaymentController extends Controller From 67e11da6716ff17dd21f4ddd6fe925d29f9a303d Mon Sep 17 00:00:00 2001 From: Prosper Otemuyiwa Date: Thu, 19 Nov 2020 17:43:40 +0100 Subject: [PATCH 28/40] Fix #127 #128 #126 --- src/Paystack.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index 0aa42dc..15386ac 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -115,7 +115,7 @@ public function makePaymentRequest( $data = null) $quantity = intval(request()->quantity ?? 1); - $data = [ + $data = array_filter([ "amount" => intval(request()->amount) * $quantity, "reference" => request()->reference, "email" => request()->email, @@ -145,10 +145,7 @@ public function makePaymentRequest( $data = null) * ] */ 'metadata' => request()->metadata - ]; - - // Remove the fields which were not sent (value would be null) - array_filter($data); + ]); } $this->setHttpResponse('/transaction/initialize', 'POST', $data); From 95243d01efaa8713e448e542436f64ee3980b22c Mon Sep 17 00:00:00 2001 From: Prosper Otemuyiwa Date: Thu, 19 Nov 2020 17:45:44 +0100 Subject: [PATCH 29/40] Fix indentation --- src/Paystack.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index 15386ac..450ec3d 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -124,6 +124,7 @@ public function makePaymentRequest( $data = null) "last_name" => 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) @@ -131,18 +132,19 @@ public function makePaymentRequest( $data = null) */ "subaccount" => request()->subaccount, "transaction_charge" => request()->transaction_charge, + /* * 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"], - * . - * . - * . - * ] - * - * ] + * 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 ]); From 731358f45ca24e7a4a8b392ee0dea0411287b795 Mon Sep 17 00:00:00 2001 From: Prosper Otemuyiwa Date: Thu, 19 Nov 2020 17:46:30 +0100 Subject: [PATCH 30/40] Rename isNullException.php to IsNullException.php --- src/Exceptions/{isNullException.php => IsNullException.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Exceptions/{isNullException.php => IsNullException.php} (100%) diff --git a/src/Exceptions/isNullException.php b/src/Exceptions/IsNullException.php similarity index 100% rename from src/Exceptions/isNullException.php rename to src/Exceptions/IsNullException.php From bb9598736a40015d96656251fb9a26fdc9e4c0d6 Mon Sep 17 00:00:00 2001 From: Olusegun Ayeni Date: Fri, 18 Jun 2021 16:42:13 +0100 Subject: [PATCH 31/40] 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 32/40] 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 */ From eec5ecd960cdc96b961d4e33284df58fae1fa0fc Mon Sep 17 00:00:00 2001 From: Ibidapo Adeolu Date: Tue, 1 Feb 2022 12:53:31 +0100 Subject: [PATCH 33/40] 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']; From 579bb6bad90635f13aeb851e76dc8fc7f34a2ef4 Mon Sep 17 00:00:00 2001 From: stojan kukrika Date: Fri, 11 Feb 2022 03:32:33 +0100 Subject: [PATCH 34/40] added support for laravel 9 and php 8.1 --- README.md | 4 ++-- composer.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c2b3b57..3289e1e 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ Route::post('/pay', [ OR ```php -// Laravel 8 +// Laravel 8 & 9 Route::post('/pay', [App\Http\Controllers\PaymentController::class, 'redirectToGateway'])->name('pay'); ``` @@ -171,7 +171,7 @@ Route::get('payment/callback', [ OR ```php -// Laravel 8 +// Laravel 8 & 9 Route::get('/payment/callback', [App\Http\Controllers\PaymentController::class, 'handleGatewayCallback']); ``` diff --git a/composer.json b/composer.json index 98db5e4..1aea8b3 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,9 @@ ], "minimum-stability": "stable", "require": { - "php": "^7.2|^8.0", - "illuminate/support": "~6|~7|~8", - "guzzlehttp/guzzle": "~6|~7|~8" + "php": "^7.2|^8.0|^8.1", + "illuminate/support": "~6|~7|~8|~9", + "guzzlehttp/guzzle": "~6|~7|~8|~9" }, "require-dev": { "phpunit/phpunit": "^8.4|^9.0", From 7fd0f9613fdf1823c67b0756a646a7843899848b Mon Sep 17 00:00:00 2001 From: a4anthony <55565463+a4anthony@users.noreply.github.com> Date: Fri, 5 Aug 2022 04:57:57 +0100 Subject: [PATCH 35/40] added channels option to request initialize data --- src/Paystack.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Paystack.php b/src/Paystack.php index c1a5ea7..55e30e7 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -119,6 +119,7 @@ public function makePaymentRequest($data = null) "amount" => intval(request()->amount) * $quantity, "reference" => request()->reference, "email" => request()->email, + "channels" => request()->channels, "plan" => request()->plan, "first_name" => request()->first_name, "last_name" => request()->last_name, From 7aea445ef452ce2c93a410e3f048ea2a5932be0a Mon Sep 17 00:00:00 2001 From: Chinedu Ukpe Date: Tue, 20 Sep 2022 15:31:32 +0100 Subject: [PATCH 36/40] Pass transaction_id to verify transaction --- src/Paystack.php | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index c1a5ea7..ed54091 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -86,7 +86,7 @@ public function setKey() */ private function setRequestOptions() { - $authBearer = 'Bearer '. $this->secretKey; + $authBearer = 'Bearer ' . $this->secretKey; $this->client = new Client( [ @@ -101,7 +101,7 @@ private function setRequestOptions() } - /** + /** * Initiate a payment request to Paystack * Included the option to pass the payload to this method for situations @@ -111,7 +111,7 @@ private function setRequestOptions() public function makePaymentRequest($data = null) { - if ( $data == null ) { + if ($data == null) { $quantity = intval(request()->quantity ?? 1); @@ -214,7 +214,7 @@ public function getAuthorizationUrl($data = null) 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 @@ -232,9 +232,9 @@ public function getAuthorizationResponse($data) /** * Hit Paystack Gateway to Verify that the transaction is valid */ - private function verifyTransactionAtGateway() + private function verifyTransactionAtGateway($transaction_id = null) { - $transactionRef = request()->query('trxref'); + $transactionRef = $transaction_id ?? request()->query('trxref'); $relativeUrl = "/transaction/verify/{$transactionRef}"; @@ -245,9 +245,9 @@ private function verifyTransactionAtGateway() * True or false condition whether the transaction is verified * @return boolean */ - public function isTransactionVerificationValid() + public function isTransactionVerificationValid($transaction_id = null) { - $this->verifyTransactionAtGateway(); + $this->verifyTransactionAtGateway($transaction_id); $result = $this->getResponse()['message']; @@ -375,7 +375,6 @@ public function createPlan() $this->setRequestOptions(); return $this->setHttpResponse("/plan", 'POST', $data)->getResponse(); - } /** @@ -436,7 +435,7 @@ public function createCustomer() public function fetchCustomer($customer_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/customer/'. $customer_id, 'GET', [])->getResponse(); + return $this->setHttpResponse('/customer/' . $customer_id, 'GET', [])->getResponse(); } /** @@ -456,7 +455,7 @@ public function updateCustomer($customer_id) ]; $this->setRequestOptions(); - return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse(); + return $this->setHttpResponse('/customer/' . $customer_id, 'PUT', $data)->getResponse(); } /** @@ -566,7 +565,7 @@ public function disableSubscription() public function fetchSubscription($subscription_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/subscription/'.$subscription_id, 'GET', [])->getResponse(); + return $this->setHttpResponse('/subscription/' . $subscription_id, 'GET', [])->getResponse(); } /** @@ -602,7 +601,7 @@ public function getAllPages() public function fetchPage($page_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/page/'.$page_id, 'GET', [])->getResponse(); + return $this->setHttpResponse('/page/' . $page_id, 'GET', [])->getResponse(); } /** @@ -619,16 +618,17 @@ public function updatePage($page_id) ]; $this->setRequestOptions(); - return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse(); + return $this->setHttpResponse('/page/' . $page_id, 'PUT', $data)->getResponse(); } - /** + /** * Creates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge * * @return array */ - public function createSubAccount(){ + public function createSubAccount() + { $data = [ "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, @@ -643,31 +643,30 @@ public function createSubAccount(){ $this->setRequestOptions(); return $this->setHttpResponse('/subaccount', 'POST', array_filter($data))->getResponse(); - } - /** + /** * Fetches details of a subaccount * @param subaccount code * @return array */ - public function fetchSubAccount($subaccount_code){ + public function fetchSubAccount($subaccount_code) + { $this->setRequestOptions(); - return $this->setHttpResponse("/subaccount/{$subaccount_code}","GET",[])->getResponse(); - + return $this->setHttpResponse("/subaccount/{$subaccount_code}", "GET", [])->getResponse(); } - /** + /** * Lists all the subaccounts associated with the account * @param $per_page - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve * @return array */ - public function listSubAccounts($per_page,$page){ + public function listSubAccounts($per_page, $page) + { $this->setRequestOptions(); - return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse(); - + return $this->setHttpResponse("/subaccount/?perPage=" . (int) $per_page . "&page=" . (int) $page, "GET")->getResponse(); } @@ -677,7 +676,8 @@ public function listSubAccounts($per_page,$page){ * @return array */ - public function updateSubAccount($subaccount_code){ + public function updateSubAccount($subaccount_code) + { $data = [ "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, @@ -693,6 +693,5 @@ public function updateSubAccount($subaccount_code){ $this->setRequestOptions(); return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse(); - } } From 15dac8a5bf0a9dbf20f889465476773c561db026 Mon Sep 17 00:00:00 2001 From: Md Omor Faruk Date: Wed, 15 Mar 2023 16:10:01 +0600 Subject: [PATCH 37/40] laravel 10 done --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1aea8b3..e93effc 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "minimum-stability": "stable", "require": { "php": "^7.2|^8.0|^8.1", - "illuminate/support": "~6|~7|~8|~9", + "illuminate/support": "~6|~7|~8|~9|^10.0", "guzzlehttp/guzzle": "~6|~7|~8|~9" }, "require-dev": { From 1dd3cabff72292939ea25c33d238caa465dfccb9 Mon Sep 17 00:00:00 2001 From: PrevailExcel Date: Mon, 9 Oct 2023 12:50:50 +0100 Subject: [PATCH 38/40] Added Get Banks list and Account Confirmation --- src/Paystack.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Paystack.php b/src/Paystack.php index ed54091..21443c2 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -694,4 +694,32 @@ public function updateSubAccount($subaccount_code) $this->setRequestOptions(); return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse(); } + + + /** + * Get a list of all supported banks and their properties + * @param $country - The country from which to obtain the list of supported banks, $per_page - Specifies how many records to retrieve per page , + * $use_cursor - Flag to enable cursor pagination on the endpoint + * @return array + */ + public function getBanks(?string $country, int $per_page = 50, bool $use_cursor = false) + { + if (!$country) + $country = request()->country ?? 'nigeria'; + + $this->setRequestOptions(); + return $this->setHttpResponse("/bank/?country=" . $country . "&use_cursor=" . $use_cursor . "&perPage=" . (int) $per_page, "GET")->getResponse(); + } + + /** + * Confirm an account belongs to the right customer + * @param $account_number - Account Number, $bank_code - You can get the list of bank codes by calling the List Banks endpoint + * @return array + */ + public function confirmAccount(string $account_number, string $bank_code) + { + + $this->setRequestOptions(); + return $this->setHttpResponse("/bank/resolve/?account_number=" . $account_number . "&bank_code=" . $bank_code, "GET")->getResponse(); + } } From 244dc70314d72b3281ae224e9dfa02d17c6f86f1 Mon Sep 17 00:00:00 2001 From: theJohnCode Date: Wed, 13 Dec 2023 18:21:31 +0100 Subject: [PATCH 39/40] allowed the createCustomer method to accept a data parameter --- .phpunit.result.cache | 1 + src/Paystack.php | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..5c6751f --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":[],"times":{"Unicodeveloper\\Paystack\\Test\\HelpersTest::it_returns_instance_of_paystack":0.213,"Unicodeveloper\\Paystack\\Test\\PaystackTest::testAllCustomersAreReturned":0.089,"Unicodeveloper\\Paystack\\Test\\PaystackTest::testAllTransactionsAreReturned":0.001,"Unicodeveloper\\Paystack\\Test\\PaystackTest::testAllPlansAreReturned":0.001}} \ No newline at end of file diff --git a/src/Paystack.php b/src/Paystack.php index ed54091..453eea8 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -412,17 +412,20 @@ public function updatePlan($plan_code) /** * Create a customer */ - public function createCustomer() + public function createCustomer($data = null) { - $data = [ - "email" => request()->email, - "first_name" => request()->fname, - "last_name" => request()->lname, - "phone" => request()->phone, - "metadata" => request()->additional_info /* key => value pairs array */ + if ($data == null) { - ]; + $data = [ + "email" => request()->email, + "first_name" => request()->fname, + "last_name" => request()->lname, + "phone" => request()->phone, + "metadata" => request()->additional_info /* key => value pairs array */ + ]; + } + $this->setRequestOptions(); return $this->setHttpResponse('/customer', 'POST', $data)->getResponse(); } From aba26bebbb19dcdb3d78437a309c64f7547da30c Mon Sep 17 00:00:00 2001 From: Shift Date: Tue, 27 Feb 2024 16:13:56 +0000 Subject: [PATCH 40/40] Bump dependencies for Laravel 11 --- composer.json | 124 +++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/composer.json b/composer.json index e93effc..e67e985 100644 --- a/composer.json +++ b/composer.json @@ -1,66 +1,66 @@ { - "name": "unicodeveloper/laravel-paystack", - "description": "A Laravel Package for Paystack", - "keywords": [ - "php", - "github", - "laravel", - "Open Source", - "payments", - "subscription", - "paystack", - "paystack.co", - "laravel 6", - "laravel 7", - "laravel 8" - ], - "license": "MIT", - "authors": [ - { - "name": "unicodeveloper", - "email": "prosperotemuyiwa@gmail.com" - }, - { - "name": "iamfunsho", - "email": "info@devfunsho.com" - } - ], - "minimum-stability": "stable", - "require": { - "php": "^7.2|^8.0|^8.1", - "illuminate/support": "~6|~7|~8|~9|^10.0", - "guzzlehttp/guzzle": "~6|~7|~8|~9" - }, - "require-dev": { - "phpunit/phpunit": "^8.4|^9.0", - "scrutinizer/ocular": "~1.1", - "php-coveralls/php-coveralls": "^2.0", - "mockery/mockery": "^1.3" - }, - "autoload": { - "files": [ - "src/Support/helpers.php" + "name": "unicodeveloper/laravel-paystack", + "description": "A Laravel Package for Paystack", + "keywords": [ + "php", + "github", + "laravel", + "Open Source", + "payments", + "subscription", + "paystack", + "paystack.co", + "laravel 6", + "laravel 7", + "laravel 8" ], - "psr-4": { - "Unicodeveloper\\Paystack\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Unicodeveloper\\Paystack\\Test\\": "tests" - } - }, - "scripts": { - "test": "vendor/bin/phpunit" - }, - "extra": { - "laravel": { - "providers": [ - "Unicodeveloper\\Paystack\\PaystackServiceProvider" - ], - "aliases": { - "Paystack": "Unicodeveloper\\Paystack\\Facades\\Paystack" - } + "license": "MIT", + "authors": [ + { + "name": "unicodeveloper", + "email": "prosperotemuyiwa@gmail.com" + }, + { + "name": "iamfunsho", + "email": "info@devfunsho.com" + } + ], + "minimum-stability": "stable", + "require": { + "php": "^7.2|^8.0|^8.1", + "illuminate/support": "~6|~7|~8|~9|^10.0|^11.0", + "guzzlehttp/guzzle": "~6|~7|~8|~9" + }, + "require-dev": { + "phpunit/phpunit": "^8.4|^9.0|^10.5", + "scrutinizer/ocular": "~1.1", + "php-coveralls/php-coveralls": "^2.0", + "mockery/mockery": "^1.3" + }, + "autoload": { + "files": [ + "src/Support/helpers.php" + ], + "psr-4": { + "Unicodeveloper\\Paystack\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Unicodeveloper\\Paystack\\Test\\": "tests" + } + }, + "scripts": { + "test": "vendor/bin/phpunit" + }, + "extra": { + "laravel": { + "providers": [ + "Unicodeveloper\\Paystack\\PaystackServiceProvider" + ], + "aliases": { + "Paystack": "Unicodeveloper\\Paystack\\Facades\\Paystack" + } + } } - } }