PHP code example of xnf4o / sberbank

1. Go to this page and download the library: Download xnf4o/sberbank 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/ */

    

xnf4o / sberbank example snippets


use Xnf4o\Sberbank;

$access_token  = 'sberbank_secret_token';

$sberbank = new Sberbank(true, ['access_token' => $access_token]);

$login = 'sberbank_login';
$password  = 'sberbank_password';

$sberbank = new Sberbank(false, ['login' => $login, 'password' => $password]);

//Подготовка массива с данными об оплате
$payment = [
    'orderNumber'   => '1234567',                           //Номер заказа
    'amount'        => 100,                                 //Сумма заказа в рублях
    'language'      => 'ru',                                //Локализация
    'description'   => 'New payment',                       //Описание заказа
    'returnUrl'     => 'http://my.site/successful-payment', //URL сайта в случае успешной оплаты
    'failUrl'       => 'http://my.site/fail-payment',       //URL сайта в случае НЕуспешной оплаты
];

//Получение url для оплаты
$result = $sberbank->paymentURL($payment);

//Контроль ошибок
if(!$result['success']){
  echo($result['error']);
} else{
  $payment_id = $result['payment_id'];
  return redirect($result['payment_url']);
}

//$payment_id Идентификатор платежа банка (полученый в пункте "2 Получить URL для оплаты")

$result = $sberbank->getState($payment_id)

//Контроль ошибок
if(!$result['success']){
  echo($result['error']);
} else{
  echo($result['payment_status']);
}