import {z} from 'zod' export type CreateApiPaymentsPaymentIdTransactionsTransactionIdCancelArgs = {payment_id: string, transaction_id: string, body: {description?: string | undefined, reason?: ('DUPLICATE' | 'FRAUDULENT' | 'REQUESTED_BY_CUSTOMER') | undefined, merchant_reference: string, response_additional_data?: ({receipt?: boolean | undefined, receipt_language?: ('ES' | 'EN' | 'PT') | undefined, transactions_history?: boolean | undefined, raw_request: unknown, raw_response?: boolean | undefined}) | undefined}}; export type CreateApiPaymentsPaymentIdTransactionsTransactionIdCancelOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPaymentsPaymentIdTransactionsTransactionIdCancelResponse = z.object({id: z.string().optional(), type: z.string().optional(), status: z.string().optional(), category: z.string().optional(), amount: z.object({captured: z.number().int().optional(), currency: z.string().optional(), currency_conversion: z.unknown(), refunded: z.number().int().optional(), value: z.number().int().optional()}).optional(), merchant_reference: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), provider_data: z.object({id: z.string().optional(), transaction_id: z.string().optional(), account_id: z.string().optional(), status: z.string().optional(), sub_status: z.string().optional(), status_detail: z.string().optional(), response_message: z.unknown(), response_code: z.string().optional(), raw_request: z.object({}).optional(), raw_response: z.object({message: z.string().optional()}).optional(), third_party_transaction_id: z.unknown(), third_party_account_id: z.unknown(), iso8583_response_code: z.string().optional(), iso8583_response_message: z.string().optional()}).optional(), response_code: z.string().optional(), response_message: z.string().optional(), payment: z.object({id: z.string().optional(), account_id: z.string().optional(), description: z.string().optional(), country: z.string().optional(), status: z.string().optional(), sub_status: z.string().optional(), merchant_order_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), amount: z.object({captured: z.number().int().optional(), currency: z.string().optional(), currency_conversion: z.unknown(), refunded: z.number().int().optional(), value: z.number().int().optional()}).optional(), split_marketplace: z.array(z.unknown()).optional()}).optional(), customer_payer: z.unknown(), simplified_mode: z.boolean().optional(), receipt: z.boolean().optional(), receipt_url: z.unknown(), receipt_language: z.unknown()}); 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 }; /** * Cancel Payment * * POST /payments/{payment_id}/transactions/{transaction_id}/cancel */ export const createApiPaymentsPaymentIdTransactionsTransactionIdCancel = async (args: CreateApiPaymentsPaymentIdTransactionsTransactionIdCancelArgs, options?: CreateApiPaymentsPaymentIdTransactionsTransactionIdCancelOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (publicApiKey !== undefined) headers.set("PUBLIC-API-KEY", publicApiKey) if (privateSecretKey !== undefined) headers.set("PRIVATE-SECRET-KEY", privateSecretKey) const url = `${baseUrl.replace(/\/+$/, '')}/payments/${encodeURIComponent(String(args.payment_id))}/transactions/${encodeURIComponent(String(args.transaction_id))}/cancel${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(createApiPaymentsPaymentIdTransactionsTransactionIdCancelResponse, await res.json()) };