recurly-js icon indicating copy to clipboard operation
recurly-js copied to clipboard

Missing types definitions for `coupon` method

Open mreszke opened this issue 3 years ago • 0 comments

types definition from the project I'm working on. May be helpful.

export interface Amount {
  [key: string]: number;
}

export type PercentDiscount = {
  type: 'percent';
  rate: number;
}
export type DolarsDiscount = {
  type: 'dollars';
  amount: Amount;
}
export type Discount = PercentDiscount | DolarsDiscount
export type CouponDuration = 'single_use' | 'forever' | 'temporal';
export type CouponTemporalUnit = 'day' | 'month' | 'year';
export type CouponRedemptionResource = 'account' | 'subscription';

export type CopuponResult = {
  discount: Discount;
  duration: CouponDuration; 
  temporal_amount: number | null;
  temporal_unit: CouponTemporalUnit | null;
  applies_to_plans: boolean;
  applies_to_all_plans: boolean;
  applies_for_months: number | null;
  applies_to_non_plan_charges: boolean
  redemption_resource: CouponRedemptionResource;
  single_use: boolean;
  plans: string[];
  code: string;
  name: string;
}

export type CouponOptions = {
  coupon: string;
  plans: string[];
  plan: string;
  currency: string;
}

export type CouponInfoHandler = (error: RecurlyError, result: CopuponResult) => void;

export type Coupon = (options: CouponOptions, couponInfoHandler: CouponInfoHandler) => void;

mreszke avatar Dec 29 '21 14:12 mreszke