Deleting the binding of a basket

The article contains a description of the method used to remove the binding of a basket together with an example implementation of the method in PHP.

Description of the method

The method used to remove a basket from the InPost Pay app. Disconnection from the bound phone number. A method used in the cases when:

  • the customer has a basket bound and wants to bind the basket to another phone number, then, first, they need to remove its binding with the previous

  • the Merchant experiences a business situation based on which it is required to remove a basket from the InPost Pay app, for instance the realization of the basket in the Merchant's store.

 

Parameters 

Field name

Description

Type

Requirement status

Additional remarks

basket_id

Basket's unique ID assigned by the merchant

string

Y

 

if_basket_realized

A flag used to notify that the reason for the removal of the basket is the realization of the basket at the merchant's store.

If the abovementioned situation exists, then transfer the value true. In other cases, the flag is not required

 

boolean

O

 

Request – none

Response – none. 204 – this means that the removal of the basket was successful.


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

Example implementation in PHP

  • Entering the code -

Only the deleteBasketBinding function has been added in the implementacjaKlienta.txt file.

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