import {z} from 'zod' export type GetApiCustomersCustomerIdPaymentMethodsArgs = {customer_id: string}; export type GetApiCustomersCustomerIdPaymentMethodsOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCustomersCustomerIdPaymentMethodsResponse = z.object({payment_methods: z.array(z.object({idempotency_key: z.unknown(), name: z.string().optional(), description: z.string().optional(), icon: z.string().optional(), type: z.string().optional(), category: z.string().optional(), country: z.string().optional(), status: z.string().optional(), sub_status: z.unknown(), vaulted_token: z.string().optional(), callback_url: z.unknown(), action: z.unknown(), redirect_url: z.unknown(), created_at: z.string().optional(), updated_at: z.string().optional(), card_data: z.object({iin: z.string().optional(), lfd: z.string().optional(), expiration_month: z.number().int().optional(), expiration_year: z.number().int().optional(), number_length: z.number().int().optional(), security_code_length: z.number().int().optional(), brand: z.string().optional(), issuer: z.unknown(), issuer_name: z.string().optional(), issuer_code: z.string().optional(), category: z.unknown(), type: z.string().optional()}).optional(), last_successfully_used: z.boolean().optional(), last_successfully_used_at: z.string().optional()})).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 }; /** * Retrieve Enrolled Payment Methods * * GET /customers/{customer_id}/payment-methods */ export const getApiCustomersCustomerIdPaymentMethods = async (args: GetApiCustomersCustomerIdPaymentMethodsArgs, options?: GetApiCustomersCustomerIdPaymentMethodsOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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/${encodeURIComponent(String(args.customer_id))}/payment-methods${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiCustomersCustomerIdPaymentMethodsResponse, await res.json()) };