-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(readme.md): added example to readme
- Loading branch information
Showing
1 changed file
with
11 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |