uzzal/sslcommerz

Laravel 适配 SSLCommerz 支付网关的库

v1.0.0 2020-05-03 08:44 UTC

This package is auto-updated.

Last update: 2024-09-29 05:33:59 UTC


README

SSLCommerz 是 Laravel 框架的支付网关库。官方文档位于 此处

安装

composer require uzzal/sslcommerz

发布

artisan vendor:publish

此命令将在 config 目录中创建一个 sslcommerz.php 文件。在您的 .env 文件中配置您的参数

#sslcommerz
STORE_ID=your_store_id
STORE_PASSWORD=your_store_password
SUCCESS_URL=http://your-domain.at/success.php
FAIL_URL=http://your-domain.at/fail.php
CANCEL_URL=http://your-domain.at/cancel.php
SANDBOX_MODE=true

启动支付会话

initSession 将为您提供网关 URL。使用此 URL,您将通过 sslcommerz 继续支付。

$customer = new Customer('Mahabubul Hasan', 'mahabub@example.com', '0171xxxxx22');
$resp = Client::initSession($customer, 29); //29 is the amount
echo $resp->getGatewayUrl();

或使用配置

$customer = new Customer('Mahabubul Hasan', 'mahabub@example.com', '0171xxxxx22');
$config[SessionRequest::EMI] = '0';
$resp = Client::initSession($customer, 29, $config);
echo $resp->getGatewayUrl();

请求验证

verifyOrder 方法接收一个 val_id 参数,您将在 IPN 请求中获得此参数。

$resp = Client::verifyOrder('180828114058np43AJdzJJOsYzc');
echo 'status: '.$resp->getStatus();
echo 'transaction: '.$resp->getTransactionId();

IPN 监听器(步骤 4,5)

在填写卡信息并提交 sslcommerz 窗口后,它将向您指定的 IPN URL 发送 IPN 通知。要获取通知,请使用以下代码。更多详细信息,请 见此处

if(ipn_hash_varify(config('sslcommerz.store_password'))){
    $ipn = new IpnNotification($_POST);
    $val_id = $ipn->getValId();
    $transaction_id = $ipn->getTransactionId();
    $amount = $ipn->getAmount();
    $resp = Client::verifyOrder($val_id);
} 

SSLCommerz 处理流程

alt text