Webhooks
Stripe webhook events handled by MetaNow Console.
MetaNow Console receives Stripe webhook events at a single endpoint. The server validates the HMAC signature on every request using the STRIPE_WEBHOOK_SECRET environment variable. No session auth is required — the signature is the sole authentication mechanism.
Endpoint
POST /webhooks/stripeThe request body must be the raw Stripe event payload (not JSON-parsed). Include the stripe-signature header that Stripe attaches to every webhook delivery.
Registering the webhook in Stripe
In the Stripe Dashboard → Developers → Webhooks, add an endpoint pointing to:
{your-server-url}/webhooks/stripeSelect the following event types to subscribe to:
customer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.paid
After saving, Stripe shows the Signing secret — copy it to STRIPE_WEBHOOK_SECRET in your .env.
Handled events
| Event | Effect |
|---|---|
customer.subscription.created | Updates organizations.billing_status to the subscription status; stores stripe_customer_id and stripe_subscription_id |
customer.subscription.updated | Same as above — idempotent upsert |
customer.subscription.deleted | Sets billing_status to canceled; clears stripe_subscription_id |
invoice.paid | Sets billing_status to active |
All other event types are silently acknowledged (returns 200).
Events from connected accounts (Stripe Connect)
When a reseller has connected its own Stripe account, events from that account reach the same endpoint with event.account set. The metadata on those objects is written by the reseller, so the server accepts less from them:
- An event whose live/test mode differs from the deployment's is ignored. The deployment's mode comes from the prefix of
STRIPE_SECRET_KEY(sk_live_/rk_live_orsk_test_/rk_test_); any other key counts as live. - Subscription events (
customer.subscription.*) andinvoice.paidevents that are not a flat-rate invoice are ignored — organisation subscriptions are billed on the platform account only. - Premium-module checkouts (
checkout.session.completedwithpremium_subscription) and tenant card setups (setup_intent.succeeded) are ignored — both are created on the platform account only. - A flat-rate
invoice.paidorinvoice.payment_failedupdates only the reseller-to-organisation invoice that already stores that Stripe invoice's id. - Card-on-file changes (
customer.updated,payment_method.*) update only the reseller's own organisations, matched by their customer on the reseller's account.
Ignored events still return 200, so Stripe does not retry them; each is logged for review.
Tenant resolution via metadata
Stripe events do not carry a MetaNow org ID by default. You must attach org_id to the metadata of every Stripe customer and subscription object. The webhook handler reads event.data.object.metadata.org_id to determine which organisation to update.
If org_id is missing from the metadata, the webhook returns 400 Bad Request:
{
"statusCode": 400,
"message": "Stripe event metadata missing org_id — cannot process without tenant context"
}Error responses
| Status | Cause |
|---|---|
400 | Invalid HMAC signature, missing raw body, missing stripe-signature header, or missing org_id in event metadata |
200 | Event processed (or silently ignored if the type is not handled) |
Testing locally
Use the Stripe CLI to forward events to your local server:
stripe listen --forward-to localhost:8000/webhooks/stripeThe CLI prints a temporary signing secret. Set it as STRIPE_WEBHOOK_SECRET in your local .env for testing.