From c993267853b2772992e233167a5711eb1cbb089e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=96zisik?= Date: Wed, 29 Nov 2023 11:20:05 +0200 Subject: [PATCH] add locale to all requests --- src/Messages/AbstractRequest.php | 7 ++++++- src/Messages/CitPaymentRequest.php | 1 - src/Messages/MitPaymentRequest.php | 1 - src/Messages/OneOffPaymentRequest.php | 1 - tests/RequestsTest.php | 6 ++++++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Messages/AbstractRequest.php b/src/Messages/AbstractRequest.php index 6581afd..17bca95 100644 --- a/src/Messages/AbstractRequest.php +++ b/src/Messages/AbstractRequest.php @@ -41,6 +41,11 @@ protected function getBaseData() * The request will be rejected if the provided timestamp is outside of an allowed time-window. */ 'timestamp' => date('c'), + + /** + * Locale + */ + 'locale' => $this->getLocale(), ]; } @@ -66,7 +71,7 @@ protected function httpRequest($method, $uri, array $headers, $data = null): arr $data = @json_decode($response->getBody()->getContents(), true); - if (! $data || ! is_array($data)) { + if (!$data || !is_array($data)) { throw new InvalidResponseException( 'Unrecognized error format.', $response->getStatusCode() diff --git a/src/Messages/CitPaymentRequest.php b/src/Messages/CitPaymentRequest.php index e5d3829..94c3231 100644 --- a/src/Messages/CitPaymentRequest.php +++ b/src/Messages/CitPaymentRequest.php @@ -37,7 +37,6 @@ public function getData() 'amount' => $this->getAmount(), 'order_reference' => $this->getTransactionId(), 'token_agreement' => TokenAgreement::UNSCHEDULED, - 'locale' => $this->getLocale() ]; if ($this->getEmail()) { diff --git a/src/Messages/MitPaymentRequest.php b/src/Messages/MitPaymentRequest.php index 02a54a1..c63afc5 100644 --- a/src/Messages/MitPaymentRequest.php +++ b/src/Messages/MitPaymentRequest.php @@ -38,7 +38,6 @@ public function getData() 'token_agreement' => TokenAgreement::UNSCHEDULED, 'merchant_ip' => $this->getMerchantIp(), - 'locale' => $this->getLocale() ]; if ($this->getEmail()) { diff --git a/src/Messages/OneOffPaymentRequest.php b/src/Messages/OneOffPaymentRequest.php index 6527df1..316f628 100644 --- a/src/Messages/OneOffPaymentRequest.php +++ b/src/Messages/OneOffPaymentRequest.php @@ -36,7 +36,6 @@ public function getData(): array 'amount' => $this->getAmount(), 'order_reference' => $this->getTransactionId(), - 'locale' => $this->getLocale() ]; if ($this->getEmail()) { diff --git a/tests/RequestsTest.php b/tests/RequestsTest.php index 4b2e43f..475b3b0 100644 --- a/tests/RequestsTest.php +++ b/tests/RequestsTest.php @@ -19,6 +19,12 @@ public function testPurchaseRequest() $this->assertInstanceOf(OneOffPaymentRequest::class, $gateway->purchase()); + $purchaseRequest = $gateway->purchase(); + $requestData = $purchaseRequest->getData(); + + $this->assertArrayHasKey('api_username', $requestData); + $this->assertSame('en', $requestData['locale']); + $this->assertInstanceOf(OneOffPaymentRequest::class, $gateway->purchase([ 'paymentType' => PaymentType::ONE_OFF, ]));