Skip to content

Commit 64b71c5

Browse files
authored
Pass locale to EveryPay (#9)
* apply locale patch * set default locale to en * add locale to all requests
1 parent c28fe7e commit 64b71c5

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

src/Concerns/Parameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function getDefaultParameters()
1313
'secret' => getenv('EVERY_PAY_API_SECRET'), // api_secret
1414
'accountName' => getenv('EVERY_PAY_ACCOUNT_NAME'), // processing account
1515
'testMode' => true,
16-
'locale' => 'et',
16+
'locale' => 'en',
1717
'saveCard' => false,
1818
];
1919
}

src/Messages/AbstractRequest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ protected function getBaseData()
4141
* The request will be rejected if the provided timestamp is outside of an allowed time-window.
4242
*/
4343
'timestamp' => date('c'),
44+
45+
/**
46+
* Locale
47+
*/
48+
'locale' => $this->getLocale(),
4449
];
4550
}
4651

@@ -66,7 +71,7 @@ protected function httpRequest($method, $uri, array $headers, $data = null): arr
6671

6772
$data = @json_decode($response->getBody()->getContents(), true);
6873

69-
if (! $data || ! is_array($data)) {
74+
if (!$data || !is_array($data)) {
7075
throw new InvalidResponseException(
7176
'Unrecognized error format.',
7277
$response->getStatusCode()

tests/EveryPayTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public function testMerchantIp()
4444
$this->assertSame('2.2.2.2', $this->gateway->getMerchantIp());
4545
}
4646

47+
48+
public function testLocale()
49+
{
50+
// Default locale is English
51+
$this->assertSame('en', $this->gateway->getLocale());
52+
53+
$this->assertSame($this->gateway, $this->gateway->setLocale('lv'));
54+
$this->assertSame('lv', $this->gateway->getLocale());
55+
}
56+
4757
public function testSaveCard()
4858
{
4959
// Default is false

tests/RequestsTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public function testPurchaseRequest()
1919

2020
$this->assertInstanceOf(OneOffPaymentRequest::class, $gateway->purchase());
2121

22+
$purchaseRequest = $gateway->purchase();
23+
$requestData = $purchaseRequest->getData();
24+
25+
$this->assertArrayHasKey('api_username', $requestData);
26+
$this->assertSame('en', $requestData['locale']);
27+
2228
$this->assertInstanceOf(OneOffPaymentRequest::class, $gateway->purchase([
2329
'paymentType' => PaymentType::ONE_OFF,
2430
]));

0 commit comments

Comments
 (0)