What is a Subscription?
A Subscription in Flowglad tracks the details of a recurring charge for a customer, including what products or services they’re paying for, how often, and their current status. Key concepts:- Customers are always on a subscription, even if they aren’t paying: when a customer is created, they are subscribed to the default plan for their pricing model. If they purchase a subscription product while they are currently subscribed to your pricing model’s free plan, their current subscription will change to be attached to the new price.
- One Current Subscription per Customer (Default): By default, a customer can only have one active subscription at a time (see “Current vs Non-Current Subscriptions” below). This encourages simpler billing management. If you need customers to have multiple simultaneous subscriptions, you can enable the
allow_multiple_subscriptions_per_customersetting at the organization level in your dashboard settings page. - Billing Cycle Anchor Date: The
billingCycleAnchorDate(set from thestartDateon creation) determines the day of the month billing occurs. If this date doesn’t exist in a given month (e.g., the 31st in February), billing occurs on the last day of that month. - Billing Periods: Defined by the
startDate,interval(e.g.,Month,Year), andintervalCount. Flowglad automatically calculates thecurrentBillingPeriodStartandcurrentBillingPeriodEndfor each cycle.
Subscription Structure
EachSubscription record has one or more SubscriptionItem records.
SubscriptionRecord: Holds the core details like the customer (customerId), overall status, billing cycle information (interval,intervalCount,billingCycleAnchorDate), trial period (trialEnd), and potentially default/backup payment methods. It also has a primarypriceIdwhich often corresponds to the initial item purchased. But note: theSubscriptionItems define the actual billing components.SubscriptionItemRecord: Represents a specific product or service line item within the subscription. Each item has its ownpriceId,quantity, andunitPrice. This allows for subscriptions with multiple components, potentially added or changed over time. The sum of active subscription items determines the amount billed each period (for non-usage-based items).
Current vs Non-Current Subscriptions
Depending on its status, a subscription can either be current or not. A current subscription will grant feature access and usage credits. A non-current subscription will not. Current subscriptions have one of the following statuses:"active""past_due""trialing""cancellation_scheduled""unpaid"
Creating a Subscription
There are two primary ways to create a subscription:1. Via Checkout Session
Customers can initiate subscriptions themselves by completing a checkout session for a product with asubscription type price.
- How: This can be done through hosted product/price purchase pages or programmatically using the
useBilling()hook’screateCheckoutSessionmethod. - Use Case: Standard customer sign-ups and purchases where the customer interacts directly with a checkout flow initiated from within the product
- Payment Method: Checkout Sessions typically require collecting payment details (unless a trial is offered).
Learn more about setting up checkouts in the Checkout Sessions documentation.
2. Via API
You can programmatically create subscriptions using the API endpoint- How: Requires providing
customerId,priceId,startDate,interval, andintervalCount. - Use Case: Ideal for scenarios where you create subscriptions automatically based on actions within your application, such as user sign-up, plan changes initiated within your UI, or migrations.
- Payment Method: Creating subscriptions via the API does not require a
defaultPaymentMethodIdorbackupPaymentMethodId. This is useful for starting customers on free trials without asking for card details upfront. The subscription status will initially beIncompleteifautoStartis false and there’s no trial or payment method. It becomesTrialingif atrialEnddate is provided, orActiveifautoStartis true and a default payment method exists for the customer or is provided.
Subscription Lifecycle & Billing
Subscriptions transition through various statuses and billing cycles over their lifetime.Statuses
A subscription can be in one of several states (SubscriptionStatus):
Trialing: Active during a free trial period. Considered a “current” subscription.Active: The standard state for a paying, up-to-date subscription. Considered “current”.PastDue: Payment failed, but Flowglad may retry. Considered “current”.Unpaid: Payment failed after retries; requires manual intervention or updated payment method. Considered “current”.Incomplete: Created but needs setup (e.g., payment method added) before becoming active. Not “current”.IncompleteExpired: A related Checkout Session expired before completion. Not “current”.CancellationScheduled: Will be canceled at a future date (usually the end of the current billing period). Considered “current” until the cancellation date.Canceled: The subscription has ended and is no longer active. Not “current”.
Active, PastDue, Trialing, CancellationScheduled, Unpaid) using helper functions or by checking the status directly.
Billing Periods & Transitions
At the end of eachcurrentBillingPeriodEnd, a transition occurs:
- A new billing period is calculated based on the anchor date, interval, and interval count.
- For upcoming charges, a
BillingRunis generated.
Charging Behavior
runBillingAtPeriodStart: This boolean field on theSubscriptiondetermines when the charge for a billing period is attempted.- Default for
subscriptionPrice Type:true. Charges are typically attempted at the start of the billing period (e.g., paying for the upcoming month). - Default for
usagePrice Type:false. Charges are attempted at the end of the billing period after usage for that period has been recorded.
- Default for
- Overrides: This default behavior can be overridden when creating or updating the subscription if needed.
Canceling a Subscription
Flowglad offers flexibility in how subscriptions can be canceled.Cancellation Options
- Immediately: The subscription is canceled right away. Proration logic may apply depending on your settings (though explicit proration controls are still evolving).
- At End of Current Billing Period: The subscription remains active until the
currentBillingPeriodEnd, at which point it transitions toCanceled. The status becomesCancellationScheduleduntil then. - At a Future Date (Coming Soon): Functionality to cancel on a specific arbitrary date in the future is planned.
Methods for Cancellation
- Flowglad Dashboard: Manually cancel subscriptions directly within the Flowglad UI.
- API: Programmatically cancel subscriptions using the API endpoint
- Customer Self-Service: Allow customers to manage their own subscriptions.
- Hosted Billing Portal: (available for livemode customers only) A no-code option accessible via a unique URL for your organization. The
billingPortalUrlis returned in customer billing details fromuseBillingor the get billing details API. It can also be found in the customer details page in your Flowglad dashboard. - Headless Implementation: Use the
useBilling()hook’scancelSubscriptionfunction (ensure it’s used within a<FlowgladProvider>context) to build a completely custom cancellation UI.
- Hosted Billing Portal: (available for livemode customers only) A no-code option accessible via a unique URL for your organization. The