import {z} from 'zod' export type GetApiPaymentOpenOtcApiRechargeListArgs = {'X-GatePay-Certificate-ClientId': string, 'X-GatePay-Signature': string, 'X-GatePay-Timestamp': string, 'X-GatePay-Nonce': string, 'X-GatePay-On-Behalf-Of'?: string | undefined, status?: ('PENDING' | 'PROCESSING' | 'DONE' | 'CANCEL' | 'ERROR') | undefined, startTime: number, endTime: number, page?: number | undefined, count?: number | undefined}; export type GetApiPaymentOpenOtcApiRechargeListOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const otcCardInfo = z.object({id: z.number().int().optional(), uid: z.number().int().optional(), entity: z.string().optional(), bank_account_name: z.string().optional(), bank_name: z.string().optional(), bank_country: z.string().optional(), bank_address: z.string().optional(), bank_code: z.string().optional(), branch_code: z.string().optional(), iban: z.string().optional(), swift: z.string().optional(), remittance_line_number: z.string().optional(), agent_bank_name: z.string().optional(), agent_bank_swift: z.string().optional(), transferRemark: z.string().optional(), memo: z.string().optional(), is_default: z.boolean().optional(), bank_id: z.string().optional()}); export const otcQuoteFeeDetail = z.object({feeType: z.string().optional(), amount: z.string().optional()}); export const otcRechargeOrder = z.object({orderId: z.string().optional(), otcOrderId: z.string().optional(), currency: z.string().optional(), amount: z.string().optional(), fiatCurrency: z.string().optional(), fiatAmount: z.string().optional(), cfRate: z.string().optional(), bankId: z.string().optional(), bankNumber: z.string().optional(), paid: z.boolean().optional(), status: z.string().optional(), card_info: otcCardInfo.optional(), createTime: z.number().int().optional(), promoCode: z.string().optional(), transferRemark: z.string().optional(), paymentReceiptFileUrl: z.string().optional(), tradeFee: z.string().optional(), feeCurrency: z.string().optional(), feeDetail: z.array(otcQuoteFeeDetail).optional()}); export const otcRechargeListResponse = z.object({code: z.string().optional(), status: z.string().optional(), errorMessage: z.string().optional(), data: z.object({total: z.number().int().optional(), page: z.number().int().optional(), list: z.array(otcRechargeOrder).optional()}).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 }; /** * Query OTC Recharge Order List * * GET /payment/open/otc/api/recharge/list */ export const getApiPaymentOpenOtcApiRechargeList = async (args: GetApiPaymentOpenOtcApiRechargeListArgs, options?: GetApiPaymentOpenOtcApiRechargeListOptions) => { const {baseUrl = "https://openplatform.gateapi.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-GatePay-Certificate-ClientId'] != null) headers.set("X-GatePay-Certificate-ClientId", String(args['X-GatePay-Certificate-ClientId'])) if (args['X-GatePay-Signature'] != null) headers.set("X-GatePay-Signature", String(args['X-GatePay-Signature'])) if (args['X-GatePay-Timestamp'] != null) headers.set("X-GatePay-Timestamp", String(args['X-GatePay-Timestamp'])) if (args['X-GatePay-Nonce'] != null) headers.set("X-GatePay-Nonce", String(args['X-GatePay-Nonce'])) if (args['X-GatePay-On-Behalf-Of'] != null) headers.set("X-GatePay-On-Behalf-Of", String(args['X-GatePay-On-Behalf-Of'])) if (args.status != null) query.append("status", String(args.status)) if (args.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.page != null) query.append("page", String(args.page)) if (args.count != null) query.append("count", String(args.count)) const url = `${baseUrl.replace(/\/+$/, '')}/payment/open/otc/api/recharge/list${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(otcRechargeListResponse, await res.json()) };