用于获取 Sberbank 和 Alphabank REST API 的 PHP 客户端
PHP client for Sberbank, Alfabank and YooKassa REST APIs.
php-json extension installedcomposer require 'voronkovich/sberbank-acquiring-client'In most cases to instantiate a client you need to pass your username and password to a factory:
…Alternatively you can use an authentication token:
$client = ClientFactory::sberbank(['token' => 'sberbank-token']);More advanced example:
…Also you can use an adapter for the Guzzle:
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()),
]);Also, there are available adapters for Symfony and PSR-18 HTTP clents.
You can interact with the Gateway REST API using a low level method execute:
$client->execute('/ecomm/gw/partner/api/v1/register.do', [
'orderNumber' => 1111,
'amount' => 10,
'returnUrl' => 'http://localhost/sberbank/success',
]);
$status = $client->execute('/ecomm/gw/partner/api/v1/getOrderStatusExtended.do', [
'orderId' => '64fc8831-a2b0-721b-64fc-883100001553',
]);But it's more convenient to use one of the shortcuts listed below.
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);If you want to use UUID identifiers (ramsey/uuid) for orders you should convert them to a hex format:
use Ramsey\Uuid\Uuid;
$orderId = Uuid::uuid4();
$result = $client->registerOrder($orderId->getHex(), $orderAmount, $returnUrl);Use a registerOrderPreAuth method to create a 2-step order.
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!";
}Also, you can get an order's status by using you own identifier (e.g. assigned by your database):
$result = $client->getOrderStatusByOwnId($orderId);$result = $client->reverseOrder($orderId);$result = $client->refundOrder($orderId, $amountToRefund);Currently only supported by Alfabank, see docs.
$result = $client->getSbpDynamicQr($orderId, [
'qrHeight' => 100,
'qrWidth' => 100,
'qrFormat' => 'image',
]);
echo sprintf(
'',
$result['payload'],
'data:image/png;base64,' . $result['renderedQr']
);See Client source code to find methods for payment bindings and dealing with 2-step payments.
Copyright (c) Voronkovich Oleg. Distributed under the MIT.
暂无开放 Issues,或尚未同步最近议题。