PHP code example of voronkovich / sberbank-acquiring-client
1. Go to this page and download the library: Download voronkovich/sberbank-acquiring-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/ */
voronkovich / sberbank-acquiring-client example snippets
use Voronkovich\SberbankAcquiring\ClientFactory;
use Voronkovich\SberbankAcquiring\Currency;
use Voronkovich\SberbankAcquiring\HttpClient\HttpClientInterface;
$client = ClientFactory::sberbank([
'userName' => 'username',
'password' => 'password',
// A language code in ISO 639-1 format.
// Use this option to set a language of error messages.
'language' => 'ru',
// A currency code in ISO 4217 format.
// Use this option to set a currency used by default.
'currency' => Currency::RUB,
// An HTTP method to use in requests.
// Must be "GET" or "POST" ("POST" is used by default).
'httpMethod' => HttpClientInterface::METHOD_GET,
// An HTTP client for sending requests.
// Use this option when you don't want to use
// a default HTTP client implementation distributed
// with this package (for example, when you have'nt
// a CURL extension installed in your server).
'httpClient' => new YourCustomHttpClient(),
]);
use Voronkovich\SberbankAcquiring\ClientFactory;
use Voronkovich\SberbankAcquiring\HttpClient\GuzzleAdapter;
use GuzzleHttp\Client as Guzzle;
$client = ClientFactory::sberbank([
'userName' => 'username',
'password' => 'password',
'httpClient' => new GuzzleAdapter(new Guzzle()),
]);
use Voronkovich\SberbankAcquiring\Currency;
// Required arguments
$orderId = 1234;
$orderAmount = 1000;
$returnUrl = 'http://mycoolshop.local/payment-success';
// You can pass additional parameters like a currency code and etc.
$params['currency'] = Currency::EUR;
$params['failUrl'] = 'http://mycoolshop.local/payment-failure';
$result = $client->registerOrder($orderId, $orderAmount, $returnUrl, $params);
$paymentOrderId = $result['orderId'];
$paymentFormUrl = $result['formUrl'];
header('Location: ' . $paymentFormUrl);
use Ramsey\Uuid\Uuid;
$orderId = Uuid::uuid4();
$result = $client->registerOrder($orderId->getHex(), $orderAmount, $returnUrl);
use Voronkovich\SberbankAcquiring\OrderStatus;
$result = $client->getOrderStatus($orderId);
if (OrderStatus::isDeposited($result['orderStatus'])) {
echo "Order #$orderId is deposited!";
}
if (OrderStatus::isDeclined($result['orderStatus'])) {
echo "Order #$orderId was declined!";
}