Advanced Subscriptions
Advanced subscriptions are recurrent payments that can:
- Recur with any interval, e.g. every 3 months
- Start at a certain time, not immediately
- Change payment amount over time
- Continue for a finite number of payments, not indefinitely
You can set the subscription rules with by passing the subscription
field to the widget or the API when creating a payment. The subscription
parameter is an array of type SubscriptionItem
.
Code Example
Let's create a subscription that has an "introductory rate" of $10.00 for the first 3 months, then changes to $50.00 per month in perpetuity. In addition, starting after 6 months, the user should be billed $100.00 every 6 months in perpetuity.
<button onclick="atlos.Pay({
merchantId: '8XOZ64KC9X',
orderId: '123456',
orderCurrency: 'USD',
userName: 'John Smith',
userEmail: 'name@email.com',
subscription: [
{
amount: 10.00,
unit: atlos.RECURRENCE_MONTH,
interval: 1,
paymentCount: 3,
},
{
amount: 50.00,
unit: atlos.RECURRENCE_MONTH,
interval: 1,
startInterval: 3,
},
{
amount: 100.00,
unit: atlos.RECURRENCE_MONTH,
interval: 6,
startInterval: 1,
},
]})">
Pay & Subscribe
</button>
SubscriptionItem
Type
export type SubscriptionItem = {
amount: number,
unit: number,
interval?: number,
startInterval?: number,
startDate?: string,
paymentCount?: number,
}
Field Description
Field | Type | Required | Description | Default |
---|---|---|---|---|
amount | number | yes | amount to bill in orderCurrency | – |
unit | number | yes | the time unit for the recurrence interval, e.g. atlos.RECURRENCE_MONTH | – |
interval | number | no | recurrence interval, e.g. 3 months | 1 |
startInterval | number | no | start date measured in intervals from now, e.g. start in 2 months | 0 |
startDate | string | no | start date; the date format must be YYYY-MM-DD | null |
paymentCount | number | no | total number of payments for this entry; if omitted, then bills until canceled | null |
If both, the recurrence
and the subscription
are specified, the subscription
value will be used.
If both, the startInterval
and the startDate
are specified, the startDate
will be used.
When using the subscription
parameter, you do not need to specify the orderAmount
, as it will be computed automatically. However, if you do specify the orderAmount
, it will override the computed subscription amount and your payment will be for the orderAmount
.