import {z} from 'zod' export type GetApiOrdersOrderIdTransactionsArgs = {order_id: string, after?: string | undefined, per_page?: number | undefined, sort_order?: ('asc' | 'desc') | undefined, sort_property?: ('id' | 'updated_at') | undefined}; export type GetApiOrdersOrderIdTransactionsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const ordersTransactionAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), order_id: z.number().int().optional(), status: z.string().optional(), external_type: z.string().nullable().optional(), external_id: z.string().optional(), amount: z.string().nullable().optional(), currency: z.string().nullable().optional(), reason: z.string().nullable().optional(), adjusted_transaction_id: z.string().nullable().optional(), result: z.string().optional(), billing_payment_instruction_id: z.string().nullable().optional(), billing_payment_instruction_type: z.string().nullable().optional(), arn: z.string().nullable().optional(), is_rebill: z.boolean().nullable().optional(), rebill_number: z.string().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); export const getApiOrdersOrderIdTransactionsResponse = z.array(ordersTransactionAttributes); 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 }; /** * List Transactions * * GET /orders/{order_id}/transactions * * Also accepts auth: OAuth2 */ export const getApiOrdersOrderIdTransactions = async (args: GetApiOrdersOrderIdTransactionsArgs, options?: GetApiOrdersOrderIdTransactionsOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.after != null) query.append("after", String(args.after)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.sort_property != null) query.append("sort_property", String(args.sort_property)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/orders/${encodeURIComponent(String(args.order_id))}/transactions${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(getApiOrdersOrderIdTransactionsResponse, await res.json()) };