import {z} from 'zod' export type GetApiStatementsPaymentsArgs = {ref_ids?: Array | undefined, payment_ids?: Array | undefined, customer_id?: string | undefined, product?: 'USDG_REWARDS' | undefined, payment_status?: ('PAYMENT_STATUS_PENDING' | 'PAYMENT_STATUS_COMPLETED' | 'PAYMENT_STATUS_FAILED') | undefined, limit?: number | undefined, order?: ('DESC' | 'ASC') | undefined, page_cursor?: string | undefined}; export type GetApiStatementsPaymentsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const product = z.literal("USDG_REWARDS"); export const paymentType = z.literal("PAYMENT_TYPE_CRYPTO_WITHDRAWAL"); export const paymentStatus = z.enum(["PAYMENT_STATUS_PENDING", "PAYMENT_STATUS_COMPLETED", "PAYMENT_STATUS_FAILED"]); export const payment = z.object({id: z.string().optional(), customer_id: z.string().optional(), profile_id: z.string().optional(), account_id: z.string().optional(), ref_id: z.string().optional(), product: product.optional(), payment_type: paymentType.optional(), payment_source: z.string().optional(), payment_destination: z.string().optional(), payment_asset: z.string().optional(), payment_amount: z.string().optional(), payment_status: paymentStatus.optional(), payment_tx_id: z.string().optional(), description: z.string().optional(), metadata: z.string().optional(), created_at: z.string().optional(), processed_at: z.string().optional()}); export const listPaymentsResponse = z.object({payments: z.array(payment).optional(), next_page_cursor: 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 }; /** * List Payments * * GET /statements/payments */ export const getApiStatementsPayments = async (args: GetApiStatementsPaymentsArgs, options?: GetApiStatementsPaymentsOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.ref_ids ?? []) query.append("ref_ids", String(item)) for (const item of args.payment_ids ?? []) query.append("payment_ids", String(item)) if (args.customer_id != null) query.append("customer_id", String(args.customer_id)) if (args.product != null) query.append("product", String(args.product)) if (args.payment_status != null) query.append("payment_status", String(args.payment_status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (args.page_cursor != null) query.append("page_cursor", String(args.page_cursor)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/statements/payments${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(listPaymentsResponse, await res.json()) };