Models

Subscription Model

A subscription is a recurring payment for a product or service. This model includes information about the subscription, including its status, billing cycle, items, and discounts.

Properties

idstring
required

The unique identifier of the subscription

customerIdstring
required

ID of the customer to whom the subscription belongs.

statusunion
required

Includes status.name and status-specific fields. View details bellow.

startDate
required

The start date of the subscription

durationobject
required

The duration of the subscription, also known as the billing cycle

itemsarray
required

The items included in the subscription. Each item represents a product or service and its quantity. Make sure you already have a Price model to use it here.

discountsarray
optional

If your app has subscription level discounts, you can specify them in the discounts array. Make sure you already have a Coupon model to use it here. Required for the Discount Offer.

Code Example

import { Integrator } from '@churnkey/sdk'
import { Price } from './Price' // you should implement Price model
import { Coupon } from './Coupon' // optional, you should implement Coupon model

export class Subscription extends Integrator.Subscription {
    constructor(subscription: YourSubscription) {
        super({
            id: subscription.id,
            items: subscription.items.map(i => {
                return {
                    id: i.id,
                    price: new Price(i.price),
                    quantity: i.quantity
                }
            }),
            discounts: subscription.discounts?.map(d => { // optional
                return {
                    coupon: new Coupon(d.coupon),
                    start: d.start,
                    end: d.end
                }
            }),
            ... // map other properties
        })
    }
}