Plan Templates
A payment plan template is a reusable billing schedule definition. It describes the amount, currency, renewal interval, optional trial period, and when the plan ends. Create a template once and reference it when creating plans for individual customers.
Create a template
import AccruPay, { CURRENCY, PAYMENT_PLAN_TEMPLATE_STATUS } from '@accrupay/node';
const sdk = new AccruPay({
apiSecret: process.env.ACCRUPAY_API_SECRET!,
});
const template = await sdk.paymentPlanTemplates.createOne({
merchantTransactionProviderId: process.env.ACCRUPAY_PROVIDER_ID,
data: {
name: 'Monthly Pro',
description: 'Pro plan billed monthly',
amount: 2999n, // $29.99 per billing cycle
currency: CURRENCY.USD,
renewalIntervalMonths: 1,
// Optional: trial period
trialPeriodDays: 14, // 14-day free trial
initialAmount: 0n, // $0 charged at the start of the trial
// Optional: end the plan automatically
endsAfterMonths: 12, // plan ends after 12 billing cycles
},
});
console.log(template.id, template.status);
AccruPay amounts are bigint in the smallest currency unit (cents for USD). 2999n = $29.99.
Template field reference
Required fields
| Field | Type | Description |
|---|---|---|
name | string | Display name for the template |
amount | bigint | Recurring charge amount in the smallest currency unit |
currency | CURRENCY | Currency for all charges on this template |
Optional fields
| Field | Type | Description |
|---|---|---|
description | string | Internal description — not shown to customers |
initialAmount | bigint | Amount charged at plan creation (e.g. 0n for a free trial, or a setup fee) |
renewalIntervalDays | number | Renewal every N days |
renewalIntervalMonths | number | Renewal every N months |
renewalIntervalYears | number | Renewal every N years |
endsAfterDays | number | Auto-cancel the plan after N days from start |
endsAfterMonths | number | Auto-cancel after N months |
endsAfterYears | number | Auto-cancel after N years |
trialPeriodDays | number | Free trial length in days |
trialPeriodMonths | number | Free trial length in months |
trialPeriodYears | number | Free trial length in years |
Set only one renewal interval field at a time (Days, Months, or Years). The provider may reject combinations. If no interval is set, the provider's default interval applies.
Update a template
const updated = await sdk.paymentPlanTemplates.updateOne({
merchantTransactionProviderId: process.env.ACCRUPAY_PROVIDER_ID,
merchantPaymentPlanTemplateId: template.id,
data: {
name: 'Monthly Pro (Updated)',
description: 'Revised pro plan',
},
});
Updating a template does not automatically change the billing schedule of existing active plans — changes apply to newly created plans only, unless the provider propagates updates automatically.
Sync a template
Pull the latest template state from the provider. Use this after making changes in the provider dashboard or to confirm the template is active:
const synced = await sdk.paymentPlanTemplates.syncOne({
merchantTransactionProviderId: process.env.ACCRUPAY_PROVIDER_ID,
providerCode: template.providerCode,
});
console.log(synced.status); // ENABLED or DISABLED
Template status
| Status | Description |
|---|---|
ENABLED | Template is active and can be used to create new plans |
DISABLED | Template is inactive — creating plans against it will fail |
List and fetch templates
// List all templates
const templates = await sdk.paymentPlanTemplates.getMany({
take: 20,
skip: 0,
});
// Fetch a single template
const template = await sdk.paymentPlanTemplates.getOne({
merchantPaymentPlanTemplateId: 'template-id',
});
Next steps
- Payment Plans — create customer subscriptions using a template
- Save a Card — store a payment method to use when creating plans