Skip to content

Commit f11201a

Browse files
authored
Merge pull request #760 from Adyen/fix-possdk
Correct PosSdk (PosMobileService) LIVE url
2 parents 1da97f4 + 114e04e commit f11201a

File tree

5 files changed

+159
-6
lines changed

5 files changed

+159
-6
lines changed

src/Adyen/Service.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,21 @@ public function createBaseUrl(string $url): string
135135
);
136136
}
137137

138-
// We inject the live prefix like "https://{PREFIX}-"
139-
$url = str_replace(
140-
"https://checkout-test.adyen.com/",
141-
"https://" . $config->get('prefix') . '-checkout-live.adyenpayments.com/checkout/',
142-
$url
143-
);
138+
if (strpos($url, "possdk") !== false) {
139+
// PosSdk (PosMobileApi): inject the live prefix like "https://{PREFIX}-" without duplicating `/checkout` in path
140+
$url = str_replace(
141+
"https://checkout-test.adyen.com/",
142+
"https://" . $config->get('prefix') . '-checkout-live.adyenpayments.com/',
143+
$url
144+
);
145+
} else {
146+
// Other services: inject the live prefix like "https://{PREFIX}-"
147+
$url = str_replace(
148+
"https://checkout-test.adyen.com/",
149+
"https://" . $config->get('prefix') . '-checkout-live.adyenpayments.com/checkout/',
150+
$url
151+
);
152+
}
144153
}
145154

146155
// Replace 'test' in string with 'live' for the other endpoints
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"id": "APP_SESSION_ID",
3+
"installationId": "INSTALLATION_ID",
4+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
5+
"store": "YOUR_STORE_ID",
6+
"sdkData": "SDK_DATA_BLOB"
7+
}

tests/Unit/ClientTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Adyen\Tests\Unit;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Adyen\Client;
7+
use Adyen\Environment;
8+
9+
class ClientTest extends TestCase
10+
{
11+
12+
public function testCreate(): void
13+
{
14+
$client = new Client();
15+
$client->setApplicationName("My Test Application");
16+
$client->setEnvironment(Environment::TEST);
17+
$client->setXApiKey("MockAPIKey");
18+
$client->setTimeout(60);
19+
$client->setConnectionTimeout(30);
20+
21+
$this->assertEquals(
22+
"test",
23+
$client->getConfig()->getEnvironment()
24+
);
25+
}
26+
27+
public function testCreateWithLivePrefix(): void
28+
{
29+
$client = new Client();
30+
$client->setEnvironment(Environment::LIVE);
31+
$client->setXApiKey("MockAPIKey");
32+
33+
// check LIVE Terminal API url
34+
$this->assertEquals(
35+
"https://terminal-api-live.adyen.com",
36+
$client->getConfig()->get('endpointTerminalCloud')
37+
);
38+
}
39+
40+
public function testCreateWithInvalidPrefix(): void
41+
{
42+
// check an exception is thrown
43+
$this->expectException(\Adyen\AdyenException::class);
44+
45+
$client = new Client();
46+
$client->setEnvironment("Invalid");
47+
$client->setXApiKey("MockAPIKey");
48+
}
49+
}

tests/Unit/PosMobileApiTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Adyen\Tests\Unit;
4+
5+
use Adyen\Service\PosMobileApi;
6+
use Adyen\Model\PosMobile\CreateSessionRequest;
7+
use Adyen\Environment;
8+
9+
class PosMobileApiTest extends TestCaseMock
10+
{
11+
12+
/**
13+
* @param $jsonFile
14+
* @param $httpStatus
15+
* @dataProvider posMobileApiProvider
16+
* @throws \Adyen\AdyenException
17+
*/
18+
public function testCreateCommunicationSessionSuccess($jsonFile, $httpStatus): void
19+
{
20+
// create client
21+
$client = $this->createMockClient($jsonFile, $httpStatus, $environment = Environment::LIVE);
22+
23+
24+
// initialize service
25+
$service = new PosMobileApi($client);
26+
27+
$json = '{
28+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
29+
"setupToken": "SETUP_TOKEN",
30+
"store": "YOUR_STORE_ID"
31+
}';
32+
33+
//$params = json_decode($json, true);
34+
$params = new CreateSessionRequest(json_decode($json, true));
35+
36+
$result = $service->createCommunicationSession($params);
37+
38+
$this->assertEquals('APP_SESSION_ID', $result->getId());
39+
}
40+
41+
42+
public static function posMobileApiProvider()
43+
{
44+
return array(
45+
array('tests/Resources/PosMobileApp/create-auth-session.json', 200),
46+
);
47+
}
48+
}

tests/Unit/ServiceTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,44 @@ public function testLiveURLPrefixOther()
5757
$url = $service->createBaseUrl("https://kyc-test.adyen.com/lem/v3/legalEntities");
5858
self::assertEquals("https://kyc-live.adyen.com/lem/v3/legalEntities", $url);
5959
}
60+
61+
// test PosMobileApi LIVE url with prefix
62+
public function testLiveURLPosSdkWithPrefix()
63+
{
64+
$client = new Client();
65+
$client->setEnvironment(Environment::LIVE, "myCompany");
66+
$service = new Service($client);
67+
$url = $service->createBaseUrl("https://checkout-test.adyen.com/checkout/possdk/v68");
68+
self::assertEquals(
69+
"https://myCompany-checkout-live.adyenpayments.com/checkout/possdk/v68",
70+
$url
71+
);
72+
}
73+
74+
// test PosMobileApi TEST url without prefx
75+
public function testTestURLPosSdk()
76+
{
77+
$client = new Client();
78+
$client->setEnvironment(Environment::TEST);
79+
$service = new Service($client);
80+
$url = $service->createBaseUrl("https://checkout-test.adyen.com/checkout/possdk/v68");
81+
self::assertEquals(
82+
"https://checkout-test.adyen.com/checkout/possdk/v68",
83+
$url
84+
);
85+
}
86+
87+
// test PosMobileApi TEST url with prefix
88+
public function testTestURLPosSdkWithPrefix()
89+
{
90+
$client = new Client();
91+
$client->setEnvironment(Environment::TEST, "myCompany");
92+
$service = new Service($client);
93+
$url = $service->createBaseUrl("https://checkout-test.adyen.com/checkout/possdk/v68");
94+
// check prefix is ignored on TEST
95+
self::assertEquals(
96+
"https://checkout-test.adyen.com/checkout/possdk/v68",
97+
$url
98+
);
99+
}
60100
}

0 commit comments

Comments
 (0)