import {z} from 'zod' export type CreateApiCustomersSessionsCustomerSessionPaymentMethodsArgs = {customer_session: string, body: {account_id: string, payment_method_type: 'CARD' | 'MERCADO_PAGO_WALLET' | 'NEQUI' | 'BANCOLOMBIA_TOKENBOX' | 'NU_PAY_ENROLLMENT', country: 'AR' | 'BO' | 'BR' | 'CL' | 'CO' | 'CR' | 'EC' | 'SV' | 'GT' | 'HN' | 'MX' | 'NI' | 'PA' | 'PY' | 'PE' | 'US' | 'UY', account_updater?: boolean | undefined, verify?: ({vault_on_success: boolean, currency?: string | undefined}) | undefined}}; export type CreateApiCustomersSessionsCustomerSessionPaymentMethodsOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiCustomersSessionsCustomerSessionPaymentMethodsResponse = z.union([z.object({id: z.string().optional(), account_id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), type: z.string().optional(), category: z.string().optional(), country: z.string().optional(), status: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), enrollment: z.object({session: z.string().optional(), sdk_required_action: z.boolean().optional()}).optional(), provider: z.object({id: z.string().optional(), type: z.string().optional(), provider_status: z.unknown()}).optional(), customer_payer: z.object({first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), gender: z.string().optional(), date_of_birth: z.string().optional(), document: z.object({document_number: z.string().optional(), document_type: z.string().optional()}).optional(), phone: z.object({number: z.string().optional(), country_code: z.string().optional()}).optional(), billing_address: z.object({address_line_1: z.string().optional(), address_line_2: z.string().optional(), country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), zip_code: z.string().optional()}).optional()}).optional(), verify: z.object({vault_on_success: z.boolean().optional(), payment: z.unknown()}).optional(), preferred: z.unknown()}), z.object({id: z.string().optional(), account_id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), type: z.string().optional(), category: z.string().optional(), country: z.string().optional(), status: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), enrollment: z.object({session: z.string().optional(), sdk_required_action: z.boolean().optional()}).optional(), provider: z.object({id: z.string().optional(), type: z.string().optional(), provider_status: z.unknown()}).optional(), customer_payer: z.object({first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), gender: z.string().optional(), date_of_birth: z.string().optional(), document: z.object({document_number: z.string().optional(), document_type: z.string().optional()}).optional(), phone: z.object({number: z.string().optional(), country_code: z.string().optional()}).optional(), billing_address: z.object({address_line_1: z.string().optional(), address_line_2: z.string().optional(), country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), zip_code: z.string().optional()}).optional()}).optional(), verify: z.object({vault_on_success: z.boolean().optional(), currency: z.string().optional(), payment: z.unknown()}).optional(), preferred: z.unknown()})]); 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 }; /** * Enroll Payment Method * * POST /customers/sessions/{customer_session}/payment-methods */ export const createApiCustomersSessionsCustomerSessionPaymentMethods = async (args: CreateApiCustomersSessionsCustomerSessionPaymentMethodsArgs, options?: CreateApiCustomersSessionsCustomerSessionPaymentMethodsOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (publicApiKey !== undefined) headers.set("PUBLIC-API-KEY", publicApiKey) if (privateSecretKey !== undefined) headers.set("PRIVATE-SECRET-KEY", privateSecretKey) const url = `${baseUrl.replace(/\/+$/, '')}/customers/sessions/${encodeURIComponent(String(args.customer_session))}/payment-methods${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(createApiCustomersSessionsCustomerSessionPaymentMethodsResponse, await res.json()) };