import {z} from 'zod' export type Address = {line_1?: string | undefined, line_2?: string | undefined, city?: string | undefined, state?: string | undefined, postcode?: string | undefined, country_code?: ('al' | 'al' | 'dz' | 'as' | 'ad' | 'ao' | 'ai' | 'aq' | 'ag' | 'ar' | 'am' | 'aw' | 'au' | 'at' | 'az' | 'bs' | 'bh' | 'bd' | 'bb' | 'by' | 'be' | 'bz' | 'bj' | 'bm' | 'bt' | 'bo' | 'ba' | 'bw' | 'br' | 'io' | 'bn' | 'bg' | 'bf' | 'bi' | 'cv' | 'kh' | 'cm' | 'ca' | 'ky' | 'cf' | 'td' | 'cl' | 'cn' | 'co' | 'km' | 'cg' | 'cd' | 'cr' | 'hr' | 'cu' | 'cy' | 'cz' | 'dk' | 'dj' | 'dm' | 'do' | 'ec' | 'eg' | 'sv' | 'gq' | 'er' | 'ee' | 'sz' | 'et' | 'fk' | 'fo' | 'fj' | 'fi' | 'fr' | 'gf' | 'pf' | 'ga' | 'gm' | 'ge' | 'de' | 'gh' | 'gi' | 'gr' | 'gl' | 'gd' | 'gu' | 'gt' | 'gg' | 'gn' | 'gw' | 'gy' | 'ht' | 'hn' | 'hk' | 'hu' | 'is' | 'in' | 'id' | 'ir' | 'iq' | 'ie' | 'im' | 'il' | 'it' | 'jm' | 'jp' | 'je' | 'jo' | 'kz' | 'ke' | 'ki' | 'kp' | 'kr' | 'kw' | 'kg' | 'la' | 'lv' | 'lb' | 'ls' | 'lr' | 'ly' | 'li' | 'lt' | 'lu' | 'mo' | 'mk' | 'mg' | 'mw' | 'my' | 'mv' | 'ml' | 'mt' | 'mh' | 'mq' | 'mr' | 'mu' | 'yt' | 'mx' | 'fm' | 'md' | 'mc' | 'mn' | 'me' | 'ms' | 'ma' | 'mz' | 'mm' | 'na' | 'nr' | 'np' | 'nl' | 'nc' | 'nz' | 'ni' | 'ne' | 'ng' | 'nu' | 'nf' | 'mp' | 'no' | 'om' | 'pk' | 'pw' | 'ps' | 'pa' | 'pg' | 'py' | 'pe' | 'ph' | 'pl' | 'pt' | 'pr' | 'qa' | 'ro' | 'ru' | 'rw' | 're' | 'bl' | 'sh' | 'kn' | 'lc' | 'mf' | 'pm' | 'vc' | 'ws' | 'sm' | 'st' | 'sa' | 'sn' | 'rs' | 'sc' | 'sl' | 'sg' | 'sx' | 'sk' | 'si' | 'sb' | 'so' | 'za' | 'gs' | 'ss' | 'es' | 'lk' | 'sd' | 'sr' | 'se' | 'ch' | 'sx' | 'sy' | 'tw' | 'tj' | 'tz' | 'th' | 'tg' | 'tk' | 'to' | 'tt' | 'tn' | 'tr' | 'tm' | 'tc' | 'tv' | 'ug' | 'ua' | 'ae' | 'gb' | 'us' | 'uy' | 'uz' | 'vu' | 've' | 'vn' | 'vg' | 'vi' | 'wf' | 'eh' | 'ye' | 'zm' | 'zw') | undefined}; export type Phone = {country_code?: string | undefined, number?: string | undefined}; export type CustomerRequest = {customer_id?: string | undefined, reference?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, dob?: string | undefined, custom_data?: string | undefined, billing?: ({address?: Address | undefined, email?: string | undefined, phone?: Phone | undefined}) | undefined, shipping?: ({address_match?: boolean | undefined, first_name?: string | undefined, last_name?: string | undefined, address?: Address | undefined, email?: string | undefined, phone?: Phone | undefined}) | undefined}; export type ThreeDSecure = {is_active?: boolean | undefined, challenge_preference?: ('challenge_mandated' | 'challenge_preferred' | 'no_challenge_requested' | 'no_preference') | undefined, challenge_window_size?: ('full_screen' | 'windowed_250x400' | 'windowed_390x400' | 'windowed_500x600' | 'windowed_600x400') | undefined, contact_url?: string | undefined, redirect_url?: string | undefined, webhook_url?: string | undefined}; export type UpdateApiPaymentSessionsSessionIdArgs = {session_id: string, body: {transaction?: ({order_id: string, amount: number, currency: 'AED' | 'AUD' | 'CAD' | 'CHF' | 'CNY' | 'DKK' | 'EUR' | 'GBP' | 'HKD' | 'JPY' | 'MXN' | 'SEK' | 'USD' | 'ZAR', moto?: boolean | undefined, capture?: boolean | undefined, custom_data?: string | undefined, custom1?: string | undefined, custom2?: string | undefined}) | undefined, customer?: CustomerRequest | undefined, tds?: ThreeDSecure | undefined, webhook_url?: string | undefined, payment_methods?: (Array<'card' | 'apple_pay' | 'google_pay'>) | undefined}}; export type UpdateApiPaymentSessionsSessionIdOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiPaymentSessionsSessionIdResponse = z.object({status: z.literal("success").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 }; /** * Update a session_id * * PUT /payment-sessions/{session_id} */ export const updateApiPaymentSessionsSessionId = async (args: UpdateApiPaymentSessionsSessionIdArgs, options?: UpdateApiPaymentSessionsSessionIdOptions) => { const {baseUrl = "https://test-api.acquired.com/v1", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/payment-sessions/${encodeURIComponent(String(args.session_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiPaymentSessionsSessionIdResponse, await res.json()) };