/** * SDK Type Definitions */ export type CheckoutMode = "test" | "live"; export type DisplayType = "overlay" | "inline"; export type EventType = "checkout.opened" | "checkout.payment_page_opened" | "checkout.closed" | "checkout.error" | "checkout.customer_details_submitted" | "checkout.redirect" | "checkout.resize" | "checkout.breakdown" | "checkout.link_expired" | "checkout.status" | "checkout.redirect_requested" | "checkout.pay_button_clicked" | "checkout.keys_provided" | "checkout.form_ready" | "checkout.payment_method_selected" | "checkout.express_fallback"; export interface CheckoutEvent { event_type: EventType; data?: Record; } export type CheckoutEventCallback = (event: CheckoutEvent) => void; export type EventCallback = (data: Record) => void; export type EventMap = Record; export interface CheckoutConfig { mode: CheckoutMode; onEvent?: CheckoutEventCallback; displayType?: DisplayType; } export type FontSize = "xs" | "sm" | "md" | "lg" | "xl" | "2xl"; export type FontWeight = "normal" | "medium" | "bold" | "extraBold"; export interface CheckoutOptions { showTimer?: boolean; showSecurityBadge?: boolean; /** * `true`: the one-line legal footer on every device. `false`: the full * footer everywhere. Unset: the checkout decides (express on a phone gets * the one-line footer). */ compactFooter?: boolean; manualRedirect?: boolean; payButtonText?: string; fontSize?: FontSize; fontWeight?: FontWeight; } export interface OpenCheckoutOptions { checkoutUrl: string; elementId?: string; options?: CheckoutOptions; } export type DodoWalletDisplayMode = "auto" | "never"; export interface DodoWalletsConfig { applePay?: DodoWalletDisplayMode; googlePay?: DodoWalletDisplayMode; payPal?: DodoWalletDisplayMode; } /** * Subset of the SDK's PaymentMethodSubType that this library uses for * `allowedPaymentMethods`. The SDK accepts the full union; we only need the * wallet/card identifiers here. */ export type DodoPaymentMethodSubType = "apple_pay" | "google_pay" | "credit" | "debit"; export interface DodoElementsOptions { clientSecret: string; appearance?: { theme?: string; variables?: Record; }; locale?: string; walletReturnUrl?: string; wallets?: DodoWalletsConfig; /** Restricts which payment methods render. Omitted/empty shows all; when set, * only the listed methods appear. Saved methods stay governed by * displaySavedPaymentMethods. */ allowedPaymentMethods?: DodoPaymentMethodSubType[]; /** When false, the SDK does not show saved customer payment methods. */ displaySavedPaymentMethods?: boolean; manualRedirect?: boolean; /** When true, Apple Pay and Google Pay also collect the payer name. */ walletCollectName?: boolean; } export type DodoElementType = "payment" | "card" | "wallet"; export interface DodoPaymentElement { mount: (selector: string) => void; unmount: () => void; destroy: () => void; on: (event: string, handler: (data: unknown) => void) => void; } export interface DodoElements { create: (type: DodoElementType, options?: { layout?: "tabs" | "accordion"; }) => DodoPaymentElement; update: (options: Partial) => void; } export interface DodoInstance { elements: (options: DodoElementsOptions) => DodoElements; } export interface DodoLoadOptions { apiUrl?: string; baseUrl?: string; locale?: string; } export interface DodoCheckoutWebSDK { loadDodoPayments: (publishableKey: string, options?: DodoLoadOptions) => DodoInstance; } export interface CheckoutState { iframe: HTMLIFrameElement | null; container: HTMLDivElement | null; config: CheckoutConfig; baseUrl: string; allowedOrigin: string; iframeId: string; eventListeners: EventMap; dodoInstance: DodoInstance | null; walletElement: DodoPaymentElement | null; walletElementContainer: HTMLDivElement | null; dodoScriptPromise: Promise | null; walletResizeObserver: ResizeObserver | null; lastCheckoutIframeHeight: number; wrapperDiv: HTMLDivElement | null; iframeResizerInstance: Array<{ iFrameResizer: { close: () => void; }; }> | null; } export interface CheckoutBreakdownData { subTotal?: number; discount?: number; total?: number; tax?: number; currency?: string; finalTotal?: number; finalTotalCurrency?: string; }