FlowPrime guides

Webhooks: receive your Stripe events and forward them to your own server

The router receives the Stripe events of your workspace's own Stripe account, verifies their signature, keeps a log of each one, and forwards them to HTTP endpoints you choose by matching a field in the event. FlowPrime already consumes the events your sales need (checkout, subscription changes, invoices, refunds), so most products never add a route. Add one when your own server must react to a Stripe event directly, and use the logs to answer "did Stripe's event arrive, and where did it go?".

What you can do

Capability How Status
List your routes router_list_routes live
Create, edit, pause or delete a route REST: POST, PUT, DELETE /v1/admin/routes with an org API key, via service_contract service=router; or the dashboard (Developers > Webhooks > Routes) live
See which route a payload would match, without sending router_test_route live
Delivery log, filterable by event type, status, date, event id router_get_logs live
Delivery status of one Stripe event router_get_event_status live
Counts of events and routes router_get_stats live
Send a logged event again router_replay_webhook live
Receive the Stripe events of your own Stripe account automatic once a Stripe account is linked (see platform_guide topic=payments) live
Verify that a forwarded event came from FlowPrime and is fresh X-FlowPrime-Signature on every forward from a route with a destinationSecret (see "Verify a forwarded event") live
Licence events about your product's customers (license.created, license.updated, license.suspended, ...) webhookUrl on reseller_operator_product_create; sent by license, not by the router live
Rotate the licence webhook's signing secret reseller_operator_product_rotate_webhook_secret live
GitHub webhooks the endpoint exists, but a workspace cannot set its GitHub signing secret planned
Other sources (Shopify, arbitrary JSON) only Stripe and GitHub signatures are accepted planned
Match on anything but exact equality (prefix, wildcard, several fields) not implemented planned

Before you start

  1. A linked, active Stripe account: reseller_stripe_account_get must answer connected: true, status: active, and routerWired: true. Linking (dashboard, Business > Settings > Payment account) registers a webhook endpoint on your Stripe account that points at your router address and stores its signing secret. Nothing else gives the router your secret.
  2. That Stripe endpoint carries these event types: checkout.session.completed, checkout.session.async_payment_succeeded, checkout.session.async_payment_failed, customer.subscription.updated, customer.subscription.deleted, customer.subscription.trial_will_end, invoice.paid, invoice.payment_failed, charge.refunded. To receive more, add them to that same endpoint in your Stripe dashboard; FlowPrime keeps extra types you add.
  3. For REST writes, an org API key from auth_create_api_key, sent as Authorization: Bearer ffk_.... A scoped key needs the router:admin scope. A token that holds only a customer seat is refused.

Step by step

Forward an event type to your server

  1. Decide the match: a dot path into the Stripe event and the exact value it must equal. Usually type = invoice.paid. Nested paths work: data.object.metadata.plan = pro.
  2. Create the route with REST POST /v1/admin/routes:
    { "name": "invoices to billing", "matchField": "type", "matchValue": "invoice.paid",
      "destinationUrl": "https://api.example.com/hooks/stripe",
      "destinationSecret": "a-long-random-string", "priority": 10, "active": true }
    
  3. router_list_routes to confirm it is there and active. The secret is never read back (hasDestinationSecret says one is set).
  4. router_test_route with a sample event, for example {"id":"evt_test","type":"invoice.paid","data":{"object":{}}}. The answer names the route that matched and the value it extracted, or every route it checked when nothing matched.
  5. On your server, accept POST with the raw Stripe event as JSON and verify X-FlowPrime-Signature (below). The router also sends Authorization: Bearer <destinationSecret>, X-FlowPrime-Event-Id, X-Stripe-Event-Id, X-Stripe-Event-Type, X-Tenant-Id and X-Forwarded-By. Answer 2xx fast.

