API reference · Billing & payment gateway
Stripe webhook
post
/billing/webhooks/stripe| Authentication | None (public) |
|---|---|
| Access | Guest · Free user · Pro user · Consultant · Super admin Public (no token, no CSRF) |
| Rate limit | 120/1min |
Stripe calls this with events; set it in the Stripe dashboard (Developers › Webhooks) with the event
checkout.session.completed. The URL to copy is shown on the admin Stripe gateway page (webhook_url):
{APP_URL}/api/billing/webhooks/stripe.
- The raw body is verified against the
Stripe-Signatureheader (t=…,v1=…): HMAC-SHA256 of"{t}.{body}"with the webhook signing secret of a Stripe gateway, andtwithin 5 minutes of now. checkout.session.completed(andcheckout.session.async_payment_succeeded) withpayment_status: "paid": the session must match the payment inmetadata.payment_id(session id, amount, currency); the payment is then completed like a successful return (plan, email, referral), or, for an the admin panel test payment, verified and refunded. Idempotent: a replayed event or one that arrives after the customer's return changes nothing and sends no second receipt.checkout.session.expired/checkout.session.async_payment_failed: a still-pending payment is marked failed.- Automatic renewal (subscribe the endpoint to these too):
invoice.paidwith a renewalbilling_reason(notsubscription_create, which is the checkout payment) records a payment in the invoice's currency andamount_paid(authority= invoice id, tracking code = its PaymentIntent) and extends the plan by one period from the current end (email receipt); idempotent per invoice.invoice.payment_failedsetssubscription_status: past_dueand sends email.customer.subscription.updated/customer.subscription.deletedkeepsubscription_statusin step (cancel_at_period_end,canceled= stops renewing). The subscription is found byusers.stripe_subscription_id(invoice.subscription, orinvoice.parent.subscription_details.subscriptionon newer API versions). A subscription that still renews keeps the plan forRENEWAL_GRACE_DAYS(3) afterplan_expires_atwhile its invoice is pending. - Other events, unknown payments and sessions that do not match are acknowledged and ignored.
Request — a Stripe Event object (raw JSON body), e.g.
Request body
Examplejson
{
"id": "evt_test_1",
"type": "checkout.session.completed",
"data": {
"object": {
"id": "cs_test_a1",
"payment_status": "paid",
"amount_total": 16200,
"currency": "usd",
"client_reference_id": "{{paymentId}}",
"metadata": {
"payment_id": "{{paymentId}}"
},
"payment_intent": "pi_test_1"
}
}
}
Responses
200
| Field | Type |
|---|---|
received* | boolean |
json
{
"received": false
}
400
| Field | Type | Description |
|---|---|---|
message* | string | Human-readable message in the request language. |
code* | string | Machine-readable code. |
json
{
"message": "Invalid signature",
"code": "invalid_signature"
}
429 — More than 120 requests a minute
| Field | Type | Description |
|---|---|---|
message* | string | |
resend_in | integer | Seconds until a new login code may be requested (login-code cooldown only). |
json
{
"message": "Too Many Attempts.",
"resend_in": 0
}
curl example
bash
curl -X POST 'http://127.0.0.1:8010/api/billing/webhooks/stripe' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"id": "evt_test_1",
"type": "checkout.session.completed",
"data": {
"object": {
"id": "cs_test_a1",
"payment_status": "paid",
"amount_total": 16200,
"currency": "usd",
"client_reference_id": "{{paymentId}}",
"metadata": {
"payment_id": "{{paymentId}}"
},
"payment_intent": "pi_test_1"
}
}
}'