import { QelosSDKOptions } from '../types'; import BaseSDK from '../base-sdk'; import { IPlan, ISubscription, IInvoice, ICoupon, BillableEntityType, SubscriptionStatus, InvoiceStatus, BillingCycle, IPaymentsConfigurationMetadata } from '@qelos/global-types'; export interface PaymentsConfigurationRecord { key: string; metadata: IPaymentsConfigurationMetadata; } export interface AdminCheckoutRequest { planId: string; billingCycle: BillingCycle; /** When omitted, the authenticated user / default billable entity is used (same as public checkout). */ billableEntityType?: BillableEntityType; billableEntityId?: string; couponCode?: string; successUrl?: string; cancelUrl?: string; /** When true, cancels any existing active/trialing subscription before checkout. */ reset?: boolean; /** * Admin-only. For plans with `dynamic: true`, sets the `dynamicAmount` on the * pending subscription before initiating checkout. Regular users cannot set this; * use `setSubscriptionDynamicAmount()` + a separate `checkout()` call instead. */ amount?: number; } export interface CreateSubscriptionData { planId: string; billingCycle: BillingCycle; billableEntityType: BillableEntityType; billableEntityId: string; /** Required for plans with `dynamic: true` before checkout can be initiated. */ dynamicAmount?: number; couponCode?: string; } export interface AdminCheckoutResponse { subscriptionId: string; checkoutUrl?: string; clientToken?: string; } export default class QlPaymentsAdmin extends BaseSDK { private options; constructor(options: QelosSDKOptions); getPlans(query?: { isActive?: boolean; }): Promise; getPlan(planId: string): Promise; createPlan(data: Omit): Promise; updatePlan(planId: string, data: Partial): Promise; deletePlan(planId: string): Promise; /** * Start subscription checkout (same as `sdk.payments.checkout`, plus optional billable-entity overrides for admins). * For plans with `dynamic: true`, `amount` is required. */ checkout(params: AdminCheckoutRequest): Promise; getSubscriptions(query?: { billableEntityType?: BillableEntityType; billableEntityId?: string; status?: SubscriptionStatus; }): Promise; getSubscription(subscriptionId: string): Promise; /** * Creates a pending subscription on behalf of any billable entity. Admins can * also set `dynamicAmount` here for dynamic plans, making the subscription * immediately ready for checkout. */ createSubscription(data: CreateSubscriptionData): Promise; cancelSubscription(subscriptionId: string): Promise; /** * Sets or updates the dynamic amount for a pending subscription. Only admins * can call this. Must be done before a user can complete checkout on a dynamic plan. */ setSubscriptionDynamicAmount(subscriptionId: string, amount: number): Promise; getInvoices(query?: { billableEntityType?: BillableEntityType; billableEntityId?: string; status?: InvoiceStatus; }): Promise; getInvoice(invoiceId: string): Promise; getCoupons(query?: { isActive?: boolean; }): Promise; getCoupon(couponId: string): Promise; createCoupon(data: Omit): Promise; updateCoupon(couponId: string, data: Partial): Promise; deleteCoupon(couponId: string): Promise; /** Load tenant payments settings (`payments-configuration`). */ getPaymentsConfiguration(): Promise; /** Update tenant payments settings. Partial metadata is merged with the existing record. */ updatePaymentsConfiguration(metadata: Partial): Promise; }