voronkovich/sberbank-acquiring-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

voronkovich/sberbank-acquiring-client

Composer 安装命令:

composer require voronkovich/sberbank-acquiring-client

包简介

Client for working with Sberbank's acquiring REST API

README 文档

README

Build Status Latest Stable Version Total Downloads License

PHP client for Sberbank, Alfabank and YooKassa REST APIs.

Requirements

  • PHP 7.1 or above (Old version for PHP 5 you can find here)
  • TLS 1.2 or above (more information you can find here)
  • php-json extension installed

Installation

composer require 'voronkovich/sberbank-acquiring-client'

Usage

Instantiating a client

In most cases to instantiate a client you need to pass your username and password to a factory:

use Voronkovich\SberbankAcquiring\ClientFactory;

// Sberbank production environment
$client = ClientFactory::sberbank(['userName' => 'username', 'password' => 'password']);

// Sberbank testing environment
$client = ClientFactory::sberbankTest(['userName' => 'username', 'password' => 'password']);

// Alfabank production environment
$client = ClientFactory::alfabank(['userName' => 'username', 'password' => 'password']);

// Alfabank testing environment
$client = ClientFactory::alfabankTest(['userName' => 'username', 'password' => 'password']);

// YooKassa production environment
$client = ClientFactory::yookassa(['userName' => 'username', 'password' => 'password']);

Alternatively you can use an authentication token:

$client = ClientFactory::sberbank(['token' => 'sberbank-token']);

More advanced example:

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(),
]);

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.

Low level method "execute"

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.

Creating a new order

Sberbank Alfabank

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.

Getting a status of an exising order

Sberbank Alfabank

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);

Reversing an exising order

Sberbank Alfabank

$result = $client->reverseOrder($orderId);

Refunding an exising order

Sberbank Alfabank

$result = $client->refundOrder($orderId, $amountToRefund);

SBP payments using QR codes

Currently only supported by Alfabank, see docs.

$result = $client->getSbpDynamicQr($orderId, [
    'qrHeight' => 100,
    'qrWidth' => 100,
    'qrFormat' => 'image',
]);

echo sprintf(
    '<a href="%s"><img src="%s" /></a>',
    $result['payload'],
    'data:image/png;base64,' . $result['renderedQr']
);

See Client source code to find methods for payment bindings and dealing with 2-step payments.

License

Copyright (c) Voronkovich Oleg. Distributed under the MIT.

voronkovich/sberbank-acquiring-client 适用场景与选型建议

voronkovich/sberbank-acquiring-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 348.74k 次下载、GitHub Stars 达 193, 最近一次更新时间为 2016 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「client」 「credit card」 「sberbank」 「acquiring」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 voronkovich/sberbank-acquiring-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 voronkovich/sberbank-acquiring-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 voronkovich/sberbank-acquiring-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 348.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 196
  • 点击次数: 25
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 193
  • Watchers: 18
  • Forks: 58
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-28