import {z} from 'zod' export type AmountFilter = {start_amount?: (number | null) | undefined, end_amount?: (number | null) | undefined}; export type Currency = 'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLE' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STD' | 'STN' | 'SVC' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'UYU' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW' | 'ZWL'; export type RefundStatus = 'succeeded' | 'failed' | 'pending' | 'review'; export type RefundListRequest = {start_time: string, end_time?: (string | null) | undefined, payment_id?: (string | null) | undefined, refund_id?: (string | null) | undefined, profile_id?: (string | null) | undefined, limit?: (number | null) | undefined, offset?: (number | null) | undefined, amount_filter?: (AmountFilter | null) | undefined, connector?: (Array | null) | undefined, merchant_connector_id?: (Array | null) | undefined, currency?: (Array | null) | undefined, refund_status?: (Array | null) | undefined} | null; export type CreateApiRefundsListArgs = {body: RefundListRequest}; export type CreateApiRefundsListOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const refundStatus = z.enum(["succeeded", "failed", "pending", "review"]); export const stripeSplitRefundRequest = z.object({revert_platform_fee: z.boolean().nullable().optional(), revert_transfer: z.boolean().nullable().optional()}); export const adyenSplitType = z.enum(["BalanceAccount", "AcquiringFees", "PaymentFee", "AdyenFees", "AdyenCommission", "AdyenMarkup", "Interchange", "SchemeFee", "Commission", "TopUp", "Vat"]); export const adyenSplitItem = z.object({amount: z.number().int(), split_type: adyenSplitType, account: z.string().nullable().optional(), reference: z.string(), description: z.string().nullable().optional()}); export const adyenSplitData = z.object({store: z.string().nullable().optional(), split_items: z.array(adyenSplitItem)}); export const xenditSplitSubMerchantData = z.object({for_user_id: z.string()}); export const splitRefund = z.union([z.object({stripe_split_refund: stripeSplitRefundRequest}), z.object({adyen_split_refund: adyenSplitData}), z.object({xendit_split_refund: xenditSplitSubMerchantData})]); export const refundResponse = z.object({refund_id: z.string(), payment_id: z.string(), amount: z.number().int().gte(100), currency: z.string(), status: refundStatus, reason: z.string().nullable().optional(), metadata: z.object({}).nullable().optional(), error_message: z.string().nullable().optional(), error_code: z.string().nullable().optional(), unified_code: z.string().nullable().optional(), unified_message: z.string().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), connector: z.string(), profile_id: z.string().nullable().optional(), merchant_connector_id: z.string().nullable().optional(), split_refunds: splitRefund.nullable().optional(), issuer_error_code: z.string().nullable().optional(), issuer_error_message: z.string().nullable().optional(), raw_connector_response: z.string().nullable().optional(), connector_refund_id: z.string().nullable().optional()}); export const refundListResponse = z.object({count: z.number().int().gte(0), total_count: z.number().int(), data: z.array(refundResponse)}); 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 }; /** * Refunds - List * * POST /refunds/list */ export const createApiRefundsList = async (args: CreateApiRefundsListArgs, options: CreateApiRefundsListOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/refunds/list${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(refundListResponse, await res.json()) };