lexty/robokassa

Robokassa支付系统的PHP库

2.0.0 2020-05-28 17:27 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:14:39 UTC


README

Build Status Latest Stable Version Latest Unstable Version Total Downloads License SensioLabsInsight

安装

$ composer require lexty/robokassa

示例

创建支付

$payment = new \Lexty\Robokassa\Payment(
    new \Lexty\Robokassa\Auth('your_login', 'password1', 'password2', true)
);

$payment
    ->setInvoiceId($orderId)
    ->setSum($orderAmount)
    ->setCulture(Payment::CULTURE_EN)
    ->setDescription('Payment for some goods');

// redirect to payment url
header("Location: {$payment->getPaymentUrl()}");

// or show payment button on page
// <script src="<?php echo $payment->getFormUrl(Payment::FORM_TYPE_L); ?>"></script>

检查支付结果

// somewhere in result url handler...
...
$payment = new \Lexty\Robokassa\Payment(
    new \Lexty\Robokassa\Auth('your_login', 'password1', 'password2', true)
);

if ($payment->validateResult($_GET) {

    // send answer
    echo $payment->getSuccessAnswer(); // "OK123\n"
}
...

检查成功页面上的支付

...
$payment = new \Lexty\Robokassa\Payment(
    new \Lexty\Robokassa\Auth('your_login', 'password1', 'password2', true)
);

if ($payment->validateSuccess($_GET) {
    // payment is valid
}
...

支付买家的佣金

为了支付买家的佣金,只需简单地调用$payment->setShopCommission(true)

请注意,在支付页面ROBOKASSA的用户可以更改佣金的其他支付方式。在这种情况下,他将支付不同的金额。

获取货币列表

Robokassa API

返回特定商店/网站可支付的订单的货币列表。

用于指定$payment->setPaymentMethod($method)的值,并在您的网站上显示可用的支付选项,如果您希望向客户提供更多信息。

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$currencies = $client
	->setCulture(Client::CULTURE_EN)
	->getCurrencies();

返回

array (
  array (
    'Code' => 'Terminals',
    'Description' => 'terminal ',
    'Items' => 
    array (
      array (
        'Label' => 'TerminalsElecsnetOceanR',
        'Alias' => 'Elecsnet',
        'Name' => 'Elecsnet',
        'MaxValue' => '15000',
      ),
    ),
  ),
  array (
    'Code' => 'EMoney',
    'Description' => 'e-wallet',
    'Items' => 
    array (
      array (
        'Label' => 'W1OceanR',
        'Alias' => 'W1',
        'Name' => 'RUR W1',
        'MaxValue' => '14999',
      ),
      array (
        'Label' => 'ElecsnetWalletR',
        'Alias' => 'ElecsnetWallet',
        'Name' => 'ElecsnetWallet',
        'MaxValue' => '14999',
      ),
    ),
  ),
)

获取可用的支付方法组列表

Robokassa API

返回特定商店/网站可支付的订单的支付方法列表。用于在您的网站上显示可用的支付方法,如果您希望向客户提供更多信息。与$payment->getCurrencies()的区别是,这里不显示所有支付选项的详细信息,而只显示支付组/方法。

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$paymentMethodGroups = $client
	->setCulture(Client::CULTURE_EN)
	->getPaymentMethodGroups();

返回

array (
  'Terminals' => 'terminal ',
  'EMoney' => 'e-wallet',
  'BankCard' => 'Bank card',
  'Bank' => 'Internet Banking',
  'Other' => 'other methods ',
)

计算包括ROBOKASSA费用在内的应付金额

Robokassa API

帮助计算买家的应付金额,包括ROBOKASSA的服务计划费用以及其他系统通过该系统决定支付订单的费用。这可以用于您的内部支付,也可以在您的网站上向客户提供额外的信息。

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$rates = $client
	->setCulture(Client::CULTURE_EN)
	->getRates(500);

返回

array (
  array (
    'Code' => 'Terminals',
    'Description' => 'terminal ',
    'Items' => 
    array (
      array (
        'Label' => 'TerminalsElecsnetOceanR',
        'Alias' => 'Elecsnet',
        'Name' => 'Elecsnet',
        'MaxValue' => '15000',
        'ClientSum' => 534.76,
      ),
    ),
  ),
  array (
    'Code' => 'EMoney',
    'Description' => 'e-wallet',
    'Items' => 
    array (
      array (
        'Label' => 'W1OceanR',
        'Alias' => 'W1',
        'Name' => 'RUR W1',
        'MaxValue' => '14999',
        'ClientSum' => 537.63,
      ),
      array (
        'Label' => 'ElecsnetWalletR',
        'Alias' => 'ElecsnetWallet',
        'Name' => 'ElecsnetWallet',
        'MaxValue' => '14999',
        'ClientSum' => 535,
      ),
    ),
  ),
)

外发金额计算

Robokassa API

帮助根据ROBOKASSA的现行汇率,从用户的应付金额计算可收到的金额。

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$sum = $client->calculateClientSum(500, 'TerminalsElecsnetOceanR'); // 534.76

操作状态

Robokassa API

返回有关当前状态和支付详情的详细信息。

请注意,交易不是在用户被重定向到支付页面时发起的,而是在他的支付详情被确认后发起的,即您可能看不到应该已经启动的交易。

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$invoice = $client
    ->setCulture(Client::CULTURE_EN)
    ->getInvoice(1);

返回

array (
  'InvoiceId' => 1,
  'StateCode' => 100,
  'RequestDate' => \DateTime object,
  'StateDate' => \DateTime object,
  'PaymentMethod' => 'HandyBankKB',
  'ClientSum' => 100,
  'ClientAccount' => 'Test account',
  'PaymentMethodCode' => 'eInvoicing',
  'PaymentMethodDescription' => 'Internet bank',
  'Currency' => 'MerchantR',
  'ShopSum' => 94.5,
)

许可

MIT