Skip to content

Commit

Permalink
refactor(readme.md): added example to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
adshrc authored Sep 18, 2024
1 parent e2ba3fd commit 67c35e6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Stripe Multi-Environment Webhook Handler (SMEWH) 🌍💳

[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/adshrc/stripe-multi-environment-webhook-handler)

Struggling to handle dev, staging, demo, and other environments with a single Stripe Test Environment? Here's an easy and flexible solution!

This Cloudflare Worker forwards incoming Stripe webhook events to the appropriate environment based on the `returnUrl` included in the event's `metadata` property.

## Requirements

- Create the Cloudflare Worker
- Create a Webhook in your Stripe Dashboard: https://dashboard.stripe.com/test/webhooks
- Create the Cloudflare Worker and upload the `worker.js` contents or use this Button:

[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/adshrc/stripe-multi-environment-webhook-handler)
- Create a Webhook in your Stripe Dashboard: https://dashboard.stripe.com/test/webhooks. Make sure to replace the original URL's Domain with the Worker Domain. In the end you should have something like this: `https://smewh.worker.dev/<originalPath>`

- Add the `returnUrl` property in the `metadata` of every Stripe request your Server sends. It should be the URL of the originating server (e.g. `https://dev.your-server.com`)

**IMPORTANT: You need to include the target path: `https://<workerDomain>/<targetPath>`**
- Add the `returnUrl` property in the `metadata` of every Stripe request your server sends. It should be the URL of the originating server.
## What the Worker actually does

## Example
Stripe sends a webhook event to your Worker, e.g. `https://smewh.worker.dev/stripe/webhook`, then the Worker:

1. Stripe sends a webhook event to your Worker, e.g. `https://smewh.worker.dev/payment-processors/stripe/webhook-direct`
2. The Worker extracts the `returnUrl` from `metadata.returnUrl` (e.g., `https://your-env.com`)
3. The Worker forwards the original request (including the `stripe-signature` header for validation) to `https://your-env.com/payment-processors/stripe/webhook-direct`
4. The Worker returns the response back to Stripe
1. Parses the body, extracts `metadata.returnUrl` (e.g. `https://dev.your-server.com`)
2. Forwards the original request (including headers!) to `https://dev.your-server.com/stripe/webhook`
3. Returns the response back to Stripe

0 comments on commit 67c35e6

Please sign in to comment.