import {z} from 'zod' export type GetApiAppsAppUuidPaymentsMeInvoiceNumberArgs = {'X-Fanvue-API-Version': string, appUuid: string, invoiceNumber: string}; export type GetApiAppsAppUuidPaymentsMeInvoiceNumberOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAppsAppUuidPaymentsMeInvoiceNumberResponse = z.object({uuid: z.string(), appUuid: z.string(), buyerUuid: z.string(), planUuid: z.string(), invoiceNumber: z.string().nullable(), billingReferenceId: z.string(), clientReferenceId: z.string(), status: z.enum(["pending", "completed", "failed", "refunded", "expired"]), amount: z.number(), currency: z.string(), externalPaymentId: z.string(), createdAt: z.string(), updatedAt: 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 }; /** * Get the authenticated user's one-time (app-OTP) payment by invoice number * * GET /apps/{appUuid}/payments/me/{invoiceNumber} */ export const getApiAppsAppUuidPaymentsMeInvoiceNumber = async (args: GetApiAppsAppUuidPaymentsMeInvoiceNumberArgs, options?: GetApiAppsAppUuidPaymentsMeInvoiceNumberOptions) => { const {baseUrl = "https://api.fanvue.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Fanvue-API-Version'] != null) headers.set("X-Fanvue-API-Version", String(args['X-Fanvue-API-Version'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/apps/${encodeURIComponent(String(args.appUuid))}/payments/me/${encodeURIComponent(String(args.invoiceNumber))}${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(getApiAppsAppUuidPaymentsMeInvoiceNumberResponse, await res.json()) };