# Webhook Configuration

### What is a webhook?

Webhooks allow Stripe to send notifications to your website when certain events occur. For example, if a payment is refunded in Stripe, Stripe can automatically send a notification to your webhook to let your website know.

### Which features require a webhook?

* [x] Email notification
* [x] Delayed & Redirection payment methods (Sofort, PayPal, Alipay, etc)
* [x] Subscription schedule plan (occurrences)

### How to setup a webhook?

1. In your Stripe dashboard, click Developer -> [Webhooks](https://dashboard.stripe.com/webhooks), then click the Add endpoint button.

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2FpTBHzusAgtVaSPKWDOpF%2Fimage.png?alt=media&#x26;token=e166fb04-f24c-4b8f-8c1c-ba3bb3afb2aa" alt=""><figcaption></figcaption></figure>

2. To get the endpoint URL, go back to the **Setting** tab in your WordPress dashboard and you should see a field labeled `Webhook URL`. Copy the URL or click the copy icon.

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2F6cqTEppiSfEG9SIQ2UCU%2Fimage.png?alt=media&#x26;token=7c9412ca-c652-4453-b06b-6342dae313af" alt=""><figcaption></figcaption></figure>

3. Paste the endpoint URL into the dialog box in your Stripe dashboard.

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2F6O5NP1GuEtXPZAr1dKVi%2Fimage.png?alt=media&#x26;token=13f70d2a-bf87-43ae-a624-7294882869fa" alt=""><figcaption></figcaption></figure>

4. Add the below events to listener

```
payment_intent.payment_failed
payment_intent.succeeded
charge.succeeded
invoice.upcoming
invoice.payment_succeeded
invoice.payment_failed
checkout.session.async_payment_succeeded
checkout.session.async_payment_failed

```

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2FE9yXNEcnDKyJ1nGSX5m1%2Fimage.png?alt=media&#x26;token=6819ab1e-b516-431c-9268-d6431ccb7609" alt=""><figcaption></figcaption></figure>

### Enable Webhook signatures (Strongly recommended)

Generating a signature for the webhook can greatly protect your endpoint from being abused by external parties.

In your Stripe dashboard, go to the webhook settings and click the `Signing secret` button to generate a signature.

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2FYfa5hv8awNhwT38AbnIx%2Fimage.png?alt=media&#x26;token=532b8e8e-8ee5-4cf9-8dbc-b77ffd40e229" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2FW4rAw2deBtHpfMVKOy5Y%2Fimage.png?alt=media&#x26;token=d46db859-52df-40e1-8456-b14cd91e00f1" alt=""><figcaption></figcaption></figure>

Go back to plugin settings and paste to the webhook secret field in the **Settings** tab

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2FPW639xwW3O1cEedFUioz%2Fimage.png?alt=media&#x26;token=5671cb6d-7b4a-44ee-bb3b-ee3f8004767a" alt=""><figcaption></figcaption></figure>

### Webhook Connection Test

First of all, let's do some payments with our plugin under test mode, then go to the webhook URL and find any events such as a payment\_intent.succeeded. Now click the \`Resend\` button to trigger the event again.

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2Fni7ib9UPmbiFoXr3CMJZ%2FGroup%2011.png?alt=media&#x26;token=49d2ffc3-5a68-4de9-ac99-ae6fb882abdf" alt=""><figcaption></figcaption></figure>

If the response is 200 (OK), our plugin will process the event and display a connected status in the Webhook URL field.

<figure><img src="https://1993841678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6FFXqELmFsGrfOxBauwC%2Fuploads%2FVahdWDwgLMubyGdm9urv%2Fimage.png?alt=media&#x26;token=cf67e89f-6fed-4929-a938-5da5913cff2d" alt=""><figcaption></figcaption></figure>
