From 3a8dc567b6df5bcd8bca19409db9d222779460a5 Mon Sep 17 00:00:00 2001 From: ashwani Date: Wed, 2 Sep 2026 09:18:28 +0200 Subject: [PATCH 1/6] Fix Terminal API regional endpoint configuration --- src/Adyen/Client.php | 41 ++++- src/Adyen/Service/PosPayment.php | 12 +- tests/Unit/TerminalApiRegionTest.php | 236 +++++++++++++++++++++++++++ 3 files changed, 274 insertions(+), 15 deletions(-) create mode 100644 tests/Unit/TerminalApiRegionTest.php diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index e81aef79a..df9fbebf0 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -175,14 +175,41 @@ public function setEnvironment(string $environment, ?string $liveEndpointUrlPref } // Retrieve and set the Terminal API Cloud Endpoint - $endpoint = $this->retrieveCloudEndpoint($this->config->get('terminalApiRegion'), $environment); - $this->config->set('terminalApiCloudEndpoint', $endpoint); + $this->setCloudEndPoint($this->config->get('terminalApiRegion'), $environment); } + /** + * @throws AdyenException + */ + public function setTerminalApiRegion(string $region) + { + if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) { + throw new AdyenException("TerminalAPI endpoint for $region is not supported yet"); + } + $this->config->set('terminalApiRegion', $region); + $environment = $this->config->getEnvironment(); + if ($environment!=null) { + $this->setCloudEndPoint($region, $environment); + } + } + + /** + * @throws AdyenException + */ + private function setCloudEndPoint(?string $region, string $environment): void + { + $endpoint = $this->retrieveCloudEndpoint($region, $environment); + $this->config->set('terminalApiCloudEndpoint', $endpoint); + $this->config->set('endpointTerminalCloud', $endpoint); + } + + + /** * Retrieve the cloud endpoint for a given region and environment. * - * @param string|null $region The region for which the endpoint is requested. Defaults to the EU endpoint if null or unsupported. + * @param string|null $region The region for which the endpoint is requested. + * Defaults to the EU endpoint if null. Throws for unsupported regions in live mode. * @param string $environment The environment, either 'test' or 'live'. * @return string The endpoint URL. * @throws AdyenException @@ -196,13 +223,11 @@ public function retrieveCloudEndpoint(?string $region, string $environment): str // Check if the environment is LIVE if ($environment === Environment::LIVE) { - if ($environment === Environment::LIVE) { $region = $region ?? Region::EU; - if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) { - throw new AdyenException("TerminalAPI endpoint for $region is not supported yet"); - } - return Region::TERMINAL_API_ENDPOINTS_MAPPING[$region]; + if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) { + throw new AdyenException("TerminalAPI endpoint for $region is not supported yet"); } + return Region::TERMINAL_API_ENDPOINTS_MAPPING[$region]; } // Default to TEST endpoint if no valid environment is specified return self::ENDPOINT_TERMINAL_CLOUD_TEST; diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php index dfd8dd8b8..e338aa0f7 100644 --- a/src/Adyen/Service/PosPayment.php +++ b/src/Adyen/Service/PosPayment.php @@ -4,7 +4,6 @@ use Adyen\Client; use Adyen\Environment; -use Adyen\Region; class PosPayment extends \Adyen\ApiKeyAuthenticatedService { @@ -33,14 +32,13 @@ public function __construct(Client $client) { parent::__construct($client); - $region = $this->getClient()->getConfig()->get('region'); + $config = $this->getClient()->getConfig(); + $region = $config->get('terminalApiRegion') + ?? $config->get('region'); $environment = $this->getClient()->getConfig()->get('environment'); - if (isset($region) && $environment == Environment::LIVE) { - $this->getClient()->getConfig()->set( - 'endpointTerminalCloud', - Region::TERMINAL_API_ENDPOINTS_MAPPING[$region] - ); + if ($region !== null && $environment == Environment::LIVE) { + $this->getClient()->setTerminalApiRegion($region); } $this->runTenderSync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, false); diff --git a/tests/Unit/TerminalApiRegionTest.php b/tests/Unit/TerminalApiRegionTest.php new file mode 100644 index 000000000..2adfcfcc5 --- /dev/null +++ b/tests/Unit/TerminalApiRegionTest.php @@ -0,0 +1,236 @@ +getConfig()->set($regionKey, Region::US); + $client->setEnvironment(Environment::LIVE); + $client->setXApiKey("MockKey"); + + $httpClient = $this->getMockBuilder(CurlClient::class) + ->onlyMethods(['requestJson']) + ->getMock(); + + $httpClient->method('requestJson') + ->willReturnCallback( + function (Service $service, $requestUrl, $params, $requestOptions = null) use (&$requestUrls) { + $requestUrls[] = $requestUrl; + + return []; + } + ); + + $client->setHttpClient($httpClient); + + return $client; + } + + /** + * @throws AdyenException + */ + public function testUsesTerminalApiRegionForTerminalRequests(): void + { + $requestUrls = []; + $client = $this->createLiveClient('terminalApiRegion', $requestUrls); + $service = new PosPayment($client); + $service->runTenderSync(['SaleToPOIRequest' => []]); + $service->runTenderAsync(['SaleToPOIRequest' => []]); + $service->getConnectedTerminals(['merchantAccount' => 'TestMerchant']); + + $this->assertSame( + [ + 'https://terminal-api-live-us.adyen.com/sync', + 'https://terminal-api-live-us.adyen.com/async', + 'https://terminal-api-live-us.adyen.com/connectedTerminals', + ], + $requestUrls + ); + } + + /** + * @throws AdyenException + */ + public function testSupportsLegacyRegion(): void + { + $requestUrls = []; + $client = $this->createLiveClient('region', $requestUrls); + $service = new PosPayment($client); + $service->runTenderSync(['SaleToPOIRequest' => []]); + $service->runTenderAsync(['SaleToPOIRequest' => []]); + $service->getConnectedTerminals(['merchantAccount' => 'TestMerchant']); + + $this->assertSame( + [ + 'https://terminal-api-live-us.adyen.com/sync', + 'https://terminal-api-live-us.adyen.com/async', + 'https://terminal-api-live-us.adyen.com/connectedTerminals', + ], + $requestUrls + ); + } + + + /** + * @throws AdyenException + */ + public function testSetsRegionBeforeEnvironment(): void + { + $client = new Client(); + $client->setTerminalApiRegion(Region::US); + $client->setEnvironment(Environment::LIVE); + $this->assertSame( + 'https://terminal-api-live-us.adyen.com', + $client->getConfig()->get('endpointTerminalCloud') + ); + $this->assertSame( + 'https://terminal-api-live-us.adyen.com', + $client->getConfig()->get('terminalApiCloudEndpoint') + ); + } + + /** + * @throws AdyenException + */ + public function testSetsRegionAfterEnvironment(): void + { + $client = new Client(); + $client->setEnvironment(Environment::LIVE); + $client->setTerminalApiRegion(Region::US); + $this->assertSame( + 'https://terminal-api-live-us.adyen.com', + $client->getConfig()->get('endpointTerminalCloud') + ); + } + + public function testRejectsUnsupportedRegion(): void + { + $client = new Client(); + + $this->expectException(AdyenException::class); + $this->expectExceptionMessage( + 'TerminalAPI endpoint for in is not supported yet' + ); + + $client->setTerminalApiRegion(Region::IN); + } + + public function testRejectsUnknownRegion(): void + { + $client = new Client(); + + $this->expectException(AdyenException::class); + $this->expectExceptionMessage( + 'TerminalAPI endpoint for invalid-region is not supported yet' + ); + + $client->setTerminalApiRegion('invalid-region'); + } + + /** + * @throws AdyenException + */ + public function testIgnoresRegionInTest(): void + { + $client = new Client(); + $client->setTerminalApiRegion(Region::US); + $client->setEnvironment(Environment::TEST); + $this->assertSame( + 'https://terminal-api-test.adyen.com', + $client->getConfig()->get('endpointTerminalCloud') + ); + } + + /** + * @throws AdyenException + */ + public function testUsesDefaultTestEndpoint(): void + { + $client = new Client(); + $client->setEnvironment(Environment::TEST); + $this->assertSame( + 'https://terminal-api-test.adyen.com', + $client->getConfig()->get('endpointTerminalCloud') + ); + } + + /** + * @throws AdyenException + */ + public function testUsesDefaultLiveEndpoint(): void + { + $client = new Client(); + $client->setEnvironment(Environment::LIVE); + $this->assertSame( + 'https://terminal-api-live.adyen.com', + $client->getConfig()->get('endpointTerminalCloud') + ); + } + + /** + * @throws AdyenException + */ + public function testIgnoresLivePrefix(): void + { + $client = new Client(); + + $client->setEnvironment(Environment::LIVE, 'testprefix'); + + $this->assertSame( + 'https://testprefix-pal-live.adyenpayments.com', + $client->getConfig()->get('endpoint') + ); + + $this->assertSame( + 'https://terminal-api-live.adyen.com', + $client->getConfig()->get('endpointTerminalCloud') + ); + } + + /** + * @throws AdyenException + */ + public function testPrefersTerminalApiRegion(): void + { + $client = new Client(); + $client->getConfig()->set('region', Region::AU); + $client->getConfig()->set('terminalApiRegion', Region::US); + $client->setEnvironment(Environment::LIVE); + new PosPayment($client); + $this->assertSame( + 'https://terminal-api-live-us.adyen.com', + $client->getConfig()->get('endpointTerminalCloud') + ); + } + + public function testRejectsUnknownLegacyRegion(): void + { + $client = new Client(); + + $this->expectException(AdyenException::class); + $this->expectExceptionMessage( + 'TerminalAPI endpoint for invalid-region is not supported yet' + ); + + $client->getConfig()->set('region', 'invalid-region'); + $client->setEnvironment(Environment::LIVE); + new PosPayment($client); + } +} From 5aba3557ff3ad00fb315d0abc240a7937b41bd97 Mon Sep 17 00:00:00 2001 From: ashwani Date: Wed, 2 Sep 2026 09:39:21 +0200 Subject: [PATCH 2/6] Fix Implemented Gemini Code comments, minor good code practices --- src/Adyen/Client.php | 4 ++-- src/Adyen/Service/PosPayment.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index df9fbebf0..2dca6f053 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -181,14 +181,14 @@ public function setEnvironment(string $environment, ?string $liveEndpointUrlPref /** * @throws AdyenException */ - public function setTerminalApiRegion(string $region) + public function setTerminalApiRegion(string $region): void { if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) { throw new AdyenException("TerminalAPI endpoint for $region is not supported yet"); } $this->config->set('terminalApiRegion', $region); $environment = $this->config->getEnvironment(); - if ($environment!=null) { + if ($environment !== null) { $this->setCloudEndPoint($region, $environment); } } diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php index e338aa0f7..41f5aa715 100644 --- a/src/Adyen/Service/PosPayment.php +++ b/src/Adyen/Service/PosPayment.php @@ -35,9 +35,9 @@ public function __construct(Client $client) $config = $this->getClient()->getConfig(); $region = $config->get('terminalApiRegion') ?? $config->get('region'); - $environment = $this->getClient()->getConfig()->get('environment'); + $environment = $config->get('environment'); - if ($region !== null && $environment == Environment::LIVE) { + if ($region !== null && $environment === Environment::LIVE) { $this->getClient()->setTerminalApiRegion($region); } From a69eb2db0fbcec062db5e8dd9b0803ab4a35005b Mon Sep 17 00:00:00 2001 From: ashwani Date: Thu, 3 Sep 2026 11:54:35 +0200 Subject: [PATCH 3/6] Fix Add region setter in client, remove terminal api region changes from PosPayment --- src/Adyen/Client.php | 28 +---- src/Adyen/Service/PosPayment.php | 14 ++- tests/Unit/TerminalApiRegionTest.php | 171 +-------------------------- 3 files changed, 19 insertions(+), 194 deletions(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 2dca6f053..f0faf5720 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -175,41 +175,23 @@ public function setEnvironment(string $environment, ?string $liveEndpointUrlPref } // Retrieve and set the Terminal API Cloud Endpoint - $this->setCloudEndPoint($this->config->get('terminalApiRegion'), $environment); + $endpoint = $this->retrieveCloudEndpoint($this->config->get('terminalApiRegion'), $environment); + $this->config->set('terminalApiCloudEndpoint', $endpoint); } - /** - * @throws AdyenException - */ - public function setTerminalApiRegion(string $region): void + public function setRegion(string $region): void { if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) { throw new AdyenException("TerminalAPI endpoint for $region is not supported yet"); } - $this->config->set('terminalApiRegion', $region); - $environment = $this->config->getEnvironment(); - if ($environment !== null) { - $this->setCloudEndPoint($region, $environment); - } - } - - /** - * @throws AdyenException - */ - private function setCloudEndPoint(?string $region, string $environment): void - { - $endpoint = $this->retrieveCloudEndpoint($region, $environment); - $this->config->set('terminalApiCloudEndpoint', $endpoint); - $this->config->set('endpointTerminalCloud', $endpoint); + $this->config->set('region', $region); } - - /** * Retrieve the cloud endpoint for a given region and environment. * * @param string|null $region The region for which the endpoint is requested. - * Defaults to the EU endpoint if null. Throws for unsupported regions in live mode. + * Defaults to the EU endpoint if null or unsupported. * @param string $environment The environment, either 'test' or 'live'. * @return string The endpoint URL. * @throws AdyenException diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php index 41f5aa715..dfd8dd8b8 100644 --- a/src/Adyen/Service/PosPayment.php +++ b/src/Adyen/Service/PosPayment.php @@ -4,6 +4,7 @@ use Adyen\Client; use Adyen\Environment; +use Adyen\Region; class PosPayment extends \Adyen\ApiKeyAuthenticatedService { @@ -32,13 +33,14 @@ public function __construct(Client $client) { parent::__construct($client); - $config = $this->getClient()->getConfig(); - $region = $config->get('terminalApiRegion') - ?? $config->get('region'); - $environment = $config->get('environment'); + $region = $this->getClient()->getConfig()->get('region'); + $environment = $this->getClient()->getConfig()->get('environment'); - if ($region !== null && $environment === Environment::LIVE) { - $this->getClient()->setTerminalApiRegion($region); + if (isset($region) && $environment == Environment::LIVE) { + $this->getClient()->getConfig()->set( + 'endpointTerminalCloud', + Region::TERMINAL_API_ENDPOINTS_MAPPING[$region] + ); } $this->runTenderSync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, false); diff --git a/tests/Unit/TerminalApiRegionTest.php b/tests/Unit/TerminalApiRegionTest.php index 2adfcfcc5..d5fd5adfc 100644 --- a/tests/Unit/TerminalApiRegionTest.php +++ b/tests/Unit/TerminalApiRegionTest.php @@ -16,12 +16,10 @@ class TerminalApiRegionTest extends TestCaseMock /** * @throws AdyenException */ - private function createLiveClient( - string $regionKey, - array &$requestUrls - ): Client { + private function createLiveClient(array &$requestUrls): Client + { $client = new Client(); - $client->getConfig()->set($regionKey, Region::US); + $client->setRegion(Region::US); $client->setEnvironment(Environment::LIVE); $client->setXApiKey("MockKey"); @@ -46,10 +44,10 @@ function (Service $service, $requestUrl, $params, $requestOptions = null) use (& /** * @throws AdyenException */ - public function testUsesTerminalApiRegionForTerminalRequests(): void + public function testUsesRegionForTerminalRequests(): void { $requestUrls = []; - $client = $this->createLiveClient('terminalApiRegion', $requestUrls); + $client = $this->createLiveClient($requestUrls); $service = new PosPayment($client); $service->runTenderSync(['SaleToPOIRequest' => []]); $service->runTenderAsync(['SaleToPOIRequest' => []]); @@ -65,61 +63,6 @@ public function testUsesTerminalApiRegionForTerminalRequests(): void ); } - /** - * @throws AdyenException - */ - public function testSupportsLegacyRegion(): void - { - $requestUrls = []; - $client = $this->createLiveClient('region', $requestUrls); - $service = new PosPayment($client); - $service->runTenderSync(['SaleToPOIRequest' => []]); - $service->runTenderAsync(['SaleToPOIRequest' => []]); - $service->getConnectedTerminals(['merchantAccount' => 'TestMerchant']); - - $this->assertSame( - [ - 'https://terminal-api-live-us.adyen.com/sync', - 'https://terminal-api-live-us.adyen.com/async', - 'https://terminal-api-live-us.adyen.com/connectedTerminals', - ], - $requestUrls - ); - } - - - /** - * @throws AdyenException - */ - public function testSetsRegionBeforeEnvironment(): void - { - $client = new Client(); - $client->setTerminalApiRegion(Region::US); - $client->setEnvironment(Environment::LIVE); - $this->assertSame( - 'https://terminal-api-live-us.adyen.com', - $client->getConfig()->get('endpointTerminalCloud') - ); - $this->assertSame( - 'https://terminal-api-live-us.adyen.com', - $client->getConfig()->get('terminalApiCloudEndpoint') - ); - } - - /** - * @throws AdyenException - */ - public function testSetsRegionAfterEnvironment(): void - { - $client = new Client(); - $client->setEnvironment(Environment::LIVE); - $client->setTerminalApiRegion(Region::US); - $this->assertSame( - 'https://terminal-api-live-us.adyen.com', - $client->getConfig()->get('endpointTerminalCloud') - ); - } - public function testRejectsUnsupportedRegion(): void { $client = new Client(); @@ -129,108 +72,6 @@ public function testRejectsUnsupportedRegion(): void 'TerminalAPI endpoint for in is not supported yet' ); - $client->setTerminalApiRegion(Region::IN); - } - - public function testRejectsUnknownRegion(): void - { - $client = new Client(); - - $this->expectException(AdyenException::class); - $this->expectExceptionMessage( - 'TerminalAPI endpoint for invalid-region is not supported yet' - ); - - $client->setTerminalApiRegion('invalid-region'); - } - - /** - * @throws AdyenException - */ - public function testIgnoresRegionInTest(): void - { - $client = new Client(); - $client->setTerminalApiRegion(Region::US); - $client->setEnvironment(Environment::TEST); - $this->assertSame( - 'https://terminal-api-test.adyen.com', - $client->getConfig()->get('endpointTerminalCloud') - ); - } - - /** - * @throws AdyenException - */ - public function testUsesDefaultTestEndpoint(): void - { - $client = new Client(); - $client->setEnvironment(Environment::TEST); - $this->assertSame( - 'https://terminal-api-test.adyen.com', - $client->getConfig()->get('endpointTerminalCloud') - ); - } - - /** - * @throws AdyenException - */ - public function testUsesDefaultLiveEndpoint(): void - { - $client = new Client(); - $client->setEnvironment(Environment::LIVE); - $this->assertSame( - 'https://terminal-api-live.adyen.com', - $client->getConfig()->get('endpointTerminalCloud') - ); - } - - /** - * @throws AdyenException - */ - public function testIgnoresLivePrefix(): void - { - $client = new Client(); - - $client->setEnvironment(Environment::LIVE, 'testprefix'); - - $this->assertSame( - 'https://testprefix-pal-live.adyenpayments.com', - $client->getConfig()->get('endpoint') - ); - - $this->assertSame( - 'https://terminal-api-live.adyen.com', - $client->getConfig()->get('endpointTerminalCloud') - ); - } - - /** - * @throws AdyenException - */ - public function testPrefersTerminalApiRegion(): void - { - $client = new Client(); - $client->getConfig()->set('region', Region::AU); - $client->getConfig()->set('terminalApiRegion', Region::US); - $client->setEnvironment(Environment::LIVE); - new PosPayment($client); - $this->assertSame( - 'https://terminal-api-live-us.adyen.com', - $client->getConfig()->get('endpointTerminalCloud') - ); - } - - public function testRejectsUnknownLegacyRegion(): void - { - $client = new Client(); - - $this->expectException(AdyenException::class); - $this->expectExceptionMessage( - 'TerminalAPI endpoint for invalid-region is not supported yet' - ); - - $client->getConfig()->set('region', 'invalid-region'); - $client->setEnvironment(Environment::LIVE); - new PosPayment($client); + $client->setRegion(Region::IN); } } From d53186d688dfbca17633ce2720c8e838c0ab8410 Mon Sep 17 00:00:00 2001 From: ashwani Date: Thu, 3 Sep 2026 11:59:34 +0200 Subject: [PATCH 4/6] Fix Remove TerminalApiRegionTest, add unit test in RegionTest --- tests/Unit/RegionTest.php | 16 +++++- tests/Unit/TerminalApiRegionTest.php | 77 ---------------------------- 2 files changed, 15 insertions(+), 78 deletions(-) delete mode 100644 tests/Unit/TerminalApiRegionTest.php diff --git a/tests/Unit/RegionTest.php b/tests/Unit/RegionTest.php index 4393ec3ad..f58425b77 100644 --- a/tests/Unit/RegionTest.php +++ b/tests/Unit/RegionTest.php @@ -2,6 +2,8 @@ namespace Adyen\Tests\Unit; +use Adyen\AdyenException; +use Adyen\Client; use PHPUnit\Framework\TestCase; use Adyen\Region; @@ -17,7 +19,7 @@ private function getRegionValues(): array { $reflection = new \ReflectionClass(Region::class); $constants = $reflection->getConstants(); - + $enumConstants = array_filter($constants, function ($value) { return is_string($value); }); @@ -71,4 +73,16 @@ public function testTerminalApiEndpointsMapping(): void "TERMINAL_API_ENDPOINTS_MAPPING should match the expected mappings." ); } + + public function testRejectsUnsupportedRegion(): void + { + $client = new Client(); + + $this->expectException(AdyenException::class); + $this->expectExceptionMessage( + 'TerminalAPI endpoint for in is not supported yet' + ); + + $client->setRegion(Region::IN); + } } diff --git a/tests/Unit/TerminalApiRegionTest.php b/tests/Unit/TerminalApiRegionTest.php deleted file mode 100644 index d5fd5adfc..000000000 --- a/tests/Unit/TerminalApiRegionTest.php +++ /dev/null @@ -1,77 +0,0 @@ -setRegion(Region::US); - $client->setEnvironment(Environment::LIVE); - $client->setXApiKey("MockKey"); - - $httpClient = $this->getMockBuilder(CurlClient::class) - ->onlyMethods(['requestJson']) - ->getMock(); - - $httpClient->method('requestJson') - ->willReturnCallback( - function (Service $service, $requestUrl, $params, $requestOptions = null) use (&$requestUrls) { - $requestUrls[] = $requestUrl; - - return []; - } - ); - - $client->setHttpClient($httpClient); - - return $client; - } - - /** - * @throws AdyenException - */ - public function testUsesRegionForTerminalRequests(): void - { - $requestUrls = []; - $client = $this->createLiveClient($requestUrls); - $service = new PosPayment($client); - $service->runTenderSync(['SaleToPOIRequest' => []]); - $service->runTenderAsync(['SaleToPOIRequest' => []]); - $service->getConnectedTerminals(['merchantAccount' => 'TestMerchant']); - - $this->assertSame( - [ - 'https://terminal-api-live-us.adyen.com/sync', - 'https://terminal-api-live-us.adyen.com/async', - 'https://terminal-api-live-us.adyen.com/connectedTerminals', - ], - $requestUrls - ); - } - - public function testRejectsUnsupportedRegion(): void - { - $client = new Client(); - - $this->expectException(AdyenException::class); - $this->expectExceptionMessage( - 'TerminalAPI endpoint for in is not supported yet' - ); - - $client->setRegion(Region::IN); - } -} From 4bff44896931fc14923b3e8a30a58ad18c311af1 Mon Sep 17 00:00:00 2001 From: ashwani Date: Thu, 3 Sep 2026 13:22:18 +0200 Subject: [PATCH 5/6] Fix Add unit test for fetching US endpointTerminalCLoud Url --- tests/Unit/RegionTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Unit/RegionTest.php b/tests/Unit/RegionTest.php index f58425b77..1848a7feb 100644 --- a/tests/Unit/RegionTest.php +++ b/tests/Unit/RegionTest.php @@ -4,6 +4,8 @@ use Adyen\AdyenException; use Adyen\Client; +use Adyen\Environment; +use Adyen\Service\PosPayment; use PHPUnit\Framework\TestCase; use Adyen\Region; @@ -74,6 +76,23 @@ public function testTerminalApiEndpointsMapping(): void ); } + /** + * @throws AdyenException + */ + public function testSetsUnitedStatesTerminalCloudEndpoint(): void + { + $client = new Client(); + $client->setRegion(Region::US); + $client->setEnvironment(Environment::LIVE); + + new PosPayment($client); + + $this->assertSame( + Client::ENDPOINT_TERMINAL_CLOUD_US_LIVE, + $client->getConfig()->get('endpointTerminalCloud') + ); + } + public function testRejectsUnsupportedRegion(): void { $client = new Client(); From 19cd4a8b14583a0b06f6d25825e4db2e217f493f Mon Sep 17 00:00:00 2001 From: ashwani Date: Fri, 4 Sep 2026 11:37:01 +0200 Subject: [PATCH 6/6] Fix make setting region generic --- src/Adyen/Client.php | 4 +--- src/Adyen/Service/PosPayment.php | 4 ++++ tests/Unit/RegionTest.php | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index f0faf5720..b5e80dae2 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -181,9 +181,6 @@ public function setEnvironment(string $environment, ?string $liveEndpointUrlPref public function setRegion(string $region): void { - if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) { - throw new AdyenException("TerminalAPI endpoint for $region is not supported yet"); - } $this->config->set('region', $region); } @@ -195,6 +192,7 @@ public function setRegion(string $region): void * @param string $environment The environment, either 'test' or 'live'. * @return string The endpoint URL. * @throws AdyenException + * @deprecated */ public function retrieveCloudEndpoint(?string $region, string $environment): string { diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php index dfd8dd8b8..251d8c7ab 100644 --- a/src/Adyen/Service/PosPayment.php +++ b/src/Adyen/Service/PosPayment.php @@ -2,6 +2,7 @@ namespace Adyen\Service; +use Adyen\AdyenException; use Adyen\Client; use Adyen\Environment; use Adyen\Region; @@ -37,6 +38,9 @@ public function __construct(Client $client) $environment = $this->getClient()->getConfig()->get('environment'); if (isset($region) && $environment == Environment::LIVE) { + if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) { + throw new AdyenException("TerminalAPI endpoint for $region is not supported yet"); + } $this->getClient()->getConfig()->set( 'endpointTerminalCloud', Region::TERMINAL_API_ENDPOINTS_MAPPING[$region] diff --git a/tests/Unit/RegionTest.php b/tests/Unit/RegionTest.php index 1848a7feb..b8eb5c651 100644 --- a/tests/Unit/RegionTest.php +++ b/tests/Unit/RegionTest.php @@ -103,5 +103,7 @@ public function testRejectsUnsupportedRegion(): void ); $client->setRegion(Region::IN); + $client->setEnvironment(Environment::LIVE); + new PosPayment($client); } }