Chisle
코딩 에이전트 플러그인, 20개 실시간 작업에서 기본 모델 52% 활용, 간결한 페르소나와 출력 압축 제공
Handle Stripe webhooks in a Laravel application
README 전체를 불러오는 중입니다.
README 전문 보기 ↗Stripe can notify your application of events using webhooks. This package can help you handle those webhooks. Out of the box it will verify the Stripe signature of all incoming requests. All valid calls will be logged to the database. You can easily define jobs or events that should be dispatched when specific events hit your app.
This package will not handle what should be done after the webhook request has been validated and the right job or event is called. You should still code up any work (eg. regarding payments) yourself.
Before using this package we highly recommend reading the entire documentation on webhooks over at Stripe.
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Please see UPGRADING for details.
You can install the package via composer:
composer require spatie/laravel-stripe-webhooks
The service provider will automatically register itself.
You must publish the config file with:
php artisan vendor:publish --provider="Spatie\StripeWebhooks\StripeWebhooksServiceProvider"
This is the contents of the config file that will be published at config/stripe-webhooks.php:
return [
/*
* Stripe will sign each webhook using a secret. You can find the used secret at the
* webhook configuration settings: https://dashboard.stripe.com/account/webhooks.
*/
'signing_secret' => env('STRIPE_WEBHOOK_SECRET'),
/*
* You can define a default job that should be run for all other Stripe event type
* without a job defined in next configuration.
* You may leave it empty to store the job in database but without processing it.
*/
'default_job' => '',
/*
* You can define the job that should be run when a certain webhook hits your application
* here. The key is the name of the Stripe event type with the `.` replaced by a `_`.
*
* You can find a list of Stripe webhook types here:
* https://stripe.com/docs/api#event_types.
*/
'jobs' => [
// 'source_chargeable' => \App\Jobs\StripeWebhooks\HandleChargeableSource::class,
// 'charge_failed' => \App\Jobs\StripeWebhooks\HandleFailedCharge::class,
],
/*
* The classname of the model to be used. The class should equal or extend
* Spatie\WebhookClient\Models\WebhookCall.
*/
'model' => \Spatie\WebhookClient\Models\WebhookCall::class,
/**
* This class determines if the webhook call should be stored and processed.
*/
'profile' => \Spatie\StripeWebhooks\StripeWebhookProfile::class,
/*
* Specify a connection and or a queue to process the webhooks
*/
'connection' => env('STRIPE_WEBHOOK_CONNECTION'),
'queue' => env('STRIPE_WEBHOOK_QUEUE'),
/*
* When disabled, the package will not verify if the signature is valid.
* This can be handy in local environments.
*/
'verify_signature' => env('STRIPE_SIGNATURE_VERIFY', true),
];
In the signing_secret key of the config file you should add a valid webhook secret. You can find the secret used at the webhook configuration settings on the Stripe dashboard.
Next, you must publish the migration with:
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-migrations"
After the migration has been published you can create the webhook_calls table by running the migrations:
php artisan migrate
Finally, take care of the routing: At the Stripe dashboard you must configure at what url Stripe webhooks should hit your app. In the routes file of your app you must pass that route to Route::stripeWebhooks:
Route::stripeWebhooks('webhook-route-configured-at-the-stripe-dashboard');
Behind the scenes this will register a POST route to a controller provided by this package. Because Stripe has no way of getting a csrf-token, you must add that route to the except array of the VerifyCsrfToken middleware:
protected $except = [
'webhook-route-configured-at-the-stripe-dashboard',
];
Stripe will send out webhooks for several event types. You can find the full list of events types in the Stripe documentation.
Stripe will sign all requests hitting the webhook url of your app. This package will automatically verify if the signature is valid. If it is not, the request was probably not sent by Stripe.
여기까지가 README 앞부분입니다. 나머지는 원문에서 읽을 수 있습니다. README 전문 보기 ↗