Overview
Use Flowglad to create, update, and cancel subscriptions across web and server experiences.How to use
Create Subscriptions
Subscriptions are most commonly created as part of the standard checkout flow withcreateCheckoutSession when the price type is subscription. The checkout session will collect payment details from the customer, even if the subscription includes a trial period, so a charge attempt will be made automatically when the customer’s trial expires.
Free Trials
You can create subscriptions with free trials with or without requiring a valid payment method up-front. If you prefer to start customers on free trials without asking for payment details, you can use flowgladServer’screateSubscription method, passing in the priceSlug and other optional fields (see the create subscription API body for more details on the parameters).
You do not need to include
customerId when calling createSubscription with the flowgladServer, as the server client is already bound to the requesting customer scope.createActivateSubscriptionCheckoutSession method.
If there is a payment method associated with a subscription on a free trial, Flowglad will attempt to charge the payment method when the trial ends. If the payment method fails, Flowglad will not activate the subscription.
Cancel Subscriptions
You can cancel a subscription withuseBilling’s cancelSubscription from client side or with flowgladServer’s cancelSubscription from server side. You provide the subscription id and specify the cancellation timing— either immediately or at_end_of_current_billing_period (see the cancel subscription API body for details).
Uncancel Subscriptions
If a subscription has been scheduled for cancellation (statuscancellation_scheduled), you can reverse the cancellation before it takes effect using useBilling’s uncancelSubscription from client side or flowgladServer’s uncancelSubscription from server side. You provide just the subscription id.
Requirements:
- The subscription must be in
cancellation_scheduledstatus (cancellation timing wasat_end_of_current_billing_period) - For paid subscriptions, a valid payment method must exist for the subscription. For free subscriptions, no payment method is required
- The operation is idempotent - calling it on a subscription that isn’t scheduled for cancellation will silently succeed without uncanceling
- The subscription status reverts to
active(ortrialingif still in trial period) - Any billing runs that were aborted due to the cancellation are rescheduled
Adjust Subscriptions
You can upgrade or downgrade a subscription usinguseBilling’s adjustSubscription from client side or flowgladServer’s adjustSubscription from server side. This allows customers to change their plan mid-billing cycle with automatic proration handling.
Input Options:
There are three ways to specify the new plan:
priceSlug: Reference a price by its slug (simplest form)priceId: Reference a price by its IDsubscriptionItems: Array of subscription items for complex multi-item adjustments
timing parameter controls when the adjustment takes effect:
auto(default): Automatically determines timing based on whether this is an upgrade or downgrade. Upgrades happen immediately with proration; downgrades happen at the end of the current billing period.immediately: Apply the change immediately. For upgrades, the customer is charged the prorated difference. For downgrades, the plan changes immediately but no refund is issued.at_end_of_current_billing_period: Apply the change at the end of the current billing period (only valid for downgrades).
auto determines upgrade vs downgrade:
The auto timing compares the total monetary value of the current subscription items against the new subscription items:
- Upgrade: New total price > current total price → applies immediately
- Downgrade: New total price < current total price → applies at end of period
- Same price: New total price = current total price → applies immediately
unitPrice × quantity across all subscription items. This means switching between plans at the same price point (e.g., changing from “Pro Monthly” to “Pro Annual” with equivalent monthly cost) is treated as a same-price change and applies immediately.
Proration:
By default, immediate adjustments are prorated (prorate: true). This means:
- Upgrades: Customer is charged the prorated difference for the remainder of the billing period
- Downgrades: No refund is issued; the plan changes take effect based on timing
prorate: false to skip the mid-period proration charge. The plan change still happens immediately, but the customer isn’t charged until the next billing period. This effectively gives the customer the upgraded features for free until the period ends.
The
prorate option only applies to immediately and auto timing. The at_end_of_period timing has no proration since changes take effect at the next billing cycle.subscriptionId is automatically resolved. If the customer has multiple subscriptions, you must specify which subscription to adjust using the subscriptionId parameter.
Requirements:
- The subscription must be active (not in a terminal state like
canceled) - The subscription must be a renewing subscription (not a one-time purchase)
- The subscription cannot be on a free plan (use
createSubscriptionto upgrade from free instead) - A valid payment method is required for proration charges (upgrades with
prorate: true) - The new price must belong to the same pricing model as the subscription and be an active, recurring price
- Upgrades: Claims are preserved, and new capacity is immediately available
- Downgrades: If claimed resources exceed the new capacity, the adjustment is blocked
lib/downgrade-with-seats.ts
What you can do
- Allow customer to complete a subscription product checkout which will create a subscription automatically.
- Create subscriptions server-side using the Flowglad Server SDK.
- Trigger cancellations and uncancellations from server or client flows.
- Adjust existing subscriptions to upgrade or downgrade plans with automatic proration.
- Check entitlements for feature access or usage credits based on customer subscription.
Example: Create subscription
- Client
- Server
Example: Cancel subscription
- Client
- Server
Example: Uncancel subscription
- Client
- Server
Example: Adjust subscription (upgrade)
- Client
- Server
Example: Adjust subscription (downgrade)
- Client
- Server
Example: Adjust subscription with explicit timing
- Client
- Server