import {z} from 'zod' export type Address = {address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined}; export type PhoneNumber = {country_code?: string | undefined, number?: string | undefined}; export type AccountHolder = {type: 'individual' | 'corporate' | 'government', first_name: string, last_name: string, tax_id?: string | undefined, date_of_birth?: string | undefined, country_of_birth?: string | undefined, residential_status?: ('resident' | 'non_resident') | undefined, billing_address: Address, phone?: PhoneNumber | undefined, identification?: ({type?: string | undefined, issuing_country?: string | undefined, number?: string | undefined}) | undefined} | {type: 'individual' | 'corporate' | 'government', company_name: string, tax_id?: string | undefined, billing_address?: Address | undefined} | {type: 'individual' | 'corporate' | 'government', company_name: string, tax_id?: string | undefined, billing_address?: Address | undefined}; export type TokenData = {version?: string | undefined, data?: string | undefined, signature?: string | undefined, header?: Record | undefined}; export type AccountHolderEps = {first_name: string, last_name: string}; export type PaymentRequestSource = {number: string, expiry_month: number, expiry_year: number, name?: string | undefined, cvv?: string | undefined, stored?: boolean | undefined, store_for_future_use?: boolean | undefined, billing_address?: Address | undefined, phone?: PhoneNumber | undefined, account_holder?: {type: string} | undefined, allow_update?: boolean | undefined, type: 'card'} | {billing_address?: ({address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: number | undefined, country?: string | undefined}) | undefined, type: 'wechatpay'} | {type: 'vipps'} | {type: 'twint'} | {billing_address: Address, type: 'tamara'} | {type: 'stcpay'} | {country: string, account_number: string, currency: string, mandate_id?: string | undefined, mandate_type?: ('Core' | 'B2B') | undefined, date_of_signature?: string | undefined, account_holder: {first_name?: string | undefined, last_name?: string | undefined, company_name?: string | undefined, type?: ('Individual' | 'Corporate') | undefined, billing_address: {address_line1: string, address_line2: string, city: string, zip: string, country: string}}, type: 'sepa'} | {type: 'bacs', id: string} | {type: 'sequra', billing_address: Address} | {type: 'qpay', quantity?: number | undefined, description: string, language?: string | undefined, national_id?: string | undefined} | {type: 'p24', payment_country: 'PL', account_holder_name: string, account_holder_email: string, billing_descriptor?: string | undefined} | {token: string, account_holder: AccountHolder, type: 'plaid'} | {type: 'paynow'} | {type: 'octopus'} | {payment_country: 'PT', account_holder_name: string, billing_descriptor?: string | undefined, type: 'multibanco'} | {type: 'mobilepay'} | {type: 'mbway'} | {type: 'knet', language?: ('ar' | 'en') | undefined, user_defined_field1?: string | undefined, user_defined_field2?: string | undefined, user_defined_field3?: string | undefined, user_defined_field4?: string | undefined, user_defined_field5?: string | undefined, card_token?: string | undefined, ptlf?: string | undefined, token_type?: 'applepay' | undefined, token_data?: TokenData | undefined, payment_method_details?: ({display_name?: string | undefined, type?: string | undefined, network?: string | undefined}) | undefined} | {description: string, language?: string | undefined, type: 'ideal'} | {description: string, customer_profile_id?: string | undefined, customer_email: string, customer_mobile: string, expires_on?: string | undefined, products: Array<{product_id: string, quantity: number, price: number, description: string}>, type: 'fawry'} | {type: 'eps', purpose: string, account_holder?: AccountHolderEps | undefined} | {type: 'bizum'} | {type: 'blik', partner_agreement_id?: string | undefined} | {payment_country: 'BE', account_holder_name: string, billing_descriptor?: string | undefined, language?: ('fr' | 'nl' | 'de' | 'en') | undefined, type: 'bancontact'} | {type: 'alma', billing_address?: ({address_line1: string, address_line2?: string | undefined, city: string, state?: string | undefined, zip?: string | undefined, country: string}) | undefined} | {type: 'alipay_cn'} | {type: 'alipay_hk'} | {type: 'alipay_plus'} | {type: 'dana'} | {type: 'gcash'} | {type: 'kakaopay'} | {type: 'tng'} | {type: 'truemoney'} | {account_type: 'savings' | 'checking' | 'cash', country: string, account_number: string, bank_code: string, account_holder: {type: 'individual' | 'corporate' | 'government', first_name: string, last_name: string, company_name?: string | undefined, billing_address?: Address | undefined, date_of_birth?: string | undefined, identification?: ({type?: string | undefined, issuing_country?: string | undefined, number?: string | undefined}) | undefined, account_name_inquiry?: boolean | undefined, allow_partial_match?: boolean | undefined}, type: 'ach'} | {type: 'token', token?: string | undefined, billing_address?: Address | undefined, phone?: PhoneNumber | undefined, store_for_future_use?: boolean | undefined, account_holder?: Record | undefined} | {token: string, expiry_month: number, expiry_year: number, token_type: 'vts' | 'mdes' | 'applepay' | 'googlepay', cryptogram: string, eci: string, stored?: boolean | undefined, store_for_future_use?: boolean | undefined, name?: string | undefined, cvv?: string | undefined, billing_address?: Address | undefined, phone?: PhoneNumber | undefined, account_holder?: Record | undefined, type: 'network_token'} | {id: string, cvv?: string | undefined, payment_method?: string | undefined, billing_address?: Address | undefined, phone?: PhoneNumber | undefined, account_holder?: Record | undefined, allow_update?: boolean | undefined, type: 'id'} | {id: string, billing_address?: Address | undefined, phone?: PhoneNumber | undefined, account_holder?: Record | undefined, allow_update?: boolean | undefined, type: 'customer'}; export type PaymentRequestFallbackSource = {number: string, expiry_month: number, expiry_year: number, name?: string | undefined, cvv?: string | undefined, stored?: boolean | undefined, store_for_future_use?: boolean | undefined, billing_address?: Address | undefined, phone?: PhoneNumber | undefined, account_holder?: Record | undefined, allow_update?: boolean | undefined, type: 'card'}; export type PartialAuthorization = {enabled: boolean}; export type Timestamp = string; export type CustomerSummary = {registration_date?: string | undefined, first_transaction_date?: string | undefined, last_payment_date?: string | undefined, total_order_count?: number | undefined, last_payment_amount?: number | undefined, is_premium_customer?: boolean | undefined, is_returning_customer?: boolean | undefined, lifetime_value?: number | undefined}; export type CustomerRequest = {id?: string | undefined, email?: string | undefined, name?: string | undefined, tax_number?: string | undefined, phone?: PhoneNumber | undefined, summary?: CustomerSummary | undefined}; export type LocalBillingDescriptor = {name: string, character_set: 'kanji' | 'katakana'}; export type BillingDescriptor = {name: string, city: string, reference?: string | undefined, local_descriptors?: (Array | null) | undefined}; export type Shipping = {first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, address?: Address | undefined, phone?: PhoneNumber | undefined, from_address_zip?: string | undefined, timeframe?: ('ElectronicDelivery' | 'SameDay' | 'Overnight' | 'TwoDayOrMore') | undefined, method?: ('Digital' | 'PickUp' | 'BillingAddress' | 'OtherAddress') | undefined, delay?: number | undefined}; export type MerchantAuthenticationInfo = {three_ds_req_auth_method?: ('no_threeds_requestor_authentication_occurred' | 'three3ds_requestor_own_credentials' | 'federated_id' | 'issuer_credentials' | 'third_party_authentication' | 'fido_authenticator' | 'fido_authenticator_fido_assurance_data_signed' | 'src_assurance_data') | undefined, three_ds_req_auth_timestamp?: string | undefined, three_ds_req_auth_data?: string | undefined}; export type AccountInfo = {purchase_count?: number | undefined, account_age?: ('no_account' | 'created_during_transaction' | 'less_than_thirty_days' | 'thirty_to_sixty_days' | 'more_than_sixty_days') | undefined, add_card_attempts?: number | undefined, shipping_address_age?: ('this_transaction' | 'less_than_thirty_days' | 'thirty_to_sixty_days' | 'more_than_sixty_days') | undefined, account_name_matches_shipping_name?: boolean | undefined, suspicious_account_activity?: boolean | undefined, transactions_today?: number | undefined, authentication_method?: ('no_authentication' | 'own_credentials' | 'federated_id' | 'issuer_credentials' | 'third_party_authentication' | 'fido') | undefined, cardholder_account_age_indicator?: ('no_account,' | 'this_transaction' | 'less_than_thirty_days' | 'thirty_to_sixty_days' | 'more_than_sixty_days') | undefined, account_change?: string | undefined, account_change_indicator?: ('this_transaction' | 'less_than_thirty_days' | 'thirty_to_sixty_days' | 'more_than_sixty_days') | undefined, account_date?: string | undefined, account_password_change?: string | undefined, account_password_change_indicator?: ('no_change' | 'this_transaction' | 'less_than_thirty_days' | 'thirty_to_sixty_days' | 'more_than_sixty_days') | undefined, transactions_per_year?: number | undefined, payment_account_age?: string | undefined, shipping_address_usage?: string | undefined, account_type?: ('not_applicable' | 'credit' | 'debit') | undefined, account_id?: string | undefined}; export type InitialAuthentication = {acs_transaction_id?: string | undefined, authentication_method?: ('frictionless_authentication' | 'challenge_occurred' | 'avs_verified' | 'other_issuer_methods') | undefined, authentication_timestamp?: string | undefined, authentication_data?: string | undefined, initial_session_id?: string | undefined}; export type PaymentAuthenticationRequest = {preferred_experiences?: (Array<'google_spa' | '3ds'>) | undefined}; export type Network = {ipv4?: string | undefined, ipv6?: string | undefined, tor?: boolean | undefined, vpn?: boolean | undefined, proxy?: boolean | undefined}; export type DeviceProvider = {id?: string | undefined, name?: string | undefined}; export type DeviceDetails = {user_agent?: string | undefined, network?: Network | undefined, provider?: DeviceProvider | undefined, timestamp?: string | undefined, timezone?: string | undefined, virtual_machine?: boolean | undefined, incognito?: boolean | undefined, jailbroken?: boolean | undefined, rooted?: boolean | undefined, java_enabled?: boolean | undefined, javascript_enabled?: boolean | undefined, language?: string | undefined, color_depth?: string | undefined, screen_height?: string | undefined, screen_width?: string | undefined, user_agent_client_hint?: string | undefined, iframe_payment_allowed?: boolean | undefined, accept_header?: string | undefined}; export type RiskRequest = {enabled?: boolean | undefined, device_session_id?: string | undefined, device?: DeviceDetails | undefined}; export type IPAddress = string; export type PaymentRequestSender = {type: 'individual' | 'corporate' | 'instrument', reference?: string | undefined, first_name: string, last_name: string, date_of_birth?: string | undefined, address: Address, identification?: ({type?: ('passport' | 'driving_licence' | 'national_id') | undefined, number?: string | undefined, issuing_country?: string | undefined}) | undefined} | {type: 'individual' | 'corporate' | 'instrument', reference?: string | undefined, company_name: string, address: Address} | {type: 'individual' | 'corporate' | 'instrument', reference?: string | undefined}; export type PaymentRecipient = {dob?: string | undefined, account_number?: string | undefined, address?: Address | undefined, zip?: string | undefined, first_name?: string | undefined, last_name?: string | undefined}; export type AmountAllocations = Array<{id: string, amount: number, reference?: string | undefined, commission?: ({amount?: number | undefined, percentage?: number | undefined}) | undefined}>; export type AirlineData = Array<{ticket?: ({number?: string | undefined, issue_date?: string | undefined, issuing_carrier_code?: string | undefined, travel_package_indicator?: string | undefined, travel_agency_name?: string | undefined, travel_agency_code?: string | undefined}) | undefined, passenger?: (Array<{first_name?: string | undefined, last_name?: string | undefined, date_of_birth?: string | undefined, address?: ({country?: string | undefined}) | undefined}>) | undefined, flight_leg_details?: (Array<{flight_number?: string | undefined, carrier_code?: string | undefined, class_of_travelling?: string | undefined, departure_airport?: string | undefined, departure_date?: string | undefined, departure_time?: string | undefined, arrival_airport?: string | undefined, stop_over_code?: string | undefined, fare_basis_code?: string | undefined}>) | undefined}>; export type AccommodationData = Array<{name?: string | undefined, booking_reference?: string | undefined, check_in_date?: string | undefined, check_out_date?: string | undefined, address?: ({address_line1?: string | undefined, zip?: string | undefined}) | undefined, state?: string | undefined, country?: string | undefined, city?: string | undefined, number_of_rooms?: number | undefined, guests?: (Array<{first_name?: string | undefined, last_name?: string | undefined, date_of_birth?: string | undefined}>) | undefined, room?: (Array<{rate?: string | undefined, number_of_nights_at_room_rate?: string | undefined}>) | undefined, property_phone?: (Array<{country_code?: string | undefined, number?: string | undefined}>) | undefined, customer_service_phone?: (Array<{country_code?: string | undefined, number?: string | undefined}>) | undefined}>; export type Aggregator = {sub_merchant_id?: string | undefined, aggregator_id_visa?: string | undefined, aggregator_id_mc?: string | undefined}; export type PaymentRequestProcessing = {order_id?: string | undefined, tax_amount?: number | undefined, surcharge_amount?: number | undefined, discount_amount?: number | undefined, duty_amount?: number | undefined, shipping_amount?: number | undefined, shipping_tax_amount?: number | undefined, aft?: boolean | undefined, preferred_scheme?: ('mastercard' | 'visa' | 'cartes_bancaires' | 'accel' | 'discover' | 'eftpos' | 'maestro' | 'nyce' | 'pulse' | 'star') | undefined, merchant_initiated_reason?: ('Delayed_charge' | 'Resubmission' | 'No_show' | 'Reauthorization') | undefined, campaign_id?: number | undefined, product_type?: string | undefined, open_id?: string | undefined, original_order_amount?: number | undefined, receipt_id?: string | undefined, terminal_type?: ('APP' | 'WAP' | 'WEB') | undefined, os_type?: ('ANDROID' | 'IOS') | undefined, invoice_id?: string | undefined, locale?: string | undefined, airline_data?: AirlineData | undefined, accommodation_data?: AccommodationData | undefined, merchant_callback_url?: string | undefined, line_of_business?: string | undefined, pan_preference?: ('fpan' | 'dpan') | undefined, service_type?: ('same_day' | 'standard') | undefined, partner_code?: string | undefined, provision_network_token?: boolean | undefined, card_type?: ('credit' | 'debit') | undefined, affiliate_id?: string | undefined, affiliate_url?: string | undefined, purchase_country?: string | undefined, foreign_retailer_amount?: number | undefined, reconciliation_id?: string | undefined, aggregator?: Aggregator | undefined, scheme_transaction_link_id?: string | undefined}; export type Items = Array<{type?: ('digital' | 'discount' | 'physical') | undefined, sub_type?: ('blockchain' | 'cbdc' | 'cryptocurrency' | 'nft' | 'stablecoin') | undefined, name?: string | undefined, quantity?: number | undefined, unit_price?: number | undefined, reference?: string | undefined, commodity_code?: string | undefined, unit_of_measure?: string | undefined, total_amount?: number | undefined, tax_rate?: number | undefined, tax_amount?: number | undefined, tax_exempt?: boolean | undefined, discount_amount?: number | undefined, wxpay_goods_id?: string | undefined, url?: string | undefined, image_url?: string | undefined, service_ends_on?: string | undefined, purchase_country?: string | undefined, foreign_retailer_amount?: number | undefined}>; export type DunningRetryRequest = {enabled: boolean, max_attempts?: number | undefined, end_after_days?: number | undefined}; export type DowntimeRetryRequest = {enabled: boolean}; export type RetryRequest = {enabled: boolean, dunning?: DunningRetryRequest | undefined, downtime?: DowntimeRetryRequest | undefined}; export type Subscription = {id?: string | undefined}; export type Segment = {brand?: string | undefined, business_category?: string | undefined, market?: string | undefined}; export type Purpose = 'donations' | 'education' | 'emergency_need' | 'expatriation' | 'family_support' | 'financial_services' | 'gifts' | 'income' | 'insurance' | 'investment' | 'it_services' | 'leisure' | 'loan_payment' | 'medical_treatment' | 'other' | 'pension' | 'royalties' | 'savings' | 'travel_and_tourism'; export type Attempt = {scheme?: ('accel' | 'amex' | 'cartes_bancaires' | 'diners' | 'discover' | 'jcb' | 'mada' | 'maestro' | 'mastercard' | 'nyce' | 'omannet' | 'pulse' | 'shazam' | 'star' | 'upi' | 'visa') | undefined}; export type PaymentRequest = {source?: PaymentRequestSource | undefined, fallback_source?: PaymentRequestFallbackSource | undefined, amount?: number | undefined, currency: string, payment_type?: ('Regular' | 'Recurring' | 'MOTO' | 'Installment' | 'PayLater' | 'Unscheduled') | undefined, payment_plan?: ({amount_variability?: ('Fixed' | 'Variable') | undefined, days_between_payments?: number | undefined, total_number_of_payments?: number | undefined, current_payment_number?: number | undefined, expiry?: string | undefined, name?: string | undefined, start_date?: string | undefined, amount?: number | undefined} | {financing?: boolean | undefined, days_between_payments?: number | undefined, total_number_of_payments?: number | undefined, current_payment_number?: number | undefined, expiry?: string | undefined, name?: string | undefined, start_date?: string | undefined, amount?: number | undefined}) | undefined, merchant_initiated?: boolean | undefined, reference?: string | undefined, description?: string | undefined, authorization_type?: ('Final' | 'Estimated') | undefined, partial_authorization?: PartialAuthorization | undefined, capture?: boolean | undefined, capture_on?: Timestamp | undefined, expire_on?: Timestamp | undefined, customer?: CustomerRequest | undefined, billing_descriptor?: BillingDescriptor | undefined, shipping?: Shipping | undefined, '3ds'?: ({enabled: 'true' | 'false', challenge_indicator?: ('no_preference' | 'no_challenge_requested' | 'challenge_requested' | 'challenge_requested_mandate') | undefined, allow_upgrade?: boolean | undefined, exemption?: ('low_value' | 'trusted_listing' | 'trusted_listing_prompt' | 'transaction_risk_assessment' | '3ds_outage' | 'sca_delegation' | 'out_of_sca_scope' | 'low_risk_program' | 'recurring_operation' | 'data_share' | 'other') | undefined} | {enabled: 'true' | 'false', challenge_indicator?: ('no_preference' | 'no_challenge_requested' | 'challenge_requested' | 'challenge_requested_mandate') | undefined, attempt_n3d?: boolean | undefined, exemption?: ('low_value' | 'trusted_listing' | 'trusted_listing_prompt' | 'transaction_risk_assessment' | 'data_share') | undefined, merchant_authentication_info?: MerchantAuthenticationInfo | undefined, account_info?: AccountInfo | undefined} | {enabled: true, authentication_id: string} | {enabled: true, eci: string, cryptogram: string, xid: string, version: string, exemption?: ('low_value' | 'secure_corporate_payment' | 'trusted_listing' | 'transaction_risk_assessment' | '3ds_outage' | 'sca_delegation' | 'out_of_sca_scope' | 'other' | 'low_risk_program' | 'recurring_operation') | undefined, status?: string | undefined, authentication_date?: (string | null) | undefined, authentication_amount?: (number | null) | undefined, flow_type?: ('challenged' | 'frictionless' | 'frictionless_delegated') | undefined, challenge_indicator?: ('no_preference' | 'no_challenge_requested' | 'challenge_requested' | 'challenge_requested_mandate') | undefined, status_reason_code?: string | undefined, challenge_cancel_reason?: string | undefined, score?: string | undefined, cryptogram_algorithm?: string | undefined, initial_authentication?: InitialAuthentication | undefined}) | undefined, authentication?: PaymentAuthenticationRequest | undefined, processing_channel_id?: string | undefined, previous_payment_id?: string | undefined, risk?: RiskRequest | undefined, success_url?: string | undefined, failure_url?: string | undefined, payment_ip?: IPAddress | undefined, sender?: PaymentRequestSender | undefined, recipient?: PaymentRecipient | undefined, amount_allocations?: AmountAllocations | undefined, processing?: PaymentRequestProcessing | undefined, items?: Items | undefined, retry?: RetryRequest | undefined, subscription?: Subscription | undefined, metadata?: Record | undefined, segment?: Segment | undefined, instruction?: ({purpose?: Purpose | undefined}) | undefined, routing?: ({attempts?: Array | undefined}) | undefined}; export type PaymentContextId = string; export type PaymentContextPaymentRequest = {payment_context_id: PaymentContextId, amount?: number | undefined, reference?: string | undefined, description?: string | undefined, processing_channel_id?: string | undefined, processing?: ({invoice_id?: string | undefined, shipping_amount?: number | undefined, discount_amount?: number | undefined, tax_amount?: number | undefined, otp_value?: string | undefined, airline_data?: AirlineData | undefined, accommodation_data?: AccommodationData | undefined}) | undefined, shipping?: Shipping | undefined, segment?: Segment | undefined}; export type CardPayoutRequestDestination = {type: string}; export type CardPayoutItems = Array<{type?: ('digital' | 'physical') | undefined, sub_type?: ('blockchain' | 'cbdc' | 'cryptocurrency' | 'nft' | 'stablecoin') | undefined}>; export type CardPayoutRequestSender = {type: string}; export type CardPayoutRequest = {source: {type: 'currency_account', id: string}, destination: CardPayoutRequestDestination, amount?: number | undefined, currency: string, instruction: {funds_transfer_type: string, purpose?: ('family_support' | 'expatriation' | 'travel_and_tourism' | 'education' | 'medical_treatment' | 'emergency_need' | 'leisure' | 'savings' | 'gifts' | 'donations' | 'financial_services' | 'it_services' | 'investment' | 'insurance' | 'loan_payment' | 'pension' | 'royalties' | 'other' | 'income') | undefined}, items?: CardPayoutItems | undefined, processing_channel_id: string, sender?: CardPayoutRequestSender | undefined, reference?: string | undefined, previous_payment_id?: string | undefined, metadata?: Record | undefined, segment?: Segment | undefined, processing?: ({affiliate_id?: string | undefined, affiliate_url?: string | undefined, processing_speed?: 'fast' | undefined, purchase_country?: string | undefined}) | undefined}; export type BankPayoutRequestSource = {type: string, id: string} | {type: string, id: string}; export type PaymentRequestDestination = {type: string, id: string} | {type: string, country: string, iban?: string | undefined, account_number?: string | undefined, bank_code?: string | undefined, branch_code?: string | undefined, bban?: string | undefined, swift_bic?: string | undefined, account_type: 'savings' | 'current' | 'cash', account_holder?: AccountHolder | undefined}; export type PayoutBillingDescriptor = {reference: string}; export type PayoutSender = {type: 'instrument' | 'individual' | 'corporate', reference: string} | {type: 'instrument' | 'individual' | 'corporate', reference: string, first_name: string, last_name: string, dob?: string | undefined, address: Address, identification?: ({type?: ('passport' | 'driving_licence' | 'national_id') | undefined, number?: string | undefined, issuing_country?: string | undefined}) | undefined} | {type: 'instrument' | 'individual' | 'corporate', reference: string, company_name: string, address: Address}; export type PaymentInstruction = {scheme?: ('local' | 'instant') | undefined, remittance?: ({reference?: string | undefined}) | undefined}; export type BankPayoutRequest = {source: BankPayoutRequestSource, destination: PaymentRequestDestination, amount: number, currency: string, reference?: string | undefined, billing_descriptor: PayoutBillingDescriptor, sender?: PayoutSender | undefined, instruction?: PaymentInstruction | undefined, processing_channel_id: string, segment?: Segment | undefined}; export type UnreferencedRefundRequestAccountHolder = {type: string, first_name?: string | undefined, middle_name?: string | undefined, last_name?: string | undefined, billing_address?: ({address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined}) | undefined, phone?: {country_code: string, number: string} | undefined, identification?: ({type: 'passport' | 'driving_license' | 'national_id' | 'company_registration' | 'tax_id', number: string, issuing_country?: string | undefined, date_of_expiry?: string | undefined}) | undefined, email?: string | undefined, date_of_birth?: string | undefined, country_of_birth?: string | undefined} | {type: string, company_name: string, billing_address?: ({address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined}) | undefined, phone?: {country_code: string, number: string} | undefined, identification?: ({type: 'passport' | 'driving_license' | 'national_id' | 'company_registration' | 'tax_id', number: string, issuing_country?: string | undefined, date_of_expiry?: string | undefined}) | undefined, email?: string | undefined} | {type: string, company_name: string, billing_address?: ({address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined}) | undefined, phone?: {country_code: string, number: string} | undefined, identification?: ({type: 'passport' | 'driving_license' | 'national_id' | 'company_registration' | 'tax_id', number: string, issuing_country?: string | undefined, date_of_expiry?: string | undefined}) | undefined, email?: string | undefined}; export type UnreferencedRefundRequestNameRequiredAccountHolder = {type: string, first_name: string, middle_name?: string | undefined, last_name: string, billing_address?: ({address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined}) | undefined, phone?: {country_code: string, number: string} | undefined, identification?: ({type: 'passport' | 'driving_license' | 'national_id' | 'company_registration' | 'tax_id', number: string, issuing_country?: string | undefined, date_of_expiry?: string | undefined}) | undefined, email?: string | undefined, date_of_birth?: string | undefined, country_of_birth?: string | undefined} | {type: string, company_name: string, billing_address?: ({address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined}) | undefined, phone?: {country_code: string, number: string} | undefined, identification?: ({type: 'passport' | 'driving_license' | 'national_id' | 'company_registration' | 'tax_id', number: string, issuing_country?: string | undefined, date_of_expiry?: string | undefined}) | undefined, email?: string | undefined} | {type: string, company_name: string, billing_address?: ({address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined}) | undefined, phone?: {country_code: string, number: string} | undefined, identification?: ({type: 'passport' | 'driving_license' | 'national_id' | 'company_registration' | 'tax_id', number: string, issuing_country?: string | undefined, date_of_expiry?: string | undefined}) | undefined, email?: string | undefined}; export type UnreferencedRefundRequestDestination = {type: string, token: string, account_holder?: UnreferencedRefundRequestAccountHolder | undefined} | {type: string, id: string, account_holder?: UnreferencedRefundRequestAccountHolder | undefined} | {type: string, number: string, expiry_month: number, expiry_year: number, account_holder: UnreferencedRefundRequestNameRequiredAccountHolder} | {type: string, token: string, expiry_month: number, expiry_year: number, token_type: 'vts' | 'mdes' | 'applepay' | 'googlepay', cryptogram?: string | undefined, eci?: string | undefined, account_holder: UnreferencedRefundRequestNameRequiredAccountHolder}; export type UnreferencedRefundRequest = {source: {type: 'currency_account', id: string}, destination: UnreferencedRefundRequestDestination, instruction?: ({funds_transfer_type?: string | undefined, purpose?: ('family_support' | 'expatriation' | 'travel_and_tourism' | 'education' | 'medical_treatment' | 'emergency_need' | 'leisure' | 'savings' | 'gifts' | 'donations' | 'financial_services' | 'it_services' | 'investment' | 'insurance' | 'loan_payment' | 'pension' | 'royalties' | 'other' | 'income') | undefined}) | undefined, amount: number, currency: string, payment_type: 'UnreferencedRefund', processing_channel_id: string, reference?: string | undefined, metadata?: Record | undefined, previous_payment_id?: string | undefined, segment?: Segment | undefined, processing?: ({processing_speed?: 'fast' | undefined}) | undefined}; export type CreateApiPaymentsArgs = {'Cko-Idempotency-Key'?: string | undefined, 'Cko-Encryption-Key-Id'?: string | undefined, 'Cko-Encrypted-Properties'?: string | undefined, body: PaymentRequest | PaymentContextPaymentRequest | CardPayoutRequest | BankPayoutRequest | UnreferencedRefundRequest}; export type CreateApiPaymentsOptions = {baseUrl: string, OAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentId = z.string().min(30).max(30); export const actionId = z.string().min(30).max(30); export const schema3dsEnrollmentData = z.object({downgraded: z.boolean().optional(), enrolled: z.string().optional(), upgrade_reason: z.string().optional()}); export const address = z.object({address_line1: z.string().max(200).optional(), address_line2: z.string().max(200).optional(), city: z.string().max(50).optional(), state: z.string().max(3).optional(), zip: z.string().max(50).optional(), country: z.string().min(2).max(2).optional()}); export const phoneNumber = z.object({country_code: z.string().min(1).max(7).optional(), number: z.string().max(25).optional()}); export const paymentResponseSource = z.discriminatedUnion("type", [z.object({type: z.literal("card"), id: z.string().optional(), billing_address: address.optional(), phone: phoneNumber.optional(), expiry_month: z.number().int().gte(1), expiry_year: z.number().int(), name: z.string().optional(), scheme: z.string().optional(), scheme_local: z.string().optional(), local_schemes: z.array(z.string()).optional(), last4: z.string(), fingerprint: z.string(), bin: z.string().max(8), card_type: z.enum(["CREDIT", "DEBIT", "PREPAID", "CHARGE", "DEFERRED DEBIT"]).optional(), card_category: z.enum(["CONSUMER", "COMMERCIAL"]).optional(), card_wallet_type: z.enum(["applepay", "googlepay"]).optional(), issuer: z.string().optional(), issuer_country: z.string().min(2).max(2).optional(), product_id: z.string().optional(), product_type: z.string().optional(), avs_check: z.string().optional(), cvv_check: z.string().optional(), payment_account_reference: z.string().optional(), encrypted_card_number: z.string().optional(), account_update_status: z.enum(["card_updated", "card_expiry_updated", "card_closed", "contact_cardholder"]).optional(), account_update_failure_code: z.string().optional(), account_holder: z.object({}).optional()}), z.object({id: z.string(), type: z.enum(["card", "ach", "alipay_cn", "bank_account", "sepa", "bacs"])})]); export const customerSummary = z.object({registration_date: z.string().optional(), first_transaction_date: z.string().optional(), last_payment_date: z.string().optional(), total_order_count: z.number().int().optional(), last_payment_amount: z.number().optional(), is_premium_customer: z.boolean().optional(), is_returning_customer: z.boolean().optional(), lifetime_value: z.number().optional()}); export const customerResponse = z.object({id: z.string(), email: z.string().optional(), name: z.string().optional(), phone: phoneNumber.optional(), summary: customerSummary.optional()}); export const paymentResponseBalances = z.object({total_authorized: z.number().int().optional(), total_voided: z.number().int().optional(), available_to_void: z.number().int().optional(), total_captured: z.number().int().optional(), available_to_capture: z.number().int().optional(), total_refunded: z.number().int().optional(), available_to_refund: z.number().int().optional()}); export const serverTimestamp = z.string(); export const subscription = z.object({id: z.string().max(50).optional()}); export const aggregator = z.object({sub_merchant_id: z.string().optional(), aggregator_id_visa: z.string().optional(), aggregator_id_mc: z.string().optional()}); export const timestamp = z.string(); export const retryPostResponse = z.object({enabled: z.boolean(), max_attempts: z.number().int().gte(1).lte(15).optional(), ends_on: timestamp.optional(), next_attempt_on: timestamp.optional()}); export const link = z.object({href: z.string()}); export const paymentResponse = z.object({id: paymentId, action_id: actionId, amount: z.number().int(), amount_requested: z.number().int().optional(), currency: z.string().min(3).max(3), approved: z.boolean(), status: z.enum(["Authorized", "Pending", "Card Verified", "Declined", "Retry Scheduled"]), auth_code: z.string().optional(), response_code: z.string(), response_summary: z.string().optional(), expires_on: z.string().optional(), "3ds": schema3dsEnrollmentData.optional(), risk: z.object({flagged: z.boolean().optional(), score: z.number().gte(0).lte(100).optional()}).optional(), source: paymentResponseSource.optional(), customer: customerResponse.optional(), balances: paymentResponseBalances.optional(), processed_on: serverTimestamp, reference: z.string().optional(), subscription: subscription.optional(), processing: z.object({retrieval_reference_number: z.string().optional(), acquirer_transaction_id: z.string().optional(), recommendation_code: z.string().optional(), scheme: z.string().optional(), partner_merchant_advice_code: z.string().optional(), partner_response_code: z.string().optional(), partner_order_id: z.string().optional(), partner_payment_id: z.string().optional(), partner_status: z.string().optional(), partner_transaction_id: z.string().optional(), partner_error_codes: z.array(z.string()).optional(), partner_error_message: z.string().optional(), partner_authorization_code: z.string().optional(), partner_authorization_response_code: z.string().optional(), surcharge_amount: z.number().int().gte(0).optional(), pan_type_processed: z.enum(["fpan", "dpan"]).optional(), fallback_source_used: z.boolean().optional(), cko_network_token_available: z.boolean().optional(), purchase_country: z.string().max(2).optional(), foreign_retailer_amount: z.number().int().gte(0).optional(), scheme_merchant_id: z.string().optional(), reconciliation_id: z.string().optional(), aggregator: aggregator.optional(), scheme_transaction_link_id: z.string().optional()}).optional(), eci: z.string().optional(), scheme_id: z.string().optional(), retry: retryPostResponse.optional(), _links: z.object({self: link, actions: link, authorize: link.optional(), void: link.optional(), capture: link.optional(), refund: link.optional(), cancel: link.optional()})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Request a payment or payout * * POST /payments * * Also accepts auth: ApiSecretKey */ export const createApiPayments = async (args: CreateApiPaymentsArgs, options: CreateApiPaymentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Cko-Idempotency-Key'] != null) headers.set("Cko-Idempotency-Key", String(args['Cko-Idempotency-Key'])) if (args['Cko-Encryption-Key-Id'] != null) headers.set("Cko-Encryption-Key-Id", String(args['Cko-Encryption-Key-Id'])) if (args['Cko-Encrypted-Properties'] != null) headers.set("Cko-Encrypted-Properties", String(args['Cko-Encrypted-Properties'])) if (OAuth !== undefined) headers.set('authorization', `Bearer ${OAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/payments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paymentResponse, await res.json()) };