PHP code example of vlsv / sber-pay-qr-api-client

1. Go to this page and download the library: Download vlsv/sber-pay-qr-api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vlsv / sber-pay-qr-api-client example snippets


$orderParamsType = (new \Vlsv\SberPayQrApiClient\Entity\RequestCreationOrderParamsType())
    ->setPositionName('some_position_name')
    ->setPositionCount(1)
    ->setPositionDescription('some_position_description')
    ->setPositionSum(190000);

$requestCreation = (new \Vlsv\SberPayQrApiClient\Entity\RequestCreation())
    ->setMemberId('some_member_id')
    ->setOrderCreateDate(new DateTimeImmutable())
    ->setOrderParamsType([$orderParamsType]);

try {
    /** @var \Vlsv\SberPayQrApiClient\Entity\ResponseCreation $responseCreation */
    $responseCreation = $this->apiClient->makeRequest(
        accessToken: 'personal_temporary_access_token',
        apiEndpoint: \Vlsv\SberPayQrApiClient\Entity\ApiEndpoint::CREATION,
        requestObject: $requestCreation,
    );
} catch (ApiException $exception) {
    echo $exception->getMessage();

    exit();
}

// Идентификатор заказа на стороне эквайера.
// Необходим для дальнейшей работы с API.
echo $responseCreation->getOrderId();

// Ссылка на форму оплаты - QR-код.
echo $responseCreation->getOrderFormUrl();

$requestStatus = (new \Vlsv\SberPayQrApiClient\Entity\RequestStatus())
    ->setOrderId('5cf8cb8b-37e3-42e9-8f69-306fa72e106f')
    ->setTid('83457dda-332c-46f4-b928-8d4bd9ee3afe');

try {
    /** @var \Vlsv\SberPayQrApiClient\Entity\ResponseStatus $responseStatus */
    $responseStatus = $this->apiClient->makeRequest(
        accessToken: 'personal_temporary_access_token',
        apiEndpoint: \Vlsv\SberPayQrApiClient\Entity\ApiEndpoint::STATUS,
        requestObject: $requestStatus,
    );
} catch (\Vlsv\SberPayQrApiClient\Entity\ApiException $exception) {
    echo $exception->getMessage();

    exit();
}

// Состояние заказа на стороне эквайера.
echo $responseStatus->getOrderState()->value;