InPost Pay (Basket_App)

InPost Pay (Basket_App)

InPost Pay (Basket App) - it is a module that provides access to the API that allows to exchange information about the basket and process the order. This section contains information regarding the API methods made available by InPost for the purposes of communication between the Merchant and InPost Pay.

InPost Pay API

Production environment

Address of the production environment: https://api.inpost.pl

Sandbox environment

Address of the test environment: https://sandbox-api.inpost.pl

List of endpoints

The table below includes the list of InPost Pay application endpoints used for the purposes of communication between the Merchant and the InPost Pay application.

 

 

Method

Description

Basket

PUT /v2/izi/basket/{basket_id}

A method used only to update a basket, e.g. change the quantity of products, delivery method, etc.

DELETE /v1/izi/basket/{basket_id}/binding

A method used to desynchronize the basket and the phone number

PUT /v2/izi/basket/{basket_id}/binding

A method used to initialize the process of linking a basket.

GET /v1/izi/basket/{basket_id}/binding

A method used to verify whether a basket is linked to the InPost app

GET /v1/izi/baskets

Optional back office endpoint, returns the list of baskets for the Merchant

Order

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

Order update

GET /v1/izi/orders

Optional back office endpoint, returns the list of orders for the Merchant

Payment

GET /v1/izi/payment-methods

Returns payment methods available to the Merchant – method available in the next version of the application

Signature verification

GET /v1/izi/signing-keys/public

Returns public signing keys

GET /v1/izi/signing-keys/public/{version}

Returns public signing key for a version

 

