import {z} from 'zod' export type ExternalCustomerReference = string; export type PatchApiPaymentsPreChargebackAlertsAlertsAlertIdArgs = {alert_id: string, body: {action?: ('REFUND' | 'CANCEL' | 'REFUND_AND_CANCEL' | 'ACCEPT_DISPUTE') | undefined, note?: string | undefined, externalCustomerReference?: ExternalCustomerReference | undefined}}; export type PatchApiPaymentsPreChargebackAlertsAlertsAlertIdOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const preChargebackAlert = z.object({id: z.string(), merchantId: z.string(), alertType: z.enum(["ETHOCA_ALERT", "VERIFI_RDR"]), alertNetworkId: z.string().nullable().optional(), status: z.enum(["ACTION_REQUIRED", "RESOLVED", "INVALID"]), chargebackReasonCode: z.string().nullable().optional(), transactionAmountInCents: z.number().int().nullable().optional(), transactionCurrencyCode: z.string().nullable().optional(), transactionAuthorizedAt: z.string().nullable().optional(), actionRequiredDeadline: z.string().nullable().optional(), transactionAuthorizationCode: z.string().nullable().optional(), transactionAcquirerReferenceNumber: z.string().nullable().optional(), transactionStatementDescriptor: z.string().nullable().optional(), transactionCardBin: z.string().nullable().optional(), card: z.object({bin: z.string().nullable().optional(), lastFour: z.string().nullable().optional(), brand: z.string().nullable().optional(), issuer: z.string().nullable().optional()}).nullable().optional(), transactionRefundOutcome: z.enum(["REFUNDED", "NOT_REFUNDED", "null"]).nullable().optional(), transactionNetworkId: z.string().nullable().optional(), subscriptionCancelOutcome: z.string().nullable().optional(), note: z.string().nullable().optional(), integrationId: z.string().nullable().optional(), integrationTransactionId: z.string().nullable().optional(), createdAt: z.string()}); 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 a Pre-Chargeback Alert * * PATCH /payments/pre-chargeback-alerts/alerts/{alert_id} */ export const patchApiPaymentsPreChargebackAlertsAlertsAlertId = async (args: PatchApiPaymentsPreChargebackAlertsAlertsAlertIdArgs, options?: PatchApiPaymentsPreChargebackAlertsAlertsAlertIdOptions) => { const {baseUrl = "https://api.evervault.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/payments/pre-chargeback-alerts/alerts/${encodeURIComponent(String(args.alert_id))}${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(preChargebackAlert, await res.json()) };