Skip to main content
Some billing changes should not take effect until the customer has paid for them. A seat increase that generates a proration charge, or a wallet top-up that adds purchased credits, can both be gated behind a hosted payment. You opt in by adding a checkout object to the request you already send. Flexprice then defers the change, returns a payment link, and applies the change only after the payment succeeds. Omit checkout and the endpoint behaves exactly as before.

Supported flows

Both actions are created only through the endpoint that owns them. Passing either to POST /checkout/sessions returns a validation error pointing you at the right endpoint:

The checkout object

How it works

  1. Flexprice validates the request and computes the amount to collect.
  2. A ONE_OFF invoice is created in DRAFT status. This invoice locks the amount — it is never recomputed later.
  3. A checkout session is created in pending status. The change you asked for is stored on the session’s configuration, and the invoice and payment IDs are recorded as checkout_invoice_id and checkout_payment_id.
  4. A payment is created in INITIATED status and the provider is called for a payment link.
  5. The response includes a checkout_session object. Redirect the customer to checkout_session.payment_action.url.
  6. When the provider reports success, Flexprice completes the session: it applies the deferred change, finalizes the draft invoice, and marks the payment SUCCEEDED.
Nothing about the subscription or wallet balance changes between steps 1 and 6.

Status at each phase

Poll GET /v1/checkout/sessions/{id} from your redirect pages to read checkout_status before showing the customer a result.

Charge a saved payment method

Set collection_method to charge_automatically to attempt an off-session charge against a payment method the customer has already authorized, instead of sending them to a payment page.
With charge_automatically, Flexprice first looks for a confirmed saved token and tries to charge it off-session. Two outcomes are possible:
  • The charge is submitted. No payment URL is returned, so there is nothing to redirect to. The session completes when the provider’s payment webhook arrives.
  • No usable saved method exists, or the amount exceeds the mandate ceiling. Flexprice falls back to a Razorpay authorization link, which registers a mandate and collects this payment in one step. Redirect the customer to it as usual.
Because the first outcome returns no URL, treat payment_action.url as optional in your integration and drive completion from the webhook rather than the redirect.
max_mandate_limit is capped against your tenant-level mandate ceiling for UPI only. If you request a higher limit than the tenant allows, the tenant ceiling applies. Card mandates have no ceiling.

Guards and retries

One active session per target. A second pay-first request for the same subscription, or the same wallet, is rejected while a session is initiated or pending. The error names the session that is already open:
Complete or cancel the open session before starting another. Deleting a session is allowed only while it is non-terminal. Sessions expire. Razorpay sessions expire 15 minutes after creation. If the provider’s own link expires sooner, Flexprice shortens the session to match. On expiry the draft invoice and payment are archived and the change is discarded. Completion is idempotent. If your provider delivers the same success event twice, only the first delivery applies the change; the duplicate is rejected. Make your own webhook handler idempotent for the same reason. idempotency_key scope. A key is reserved only while its session is active. Once the session reaches a terminal state the same key can be reused. Reusing a key that belongs to an active session returns a conflict rather than the existing session.

Webhook events

Completing a modify_subscription session also publishes subscription.updated.

Gate a seat change

Require payment before a seat increase takes effect.

Gate a wallet top-up

Require payment before purchased credits land.