xenon/sslcommerz

Laravel 对 SSLCommerz 支付网关的库

v1.0.3 2023-03-07 19:43 UTC

This package is auto-updated.

Last update: 2024-09-19 10:14:40 UTC


README

这是 uzzal/sslcommerz 包的分支,用于 Laravel。这是 Laravel 框架的 SSLCommerz 支付网关库。官方文档在这里:here

安装

composer require xenon/sslcommerz

发布

php artisan vendor:publish --provider=Xenon\SslCommerz\SslCommerzServiceProvider

此命令将在 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
IPN_URL=http://your-domain.at/ipn.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);
}