Metanow Docs
API & Integration

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/stripe

The 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/stripe

Select the following event types to subscribe to:

  • customer.subscription.created
  • customer.subscription.updated
  • customer.subscription.deleted
  • invoice.paid

After saving, Stripe shows the Signing secret — copy it to STRIPE_WEBHOOK_SECRET in your .env.

Handled events

EventEffect
customer.subscription.createdUpdates organizations.billing_status to the subscription status; stores stripe_customer_id and stripe_subscription_id
customer.subscription.updatedSame as above — idempotent upsert
customer.subscription.deletedSets billing_status to canceled; clears stripe_subscription_id
invoice.paidSets 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_ or sk_test_ / rk_test_); any other key counts as live.
  • Subscription events (customer.subscription.*) and invoice.paid events that are not a flat-rate invoice are ignored — organisation subscriptions are billed on the platform account only.
  • Premium-module checkouts (checkout.session.completed with premium_subscription) and tenant card setups (setup_intent.succeeded) are ignored — both are created on the platform account only.
  • A flat-rate invoice.paid or invoice.payment_failed updates 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

StatusCause
400Invalid HMAC signature, missing raw body, missing stripe-signature header, or missing org_id in event metadata
200Event 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/stripe

The CLI prints a temporary signing secret. Set it as STRIPE_WEBHOOK_SECRET in your local .env for testing.

On this page