import {z} from 'zod' export type GetApiPaymentMethodsPaymentMethodIdArgs = {payment_method_id: string}; export type GetApiPaymentMethodsPaymentMethodIdOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPaymentMethodsPaymentMethodIdResponse = z.union([z.object({id: z.string().optional(), idempotency_key: z.unknown(), 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(), verify: z.object({vault_on_success: z.boolean().optional(), payment: z.unknown()}).optional(), preferred: z.unknown()}), z.object({id: z.string().optional(), idempotency_key: z.unknown(), 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(), token: z.string().optional(), provider_status: z.unknown()}).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.string().optional(), issuer_code: z.unknown(), category: z.string().optional(), type: z.string().optional(), fingerprint: z.string().optional()}).optional(), verify: z.object({vault_on_success: z.boolean().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 }; /** * Retrieve Payment Method By ID * * GET /payment-methods/{payment_method_id} */ export const getApiPaymentMethodsPaymentMethodId = async (args: GetApiPaymentMethodsPaymentMethodIdArgs, options?: GetApiPaymentMethodsPaymentMethodIdOptions) => { 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(/\/+$/, '')}/payment-methods/${encodeURIComponent(String(args.payment_method_id))}${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(getApiPaymentMethodsPaymentMethodIdResponse, await res.json()) };