From 67c35e6bbe01868b1fe9fc47346f7e542a9c936e Mon Sep 17 00:00:00 2001 From: adshrc Date: Wed, 18 Sep 2024 17:13:58 +0200 Subject: [PATCH] refactor(readme.md): added example to readme --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 98aab25..6320fe2 100644 --- a/README.md +++ b/README.md @@ -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/` + +- 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:///`** -- 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