Naafi Pay

Subscription Checkout

POST/api/subscriptions/checkout

Creates a subscription checkout session for an existing plan and returns a hosted checkout URL. The customer enters their payment details once, agrees to recurring billing, and NaafiPay charges them automatically on every renewal cycle. Renewals emit subscription.renewed webhooks; if a renewal fails, NaafiPay runs dunning automatically and notifies you via webhook for each attempt. Subscriptions currently support monthly and yearly billing intervals.

Request headers

FieldTypeRequiredDescription
AuthorizationstringrequiredYour test or live API key.
Example: pg_live_xxx
Content-TypestringrequiredMust be application/json.
Example: application/json

Request body

FieldTypeRequiredDescription
plan_idstringrequiredThe id of a plan you created in the dashboard.
Example: plan_pro_monthly
customer_emailstringrequiredCustomer email. Used for receipts and portal sign-in.
Example: tasin@example.com
customer_namestringrequiredCustomer's full name, shown on receipts.
Example: Tasin Fahim
success_urlstringrequiredHTTPS URL after first successful charge. Receives subscription_id as a query param.
Example: https://yourapp.com/welcome
cancel_urlstringrequiredHTTPS URL if the customer abandons checkout.
Example: https://yourapp.com/pricing
metadataobjectoptionalArbitrary key/value pairs returned in webhooks. Max 20 keys.
Example: { "user_id": "u_99" }

Response

200 OK
1{
2 "subscription_id": "sub_01HZY8K2R4T8AB7CDEF9G2H3JK",
3 "checkout_url": "https://pay.naafipay.com/s/sub_01HZY8K2R4T8AB7CDEF9G2H3JK",
4 "status": "incomplete",
5 "plan": { "id": "plan_pro_monthly", "amount": 1500, "interval": "month" }
6}
TipPlans live in the dashboard
Create plans under Dashboard → Subscriptions → Plans. Each plan defines the amount, currency, billing interval, and optional trial period. The plan id you reference here must already exist.

Error codes

FieldTypeRequiredDescription
400invalid_planoptionalplan_id does not exist or belongs to a different storefront.
400invalid_urloptionalsuccess_url or cancel_url is not a valid HTTPS URL.
401unauthorizedoptionalAPI key is missing or invalid.
WarningCustomers consent to recurring billing
The hosted checkout shows a clear consent screen for the recurring charge. If you bypass the hosted checkout, you must collect this consent yourself — it is a legal requirement under Bangladesh consumer protection rules.
Updated at: May 30, 2026