/** * @module Resources/Subscriptions */ import { AuthParams, PollData, PollParams, RestAPI, SendData } from "../api/RestAPI.js"; import { ProcessingMode } from "./common/enums.js"; import { Metadata, WithStoreMerchantName } from "./common/types.js"; import { ChargeCreateParams, Charges, ChargeThreeDsMode } from "./Charges.js"; import { ChargesListParams, ResponseCharges } from "./Charges.js"; import { CRUDAOSItemsResponse, CRUDPaginationParams, CRUDResource } from "./CRUDResource.js"; import { ResponseCharge } from "./index.js"; import { PaymentType } from "./TransactionTokens.js"; export declare enum SubscriptionPeriod { DAILY = "daily", WEEKLY = "weekly", BIWEEKLY = "biweekly", MONTHLY = "monthly", BIMONTHLY = "bimonthly", QUARTERLY = "quarterly", SEMIANNUALLY = "semiannually", ANNUALLY = "annually" } export declare enum SubscriptionStatus { UNVERIFIED = "unverified", CURRENT = "current", SUSPENDED = "suspended", UNPAID = "unpaid", CANCELED = "canceled", UNCONFIRMED = "unconfirmed", COMPLETED = "completed", AUTHORIZED = "authorized" } export declare enum InstallmentPlan { REVOLVING = "revolving", FIXED_CYCLES = "fixed_cycles", FIXED_CYCLE_AMOUNT = "fixed_cycle_amount" } export interface InstallmentBaseParams { planType: InstallmentPlan; } export interface InstallmentRevolvingParams extends InstallmentBaseParams { planType: InstallmentPlan.REVOLVING; } export interface ScheduledPaymentItem { id: string; dueDate: string; zoneId: string; amount: number; amountFormatted: number; currency: string; isPaid: boolean; isLastPayment: boolean; createdOn: string; successfulPaymentDate?: string; terminateWithStatus?: SubscriptionStatus; retryDate?: string; retryInterval?: string; } export type SchedulePaymentListItem = ScheduledPaymentItem; export type InstallmentPlanItem = { planType: InstallmentPlan.REVOLVING; } | { planType: InstallmentPlan.FIXED_CYCLES; fixedCycles: number; }; export type SubscriptionPlanItem = { planType: InstallmentPlan.FIXED_CYCLES; fixedCycles: number; } | { planType: InstallmentPlan.FIXED_CYCLE_AMOUNT; fixedCycleAmount: number; }; export type SubscriptionsListParams = CRUDPaginationParams & { search?: string; status?: SubscriptionStatus; statuses?: SubscriptionStatus[]; mode?: ProcessingMode; }; export type ScheduledPaymentsListParams = CRUDPaginationParams; export type SubscriptionCreateBaseParams = { transactionTokenId: string; amount: number; currency: string; descriptor?: string; initialAmount?: number; installmentPlan?: InstallmentPlanItem; subscriptionPlan?: SubscriptionPlanItem; onlyDirectCurrency?: boolean; threeDs?: { mode?: ChargeThreeDsMode; redirectEndpoint?: string; redirectId?: string; }; /** * Metadata or stringified JSON object */ metadata?: T | string; /** * Interval (e.g: P7D) * * Needs firstChargeAuthorizationOnly to be true to be used */ firstChargeCaptureAfter?: string; firstChargeAuthorizationOnly?: boolean; } & PeriodParams; export type SubscriptionCreateLegacyParams = SubscriptionCreateBaseParams & { /** * @deprecated Used scheduleSettings instead */ subsequentCyclesStart?: string | number; }; export type SubscriptionCreateNewParams = SubscriptionCreateBaseParams & { scheduleSettings: Partial; }; export type SubscriptionCreateParams = SubscriptionCreateLegacyParams | SubscriptionCreateNewParams; export type SubscriptionUpdateParams = { transactionTokenId?: string; amount?: number; status?: SubscriptionStatus; installmentPlan?: Partial; subscriptionPlan?: Partial; onlyDirectCurrency?: boolean; /** * Metadata or stringified JSON object */ metadata?: T | string; /** * Interval (e.g: P7D) * * Needs firstChargeAuthorizationOnly to be true to be used */ firstChargeCaptureAfter?: string; firstChargeAuthorizationOnly?: boolean; scheduleSettings?: { terminationMode?: TerminateMode; }; }; export type PaymentUpdateParams = Partial; export declare enum TerminateMode { IMMEDIATE = "immediate", ON_NEXT_PAYMENT = "on_next_payment" } export type ScheduleSettings = { startOn?: string; zoneId: string; preserveEndOfMonth?: boolean; retryInterval?: string; terminationMode?: TerminateMode; }; type PeriodParams = { /** * Can not be used with the cyclicalPeriod parameter */ period: SubscriptionPeriod; } | { /** * ISO 8601 period. e.g P1M, P23D. Can not be used with the `period` parameter */ cyclicalPeriod: string | null; period?: never; }; export type SubscriptionItem = { id: string; storeId: string; transactionTokenId: string; mode: ProcessingMode; status: SubscriptionStatus; amount: number; amountFormatted: number; amountLeft: number; amountLeftFormatted: number; currency: string; paymentsLeft: number; descriptor: string; onlyDirectCurrency: boolean; createdOn: string; scheduleSettings: ScheduleSettings | null; nextPayment: ScheduledPaymentItem; threeDs?: { mode?: ChargeThreeDsMode; redirectEndpoint?: string; redirectId?: string; }; nextPaymentDate?: string; initialAmount?: number | null; initialAmountFormatted?: number; subsequentCyclesStart?: string; installmentPlan?: InstallmentPlanItem; subscriptionPlan?: SubscriptionPlanItem; period?: SubscriptionPeriod; cyclicalPeriod?: string | null; cyclesLeft?: number; metadata?: T; }; export type SubscriptionListItem = WithStoreMerchantName>; type SubscriptionSimulationBaseParams = { installmentPlan?: InstallmentPlanItem | null; amount: number; currency: string; initialAmount?: number; paymentType: PaymentType; } & PeriodParams; export type SimulationInstallmentPayment = { amount: number; currency: string; dueDate: string; isLastPayment: boolean; isPaid: boolean; zoneId: string; }; export type SubscriptionSimulationLegacyParams = SubscriptionSimulationBaseParams & { subsequentCyclesStart?: string | number; }; export type SubscriptionSimulationNewParams = SubscriptionSimulationBaseParams & { scheduleSettings: ScheduleSettings; }; export type SubscriptionSimulationParams = SubscriptionSimulationLegacyParams | SubscriptionSimulationNewParams; export type CycleAmount = { cycleDate: string; amount: number; }; export type SubscriptionSimulationLegacyItem = Required & { cycles: CycleAmount[]; }; export type SubscriptionSimulationNewItem = { [index: string]: Omit; }; export type SubscriptionSimulationItem = SubscriptionSimulationLegacyItem | SubscriptionSimulationNewItem; export type ResponseSubscription = SubscriptionItem; export type ResponseSubscriptions = CRUDAOSItemsResponse>; export type ResponsePayment = ScheduledPaymentItem; export type ResponsePayments = CRUDAOSItemsResponse; export type BatchSubscriptionCreateParams = { subscriptions: SubscriptionCreateParams[]; charges?: ChargeCreateParams[]; /** * Metadata or stringified JSON object */ initialChargeMetadata?: T | string; }; export declare enum BatchStatus { SUCCESSFUL = "successful", FAILED = "failed", AWAITING = "awaiting" } export type BatchSubscriptionResponse = { batchId: string; status: BatchStatus; subscriptionIds?: string[]; chargeId?: string; }; export declare class ScheduledPayments extends CRUDResource { static routeBase: string; private _list?; list(storeId: string, subscriptionsId: string, data?: SendData, auth?: AuthParams): Promise; private _get?; get(storeId: string, subscriptionsId: string, id: string, data?: SendData | null, auth?: AuthParams): Promise; private _update?; update(storeId: string, subscriptionsId: string, id: string, data?: SendData, auth?: AuthParams): Promise; private _listCharges?; listCharges(storeId: string, subscriptionsId: string, paymentId: string, data?: SendData, auth?: AuthParams): Promise>; } export declare class Subscriptions extends CRUDResource { static requiredParams: (string | string[])[]; static requiredSimulationParams: (string | string[])[]; static routeBase: string; payments: ScheduledPayments; protected chargesResource: Charges; constructor(api: RestAPI); private _list; list(data?: SendData, auth?: AuthParams, storeId?: string): Promise>; private _suspend?; suspend(storeId: string, id: string, data?: SendData<{ scheduleSettings?: { terminationMode?: TerminateMode; }; }> | null, auth?: AuthParams | null): Promise>; private _unsuspend?; unsuspend(storeId: string, id: string, data?: SendData<{ scheduleSettings?: { terminationMode?: TerminateMode; }; }> | null, auth?: AuthParams | null): Promise>; private _updateToken?; updateToken(storeId: string, id: string, data?: SendData<{ transactionTokenId: string; }>, auth?: AuthParams): Promise>; create(data: SubscriptionCreateParams, auth?: AuthParams): Promise>; createBatch(data: BatchSubscriptionCreateParams, auth?: AuthParams): Promise; private _get; get(storeId: string | null, id: string | null, data?: SendData | null, auth?: AuthParams): Promise>; private _getBatch; getBatch(batchId: string, data?: SendData, auth?: AuthParams): Promise; private _update; update(storeId: string | null, id: string | null, data?: SendData | null, auth?: AuthParams): Promise>; private _delete; delete(storeId: string | null, id: string | null, data?: SendData | null, auth?: AuthParams): Promise; private _charges; charges(storeId: string | null, id: string | null, data?: SendData | null, auth?: AuthParams): Promise>; poll(storeId: string, id: string, data?: SendData, auth?: AuthParams, pollParams?: Partial>>): Promise>; pollBatch(batchId: string, data?: SendData, auth?: AuthParams, pollParams?: Partial>): Promise; pollSubscriptionWithFirstCharge(storeId: string, id: string, data?: SendData, auth?: AuthParams): Promise<{ subscription: ResponseSubscription; charge: ResponseCharge | null; }>; private _simulation; simulation(data: SendData, auth?: AuthParams, storeId?: string): Promise; } export {};