import {z} from 'zod' export type PaymentLink = {id?: number | undefined, name: string, publishable_key?: string | undefined, cta?: ('book' | 'donate' | 'pay') | undefined, amount?: (number | null) | undefined, amount_min?: (number | null) | undefined, amount_max?: (number | null) | undefined, amount_preset?: (number | null) | undefined, amount_scheme?: ('custom' | 'fixed') | undefined, currency: string, customer_type?: ('individual' | 'business' | 'both') | undefined, description?: (string | null) | undefined, end_description?: (string | null) | undefined, hosted_page_title?: (string | null) | undefined, hosted_page_description?: (string | null) | undefined, hosted_page_layout?: ('vertical' | 'horizontal') | undefined, image?: (string | null) | undefined, return_url?: (string | null) | undefined, create_invoice?: boolean | undefined, document?: (number | null) | undefined, status?: ('active' | 'archived') | undefined, test_mode?: boolean | undefined, created?: string | undefined, updated?: string | undefined}; export type PatchApiPaymentLinksLinksIdArgs = {body: PaymentLink}; export type PatchApiPaymentLinksLinksIdOptions = {baseUrl?: string | undefined, TokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentLink = z.object({id: z.number().int().optional(), name: z.string().max(56), publishable_key: z.string().optional(), cta: z.enum(["book", "donate", "pay"]).optional(), amount: z.number().nullable().optional(), amount_min: z.number().nullable().optional(), amount_max: z.number().nullable().optional(), amount_preset: z.number().nullable().optional(), amount_scheme: z.enum(["custom", "fixed"]).optional(), currency: z.string(), customer_type: z.enum(["individual", "business", "both"]).optional(), description: z.string().nullable().optional(), end_description: z.string().nullable().optional(), hosted_page_title: z.string().max(32).nullable().optional(), hosted_page_description: z.string().nullable().optional(), hosted_page_layout: z.enum(["vertical", "horizontal"]).optional(), image: z.string().nullable().optional(), return_url: z.string().nullable().optional(), create_invoice: z.boolean().optional(), document: z.number().int().nullable().optional(), status: z.enum(["active", "archived"]).optional(), test_mode: z.boolean().optional(), created: z.string().optional(), updated: 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 }; /** * Partial update payment link * * PATCH /payment_links/links/{id}/ */ export const patchApiPaymentLinksLinksId = async (args: PatchApiPaymentLinksLinksIdArgs, options?: PatchApiPaymentLinksLinksIdOptions) => { const {baseUrl = "https://api.piriod.com", fetch: fetchFn = fetch, TokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (TokenAuth !== undefined) headers.set("Authorization", TokenAuth) const url = `${baseUrl.replace(/\/+$/, '')}/payment_links/links/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(paymentLink, await res.json()) };