import {z} from 'zod' export type GetApiReportsReconciliationsReconciliationIdArgs = {reconciliation_id: string, filter?: string | undefined}; export type GetApiReportsReconciliationsReconciliationIdOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const reconciliation = z.object({transaction_id: z.string().optional(), payment_method: z.enum(["card", "apple_pay", "google_pay"]).optional(), order_id: z.string().min(2).max(50).optional(), custom1: z.string().max(50).optional(), custom2: z.string().max(50).optional(), custom_data: z.string().optional(), card_type: z.enum(["mastercard", "visa"]).optional(), acquirer_reference_number: z.string().optional(), date: z.string().min(10).max(10).optional(), type: z.enum(["arbitration_fee", "authorisation_fee", "chargeback_reversal_charge", "consolidated_auth_fee", "credit", "credit_fund_transfer", "debit", "decline_fee", "dispute", "dispute_2nd", "dispute_fee", "dispute_fee", "dispute_liability_as", "dispute_liability_as_charge", "dispute_liability_assign_accepted", "dispute_liability_assign_accepted_charge", "dispute_lost", "dispute_pre_arb", "dispute_pre_arb_charge", "dispute_response", "dispute_reversal", "fee_collect", "fraud", "fraud_fee", "manual_adjustment", "mc_assessment_fees", "mc_fines", "min_processing_fee", "misc_fee", "monthly_fee", "msc_fee", "n/a", "onus", "other_fees", "pci_fee", "pci_non_compliance_fee", "pre_arb", "pre_arb_fee", "pre-arbitration", "refund", "refund_fee", "refund_reversal", "refund_reversal_fee", "registration_fee", "rejection", "representment_charge", "representment_reversal", "retrieval_request_fee", "reversal", "rolling_reserve_held", "rolling_reserve_released", "sale", "setup_fee", "transfer_reversal", "verifi_rdr", "visa_3ds_fees", "visa_fines", "visa_repetitive_decline_fees", "visa_unsecure_cbk_fee", "void", "void_fee", "wire_fee"]).optional(), region: z.enum(["inter", "intra", "domestic"]).optional(), amount: z.number().optional(), fee: z.number().optional(), net_amount: z.number().optional()}); export const getApiReportsReconciliationsReconciliationIdResponse = z.object({data: z.array(reconciliation).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 }; /** * Retrieve a Reconciliation Report * * GET /reports/reconciliations/{reconciliation_id} */ export const getApiReportsReconciliationsReconciliationId = async (args: GetApiReportsReconciliationsReconciliationIdArgs, options?: GetApiReportsReconciliationsReconciliationIdOptions) => { const {baseUrl = "https://test-api.acquired.com/v1", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", String(args.filter)) if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/reports/reconciliations/${encodeURIComponent(String(args.reconciliation_id))}${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(getApiReportsReconciliationsReconciliationIdResponse, await res.json()) };