In this example, we’ll set up a 30-day trial that ends when either the time limit expires or the customer runs out of credits, whichever comes first. Customers can upgrade to a paid plan at any time by adding a payment method. The trial works as follows:Documentation Index
Fetch the complete documentation index at: https://docs.withorb.com/llms.txt
Use this file to discover all available pages before exploring further.
- Customers receive 1,000 free credits when they sign up. These credits expire after 30 days.
- The trial ends when the customer runs out of credits or when 30 days have elapsed, whichever comes first.
- Customers can use your product while they have available credits. When credits are depleted, access is blocked.
- Customers are not invoiced during the trial. Invoices only occur after they add a payment method and upgrade to the paid plan.
- When a customer adds a payment method, they immediately upgrade to a $20/month Pro plan that includes 20 credits per month. Additional credits can be purchased on-demand or via automatic top-ups.
Core approach
Two-plan model
Create two separate plans in Orb:- Trial plan: No recurring charge, no credit allocation. Acts as a marker for trial customers and defines the trial period (30 days).
- Pro plan: $20/month recurring charge with a 20-credit monthly allocation. This is the paid tier customers upgrade to.
Prerequisites
Before starting a customer on a trial, set up the following:Credit balance alerts
Create two alerts for the customer using the create alert API:credit_balance_depleted: Fires when the customer’s credit balance reaches 0credit_balance_recovered: Fires when credits are added after depletion
credits). You’ll use these webhooks to block and unblock product access.
Plan creation
Create both the trial plan and Pro plan in Orb: Trial plan configuration:- No recurring charges
- No credit allocations
- Set a default subscription duration of 30 days (configure this as the plan’s default term)
- Set
external_plan_id=trialfor easy reference in your code
- $20 monthly recurring charge (in-advance)
- 20-credit monthly allocation in
creditscurrency - Credits expire at the end of each month (set this on the allocation)
- Set
external_plan_id=pro
Trial setup
Subscribe customer to trial plan
When a customer signs up, create a subscription to the trial plan:end_date to 30 days from the start date. This schedules automatic cancellation if the customer doesn’t upgrade.
Grant trial credits
After creating the subscription, grant credits using the create ledger entry endpoint:per_unit_cost_basis to $0.00 for trial credits to avoid charges. Set expiry_date to match the trial end date.
Handling credit depletion
Receive webhook notification
When the customer depletes their credit balance, Orb sends acustomer.credit_balance_depleted webhook to your endpoint:
Block product access
Do not block access based solely on the webhook. Webhook delivery order is not guaranteed. The customer may have purchased credits between depletion and webhook delivery. Instead, query the customer’s current balance using the fetch credit balance API when you receive the webhook:End trial early
If the customer has depleted credits and has not added a payment method, end the trial:Handling trial expiration
30-day limit webhook
When 30 days elapse, Orb automatically cancels the subscription (based on theend_date you set). You’ll receive a subscription.ended webhook:
Block access on expiration
When you receive this webhook, check if the customer has upgraded to a paid plan:Upgrading to paid plan
When a customer wants to upgrade, collect payment information using Stripe’s payment method collection flows. See Stripe’s save and reuse payment methods documentation. Once the payment method is saved as the customer’s default in Stripe, Orb syncs it automatically.Schedule plan change
When the customer adds a payment method, upgrade them immediately to the Pro plan:change_option=immediate to upgrade right away. Set billing_cycle_alignment=plan_change_date to reset the billing cycle to start today and charge the full $20 monthly fee immediately.
This creates an invoice for $20 and grants the customer their first 20-credit monthly allocation.
Unblock product access
After the plan change completes, unblock access:Credit persistence
Credits granted during the trial persist through the upgrade because you granted them via the ledger entry API, not as a plan allocation. The customer keeps any remaining trial credits plus receives their first 20-credit monthly allocation from the Pro plan.Preventing double trials
Check subscription history
Before creating a trial subscription, verify the customer hasn’t already had a trial:had_trial boolean in your database when you create the first trial subscription.
Subscription continuity
When a customer upgrades from trial to paid, Orb maintains the same subscription resource. The subscription ID remains constant; only the plan changes. This means:- A customer can only have one subscription lifecycle
- Plan changes don’t reset trial eligibility
- Subscription history provides a complete audit trail
Manual operations
Extending trials
Extend a trial by updating the subscription’send_date:
Compensatory credits
Grant additional credits during the trial without charges:per_unit_cost_basis to $0.00 to avoid invoicing. Use the description field to document the reason for the grant.