Agent Wranglers

Subscriptions Recommended

Preview the amount before a plan change

Before the customer confirms a plan change, show the exact amount due now and at the next renewal, taken from the provider's preview.

How to do it

Upgrade at once and charge the prorated difference. Downgrade at the end of the period, so the customer keeps what they paid for. Ask the provider for a preview invoice, and pass the same proration time to the change itself, so the charge matches the preview. Quantity changes, such as more seats, follow the same rule.

Example

const prorationDate = Math.floor(Date.now() / 1000)
const items = [{ id: subscriptionItemId, price: 'price_team_monthly' }]
const preview = await stripe.invoices.createPreview({
  subscription: subscriptionId,
  subscription_details: { items, proration_date: prorationDate },
})
showAmountDueNow(preview.amount_due, preview.currency)
// After the customer confirms:
await stripe.subscriptions.update(subscriptionId, { items, proration_date: prorationDate })
proration_date = int(time.time())
items = [{"id": subscription_item_id, "price": "price_team_monthly"}]
preview = stripe.Invoice.create_preview(
    subscription=subscription_id,
    subscription_details={"items": items, "proration_date": proration_date},
)
show_amount_due_now(preview.amount_due, preview.currency)
# After the customer confirms:
stripe.Subscription.modify(subscription_id, items=items, proration_date=proration_date)

How to check

Upgrade a test subscription halfway through a month. The charged amount equals the previewed amount to the minor unit.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers payments playbook: https://agentwranglers.se/playbook/payments/subscriptions/plan-change-proration.