import {z} from 'zod' export type CurrencyEnum = 'KES' | 'GHS' | 'NGN' | 'UGX' | 'TZS' | 'XAF' | 'XOF'; export type MobileTarrifEnum = 'BUSINESS-PAYS' | 'CUSTOMER-PAYS'; export type CardTarrifEnum = 'BUSINESS-PAYS' | 'CUSTOMER-PAYS'; export type PaymentLinksSer = {id?: string | undefined, title: string, is_active?: boolean | undefined, redirect_url?: (string | null) | undefined, amount?: number | undefined, usage_limit?: number | undefined, qrcode_file: string | null, url: string, currency?: CurrencyEnum | undefined, mobile_tarrif?: MobileTarrifEnum | undefined, card_tarrif?: CardTarrifEnum | undefined, created_at: string | null, updated_at: string | null}; export type UpdateApiApiV1PaymentlinksIdArgs = {id: string, body: PaymentLinksSer}; export type UpdateApiApiV1PaymentlinksIdOptions = {baseUrl?: string | undefined, IntaSendBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const currencyEnum = z.enum(["KES", "GHS", "NGN", "UGX", "TZS", "XAF", "XOF"]); export const mobileTarrifEnum = z.enum(["BUSINESS-PAYS", "CUSTOMER-PAYS"]); export const cardTarrifEnum = z.enum(["BUSINESS-PAYS", "CUSTOMER-PAYS"]); export const paymentLinksSer = z.object({id: z.string().optional(), title: z.string().max(140), is_active: z.boolean().optional(), redirect_url: z.string().max(400).nullable().optional(), amount: z.number().int().gte(0).optional(), usage_limit: z.number().int().gte(0).optional(), qrcode_file: z.string().nullable(), url: z.string(), currency: currencyEnum.optional(), mobile_tarrif: mobileTarrifEnum.optional(), card_tarrif: cardTarrifEnum.optional(), created_at: z.string().nullable(), updated_at: z.string().nullable()}); 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 }; /** * Update Paymentlinks * * PUT /api/v1/paymentlinks/{id}/ */ export const updateApiApiV1PaymentlinksId = async (args: UpdateApiApiV1PaymentlinksIdArgs, options?: UpdateApiApiV1PaymentlinksIdOptions) => { const {baseUrl = "https://api.intasend.com", fetch: fetchFn = fetch, IntaSendBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (IntaSendBearerAuth !== undefined) headers.set('authorization', `Bearer ${IntaSendBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/paymentlinks/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(paymentLinksSer, await res.json()) };