import {z} from 'zod' export type PaymentInfo = {payment_description_wire?: string | undefined, payment_reason_code?: string | undefined}; export type UpdatePaymentDesiredFromLeg = {account_id: string}; export type UpdatePaymentDesiredToLeg = {account_id: string}; export type UpdatePaymentDesiredOverlay = {from: UpdatePaymentDesiredFromLeg, to: UpdatePaymentDesiredToLeg}; export type UpdatePaymentRequest = {organization_reference_id?: string | undefined, payment_info?: PaymentInfo | undefined, funding_account_id: string, desired: UpdatePaymentDesiredOverlay}; export type PatchApiV1PaymentsPaymentIdArgs = {paymentId: string, body: UpdatePaymentRequest}; export type PatchApiV1PaymentsPaymentIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentInfo = z.object({payment_description_wire: z.string().max(140).optional(), payment_reason_code: z.string().optional()}); export const paymentDesiredFromLegResponse = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentDesiredToLegResponse = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentDesiredOverlay = z.object({from: paymentDesiredFromLegResponse, to: paymentDesiredToLegResponse}); export const paymentEstimatedFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentEstimatedToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentEstimatedOverlay = z.object({from: paymentEstimatedFromLeg, to: paymentEstimatedToLeg}); export const paymentActualFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentActualToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentActualOverlay = z.object({from: paymentActualFromLeg, to: paymentActualToLeg}); export const riskStatusReason = z.object({risk_status_reason_type: z.enum(["ENTITY", "ACCOUNT", "OWNERSHIP", "COUNTERPARTY", "INDIRECT", "BEHAVIORAL", "ERROR"]), risk_status_reason_category: z.string(), risk_status_reason_participant_id: z.string().nullable().optional(), risk_status_reason_message: z.string(), risk_status_reason_severity: z.enum(["Low", "Medium", "High", "Severe", "ALLOWLISTED", "BLOCKLISTED"]), risk_status_reason_significance: z.enum(["DECISIVE", "NON_DECISIVE", "SUPERSEDED_BY_ALLOWLIST", "SUPERSEDED_BY_BLOCKLIST"]).nullable().optional(), volume_usd_percent: z.string().nullable().optional(), volume_usd_percent_threshold: z.string().nullable().optional(), volume_usd_amount: z.string().nullable().optional(), volume_usd_amount_threshold: z.string().nullable().optional(), confidence_score: z.enum(["LOW_CONFIDENCE", "LOW_MODERATE_CONFIDENCE", "MODERATE_CONFIDENCE", "HIGH_MODERATE_CONFIDENCE", "HIGH_CONFIDENCE", "NEAR_CERTAINTY", "CERTAIN", "EXACT_MATCH"]).nullable().optional(), confidence_score_threshold: z.enum(["LOW_CONFIDENCE", "LOW_MODERATE_CONFIDENCE", "MODERATE_CONFIDENCE", "HIGH_MODERATE_CONFIDENCE", "HIGH_CONFIDENCE", "NEAR_CERTAINTY", "CERTAIN"]).nullable().optional()}); export const paymentStepEstimatedFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentStepEstimatedToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentStepEstimatedOverlay = z.object({from: paymentStepEstimatedFromLeg, to: paymentStepEstimatedToLeg}); export const paymentStepActualFromLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentStepActualToLeg = z.object({account_id: z.string().nullable(), amount: z.string().nullable(), currency: z.string().nullable(), network: z.string().nullable()}); export const paymentStepActualOverlay = z.object({from: paymentStepActualFromLeg, to: paymentStepActualToLeg}); export const stepFee = z.object({fee_amount: z.string(), fee_currency: z.string(), fee_type: z.string(), fee_metadata: z.record(z.string(), z.unknown()).optional()}); export const statusReason = z.object({error_code: z.string(), error_message: z.string()}); export const paymentStep = z.object({id: z.string(), payment_id: z.string(), step_sequence: z.number().int(), step_type: z.enum(["transfer", "swap"]), estimated: paymentStepEstimatedOverlay, actual: paymentStepActualOverlay, transaction_hash: z.string().nullable().optional(), unsigned_transaction: z.string().nullable().optional(), fees: z.array(stepFee), provider_key: z.enum(["capa", "circle_mint", "kraken", "openfx", "turnkey", "zuba"]).nullable().optional(), status: z.enum(["created", "signature_requested", "signed", "submitted", "confirmed", "completed", "failed"]), status_reasons: z.array(statusReason).nullable().optional(), created_at: z.string(), updated_at: z.string(), signature_requested_at: z.string().nullable().optional(), signed_at: z.string().nullable().optional(), submitted_at: z.string().nullable().optional(), confirmed_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), failed_at: z.string().nullable().optional()}); export const payment = z.object({id: z.string(), workspace_id: z.string(), organization_reference_id: z.string().nullable().optional(), payment_info: paymentInfo.nullable().optional(), direction: z.enum(["inbound", "outbound", "rebalance"]), funding_account_id: z.string().nullable(), desired: paymentDesiredOverlay, estimated: paymentEstimatedOverlay, actual: paymentActualOverlay, risk_status: z.enum(["unchecked", "awaiting_decision", "automatically_approved", "manually_approved", "automatically_rejected", "manually_rejected", "null"]).nullable(), risk_status_reasons: z.array(riskStatusReason), provider_metadata: z.array(z.object({provider_metadata_type: z.enum(["WALLET_RISK_SCREENING", "TRAVEL_RULE"]).optional(), provider_metadata_key: z.enum(["TRM_LABS", "NOTABENE"]).optional(), provider_metadata_data: z.record(z.string(), z.unknown()).optional()})), participants: z.array(z.object({role: z.enum(["ORIGINATOR", "ORIGINATOR_VASP", "BENEFICIARY", "BENEFICIARY_VASP", "CUSTODY_SERVICE", "INTERMEDIARY_VASP", "CONTRACT"]).optional(), resource: z.object({resource_type: z.enum(["COUNTERPARTY", "TENANT", "WORKSPACE", "ACCOUNT"]).optional(), id: z.string().nullable().optional(), name_match_score: z.string().nullable().optional(), name_match_threshold: z.string().nullable().optional(), name_match_comparison_id: z.string().nullable().optional(), resolution: z.enum(["EXACT_MATCH", "PARTIAL_MATCH", "DID_NOT_MATCH", "COUNTERPARTY_CREATED", "USER_SUPPLIED_ID"]).optional()}).optional()})), risk_reviewed_by: z.string().nullable().optional(), risk_reviewed_at: z.string().nullable().optional(), risk_review_reason: z.string().nullable().optional(), balance_status: z.enum(["unreserved", "awaiting_funds", "reserved"]).nullable(), balance_reserved_at: z.string().nullable(), steps: z.array(paymentStep), created_at: z.string(), updated_at: z.string(), expires_at: z.string().nullable()}); export const paymentResponse = z.object({data: payment}); 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 }; /** * Update payment * * PATCH /v1/payments/{paymentId} */ export const patchApiV1PaymentsPaymentId = async (args: PatchApiV1PaymentsPaymentIdArgs, options?: PatchApiV1PaymentsPaymentIdOptions) => { const {baseUrl = "https://api.tesser.xyz", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/payments/${encodeURIComponent(String(args.paymentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(paymentResponse, await res.json()) };