import {z} from 'zod' export type GetApiApiV1TransactionsIdArgs = {id: string}; export type GetApiApiV1TransactionsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionResponse = z.object({success: z.boolean(), data: 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"]), status_message: z.string().nullable(), 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(), payment_request: z.object({id: z.string(), order_id: z.string(), merchant: z.object({id: z.string(), partner: z.object({id: z.string()}).nullable()}).nullable(), customer: z.object({id: z.string(), name: z.string(), email: z.string()}).nullable(), payment_token: z.string(), authorization_agreement_record_id: z.string().nullable()}).nullable(), destination_account: z.string().nullable(), destination_account_type: z.string().nullable(), remittance_information: z.string().nullable(), payment_scheme: 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(), related_transaction: z.object({id: z.string(), transaction_number: z.string()}).nullable(), provider_status_events: z.array(z.object({id: z.string(), source: z.enum(["webhook", "polling", "finalization", "admin"]), provider_name: z.string(), provider_status: z.string(), processing_status: z.enum(["received", "processed", "ignored", "failed", "conflict", "stale"]), provider_updated_at: z.string().nullable(), created_at: z.string(), observed_at: z.string(), signature_valid: z.boolean(), event_id: z.string().optional(), event_type: z.string().optional(), processing_error: z.string().optional(), provider_request_id: z.string().optional()})), merchant_webhook_deliveries: z.array(z.object({id: z.string(), payment_provider_status_id: z.string().nullable(), webhook_url: z.string(), platform: z.enum(["embedded", "shopify", "woocommerce"]), event_type: z.string(), status: z.enum(["delivered", "failed"]), response_status_code: z.number().nullable(), error_message: z.string().optional(), duration_ms: z.number().nullable(), created_at: z.string()})), 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()}))}), 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"]), status_message: z.string().nullable(), 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(), payment_request: z.object({id: z.string(), order_id: z.string(), merchant: z.object({id: z.string(), partner: z.object({id: z.string()}).nullable()}).nullable(), customer: z.object({id: z.string(), name: z.string(), email: z.string()}).nullable(), payment_token: z.string(), authorization_agreement_record_id: z.string().nullable()}).nullable(), destination_account: z.string().nullable(), destination_account_type: z.string().nullable(), remittance_information: z.string().nullable(), payment_scheme: 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(), related_transaction: z.object({id: z.string(), transaction_number: z.string()}).nullable(), provider_status_events: z.array(z.object({id: z.string(), source: z.enum(["webhook", "polling", "finalization", "admin"]), provider_name: z.string(), provider_status: z.string(), processing_status: z.enum(["received", "processed", "ignored", "failed", "conflict", "stale"]), provider_updated_at: z.string().nullable(), created_at: z.string(), observed_at: z.string(), signature_valid: z.boolean(), event_id: z.string().optional(), event_type: z.string().optional(), processing_error: z.string().optional(), provider_request_id: z.string().optional()})), merchant_webhook_deliveries: z.array(z.object({id: z.string(), payment_provider_status_id: z.string().nullable(), webhook_url: z.string(), platform: z.enum(["embedded", "shopify", "woocommerce"]), event_type: z.string(), status: z.enum(["delivered", "failed"]), response_status_code: z.number().nullable(), error_message: z.string().optional(), duration_ms: z.number().nullable(), created_at: z.string()})), 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(), 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"]), status_message: z.string().nullable(), 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(), payment_request: z.object({id: z.string(), order_id: z.string(), merchant: z.object({id: z.string(), partner: z.object({id: z.string()}).nullable()}).nullable(), customer: z.object({id: z.string(), name: z.string(), email: z.string()}).nullable(), payment_token: z.string(), authorization_agreement_record_id: z.string().nullable()}).nullable(), destination_account: z.string().nullable(), destination_account_type: z.string().nullable(), remittance_information: z.string().nullable(), payment_scheme: 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(), related_transaction: z.object({id: z.string(), transaction_number: z.string()}).nullable(), provider_status_events: z.array(z.object({id: z.string(), source: z.enum(["webhook", "polling", "finalization", "admin"]), provider_name: z.string(), provider_status: z.string(), processing_status: z.enum(["received", "processed", "ignored", "failed", "conflict", "stale"]), provider_updated_at: z.string().nullable(), created_at: z.string(), observed_at: z.string(), signature_valid: z.boolean(), event_id: z.string().optional(), event_type: z.string().optional(), processing_error: z.string().optional(), provider_request_id: z.string().optional()})), merchant_webhook_deliveries: z.array(z.object({id: z.string(), payment_provider_status_id: z.string().nullable(), webhook_url: z.string(), platform: z.enum(["embedded", "shopify", "woocommerce"]), event_type: z.string(), status: z.enum(["delivered", "failed"]), response_status_code: z.number().nullable(), error_message: z.string().optional(), duration_ms: z.number().nullable(), created_at: z.string()})), 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()})}); 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 }; /** * Get a transaction by ID * * GET /api/v1/transactions/{id} */ export const getApiApiV1TransactionsId = async (args: GetApiApiV1TransactionsIdArgs, options?: GetApiApiV1TransactionsIdOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/transactions/${encodeURIComponent(String(args.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(transactionResponse, await res.json()) };