import {z} from 'zod' export type GetApiSwiftCustomersCustomerIdPaymentsPaymentIdArgs = {customerId: string, paymentId: string}; export type GetApiSwiftCustomersCustomerIdPaymentsPaymentIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getSwiftResultData = z.object({transactionStatus: z.string().optional(), transactionStatusReason: z.string().optional(), statusDescription: z.string().optional(), reasonDescription: z.string().optional(), trackingReference: z.string().optional(), originalPaymentId: z.string().optional(), orderDetailId: z.string().optional(), releasedDateFromGpg: z.string().optional(), initiationTime: z.string().optional(), lastUpdatedTime: z.string().optional(), creditedTimestamp: z.string().optional(), completionTime: z.string().optional(), instructedAmount: z.object({}).optional(), estimatedAmount: z.object({}).optional(), creditedAmount: z.object({}).optional(), payerBank: z.object({}).optional(), beneficiaryBank: z.object({}).optional(), paymentEvents: z.object({}).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 SWIFT Status by payment ID * * GET /swift/customers/{customerId}/payments/{paymentId} */ export const getApiSwiftCustomersCustomerIdPaymentsPaymentId = async (args: GetApiSwiftCustomersCustomerIdPaymentsPaymentIdArgs, options?: GetApiSwiftCustomersCustomerIdPaymentsPaymentIdOptions) => { const {baseUrl = "https://masspaysandbox.api.convera.com/masspayments", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/swift/customers/${encodeURIComponent(String(args.customerId))}/payments/${encodeURIComponent(String(args.paymentId))}${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(getSwiftResultData, await res.json()) };