Skip to main content

Payment Plans

Manage recurring payment plans. A plan is an active subscription-like agreement that charges a customer on a recurring schedule.

Methods

getMany()

List payment plans with optional filters and pagination.

import { CURRENCY, PAYMENT_PLAN_STATUS } from '@accrupay/node';

const plans = await accrupay.paymentPlans.getMany({
merchantInternalCustomerCode: 'customer-123',
status: PAYMENT_PLAN_STATUS.ACTIVE,
currency: CURRENCY.USD,
take: 20,
skip: 0,
});

Filters

ParameterTypeDescription
idstringFilter by AccruPay plan ID.
transactionProviderTRANSACTION_PROVIDERFilter by provider enum value.
transactionProviderIdstringFilter by provider record ID.
currencyCURRENCYFilter by currency.
providerCodestringProvider's plan identifier.
providerStatusPAYMENT_PLAN_STATUSProvider-reported status.
paymentMethodIdstringPlans using a specific stored payment method.
paymentMethodPAYMENT_METHODFilter by payment method type.
templateIdstringPlans created from a specific template.
customerIdstringFilter by AccruPay customer ID.
providerCustomerCodestringProvider's customer identifier.
merchantInternalCustomerCodestringYour internal customer code.
merchantInternalPaymentPlanCodestringYour internal plan code.
hasProviderErrorbooleanFilter plans that have a provider error.
endedbooleanFilter plans that have ended.
startedbooleanFilter plans that have started billing.
canceledbooleanFilter canceled plans.
skipnumberOffset-based pagination offset.
takenumberOffset-based page size.
afterstringCursor for forward pagination.
firstnumberPage size for forward cursor pagination.
beforestringCursor for backward pagination.
lastnumberPage size for backward cursor pagination.
sortingobjectSort field and direction.

getOne()

Fetch a single payment plan by ID.

const plan = await accrupay.paymentPlans.getOne({
merchantPaymentPlanId: 'plan-id', // required
});
ParameterTypeRequiredDescription
merchantPaymentPlanIdstringYesAccruPay payment plan ID.

createOne()

Create a new payment plan for a customer.

import { CURRENCY } from '@accrupay/node';

const plan = await accrupay.paymentPlans.createOne({
merchantTransactionProviderId: 'provider-id', // required
data: {
amount: 4999n,
currency: CURRENCY.USD,
merchantInternalPaymentPlanCode: 'plan-sub-123',
templateId: 'template-id',
paymentMethodId: 'payment-method-id',
renewalIntervalMonths: 1,
renewalIntervalDays: 0,
renewalIntervalYears: 0,
endsAfterMonths: 12,
endsAfterDays: 0,
endsAfterYears: 0,
trialPeriodDays: 14,
trialPeriodMonths: 0,
trialPeriodYears: 0,
customer: {
merchantInternalCustomerCode: 'customer-123',
},
},
});
ParameterTypeRequiredDescription
merchantTransactionProviderIdstringYesAccruPay transaction provider ID.
dataMerchantPaymentPlanCreateSchemaYesPlan creation payload.
note

amount and initialAmount are bigint. Use the n suffix: 4999n = $49.99.


cancelOne()

Cancel an active payment plan. Both IDs are required.

await accrupay.paymentPlans.cancelOne({
merchantPaymentPlanId: 'plan-id', // required
merchantTransactionProviderId: 'provider-id', // required
});
ParameterTypeRequiredDescription
merchantPaymentPlanIdstringYesAccruPay payment plan ID.
merchantTransactionProviderIdstringYesAccruPay transaction provider ID.

syncOne()

Pull the latest plan state from the provider. Both parameters are required.

await accrupay.paymentPlans.syncOne({
merchantTransactionProviderId: 'provider-id', // required
providerCode: 'provider-plan-code', // required
});
ParameterTypeRequiredDescription
merchantTransactionProviderIdstringYesAccruPay transaction provider ID.
providerCodestringYesThe provider's own plan identifier.

Return shape

All methods return a PaymentPlan object (or a paginated list for getMany).

Identifiers and status

FieldTypeDescription
idstringAccruPay plan ID.
customerIdstringAccruPay customer ID.
merchantInternalCustomerCodestringYour customer identifier.
merchantInternalPaymentPlanCodestringYour plan identifier.
merchantInternalPaymentPlanDescriptionstringOptional description.
statusPAYMENT_PLAN_STATUSAccruPay status (see below).
providerStatusstringRaw status string from the provider.
providerCodestringProvider's plan identifier.
providerCustomerCodestringProvider's customer identifier.
providerErrorstring | nullLast provider error message, if any.
providerLastSyncedAtstringISO timestamp of last sync.
providerLastVerifiedAtstringISO timestamp of last verification.

Amounts and currency

FieldTypeDescription
amountbigintRecurring charge amount in smallest currency unit.
initialAmountbigintFirst-charge amount (may differ for setup fees).
currencyCURRENCYISO 4217 currency.

Schedule

FieldTypeDescription
renewalIntervalDaysnumberDays between renewals.
renewalIntervalMonthsnumberMonths between renewals.
renewalIntervalYearsnumberYears between renewals.
endsAfterDaysnumberPlan lifetime in days.
endsAfterMonthsnumberPlan lifetime in months.
endsAfterYearsnumberPlan lifetime in years.
trialPeriodDaysnumberTrial length in days.
trialPeriodMonthsnumberTrial length in months.
trialPeriodYearsnumberTrial length in years.
periodCountnumberNumber of billing periods completed.
timeAnchorstringBilling anchor timestamp.
currentPeriodStartstringCurrent period start (ISO).
currentPeriodEndstringCurrent period end (ISO).
startedAtstring | nullWhen billing started (ISO).
endsAtstring | nullScheduled end date (ISO).
trialEndsAtstring | nullTrial end date (ISO).
canceledAtstring | nullCancellation timestamp (ISO).

Relations

FieldTypeDescription
paymentMethodIdstringStored payment method used.
templateIdstring | nullTemplate this plan was created from.
transactionProviderIdstringAssociated transaction provider.
payloadobject | nullArbitrary metadata.
paymentMethodobjectNested payment method object.
templateobject | nullNested template object.
transactionProviderobjectNested provider object.
transactionsobject[]Transactions generated by this plan.
createdAtstringISO creation timestamp.
updatedAtstringISO last-update timestamp.

PAYMENT_PLAN_STATUS values

ValueMeaning
ACTIVEPlan is billing normally.
CANCELEDPlan was canceled by merchant or customer.
ENDEDPlan reached its end date or period count.
PAUSEDBilling is temporarily suspended.
PENDINGPlan created but not yet started.
TRIALINGPlan is in the trial period.