The Subscription State Machine, From Created to Halted
The problem
A customer starts a free trial on your app. Razorpay says the subscription is authenticated. Is that person paying? Should they see the Pro features? A week later it says active. A month later it says pending. Then halted. Somewhere in there your support inbox gets an angry email: "I was charged, why is my account locked?"
Most subscription bugs are not payment bugs. They are state bugs. The payment worked, but the app read the wrong field, or treated two different states as the same thing, or never heard about a change at all.
This part walks through the life of one subscription on Razorpay: the plan it hangs off, the customer it belongs to, the fields you set when you create it, and every state it can move through. The running example is a ₹499/month plan with a 7-day free trial. That is how BlogLLM Pro works, which is the only reason we picked it. Every rule below comes from Razorpay's own docs, linked under Sources. Where those docs contradict each other, this post says so instead of picking a side.
Step zero: the plan
A subscription never stands alone. It always points at a plan, and the plan says how much and how often.
You create one with POST /v1/plans. Three fields do most of the work:
| Field | What it means | Our example |
|---|---|---|
period | The unit of time. The request docs list daily, weekly, monthly, quarterly and yearly. | monthly |
interval | How many periods make one billing cycle. 2 with monthly means every 2 months. | 1 |
item.amount | The price per cycle, in paise. The minimum is ₹1.00 (100 paise). | 49900 |
So ₹499 becomes 49900. Razorpay's own example is 69900 for ₹699. Get this wrong by a factor of 100 and you either charge ₹4.99 or ₹49,900, and neither conversation with a customer goes well.
Two small rules worth knowing. Daily plans need an interval of at least 7, so you cannot bill someone every single day. And a plan can carry up to 15 notes key-value pairs for your own bookkeeping.
One honest wrinkle: the plan API page lists quarterly as a valid request value, but the response description and the error text on the same page list only daily, weekly, monthly and yearly. If you need a quarterly plan, monthly with interval: 3 says the same thing and does not depend on which part of the page is right.
The customer
Razorpay keeps a customer record with an ID like cust_.... You can create one yourself with POST /v1/customers, passing a name (3 to 50 characters), a contact number (up to 15 characters including country code) and an email (up to 64 characters).
The useful flag here is fail_existing. By default it is "1", which means "if a customer with these details already exists, throw an error". Set it to "0" and Razorpay hands you back the existing customer instead. That turns "create customer" into "create or fetch", which is what you almost always want when a returning user clicks Subscribe again.
You do not have to do this step at all for subscriptions. The subscription's customer_id field "is populated automatically once the customer completes the authorisation transaction". In other words, Razorpay learns who the customer is at the moment they pay, and links them for you.
Creating the subscription: the fields that matter
The subscription itself comes from POST /v1/subscriptions. Here are the fields that shape its life, with what Razorpay's API page says about each:
| Field | What it does |
|---|---|
plan_id | Required. Which plan this subscription bills against. |
total_count | How many billing cycles to charge. Required unless you pass end_at instead. You cannot pass both. |
quantity | Multiplies the plan amount. Defaults to 1. Five licences of a ₹100 plan is ₹500 per cycle. |
start_at | When billing starts. Leave it out and the subscription starts right after the authorisation payment. It cannot be in the past. |
expire_by | The deadline for the customer to complete the authorisation payment. The default is 30 years. |
customer_notify | true (the default) means Razorpay sends the customer emails and messages. false means you handle all communication. |
offer_id, addons, notes | Discounts, upfront charges and your own metadata. |
A few of these deserve a second look.
total_count is a finish line, not a suggestion. A one year subscription billed every two months has a total_count of 6. When the last cycle is billed, the subscription completes. For an open ended product like a monthly membership you still have to pick a number. Razorpay's API page says it supports a maximum duration of 100 years. Its integration guide, however, lists an error that says you "can only charge a Subscription for up to 10 years". We could not resolve which limit actually applies, so if you plan to set a very large total_count, test it in test mode first.
start_at is where trials live. More on this in a moment. Note that a future start date makes the payment frequency as_presented, which matters for the mandate side covered in Part 2.
customer_notify decides who talks. If you set it to false, Razorpay stops emailing your customer. That includes the email with a change card link when a renewal fails. You take on that job.
The response gives you an ID like sub_..., a status of created, and a short_url. That URL is the hosted page where the customer completes authorisation, if you are not opening Checkout yourself. It also gives you counters you will lean on later: paid_count, remaining_count and auth_attempts, plus timestamps like current_start, current_end and charge_at (when the next charge is due).
How a free trial actually works
Razorpay has no field called trial_days. A trial is just a subscription whose start_at is in the future.
The trick is in what the customer pays when they sign up. Razorpay's workflow page gives four cases for the authorisation transaction:
| Start | Upfront amount? | Customer pays at signup |
|---|---|---|
| Immediate | No | The plan amount |
| Future (trial) | No | ₹5, refunded automatically |
| Immediate | Yes | Upfront amount plus plan amount |
| Future (trial) | Yes | The upfront amount only |
For our ₹499 plan with a 7-day trial, you create the subscription with start_at set to seven days from now. The customer authorises ₹5 with full two-factor authentication (OTP or 3DS for cards, UPI PIN for UPI, NetBanking for eMandate). That ₹5 proves the payment method works and registers the mandate. Razorpay refunds it automatically. Seven days later, at start_at, the first real ₹499 charge happens.

