From bd125027e89eb71676f00a24d0afd50538ff0c26 Mon Sep 17 00:00:00 2001 From: m4yankpomelo Date: Thu, 27 Jul 2023 14:10:24 +0800 Subject: [PATCH 1/4] Support multi tenant client --- src/Client.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2f0a639..867808d 100755 --- a/src/Client.php +++ b/src/Client.php @@ -11,8 +11,12 @@ class Client const API_VERSION = '2.0'; const APP_VERSION = 'pomelo-php-v2.1.2'; const SIGN_METHOD = 'sha1'; - const SANDBOX_ENDPOINT = 'https://api.dev.pomelopay.com/public/'; - const PRODUCTION_ENDPOINT = 'https://api.pomelopay.com/public/'; + const ENDPOINTS = [ + 'pomelopay' => ['sandbox'=> 'https://api.dev.pomelopay.com/public/', 'production' => 'https://api.pomelopay.com/public/'], + 'dialog' => ['sandbox'=> 'https://api.uat.geniebiz.lk/public/', 'production' => 'https://api.geniebiz.lk/public/'], + 'rabbit' => ['sandbox'=> 'https://api.uat.pgw.rabbit.co.th/public/', 'production' => 'https://api.pgw.rabbit.co.th/public/'], + 'bml' => ['sandbox'=> 'https://api.uat.merchants.bankofmaldives.com.mv/public/', 'production' => 'https://api.merchants.bankofmaldives.com.mv/public/'] + ]; /** * @var \GuzzleHttp\Client @@ -55,14 +59,15 @@ class Client * @param string $apiKey * @param string $appId * @param string $mode + * @param string $tenant * @param array $clientOptions */ - public function __construct(string $apiKey, string $appId, $mode = 'production', array $clientOptions = []) + public function __construct(string $apiKey, string $appId, $mode = 'production', $tenant = 'pomelopay', array $clientOptions = []) { $this->apiKey = $apiKey; $this->appId = $appId; $this->mode = $mode; - $this->baseUrl = ($mode === 'production' ? self::PRODUCTION_ENDPOINT : self::SANDBOX_ENDPOINT); + $this->baseUrl = ($mode === 'production' ? self::ENDPOINTS[$tenant][$mode] : self::SANDBOX_ENDPOINT[$tenant]['sandbox']); $this->clientOptions = $clientOptions; $this->initiateHttpClient(); From b897dadd18a236b99636db51eff58c5495a58190 Mon Sep 17 00:00:00 2001 From: m4yankpomelo Date: Thu, 27 Jul 2023 14:26:47 +0800 Subject: [PATCH 2/4] Fix --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 867808d..bb0c0ce 100755 --- a/src/Client.php +++ b/src/Client.php @@ -67,7 +67,7 @@ public function __construct(string $apiKey, string $appId, $mode = 'production', $this->apiKey = $apiKey; $this->appId = $appId; $this->mode = $mode; - $this->baseUrl = ($mode === 'production' ? self::ENDPOINTS[$tenant][$mode] : self::SANDBOX_ENDPOINT[$tenant]['sandbox']); + $this->baseUrl = ($mode === 'production' ? self::ENDPOINTS[$tenant][$mode] : self::ENDPOINTS[$tenant]['sandbox']); $this->clientOptions = $clientOptions; $this->initiateHttpClient(); From 2b285357376f8b75bfb3e8185958e4c424f7854a Mon Sep 17 00:00:00 2001 From: m4yankpomelo Date: Thu, 27 Jul 2023 14:33:12 +0800 Subject: [PATCH 3/4] Update to allow custom endpoint Update to allow custom endpoint --- src/Client.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Client.php b/src/Client.php index bb0c0ce..33e85ad 100755 --- a/src/Client.php +++ b/src/Client.php @@ -11,12 +11,8 @@ class Client const API_VERSION = '2.0'; const APP_VERSION = 'pomelo-php-v2.1.2'; const SIGN_METHOD = 'sha1'; - const ENDPOINTS = [ - 'pomelopay' => ['sandbox'=> 'https://api.dev.pomelopay.com/public/', 'production' => 'https://api.pomelopay.com/public/'], - 'dialog' => ['sandbox'=> 'https://api.uat.geniebiz.lk/public/', 'production' => 'https://api.geniebiz.lk/public/'], - 'rabbit' => ['sandbox'=> 'https://api.uat.pgw.rabbit.co.th/public/', 'production' => 'https://api.pgw.rabbit.co.th/public/'], - 'bml' => ['sandbox'=> 'https://api.uat.merchants.bankofmaldives.com.mv/public/', 'production' => 'https://api.merchants.bankofmaldives.com.mv/public/'] - ]; + const SANDBOX_ENDPOINT = 'https://api.dev.pomelopay.com/public/'; + const PRODUCTION_ENDPOINT = 'https://api.pomelopay.com/public/'; /** * @var \GuzzleHttp\Client @@ -59,15 +55,15 @@ class Client * @param string $apiKey * @param string $appId * @param string $mode - * @param string $tenant * @param array $clientOptions + * @param string $endpoint */ - public function __construct(string $apiKey, string $appId, $mode = 'production', $tenant = 'pomelopay', array $clientOptions = []) - { + public function __construct(string $apiKey, string $appId, $mode = 'production', array $clientOptions = [], $endpoint = '') + { $this->apiKey = $apiKey; $this->appId = $appId; $this->mode = $mode; - $this->baseUrl = ($mode === 'production' ? self::ENDPOINTS[$tenant][$mode] : self::ENDPOINTS[$tenant]['sandbox']); + $this->baseUrl = $endpoint === '' ? ($mode === 'production' ? self::PRODUCTION_ENDPOINT : self::SANDBOX_ENDPOINT) : $endpoint; $this->clientOptions = $clientOptions; $this->initiateHttpClient(); From fc93b7ba2f94df2c744ade0065d5dccb58e7c44c Mon Sep 17 00:00:00 2001 From: m4yankpomelo Date: Thu, 27 Jul 2023 14:46:42 +0800 Subject: [PATCH 4/4] Base URL Can be passed as clientOptions --- README.md | 9 +++++++++ src/Client.php | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 578c95f..744ccce 100755 --- a/README.md +++ b/README.md @@ -65,6 +65,15 @@ $options = ['headers' => ['foo' => 'bar']]; $client = new Client('apikey', 'appid', 'sandbox', $options); ``` +If you want to pass a custom base URL: + +```php +use PomeloPayConnect\Client; + +$options = ['baseUrl' => 'my-custom-url']; +$client = new Client('apikey', 'appid', 'sandbox', $options); +``` + ## Available API Operations The following exposed API operations from the Pomelo Pay Connect API are available using the API Client. diff --git a/src/Client.php b/src/Client.php index 33e85ad..340bd31 100755 --- a/src/Client.php +++ b/src/Client.php @@ -56,14 +56,14 @@ class Client * @param string $appId * @param string $mode * @param array $clientOptions - * @param string $endpoint */ - public function __construct(string $apiKey, string $appId, $mode = 'production', array $clientOptions = [], $endpoint = '') + public function __construct(string $apiKey, string $appId, $mode = 'production', array $clientOptions = []) { $this->apiKey = $apiKey; $this->appId = $appId; $this->mode = $mode; - $this->baseUrl = $endpoint === '' ? ($mode === 'production' ? self::PRODUCTION_ENDPOINT : self::SANDBOX_ENDPOINT) : $endpoint; + $this->baseUrl = isset($clientOptions['baseUrl']) ? $clientOptions['baseUrl'] : ($mode === 'production' ? self::PRODUCTION_ENDPOINT : self::SANDBOX_ENDPOINT); + if (isset($clientOptions['baseUrl'])) unset($clientOptions['baseUrl']); $this->clientOptions = $clientOptions; $this->initiateHttpClient();