# 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.

### 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://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2FNm2g1qsIIS3YauEYCiRK%2Fimage.png?alt=media&#x26;token=49b6adca-5332-4c54-8867-06481fc551fc" 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://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2FkmhVCc1oUvMVDF7Ha9iD%2Fimage.png?alt=media&#x26;token=ff23ed0a-16d7-4d7d-b647-529e40a342c6" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2FYIgOLp33M0pI3wNaEcrt%2Fimage.png?alt=media&#x26;token=35a980d6-4422-443e-8640-493c82f3567b" alt=""><figcaption></figcaption></figure>

4. Add the below events to listener

```
charge.succeeded
charge.failed
charge.captured
charge.refunded
charge.refund.updated
checkout.session.completed
checkout.session.async_payment_succeeded
checkout.session.async_payment_failed
checkout.session.expired
payment_intent.payment_failed
payment_intent.succeeded
payment_intent.amount_capturable_updated
payment_intent.requires_action

```

<figure><img src="https://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2FJv3rTcGb3TGuGedkhLiF%2Fimage.png?alt=media&#x26;token=0af5e71c-93d0-4d7d-8aa5-9af7e2907bd3" 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://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2FuQTWqINKNiCJjK1aIVzC%2Fimage.png?alt=media&#x26;token=efc177e0-6b73-450f-b341-6eafb678275d" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2FSFrtrlx4qrhUNHb5AZj7%2Fimage.png?alt=media&#x26;token=fbd061df-b699-4c26-b183-f2b0de4d75d1" 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://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2Fqj1chiUpXq8sTWZztset%2Fimage.png?alt=media&#x26;token=22809327-d30c-4dcd-af51-dd550e504a78" 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://2515576520-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FG0PUsYuzKts2zzoPrZBP%2Fuploads%2F3zJSivOdV2XamJZjlysH%2Fimage.png?alt=media&#x26;token=4b43bcf5-c092-482f-8e29-80213d88b4da" alt=""><figcaption></figcaption></figure>
