Download the PHP package wayofdev/laravel-stripe-webhooks without Composer

On this page you can find all versions of the php package wayofdev/laravel-stripe-webhooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-stripe-webhooks


Dark WOD logo for light theme Light WOD logo for dark theme



Build Status Total Downloads Latest Stable Version Software License Commits since latest release


Handle Stripe Webhooks in a Laravel application with Cycle-ORM integration

Stripe can notify your application of various events using webhooks. This package simplifies the process of handling those webhooks. Out of the box, it verifies the Stripe signature for all incoming requests.

Once verified, all valid webhook calls will be logged to the database using Cycle-ORM. You can effortlessly define jobs or events to be dispatched when certain events are received by your app.

However, please note that this package only manages the initial webhook request validation and the dispatching of corresponding jobs or events.

The subsequent actions (e.g., regarding payments) should be implemented separately by the developer. Before diving into this package, it's highly recommended to familiarize yourself with Stripe's comprehensive documentation on webhooks.


If you like/use this package, please consider starring it. Thanks!


πŸ’Ώ Installation

β†’ Using Composer

Require as dependency:

The service provider will automatically register itself.

β†’ Configuring the Package

You must publish the config file with:

This is the contents of the config file that will be published at config/stripe-webhooks.php:

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.

β†’ Preparing the Database

By default, all webhook calls will get saved in the database.

To create the table for storing webhook calls:

  1. Ensure you've already set up and are running the wayofdev/laravel-cycle-orm-adapter package in your Laravel project.

  2. Modify the cycle.php config to include the WebhookCall entity in search paths:

  3. After updating the config, run the command to generate migrations for the new entity:

    (Optional): To see a list of pending migrations:

  4. Execute any outstanding migrations:

β†’ Configuring Webhook Routing

On the Stripe dashboard, specify the URL at which Stripe should send webhook requests. In your application's route file, map this URL using Route::stripeWebhooks:

Internally, this command registers a POST route to a controller provided by this package. As Stripe can't retrieve a csrf-token, exclude this route from the VerifyCsrfToken middleware:


πŸ’» Usage

Stripe dispatches webhooks for various event types. View the complete list of event types in Stripe's official 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.

Unless something goes terribly wrong, this package will always respond with a 200 to webhook requests. Sending a 200 will prevent Stripe from resending the same event over and over again. Stripe might occasionally send a duplicate webhook request more than once. This package makes sure that each request will only be processed once. All webhook requests with a valid signature will be logged in the webhook_calls table. The table has a payload column where the entire payload of the incoming webhook is saved.

If the signature is invalid, the package will not log the request but will throw a WayOfDev\StripeWebhooks\Exceptions\WebhookFailed exception. Any errors that occur during a webhook call will be recorded in the exception column. If there's an error, a 500 response will be sent, otherwise a 200 response.

You can handle webhook requests in two ways with this package: by queuing a job or by listening to the package's events.

β†’ Handling Webhook Requests with Jobs

To take action when a specific event type is received, define a job. Here's a job example:

To ensure prompt responses to webhook requests, consider making the job queueable. This allows for efficient handling of multiple Stripe webhook requests, reducing the chance of timeouts.

After creating the job, register it in the jobs array of the stripe-webhooks.php config file. The key should be the name of the stripe event type where but with the . replaced by _. The value should be the fully qualified classname.

In case you want to configure one job as default to process all undefined event, you may set the job at default_job in the stripe-webhooks.php config file. The value should be the fully qualified classname.

By default, the configuration is an empty string '', which will only store the event in database but without handling.

β†’ Handling Webhook Requests with Events

Instead of queueing jobs to perform some work when a webhook request comes in, you can opt to listen to the events this package will fire. Whenever a valid request hits your app, the package will fire a stripe-webhooks::<name-of-the-event> event.

The payload of the events will be the instance of WebhookCall that was created for the incoming request.

Let's take a look at how you can listen for such an event. In the EventServiceProvider you can register listeners.

Here's an example of such a listener:

We highly recommend that you make the event listener queueable, as this will minimize the response time of the webhook requests. This allows you to handle more Stripe webhook requests and avoid timeouts.

To learn about other ways to handle events in Laravel, check out Laravel's official documentation on event handling.


βš™οΈ Advanced Usage

β†’ Retry Handling a Webhook

All incoming webhook requests are written to the database. This is incredibly valuable when something goes wrong while handling a webhook call. You can easily retry processing the webhook call, after you've investigated and fixed the cause of failure, like this:

β†’ Performing Custom Logic

You can add some custom logic that should be executed before and/or after the scheduling of the queued job by using your own entity. You can do this by specifying your own entity in the entity key of the stripe-webhooksconfig file. The class should extend WayOfDev\StripeWebhooks\Bridge\Laravel\Jobs\ProcessStripeWebhookJob.

Here's an example:

β†’ Determine if a Request Should be Processed

You may use your own logic to determine if a request should be processed or not. You can do this by specifying your own profile in the profile key of the stripe-webhooks config file. The class should implement WayOfDev\WebhookClient\Contracts\WebhookProfile.

In this example we will make sure to only process a request if it wasn't processed before.

β†’ Handling Multiple Signing Secrets

When using Stripe Connect you might want to the package to handle multiple endpoints and secrets. Here's how to configurate that behaviour.

If you are using the Route::stripeWebhooks macro, you can append the configKey as follows:

Alternatively, if you are manually defining the route, you can add configKey like so:

If this route parameter is present the verify middleware will look for the secret using a different config key, by appending the given the parameter value to the default config key. E.g. If Stripe posts to webhook-url/my-named-secret you'd add a new config named signing_secret_my-named-secret.

Example config for Connect might look like:

β†’ Transforming the Webhook Payload into a Stripe Object

You can transform the Webhook payload into a Stripe object to assist in accessing its various methods and properties.

To do this, use the Stripe\Event::constructFrom($payload) method with the WebhookCall's payload:

For example, if you have setup a Stripe webhook for the invoice.created event, you can transform the payload into a StripeInvoice object:


⚑️Sequence Diagram


πŸ§ͺ Running Tests

β†’ PHPUnit Tests

To run tests, run the following command:

β†’ Static Analysis

Code quality using PHPStan:

β†’ Coding Standards Fixing

Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:


🀝 License


🧱 Credits and Useful Resources

This repository is based on the spatie/laravel-stripe-webhooks work.


πŸ™†πŸΌβ€β™‚οΈ Author Information

Created in 2023 by lotyp / wayofdev


πŸ™Œ Want to Contribute?

Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:


All versions of laravel-stripe-webhooks with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
cycle/database Version ^2.8
cycle/orm Version ^2.7
laravel/framework Version ^v10.46
stripe/stripe-php Version ^14.0
wayofdev/laravel-webhook-client Version ^1.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wayofdev/laravel-stripe-webhooks contains the following files

Loading the files please wait ....