---
title: Subscription Model
description: 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
:field-schema{schema="/types/subscription/subscription.type"}


## Code Example

::code-group
```typescript [Typescript (SDK)]
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
        })
    }
}
```
```typescript [Typescript]
import { Price } from './Price' // you should implement Price model
import { Coupon } from './Coupon' // optional, you should implement Coupon model

interface Subscription {
    id: string
    status: Status
    duration: Duration
    items: Item[]
    discounts?: Discount[]
    metadata?: Record<string, string>
}

export function Subscription(subscription: YourSubscription): Subscription {
    return {
        id: subscription.id,
        ... // map other properties
    }
}

export type Status = Status.Active | Status.Canceled | Status.Paused | Status.Unpaid | Status.Trial

export namespace Status {
    interface Base {
        name: Name
        currentPeriod?: Period
        trial?: Period
    }

    export enum Name {
        Active = "active",
        Canceled = "canceled",
        Paused = "paused",
        Unpaid = "unpaid",
        Trial = "trial",
    }

    export interface Active extends Base {
        name: Name.Active
        currentPeriod: Period
    }

    export interface Canceled extends Base {
        name: Name.Canceled
        canceledAt: Date
    }

    export interface Paused extends Base {
        name: Name.Paused
        start: Date
        end: Date
    }

    export interface Unpaid extends Base {
        name: Name.Unpaid
    }

    export interface Trial extends Base {
        name: Name.Trial
        trial: Period
    }
}

export interface Duration {
    amount: number
    unit: Duration.Unit
}

export namespace Duration {
    export enum Unit {
        Month = "month",
        Year = "year"
    }
}

export interface Period {
    start: Date
    end: Date
}

export interface Item {
    id?: string
    price: Price
    quantity: number
}

export interface Discount {
    coupon: Coupon
    start: Date
    end?: Date
}
```
::