import {z} from 'zod' export type GetApiApiV1AdminTransactionsTransactionIdArgs = {transactionId: string, include_timeline?: boolean | undefined, include_payloads?: boolean | undefined}; export type GetApiApiV1AdminTransactionsTransactionIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionAdminDetailResponse = z.object({success: z.boolean(), data: z.object({transaction: z.object({id: z.string(), transaction_number: z.string(), transaction_type: z.enum(["payment", "refund", "reversal"]), status: z.string(), status_message: z.string().nullable(), target_status: z.string().nullable(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), cross_border: z.boolean(), cross_border_provider: z.string().nullable(), 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(), tpp_transaction_id: z.string().nullable(), bank_provider_transaction_id: z.string().nullable(), tpp_created_at: z.string().nullable(), tpp_updated_at: z.string().nullable(), payment_scheme: z.string().nullable(), remittance_information: z.string().nullable(), customer_account: z.string().nullable(), customer_account_type: z.string().nullable(), customer_bank_name: z.string().nullable(), customer_name: z.string().nullable(), destination_account: z.string().nullable(), destination_account_type: z.string().nullable(), destination_account_holder_name: z.string().nullable(), payout_at: z.string().nullable(), payout_batch_id: z.string().nullable(), invoice_id: z.string().nullable(), settled_at: z.string().nullable(), webhook_status: z.string().nullable(), webhook_error_message: z.string().nullable(), related_transaction: z.object({id: z.string(), transaction_number: z.string()}).nullable(), test: z.boolean().nullable(), platform: z.string().nullable(), created_at: z.string(), updated_at: z.string(), problems: z.array(z.object({code: z.string(), message: z.string(), label: z.string(), is_resolvable: z.boolean()})).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(), payment_request: z.object({id: z.string(), order_id: z.string().nullable(), status: z.string(), external_payment_request_id: z.string().nullable(), provider_name: z.string().nullable(), provider_environment: z.string().nullable(), tink_request_id: z.string().nullable(), provider_request_id: z.string().nullable(), payment_token: z.string().nullable(), payment_token_expires_at: z.string().nullable(), payment_reference: z.string().nullable(), selected_bank_id: z.string().nullable(), payment_link_id: z.string().nullable(), session_id: z.string().nullable(), locale: z.string().nullable(), original_amount: z.string().nullable(), original_currency: z.string().nullable(), display_exchange_rate: z.union([z.string(), z.number()]).nullable(), authorization_agreement_record_id: z.string().nullable(), merchant: z.object({id: z.string(), brand_name: z.string(), uri: z.string(), mode: z.string(), country: z.string().nullable(), partner: z.object({id: z.string()}).nullable()}).nullable(), customer: z.object({id: z.string(), name: z.string(), email: z.string().nullable(), customer_identifier: z.string().nullable(), provider_ids: z.unknown()}).nullable()}).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()}))}), can_refund: z.boolean(), 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()})), refunds: z.array(z.object({id: z.string(), transaction_number: z.string(), transaction_type: z.enum(["payment", "refund", "reversal"]), status: z.string(), status_message: z.string().nullable(), target_status: z.string().nullable(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), cross_border: z.boolean(), cross_border_provider: z.string().nullable(), 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(), tpp_transaction_id: z.string().nullable(), bank_provider_transaction_id: z.string().nullable(), tpp_created_at: z.string().nullable(), tpp_updated_at: z.string().nullable(), payment_scheme: z.string().nullable(), remittance_information: z.string().nullable(), customer_account: z.string().nullable(), customer_account_type: z.string().nullable(), customer_bank_name: z.string().nullable(), customer_name: z.string().nullable(), destination_account: z.string().nullable(), destination_account_type: z.string().nullable(), destination_account_holder_name: z.string().nullable(), payout_at: z.string().nullable(), payout_batch_id: z.string().nullable(), invoice_id: z.string().nullable(), settled_at: z.string().nullable(), webhook_status: z.string().nullable(), webhook_error_message: z.string().nullable(), related_transaction: z.object({id: z.string(), transaction_number: z.string()}).nullable(), test: z.boolean().nullable(), platform: z.string().nullable(), created_at: z.string(), updated_at: z.string(), problems: z.array(z.object({code: z.string(), message: z.string(), label: z.string(), is_resolvable: z.boolean()})).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(), payment_request: z.object({id: z.string(), order_id: z.string().nullable(), status: z.string(), external_payment_request_id: z.string().nullable(), provider_name: z.string().nullable(), provider_environment: z.string().nullable(), tink_request_id: z.string().nullable(), provider_request_id: z.string().nullable(), payment_token: z.string().nullable(), payment_token_expires_at: z.string().nullable(), payment_reference: z.string().nullable(), selected_bank_id: z.string().nullable(), payment_link_id: z.string().nullable(), session_id: z.string().nullable(), locale: z.string().nullable(), original_amount: z.string().nullable(), original_currency: z.string().nullable(), display_exchange_rate: z.union([z.string(), z.number()]).nullable(), authorization_agreement_record_id: z.string().nullable(), merchant: z.object({id: z.string(), brand_name: z.string(), uri: z.string(), mode: z.string(), country: z.string().nullable(), partner: z.object({id: z.string()}).nullable()}).nullable(), customer: z.object({id: z.string(), name: z.string(), email: z.string().nullable(), customer_identifier: z.string().nullable(), provider_ids: z.unknown()}).nullable()}).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(), reversals: z.array(z.object({id: z.string(), transaction_number: z.string(), transaction_type: z.enum(["payment", "refund", "reversal"]), status: z.string(), status_message: z.string().nullable(), target_status: z.string().nullable(), amount: z.number(), currency: z.object({code: z.string().min(3).max(3), symbol: z.string(), name: z.string(), minor_unit: z.number()}), cross_border: z.boolean(), cross_border_provider: z.string().nullable(), 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(), tpp_transaction_id: z.string().nullable(), bank_provider_transaction_id: z.string().nullable(), tpp_created_at: z.string().nullable(), tpp_updated_at: z.string().nullable(), payment_scheme: z.string().nullable(), remittance_information: z.string().nullable(), customer_account: z.string().nullable(), customer_account_type: z.string().nullable(), customer_bank_name: z.string().nullable(), customer_name: z.string().nullable(), destination_account: z.string().nullable(), destination_account_type: z.string().nullable(), destination_account_holder_name: z.string().nullable(), payout_at: z.string().nullable(), payout_batch_id: z.string().nullable(), invoice_id: z.string().nullable(), settled_at: z.string().nullable(), webhook_status: z.string().nullable(), webhook_error_message: z.string().nullable(), related_transaction: z.object({id: z.string(), transaction_number: z.string()}).nullable(), test: z.boolean().nullable(), platform: z.string().nullable(), created_at: z.string(), updated_at: z.string(), problems: z.array(z.object({code: z.string(), message: z.string(), label: z.string(), is_resolvable: z.boolean()})).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(), payment_request: z.object({id: z.string(), order_id: z.string().nullable(), status: z.string(), external_payment_request_id: z.string().nullable(), provider_name: z.string().nullable(), provider_environment: z.string().nullable(), tink_request_id: z.string().nullable(), provider_request_id: z.string().nullable(), payment_token: z.string().nullable(), payment_token_expires_at: z.string().nullable(), payment_reference: z.string().nullable(), selected_bank_id: z.string().nullable(), payment_link_id: z.string().nullable(), session_id: z.string().nullable(), locale: z.string().nullable(), original_amount: z.string().nullable(), original_currency: z.string().nullable(), display_exchange_rate: z.union([z.string(), z.number()]).nullable(), authorization_agreement_record_id: z.string().nullable(), merchant: z.object({id: z.string(), brand_name: z.string(), uri: z.string(), mode: z.string(), country: z.string().nullable(), partner: z.object({id: z.string()}).nullable()}).nullable(), customer: z.object({id: z.string(), name: z.string(), email: z.string().nullable(), customer_identifier: z.string().nullable(), provider_ids: z.unknown()}).nullable()}).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()}), timeline: z.array(z.object({id: z.string(), type: z.union([z.literal("provider_status"), z.literal("merchant_webhook"), z.literal("tm_webhook"), z.literal("tm_post_processor"), z.literal("payout_batch"), z.literal("refund_session"), z.literal("fee"), z.literal("payment_request_update"), z.literal("refund"), z.literal("reversal")]), timestamp: z.string(), summary: z.string(), details: z.object({}), source: z.object({kind: z.union([z.literal("payment"), z.literal("refund"), z.literal("reversal")]), transaction_id: z.string(), transaction_number: z.string()}).optional()})).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 full internal detail for a transaction (admin/debug): merchant, payment-request and provider references, fees, refunds/reversals, and an optional unified event timeline. * * GET /api/v1/admin/transactions/{transactionId} */ export const getApiApiV1AdminTransactionsTransactionId = async (args: GetApiApiV1AdminTransactionsTransactionIdArgs, options?: GetApiApiV1AdminTransactionsTransactionIdOptions) => { 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 (args.include_timeline != null) query.append("include_timeline", String(args.include_timeline)) if (args.include_payloads != null) query.append("include_payloads", String(args.include_payloads)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/transactions/${encodeURIComponent(String(args.transactionId))}${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(transactionAdminDetailResponse, await res.json()) };