Properties
idstring
required
Unique identifier of the coupon
durationunion
required
Duration of the coupon. See details below
valueunion
required
Amount of the discount. See details below
namestring
optional
Customer-facing name of the coupon. If not provided, code will be used as name
codestring
recommended
Unique code that can be redeemed for a discount.
redemptionsobject
optional
Redemption limits and counters
expiresAtDate
optional
Date when the coupon expires. Leave empty for no expiration.
Code Example
import { Integrator } from '@churnkey/sdk'
export class Coupon extends Integrator.Coupon {
constructor(coupon: YourCoupon) {
super({
id: coupon.id,
... // map other properties
})
}
}
interface Coupon {
id: string
duration: Duration
value: Value
name?: string
code?: string
redemptions?: Redemptions
expiresAt?: Date
}
export function Coupon(coupon: YourCoupon): Coupon {
return {
id: coupon.id,
... // map other properties
}
}
export type Duration = Duration.Once | Duration.Recurring | Duration.Forever | Duration.CycleAmount
namespace Duration {
export enum Type {
Once = "once",
Recurring = "recurring"
Forever = "forever"
CycleAmount = "cycle-amount"
}
interface Base {
type: Type
}
export interface Once extends Base {
type: Type.Once
}
export interface Recurring extends Base {
type: Type.Recurring
amount: number
unit: Duration.Unit
}
export interface Forever extends Base {
type: Type.Forever
}
export interface CycleAmount extends Base {
type: Type.CycleAmount
cycles: number
}
export enum Unit {
Month = "month",
Year = "year"
}
}
export type Value = Value.Fixed | Value.Percentage
export namespace Value {
export enum Type {
Fixed = "fixed",
Percentage = "percentage"
}
interface Base {
type: Type
}
export interface Fixed extends Base {
type: Type.Fixed
currency: string
unit?: number
flat?: number
}
export interface Percentage extends Base {
type: Type.Percentage
percent: number
currency?: string
}
}
export interface Redemptions {
max?: number
current?: number
}