import {z} from 'zod' export type GetApiApiV21CustomersExtExtCustomerIdOperationsArgs = {extCustomerId: string, currencyCode?: string | undefined, type?: ('PAYMENT_SENT' | 'PAYMENT_RECEIVED' | 'PAYOUT' | 'REFUND_SENT' | 'REFUND_RECEIVED' | 'RETURN' | 'ADMIN_TRANSFER_SENT' | 'ADMIN_TRANSFER_RECEIVED' | 'FEE_TRANSFER_SENT' | 'FEE_TRANSFER_RECEIVED') | undefined, eventDateFrom: unknown, eventDateTo: unknown, creationDateFrom?: unknown | undefined, creationDateTo?: unknown | undefined, limit?: string | undefined, offset?: string | undefined, sortBy?: ('eventDate' | 'creationDate' | 'type' | 'currencyCode') | undefined, 'Content-Type': string, Authorization: string}; export type GetApiApiV21CustomersExtExtCustomerIdOperationsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const pAYMENTRECEIVED = z.object({operations: z.array(z.object({type: z.enum(["PAYMENT_SENT", "PAYMENT_RECEIVED", "PAYOUT", "REFUND_SENT", "REFUND_RECEIVED", "RETURN", "ADMIN_TRANSFER_SENT", "ADMIN_TRANSFER_RECEIVED", "FEE_TRANSFER_SENT", "FEE_TRANSFER_RECEIVED", "CHARGEBACK", "ADMIN_CORRECTION"]).optional(), amount: z.string().optional(), currencyCode: z.string().optional(), description: z.string().optional(), status: z.string().optional(), creationDate: z.string().optional(), eventDate: z.string().optional(), details: z.object({orderId: z.string().optional(), extOrderId: z.string().optional(), feeAmount: z.string().optional(), counterparties: z.object({extCustomerId: z.string().optional(), name: z.string().optional(), email: z.string().optional(), products: z.array(z.object({name: z.string().optional(), unitPrice: z.string().optional(), quantity: z.string().optional()})).optional()}).optional()}).optional(), funds: z.array(z.object({})).optional()})).optional(), pageResponse: z.object({records: z.string().optional(), size: z.string().optional(), pageCount: z.string().optional()}).optional()}); export const rEFUNDSENT = z.object({operations: z.array(z.object({type: z.enum(["PAYMENT_SENT", "PAYMENT_RECEIVED", "PAYOUT", "REFUND_SENT", "REFUND_RECEIVED", "RETURN", "ADMIN_TRANSFER_SENT", "ADMIN_TRANSFER_RECEIVED", "FEE_TRANSFER_SENT", "FEE_TRANSFER_RECEIVED", "CHARGEBACK", "ADMIN_CORRECTION"]).optional(), amount: z.string().optional(), currencyCode: z.string().optional(), description: z.string().optional(), status: z.string().optional(), creationDate: z.string().optional(), eventDate: z.string().optional(), details: z.object({orderId: z.string().optional(), extOrderId: z.string().optional(), refundId: z.string().optional(), extRefundId: z.string().optional(), counterparties: z.object({extCustomerId: z.string().optional(), name: z.string().optional(), email: z.string().optional()}).optional(), funds: z.array(z.object({})).optional()}).optional()})).optional(), pageResponse: z.object({records: z.string().optional(), size: z.string().optional(), pageCount: z.string().optional()}).optional()}); export const pAYOUT = z.object({operations: z.array(z.object({type: z.enum(["PAYMENT_SENT", "PAYMENT_RECEIVED", "PAYOUT", "REFUND_SENT", "REFUND_RECEIVED", "RETURN", "ADMIN_TRANSFER_SENT", "ADMIN_TRANSFER_RECEIVED", "FEE_TRANSFER_SENT", "FEE_TRANSFER_RECEIVED", "CHARGEBACK", "ADMIN_CORRECTION"]).optional(), amount: z.string().optional(), currencyCode: z.string().optional(), description: z.string().optional(), status: z.string().optional(), creationDate: z.string().optional(), eventDate: z.string().optional(), details: z.object({payoutId: z.string().optional(), extPayoutId: z.string().optional(), accountNumber: z.string().optional(), funds: z.array(z.object({})).optional()}).optional()})).optional(), pageResponse: z.object({records: z.string().optional(), size: z.string().optional(), pageCount: z.string().optional()}).optional()}); export const rETURN = z.object({operations: z.array(z.object({type: z.enum(["PAYMENT_SENT", "PAYMENT_RECEIVED", "PAYOUT", "REFUND_SENT", "REFUND_RECEIVED", "RETURN", "ADMIN_TRANSFER_SENT", "ADMIN_TRANSFER_RECEIVED", "FEE_TRANSFER_SENT", "FEE_TRANSFER_RECEIVED", "CHARGEBACK", "ADMIN_CORRECTION"]).optional(), amount: z.string().optional(), currencyCode: z.string().optional(), description: z.string().optional(), status: z.string().optional(), creationDate: z.string().optional(), eventDate: z.string().optional(), details: z.object({payoutId: z.string().optional(), extPayoutId: z.string().optional(), funds: z.array(z.object({})).optional()}).optional()})).optional(), pageResponse: z.object({records: z.string().optional(), size: z.string().optional(), pageCount: z.string().optional()}).optional()}); export const cHARGEBACK = z.object({operations: z.array(z.object({type: z.enum(["PAYMENT_SENT", "PAYMENT_RECEIVED", "PAYOUT", "REFUND_SENT", "REFUND_RECEIVED", "RETURN", "ADMIN_TRANSFER_SENT", "ADMIN_TRANSFER_RECEIVED", "FEE_TRANSFER_SENT", "FEE_TRANSFER_RECEIVED", "CHARGEBACK", "ADMIN_CORRECTION"]).optional(), amount: z.string().optional(), currencyCode: z.string().optional(), description: z.string().optional(), status: z.string().optional(), creationDate: z.string().optional(), eventDate: z.string().optional(), details: z.object({correctionId: z.string().optional(), funds: z.array(z.object({})).optional()}).optional()})).optional(), pageResponse: z.object({records: z.string().optional(), size: z.string().optional(), pageCount: z.string().optional()}).optional()}); export const aDMINCORRECTION = z.object({operations: z.array(z.object({type: z.enum(["PAYMENT_SENT", "PAYMENT_RECEIVED", "PAYOUT", "REFUND_SENT", "REFUND_RECEIVED", "RETURN", "ADMIN_TRANSFER_SENT", "ADMIN_TRANSFER_RECEIVED", "FEE_TRANSFER_SENT", "FEE_TRANSFER_RECEIVED", "CHARGEBACK", "ADMIN_CORRECTION"]).optional(), amount: z.string().optional(), currencyCode: z.string().optional(), description: z.string().optional(), status: z.string().optional(), creationDate: z.string().optional(), eventDate: z.string().optional(), details: z.object({correctionId: z.string().optional(), funds: z.array(z.object({})).optional()}).optional()})).optional(), pageResponse: z.object({records: z.string().optional(), size: z.string().optional(), pageCount: z.string().optional()}).optional()}); export const getApiApiV21CustomersExtExtCustomerIdOperationsResponse = z.union([pAYMENTRECEIVED, rEFUNDSENT, pAYOUT, rETURN, cHARGEBACK, aDMINCORRECTION]); 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 }; /** * Retrieve Seller Operation History * * GET /api/v2_1/customers/ext/{extCustomerId}/operations */ export const getApiApiV21CustomersExtExtCustomerIdOperations = async (args: GetApiApiV21CustomersExtExtCustomerIdOperationsArgs, options?: GetApiApiV21CustomersExtExtCustomerIdOperationsOptions) => { const {baseUrl = "https://secure.payu.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.currencyCode != null) query.append("currencyCode", String(args.currencyCode)) if (args.type != null) query.append("type", String(args.type)) if (args.eventDateFrom != null) query.append("eventDateFrom", String(args.eventDateFrom)) if (args.eventDateTo != null) query.append("eventDateTo", String(args.eventDateTo)) if (args.creationDateFrom != null) query.append("creationDateFrom", String(args.creationDateFrom)) if (args.creationDateTo != null) query.append("creationDateTo", String(args.creationDateTo)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2_1/customers/ext/${encodeURIComponent(String(args.extCustomerId))}/operations${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(getApiApiV21CustomersExtExtCustomerIdOperationsResponse, await res.json()) };