The workflow page adds that no invoice is sent for a future start subscription without an upfront amount, because only the authorisation transaction happens. Every other case sends one.
Testing tip from Razorpay's test page: in test mode, a future start_at subscription goes to authenticated with no webhook, and the ₹5 is refunded right away. So do not wait for a subscription.authenticated webhook in test mode and conclude your handler is broken.
Every state, and what moves it
Razorpay's API lists eight status values: created, authenticated, active, pending, halted, cancelled, completed and expired. Its states page adds a ninth, paused. Here is the whole machine.
stateDiagram-v2 [*] --> created: POST /v1/subscriptions created --> authenticated: auth done, future start_at (trial) created --> active: auth done, immediate start, first charge created --> expired: no auth before start_at authenticated --> active: start_at reached, cycle 1 charged authenticated --> cancelled: cancel, or pause (yes, pause) active --> pending: automatic charge failed pending --> active: retry or new card succeeds pending --> halted: all retries used up halted --> active: new card, or older invoice paid active --> paused: pause (active only) paused --> active: resume active --> cancelled: cancel now, or at cycle end active --> completed: last cycle billed cancelled --> [*] completed --> [*] expired --> [*]
Now the states one by one.
created
The subscription exists, but the customer has not completed authorisation. Nobody has paid anything. With an immediate start, the subscription actually stays in created until the first charge goes through, then jumps straight to active. Razorpay's test page shows that path firing subscription.activated then subscription.charged.
authenticated
The customer completed the authorisation transaction, and billing has not started yet. This is the trial state. In our example, a customer who signed up today sits in authenticated for seven days. Razorpay fires subscription.authenticated when "the first payment is made on the subscription", which can be the ₹5 auth amount, an upfront amount, or the plan amount.
One detail from the states page: with a trial plus an add-on, the subscription stays created until the add-on is processed and only then moves to authenticated. Razorpay's FAQ separately says add-ons are deprecated, while the API still documents addons. If you do not use add-ons, you can ignore this.
active
The billing cycle has started. When a subscription moves from authenticated to active, Razorpay attempts to charge the invoice amount. Each successful charge fires subscription.charged. This is the happy state, and with luck most of your subscribers live here.
pending
An automatic charge failed. Razorpay keeps retrying while the subscription is pending, and fires subscription.pending again on each failed retry, so expect more than one. For cards, Razorpay's retries page describes the charge failing at T=0, then retries on T+1, T+2 and T+3. The customer gets an email with a link to change the card (if customer_notify is on). If a retry succeeds, or the customer authenticates another card, the subscription goes back to active. Part 5 covers retries in detail.
halted
All retries are used up. This is where things get strange if you are not expecting it: invoices keep being generated for every billing cycle, but Razorpay no longer charges them automatically. To get back to active, the customer authenticates a new card, or you or the customer manually charge one of the older unpaid invoices.
And the line that catches people out, from the states page: once the subscription returns to active, "the previous charges will not be re-attempted. Only future billing cycles are charged automatically." So a subscription can sit halted for two months, come back, and those two unpaid invoices simply stay unpaid unless someone charges them by hand.
paused
Only an active subscription can be paused. While paused, no charges happen. You pause with POST /v1/subscriptions/:id/pause and pause_at: "now". The response shows the status as paused, a paused_at time and pause_initiated_by. If you get the error "pause is not allowed, feature is not enabled", Razorpay says to contact support.
Who can pause depends on the payment method. For cards and eMandate, only the merchant can. For UPI, both the merchant and the customer can, because the customer can pause from their UPI app. And if a UPI customer pauses, only they can resume. Your server cannot override it.
Resuming uses POST /v1/subscriptions/:id/resume with resume_at: "now", and the documented response shows the status back at active. Razorpay does fire a subscription.resumed webhook, and its webhook page describes it as moving to "the resumed state". But resumed is not one of the status values in the API, and the states page describes resume as going back to active. Treat subscription.resumed as an event, not a state you need to store.
cancelled
The subscription is over and cannot be restarted. Not renewed, not reactivated. If the customer comes back, you create a new subscription.
completed
The subscription reached the end of its life cycle, meaning all its total_count cycles were billed or it reached end_at. The subscription.completed webhook fires "when all the invoices are generated for a subscription".
expired
You set a start_at, and the customer never completed authorisation before that time. The subscription moves to expired and cannot be used again. In our example, if someone opens the checkout, gets distracted, and never pays before the trial would have ended, this is where their subscription lands.
Cancelling: now, or at the end of the cycle
Cancelling is POST /v1/subscriptions/:id/cancel, with one important flag:
cancel_at_cycle_end: false(the default) cancels immediately.cancel_at_cycle_end: truelets the current paid cycle run out. The status changes tocancelledonly at the end of the current billing cycle.
For a monthly product, the second option is usually the kind one. The customer paid for the month. Let them have the month.
But there are rules. You cannot cancel a subscription that is already expired or cancelled. And cancel_at_cycle_end: true fails when no cycle is running, which means created and authenticated, and also fails in the final cycle.
Put that next to the pause rule and you get a trap for trial users. Someone in their 7-day trial is authenticated. You cannot cancel them "at cycle end", because no cycle has started. And if you try to pause them instead, Razorpay's states page warns that pausing an authenticated subscription moves it to cancelled. So for a trial user who wants out, the only Razorpay action is an immediate cancel. If you want to let them keep using the product until the trial date, that is a decision your own app has to make and remember, because Razorpay will already say cancelled.
Changing a live subscription
On an active subscription you can change the plan, quantity, start date, total count and offer, either right away or at the end of the cycle. Immediate changes are prorated, a successful update fires subscription.updated, and it is not a state change. UPI subscriptions cannot be updated at all, per Razorpay's FAQ. The maths of proration has its own section in Part 6.
What your app should do in each state
Razorpay tells you the state. It does not tell you whether to unlock your product. That is your policy, and it is worth writing down before the first support email arrives.
Here is a sensible default. The "Give access?" column is our suggestion, not a Razorpay rule. The "Show" column uses fields Razorpay actually returns.
| State | Give access? | Show the customer |
|---|---|---|
created | No | "Finish setting up your payment" and the short_url or a Checkout button |
authenticated | Yes, this is the trial | Trial end date (start_at) and the amount that will be charged then |
active | Yes | Next charge date (charge_at) and a manage or cancel option |
active with cancel at cycle end | Yes, until current_end | "Your plan ends on (date)" and a way to change their mind with a new subscription |
pending | Your call. A short grace period is common | "Your last payment failed, update your payment method" |
halted | No, or read only | "Payment failed after several tries" and a way to pay or change card |
paused | Your call | "Paused" and a resume option (for UPI, tell them to resume from their UPI app if they paused it) |
cancelled | No | "Your subscription has ended" and a resubscribe button |
completed | No | "Your plan has finished" and a renew button |
expired | No | "This signup expired, start again" |

