import {z} from 'zod' export type SearchRequest = {search?: ({id?: {eq: string} | undefined, amount?: ({gt?: number | undefined, lt?: number | undefined, gte?: number | undefined, lte?: number | undefined, between?: Array | undefined}) | undefined, status?: ({eq?: ('completed' | 'failed' | 'cancelled' | 'pending' | 'processing' | 'error' | 'refunding' | 'refunding_stuck' | 'refunding_failed' | 'partially_refunded' | 'fully_refunded') | undefined, in?: (Array<'completed' | 'failed' | 'cancelled' | 'pending' | 'processing' | 'error' | 'refunding' | 'refunding_stuck' | 'refunding_failed' | 'partially_refunded' | 'fully_refunded'>) | undefined}) | undefined, transaction_type?: ({eq?: ('payment' | 'refund') | undefined, in?: (Array<'payment' | 'refund'>) | undefined}) | undefined, payment_request_id?: {eq: string} | undefined, payment_token?: {eq: string} | undefined, customer_email?: {contains: string} | undefined, created_at?: ({eq?: string | undefined, gte?: string | undefined, lte?: string | undefined, between?: Array | undefined}) | undefined, currency?: {eq: string} | undefined, order_id?: {contains: string} | undefined, payout_batch_id?: {eq: string} | undefined}) | undefined, pagination?: ({page?: number | undefined, limit?: number | undefined}) | undefined, sort?: (Array<{field: 'created_at' | 'updated_at' | 'amount' | 'converted_amount' | 'status' | 'transaction_type', direction: 'asc' | 'desc'}>) | undefined, include_all_statuses?: boolean | undefined}; export type CreateApiApiV1MerchantsIdTransactionsArgs = {id: string, body: SearchRequest}; export type CreateApiApiV1MerchantsIdTransactionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionSearchResponse = z.object({success: z.boolean(), data: z.array(z.object({id: z.string(), transaction_number: z.string(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), transaction_type: z.enum(["payment", "refund", "reversal"]), status: z.enum(["pending", "received", "fee_paid", "converted", "completed", "failed", "cancelled", "error", "unknown"]), cross_border: z.boolean(), deposit_country: z.string(), payout_country: z.string(), payout_currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}).nullable(), exchange_rate: z.number().nullable(), converted_amount: z.number().nullable(), payout_at: z.string().nullable(), payout_batch_id: z.string().nullable(), test: z.boolean().nullable(), created_at: z.string(), updated_at: z.string(), settled_at: z.string().nullable(), platform: z.enum(["shopify", "woocommerce", "embedded", "payment_link"]).nullable(), problems: z.array(z.object({code: z.string(), message: z.string(), label: z.string(), is_resolvable: z.boolean()})).optional(), target_status: z.union([z.literal("pending"), z.literal("received"), z.literal("fee_paid"), z.literal("converted"), z.literal("completed"), z.literal("failed"), z.literal("cancelled"), z.literal("error"), z.literal("unknown")]).optional(), refund_status: z.union([z.literal("refunding"), z.literal("refunding_stuck"), z.literal("refunding_failed"), z.literal("partially_refunded"), z.literal("fully_refunded")]).nullable(), can_refund: z.boolean(), payment_request: z.object({id: z.string(), order_id: z.string(), customer: z.object({name: z.string(), email: z.string()}).nullable(), payment_token: z.string()}).nullable(), fees: z.object({total: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), items: z.array(z.object({id: z.string(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), fee_type: z.string(), rate_type: z.string(), rate_value: z.string(), rate_unit: z.string(), rate_base: z.string(), notes: z.string().nullable(), settlement_status: z.string(), invoice_id: z.string().nullable(), settled_at: z.string().nullable(), created_at: z.string(), updated_at: z.string()}))}).optional(), refunds: z.array(z.object({id: z.string(), transaction_number: z.string(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), transaction_type: z.enum(["payment", "refund", "reversal"]), status: z.enum(["pending", "received", "fee_paid", "converted", "completed", "failed", "cancelled", "error", "unknown"]), cross_border: z.boolean(), deposit_country: z.string(), payout_country: z.string(), payout_currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}).nullable(), exchange_rate: z.number().nullable(), converted_amount: z.number().nullable(), payout_at: z.string().nullable(), payout_batch_id: z.string().nullable(), test: z.boolean().nullable(), created_at: z.string(), updated_at: z.string(), settled_at: z.string().nullable(), platform: z.enum(["shopify", "woocommerce", "embedded", "payment_link"]).nullable(), problems: z.array(z.object({code: z.string(), message: z.string(), label: z.string(), is_resolvable: z.boolean()})).optional(), target_status: z.union([z.literal("pending"), z.literal("received"), z.literal("fee_paid"), z.literal("converted"), z.literal("completed"), z.literal("failed"), z.literal("cancelled"), z.literal("error"), z.literal("unknown")]).optional(), refund_status: z.union([z.literal("refunding"), z.literal("refunding_stuck"), z.literal("refunding_failed"), z.literal("partially_refunded"), z.literal("fully_refunded")]).nullable(), can_refund: z.boolean(), payment_request: z.object({id: z.string(), order_id: z.string(), customer: z.object({name: z.string(), email: z.string()}).nullable(), payment_token: z.string()}).nullable(), fees: z.object({total: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), items: z.array(z.object({id: z.string(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), fee_type: z.string(), rate_type: z.string(), rate_value: z.string(), rate_unit: z.string(), rate_base: z.string(), notes: z.string().nullable(), settlement_status: z.string(), invoice_id: z.string().nullable(), settled_at: z.string().nullable(), created_at: z.string(), updated_at: z.string()}))}).optional()})).optional(), reversals: z.array(z.object({id: z.string(), transaction_number: z.string(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), transaction_type: z.enum(["payment", "refund", "reversal"]), status: z.enum(["pending", "received", "fee_paid", "converted", "completed", "failed", "cancelled", "error", "unknown"]), cross_border: z.boolean(), deposit_country: z.string(), payout_country: z.string(), payout_currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}).nullable(), exchange_rate: z.number().nullable(), converted_amount: z.number().nullable(), payout_at: z.string().nullable(), payout_batch_id: z.string().nullable(), test: z.boolean().nullable(), created_at: z.string(), updated_at: z.string(), settled_at: z.string().nullable(), platform: z.enum(["shopify", "woocommerce", "embedded", "payment_link"]).nullable(), problems: z.array(z.object({code: z.string(), message: z.string(), label: z.string(), is_resolvable: z.boolean()})).optional(), target_status: z.union([z.literal("pending"), z.literal("received"), z.literal("fee_paid"), z.literal("converted"), z.literal("completed"), z.literal("failed"), z.literal("cancelled"), z.literal("error"), z.literal("unknown")]).optional(), refund_status: z.union([z.literal("refunding"), z.literal("refunding_stuck"), z.literal("refunding_failed"), z.literal("partially_refunded"), z.literal("fully_refunded")]).nullable(), can_refund: z.boolean(), payment_request: z.object({id: z.string(), order_id: z.string(), customer: z.object({name: z.string(), email: z.string()}).nullable(), payment_token: z.string()}).nullable(), fees: z.object({total: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), items: z.array(z.object({id: z.string(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), fee_type: z.string(), rate_type: z.string(), rate_value: z.string(), rate_unit: z.string(), rate_base: z.string(), notes: z.string().nullable(), settlement_status: z.string(), invoice_id: z.string().nullable(), settled_at: z.string().nullable(), created_at: z.string(), updated_at: z.string()}))}).optional()})).optional()})), pagination: z.object({total: z.number(), page: z.number(), limit: z.number(), totalPages: z.number(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean()}), search_metadata: z.object({filters_applied: z.array(z.string()), sort_applied: z.array(z.object({field: z.enum(["created_at", "updated_at", "amount", "converted_amount", "status", "transaction_type"]), direction: z.enum(["asc", "desc"])})), query_execution_time: z.number(), total_records_scanned: z.number()}).optional(), totals: z.array(z.object({currency: z.string().min(3).max(3), total_amount: z.number()}))}); 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 }; /** * Search transactions for a merchant with filtering and sorting * * POST /api/v1/merchants/{id}/transactions */ export const createApiApiV1MerchantsIdTransactions = async (args: CreateApiApiV1MerchantsIdTransactionsArgs, options?: CreateApiApiV1MerchantsIdTransactionsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/merchants/${encodeURIComponent(String(args.id))}/transactions${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(transactionSearchResponse, await res.json()) };