PHP code example of nomokonov / sber-sdk-php

1. Go to this page and download the library: Download nomokonov/sber-sdk-php 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/ */

    

nomokonov / sber-sdk-php example snippets


use Nomokonov\SberSdk\Authorization\ApiClient;

$client = new ApiClient([
    'host'            => 'https://iftfintech.testsbi.sberbank.ru:9443',
    'p12Path'         => '/path/to/SBBAPI_xxx.p12',
    'p12Password'     => 'certpass',
    // For production, pass the full certificate chain:
    // 'caPath'       => [__DIR__ . '/certs/sberca-ext.crt', __DIR__ . '/certs/sberca-root-ext.crt'],
    'caPath'          => '/path/to/russiantrustedca2024.pem',
    'connectTimeout'  => 60000, // ms, default 60000
    'readTimeout'     => 60000, // ms, default 60000
    'enableLogs'      => true,  // default false
    'maxRetries'      => 3,     // default 3
    'retryDelay'      => 1000,  // ms, default 1000
]);

$client = new ApiClient($config, httpClient: null, logger: $psr3Logger);

$client = new ApiClient(['host' => 'https://...'], $guzzleClient);

// Obtain an access token
$token = $client->getAccessToken([
    'code'          => $authorizationCode,
    'client_id'     => $clientId,
    'redirect_uri'  => 'https://example.com/callback',
    'client_secret' => $clientSecret,
]);
$accessToken = $token['access_token'];

// Refresh the token
$client->getRefreshToken([
    'refresh_token' => $refreshToken,
    'client_id'     => $clientId,
    'redirect_uri'  => 'https://example.com/callback',
    'client_secret' => $clientSecret,
]);

// Revoke the token
$client->getRevokeToken($accessToken, [
    'client_id'       => $clientId,
    'client_secret'   => $clientSecret,
    'token'           => $accessToken,
    'token_type_hint' => 'access_token',
]);

// Rotate the client secret (a new secret is generated automatically)
$result = $client->getChangeClientSecret($accessToken, [
    'client_id'     => $clientId,
    'client_secret' => $clientSecret,
]);
// $result['new_client_secret'], $result['clientSecretExpiration']

// User info (with JWT decoding)
$info = $client->getUserInfo($accessToken);
// $info['userInfoBodyResponse'], $info['jwt']

use Nomokonov\SberSdk\Authorization\SecurityService;

$security = new SecurityService();
$verifier  = $security->generatePkceCodeVerifier();
$challenge = $security->generatePkceCodeChallenge($verifier);

use Nomokonov\SberSdk\Authorization\SignatureVerificationService;

$verifier = new SignatureVerificationService('/path/to/sber-signing-cert.cer');
$verifier->verifyJwt($token['id_token']); // true or SignatureVerificationException

use Nomokonov\SberSdk\H2H\H2hClient;

$h2h = new H2hClient($client);

$dict       = $h2h->getDictionary($accessToken, 'banks'); // ['name' => ..., 'content' => ...]
$clientInfo = $h2h->getClientInfo($accessToken);
$crypto     = $h2h->getCrypto($accessToken);

// Certificates
$h2h->certificateRequest($accessToken, $certRequest);
$h2h->activateCert($accessToken, $externalId);
$pdf = $h2h->printCert($accessToken, $externalId); // raw PDF bytes
$h2h->getCertState($accessToken, $externalId);

// Payments
$h2h->createPayment($accessToken, $paymentRequest);
$h2h->getPayment($accessToken, $externalId);
$h2h->getPaymentDocState($accessToken, $externalId);

// Statements
$h2h->getStatementSummary($accessToken, $accountNumber, $statementDate);
$h2h->getStatementTransactions($accessToken, $accountNumber, $statementDate, 1);

// Payroll sheets
$h2h->createPayroll($accessToken, $payrollRequest);

// SBP B2B payment links
$h2h->createPaymentLink($accessToken, $linkRequest);
$h2h->getPaymentLinkList($accessToken, '550e8400-e29b-41d4-a716-446655440000');

use Nomokonov\SberSdk\InstantPayment\InstantPaymentClient;
use Nomokonov\SberSdk\InstantPayment\CryptoprofileType;

$instant = new InstantPaymentClient($client);

$instant->getPaymentInvoice($accessToken, $invoiceRequest);        // fixed requisites
$instant->getPaymentInvoiceBudget($accessToken, $budgetRequest);   // budget payment
$instant->getPaymentInvoiceAny($accessToken, $anyRequest);         // free requisites
$instant->getPaymentState($accessToken, $externalId);

$url = $instant->buildPaymentUrl(
    externalId: $externalId,
    backUrl: 'https://shop.example/return',
    cryptoprofileType: CryptoprofileType::SMS,
    isProd: false,
);
bash
composer