import {z} from 'zod' export type EmbeddedSessionPaymentRequest = {session_id: string, payment_type?: string | undefined, order_id?: string | undefined, amount?: (number | string) | undefined, currency?: string | undefined, language?: string | undefined, mode?: string | undefined, success_url?: string | undefined, fail_url?: string | undefined, parent_origin?: string | undefined, is_3d?: boolean | undefined, installment_count?: (number | string) | undefined, card_number: string, card_holder_name: string, expire_month: string, expire_year: string, cvc: string, customer?: Record | undefined, customer_basket?: Array> | undefined, submerchant_external_id?: string | undefined, is_submerchant_payment?: boolean | undefined, campaign_name?: string | undefined, billing_tax_office?: string | undefined, billing_tax_number?: string | undefined}; export type CreateApiApiV1EmbeddedPaymentPayArgs = {'x-browser-token'?: string | undefined, body: EmbeddedSessionPaymentRequest}; export type CreateApiApiV1EmbeddedPaymentPayOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1EmbeddedPaymentPayResponse = 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 }; /** * Payment Pay * * POST /api/v1/embedded/payment/pay */ export const createApiApiV1EmbeddedPaymentPay = async (args: CreateApiApiV1EmbeddedPaymentPayArgs, options?: CreateApiApiV1EmbeddedPaymentPayOptions) => { const {baseUrl = "https://api.paylox.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-browser-token'] != null) headers.set("x-browser-token", String(args['x-browser-token'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/embedded/payment/pay${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(createApiApiV1EmbeddedPaymentPayResponse, await res.json()) };