Aktualizacja zamówienia

Artykuł zawiera opis metody wykorzystywanej do aktualizacji informacji o zamówieniu wraz z przykładem implementacji metody w języku PHP.

Opis metody

Metoda służy do aktualizacji informacji o zamówieniu w aplikacji InPost Pay (powiadomienia przekazywane do InPost Pay przez Merchanta o wystąpieniu zamiany na zamówieniu).

Parameters 

Nazwa pola 

Opis  

Typ 

Wymagalność 

Dodatkowe uwagi 

order_id 

Unikalny identyfikator zamówienia nadawany przez merchanta 

string 

  

 

Request  

Nazwa pola 

Opis  

Typ 

Wymagalność 

Dodatkowe uwagi 

event_id

Unikalny identyfikator eventu 

string 

"event_id":1694704936

event_data_time

Data wystąpienia zdarzenia 

string 

"event_data_time":"2023-09-14T15:22:16.000Z"

phone_number

Obiekt służący do przekazania numeru telefonu klienta 

object 

 

phone_number.country_prefix

Prefix 

string 

"phone_number":{"country_prefix":"+48","phone":"600000000"}

phone_number.phone

Numer telefonu klienta 

string 

event_data

Obiekt służący do przekazania danych eventu 

object 

 

event_data.order_status

Status techniczny - służy do określenia uprawnień, jakie może wykonać klient na zamówieniu w aplikacji InPost Pay. Merchant może przekazać dwa statusy:  

  

ORDER_COMPLETED - status nadawany przez Merchanta, informujący aplikacje InPost Pay, że zamówienie zostało sfinalizowane przez klienta na stronie sklepu Merchanta. Nie wysyłamy tego statusu dla zamówień, które zostały opłacone w aplikacji InPost.

ORDER_REJECTED - status oznacza odrzucenie zamówienia. 

string 

"order_status":"ORDER_COMPLETED"

event_data.order_merchant_status_description

Status opisowy prezentowany klientowi w aplikacji InPost Pay - każdy Merchant może przekazać status tak, aby statusy prezentowane w InPost Mobile były zgodne ze statusem prezentowanym klientowi w sklepie Merchanta. 

string 

"order_merchant_status_description":"W trakcie realizacji"

event_data.delivery_references_list

Obiekt służący do przekazania listy numerów referencyjnych nadanych przesyłek 

array 

"delivery_references_list":[12345678]

  

Response 

200 – aktualizacja danych zakończona sukcesem 

POST /v1/izi/order/{order_id}/event

Przykładowy request 

{ "event_id": "xxxxxxxxxx", "event_data_time": "2023-08-23T09:26:45.000Z", "phone_number": { "country_prefix": "+48", "phone": "6xxxxxxxx" }, "event_data": { "order_status": "ORDER_COMPLETED", "order_merchant_status_description": "W trakcie realizacji", "delivery_references_list": [ "" ] } }

 

 

 

Przykład implementacji w języku PHP

  • Podanie kodu -

W pliku implementacjaKlienta.txt została dodana tylko funkcja postOrderEvent.

