import { SetupIntent } from '@stripe/stripe-js'; import { BaseZenskarElementInstance, ZenskarElementProps } from './base.types'; import type * as setupIntents from '@stripe/stripe-js/dist/stripe-js/setup-intents'; /** * Supported payment method types for Stripe Payment Element */ export type PaymentMethodType = 'card' | 'us_bank_account'; /** * Add Payment Method Element Props * Extends base element props with payment-specific functionality */ export type AddPaymentMethodElementProps = { /** * Triggered when the Element is fully rendered and ready for interaction. */ onReady?: () => void; } & ZenskarElementProps; /** * Event data emitted when the payment method form changes */ export type AddPaymentMethodChangeEvent = { /** Type of element that emitted the event */ elementType: 'add-payment-method'; /** Whether the form is complete and valid */ complete: boolean; /** Whether the form is empty */ empty: boolean; /** Error information if validation fails */ error?: { type: 'validation_error' | 'provider_error' | 'network_error'; code: string; message: string; field?: string; }; }; /** * Element instance type for internal registry * This is what gets registered with the ZenskarProvider */ export type AddPaymentMethodElementInstance = { /** Element type identifier */ type: 'add-payment-method'; /** * Get the current state of the payment form * Returns success/error state without submitting */ getValue: () => PaymentElementFormResult; /** * Trigger validation on the element and show field errors * Returns validation result with isValid flag and error details */ validate: () => Promise; /** * Submit the payment method (confirm setup intent) * Returns success/error result */ submit: () => Promise; /** * Reset the element by creating a new SetupIntent * Useful after successful payment submission to prepare for next payment */ reset: () => void; /** * Whether the form is empty (no data entered) * Use this to distinguish between "no data" vs "invalid data" * Useful for showing neutral state on initial render vs red invalid state */ isEmpty: boolean; } & BaseZenskarElementInstance; type TSuccess = { data: T | null; success: boolean; error?: null; }; type TError = { data?: null; success: boolean; error: T; }; export type PaymentElementFormResult = TSuccess | TError; /** * Optional parameters for Stripe's `confirmSetup` method. * Use this when you've hidden billing fields from the UI but need to provide them programmatically. * * @example * ```tsx * const confirmParams: ConfirmSetupParams = { * payment_method_data: { * billing_details: { * address: { * country: 'US', * }, * }, * }, * } * ``` */ export type ConfirmSetupParams = Partial; export {};