mariojgt / gateway
此包旨在将支付网关与应用程序集成
2.4.1
2022-02-22 11:09 UTC
Requires
- php: ^7.3|^8.0
- braintree/braintree_php: 6.5.1
- gocardless/gocardless-pro: ^4.15
- stripe/stripe-php: ^7.113.0
README
Laravel Gateway,与laravel 9兼容
#composer require mariojgt/gateway
这是一个为简化实现流程而设计的Laravel包,支持Stripe等可用集成(未来还将支持更多网关集成,PayPal也即将推出)
如何使用
在Blade文件中执行以下操作
-
<x-gateway::pay_stripe /> 此组件将添加所有javascript方法,以便我们生成会话并重定向用户。
-
在按钮上需要添加此方法 RegenerateSessionAndRedirect
<button onclick="RegenerateSessionAndRedirect()" Pay with Stripe Example </button>
此方法将向您的服务器发送请求并生成一个密钥,以便我们在javascript结算中使用。
-
在配置文件中,您有stripe_session_generate密钥,需要将其指向您的laravel控制器之一,您可以使用get或post进行此操作。
-
使用以下示例代码生成会话
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中使用它
-
您还可以使用以下方法检查会话状态
use Mariojgt\Gateway\Controllers\StripeContoller; $stipeManager = new StripeContoller(); $session = $stipeManager->checkSession('Session_id');
这将返回会话信息和支付信息。
注意
在生产环境中,通过更改gateway配置文件中的demo_mode键值到false来禁用网站演示。