Overview
The library supports multiple billing models:- Recurring subscriptions - Monthly or annual recurring charges
- Usage-based billing - Pay-as-you-go pricing
- One-time charges - Single payment
Configuration
Define your billing plans in the config:Checking for Active Subscriptions
Check if a shop has an active payment before allowing access:session- Current shop sessionplans- Array of plan names to check (optional - checks all if omitted)isTest- Whether to include test charges
lib/billing/check.ts:40-67
Check Response
By default,check() returns a boolean. Use returnObject: true for detailed information:
lib/billing/check.ts:69-109
Requesting Payment
Request payment when a shop needs to subscribe:confirmationUrl redirects the merchant to approve the charge.
Source: lib/billing/request.ts:99-194
Request Parameters
Custom Return URL
lib/billing/request.ts:122-131
Billing Intervals
- Recurring
- Usage
- One-Time
BillingInterval.Every30Days- Monthly billingBillingInterval.Annual- Yearly billing
Line Items
Subscriptions can include multiple line items:lib/billing/request.ts:204-252
Trial Periods
Offer free trials on recurring subscriptions:Discounts
Apply discounts to recurring charges:lib/billing/request.ts:217-225
Usage Records
For usage-based billing, create usage records:Updating Usage Cap
Update the capped amount for usage billing:lib/billing/index.ts:14-25
Canceling Subscriptions
Cancel an active subscription:Getting Active Subscriptions
Retrieve all active subscriptions:Error Handling
- Plan not found in config
- GraphQL user errors (validation failures)
- Network errors
lib/error.ts:116-128