InPost Pay (Basket App)


InPost Pay (Basket App) - jest to moduł udostępniający API, pozwalający na wymianę informacji o koszyku i realizacji zamówienia. W tej sekcji znajdziesz informacje o metodach API udostępnionych przez InPost służących do komunikacji pomiędzy Merchantem a InPost Pay.

InPost Pay API

Środowisko produkcyjne

Adres środowiska produkcyjnego: https://api.inpost.pl

Środowisko sandbox

Adres środowiska testowego: https://sandbox-api.inpost.pl

Lista endpointów

Poniższa tabel przedstawia listę endpointów wystawionych przez aplikacje InPost Pay, służących do komunikacji pomiędzy Merchantem a aplikacją InPost Pay.

 

Metoda

Opis

Przeglądarka

DELETE /v1/izi/browser/{browser_id}/binding

Metoda usuwa powiązaną przeglądarkę lub usuwa telefon z powiązanej przeglądarki.

Koszyk

PUT /v1/izi/basket/{basket_id}

Metoda aktualizuje lub tworzy koszyk, np. zmienia ilość produktów, typ dostawy itp

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

Desynchronizacja koszyka z numerem telefonu

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

Metoda łączy koszyk z aplikacją InPost

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

Metoda sprawdza, czy koszyk jest połączony z aplikacją InPost

GET /v1/izi/baskets

Opcjonalny endpoint back office'owy, zwraca listę koszyków dla Merchanta

Zamówienie

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

Aktualizacja zamówienia

GET /v1/izi/orders

Opcjonalny endpoint back office'owy, zwraca listę zamówień dla Merchanta

Płatności

GET /v1/izi/payment-methods

Zwraca metody płatności dostępne dla Merchanta - metoda dostępna w kolejnej wersji aplikacji

Weryfikacja sygnatury

GET /v1/izi/signing-keys/public

Zwraca publiczne klucze podpisujące

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

Zwraca publiczny klucz podpisujący dla wersji




 

Przykład implementacji w języku PHP

  • Tworzymy interfejs serwisu klienta, który będzie odpowiedzialny za komunikację Merchant -> InPost - .

    <?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; }

  • Tworzymy interfejs url creatora, który będzie odpowiedzialny za uzyskanie odpowiedniego adresu url do API InPostPay'a.

    <?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; }

  • Tworzymy implementację serwisu url creatora dla środowiska Sandbox.

    <?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/'); } }

  • Tworzymy implementację serwisu url creatora dla środowiska Produkcyjnego.

  • Tworzymy implementację serwisu klienta, wykorzystując do tego PSR'owego klienta do komunikacji REST, oraz wcześniej zaimplementowany interfejs url creatora aby uzyskać url do API InpostPay'a oraz interfejs serwisu bearera aby uzyskać access token. Aby klient był w całości sprawny, potrzebna jest implementacja funkcji opisanych w interfejsie, odpowiedzialnych za konkretne endpointy w Lista endpointów.