Change, pause or remove a route

  1. router_list_routes for the route id.
  2. REST PUT /v1/admin/routes/{id} with only the fields to change. "active": false pauses it; "destinationSecret": "" clears the secret, and omitting it keeps the current one.
  3. REST DELETE /v1/admin/routes/{id} removes it. Its past log rows stay.

Verify a forwarded event

Every forward from a route that has a destinationSecret carries:

X-FlowPrime-Signature: t=1731150000,v1=5f2b...
X-FlowPrime-Event-Id: evt_1QabcXYZ
# FastAPI
import hashlib, hmac, json, os, time
from fastapi import FastAPI, Header, HTTPException, Request

app = FastAPI()
SECRET = os.environ["ROUTE_SECRET"].encode()  # the route's destinationSecret
TOLERANCE = 300                               # seconds
seen: set[str] = set()                        # use your database in production

def verify(raw: bytes, header: str) -> None:
    parts = [p.split("=", 1) for p in header.split(",") if "=" in p]
    t = next((v for k, v in parts if k == "t"), "")
    sigs = [v for k, v in parts if k == "v1"]
    if not t.isdigit() or abs(time.time() - int(t)) > TOLERANCE:
        raise HTTPException(401, "stale or missing timestamp")
    expected = hmac.new(SECRET, t.encode() + b"." + raw, hashlib.sha256).hexdigest()
    if not any(hmac.compare_digest(expected, s) for s in sigs):
        raise HTTPException(401, "bad signature")

@app.post("/hooks/stripe")
async def stripe_hook(request: Request,
                      x_flowprime_signature: str = Header(""),
                      x_flowprime_event_id: str = Header("")):
    raw = await request.body()
    verify(raw, x_flowprime_signature)
    event_id = json.loads(raw)["id"]           # the body's id: the same for retries AND replays
    if event_id in seen:                       # an event you already handled
        return {"ok": True}
    event = await request.json()
    if event["type"] == "invoice.paid":
        ...                                   # your work, kept short
    seen.add(event_id)
    return {"ok": True}                       # 2xx, also for types you ignore

The body is the Stripe event object exactly as Stripe sent it (id, type, data.object, ...). A replay carries the original body; only the event id headers gain the replay_ prefix, so key your de-duplication on the body's id if a replay must not run twice. Keep the de-duplication record for at least the 24 hours retries can last.

To change a route's secret, accept both the old and the new secret on your server first, then PUT /v1/admin/routes/{id} with the new destinationSecret, then drop the old one: the router signs with one secret at a time, and retries already queued are signed with the secret the route had when the event arrived.

Find out what happened to an event

  1. router_get_event_status with the Stripe event id (evt_...): latest status, delivery status, attempts, response code, error, destination.
  2. Or router_get_logs with eventType, status (forwarded, failed, no_match), dateFrom/dateTo or eventIdSearch. Each row has a numeric id: that is the logId replay takes.
  3. router_get_stats for totals.

Replay an event

  1. Fix the cause first (the route, your server).
  2. router_replay_webhook with the logId of the received event.
  3. The replay re-matches against your routes AS THEY ARE NOW and forwards to every match. Its log rows carry the event id prefixed replay_.

When nothing arrives

  1. router_get_event_status with the evt_... id from your Stripe dashboard. "No logs found" means the event never reached the router: check that the Stripe endpoint carries that event type and that reseller_stripe_account_get shows routerWired: true.
  2. Status no_match: the event arrived and no route matched. Compare your matchField and matchValue with the event using router_test_route and the real payload.
  3. Status failed with a response_code: your server answered it. A 401 means your server refused the bearer or the signature: check the secret and that you compute the HMAC over the raw body; a 404 means the path is wrong. Fix it. The background retries keep going for 24 hours on their own; router_replay_webhook resends now, or after they gave up.
  4. Status failed with no response code: the destination did not answer (timeout, DNS, TLS). Check that the URL is public and serves valid HTTPS.

Things that trip agents up

Reference

Where to go next