import {z} from 'zod' export type GetApiBillingV1SubscriptionsSubscriptionIdPaymentsArgs = {subscriptionId: string, count?: number | undefined, fromDate?: number | undefined, method?: ('ADP_INVOICE' | 'ARIBAPAY' | 'BT_BILL' | 'CLICKANDBUY' | 'CLOUDFOUNDRY' | 'CREDIT_CARD' | 'CUMULA_BILL' | 'DTAG' | 'EXTERNAL_INVOICE' | 'KREDITKARTE' | 'LASTSCHRIFT_MRNEXNET' | 'MANO_TEO_BILL' | 'MANUAL' | 'MARKETPLACE_CREDITS' | 'NETS_ARVATO_INVOICE' | 'NEXTEL' | 'PAYPAL' | 'ROGERS_CC_DTMF' | 'ROGERS_CC_POS' | 'SNAP' | 'TBILL' | 'THISTLE' | 'TOICLEARING') | undefined, result?: ('FAILED' | 'GATEWAY_NOT_AVAILABLE' | 'MANUAL' | 'SUCCESSFUL') | undefined, sortField?: ('AMOUNT' | 'DATE' | 'PAYMENT_ID') | undefined, sortOrder?: ('ASC' | 'DESC') | undefined, start?: number | undefined, toDate?: number | undefined}; export type GetApiBillingV1SubscriptionsSubscriptionIdPaymentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({href: z.string().optional(), rel: z.string().optional()}).nullable(); export const linkWS = z.object({href: z.string().optional(), id: z.string().optional()}).nullable(); export const currency = z.enum(["USD", "CAD", "EUR", "JPY", "GBP", "KRW", "CHF", "SEK", "SGD", "MYR", "AUD", "MXN", "INR", "BRL", "DKK", "NZD", "NOK", "ZAR", "PHP", "CNY", "SAR", "GTQ", "IDR", "ARS", "COP", "PEN"]); export const gatewayResponseWS = z.object({avs: z.boolean().optional(), code: z.string().nullable().optional(), cvv: z.boolean().optional(), message: z.string().nullable().optional()}); export const paymentMethod = z.enum(["CREDIT_CARD", "PAYPAL", "MANUAL", "EXTERNAL_INVOICE", "MARKETPLACE_CREDITS"]); export const paymentResult = z.enum(["SUCCESSFUL", "FAILED", "GATEWAY_NOT_AVAILABLE", "MANUAL"]); export const paymentWS = z.object({links: z.array(link).optional(), amount: z.number().nullable().optional(), company: linkWS.optional(), currency: currency.optional(), date: z.number().nullable().optional(), gatewayResponse: gatewayResponseWS.optional(), id: z.number().nullable().optional(), method: paymentMethod.optional(), result: paymentResult.optional(), transactionId: z.string().nullable().optional(), user: linkWS.optional()}).nullable(); export const getApiBillingV1SubscriptionsSubscriptionIdPaymentsResponse = z.array(paymentWS); 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 all payments for a subscription * * GET /billing/v1/subscriptions/{subscriptionId}/payments */ export const getApiBillingV1SubscriptionsSubscriptionIdPayments = async (args: GetApiBillingV1SubscriptionsSubscriptionIdPaymentsArgs, options?: GetApiBillingV1SubscriptionsSubscriptionIdPaymentsOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.count != null) query.append("count", String(args.count)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.method != null) query.append("method", String(args.method)) if (args.result != null) query.append("result", String(args.result)) if (args.sortField != null) query.append("sortField", String(args.sortField)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (args.start != null) query.append("start", String(args.start)) if (args.toDate != null) query.append("toDate", String(args.toDate)) const url = `${baseUrl.replace(/\/+$/, '')}/billing/v1/subscriptions/${encodeURIComponent(String(args.subscriptionId))}/payments${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(getApiBillingV1SubscriptionsSubscriptionIdPaymentsResponse, await res.json()) };