Three habits make this table hold up in production.
Store the state Razorpay sends, not one you calculate. Do not decide a subscription is active because seven days have passed. Wait for Razorpay to say so. Your clock and theirs will not agree on the edges.
Drive changes from webhooks, then confirm. Most state changes have a webhook (created and expired do not): authenticated, activated, charged, pending, halted, paused, resumed, cancelled, completed, updated. If you are ever unsure, fetch the subscription and read its status. Webhooks can arrive late, twice, or out of order, which is the whole subject of the next part.
Do not lock someone out the second a charge fails. pending means Razorpay is still trying. A customer whose card was declined on Tuesday and charged successfully on Wednesday never needs to know anything went wrong.
What's next
The state machine only works if your app hears about every move, and believes only the real ones. Anyone can send a POST request to your webhook URL claiming a subscription was charged. Next up: how payment webhooks prove they are real, with Python code we actually ran that signs, verifies, rejects a tampered body and rejects a replay.
Sources
- Create a Plan, Razorpay API docs (updated 2026-10-08)
- Create a Customer, Razorpay API docs (updated 2026-12-01)
- Create a Subscription, Razorpay API docs (updated 2026-10-08)
- Subscriptions States, Razorpay docs (updated 2026-10-08)
- How Subscriptions Work (workflow), Razorpay docs (last modified Oct 8, 2026)
- Test Subscriptions, Razorpay docs (updated 2026-12-04)
- Subscriptions FAQs, Razorpay docs (updated 2026-12-04)
- Payment Retries, Razorpay docs (last modified Oct 8, 2026)
- Cancel a Subscription, Razorpay API docs (updated 2026-10-08)
- Pause a Subscription, Razorpay API docs (updated 2026-10-08)
- Resume a Subscription, Razorpay API docs (updated 2026-11-17)
- Pause, Resume and Cancel a Subscription, Razorpay docs (updated 2026-12-04)
- Update a Subscription, Razorpay docs (updated 2026-10-08)
- Integrate With Subscriptions, Razorpay docs (last modified Oct 8, 2026)
- All Webhook Events, Razorpay docs (last modified Dec 4, 2026)
