From 19a9f6d436fff6640863980373d4cfc45b4e82bd Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 10 Dec 2018 21:08:21 +0100 Subject: [PATCH 01/39] Added class and defined endpoints as constants --- phpunit.xml.dist | 14 +++++++------- src/Endpoint.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/Endpoint.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e4d77b6..eaa1336 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,11 +19,11 @@ src/ - - - - - - - + + + + + + + diff --git a/src/Endpoint.php b/src/Endpoint.php new file mode 100644 index 0000000..20e7507 --- /dev/null +++ b/src/Endpoint.php @@ -0,0 +1,35 @@ + Date: Tue, 11 Dec 2018 17:39:17 +0100 Subject: [PATCH 02/39] Replaced Endpoints with constants --- src/Endpoint.php | 4 ++-- src/Paystack.php | 50 ++++++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Endpoint.php b/src/Endpoint.php index 20e7507..42c0752 100644 --- a/src/Endpoint.php +++ b/src/Endpoint.php @@ -17,7 +17,7 @@ class Endpoint const CREATE_CUSTOMER = "/customer"; const FETCH_CUSTOMER = "/customer/"; const UPDATE_CUSTOMER = "/customer/"; - const SUBSCRIPTIONS = "/subscription"; + const GET_ALL_SUBSCRIPTIONS = "/subscription"; const CREATE_SUBSCRIPTION = "/subscription"; const GET_CUSTOMER_SUBSCRIPTION = "/subscription?customer="; const GET_PLAN_SUBSCRIPTION = "/subscription?plan="; @@ -26,7 +26,7 @@ class Endpoint const FETCH_SUBSCRIPTION = "/subscription/"; const CREATE_PAGE = "/page"; const GET_ALL_PAGES = "/page"; - const FETCH_PAGE = "/page"; + const FETCH_PAGE = "/page/"; const UPDATE_PAGE = "/page/"; const CREATE_SUB_ACCOUNT = "/subaccount"; const FETCH_SUB_ACCOUNT = "/subaccount/"; diff --git a/src/Paystack.php b/src/Paystack.php index d3b4a7c..bfd5391 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -280,7 +280,7 @@ public function getAllCustomers() { $this->setRequestOptions(); - return $this->setHttpResponse("/customer", 'GET', [])->getData(); + return $this->setHttpResponse(Endpoint::CUSTOMERS, 'GET', [])->getData(); } /** @@ -291,7 +291,7 @@ public function getAllPlans() { $this->setRequestOptions(); - return $this->setHttpResponse("/plan", 'GET', [])->getData(); + return $this->setHttpResponse(Endpoint::PLANS, 'GET', [])->getData(); } /** @@ -302,7 +302,7 @@ public function getAllTransactions() { $this->setRequestOptions(); - return $this->setHttpResponse("/transaction", 'GET', [])->getData(); + return $this->setHttpResponse(Endpoint::TRANSACTIONS, 'GET', [])->getData(); } /** @@ -340,7 +340,7 @@ public function createPlan() $this->setRequestOptions(); - $this->setHttpResponse("/plan", 'POST', $data); + $this->setHttpResponse(Endpoint::CREATE_PLAN, 'POST', $data); } @@ -352,7 +352,7 @@ public function createPlan() public function fetchPlan($plan_code) { $this->setRequestOptions(); - return $this->setHttpResponse('/plan/' . $plan_code, 'GET', [])->getResponse(); + return $this->setHttpResponse(Endpoint::FETCH_PLAN . $plan_code, 'GET', [])->getResponse(); } /** @@ -373,7 +373,7 @@ public function updatePlan($plan_code) ]; $this->setRequestOptions(); - return $this->setHttpResponse('/plan/' . $plan_code, 'PUT', $data)->getResponse(); + return $this->setHttpResponse(Endpoint::UPDATE_PLAN . $plan_code, 'PUT', $data)->getResponse(); } /** @@ -391,7 +391,7 @@ public function createCustomer() ]; $this->setRequestOptions(); - return $this->setHttpResponse('/customer', 'POST', $data)->getResponse(); + return $this->setHttpResponse(Endpoint::CREATE_CUSTOMER, 'POST', $data)->getResponse(); } /** @@ -402,7 +402,7 @@ public function createCustomer() public function fetchCustomer($customer_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/customer/'. $customer_id, 'GET', [])->getResponse(); + return $this->setHttpResponse(Endpoint::FETCH_CUSTOMER . $customer_id, 'GET', [])->getResponse(); } /** @@ -422,7 +422,7 @@ public function updateCustomer($customer_id) ]; $this->setRequestOptions(); - return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse(); + return $this->setHttpResponse(Endpoint::UPDATE_CUSTOMER . $customer_id, 'PUT', $data)->getResponse(); } /** @@ -438,7 +438,7 @@ public function exportTransactions() ]; $this->setRequestOptions(); - return $this->setHttpResponse('/transaction/export', 'GET', $data)->getResponse(); + return $this->setHttpResponse(Endpoint::EXPORT_TRANSACTION, 'GET', $data)->getResponse(); } /** @@ -453,7 +453,7 @@ public function createSubscription() ]; $this->setRequestOptions(); - $this->setHttpResponse('/subscription', 'POST', $data); + $this->setHttpResponse(Endpoint::CREATE_SUBSCRIPTION, 'POST', $data); } /** @@ -465,7 +465,7 @@ public function getAllSubscriptions() { $this->setRequestOptions(); - return $this->setHttpResponse("/subscription", 'GET', [])->getData(); + return $this->setHttpResponse(Endpoint::GET_ALL_SUBSCRIPTIONS, 'GET', [])->getData(); } /** @@ -478,7 +478,7 @@ public function getCustomerSubscriptions($customer_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/subscription?customer=' . $customer_id, 'GET', [])->getData(); + return $this->setHttpResponse(Endpoint::GET_CUSTOMER_SUBSCRIPTION . $customer_id, 'GET', [])->getData(); } /** @@ -491,7 +491,7 @@ public function getPlanSubscriptions($plan_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/subscription?plan=' . $plan_id, 'GET', [])->getData(); + return $this->setHttpResponse(Endpoint::GET_PLAN_SUBSCRIPTION . $plan_id, 'GET', [])->getData(); } /** @@ -506,7 +506,7 @@ public function enableSubscription() ]; $this->setRequestOptions(); - return $this->setHttpResponse('/subscription/enable', 'POST', $data)->getResponse(); + return $this->setHttpResponse(Endpoint::ENABLE_SUBSCRIPTION, 'POST', $data)->getResponse(); } /** @@ -521,7 +521,7 @@ public function disableSubscription() ]; $this->setRequestOptions(); - return $this->setHttpResponse('/subscription/disable', 'POST', $data)->getResponse(); + return $this->setHttpResponse(Endpoint::DISABLE_SUBSCRIPTION, 'POST', $data)->getResponse(); } /** @@ -532,7 +532,7 @@ public function disableSubscription() public function fetchSubscription($subscription_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/subscription/'.$subscription_id, 'GET', [])->getResponse(); + return $this->setHttpResponse(Endpoint::FETCH_SUBSCRIPTION . $subscription_id, 'GET', [])->getResponse(); } /** @@ -547,7 +547,7 @@ public function createPage() ]; $this->setRequestOptions(); - $this->setHttpResponse('/page', 'POST', $data); + $this->setHttpResponse(Endpoint::CREATE_PAGE, 'POST', $data); } /** @@ -557,7 +557,7 @@ public function createPage() public function getAllPages() { $this->setRequestOptions(); - return $this->setHttpResponse('/page', 'GET', [])->getResponse(); + return $this->setHttpResponse(Endpoint::GET_ALL_PAGES, 'GET', [])->getResponse(); } /** @@ -568,7 +568,7 @@ public function getAllPages() public function fetchPage($page_id) { $this->setRequestOptions(); - return $this->setHttpResponse('/page/'.$page_id, 'GET', [])->getResponse(); + return $this->setHttpResponse(Endpoint::FETCH_PAGE . $page_id, 'GET', [])->getResponse(); } /** @@ -585,7 +585,7 @@ public function updatePage($page_id) ]; $this->setRequestOptions(); - return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse(); + return $this->setHttpResponse(Endpoint::UPDATE_PAGE . $page_id, 'PUT', $data)->getResponse(); } /** @@ -608,7 +608,7 @@ public function createSubAccount(){ ]; $this->setRequestOptions(); - return $this->setHttpResponse('/subaccount', 'POST', array_filter($data))->getResponse(); + return $this->setHttpResponse(Endpoint::CREATE_SUB_ACCOUNT, 'POST', array_filter($data))->getResponse(); } @@ -620,7 +620,7 @@ public function createSubAccount(){ public function fetchSubAccount($subaccount_code){ $this->setRequestOptions(); - return $this->setHttpResponse("/subaccount/{$subaccount_code}","GET",[])->getResponse(); + return $this->setHttpResponse(Endpoint::FETCH_SUB_ACCOUNT . "{$subaccount_code}","GET",[])->getResponse(); } @@ -632,7 +632,7 @@ public function fetchSubAccount($subaccount_code){ public function listSubAccounts($per_page,$page){ $this->setRequestOptions(); - return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse(); + return $this->setHttpResponse(Endpoint::LIST_SUB_ACCOUNT . (int) $per_page."&page=".(int) $page,"GET")->getResponse(); } @@ -658,7 +658,7 @@ public function updateSubAccount($subaccount_code){ ]; $this->setRequestOptions(); - return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse(); + return $this->setHttpResponse(Endpoint::UPDATE_SUB_ACCOUNT . "{$subaccount_code}", "PUT", array_filter($data))->getResponse(); } } From 6da9b83a87be961d20f1e7bf06eb200df83a3c74 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 11 Dec 2018 17:54:24 +0100 Subject: [PATCH 03/39] Replaced Endpoints with constants --- src/Paystack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Paystack.php b/src/Paystack.php index bfd5391..807858a 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -202,7 +202,7 @@ private function verifyTransactionAtGateway() { $transactionRef = request()->query('trxref'); - $relativeUrl = "/transaction/verify/{$transactionRef}"; + $relativeUrl = Endpoint::VERIFY_TRANSACTION . "{$transactionRef}"; $this->response = $this->client->get($this->baseUrl . $relativeUrl, []); } From 789eacab51bb6dca6b1b547f775d53c07e290a0f Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Wed, 12 Dec 2018 22:35:08 +0100 Subject: [PATCH 04/39] Updated endpoint code styling --- src/Endpoint.php | 54 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Endpoint.php b/src/Endpoint.php index 42c0752..6222a95 100644 --- a/src/Endpoint.php +++ b/src/Endpoint.php @@ -5,31 +5,31 @@ class Endpoint { - const INIT_TRANSACTION = "/transaction/initialize"; - const VERIFY_TRANSACTION = "/transaction/verify/"; - const EXPORT_TRANSACTION = "/transaction/export"; - const TRANSACTIONS = "/transaction"; - const PLANS = "/plan"; - const CREATE_PLAN = "/plan"; - const FETCH_PLAN = "/plan/"; - const UPDATE_PLAN = "/plan/"; - const CUSTOMERS = "/customer"; - const CREATE_CUSTOMER = "/customer"; - const FETCH_CUSTOMER = "/customer/"; - const UPDATE_CUSTOMER = "/customer/"; - const GET_ALL_SUBSCRIPTIONS = "/subscription"; - const CREATE_SUBSCRIPTION = "/subscription"; - const GET_CUSTOMER_SUBSCRIPTION = "/subscription?customer="; - const GET_PLAN_SUBSCRIPTION = "/subscription?plan="; - const ENABLE_SUBSCRIPTION = "/subscription/enable"; - const DISABLE_SUBSCRIPTION = "/subscription/disable"; - const FETCH_SUBSCRIPTION = "/subscription/"; - const CREATE_PAGE = "/page"; - const GET_ALL_PAGES = "/page"; - const FETCH_PAGE = "/page/"; - const UPDATE_PAGE = "/page/"; - const CREATE_SUB_ACCOUNT = "/subaccount"; - const FETCH_SUB_ACCOUNT = "/subaccount/"; - const LIST_SUB_ACCOUNT = "/subaccount/?perPage="; - const UPDATE_SUB_ACCOUNT = "/subaccount/?perPage="; + const INIT_TRANSACTION = "/transaction/initialize"; + const VERIFY_TRANSACTION = "/transaction/verify/"; + const EXPORT_TRANSACTION = "/transaction/export"; + const TRANSACTIONS = "/transaction"; + const PLANS = "/plan"; + const CREATE_PLAN = "/plan"; + const FETCH_PLAN = "/plan/"; + const UPDATE_PLAN = "/plan/"; + const CUSTOMERS = "/customer"; + const CREATE_CUSTOMER = "/customer"; + const FETCH_CUSTOMER = "/customer/"; + const UPDATE_CUSTOMER = "/customer/"; + const GET_ALL_SUBSCRIPTIONS = "/subscription"; + const CREATE_SUBSCRIPTION = "/subscription"; + const GET_CUSTOMER_SUBSCRIPTION = "/subscription?customer="; + const GET_PLAN_SUBSCRIPTION = "/subscription?plan="; + const ENABLE_SUBSCRIPTION = "/subscription/enable"; + const DISABLE_SUBSCRIPTION = "/subscription/disable"; + const FETCH_SUBSCRIPTION = "/subscription/"; + const CREATE_PAGE = "/page"; + const GET_ALL_PAGES = "/page"; + const FETCH_PAGE = "/page/"; + const UPDATE_PAGE = "/page/"; + const CREATE_SUB_ACCOUNT = "/subaccount"; + const FETCH_SUB_ACCOUNT = "/subaccount/"; + const LIST_SUB_ACCOUNT = "/subaccount/?perPage="; + const UPDATE_SUB_ACCOUNT = "/subaccount/?perPage="; } \ No newline at end of file From 53ac4608df5314d8c1b46b43efc614433a32fc50 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Fri, 14 Dec 2018 22:36:07 +0100 Subject: [PATCH 05/39] UPdated Paystack.php --- src/Paystack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Paystack.php b/src/Paystack.php index 807858a..4ce90e1 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -255,7 +255,7 @@ public function redirectNow() } /** - * Get Access code from transaction callback respose + * Get Access code from transaction callback response * @return string */ public function getAccessCode() From 01a520b751d1bb185b0e12ae9eae7f5cb4996b6f Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Sun, 16 Dec 2018 11:54:06 +0100 Subject: [PATCH 06/39] Begin work on request helper --- src/Helpers/HelpsRequest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Helpers/HelpsRequest.php diff --git a/src/Helpers/HelpsRequest.php b/src/Helpers/HelpsRequest.php new file mode 100644 index 0000000..8e7d8d2 --- /dev/null +++ b/src/Helpers/HelpsRequest.php @@ -0,0 +1,12 @@ + $data) { + request()->request->add([$key => $data]); + } + } +} From cc03c51cb45ce47fd0aae967991ef5b9fd5e23b1 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 12:09:48 +0100 Subject: [PATCH 07/39] Resolve dependency issues --- .gitignore | 3 ++- composer.json | 17 ++++++++-------- src/Http/ClientBuilder.php | 12 +++++++++++ src/PaystackFactory.php | 25 +++++++++++++++++++++++ src/PaystackManager.php | 12 +++++++++++ src/PaystackServiceProvider.php | 2 ++ tests/AbstractTestCase.php | 15 ++++++++++++++ tests/GitHubFactoryTest.php | 29 +++++++++++++++++++++++++++ tests/PaystackServiceProviderTest.php | 21 +++++++++++++++++++ tests/PaystackTest.php | 4 ++-- 10 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 src/Http/ClientBuilder.php create mode 100644 src/PaystackFactory.php create mode 100644 src/PaystackManager.php create mode 100644 tests/AbstractTestCase.php create mode 100644 tests/GitHubFactoryTest.php create mode 100644 tests/PaystackServiceProviderTest.php diff --git a/.gitignore b/.gitignore index 08a1747..3639a25 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build vendor .DS_Store composer.lock -.idea \ No newline at end of file +.idea +bpaystack \ No newline at end of file diff --git a/composer.json b/composer.json index 9b4eb51..a25e482 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,17 @@ ], "minimum-stability": "stable", "require": { - "php": "^5.4.0|^7.0", - "illuminate/support": "5.*", - "guzzlehttp/guzzle": "5.*|6.*" + "php": "^7.1.3", + "illuminate/support": "5.7.*", + "xeviant/paystack": "^0.0.21" }, "require-dev": { - "phpunit/phpunit" : "4.*", - "scrutinizer/ocular": "~1.1", - "satooshi/php-coveralls": "^0.7.0", - "mockery/mockery": ">=0.7.2" - }, + "mockery/mockery": "^1.2", + "phpunit/phpunit": "^7.0", + "orchestra/testbench": "3.7.*", + "graham-campbell/testbench": "^5.2", + "php-http/guzzle6-adapter": "^2.0" + }, "autoload": { "psr-4": { "Unicodeveloper\\Paystack\\": "src/" diff --git a/src/Http/ClientBuilder.php b/src/Http/ClientBuilder.php new file mode 100644 index 0000000..e992bbb --- /dev/null +++ b/src/Http/ClientBuilder.php @@ -0,0 +1,12 @@ +getFactory(); + + $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123']); + + self::assertInstanceOf(Client::class, $client); + } + + + protected function getFactory() + { + return [new PaystackFactory()]; + } +} \ No newline at end of file diff --git a/tests/PaystackServiceProviderTest.php b/tests/PaystackServiceProviderTest.php new file mode 100644 index 0000000..baa72e3 --- /dev/null +++ b/tests/PaystackServiceProviderTest.php @@ -0,0 +1,21 @@ +assertIsInjectable(PaystackFactory::class); + } + + public function testIfPaystackManagerIsInjectable() + { + $this->assertIsInjectable(PaystackManager::class); + } +} \ No newline at end of file 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 757366b6d8bcbc3b6be25ef5035265bb8df1929f Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 17:23:46 +0100 Subject: [PATCH 08/39] Update packages and Test --- composer.json | 6 ++- src/Http/ClientBuilder.php | 35 +++++++++++++++++ src/PaystackFactory.php | 26 ++++++++++-- tests/GitHubFactoryTest.php | 29 -------------- tests/PaystackFactoryTest.php | 74 +++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 34 deletions(-) delete mode 100644 tests/GitHubFactoryTest.php create mode 100644 tests/PaystackFactoryTest.php diff --git a/composer.json b/composer.json index a25e482..5c256c4 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,16 @@ "require": { "php": "^7.1.3", "illuminate/support": "5.7.*", - "xeviant/paystack": "^0.0.21" + "xeviant/paystack": "^0.0.21", + "graham-campbell/cache-plugin": "^1.1" }, "require-dev": { "mockery/mockery": "^1.2", "phpunit/phpunit": "^7.0", "orchestra/testbench": "3.7.*", "graham-campbell/testbench": "^5.2", - "php-http/guzzle6-adapter": "^2.0" + "php-http/guzzle6-adapter": "^2.0", + "madewithlove/illuminate-psr-cache-bridge": "^1.0" }, "autoload": { "psr-4": { diff --git a/src/Http/ClientBuilder.php b/src/Http/ClientBuilder.php index e992bbb..0e0dd32 100644 --- a/src/Http/ClientBuilder.php +++ b/src/Http/ClientBuilder.php @@ -5,8 +5,43 @@ namespace Unicodeveloper\Paystack\Http; +use GrahamCampbell\CachePlugin\CachePlugin; +use Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator; +use Psr\Cache\CacheItemPoolInterface; use Xeviant\Paystack\HttpClient\Builder; class ClientBuilder extends Builder { + public function addCache(CacheItemPoolInterface $cacheItemPool, array $config = []) + { + $this->setCachePlugin($cacheItemPool, $config['generator'] ?? null, $config['lifetime'] ?? null); + + $this->setPropertyValue('httpClientModified', true); + } + + protected function setCachePlugin(CacheItemPoolInterface $cacheItemPool, CacheKeyGenerator $generator = null, int $lifetime = null): void + { + $stream = $this->getPropertyValue('streamFactory'); + + $this->setPropertyValue('cachePlugin', new CachePlugin($cacheItemPool, $stream, $generator, $lifetime)); + } + + protected function getPropertyValue(string $name) + { + return static::getProperty($name)->getValue($this); + } + + protected function setPropertyValue(string $name, $value) + { + return static::getProperty($name)->setValue($this, $value); + } + + protected static function getProperty(string $name) + { + $prop = (new \ReflectionClass(Builder::class))->getProperty($name); + + $prop->setAccessible(true); + + return $prop; + } } \ No newline at end of file diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index adf2a9a..f5dafe6 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -6,20 +6,40 @@ namespace Unicodeveloper\Paystack; +use Illuminate\Contracts\Cache\Factory; +use Madewithlove\IlluminatePsrCacheBridge\Laravel\CacheItemPool; use Unicodeveloper\Paystack\Http\ClientBuilder; use Xeviant\Paystack\Client; class PaystackFactory { + /** + * Laravel Cache Instance + * + * @var Factory + */ + private $cache; + + public function __construct(Factory $cache = null) + { + $this->cache = $cache; + } + public function make(array $config) { - $client = new Client(); + $client = new Client($this->getBuilder(), 'v1'); return $client; } - protected function getBuilder() + protected function getBuilder($config) { - return new ClientBuilder(); + $builder = new ClientBuilder(); + + if ($this->cache && class_exists(CacheItemPool::class) && $cache = array_get($config, 'cache')) { + $builder->addCache(new CacheItemPool($this->cache->store( $cache === true ? null : $cache))); + } + + return $builder; } } \ No newline at end of file diff --git a/tests/GitHubFactoryTest.php b/tests/GitHubFactoryTest.php deleted file mode 100644 index b1d6e9c..0000000 --- a/tests/GitHubFactoryTest.php +++ /dev/null @@ -1,29 +0,0 @@ -getFactory(); - - $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123']); - - self::assertInstanceOf(Client::class, $client); - } - - - protected function getFactory() - { - return [new PaystackFactory()]; - } -} \ No newline at end of file diff --git a/tests/PaystackFactoryTest.php b/tests/PaystackFactoryTest.php new file mode 100644 index 0000000..0aef91b --- /dev/null +++ b/tests/PaystackFactoryTest.php @@ -0,0 +1,74 @@ +getFactory(); + + $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123']); + + self::assertInstanceOf(Client::class, $client); + } + + public function testMakeWithCache() + { + $factory = $this->getFactory(); + + $factory[1]->shouldRecieve('store')->once()->with(null)->andReturn(Mockery::mock(Repository::class)); + + $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123']); + + $this->assertInstanceOf(Client::class, $client); + } + + public function testMakeWithApiUrl() + { + $factory = $this->getFactory(); + + $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123', 'apiUrl' => 'https://api.example.co']); + + $this->assertInstanceOf(Client::class, $client); + } + + public function testMakeWithApiVersion() + { + $factory = $this->getFactory(); + + $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123', 'apiVersion' => 'v2']); + + $this->assertInstanceOf(Client::class, $client); + } + + /** + * + */ + public function testMakeShouldFailIfKeysAreNotSet() + { + $this->expectException(InvalidArgumentException::class); + $factory = $this->getFactory(); + + $factory[0]->make([]); + } + + + protected function getFactory() + { + $cache = Mockery::mock(Factory::class); + return [new PaystackFactory(), $cache]; + } +} \ No newline at end of file From 7fafff3d3c770e66e3edcef861362c58ab8db193 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 17:33:57 +0100 Subject: [PATCH 09/39] Fix TEsts --- src/PaystackFactory.php | 7 ++++++- tests/PaystackFactoryTest.php | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index f5dafe6..ab20523 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -10,6 +10,7 @@ use Madewithlove\IlluminatePsrCacheBridge\Laravel\CacheItemPool; use Unicodeveloper\Paystack\Http\ClientBuilder; use Xeviant\Paystack\Client; +use Xeviant\Paystack\Exception\InvalidArgumentException; class PaystackFactory { @@ -27,7 +28,11 @@ public function __construct(Factory $cache = null) public function make(array $config) { - $client = new Client($this->getBuilder(), 'v1'); + if (empty($config)) { + throw new InvalidArgumentException('You cannot use the Paystack Factory without a SECRET and PUBLIC key'); + } + + $client = new Client($this->getBuilder($config), 'v1'); return $client; } diff --git a/tests/PaystackFactoryTest.php b/tests/PaystackFactoryTest.php index 0aef91b..74c7beb 100644 --- a/tests/PaystackFactoryTest.php +++ b/tests/PaystackFactoryTest.php @@ -29,9 +29,9 @@ public function testMakeWithCache() { $factory = $this->getFactory(); - $factory[1]->shouldRecieve('store')->once()->with(null)->andReturn(Mockery::mock(Repository::class)); + $factory[1]->shouldReceive('store')->once()->with(null)->andReturn(Mockery::mock(Repository::class)); - $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123']); + $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123', 'cache' => true]); $this->assertInstanceOf(Client::class, $client); } @@ -69,6 +69,6 @@ public function testMakeShouldFailIfKeysAreNotSet() protected function getFactory() { $cache = Mockery::mock(Factory::class); - return [new PaystackFactory(), $cache]; + return [new PaystackFactory($cache), $cache]; } } \ No newline at end of file From a883a4cd4bc79ed8c9806c2302823ec359182c53 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 19:18:44 +0100 Subject: [PATCH 10/39] Add Abstractmanager package --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5c256c4..20e2160 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "php": "^7.1.3", "illuminate/support": "5.7.*", "xeviant/paystack": "^0.0.21", - "graham-campbell/cache-plugin": "^1.1" + "graham-campbell/cache-plugin": "^1.1", + "graham-campbell/manager": "^4.2" }, "require-dev": { "mockery/mockery": "^1.2", From 2e65439d7fc6cee6fc7064c8576ac15118ee61db Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 19:19:23 +0100 Subject: [PATCH 11/39] Update paystac.php config to use connections --- resources/config/paystack.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/config/paystack.php b/resources/config/paystack.php index e6d0d29..272e383 100644 --- a/resources/config/paystack.php +++ b/resources/config/paystack.php @@ -1,5 +1,7 @@ 'main', + + 'connections' => [ + 'main' => [ + + ] + ], /** * Public Key From Paystack Dashboard * From 86cbe976338e5706ccebe091e4df89f630bf9091 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 19:20:21 +0100 Subject: [PATCH 12/39] Add Tests for PaystackServiceProvider and Updated the Provider --- src/PaystackServiceProvider.php | 75 +++++++++++++++++++++++++-- tests/PaystackServiceProviderTest.php | 13 +++++ 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/PaystackServiceProvider.php b/src/PaystackServiceProvider.php index 2352295..72f8167 100644 --- a/src/PaystackServiceProvider.php +++ b/src/PaystackServiceProvider.php @@ -13,7 +13,12 @@ namespace Unicodeveloper\Paystack; +use function Clue\StreamFilter\fun; +use Illuminate\Container\Container; +use Illuminate\Foundation\Application as LaravelApp; use Illuminate\Support\ServiceProvider; +use Xeviant\Paystack\Client; +use Laravel\Lumen\Application as LumenApp; class PaystackServiceProvider extends ServiceProvider { @@ -30,11 +35,22 @@ class PaystackServiceProvider extends ServiceProvider */ public function boot() { - $config = realpath(__DIR__.'/../resources/config/paystack.php'); + $this->setupConfig(); + } + + protected function setupConfig() + { + $config = realpath($raw = __DIR__.'/../resources/config/paystack.php') ?: $raw; + + if ($this->app instanceof LaravelApp && $this->app->runningInConsole()) { + $this->publishes([ + $config => config_path('paystack.php') + ]); + } elseif ($this->app instanceof LumenApp) { + $this->app->configure('paystack'); + } - $this->publishes([ - $config => config_path('paystack.php') - ]); + $this->mergeConfigFrom($config, 'paystack'); } /** @@ -47,6 +63,50 @@ public function register() return new Paystack; }); + + $this->registerPaystackFactory() + ->registerPaystackManager() + ->registerCoreBindings(); + } + + protected function registerPaystackFactory() + { + $this->app->singleton('paystack.factory', function (Container $container) { + $cache = $container['cache']; + + return new PaystackFactory($cache); + }); + + $this->app->alias('paystack.factory', PaystackFactory::class); + + return $this; + } + + protected function registerPaystackManager() + { + $this->app->singleton('paystack', function (Container $container) { + $config = $container['config']; + $factory = $container['paystack.factory']; + + return new PaystackManager($config, $factory); + }); + + $this->app->alias('paystack', PaystackManager::class); + + return $this; + } + + protected function registerCoreBindings() + { + $this->app->bind('paystack.connection', function (Container $container) { + $manager = $container['paystack']; + + return $manager->connection(); + }); + + $this->app->alias('paystack.connection', Client::class); + + return $this; } /** @@ -55,6 +115,11 @@ public function register() */ public function provides() { - return ['laravel-paystack']; + return [ + 'paystack', + 'paystack.factory', + 'laravel-paystack', + 'paystack.connection', + ]; } } diff --git a/tests/PaystackServiceProviderTest.php b/tests/PaystackServiceProviderTest.php index baa72e3..b8289f0 100644 --- a/tests/PaystackServiceProviderTest.php +++ b/tests/PaystackServiceProviderTest.php @@ -6,6 +6,7 @@ use Unicodeveloper\Paystack\PaystackFactory; use Unicodeveloper\Paystack\PaystackManager; +use Xeviant\Paystack\Client; class PaystackServiceProviderTest extends AbstractTestCase { @@ -18,4 +19,16 @@ public function testIfPaystackManagerIsInjectable() { $this->assertIsInjectable(PaystackManager::class); } + + public function testBindings() + { + $this->assertIsInjectable(Client::class); + + $original = $this->app['paystack.connection']; + $this->app['paystack']->reconnect(); + $new = $this->app['paystack.connection']; + + $this->assertNotSame($original, $new); + $this->assertEquals($original, $new); + } } \ No newline at end of file From 4c4161ee100f7935aa8e446e731d572687f10faf Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 19:20:46 +0100 Subject: [PATCH 13/39] Update Paystack manager --- src/PaystackManager.php | 61 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/PaystackManager.php b/src/PaystackManager.php index 0a05a31..c1c894a 100644 --- a/src/PaystackManager.php +++ b/src/PaystackManager.php @@ -5,8 +5,67 @@ namespace Unicodeveloper\Paystack; +/** + * @method \Xeviant\Paystack\Api\Customers customers() + * @method \Xeviant\Paystack\Api\Balance balance() + * @method \Xeviant\Paystack\Api\Bank bank() + * @method \Xeviant\Paystack\Api\BulkCharges bulkCharges() + * @method \Xeviant\Paystack\Api\Bvn bvn() + * @method \Xeviant\Paystack\Api\Charge charge() + * @method \Xeviant\Paystack\Api\Integration integration() + * @method \Xeviant\Paystack\Api\Invoices invoices() + * @method \Xeviant\Paystack\Api\Pages pages() + * @method \Xeviant\Paystack\Api\Plans plans() + * @method \Xeviant\Paystack\Api\Refund refund() + * @method \Xeviant\Paystack\Api\Settlements settlements() + * @method \Xeviant\Paystack\Api\SubAccount subAccount() + * @method \Xeviant\Paystack\Api\Subscriptions subscriptions() + * @method \Xeviant\Paystack\Api\Transactions transactions() + * @method \Xeviant\Paystack\Api\TransferRecipients transferRecipients() + * @method \Xeviant\Paystack\Api\Transfers transfers() + */ -class PaystackManager + +use GrahamCampbell\Manager\AbstractManager; +use Illuminate\Config\Repository; + +class PaystackManager extends AbstractManager { + /** + * @var PaystackFactory + */ + private $factory; + + public function __construct(Repository $repository, PaystackFactory $factory) + { + parent::__construct($repository); + $this->factory = $factory; + } + + /** + * Create the connection instance. + * + * @param array $config + * + * @return \Xeviant\Paystack\Client + */ + protected function createConnection(array $config) + { + return $this->factory->make($config); + } + + /** + * Get the configuration name. + * + * @return string + */ + protected function getConfigName() + { + return 'paystack'; + } + public function getFactory() + { + return $this->factory; + } } \ No newline at end of file From e43c95cd4303fe26225c06c4fbd873dd5dd36db8 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 19:21:09 +0100 Subject: [PATCH 14/39] Update Test for PaystackManager --- tests/PaystackManagerTest.php | 52 +++++++++++++++++++++++++++++++++++ tests/PaystackTest.php | 4 --- 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 tests/PaystackManagerTest.php diff --git a/tests/PaystackManagerTest.php b/tests/PaystackManagerTest.php new file mode 100644 index 0000000..f532a4f --- /dev/null +++ b/tests/PaystackManagerTest.php @@ -0,0 +1,52 @@ + 'sk_123abc', 'public_key' => 'pk_123abc']; + + $manager = $this->getManager($config); + + $manager->getConfig()->shouldReceive('get')->once() + ->with('paystack.default')->andReturn('main'); + + $this->assertSame([], $manager->getConnections()); + + $return = $manager->connection(); + + $this->assertInstanceOf(Client::class, $return); + + $this->assertArrayHasKey('main', $manager->getConnections()); + } + + protected function getManager(array $config) + { + $repo = Mockery::mock(Repository::class); + $factory = Mockery::mock(PaystackFactory::class); + + + $manager = new PaystackManager($repo, $factory); + + $manager->getConfig()->shouldReceive('get')->once() + ->with('paystack.connections')->andReturn(['main' => $config]); + + $config['name'] = 'main'; + + $manager->getFactory()->shouldReceive('make')->once() + ->with($config)->andReturn(Mockery::mock(Client::class)); + + return $manager; + } +} \ No newline at end of file diff --git a/tests/PaystackTest.php b/tests/PaystackTest.php index 4f21321..31f3341 100644 --- a/tests/PaystackTest.php +++ b/tests/PaystackTest.php @@ -12,11 +12,7 @@ namespace Unicodeveloper\Paystack\Test; use Mockery as m; -use GuzzleHttp\Client; use PHPUnit\Framework\TestCase; -use Unicodeveloper\Paystack\Paystack; -use Illuminate\Support\Facades\Config; -use Illuminate\Support\Facades\Facade as Facade; class PaystackTest extends TestCase { From 03a6e5f8adc97acd5ce15c6a557c179468fb1d47 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 20:38:39 +0100 Subject: [PATCH 15/39] Update Test for PaystackManager --- .gitignore | 3 +-- phpunit.xml.dist | 14 +++++++------- src/Facades/Paystack.php | 2 ++ src/PaystackServiceProvider.php | 1 - tests/PaystackTest.php | 2 ++ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 3639a25..08a1747 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ build vendor .DS_Store composer.lock -.idea -bpaystack \ No newline at end of file +.idea \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index eaa1336..9866227 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,11 +19,11 @@ src/ - - - - - - - + + + + + + + diff --git a/src/Facades/Paystack.php b/src/Facades/Paystack.php index 8805f92..fb9eccf 100644 --- a/src/Facades/Paystack.php +++ b/src/Facades/Paystack.php @@ -1,5 +1,7 @@ Date: Mon, 18 Feb 2019 20:53:58 +0100 Subject: [PATCH 16/39] Add a new Facade Accessor --- src/Facades/Pstk.php | 28 ++++++++++++++++++++++++++++ src/Paystack.php | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 src/Facades/Pstk.php diff --git a/src/Facades/Pstk.php b/src/Facades/Pstk.php new file mode 100644 index 0000000..9c46bb5 --- /dev/null +++ b/src/Facades/Pstk.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Unicodeveloper\Paystack\Facades; + +use Illuminate\Support\Facades\Facade; + +class Pstk extends Facade +{ + /** + * Get the registered name of the component + * @return string + */ + protected static function getFacadeAccessor() + { + return 'paystack'; + } +} diff --git a/src/Paystack.php b/src/Paystack.php index 4ce90e1..5f18ee8 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -1,5 +1,7 @@ Date: Mon, 18 Feb 2019 21:01:03 +0100 Subject: [PATCH 17/39] Add a new Facade Accessor --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 20e2160..0fe04ad 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "email": "info@devfunsho.com" } ], - "minimum-stability": "stable", + "minimum-stability": "dev", + "prefer-stable": true, "require": { "php": "^7.1.3", "illuminate/support": "5.7.*", From 0853d8621ef55a772ab7deaf4c54efdbf8b0714f Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 21:36:41 +0100 Subject: [PATCH 18/39] Add a new Facade Accessor --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0fe04ad..8d6c080 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "illuminate/support": "5.7.*", - "xeviant/paystack": "^0.0.21", + "xeviant/paystack": "^0.0.22", "graham-campbell/cache-plugin": "^1.1", "graham-campbell/manager": "^4.2" }, From 9521f827bc2a8cb6d4e2f40434b1e2ae68268d0f Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 21:45:57 +0100 Subject: [PATCH 19/39] Add a new Facade Accessor --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8d6c080..88ed22a 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "illuminate/support": "5.7.*", - "xeviant/paystack": "^0.0.22", + "xeviant/paystack": "^0.0.23", "graham-campbell/cache-plugin": "^1.1", "graham-campbell/manager": "^4.2" }, From 11813ff1976e37250476119988db9fec4c135074 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 23:27:52 +0100 Subject: [PATCH 20/39] Fix Config Issue --- resources/config/paystack.php | 31 +++++++++++++++++++------------ src/PaystackFactory.php | 21 +++++++++++++++++---- tests/PaystackFactoryTest.php | 8 ++++---- tests/PaystackManagerTest.php | 2 +- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/resources/config/paystack.php b/resources/config/paystack.php index 272e383..599ce82 100644 --- a/resources/config/paystack.php +++ b/resources/config/paystack.php @@ -12,36 +12,43 @@ */ return [ - - 'default' => 'main', - - 'connections' => [ - 'main' => [ - - ] - ], /** * Public Key From Paystack Dashboard * */ - 'publicKey' => getenv('PAYSTACK_PUBLIC_KEY'), + 'publicKey' => $publicKey = env('PAYSTACK_PUBLIC_KEY', 'publicKey'), /** * Secret Key From Paystack Dashboard * */ - 'secretKey' => getenv('PAYSTACK_SECRET_KEY'), + 'secretKey' => $secretKey = env('PAYSTACK_SECRET_KEY', 'secretKey'), /** * Paystack Payment URL * */ - 'paymentUrl' => getenv('PAYSTACK_PAYMENT_URL'), + 'paymentUrl' => $paymentUrl = env('PAYSTACK_PAYMENT_URL'), /** * Optional email address of the merchant * */ - 'merchantEmail' => getenv('MERCHANT_EMAIL'), + 'merchantEmail' => $merchantEmail = env('MERCHANT_EMAIL'), + + 'default' => 'main', + 'connections' => [ + 'main' => [ + 'publicKey' => $publicKey, + 'secretKey' => $secretKey, + 'paymentUrl' => $paymentUrl + ], + + 'alternative' => [ + 'publicKey' => $publicKey, + 'secretKey' => $secretKey, + 'paymentUrl' => $paymentUrl + ] + ], ]; diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index ab20523..8116ca0 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -10,6 +10,7 @@ use Madewithlove\IlluminatePsrCacheBridge\Laravel\CacheItemPool; use Unicodeveloper\Paystack\Http\ClientBuilder; use Xeviant\Paystack\Client; +use Xeviant\Paystack\Config; use Xeviant\Paystack\Exception\InvalidArgumentException; class PaystackFactory @@ -28,15 +29,27 @@ public function __construct(Factory $cache = null) public function make(array $config) { - if (empty($config)) { - throw new InvalidArgumentException('You cannot use the Paystack Factory without a SECRET and PUBLIC key'); + if ($this->secretKeyDoesNotExist($config)) { + throw new InvalidArgumentException('You cannot use the Paystack Factory without a SECRET key, go into "paystack.php" to set one.'); } - $client = new Client($this->getBuilder($config), 'v1'); + $compatibleConfig = $this->createCompatibleConfiguration($config); + + $client = new Client($this->getBuilder($config), 'v1', $compatibleConfig); return $client; } + protected function secretKeyDoesNotExist(array $config) + { + return !array_key_exists('secretKey', $config) || (isset($config['secretKey']) && empty($config['secretKey'])); + } + + public function createCompatibleConfiguration(array $config) + { + return new Config(null, $config['publicKey'] ?: null, $config['secretKey'] ?: null, 'v1'); + } + protected function getBuilder($config) { $builder = new ClientBuilder(); @@ -47,4 +60,4 @@ protected function getBuilder($config) return $builder; } -} \ No newline at end of file +} diff --git a/tests/PaystackFactoryTest.php b/tests/PaystackFactoryTest.php index 74c7beb..015fe03 100644 --- a/tests/PaystackFactoryTest.php +++ b/tests/PaystackFactoryTest.php @@ -20,7 +20,7 @@ public function testIfFactoryCanBeCreatedWithMake() { $factory = $this->getFactory(); - $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123']); + $client = $factory[0]->make(['secretKey' => 'sk_123', 'publicKey' => 'pk_123']); self::assertInstanceOf(Client::class, $client); } @@ -31,7 +31,7 @@ public function testMakeWithCache() $factory[1]->shouldReceive('store')->once()->with(null)->andReturn(Mockery::mock(Repository::class)); - $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123', 'cache' => true]); + $client = $factory[0]->make(['secretKey' => 'sk_123', 'publicKey' => 'pk_123', 'cache' => true]); $this->assertInstanceOf(Client::class, $client); } @@ -40,7 +40,7 @@ public function testMakeWithApiUrl() { $factory = $this->getFactory(); - $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123', 'apiUrl' => 'https://api.example.co']); + $client = $factory[0]->make(['secretKey' => 'sk_123', 'publicKey' => 'pk_123', 'paymentUrl' => 'https://api.example.co']); $this->assertInstanceOf(Client::class, $client); } @@ -49,7 +49,7 @@ public function testMakeWithApiVersion() { $factory = $this->getFactory(); - $client = $factory[0]->make(['secret' => 'sk_123', 'public' => 'pk_123', 'apiVersion' => 'v2']); + $client = $factory[0]->make(['secretKey' => 'sk_123', 'publicKey' => 'pk_123', 'apiVersion' => 'v2']); $this->assertInstanceOf(Client::class, $client); } diff --git a/tests/PaystackManagerTest.php b/tests/PaystackManagerTest.php index f532a4f..98377bb 100644 --- a/tests/PaystackManagerTest.php +++ b/tests/PaystackManagerTest.php @@ -15,7 +15,7 @@ class PaystackManagerTest extends AbstractTestCase { public function testCreateConnection() { - $config = ['secret_key' => 'sk_123abc', 'public_key' => 'pk_123abc']; + $config = ['secretKey' => 'sk_123abc', 'publicKey' => 'pk_123abc']; $manager = $this->getManager($config); From d8136bdbb096d00d01ce7e0c68d7f61af1df09b4 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 23:37:54 +0100 Subject: [PATCH 21/39] Update paystack.php --- resources/config/paystack.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/config/paystack.php b/resources/config/paystack.php index 599ce82..88c2ee4 100644 --- a/resources/config/paystack.php +++ b/resources/config/paystack.php @@ -40,15 +40,15 @@ 'connections' => [ 'main' => [ - 'publicKey' => $publicKey, - 'secretKey' => $secretKey, - 'paymentUrl' => $paymentUrl + 'publicKey' => $publicKey, + 'secretKey' => $secretKey, + 'paymentUrl' => $paymentUrl ], 'alternative' => [ - 'publicKey' => $publicKey, - 'secretKey' => $secretKey, - 'paymentUrl' => $paymentUrl + 'publicKey' => $publicKey, + 'secretKey' => $secretKey, + 'paymentUrl' => $paymentUrl ] ], ]; From d8ec725f76e4516c96682ea67743cf70004a3fbe Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Mon, 18 Feb 2019 23:54:54 +0100 Subject: [PATCH 22/39] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 88ed22a..3cd9efd 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "illuminate/support": "5.7.*", - "xeviant/paystack": "^0.0.23", + "xeviant/paystack": "^0.0.24", "graham-campbell/cache-plugin": "^1.1", "graham-campbell/manager": "^4.2" }, From 4cbc37cf14eeb05e37583cde986c33b2279bef31 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 19 Feb 2019 00:49:54 +0100 Subject: [PATCH 23/39] Update Manager to search legacy methods --- src/Paystack.php | 41 +++++++++++++++++++++-------------------- src/PaystackManager.php | 19 +++++++++++++++++-- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index 5f18ee8..16b191b 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -65,6 +65,7 @@ public function __construct() $this->setKey(); $this->setBaseUrl(); $this->setRequestOptions(); + $this->paystack = app()->make('paystack.connection'); } /** @@ -102,11 +103,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 */ @@ -132,7 +133,7 @@ public function makePaymentRequest( $data = null) * . * . * ] - * + * * ] */ 'metadata' => request()->metadata @@ -181,10 +182,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 */ @@ -590,15 +591,15 @@ public function updatePage($page_id) return $this->setHttpResponse(Endpoint::UPDATE_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(){ $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, @@ -614,7 +615,7 @@ public function createSubAccount(){ } - /** + /** * Fetches details of a subaccount * @param subaccount code * @return array @@ -626,28 +627,28 @@ public function fetchSubAccount($subaccount_code){ } - /** + /** * 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(Endpoint::LIST_SUB_ACCOUNT . (int) $per_page."&page=".(int) $page,"GET")->getResponse(); + return $this->paystack->subAccount()->list(['perPage' => $per_page, '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, @@ -663,4 +664,4 @@ public function updateSubAccount($subaccount_code){ return $this->setHttpResponse(Endpoint::UPDATE_SUB_ACCOUNT . "{$subaccount_code}", "PUT", array_filter($data))->getResponse(); } -} +} \ No newline at end of file diff --git a/src/PaystackManager.php b/src/PaystackManager.php index c1c894a..cbae059 100644 --- a/src/PaystackManager.php +++ b/src/PaystackManager.php @@ -2,7 +2,6 @@ declare(strict_types=1); - namespace Unicodeveloper\Paystack; /** @@ -68,4 +67,20 @@ public function getFactory() { return $this->factory; } -} \ No newline at end of file + + public function __call(string $method, array $parameters) + { + $legacyObject = $this->getLegacyObject(); + + if (method_exists($legacyObject, $method)) { + return $legacyObject->{$method}(...$parameters); + } + + return parent::__call($method, $parameters); + } + + protected function getLegacyObject() + { + return new Paystack; + } +} From 5757086f657372fe5a04bbe9faa86ff2307a593b Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 19 Feb 2019 01:33:36 +0100 Subject: [PATCH 24/39] Refactored Paystack Class --- src/Paystack.php | 237 ++++++++++++++--------------------------------- 1 file changed, 68 insertions(+), 169 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index 16b191b..821a070 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -23,12 +23,12 @@ class Paystack /** * Transaction Verification Successful */ - const VS = 'Verification successful'; + const VERIFICATION_SUCCESSFUL = 'Verification successful'; /** * Invalid Transaction reference */ - const ITF = "Invalid transaction reference"; + const INVALID_TRANSACTION_REFERENCE = "Invalid transaction reference"; /** * Issue Secret Key from your Paystack Dashboard @@ -60,59 +60,25 @@ class Paystack */ protected $authorizationUrl; - public function __construct() - { - $this->setKey(); - $this->setBaseUrl(); - $this->setRequestOptions(); - $this->paystack = app()->make('paystack.connection'); - } - - /** - * Get Base Url from Paystack config file - */ - public function setBaseUrl() - { - $this->baseUrl = Config::get('paystack.paymentUrl'); - } - /** - * Get secret key from Paystack config file + * @var \Xeviant\Paystack\Client */ - public function setKey() - { - $this->secretKey = Config::get('paystack.secretKey'); - } + private $paystack; - /** - * Set options for making the Client request - */ - private function setRequestOptions() + public function __construct() { - $authBearer = 'Bearer '. $this->secretKey; - - $this->client = new Client( - [ - 'base_uri' => $this->baseUrl, - 'headers' => [ - 'Authorization' => $authBearer, - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - ] - ] - ); + $this->paystack = app()->make('paystack.connection'); } /** - * 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) + * @param null $data * @return Paystack */ - - public function makePaymentRequest( $data = null) + public function makePaymentRequest($data = null) { if ( $data == null ) { $data = [ @@ -143,29 +109,7 @@ public function makePaymentRequest( $data = null) array_filter($data); } - $this->setHttpResponse('/transaction/initialize', 'POST', $data); - - return $this; - } - - - /** - * @param string $relativeUrl - * @param string $method - * @param array $body - * @return Paystack - * @throws IsNullException - */ - private function setHttpResponse($relativeUrl, $method, $body = []) - { - if (is_null($method)) { - throw new IsNullException("Empty method not allowed"); - } - - $this->response = $this->client->{strtolower($method)}( - $this->baseUrl . $relativeUrl, - ["body" => json_encode($body)] - ); + $this->response = $this->paystack->transactions()->initialize($data); return $this; } @@ -187,6 +131,7 @@ public function getAuthorizationUrl() * 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 + * @param $data * @return array */ public function getAuthorizationResponse($data) @@ -205,9 +150,7 @@ private function verifyTransactionAtGateway() { $transactionRef = request()->query('trxref'); - $relativeUrl = Endpoint::VERIFY_TRANSACTION . "{$transactionRef}"; - - $this->response = $this->client->get($this->baseUrl . $relativeUrl, []); + $this->response = $this->paystack->transactions()->verify($transactionRef); } /** @@ -221,10 +164,10 @@ public function isTransactionVerificationValid() $result = $this->getResponse()['message']; switch ($result) { - case self::VS: + case self::VERIFICATION_SUCCESSFUL: $validate = true; break; - case self::ITF: + case self::INVALID_TRANSACTION_REFERENCE: $validate = false; break; default: @@ -281,9 +224,7 @@ public function genTranxRef() */ public function getAllCustomers() { - $this->setRequestOptions(); - - return $this->setHttpResponse(Endpoint::CUSTOMERS, 'GET', [])->getData(); + return $this->paystack->cutsomers()->list(); } /** @@ -292,9 +233,7 @@ public function getAllCustomers() */ public function getAllPlans() { - $this->setRequestOptions(); - - return $this->setHttpResponse(Endpoint::PLANS, 'GET', [])->getData(); + return $this->paystack->plans()->list(); } /** @@ -303,9 +242,7 @@ public function getAllPlans() */ public function getAllTransactions() { - $this->setRequestOptions(); - - return $this->setHttpResponse(Endpoint::TRANSACTIONS, 'GET', [])->getData(); + return $this->paystack->transactions()->list(); } /** @@ -314,16 +251,7 @@ public function getAllTransactions() */ private function getResponse() { - return json_decode($this->response->getBody(), true); - } - - /** - * Get the data response from a get operation - * @return array - */ - private function getData() - { - return $this->getResponse()['data']; + return $this->response; } /** @@ -341,29 +269,25 @@ public function createPlan() "currency" => request()->currency, ]; - $this->setRequestOptions(); - - $this->setHttpResponse(Endpoint::CREATE_PLAN, 'POST', $data); - + return $this->paystack->plans()->create($data); } /** * Fetch any plan based on its plan id or code - * @param $plan_code + * @param $planCode * @return array */ - public function fetchPlan($plan_code) + public function fetchPlan($planCode) { - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::FETCH_PLAN . $plan_code, 'GET', [])->getResponse(); + return $this->paystack->plans()->fetch($planCode); } /** * Update any plan's details based on its id or code - * @param $plan_code + * @param $planCode * @return array */ - public function updatePlan($plan_code) + public function updatePlan($planCode) { $data = [ "name" => request()->name, @@ -375,8 +299,7 @@ public function updatePlan($plan_code) "currency" => request()->currency, ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::UPDATE_PLAN . $plan_code, 'PUT', $data)->getResponse(); + return $this->paystack->plans()->update($planCode, $data); } /** @@ -393,27 +316,25 @@ public function createCustomer() ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::CREATE_CUSTOMER, 'POST', $data)->getResponse(); + return $this->paystack->customers()->create($data); } /** * Fetch a customer based on id or code - * @param $customer_id + * @param $customerId * @return array */ - public function fetchCustomer($customer_id) + public function fetchCustomer($customerId) { - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::FETCH_CUSTOMER . $customer_id, 'GET', [])->getResponse(); + return $this->paystack->customers()->fetch($customerId); } /** * Update a customer's details based on their id or code - * @param $customer_id + * @param $customerId * @return array */ - public function updateCustomer($customer_id) + public function updateCustomer($customerId) { $data = [ "email" => request()->email, @@ -424,8 +345,7 @@ public function updateCustomer($customer_id) ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::UPDATE_CUSTOMER . $customer_id, 'PUT', $data)->getResponse(); + return $this->paystack->customers()->update($customerId, $data); } /** @@ -440,8 +360,7 @@ public function exportTransactions() 'settled' => request()->settled ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::EXPORT_TRANSACTION, 'GET', $data)->getResponse(); + return $this->paystack->transactions()->export($data); } /** @@ -455,8 +374,7 @@ public function createSubscription() "authorization" => request()->authorization_code ]; - $this->setRequestOptions(); - $this->setHttpResponse(Endpoint::CREATE_SUBSCRIPTION, 'POST', $data); + return $this->paystack->subscriptions()->create($data); } /** @@ -466,35 +384,29 @@ public function createSubscription() */ public function getAllSubscriptions() { - $this->setRequestOptions(); - - return $this->setHttpResponse(Endpoint::GET_ALL_SUBSCRIPTIONS, 'GET', [])->getData(); + return $this->paystack->subscriptions()->list(); } /** * Get customer subscriptions * - * @param integer $customer_id + * @param integer $customerId * @return array */ - public function getCustomerSubscriptions($customer_id) + public function getCustomerSubscriptions($customerId) { - $this->setRequestOptions(); - - return $this->setHttpResponse(Endpoint::GET_CUSTOMER_SUBSCRIPTION . $customer_id, 'GET', [])->getData(); + return $this->paystack->subscriptions()->list(['customer' => $customerId]); } /** * Get plan subscriptions * - * @param integer $plan_id + * @param integer $planId * @return array */ - public function getPlanSubscriptions($plan_id) + public function getPlanSubscriptions($planId) { - $this->setRequestOptions(); - - return $this->setHttpResponse(Endpoint::GET_PLAN_SUBSCRIPTION . $plan_id, 'GET', [])->getData(); + return $this->paystack->subscriptions()->list(['plan' => $planId]); } /** @@ -508,8 +420,7 @@ public function enableSubscription() "token" => request()->token, ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::ENABLE_SUBSCRIPTION, 'POST', $data)->getResponse(); + return $this->paystack->subscrptions()->enable($data); } /** @@ -523,19 +434,17 @@ public function disableSubscription() "token" => request()->token, ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::DISABLE_SUBSCRIPTION, 'POST', $data)->getResponse(); + return $this->paystack->subscriptions()->disabled($data); } /** * Fetch details about a certain subscription - * @param mixed $subscription_id + * @param mixed $subscriptionId * @return array */ - public function fetchSubscription($subscription_id) + public function fetchSubscription($subscriptionId) { - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::FETCH_SUBSCRIPTION . $subscription_id, 'GET', [])->getResponse(); + return $this->paystack->subscriptions()->fetch($subscriptionId); } /** @@ -549,8 +458,7 @@ public function createPage() "amount" => request()->amount ]; - $this->setRequestOptions(); - $this->setHttpResponse(Endpoint::CREATE_PAGE, 'POST', $data); + return $this->paystack->pages()->create($data); } /** @@ -559,27 +467,25 @@ public function createPage() */ public function getAllPages() { - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::GET_ALL_PAGES, 'GET', [])->getResponse(); + return $this->paystack->pages()->list(); } /** * Fetch details about a certain page using its id or slug - * @param mixed $page_id + * @param mixed $pageId * @return array */ - public function fetchPage($page_id) + public function fetchPage($pageId) { - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::FETCH_PAGE . $page_id, 'GET', [])->getResponse(); + return $this->paystack->pages()->fetch($pageId); } /** * Update the details about a particular page - * @param $page_id + * @param $pageId * @return array */ - public function updatePage($page_id) + public function updatePage($pageId) { $data = [ "name" => request()->name, @@ -587,8 +493,7 @@ public function updatePage($page_id) "amount" => request()->amount ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::UPDATE_PAGE . $page_id, 'PUT', $data)->getResponse(); + return $this->paystack->pages()->update($pageId, $data); } /** @@ -597,7 +502,8 @@ public function updatePage($page_id) * @return array */ - public function createSubAccount(){ + public function createSubAccount() + { $data = [ "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, @@ -610,9 +516,7 @@ public function createSubAccount(){ 'settlement_schedule' => request()->settlement_schedule ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::CREATE_SUB_ACCOUNT, 'POST', array_filter($data))->getResponse(); - + return $this->paystack->subAccount()->create($data); } /** @@ -620,33 +524,30 @@ public function createSubAccount(){ * @param subaccount code * @return array */ - public function fetchSubAccount($subaccount_code){ - - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::FETCH_SUB_ACCOUNT . "{$subaccount_code}","GET",[])->getResponse(); - + public function fetchSubAccount($subAccountCode) + { + return $this->paystack->subAccount()->fetch($subAccountCode); } /** * 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 + * @param $perPage - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve + * @param $page * @return array */ - public function listSubAccounts($per_page, $page) { - - $this->setRequestOptions(); - - return $this->paystack->subAccount()->list(['perPage' => $per_page, 'page' => $page]); + public function listSubAccounts($perPage = null, $page = null) { + return $this->paystack->subAccount()->list(['perPage' => $perPage, '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 + * Updates a sub-account to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge + * @param sub-account code * @return array */ - public function updateSubAccount($subaccount_code){ + public function updateSubAccount($subAccountCode) + { $data = [ "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, @@ -660,8 +561,6 @@ public function updateSubAccount($subaccount_code){ 'settlement_schedule' => request()->settlement_schedule ]; - $this->setRequestOptions(); - return $this->setHttpResponse(Endpoint::UPDATE_SUB_ACCOUNT . "{$subaccount_code}", "PUT", array_filter($data))->getResponse(); - + return $this->paystack->subAccount()->update($subAccountCode, $data); } } \ No newline at end of file From 10414a66d41a11555b2de0e3f9294a562a1e5be4 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 19 Feb 2019 01:37:49 +0100 Subject: [PATCH 25/39] =?UTF-8?q?Refactored=20Paystack=20Class=20?= =?UTF-8?q?=F0=9F=98=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Paystack.php | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/Paystack.php b/src/Paystack.php index 821a070..ac453e1 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -14,8 +14,6 @@ namespace Unicodeveloper\Paystack; use GuzzleHttp\Client; -use Illuminate\Support\Facades\Config; -use Unicodeveloper\Paystack\Exceptions\IsNullException; use Unicodeveloper\Paystack\Exceptions\PaymentVerificationFailedException; class Paystack @@ -30,30 +28,12 @@ class Paystack */ const INVALID_TRANSACTION_REFERENCE = "Invalid transaction reference"; - /** - * Issue Secret Key from your Paystack Dashboard - * @var string - */ - protected $secretKey; - - /** - * Instance of Client - * @var Client - */ - protected $client; - /** * Response from requests made to Paystack - * @var mixed + * @var array */ protected $response; - /** - * Paystack API base Url - * @var string - */ - protected $baseUrl; - /** * Authorization Url - Paystack payment page * @var string @@ -65,6 +45,16 @@ class Paystack */ private $paystack; + /** + * Authorization URL + * + * @var string + */ + private $url; + + /** + * Paystack constructor. + */ public function __construct() { $this->paystack = app()->make('paystack.connection'); @@ -180,7 +170,7 @@ public function isTransactionVerificationValid() /** * Get Payment details if the transaction was verified successfully - * @return json + * @return array * @throws PaymentVerificationFailedException */ public function getPaymentData() @@ -535,7 +525,8 @@ public function fetchSubAccount($subAccountCode) * @param $page * @return array */ - public function listSubAccounts($perPage = null, $page = null) { + public function listSubAccounts($perPage = null, $page = null) + { return $this->paystack->subAccount()->list(['perPage' => $perPage, 'page' => $page]); } From 09ddf9057011275245f80e5dc75b70e113b6a832 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 19 Feb 2019 01:49:53 +0100 Subject: [PATCH 26/39] Update Facades --- src/Facades/Paystack.php | 2 +- src/Facades/{Pstk.php => PaystackV1.php} | 4 ++-- src/Paystack.php | 1 - tests/PaystackTest.php | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) rename src/Facades/{Pstk.php => PaystackV1.php} (88%) diff --git a/src/Facades/Paystack.php b/src/Facades/Paystack.php index fb9eccf..a3b4acf 100644 --- a/src/Facades/Paystack.php +++ b/src/Facades/Paystack.php @@ -23,6 +23,6 @@ class Paystack extends Facade */ protected static function getFacadeAccessor() { - return 'laravel-paystack'; + return 'paystack'; } } diff --git a/src/Facades/Pstk.php b/src/Facades/PaystackV1.php similarity index 88% rename from src/Facades/Pstk.php rename to src/Facades/PaystackV1.php index 9c46bb5..423e3dd 100644 --- a/src/Facades/Pstk.php +++ b/src/Facades/PaystackV1.php @@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Facade; -class Pstk extends Facade +class PaystackV1 extends Facade { /** * Get the registered name of the component @@ -23,6 +23,6 @@ class Pstk extends Facade */ protected static function getFacadeAccessor() { - return 'paystack'; + return 'laravel-paystack'; } } diff --git a/src/Paystack.php b/src/Paystack.php index ac453e1..4aeafc8 100644 --- a/src/Paystack.php +++ b/src/Paystack.php @@ -13,7 +13,6 @@ namespace Unicodeveloper\Paystack; -use GuzzleHttp\Client; use Unicodeveloper\Paystack\Exceptions\PaymentVerificationFailedException; class Paystack diff --git a/tests/PaystackTest.php b/tests/PaystackTest.php index 59365ad..a8a08b1 100644 --- a/tests/PaystackTest.php +++ b/tests/PaystackTest.php @@ -47,7 +47,7 @@ public function testAllTransactionsAreReturned() public function testAllPlansAreReturned() { - $array = $this->paystack->shouldReceive('getAllPlans')->andReturn(['intermediate-plan']); + $array = $this->paystack->shouldReceive('getAllPlans')->andReturn([]); $this->assertEquals('array', gettype(array($array))); } From 431149e64348e9df3bffe425627f97ace91465f3 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 19 Feb 2019 01:56:51 +0100 Subject: [PATCH 27/39] Add Tests for Facade --- src/PaystackServiceProvider.php | 2 -- tests/Facades/PaystackTest.php | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/Facades/PaystackTest.php diff --git a/src/PaystackServiceProvider.php b/src/PaystackServiceProvider.php index eedee2b..f726101 100644 --- a/src/PaystackServiceProvider.php +++ b/src/PaystackServiceProvider.php @@ -58,9 +58,7 @@ protected function setupConfig() public function register() { $this->app->bind('laravel-paystack', function () { - return new Paystack; - }); $this->registerPaystackFactory() diff --git a/tests/Facades/PaystackTest.php b/tests/Facades/PaystackTest.php new file mode 100644 index 0000000..96d7a34 --- /dev/null +++ b/tests/Facades/PaystackTest.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + +namespace Unicodeveloper\Paystack\Test\Facades; + +use GrahamCampbell\TestBenchCore\FacadeTrait; +use Unicodeveloper\Paystack\Facades\Paystack; +use Unicodeveloper\Paystack\PaystackManager; +use Unicodeveloper\Paystack\Test\AbstractTestCase; + +/** + * This is the github facade test class. + */ +class PaystackTest extends AbstractTestCase +{ + use FacadeTrait; + + /** + * Get the facade accessor. + * + * @return string + */ + protected function getFacadeAccessor() + { + return 'paystack'; + } + + /** + * Get the facade class. + * + * @return string + */ + protected function getFacadeClass() + { + return Paystack::class; + } + + /** + * Get the facade root. + * + * @return string + */ + protected function getFacadeRoot() + { + return PaystackManager::class; + } +} From 1cbcc7bdd0b645c62db4c5f3ab5fc9928b19111c Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 19 Feb 2019 02:28:45 +0100 Subject: [PATCH 28/39] Update Doc blocks --- resources/config/paystack.php | 18 ++++++++++------- src/Http/ClientBuilder.php | 36 +++++++++++++++++++++++++++++++++ src/PaystackFactory.php | 29 ++++++++++++++++++++++++++ src/PaystackManager.php | 19 +++++++++++++++++ src/PaystackServiceProvider.php | 18 +++++++++++++++++ 5 files changed, 113 insertions(+), 7 deletions(-) diff --git a/resources/config/paystack.php b/resources/config/paystack.php index 88c2ee4..c094f30 100644 --- a/resources/config/paystack.php +++ b/resources/config/paystack.php @@ -36,19 +36,23 @@ */ 'merchantEmail' => $merchantEmail = env('MERCHANT_EMAIL'), - 'default' => 'main', + 'default' => 'test', + /** + * Here you can specify different Paystack connection. + */ 'connections' => [ - 'main' => [ + 'test' => [ 'publicKey' => $publicKey, 'secretKey' => $secretKey, - 'paymentUrl' => $paymentUrl + 'paymentUrl' => $paymentUrl, + 'cache' => false, ], - - 'alternative' => [ + 'live' => [ 'publicKey' => $publicKey, 'secretKey' => $secretKey, - 'paymentUrl' => $paymentUrl - ] + 'paymentUrl' => $paymentUrl, + 'cache' => false, + ], ], ]; diff --git a/src/Http/ClientBuilder.php b/src/Http/ClientBuilder.php index 0e0dd32..b8031c9 100644 --- a/src/Http/ClientBuilder.php +++ b/src/Http/ClientBuilder.php @@ -12,6 +12,13 @@ class ClientBuilder extends Builder { + /** + * Adds Cache Plugin to builder + * + * @param CacheItemPoolInterface $cacheItemPool + * @param array $config + * @throws \ReflectionException + */ public function addCache(CacheItemPoolInterface $cacheItemPool, array $config = []) { $this->setCachePlugin($cacheItemPool, $config['generator'] ?? null, $config['lifetime'] ?? null); @@ -19,6 +26,14 @@ public function addCache(CacheItemPoolInterface $cacheItemPool, array $config = $this->setPropertyValue('httpClientModified', true); } + /** + * Add a cache plugin to cache responses locally. + * + * @param CacheItemPoolInterface $cacheItemPool + * @param CacheKeyGenerator|null $generator + * @param int|null $lifetime + * @throws \ReflectionException + */ protected function setCachePlugin(CacheItemPoolInterface $cacheItemPool, CacheKeyGenerator $generator = null, int $lifetime = null): void { $stream = $this->getPropertyValue('streamFactory'); @@ -26,16 +41,37 @@ protected function setCachePlugin(CacheItemPoolInterface $cacheItemPool, CacheKe $this->setPropertyValue('cachePlugin', new CachePlugin($cacheItemPool, $stream, $generator, $lifetime)); } + /** + * Retrieves the value of a builder property + * + * @param string $name + * @return mixed + * @throws \ReflectionException + */ protected function getPropertyValue(string $name) { return static::getProperty($name)->getValue($this); } + /** + * Sets the value of a builder property + * + * @param string $name + * @param $value + * @throws \ReflectionException + */ protected function setPropertyValue(string $name, $value) { return static::getProperty($name)->setValue($this, $value); } + /** + * Gets the builder reflection property for the given name + * + * @param string $name + * @return \ReflectionProperty + * @throws \ReflectionException + */ protected static function getProperty(string $name) { $prop = (new \ReflectionClass(Builder::class))->getProperty($name); diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index 8116ca0..d5959ac 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -22,11 +22,22 @@ class PaystackFactory */ private $cache; + /** + * PaystackFactory constructor. + * + * @param Factory|null $cache + */ public function __construct(Factory $cache = null) { $this->cache = $cache; } + /** + * Creates A Paystack Client Object + * + * @param array $config + * @return Client + */ public function make(array $config) { if ($this->secretKeyDoesNotExist($config)) { @@ -40,16 +51,34 @@ public function make(array $config) return $client; } + /** + * Check to see if Secret key doesn't exists + * + * @param array $config + * @return bool + */ protected function secretKeyDoesNotExist(array $config) { return !array_key_exists('secretKey', $config) || (isset($config['secretKey']) && empty($config['secretKey'])); } + /** + * Creates a Compatible Paystack Client Configuration from a configuration array + * + * @param array $config + * @return Config + */ public function createCompatibleConfiguration(array $config) { return new Config(null, $config['publicKey'] ?: null, $config['secretKey'] ?: null, 'v1'); } + /** + * Prepares and retrieves the Paystack client builder + * + * @param $config + * @return ClientBuilder + */ protected function getBuilder($config) { $builder = new ClientBuilder(); diff --git a/src/PaystackManager.php b/src/PaystackManager.php index cbae059..2a6a6d7 100644 --- a/src/PaystackManager.php +++ b/src/PaystackManager.php @@ -35,6 +35,12 @@ class PaystackManager extends AbstractManager */ private $factory; + /** + * PaystackManager constructor. + * + * @param Repository $repository + * @param PaystackFactory $factory + */ public function __construct(Repository $repository, PaystackFactory $factory) { parent::__construct($repository); @@ -63,11 +69,19 @@ protected function getConfigName() return 'paystack'; } + /** + * Gets the instance of the Paystack Factory + * + * @return PaystackFactory + */ public function getFactory() { return $this->factory; } + /** + * {@inheritdoc} + */ public function __call(string $method, array $parameters) { $legacyObject = $this->getLegacyObject(); @@ -79,6 +93,11 @@ public function __call(string $method, array $parameters) return parent::__call($method, $parameters); } + /** + * Gets the Legacy Paystack Object from v1 of this package + * + * @return Paystack + */ protected function getLegacyObject() { return new Paystack; diff --git a/src/PaystackServiceProvider.php b/src/PaystackServiceProvider.php index f726101..4d5b910 100644 --- a/src/PaystackServiceProvider.php +++ b/src/PaystackServiceProvider.php @@ -37,6 +37,9 @@ public function boot() $this->setupConfig(); } + /** + * Sets up Paystack configuration file + */ protected function setupConfig() { $config = realpath($raw = __DIR__.'/../resources/config/paystack.php') ?: $raw; @@ -66,6 +69,11 @@ public function register() ->registerCoreBindings(); } + /** + * Registers the Paystack factory + * + * @return $this + */ protected function registerPaystackFactory() { $this->app->singleton('paystack.factory', function (Container $container) { @@ -79,6 +87,11 @@ protected function registerPaystackFactory() return $this; } + /** + * Registers Paystack manager + * + * @return $this + */ protected function registerPaystackManager() { $this->app->singleton('paystack', function (Container $container) { @@ -93,6 +106,11 @@ protected function registerPaystackManager() return $this; } + /** + * Registers the Core Paystack Binding + * + * @return $this + */ protected function registerCoreBindings() { $this->app->bind('paystack.connection', function (Container $container) { From a140fa367f338e75e1b0f9d48859bce9197f5e82 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Tue, 19 Feb 2019 02:32:04 +0100 Subject: [PATCH 29/39] Update Doc blocks --- src/Http/ClientBuilder.php | 9 +++++++++ src/PaystackFactory.php | 8 ++++++++ src/PaystackManager.php | 9 +++++++++ tests/PaystackFactoryTest.php | 9 +++++++++ 4 files changed, 35 insertions(+) diff --git a/src/Http/ClientBuilder.php b/src/Http/ClientBuilder.php index b8031c9..9539df2 100644 --- a/src/Http/ClientBuilder.php +++ b/src/Http/ClientBuilder.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the Laravel Paystack package. + * + * (c) Prosper Otemuyiwa + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Unicodeveloper\Paystack\Http; diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index d5959ac..e5b591e 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -2,6 +2,14 @@ declare(strict_types=1); +/* + * This file is part of the Laravel Paystack package. + * + * (c) Prosper Otemuyiwa + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Unicodeveloper\Paystack; diff --git a/src/PaystackManager.php b/src/PaystackManager.php index 2a6a6d7..35aea53 100644 --- a/src/PaystackManager.php +++ b/src/PaystackManager.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the Laravel Paystack package. + * + * (c) Prosper Otemuyiwa + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Unicodeveloper\Paystack; /** diff --git a/tests/PaystackFactoryTest.php b/tests/PaystackFactoryTest.php index 015fe03..f858edb 100644 --- a/tests/PaystackFactoryTest.php +++ b/tests/PaystackFactoryTest.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the Laravel Paystack package. + * + * (c) Prosper Otemuyiwa + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Unicodeveloper\Paystack\Test; From 1978c3ae8206211e41c23a53fe6ed113a4e28776 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Wed, 20 Feb 2019 22:37:11 +0100 Subject: [PATCH 30/39] Update Travis config --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2185801..c9be028 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,7 @@ language: php php: - - 5.5 - - 5.6 - - 7.0 + - 7.1 - hhvm matrix: From 66264ab4b0f4629cb65702001aa841c0c5cd7d6e Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Wed, 20 Feb 2019 23:08:21 +0100 Subject: [PATCH 31/39] Update README.md --- README.md | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cbc84f1..060357e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Installation -[PHP](https://php.net) 5.4+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org) are required. +[PHP](https://php.net) 7.1+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org) are required. To get the latest version of Laravel Paystack, simply require it @@ -57,32 +57,61 @@ A configuration-file named `paystack.php` with some sensible defaults will be pl ```php + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +return [ /** * Public Key From Paystack Dashboard * */ - 'publicKey' => getenv('PAYSTACK_PUBLIC_KEY'), + 'publicKey' => $publicKey = env('PAYSTACK_PUBLIC_KEY', 'publicKey'), /** * Secret Key From Paystack Dashboard * */ - 'secretKey' => getenv('PAYSTACK_SECRET_KEY'), + 'secretKey' => $secretKey = env('PAYSTACK_SECRET_KEY', 'secretKey'), /** * Paystack Payment URL * */ - 'paymentUrl' => getenv('PAYSTACK_PAYMENT_URL'), + 'paymentUrl' => $paymentUrl = env('PAYSTACK_PAYMENT_URL'), /** * Optional email address of the merchant * */ - 'merchantEmail' => getenv('MERCHANT_EMAIL'), + 'merchantEmail' => $merchantEmail = env('MERCHANT_EMAIL'), + 'default' => 'test', + + /** + * Here you can specify different Paystack connection. + */ + 'connections' => [ + 'test' => [ + 'publicKey' => $publicKey, + 'secretKey' => $secretKey, + 'paymentUrl' => $paymentUrl, + 'cache' => false, + ], + 'live' => [ + 'publicKey' => $publicKey, + 'secretKey' => $secretKey, + 'paymentUrl' => $paymentUrl, + 'cache' => false, + ], + ], ]; ``` From dcbba4bbfdab7aabf1cc735c78d50de2607b30b4 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Sat, 23 Feb 2019 21:15:17 +0100 Subject: [PATCH 32/39] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 060357e..ae59ebe 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,12 @@ class PaymentController extends Controller Let me explain the fluent methods this package provides a bit here. ```php +/** + * To use the Multi connection Feature you need to prefix your call like this otherwise + * the default connection will be used as specified in the paystack.php config file. + */ +Paystack::connection('live')->getAuthorizationUrl()->redirectNow(); + /** * 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 From 5b784d484080800931a3771496efa1071fec939b Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Thu, 14 Mar 2019 08:26:20 +0100 Subject: [PATCH 33/39] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3cd9efd..4a24d67 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "prefer-stable": true, "require": { "php": "^7.1.3", - "illuminate/support": "5.7.*", - "xeviant/paystack": "^0.0.24", + "illuminate/support": "^5.7", + "xeviant/paystack": "^0.0.25", "graham-campbell/cache-plugin": "^1.1", "graham-campbell/manager": "^4.2" }, From 9dac80f431025bfa2102b5302c7ffe36596a1ac8 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Thu, 14 Mar 2019 09:53:40 +0100 Subject: [PATCH 34/39] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4a24d67..a84f4fb 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "illuminate/support": "^5.7", - "xeviant/paystack": "^0.0.25", + "xeviant/paystack": "^0.0.26", "graham-campbell/cache-plugin": "^1.1", "graham-campbell/manager": "^4.2" }, From 10b8f7c9320702ac8f6f659fb3bcdffa6af05cd5 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Thu, 18 Apr 2019 19:58:47 +0100 Subject: [PATCH 35/39] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a84f4fb..bf70424 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "illuminate/support": "^5.7", - "xeviant/paystack": "^0.0.26", + "xeviant/paystack": "0.0.*", "graham-campbell/cache-plugin": "^1.1", "graham-campbell/manager": "^4.2" }, From 7caefdcd69fc4adeaf23066bb48648a15335dd31 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Thu, 18 Apr 2019 21:10:12 +0100 Subject: [PATCH 36/39] Add Event listener --- src/Event/EventHandler.php | 16 ++++++++++++++++ src/PaystackFactory.php | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 src/Event/EventHandler.php diff --git a/src/Event/EventHandler.php b/src/Event/EventHandler.php new file mode 100644 index 0000000..02776e5 --- /dev/null +++ b/src/Event/EventHandler.php @@ -0,0 +1,16 @@ +dispatch($event->getName(), $payload); + } +} diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index e5b591e..53f1fb4 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -14,8 +14,10 @@ namespace Unicodeveloper\Paystack; +use Closure; use Illuminate\Contracts\Cache\Factory; use Madewithlove\IlluminatePsrCacheBridge\Laravel\CacheItemPool; +use Unicodeveloper\Paystack\Event\EventHandler; use Unicodeveloper\Paystack\Http\ClientBuilder; use Xeviant\Paystack\Client; use Xeviant\Paystack\Config; @@ -56,6 +58,8 @@ public function make(array $config) $client = new Client($this->getBuilder($config), 'v1', $compatibleConfig); + $client->getEvent()->listen('*', Closure::fromCallable([new EventHandler, 'handle'])); + return $client; } From b46e480dd9ab731f84d9143e31b61ec0fa664b10 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Fri, 19 Apr 2019 05:49:13 +0100 Subject: [PATCH 37/39] Add Event listener --- src/PaystackFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index 53f1fb4..3eecd3d 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -58,6 +58,7 @@ public function make(array $config) $client = new Client($this->getBuilder($config), 'v1', $compatibleConfig); + // We register a Global Event listener $client->getEvent()->listen('*', Closure::fromCallable([new EventHandler, 'handle'])); return $client; From abcec558f204df3b6151b3e38acfba7d70e3f8d9 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Sat, 4 May 2019 15:41:07 +0100 Subject: [PATCH 38/39] Change paystack.php to config/paystack.php --- src/PaystackFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index 3eecd3d..de29edc 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -51,7 +51,7 @@ public function __construct(Factory $cache = null) public function make(array $config) { if ($this->secretKeyDoesNotExist($config)) { - throw new InvalidArgumentException('You cannot use the Paystack Factory without a SECRET key, go into "paystack.php" to set one.'); + throw new InvalidArgumentException('You cannot use the Paystack Factory without a SECRET key, go into "config/paystack.php" to set one.'); } $compatibleConfig = $this->createCompatibleConfiguration($config); From 0e70320796f8537491f14a0a00e4c995850f2d63 Mon Sep 17 00:00:00 2001 From: Olatunbosun Egberinde Date: Sat, 11 May 2019 21:21:34 +0100 Subject: [PATCH 39/39] Update Factory to use the Container --- composer.json | 4 ++-- src/PaystackFactory.php | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index bf70424..3e18663 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,9 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": "^7.1.3", + "php": "^7.1.3", "illuminate/support": "^5.7", - "xeviant/paystack": "0.0.*", + "xeviant/paystack": "dev-master", "graham-campbell/cache-plugin": "^1.1", "graham-campbell/manager": "^4.2" }, diff --git a/src/PaystackFactory.php b/src/PaystackFactory.php index de29edc..79c4eb1 100644 --- a/src/PaystackFactory.php +++ b/src/PaystackFactory.php @@ -19,9 +19,12 @@ use Madewithlove\IlluminatePsrCacheBridge\Laravel\CacheItemPool; use Unicodeveloper\Paystack\Event\EventHandler; use Unicodeveloper\Paystack\Http\ClientBuilder; +use Xeviant\Paystack\App\PaystackApplication; use Xeviant\Paystack\Client; use Xeviant\Paystack\Config; +use Xeviant\Paystack\Contract\Config as PaystackConfigContract; use Xeviant\Paystack\Exception\InvalidArgumentException; +use Xeviant\Paystack\HttpClient\Builder; class PaystackFactory { @@ -47,6 +50,8 @@ public function __construct(Factory $cache = null) * * @param array $config * @return Client + * @throws \ReflectionException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function make(array $config) { @@ -56,7 +61,12 @@ public function make(array $config) $compatibleConfig = $this->createCompatibleConfiguration($config); - $client = new Client($this->getBuilder($config), 'v1', $compatibleConfig); + $app = new PaystackApplication; + + $app->instance(Builder::class, $this->getBuilder($config)); + $app->instance(PaystackConfigContract::class, $compatibleConfig); + + $client = new Client($app); // We register a Global Event listener $client->getEvent()->listen('*', Closure::fromCallable([new EventHandler, 'handle'])); @@ -91,6 +101,7 @@ public function createCompatibleConfiguration(array $config) * * @param $config * @return ClientBuilder + * @throws \ReflectionException */ protected function getBuilder($config) {