Order update
The article contains a description of the method used to update an order's information together with an example implementation of the method in PHP.
On this page:
Description of the method
The method is used to update an order's information in the InPost Pay app (notifications transferred to InPost Pay by the Merchant of a change in the order).
Parameters
Field name | Description | Type | Requirement status | Additional remarks |
| Order's unique ID assigned by the merchant | string | Y |
|
Request
Field name | Description | Type | Requirement status | Additional remarks |
| Event's unique ID | string | Y |
|
| Event's date | string | Y |
|
| Object intended to transfer the customer's phone number | object | O |
|
| Prefix | string | Y |
|
| The customer's phone number | string | Y | |
| Object intended to transfer the event's data | object | Y |
|
| Technical status - used to specify the authorizations that the customer may exercise for the order in the InPost Pay app. The merchant may provide two statuses:
| string | O |
|
| A descriptive status presented to the customer in the InPost Pay app - each Merchant may provide the status so that the statuses presented in InPost Mobile are compliant with the status presented to the client in the merchant's store. | string | O |
|
| Object intended to transfer the list of reference numbers of the shipments dispatched | array | O |
|
Response
200 – data updated successfully
POST /v1/izi/order/{order_id}/event
Example 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": [
""
]
}
}
Example implementation in PHP
Entering the code -
In the implementacjaKlienta.txt file, only the postOrderEvent function was added.
/**
* 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);
}
}
SDK.zip contains a code which includes the object of the request and of the endpoint response.