import {z} from 'zod' export type CreateApiSmartSupportExternalPaymentsRecoverArgs = {body: {settings: {contact_details: {channel: 'PHONE_CALL' | 'WHATSAPP_MESSAGE', initial_template_message?: ({id?: string | undefined, variables?: Record | undefined}) | undefined, pdf_template?: ({id?: string | undefined, variables?: Record | undefined}) | undefined, payment_methods?: {available: Array} | undefined}}, additional_information?: ({seller_details?: ({name?: string | undefined, fallback_instructions?: string | undefined, redirection_url?: string | undefined}) | undefined, payment?: ({account_id?: string | undefined, id?: string | undefined, merchant_order_id?: string | undefined, country?: string | undefined, description?: string | undefined, created_at?: string | undefined, declined_reason?: string | undefined, payment_method?: ({type?: string | undefined, detail?: ({card_data?: ({expiration_month?: number | undefined, expiration_year?: number | undefined, iin?: string | undefined, lfd?: string | undefined, issuer?: string | undefined, type?: ('CREDIT' | 'DEBIT' | 'PREPAID') | undefined}) | undefined}) | undefined}) | undefined, amount?: ({value?: number | undefined, currency?: string | undefined}) | undefined, customer_payer?: ({first_name?: string | undefined, last_name?: string | undefined, phone?: ({country_code?: string | undefined, number?: string | undefined}) | undefined}) | undefined}) | undefined}) | undefined}}; export type CreateApiSmartSupportExternalPaymentsRecoverOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiSmartSupportExternalPaymentsRecoverResponse = z.object({id: z.string().optional(), message: z.string().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 }; /** * Copy of Declined Payment Calls * * POST /smart-support/external/payments/recover */ export const createApiSmartSupportExternalPaymentsRecover = async (args: CreateApiSmartSupportExternalPaymentsRecoverArgs, options?: CreateApiSmartSupportExternalPaymentsRecoverOptions) => { 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(/\/+$/, '')}/smart-support/external/payments/recover${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(createApiSmartSupportExternalPaymentsRecoverResponse, await res.json()) };