Example implementation in PHP

  • We create an interface for the customer’s website that will be responsible for Merchant -> InPost - InPost Pay (Basket App) communication.

    <?php declare(strict_types=1); namespace Iteo\InpostPayClient\Client; use Iteo\InpostPayClient\SDK\Basket\BasketApp\Basket; use Iteo\InpostPayClient\SDK\Basket\Binding\BindingBasket; use Iteo\InpostPayClient\SDK\Basket\Binding\QrCode\QrCodeData; use Iteo\InpostPayClient\SDK\Basket\Binding\Request\BasketApp\BasketBindingRequest; use Iteo\InpostPayClient\SDK\Basket\Response\BasketsResponse; use Iteo\InpostPayClient\SDK\Basket\Response\InpostBasketId; use Iteo\InpostPayClient\SDK\Core\Exceptions\InpostPayEndpointException; use Iteo\InpostPayClient\SDK\Core\Exceptions\InpostPayPostBasketBindingException; use Iteo\InpostPayClient\SDK\Core\Exceptions\InpostPayPostOrderEventException; use Iteo\InpostPayClient\SDK\Order\Request\BasketApp\OrderEventRequest; use Iteo\InpostPayClient\SDK\Order\Response\BasketApp\OrdersResponse; use Iteo\InpostPayClient\SDK\SignatureVerification\SigningKeys\SigningKeysResponse; use Iteo\InpostPayClient\SDK\SignatureVerification\SigningVersionKey\SigningKeyResponse; /** * Client interface used for communication between Merchant and InPost Pay application. */ interface InpostPayClientInterface { /** * This method verify if basket is connected with InPost app. * * @param string $basketId ID basket assigned by merchant * @param string|null $browserId Browser ID from cookie * * @return BindingBasket Object with information about whether the browser is trusted * and whether the basket is linked * * @throws InpostPayEndpointException */ public function getBasketBinding(string $basketId, ?string $browserId): BindingBasket; /** * This method connect basket with InPost app. * * @param string $basketId ID basket assigned by merchant * @param BasketBindingRequest $requestBody Request data, needed for binding basket * * @return ?QrCodeData Object with data for QR Code when successful binding with QR Code or null * when successful binding with phone number * * @throws InpostPayPostBasketBindingException|InpostPayEndpointException */ public function postBasketBinding(string $basketId, BasketBindingRequest $requestBody): ?QrCodeData; /** * This method desynchronize basket with Inpost Pay mobile app. * * @param string $basketId ID basket assigned by merchant * @param ?bool $ifBasketRealized Information about the fact that the basket will be deleted because * it has been realized * * @throws InpostPayEndpointException */ public function deleteBasketBinding(string $basketId, ?bool $ifBasketRealized): void; /** * This method updates or creates a basket e.g. change products quantity, delivery type etc. * * @param string $basketId ID basket assigned by merchant * @param Basket $basket All Basket data * * @return InpostBasketId Object with basket ID created from Inpost mobile app * * @throws InpostPayEndpointException */ public function putBasket(string $basketId, Basket $basket): InpostBasketId; /** * This method update order. * * @param string $orderId ID order assigned by merchant * @param OrderEventRequest $orderEventRequest Information about order event, that will change order status * * @throws InpostPayPostOrderEventException|InpostPayEndpointException */ public function postOrderEvent(string $orderId, OrderEventRequest $orderEventRequest): void; /** * This method deletes binded browser from Inpost Pay mobile app. * * @param string $browserId ID browser from cookie * * @throws InpostPayEndpointException */ public function deleteBrowserBinding(string $browserId): void; /** * This method get baskets list for merchant. * * @param ?int $pageIndex Information about page index of merchant baskets list * @param ?int $pageSize Information about page size of merchant baskets list page * * @return BasketsResponse Object containing list of baskets for merchant for strict page index * * @throws InpostPayEndpointException */ public function getBaskets(?int $pageIndex, ?int $pageSize): BasketsResponse; /** * This method get orders list for merchant. * * @param ?int $pageIndex Information about page index of merchant orders list * @param ?int $pageSize Information about page size of merchant orders list page * * @return OrdersResponse Object containing list of orders for merchant for strict page index * * @throws InpostPayEndpointException */ public function getOrders(?int $pageIndex, ?int $pageSize): OrdersResponse; /** * This method get public signing keys. * * @return SigningKeysResponse Object containing list of public signing keys * * @throws InpostPayEndpointException */ public function getSigningKeys(): SigningKeysResponse; /** * This method get public signing key for version. * * @param string $version Version of signing-key * * @return SigningKeyResponse Object containing public signing key * * @throws InpostPayEndpointException */ public function getSigningKey(string $version): SigningKeyResponse; }

  • We create an interface for the URL creator that will be responsible for obtaining the right URL address to the InPost Pay API.

    <?php declare(strict_types=1); namespace Iteo\InpostPayClient\Client; /** * Interface used for creating url for communication with Inpost Pay. */ interface InpostPayURLCreatorInterface { /** * Method that return url for Inpost Pay. * * @return InpostPayURL url for Inpost Pay */ public function create(): InpostPayURL; }

  • We create an implementation of the URL creator service for the Sandbox environment.

    <?php declare(strict_types=1); namespace Iteo\InpostPayClient\Client; /** * PHP URL Creator Service implementation used for creating url to Sandbox InpostPay. */ final class SandboxInPostPayURLCreator implements InpostPayURLCreatorInterface { /** * {@inheritdoc} */ public function create(): InpostPayURL { return new InpostPayURL('https://sandbox-api.inpost.pl/v1/izi/'); } }

  • We create an implementation of the URL creator service for the Production environment.

    <?php declare(strict_types=1); namespace Iteo\InpostPayClient\Client; /** * PHP URL Creator Service implementation used for creating url to Production InpostPay. */ final class ProductionInPostPayURLCreator implements InpostPayURLCreatorInterface { /** * {@inheritdoc} */ public function create(): InpostPayURL { return new InpostPayURL('https://api.inpost.pl/v1/izi/'); } }

  • We create an implementation of the client’s website using a PSR client for REST communication, a previously implemented URL creator interface to obtain a URL to the InPost Pay API, and a bearer service interface to obtain the access token. In order for the client to be fully effective, it is necessary to implement functions described in the interface, responsible for specific endpoints included on the List of endpoints.

    /** * 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; } /** * @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 ); } }