From cae7222ba1adc6510911593361488b03911462bc Mon Sep 17 00:00:00 2001 From: Daniel de Vigny Date: Thu, 30 Nov 2023 14:42:02 +0100 Subject: [PATCH] ==== BREAKING CHANGES ==== - Rename MESOMB_API_KEY env property to MESOMB_APP_KEY - Add MESOMB_SSL_VERIFY in env to disable ssl verification on http request --- composer.json | 2 +- config/mesomb.php | 13 ++++++------- readme.md | 3 ++- src/Operation/Payment/Application.php | 2 +- src/Operation/Payment/Collect.php | 15 ++++++++++++--- src/Operation/Payment/Deposit.php | 14 +++++++++++--- src/Operation/Payment/Transaction.php | 2 +- 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 2dff418..353d9dd 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "hachther/laravel-mesomb", "description": "A laravel wrapper on top of Mesomb Payment API", "license": "MIT", - "version": "1.7.1", + "version": "1.7.2", "authors": [ { "name": "Hachther LLC", diff --git a/config/mesomb.php b/config/mesomb.php index bb6bb70..531abe1 100644 --- a/config/mesomb.php +++ b/config/mesomb.php @@ -16,13 +16,7 @@ * MeSomb Application Key * Copy from https://mesomb.hachther.com/en/applications/{id} */ - 'key' => env('MESOMB_API_KEY'), - - /* - * MeSomb API Application Key - * Copy from https://mesomb.hachther.com/en/applications/{id} - */ - 'api_key' => env('MESOMB_API_KEY'), + 'app_key' => env('MESOMB_APP_KEY'), /* * MeSomb Access Key @@ -36,6 +30,11 @@ */ 'secret_key' => env('MESOMB_SECRET_KEY'), + /* + * Set MESOMB_SSL_VERIFY to false if you want to run your http request without verification + */ + 'ssl_verify' => env('MESOMB_SSL_VERIFY', true), + /* * Number of second to wait before timeout a transaction */ diff --git a/readme.md b/readme.md index 908c9f5..1ca8d2e 100644 --- a/readme.md +++ b/readme.md @@ -31,11 +31,12 @@ Setting the following parameters from MeSomb Get the below information from MeSomb after followed the above tutorial. ```dotenv -MESOMB_API_KEY= +MESOMB_APP_KEY= MESOMB_API_HOST=https://mesomb.hachther.com MESOMB_API_VERSION=v1.1 MESOMB_ACCESS_KEY= MESOMB_SECRET_KEY= +MESOMB_SSL_VERIFY=true ``` Publish configurations file diff --git a/src/Operation/Payment/Application.php b/src/Operation/Payment/Application.php index 6763b85..8e38e94 100644 --- a/src/Operation/Payment/Application.php +++ b/src/Operation/Payment/Application.php @@ -44,7 +44,7 @@ public static function status() */ public static function checkStatus(): array { - $applicationKey = config('mesomb.api_key'); + $applicationKey = config('mesomb.app_key'); $url = self::generateURL('status/'); $date = new DateTime(); $nonce = ""; diff --git a/src/Operation/Payment/Collect.php b/src/Operation/Payment/Collect.php index 67f3f47..07e4a29 100644 --- a/src/Operation/Payment/Collect.php +++ b/src/Operation/Payment/Collect.php @@ -128,6 +128,12 @@ public function pay(): ?PaymentModel { $data = $this->prepareData(); $data['source'] = 'Laravel/v'.\app()->version(); + $ip = request()->ip(); + if (empty($data['location'])) { + $data['location'] = array( + 'ip' => $ip + ); + } $nonce = Signature::nonceGenerator(); $date = new \DateTime(); $url = $this->generateURL(); @@ -139,14 +145,17 @@ public function pay(): ?PaymentModel 'x-mesomb-nonce' => $nonce, 'Authorization' => $authorization, 'Content-Type' => 'application/json', - 'X-MeSomb-Application' => config('mesomb.key'), + 'X-MeSomb-Application' => config('mesomb.app_key'), 'X-MeSomb-OperationMode' => config('mesomb.mode'), 'X-MeSomb-TrxID' => $this->paymentModel->id, ]; $response = Http::withHeaders($headers) - ->timeout(config('mesomb.timeout')) - ->post($url, $data); + ->timeout(config('mesomb.timeout')); + if (!config('mesomb.ssl_verify')) { + $response = $response->withoutVerifying(); + } + $response = $response->post($url, $data); if ($response->failed()) { $this->handleException($response); diff --git a/src/Operation/Payment/Deposit.php b/src/Operation/Payment/Deposit.php index de45c3c..3b4e7dc 100644 --- a/src/Operation/Payment/Deposit.php +++ b/src/Operation/Payment/Deposit.php @@ -126,6 +126,12 @@ public function pay(): DepositModel { $data = $this->prepareData(); $data['source'] = 'Laravel/v'.\app()->version(); + $ip = request()->ip(); + if (empty($data['location'])) { + $data['location'] = array( + 'ip' => $ip + ); + } $nonce = Signature::nonceGenerator(); $date = new \DateTime(); $url = $this->generateURL(); @@ -142,9 +148,11 @@ public function pay(): DepositModel ]; $response = Http::withHeaders($headers) - ->timeout(config('mesomb.timeout')) - ->post($url, $data); - + ->timeout(config('mesomb.timeout')); + if (!config('mesomb.ssl_verify')) { + $response = $response->withoutVerifying(); + } + $response = $response->post($url, $data); if ($response->failed()) { $this->handleException($response); diff --git a/src/Operation/Payment/Transaction.php b/src/Operation/Payment/Transaction.php index 5fa0b1c..2c0e0a8 100644 --- a/src/Operation/Payment/Transaction.php +++ b/src/Operation/Payment/Transaction.php @@ -52,7 +52,7 @@ public static function checkStatus($model) $url = self::generateURL('transactions/', $ids); $date = new DateTime(); $nonce = ""; - $applicationKey = config('mesomb.api_key'); + $applicationKey = config('mesomb.app_key'); $authorization = SignedRequest::getAuthorization('GET', $url, $date, $nonce);