import {z} from 'zod' export type Address = {company?: string | undefined, street?: string | undefined, street2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined, phone?: string | undefined, 'first-name'?: string | undefined, 'last-name'?: string | undefined}; export type AchTokenResponse = {'token-id'?: string | undefined, 'times-used'?: number | undefined, 'last-used'?: string | undefined, 'merchant-id'?: string | undefined, 'routing-number'?: string | undefined, 'account-number'?: string | undefined, 'account-type'?: ('Checking' | 'Savings') | undefined, 'individual-name'?: string | undefined, 'token-description'?: string | undefined, created?: string | undefined, updated?: string | undefined, 'customer-key'?: string | undefined, default?: boolean | undefined}; export type AchTransaction = {type: 'Debit' | 'Credit', amount?: string | undefined, status?: ('Pending' | 'Settling' | 'Settled' | 'Returned' | 'Writing' | 'Declined' | 'Not_Confirmed' | 'Sent' | 'Rejected' | 'Funded' | 'Partially_Funded' | 'Completed') | undefined, 'routing-number': string, 'account-number': string, 'account-type': 'Checking' | 'Savings', 'standard-entry-class-code': 'PPD', 'individual-name'?: string | undefined, id?: string | undefined, 'check-status'?: ('Pending' | 'Rejected' | 'Debit Sent' | 'Cancelled' | 'Credit Sent' | 'Unprocessed') | undefined, 'funding-status'?: ('Pending' | 'No Credit' | 'Credit Sent' | 'Chargeback' | 'Debit Sent' | 'Unprocessed') | undefined, invoice?: string | undefined, 'check-number'?: string | undefined, billing?: Address | undefined, shipping?: Address | undefined, 'purchase-order'?: string | undefined, 'order-id'?: string | undefined, 'status-change-date'?: string | undefined, 'customer-id'?: string | undefined, 'email-address'?: string | undefined, description?: string | undefined, comments?: string | undefined, 'billing-is-shipping'?: ('true' | 'false') | undefined, 'display-message'?: string | undefined, 'provider-transaction-id'?: string | undefined, 'trace-number'?: string | undefined, 'settled-date'?: string | undefined, 'returned-date'?: string | undefined, 'returned-code'?: string | undefined, 'returned-message'?: string | undefined, 'ach-token'?: AchTokenResponse | undefined, 'merchant-id'?: string | undefined, 'terminal-id'?: string | undefined, 'software-type'?: string | undefined, 'paya-authorization'?: string | undefined, 'processing-type'?: string | undefined, 'external-transaction-reference'?: string | undefined, 'execution-date'?: string | undefined, 'token-id'?: string | undefined, 'create-date'?: string | undefined, 'micr-data'?: string | undefined, 'image-front-edoc-id'?: string | undefined, 'image-back-edoc-id'?: string | undefined, 'image-front'?: string | undefined, 'image-back'?: string | undefined}; export type CreateApiRestV2AchTransactionsValidateArgs = {'api-key': string, body: AchTransaction}; export type CreateApiRestV2AchTransactionsValidateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const address = z.object({company: z.string().optional(), street: z.string().optional(), street2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), country: z.string().optional(), phone: z.string().optional(), "first-name": z.string().optional(), "last-name": z.string().optional()}); export const achTokenResponse = z.object({"token-id": z.string().optional(), "times-used": z.number().int().optional(), "last-used": z.string().optional(), "merchant-id": z.string().optional(), "routing-number": z.string().optional(), "account-number": z.string().optional(), "account-type": z.enum(["Checking", "Savings"]).optional(), "individual-name": z.string().optional(), "token-description": z.string().optional(), created: z.string().optional(), updated: z.string().optional(), "customer-key": z.string().optional(), default: z.boolean().optional()}); export const achTransaction = z.object({type: z.enum(["Debit", "Credit"]), amount: z.string().optional(), status: z.enum(["Pending", "Settling", "Settled", "Returned", "Writing", "Declined", "Not_Confirmed", "Sent", "Rejected", "Funded", "Partially_Funded", "Completed"]).optional(), "routing-number": z.string(), "account-number": z.string(), "account-type": z.enum(["Checking", "Savings"]), "standard-entry-class-code": z.literal("PPD"), "individual-name": z.string().optional(), id: z.string().optional(), "check-status": z.enum(["Pending", "Rejected", "Debit Sent", "Cancelled", "Credit Sent", "Unprocessed"]).optional(), "funding-status": z.enum(["Pending", "No Credit", "Credit Sent", "Chargeback", "Debit Sent", "Unprocessed"]).optional(), invoice: z.string().optional(), "check-number": z.string().optional(), billing: address.optional(), shipping: address.optional(), "purchase-order": z.string().optional(), "order-id": z.string().optional(), "status-change-date": z.string().optional(), "customer-id": z.string().optional(), "email-address": z.string().optional(), description: z.string().optional(), comments: z.string().optional(), "billing-is-shipping": z.enum(["true", "false"]).optional(), "display-message": z.string().optional(), "provider-transaction-id": z.string().optional(), "trace-number": z.string().optional(), "settled-date": z.string().optional(), "returned-date": z.string().optional(), "returned-code": z.string().optional(), "returned-message": z.string().optional(), "ach-token": achTokenResponse.optional(), "merchant-id": z.string().optional(), "terminal-id": z.string().optional(), "software-type": z.string().optional(), "paya-authorization": z.string().optional(), "processing-type": z.string().optional(), "external-transaction-reference": z.string().optional(), "execution-date": z.string().optional(), "token-id": z.string().optional(), "create-date": z.string().optional(), "micr-data": z.string().optional(), "image-front-edoc-id": z.string().optional(), "image-back-edoc-id": z.string().optional(), "image-front": z.string().optional(), "image-back": z.string().optional()}); export const achTransactionResponsePayload = z.object({"ach-transaction": achTransaction.optional(), payloadType: 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 }; /** * Validate ACH transaction * * POST /rest/v2/ach/transactions/validate */ export const createApiRestV2AchTransactionsValidate = async (args: CreateApiRestV2AchTransactionsValidateArgs, options: CreateApiRestV2AchTransactionsValidateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['api-key'] != null) headers.set("api-key", String(args['api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/rest/v2/ach/transactions/validate${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(achTransactionResponsePayload, await res.json()) };