idma / robokassa
Robokassa支付系统的PHP库
v1.0.0
2024-04-15 08:14 UTC
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-09-15 09:11:14 UTC
README
安装
通过Composer安装此包。在你的 composer.json
文件中添加
{ "require": { "idma/robokassa": "dev-master" } }
示例
创建支付
$payment = new \Idma\Robokassa\Payment( 'john_doe', 'password1', 'password2', true ); $payment ->setInvoiceId($order->id) ->setSum($order->amount) ->setDescription('Payment for some goods'); // redirect to payment url $user->redirect($payment->getPaymentUrl());
针对命名数据
// for details - https://docs.robokassa.ru/fiscalization/ $receiptData = array( 'items' => array([ 'sum' => $sum, 'name' => 'name of order', 'quantity' => 1, 'tax' => 'none', ]) ); $payment ->setInvoiceId($order->id) ->setSum($order->amount) ->setDescription('Payment for some goods') ->addReceiptData($receiptData); ... Check payment result: ```php // somewere in result url handler... ... $payment = new \Idma\Robokassa\Payment( 'john_doe', 'password1', 'password2', true ); if ($payment->validateResult($_GET) { $order = Orders::find($payment->getInvoiceId()); if ($payment->getSum() == $order->sum) { } // send answer echo $payment->getSuccessAnswer(); // "OK1254487\n" } ...
在成功页面上检查支付
... $payment = new \Idma\Robokassa\Payment( 'john_doe', 'password1', 'password2', true ); if ($payment->validateSuccess($_GET) { $order = Orders::find($payment->getInvoiceId()); if ($payment->getSum() == $order->sum) { // payment is valid } } ...