PHP code example of vlsv / sber-api-registry-oauth-client

1. Go to this page and download the library: Download vlsv/sber-api-registry-oauth-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-api-registry-oauth-client example snippets




$config = new \Vlsv\SberApiRegistryOauthClient\ClientConfig(
    clientId: 'client_id',
    clientSecret: 'client_secret',
    certPath: 'cert_path',
    certPassword: 'cert_password',
);

$oAuthClient = new \Vlsv\SberApiRegistryOauthClient\OAuthClient($config);

// OAUTH-токен
try {
    $accessToken = $oAuthClient
        ->getOauthToken(scope: 'https://api.sberbank.ru/qr/order.create')
        ->getAccessToken();
} catch (\Vlsv\SberApiRegistryOauthClient\Exception\ApiException $exception) {
    echo $exception->getMessage();

    if ($exception->getResponseObject()) {
        echo $exception->getResponseObject()->getMoreInformation();
    }
} catch (\Throwable $exception) {
    echo $exception->getMessage();
}

// OIDC-токен
try {
    $accessToken = $oAuthClient->getOidcToken(
       scope: 'https://api.sberbank.ru/qr/order.create',
       code: 'authorization_code',
       redirectUri: 'redirect_uri',
   )->getAccessToken();
} catch (\Vlsv\SberApiRegistryOauthClient\Exception\ApiException $exception) {
    echo $exception->getMessage();

    if ($exception->getResponseObject()) {
        echo $exception->getResponseObject()->getMoreInformation();
    }
} catch (\Throwable $exception) {
    echo $exception->getMessage();
}