Skip to content

Commit

Permalink
add locale to all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
aozisik committed Nov 29, 2023
1 parent 0155119 commit c993267
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Messages/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}

Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion src/Messages/CitPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function getData()
'amount' => $this->getAmount(),
'order_reference' => $this->getTransactionId(),
'token_agreement' => TokenAgreement::UNSCHEDULED,
'locale' => $this->getLocale()
];

if ($this->getEmail()) {
Expand Down
1 change: 0 additions & 1 deletion src/Messages/MitPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function getData()
'token_agreement' => TokenAgreement::UNSCHEDULED,

'merchant_ip' => $this->getMerchantIp(),
'locale' => $this->getLocale()
];

if ($this->getEmail()) {
Expand Down
1 change: 0 additions & 1 deletion src/Messages/OneOffPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function getData(): array

'amount' => $this->getAmount(),
'order_reference' => $this->getTransactionId(),
'locale' => $this->getLocale()
];

if ($this->getEmail()) {
Expand Down
6 changes: 6 additions & 0 deletions tests/RequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]));
Expand Down

0 comments on commit c993267

Please sign in to comment.