Skip to content

Commit b419fbb

Browse files
authored
Merge pull request #12 from tweet9ra/add_get_intergration_connection
add_get_intergration_connection
2 parents f87418c + 4e33933 commit b419fbb

File tree

4 files changed

+139
-7
lines changed

4 files changed

+139
-7
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"doctrine/cache": "^1.8",
2727
"guzzlehttp/guzzle": "^6.3",
2828
"symfony/property-access": "^3.4 | ^4.0 | ^5.0",
29-
"symfony/serializer": "^3.4 | ^4.0 | ^5.0"
29+
"symfony/serializer": "^3.4 | ^4.0 | ^5.0",
30+
"ext-json": "*"
3031
},
3132
"require-dev": {
3233
"phpunit/phpunit": "^8.5.12 | ^9.0"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Lamoda\OmsClient\V2\Dto;
4+
5+
final class GetIntegrationConnectionResponse
6+
{
7+
public const STATUS_SUCCESS = 'SUCCESS';
8+
public const STATUS_REJECTED = 'REJECTED';
9+
10+
/**
11+
* @var string
12+
*/
13+
private $status;
14+
15+
/**
16+
* @var string|null
17+
*/
18+
private $omsConnection;
19+
20+
/**
21+
* @var string|null
22+
*/
23+
private $rejectionReason;
24+
25+
/**
26+
* @param string $status
27+
* @param string|null $omsConnection
28+
* @param string|null $rejectionReason
29+
*/
30+
public function __construct(string $status, ?string $omsConnection, ?string $rejectionReason)
31+
{
32+
$this->status = $status;
33+
$this->omsConnection = $omsConnection;
34+
$this->rejectionReason = $rejectionReason;
35+
}
36+
37+
/**
38+
* @return string
39+
*/
40+
public function getStatus(): string
41+
{
42+
return $this->status;
43+
}
44+
45+
/**
46+
* @return string|null
47+
*/
48+
public function getOmsConnection(): ?string
49+
{
50+
return $this->omsConnection;
51+
}
52+
53+
/**
54+
* @return string|null
55+
*/
56+
public function getRejectionReason(): ?string
57+
{
58+
return $this->rejectionReason;
59+
}
60+
}

src/V2/OmsApi.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Lamoda\OmsClient\V2\Dto\CreateOrderForEmissionICResponse;
1818
use Lamoda\OmsClient\V2\Dto\GetICBufferStatusResponse;
1919
use Lamoda\OmsClient\V2\Dto\GetICsFromOrderResponse;
20+
use Lamoda\OmsClient\V2\Dto\GetIntegrationConnectionResponse;
2021
use Lamoda\OmsClient\V2\Dto\PingResponse;
2122
use Lamoda\OmsClient\V2\Signer\SignerInterface;
2223

@@ -124,6 +125,22 @@ public function closeICArray(
124125
return $this->serializer->deserialize(CloseICArrayResponse::class, $result);
125126
}
126127

128+
public function getIntegrationConnection(string $address, string $omsId, string $registrationKey, SignerInterface $signer = null): GetIntegrationConnectionResponse {
129+
$body = json_encode(['address' => $address]);
130+
131+
$headers = [
132+
'X-RegistrationKey' => $registrationKey
133+
];
134+
$headers = $this->appendSignatureHeader($headers, $body, $signer);
135+
136+
$result = $this->request(null, 'POST', '/api/v2/integration/connection', [
137+
'omsId' => $omsId,
138+
], $body, $headers);
139+
140+
/* @noinspection PhpIncompatibleReturnTypeInspection */
141+
return $this->serializer->deserialize(GetIntegrationConnectionResponse::class, $result);
142+
}
143+
127144
public function ping(Extension $extension, string $token, string $omsId): PingResponse
128145
{
129146
$url = sprintf('/api/v2/%s/ping', (string)$extension);
@@ -137,19 +154,21 @@ public function ping(Extension $extension, string $token, string $omsId): PingRe
137154
* @throws OmsRequestErrorException
138155
*/
139156
private function request(
140-
string $token,
157+
?string $token,
141158
string $method,
142159
string $uri,
143160
array $query = [],
144161
$body = null,
145162
$headers = []
146-
): string {
163+
): string
164+
{
165+
$headers['Content-Type'] = 'application/json';
166+
if ($token != null) {
167+
$headers['clientToken'] = $token;
168+
}
147169
$options = [
148170
RequestOptions::BODY => $body,
149-
RequestOptions::HEADERS => array_merge($headers, [
150-
'Content-Type' => 'application/json',
151-
'clientToken' => $token,
152-
]),
171+
RequestOptions::HEADERS => $headers,
153172
RequestOptions::QUERY => $query,
154173
RequestOptions::HTTP_ERRORS => true,
155174
];

tests/V2/OmsApiTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Lamoda\OmsClient\V2\Dto\CreateOrderForEmissionICResponse;
1919
use Lamoda\OmsClient\V2\Dto\GetICBufferStatusResponse;
2020
use Lamoda\OmsClient\V2\Dto\GetICsFromOrderResponse;
21+
use Lamoda\OmsClient\V2\Dto\GetIntegrationConnectionResponse;
2122
use Lamoda\OmsClient\V2\Dto\PingResponse;
2223
use Lamoda\OmsClient\V2\Extension;
2324
use Lamoda\OmsClient\V2\OmsApi;
@@ -460,4 +461,55 @@ public function testPing(): void
460461
$this->assertEquals($expectedResult, $result);
461462
}
462463

464+
public function testGetIntegrationConnection(): void
465+
{
466+
$this->client->expects($this->once())
467+
->method('request')
468+
->with(
469+
'POST',
470+
'api/v2/integration/connection',
471+
[
472+
RequestOptions::BODY => $requestBody = json_encode([
473+
'address' => $address = 'Kremlin 1, Moscow, Russia'
474+
]),
475+
RequestOptions::HEADERS => [
476+
'X-RegistrationKey' => $registrationKey = 'registration-key-received-from-ismp-support',
477+
'X-Signature' => $signature = 'signature',
478+
'Content-Type' => 'application/json',
479+
],
480+
RequestOptions::QUERY => [
481+
'omsId' => $omsId = 'oms-id-string',
482+
],
483+
RequestOptions::HTTP_ERRORS => true,
484+
]
485+
)
486+
->willReturn(
487+
(new Response())
488+
->withBody(stream_for(self::API_RESPONSE))
489+
);
490+
491+
$expectedResult = new GetIntegrationConnectionResponse(GetIntegrationConnectionResponse::STATUS_SUCCESS, $address, null);
492+
$this->serializer->expects($this->once())
493+
->method('deserialize')
494+
->with(
495+
GetIntegrationConnectionResponse::class,
496+
self::API_RESPONSE
497+
)
498+
->willReturn($expectedResult);
499+
500+
501+
$signer = $this->createMock(SignerInterface::class);
502+
$signer->method('sign')
503+
->with($requestBody)
504+
->willReturn($signature);
505+
506+
$result = $this->api->getIntegrationConnection(
507+
$address,
508+
$omsId,
509+
$registrationKey,
510+
$signer
511+
);
512+
513+
$this->assertEquals($expectedResult, $result);
514+
}
463515
}

0 commit comments

Comments
 (0)