conedevelopment / bazar-stripe
Bazar的Stripe支付集成。
v1.1.2
2024-09-26 12:46 UTC
Requires
- php: ^8.2 || ^8.3
- conedevelopment/bazar: dev-master || ^1.1.0
- stripe/stripe-php: ^15.4
Requires (Dev)
- fakerphp/faker: ^1.9.1
- laravel/laravel: ^11.0
- laravel/pint: ^1.6
- mockery/mockery: ^1.4.4
- nunomaduro/larastan: ^2.1.6
- phpunit/phpunit: ^10.2.5
This package is auto-updated.
Last update: 2024-09-26 12:47:13 UTC
README
安装
composer require conedevelopment/bazar-stripe
配置
.env
STRIPE_TEST_MODE= STRIPE_API_KEY= STRIPE_SECRET=
Bazar配置
// config/bazar.php 'gateway' => [ 'drivers' => [ // ... 'stripe' => [ 'test_mode' => env('STRIPE_TEST_MODE', false), 'api_key' => env('STRIPE_API_KEY'), 'secret' => env('STRIPE_SECRET'), ], ], ], // ...
Webhook事件
php artisan make:listener StripeWebhookHandler
namespace App\Listeners; use Cone\Bazar\Stripe\WebhookInvoked; use Stripe\Event; class StripeWebhookHandler { public function handle(WebhookInvoked $event): void { // https://stripe.com/docs/api/events/types $callback = match ($event->event->type) { 'payment_intent.payment_failed' => function (Event $event): void { // mark transaction as failed }, 'payment_intent.succeeded' => function (Event $event): void { // mark transaction as completed and order as paid }, default => function (): void { // }, }; call_user_func_array($callback, [$event->event]); } }
提示
如果事件发现已禁用,请确保监听器已绑定到您的EventServiceProvider
中的WebhookInvoked
事件。