Rawi

API reference · Billing & payment gateway

Stripe webhook

post/billing/webhooks/stripe
AuthenticationNone (public)
AccessGuest · Free user · Pro user · Consultant · Super admin

Public (no token, no CSRF)

Rate limit120/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-Signature header (t=…,v1=…): HMAC-SHA256 of "{t}.{body}" with the webhook signing secret of a Stripe gateway, and t within 5 minutes of now.
  • checkout.session.completed (and checkout.session.async_payment_succeeded) with payment_status: "paid": the session must match the payment in metadata.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.paid with a renewal billing_reason (not subscription_create, which is the checkout payment) records a payment in the invoice's currency and amount_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_failed sets subscription_status: past_due and sends email. customer.subscription.updated / customer.subscription.deleted keep subscription_status in step (cancel_at_period_end, canceled = stops renewing). The subscription is found by users.stripe_subscription_id (invoice.subscription, or invoice.parent.subscription_details.subscription on newer API versions). A subscription that still renews keeps the plan for RENEWAL_GRACE_DAYS (3) after plan_expires_at while 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

FieldType
received*boolean
json
{
  "received": false
}

400

FieldTypeDescription
message*stringHuman-readable message in the request language.
code*stringMachine-readable code.
json
{
  "message": "Invalid signature",
  "code": "invalid_signature"
}

429 — More than 120 requests a minute

FieldTypeDescription
message*string
resend_inintegerSeconds 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"
        }
    }
}'

Try it in the console