import type { StyleProp, TextStyle, ViewStyle } from 'react-native'; import type { PickerStyle } from 'react-native-picker-select'; import type { DuffelThreeDSecureProviderProps, UseCreate3DSecureSessionHook, } from './src/DuffelThreeDSecureProvider/DuffelThreeDSecureProvider'; import { DuffelAssistantProps } from '@duffel/react-native-components-assistant'; declare module '@duffel/react-native-components' { export interface DuffelCardFormActions { saveCard: () => void; createCardForTemporaryUse: () => void; } export const DuffelCardForm: React.ForwardRefExoticComponent< DuffelCardFormProps & React.RefAttributes >; export interface UseDuffelCardFormActionsHook { /** * The ref you should pass to the DuffelCardForm component. */ ref: React.RefObject; /** * Call this function to tell the component to save the card. */ saveCard: () => void; /** * Call this function to tell the component to create a card for temporary use. */ createCardForTemporaryUse: () => void; } /** * This hook abstracts the ref for convenience and readability. * Add `ref` to the `DuffelCardForm` `ref` prop and call the functions to trigger the actions you'd like. */ export function useDuffelCardFormActions(): UseDuffelCardFormActionsHook; interface CommonCardholderData { number: string; expiry_month: string; expiry_year: string; brand: CreditCardBrand; name: string; address_line_1: string; address_line_2: string; address_city: string; address_region: string; address_postal_code: string; address_country_code: string; multi_use: boolean; } export interface SaveCardPayload extends CommonCardholderData { multi_use: true; } export interface CreateCardForTemporaryUsePayload extends CommonCardholderData { cvc: string; multi_use: false; } export type CreateCardForTemporaryUsePayloadKey = keyof CreateCardForTemporaryUsePayload; export interface UseSavedCardPayload { card_id: string; cvc: string; brand: CreditCardBrand; } export interface APIError { errors: Array<{ code: string; documentation_url: string; message: string; title: string; type: string; }>; meta: { request_id: string; status: number }; } export interface APIResponse { data: T_Data; } export interface CreateCardForTemporaryUseResponseData { brand: string; id: string; last_4_digits: string; live_mode: boolean; saved: boolean; unavailable_at: string; } export type UseSavedCardPayloadResponseData = CreateCardForTemporaryUseResponseData; export type SaveCardResponseData = CreateCardForTemporaryUseResponseData; export type CreditCardBrand = | 'visa' | 'american_express' | 'mastercard' | 'discover' | 'diners_club' | 'jcb' | 'uatp' | ''; // Using empty string so type can be used on initial form state and when there's no brand match export interface DuffelCardFormStyles { input?: StyleProp; countryPicker?: PickerStyle; label?: StyleProp; errorMessage?: StyleProp; formField?: StyleProp; formContainer?: StyleProp; sectionTitle?: StyleProp; } export type DuffelCardFormAction = | 'validate' | 'save-card' | 'create-card-for-temporary-use'; export type DuffelCardFormIntent = | 'to-create-card-for-temporary-use' | 'to-use-saved-card' | 'to-save-card'; export interface DuffelCardFormProps { /** * The client key retrieved from the Duffel API. */ clientKey: string; /** * The styles to apply to the iframe input elements. */ styles?: DuffelCardFormStyles; /** * If you want to develop with in a different environment of the token proxy, you can choose it here. * * staging will point to `https://api.staging.duffel.card` * production will point to `https://api.duffel.card` * * You may also provide a custom environment URL. * * @default: `production` */ tokenProxyEnvironment?: string | 'staging' | 'production'; /** * The card intent defines what the form is meant to look like. * It can be one of: * * - `to-create-card-for-temporary-use`: The full form will be shown. You may also use this intent for the use case of using and saving the card. * - `to-use-saved-card`: When using this intent also provide the saved card ID. Only a cvv field will be rendered. * - `to-save-card`: The form will be shown without the cvv field. This only allows you to save a card for future use, * but not create an id for immediate, temporary use. For the use case of saving during checkout or save + use, use the `to-create-card-for-temporary-use` intent. */ intent: DuffelCardFormIntent; /** * Once a card is saved, in order to use it, travellers need to enter its cvv. * When using the `use-saved-card` intent, you must provide the card ID. */ savedCardData?: { id: string; brand: CreditCardBrand }; /** * This function will be called when the card form validation has been successful. */ onValidateSuccess: () => void; /** * If the card form validation is successful but data is changed afterwards, * making it invalid, this function will be called. */ onValidateFailure: () => void; /** * This function will be called when the card has been created for temporary use. * * This callback will only be triggered if the `create-card-for-temporary-use` * action is present in the `actions` prop. Alternatively, * you may use the `triggerCreateCardForTemporaryUse` function from the * `useDuffelCardFormActions` hook. */ onCreateCardForTemporaryUseSuccess?: ( data: CreateCardForTemporaryUseResponseData ) => void; /** * This function will be called when the component has failed to create the card for temporary use. * * This callback will only be triggered if the `create-card-for-temporary-use` * action is present in the `actions` prop. Alternatively, * you may use the `triggerCreateCardForTemporaryUse` function from the * `useDuffelCardFormActions` hook. */ onCreateCardForTemporaryUseFailure?: (error: APIError | Error) => void; /** * This function will be called when the card has been saved. * * This callback will only be triggered if the `save-card` * action is present in the `actions` prop. Alternatively, * you may use the `triggerSaveCard` function from the * `useDuffelCardFormActions` hook. */ onSaveCardSuccess?: (data: SaveCardResponseData) => void; /** * This function will be called when saving the card has failed. * * This callback will only be triggered if the `save-card` * action is present in the `actions` prop. Alternatively, * you may use the `triggerSaveCard` function from the * `useDuffelCardFormActions` hook. */ onSaveCardFailure?: (error: APIError | Error) => void; /** * Use this prop to redefine the strings used in the form. * It inlcudes placeholders, labels, and validation messages. * * __Default values__: * * - Labels * - cardNumberLabel: 'Card number' * - expirationDateLabel: 'Expiration date' * - cvvLabel: 'Security code (CVC)' * - nameLabel: 'Name on card' * - countryLabel: 'Country' * - addressLine1Label: 'Address line 1' * - addressLine2Label: 'Address line 2' * - cityLabel: 'City' * - zipCodeLabel: 'ZIP code' * - postalCodeLabel: 'Postal code' * - postcodeLabel: 'Postcode' * - regionLabel: 'Region' * - Placeholders * - expirationDatePlaceholder: 'MM/YY' * - cvvPlaceholder: 'CVV' * - cardNumberPlaceholder: '' * - namePlaceholder: '' * - addressLine1Placeholder: '' * - addressLine2Placeholder: '' * - cityPlaceholder: '' * - zipCodePlaceholder: '' * - postalCodePlaceholder: '' * - postcodePlaceholder: '' * - regionPlaceholder: '' * - Section title * - billingAddressSectionTitle: 'Billing address' * - Validation messages * - cardNumberRequired: 'Card number is required' * - cardNumberDigitsInvalidMessage: 'Card number must be between 15 and 16 digits' * - expiryDateRequiredMessage: 'A valid expiry date is required' * - expiryDateInThePastMessage: 'The expiry date must be in the future' * - cardholderNameRequired: 'Full name is required' * - addressRequiredMessage: 'Address is required' * - cityRequiredMessage: 'City is required' * - regionRequiredMessage: 'Region is required' * - postalCodeRequiredMessage: 'Postal code is required' * - zipInvalidMessage: 'ZIP Code must be 5 digits' * - postalCodeInvalidMessage: 'Postal code is invalid' * - postcodeInvalidMessage: 'Postcode is invalid' * - countryRequiredMessage: 'Country is required' * - cvvRequiredMessage: 'CVC is required' * - cvvOnlyNumberMessage: 'CVC must only contain numbers' * - cvvMinLengthMessage: 'CVC must be at least 3 digits' * - cvvMaxLengthMessage: 'CVC must be no longer than 4 digits' */ customStrings?: Partial; } export interface DuffelCardFormStrings { cardNumberLabel: string; expirationDateLabel: string; cvvLabel: string; nameLabel: string; countryLabel: string; addressLine1Label: string; addressLine2Label: string; cityLabel: string; zipCodeLabel: string; postalCodeLabel: string; postcodeLabel: string; regionLabel: string; cardNumberPlaceholder: string; expirationDatePlaceholder: string; cvvPlaceholder: string; namePlaceholder: string; addressLine1Placeholder: string; addressLine2Placeholder: string; cityPlaceholder: string; zipCodePlaceholder: string; postalCodePlaceholder: string; postcodePlaceholder: string; regionPlaceholder: string; billingAddressSectionTitle: string; cardNumberRequired: string; cardNumberDigitsInvalidMessage: string; expiryDateRequiredMessage: string; expiryDateInThePastMessage: string; cardholderNameRequired: string; addressRequiredMessage: string; cityRequiredMessage: string; regionRequiredMessage: string; postalCodeRequiredMessage: string; zipInvalidMessage: string; postalCodeInvalidMessage: string; postcodeInvalidMessage: string; countryRequiredMessage: string; cvvRequiredMessage: string; cvvOnlyNumberMessage: string; cvvMinLengthMessage: string; cvvMaxLengthMessage: string; } // Assistant export const DuffelAssistant: React.FC; // 3DS export const DuffelThreeDSecureProvider: React.FC; export const useCreate3DSecureSession: UseCreate3DSecureSessionHook; } // To make sure that @duffel/api types are exported correctly export * from '@duffel/api/types'; export * from '@duffel/react-native-components-ancillaries'; export * from './src/DuffelAncillaries/lib/types/DuffelAncillariesProps'; export * from '@duffel/react-native-components-assistant'; export * from './src/DuffelThreeDSecureProvider/lib/types';