Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Artykuł zawiera opis metody wykorzystywanej do usunięcia przeglądarki zaufanej wraz z przykładem implementacji w języku PHP.

Lista metod:


Na tej stronie:

Table of Contents
minLevel1
maxLevel6
outlinefalse
typelist
printablefalse

Usuwanie powiązanej przeglądarki

Metoda wykorzystywana do usunięcia przeglądarki zaufanej. Wykorzystywana w przypadku, gdy użytkownik posiada przeglądarkę zaufaną i w procesie wiązania koszyka, chce połączyć koszyk z innym numerem telefonu. 

Status
colourRed
titleDELETE
/v1/izi/browser/{browser_id}/binding

Parameters 

Nazwa pola 

Opis  

Typ 

Wymagalność 

Dodatkowe uwagi 

browser_id id

Id przeglądarki zaufanej nadany przez Inpost InPost Pay, który został zwrócony w procesie wiązania koszyka w request metody POST/v1/izi/basket/{basket_id}/confirmation 

string 

 

 

Request – brak 

Response – brak. 204 – oznacza, że usunięcie przeglądarki zaufanej zakończone sukcesem. 


Status
colourRed
titleDELETE
/v1/izi/browser/{browser_id}/binding

Przykład implementacji w języku PHP

  • Podanie kodu -

    View file
    nameimplementacjaKlienta.txt
    .

Panel
panelIconIdatlassian-info
panelIcon:info:
bgColor#DEEBFF

Do istniejącego kodu w pliku implementacjaKlienta.txt została dodana funkcja deleteBrowserBinding.

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