Skip to main content

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);
BigInt amounts

AccruPay amounts are bigint in the smallest currency unit (cents for USD). 2999n = $29.99.


Template field reference

Required fields

FieldTypeDescription
namestringDisplay name for the template
amountbigintRecurring charge amount in the smallest currency unit
currencyCURRENCYCurrency for all charges on this template

Optional fields

FieldTypeDescription
descriptionstringInternal description — not shown to customers
initialAmountbigintAmount charged at plan creation (e.g. 0n for a free trial, or a setup fee)
renewalIntervalDaysnumberRenewal every N days
renewalIntervalMonthsnumberRenewal every N months
renewalIntervalYearsnumberRenewal every N years
endsAfterDaysnumberAuto-cancel the plan after N days from start
endsAfterMonthsnumberAuto-cancel after N months
endsAfterYearsnumberAuto-cancel after N years
trialPeriodDaysnumberFree trial length in days
trialPeriodMonthsnumberFree trial length in months
trialPeriodYearsnumberFree trial length in years
Renewal intervals

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

StatusDescription
ENABLEDTemplate is active and can be used to create new plans
DISABLEDTemplate 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