sajaiaiuri/laravel-bogpayment

Laravel 的格鲁吉亚银行支付集成

安装: 1

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 4

类型:项目

1.0.3 2024-04-05 09:17 UTC

This package is auto-updated.

Last update: 2024-09-05 10:09:39 UTC


README

Packagist Packagist license

laravel-bogpayment

目录

安装

要开始,您需要安装该包

composer require zgabievi/laravel-bogpayment

如果您的 Laravel 版本低于 5.5,则将以下内容添加到 config/app.php 中的服务提供者

'providers' => [
    ...
    Zorb\BOGPayment\BOGPaymentServiceProvider::class,
    ...
];

您可以使用此命令发布配置文件

php artisan vendor:publish --provider="Zorb\BOGPayment\BOGPaymentServiceProvider"

此命令将为您复制配置文件。

使用

支付

默认流程有几个需要完成的步骤

  1. 重定向到卡详情页面
  2. 银行将在您的路由上检查付款详情
  3. 银行将在您的路由上注册付款详情

步骤 #1

在这个步骤中,您应该将用户重定向到卡详情页面

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentController extends Controller
{
    //
    public function __invoke()
    {
        return BOGPayment::redirect([
            'order_id' => 1,
        ], false);
    }
}

传递您想要在检查和注册步骤中接收的任何参数作为第一个值。(默认:[]

第二个值是布尔值,表示您是否想要预先授权支付,锁定金额。(默认:false

步骤 #2

在这个步骤中,银行将检查您是否已准备好接受支付。

这个过程称为 PaymentAvail

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentCheckController extends Controller
{
    //
    public function __invoke()
    {
        // chek that http authentication is correct
        BOGPayment::checkAuth();

        // check if you are getting request from allowed ip
        BOGPayment::checkIpAllowed();

        // check if you can find order with provided id
        $order_id = BOGPayment::getParam('o.order_id');
        $order = Order::find($order_id);
    
        if (!$order) {
            BOGPayment::sendError('check', 'Order couldn\'t be found with provided id');
        }

        $trx_id = BOGPayment::getParam('trx_id');

        // send success response
        BOGPayment::sendSuccess('check', [
            'amount' => $order->amount,
            'short_desc' => $order->short_desc,
            'long_desc' => $order->long_desc,
            'trx_id' => $trx_id,
            'account_id' => config('bogpayment.account_id'),
            'currency' => config('bogpayment.currency'),
        ]);
    }
}

在此处检查 请求参数

步骤 #3

在这个步骤中,银行将提供付款的详细信息。

这个过程称为 RegisterPayment

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentRegisterController extends Controller
{
    //
    public function __invoke()
    {
        // chek that http authentication is correct
        BOGPayment::checkAuth();

        // check if you are getting request from allowed ip
        BOGPayment::checkIpAllowed();

        // check if provided signature matches certificate
        BOGPayment::checkSignature('register');

        // check if you can find order with provided id
        $order_id = BOGPayment::getParam('o.order_id');
        $order = Order::find($order_id);
    
        if (!$order) {
            BOGPayment::sendError('check', 'Order couldn\'t be found with provided id');
        }

        $trx_id = BOGPayment::getParam('trx_id');
        $result_code = BOGPayment::getParam('result_code');

        if (empty($result_code)) {
            BOGPayment::sendError('register', 'Result code has not been provided');
        }
    
        if ((int)$result_code === 1) {
            // payment has been succeeded
        } else {
            // payment has been failed
        }

        // send success response
        BOGPayment::sendSuccess('register');
    }
}

在此处检查 请求参数

周期性支付

周期性流程与默认流程相同。区别在于用户不必再次填写卡详情。

  1. 请求将发送到银行以启动周期性流程
  2. 银行将在您的路由上检查付款详情
  3. 银行将在您的路由上注册付款详情
use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentRecurringController extends Controller
{
    //
    public function __invoke(string $trx_id)
    {
        return BOGPayment::repeat($trx_id, [
            'recurring' => true,
        ]);
    }
}

在您的检查和注册控制器中,您可以捕获 BOGPayment::getParam('o.recurring') 参数,现在您将知道这个过程来自周期性请求。

退款

为了退款,您需要支付交易的 trx_id 和 rrn。

use Zorb\BOGPayment\Facades\BOGPayment;

class PaymentRefundController extends Controller
{
    //
    public function __invoke(string $trx_id, string $rrn)
    {
        $result = BOGPayment::refund($trx_id, $rrn);

        if ((int)$result->code === 1) {
            // refund process succeeded
        } else {
            // refund process failed
        }
    }
}

在此处检查 结果参数

附加信息

检查请求的参数

注册请求的参数

退款结果

扩展结果代码

环境变量

许可

zgabievi/laravel-bogpayment 依照 MIT 许可 许可。