/** * PaymentService (Standalone / Vanilla JS) * * Complete standalone equivalent of the React SDK's payment system: * - usePaymentQuery (orchestration) * - usePaymentPolling (status polling) * - usePaymentActionHandler (action routing) * - usePaymentProcessors (card, APM, Apple Pay, Google Pay, saved instruments) * - usePaymentInstruments (instrument creation) * - useThreeds (3DS session + challenge) * - useGenericPaymentReturn (generic redirect return) * - useAirwallex3dsReturn (Airwallex-specific redirect return) * - All action handlers: redirect, threeds_auth, processor_auth, error, * kesspay_auth, trustflow_auth, finix_radar, stripe_radar, airwallex radar, * mastercard_auth * * No React. No hooks. No DOM framework dependency. */ import { PaymentsResource, type Payment, type CardPaymentMethod, type ApplePayToken, type GooglePayToken, type PaymentInstrumentResponse, type PaymentInstrumentCustomerResponse } from '../core/resources/payments'; import type { ApiClient } from '../core/resources/apiClient'; export interface PaymentServiceConfig { apiClient: ApiClient; storeId?: string; } export interface CardData { cardNumber: string; expiryDate: string; cvc: string; } export interface ApmData { processorId: string; paymentMethod: string; initiatedBy?: 'customer' | 'merchant'; source?: 'upsell' | 'checkout' | 'offer' | 'missing_club' | 'forced'; } export interface PaymentResult { success: boolean; payment?: Payment; order?: { id: string; checkoutSessionId?: string; } | null; error?: string; /** True if the browser is being redirected (page will unload) */ redirecting?: boolean; } export interface PaymentCallbacks { onProcessing?: (processing: boolean) => void; onError?: (error: string | null) => void; onCurrentPaymentId?: (paymentId: string | null) => void; onSuccess?: (payment: Payment) => void; onFailure?: (error: string) => void; onRedirectReturn?: (paymentId: string) => void; /** Called before a browser redirect, allows caller to await async work (e.g. funnel navigate) */ onBeforeRedirect?: (payment: Payment, redirectUrl: string) => Promise; } export interface PollingCallbacks { onSuccess: (payment: Payment) => void; onFailure: (error: string) => void; onRequireAction?: (payment: Payment) => void; } export declare class PaymentService { private paymentsResource; private threedsResource; private storeConfigResource; private storeId?; private callbacks; private basisTheory; private btInitPromise; private bt3dsClass; private bt3dsInitPromise; private storeConfig; private storeConfigPromise; private pollTimer; private pollAttempts; private isPollingActive; private redirectReturnProcessed; constructor(config: PaymentServiceConfig); /** Expose paymentsResource for advanced consumers */ get payments(): PaymentsResource; setCallbacks(callbacks: PaymentCallbacks): void; /** Pre-warm BasisTheory + store config (non-blocking). */ warmup(): void; destroy(): void; private initBasisTheory; private getBtApiKey; /** Lazy-load @basis-theory/web-threeds (BasisTheory3ds class) */ private initBt3ds; private fetchStoreConfig; stopPolling(): void; startPolling(paymentId: string, callbacks: PollingCallbacks, maxAttempts?: number, interval?: number): void; /** * Internal: call processPaymentDirect and handle requireAction / polling. * Shared by processCardPayment, processApplePayPayment, etc. */ private processAndHandle; /** * After radar / completePaymentAfterAction, handle the resumed payment. */ private handleResumedPayment; handlePaymentAction(payment: Payment): Promise; private handleKessPayAuth; private handleTrustFlowAuth; private handleFinixRadar; private handleStripeRadar; private handleNgeniusThreeds; private handleAirwallexRadar; private handleMasterCardAuth; private loadScript; private waitFor; /** * Detect ALL redirect return types and resume. * Handles both generic returns and Airwallex-specific 3DS returns. * Call once during initialization. Returns true if a return was detected. */ detectRedirectReturn(): boolean; private detectGenericRedirectReturn; private detectAirwallex3dsReturn; private handleAirwallex3dsRedirectReturn; cleanPaymentUrlParams(): void; createCardPaymentInstrument(cardData: CardPaymentMethod): Promise; createApplePayPaymentInstrument(token: ApplePayToken): Promise; createGooglePayPaymentInstrument(token: GooglePayToken): Promise; getCardPaymentInstruments(): Promise; createThreedsSession(paymentInstrument: { id: string; token: string | null; }): Promise<{ id: string; sessionId: string; }>; processCardPayment(checkoutSessionId: string, cardData: CardData, options?: { shippingRateId?: string; }): Promise; processApplePayPayment(checkoutSessionId: string, applePayToken: ApplePayToken, options?: { shippingRateId?: string; }): Promise; processGooglePayPayment(checkoutSessionId: string, googlePayToken: GooglePayToken, options?: { shippingRateId?: string; }): Promise; processPaymentWithInstrument(checkoutSessionId: string, paymentInstrumentId: string, options?: { shippingRateId?: string; }): Promise; processApmPayment(checkoutSessionId: string, apmData: ApmData, options?: { shippingRateId?: string; }): Promise; }