mariojgt/gateway

此包旨在将支付网关与应用程序集成

安装: 101

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 1

开放问题: 0

语言:Blade

类型:laravel

2.4.1 2022-02-22 11:09 UTC

This package is auto-updated.

Last update: 2024-09-26 00:37:05 UTC


README

image info

Laravel Gateway,与laravel 9兼容

#composer require mariojgt/gateway

这是一个为简化实现流程而设计的Laravel包,支持Stripe等可用集成(未来还将支持更多网关集成,PayPal也即将推出)

如何使用

在Blade文件中执行以下操作

  1. <x-gateway::pay_stripe /> 此组件将添加所有javascript方法,以便我们生成会话并重定向用户。

  2. 在按钮上需要添加此方法 RegenerateSessionAndRedirect

     <button onclick="RegenerateSessionAndRedirect()"
    	Pay with Stripe Example
    </button>

    此方法将向您的服务器发送请求并生成一个密钥,以便我们在javascript结算中使用。

  3. 在配置文件中,您有stripe_session_generate密钥,需要将其指向您的laravel控制器之一,您可以使用get或post进行此操作。

  4. 使用以下示例代码生成会话

    use Mariojgt\Gateway\Controllers\StripeContoller;
    
    public function sessionGenerate(Request $request)
        {
            // Start the stripe class
            $stipeManager = new StripeContoller();
            // Cart example, you Must folow this stucture
            $cartItem = [
                [
                    'name'        => 'kit kat',
                    'description' => 'Kit kat product',
                    'images'      => ['https://www.kitkat.com/images/main-logo-snap.png'],
                    'amount'      => 500, // Amount in pence value * 100
                    'currency'    => config('gateway.currency'),
                    'quantity'    => 2,
                ],
            ];
            // Send the cart item so stripe can create a valid session
            $session      = $stipeManager->process($cartItem);
            // Return a stripe session so we can use in the front end to redirect the user
            return response()->json([
                'session' => $session->id,
            ]);
        }

    此代码将返回一个json会话,我们可以在javascript中使用它

  5. 您还可以使用以下方法检查会话状态

use Mariojgt\Gateway\Controllers\StripeContoller;
$stipeManager = new StripeContoller();
$session      = $stipeManager->checkSession('Session_id');

这将返回会话信息和支付信息。

注意

在生产环境中,通过更改gateway配置文件中的demo_mode键值到false来禁用网站演示。