Rawi

مرجع API · Billing & payment gateway

Checkout (start payment)

post/billing/checkout
احراز هویتتوکن مشتری (Bearer)
سطح دسترسیکاربر رایگان · کاربر حرفه‌ای

Customer token (Bearer) — free and paid users

محدودیت نرخ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.

بدنه درخواست

فیلدنوعتوضیح
period*stringactive period key
codestring | nullmust be valid if given
gateway_id*integera gateway from GET /billing/gateways for this user
auto_renewboolean | null«Renew automatically»: only with a gateway whose supports_auto_renew is true (Stripe)
نمونهjson
{
  "period": "quarterly",
  "code": "FOUNDERS30",
  "gateway_id": {{gatewayId}}
}

پاسخ‌ها

201 — {payment_id, redirect_url}

فیلدنوع
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)

فیلدنوع
message*string
codestring
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)

فیلدنوع
message*string
errors*object
json
{
  "message": "",
  "errors": {
    "email": [
      "ایمیل معتبر نیست."
    ]
  }
}

429 — Throttle 10 req/min

فیلدنوعتوضیح
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

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}}
}'

امتحان در کنسول