Installation and setup | laravel-stripe-webhooks-go | Spatie       

 SPATIE  

laravel-stripe-webhooks-go
==========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-stripe-webhooks-go](https://spatie.be/docs/laravel-stripe-webhooks-go/v1)  Installation and setup

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-stripe-webhooks-go/v1) 

  Installation and setup    
- [ Introduction ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/usage)
- [ Advanced usage ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/advanced-usage)
- [ Testing ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-stripe-webhooks-go/v1/support-us)

 Installation and setup
======================

###  On this page 

1. [ Signing secret ](#content-signing-secret)
2. [ Configuration ](#content-configuration)
3. [ Storage and routing ](#content-storage-and-routing)

Requires Go 1.27 or newer and Laravel Go `go.laravel.com v0.1.0`.

You can install the package with Go:

```
go get github.com/spatie/laravel-stripe-webhooks-go@v0.1.0
```

The package depends on Webhook Client Go v0.1.0. Go resolves that dependency automatically. Adding a Go module does not activate it. Install the package explicitly in `bootstrap/app.go`:

```
import (
    stripewebhooks "github.com/spatie/laravel-stripe-webhooks-go"
    laravel "go.laravel.com"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{
            stripewebhooks.New(func(cfg *stripewebhooks.Config) {
                cfg.Path = "/stripe-webhooks"
            }),
        },
    }
}
```

Keep your application's other options, database drivers and migrations. Do not register Webhook Client a second time just for this endpoint. Stripe registers the client's migration, pruning command and jobs itself.

Signing secret
--------------------------------------------------------------------------------------------------

Stripe signs each webhook using a secret. You can find the secret in [the webhook configuration settings on the Stripe dashboard](https://dashboard.stripe.com/webhooks). A webhook signing secret starts with `whsec_`. It is not your Stripe API key. Keep it out of source control and logs.

The Stripe CLI uses a different signing secret from your Dashboard endpoint. Use the CLI's secret for forwarded local events and the Dashboard secret for events sent directly to your deployed endpoint.

Pass the original request body to signature verification. Parsing and re-encoding JSON changes the signed bytes and invalidates the signature.

Configuration
-----------------------------------------------------------------------------------------------

Configuration callbacks run after environment defaults. Set these values in your environment:

```
STRIPE_WEBHOOK_SECRET=whsec_your_endpoint_secret
STRIPE_SIGNATURE_VERIFY=true
STRIPE_WEBHOOK_CONNECTION=database
STRIPE_WEBHOOK_QUEUE=payments
```

An empty connection or queue uses the application's default. A configured per-event job can select its own connection or queue, taking precedence over these package defaults. Disable verification only for local development. Invalid typed environment values stop startup.

`Config` has `Path`, `Webhook`, `SigningSecrets`, `Jobs`, `DefaultJob`, `ProcessingJob`, `Connection`, `Queue`, `WithoutMigration` and `ConfigureClient`. `Webhook` starts with Webhook Client's defaults, with the name fixed to `stripe`, signature header `Stripe-Signature`, the Stripe validator and the selected model's duplicate profile. Use its `StoreHeaders`, `StoreAttachments`, `WebhookProfile`, `SignatureValidator` and `WebhookResponse` fields to customize those policies.

`ConfigureClient` runs after the Stripe endpoint settings and can change Webhook Client options such as retention. By default, `WEBHOOK_CLIENT_DELETE_AFTER_DAYS` is 30. Run or schedule `webhook-client:prune` to remove old calls. Pruning also removes their duplicate-detection history.

Storage and routing
-----------------------------------------------------------------------------------------------------------------

Configure a persistent database connection and register its Laravel driver. Run your application's migrations:

```
go run . migrate
```

The package creates `webhook_calls` using Webhook Client's migration. Custom models can set `WithoutMigration` and register their own schema.

At [the Stripe dashboard](https://dashboard.stripe.com/webhooks), configure the public URL that ends in `/stripe-webhooks`. The package registers that path as a bare `POST` route without a browser CSRF check or session middleware. Keep HTTPS enabled in production. If your application adds global CSRF middleware, exclude only this endpoint.

The package does not create queue-driver tables. For the database queue, register a migration using `queue.CreateTables`, migrate it, and run your application's worker:

```
go run . queue:work --queue=payments
```

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