/** * Client symfony implementation used for communication between Merchant and InPost Pay application. * * @param InpostPayBearerServiceInterface $inpostPayBearerService <p> Bearer service interface, * with contains creating bearer token which is required for communication with Inpost Pay </p> * */ final class InpostPayClient implements InpostPayClientInterface { private ClientInterface $client; private InpostPayURLCreatorInterface $URLCreator; private InpostPayBearerServiceInterface $bearerService; public function __construct( ClientInterface $client, InpostPayURLCreatorInterface $URLCreator, InpostPayBearerServiceInterface $bearerService ) { $this->client = $client; $this->URLCreator = $URLCreator; $this->bearerService = $bearerService; } public function getBaskets(int $pageIndex = null, int $pageSize = null): BasketsResponse { $path = 'baskets'; $uri = (new Uri($this->buildUri($path))) ->withQuery(Psr7\Query::build(['page_index' => $pageIndex, 'page_size' => $pageSize])); $request = new Request( 'GET', $uri, $this->provideDefaultClientHeaders() ); try { $response = $this->client->sendRequest($request); $content = $response->getBody()->getContents(); /** * @var BasketsResponseArray $data */ $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR); return BasketsResponse::fromArray($data); } catch (\Throwable $throwable) { throw InpostPayGetBasketsException::createResponseException($throwable); } } public function getBasketBinding(string $basketId, string $browserId = null): BindingBasket { $path = sprintf('basket/%s/binding', $basketId); $uri = (new Uri($this->buildUri($path))) ->withQuery(Psr7\Query::build(['browser_id' => $browserId])); $request = new Request( 'GET', $uri, $this->provideDefaultClientHeaders() ); try { $response = $this->client->sendRequest($request); $content = $response->getBody()->getContents(); /** * @var BindingBasketArray $data */ $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR); return BindingBasket::fromArray($data); } catch (\Throwable $throwable) { throw InpostPayGetBasketBindingException::createResponseException($throwable); } } public function postBasketBinding(string $basketId, BasketBindingRequest $requestBody): ?QrCodeData { if (BindingMethod::PHONE()->equals($requestBody->getBindingMethod()) && !$requestBody->getPhoneNumber()) { throw InpostPayPostBasketBindingException::createNoPhoneForPhoneBindingMethodException(); } $path = sprintf('basket/%s/binding', $basketId); $uri = new Uri($this->buildUri($path)); /** @var string $body */ $body = json_encode($requestBody); $request = new Request( 'POST', $uri, $this->provideDefaultClientHeaders(), $body ); try { $response = $this->client->sendRequest($request); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); if (HttpResponseStatus::ACCEPTED()->getValue() === $statusCode) { return null; } if (HttpResponseStatus::OK()->getValue() === $statusCode) { /** * @var QrCodeDataArray $data */ $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR); return QrCodeData::fromArray($data); } } catch (\Throwable $throwable) { throw InpostPayPostBasketBindingException::createResponseException($throwable); } throw InpostPayPostBasketBindingException::createBadStatusCodeException($statusCode, $content); } public function putBasket(string $basketId, Basket $basket): InpostBasketId { $path = sprintf('basket/%s', $basketId); $uri = new Uri($this->buildUri($path)); /** @var string $body */ $body = json_encode($basket); $request = new Request( 'PUT', $uri, $this->provideDefaultClientHeaders(), $body ); try { $response = $this->client->sendRequest($request); $content = $response->getBody()->getContents(); /** * @var array{inpost_basket_id: string} $responseData */ $responseData = json_decode($content, true, 512, JSON_THROW_ON_ERROR); return InpostBasketId::fromArray($responseData); } catch (\Throwable $throwable) { throw InpostPayPutBasketException::createResponseException($throwable); } } public function deleteBasketBinding(string $basketId, bool $ifBasketRealized = null): void { $path = sprintf('basket/%s/binding', $basketId); $uri = (new Uri($this->buildUri($path))) ->withQuery(Psr7\Query::build(['if_basket_realized' => $ifBasketRealized])); $request = new Request( 'DELETE', $uri, $this->provideDefaultClientHeaders() ); try { $response = $this->client->sendRequest($request); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); } catch (\Throwable $throwable) { throw InpostPayDeleteBasketBindingException::createResponseException($throwable); } if (HttpResponseStatus::NO_CONTENT()->getValue() === $statusCode) { return; } throw InpostPayDeleteBasketBindingException::createBadStatusCodeException($statusCode, $content); } public function deleteBrowserBinding(string $browserId): void { $path = sprintf('browser/%s/binding', $browserId); $uri = new Uri($this->buildUri($path)); $request = new Request( 'DELETE', $uri, $this->provideDefaultClientHeaders() ); try { $response = $this->client->sendRequest($request); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); } catch (\Throwable $throwable) { throw InpostPayDeleteBrowserBindingException::createResponseException($throwable); } if (HttpResponseStatus::NO_CONTENT()->getValue() === $statusCode) { return; } throw InpostPayDeleteBrowserBindingException::createBadStatusCodeException($statusCode, $content); } public function getSigningKey(string $version): SigningKeyResponse { $path = sprintf('signing-keys/public/%s', $version); $uri = new Uri($this->buildUri($path)); $request = new Request( 'GET', $uri, $this->provideDefaultClientHeaders() ); try { $response = $this->client->sendRequest($request); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); if (HttpResponseStatus::OK()->getValue() === $statusCode) { /** * @var SigningKeyResponseArray $data */ $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR); return SigningKeyResponse::fromArray($data); } } catch (\Throwable $throwable) { throw InpostPayGetSigningKeyException::createResponseException($throwable); } throw InpostPayGetSigningKeyException::createBadStatusCodeException($statusCode, $content); } public function getSigningKeys(): SigningKeysResponse { $path = 'signing-keys/public'; $uri = new Uri($this->buildUri($path)); $request = new Request( 'GET', $uri, $this->provideDefaultClientHeaders() ); try { $response = $this->client->sendRequest($request); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); if (HttpResponseStatus::OK()->getValue() === $statusCode) { /** * @var SigningKeysResponseArray $data */ $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR); return SigningKeysResponse::fromArray($data); } } catch (\Throwable $throwable) { throw InpostPayGetSigningKeysException::createResponseException($throwable); } throw InpostPayGetSigningKeysException::createBadStatusCodeException($statusCode, $content); } /** * @return array{ * Authorization: string, * Content-Type: string * } * * @throws InpostPayEndpointException */ private function provideDefaultClientHeaders(): array { return [ 'Authorization' => sprintf('Bearer %s', $this->bearerService->getBearerToken()), 'Content-Type' => 'application/json', ]; } private function buildUri(string $path): string { return sprintf( '%s%s', $this->URLCreator->create()->getUrl(), $path ); } public function postOrderEvent(string $orderId, OrderEventRequest $orderEventRequest): void { $path = sprintf('order/%s/event', $orderId); $uri = new Uri($this->buildUri($path)); /** @var string $body */ $body = json_encode($orderEventRequest); $request = new Request( 'POST', $uri, $this->provideDefaultClientHeaders(), $body ); try { $response = $this->client->sendRequest($request); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); } catch (\Throwable $throwable) { throw InpostPayPostOrderEventException::createResponseException($throwable); } if (HttpResponseStatus::CREATED()->getValue() === $statusCode) { return; } throw InpostPayPostOrderEventException::createBadStatusCodeException($statusCode, $content); } }
  • W SDK.zip zawiera się kod zawierający obiekt requestu oraz response endpointu.