/** * Payment Hook using TanStack Query (V2) * Matches the old usePayment.ts implementation exactly for easy migration */ import type { Payment, PaymentResponse, PaymentOptions, CardPaymentMethod, ApplePayToken, GooglePayToken, PaymentInstrumentResponse, PaymentInstrumentCustomerResponse } from '../../core/resources/payments'; import { TagadaError } from '../../core/errors'; export type { Payment as PaymentType, PaymentResponse, PaymentOptions, CardPaymentMethod, ApplePayToken, PaymentInstrumentResponse, PaymentInstrumentCustomerResponse, PaymentInstrumentCustomer } from '../../core/resources/payments'; /** * Metadata provided with payment callbacks */ export interface PaymentCompletionMetadata { /** True if payment completed after external redirect (3DS, PayPal, etc.) */ isRedirectReturn: boolean; /** Order associated with the payment (if available) */ order?: { id: string; amount?: number; currency?: string; [key: string]: unknown; }; /** Checkout session ID (if available) */ checkoutSessionId?: string; } /** * Hook-level options for universal payment handling */ export interface UsePaymentOptions { /** * Called when payment completes successfully * Works for BOTH immediate success AND post-redirect success (3DS, PayPal, etc.) * @param payment - The completed payment * @param metadata - Additional context about how payment completed */ onPaymentCompleted?: (payment: Payment, metadata: PaymentCompletionMetadata) => void | Promise; /** * Called when payment fails * Works for BOTH immediate failure AND post-redirect failure * @param error - Error message * @param metadata - Additional context about the failure */ onPaymentFailed?: (error: string, metadata: PaymentCompletionMetadata) => void | Promise; } export interface PaymentHook { processCardPayment: (checkoutSessionId: string, cardData: CardPaymentMethod, options?: PaymentOptions) => Promise; processApplePayPayment: (checkoutSessionId: string, applePayToken: ApplePayToken, options?: PaymentOptions) => Promise; processGooglePayPayment: (checkoutSessionId: string, googlePayToken: GooglePayToken, options?: PaymentOptions) => Promise; processPaymentWithInstrument: (checkoutSessionId: string, paymentInstrumentId: string, options?: PaymentOptions) => Promise; processApmPayment: (checkoutSessionId: string, options: { processorId: string; paymentMethod: string; initiatedBy?: 'customer' | 'merchant'; source?: 'upsell' | 'checkout' | 'offer' | 'missing_club' | 'forced'; paymentFlowId?: string; } & Pick) => Promise; createCardPaymentInstrument: (cardData: CardPaymentMethod) => Promise; createApplePayPaymentInstrument: (applePayToken: ApplePayToken) => Promise; createGooglePayPaymentInstrument: (googlePayToken: GooglePayToken) => Promise; getCardPaymentInstruments: () => Promise; isLoading: boolean; error: TagadaError | null; clearError: () => void; currentPaymentId: string | null; } export declare function usePaymentQuery(hookOptions?: UsePaymentOptions): PaymentHook;