API reference · Billing & payment gateway
Checkout (start payment)
post
/billing/checkout| Authentication | Customer token (Bearer) |
|---|---|
| Access | Free user · Pro user Customer token (Bearer) — free and paid users |
| Rate limit | 10/1min |
Creates a pending payment from the quote and returns the gateway URL. With the mock gateway the URL is a signed page on the API host (/pay/mock/{payment}) whose buttons hit /pay/callback/{payment} and redirect to {FRONTEND_URL}/app/checkout/result?payment={id}. Fires checkout_started.
Request body
| Field | Type | Description |
|---|---|---|
period* | string | active period key |
code | string | null | must be valid if given |
gateway_id* | integer | a gateway from GET /billing/gateways for this user |
auto_renew | boolean | null | «Renew automatically»: only with a gateway whose supports_auto_renew is true (Stripe) |
Examplejson
{
"period": "quarterly",
"code": "FOUNDERS30",
"gateway_id": {{gatewayId}}
}
Responses
201 — {payment_id, redirect_url}
| Field | Type |
|---|---|
payment_id* | integer |
redirect_url* | string |
json
{
"payment_id": 31,
"redirect_url": "http://127.0.0.1:8010/pay/mock/31?expires=1764064424&signature=3f6c…"
}
401 — Missing/invalid token, or a token of the wrong owner (admin token on a user route or vice versa): {"message":"…","code":"unauthenticated"} (message in the request language)
| Field | Type |
|---|---|
message* | string |
code | string |
json
{
"message": "Please sign in to continue; your session has ended or is not valid.",
"code": "unauthenticated"
}
422 — Validation failed: gateway_id «این درگاه فعال نیست.» (not in the caller's usable gateways: off, not in the caller's currency, no driver, other panel language, or a live gateway for a test account) or gateway error; code invalid or used up for this account; period; auto_renew (gateway without automatic renewal, or a subscription that still renews)
| Field | Type |
|---|---|
message* | string |
errors* | object |
json
{
"message": "",
"errors": {
"email": [
"ایمیل معتبر نیست."
]
}
}
429 — Throttle 10 req/min
| 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/checkout' \
-H 'Accept: application/json' \
-H "Authorization: Bearer $RAWI_USER_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"period": "quarterly",
"code": "FOUNDERS30",
"gateway_id": {{gatewayId}}
}'