import {z} from 'zod' export type ChannelEnum = 'WEBSITE' | 'WOOCOMMERCE' | 'SHOPIFY' | 'WORDPRESS' | 'BUBBLE' | 'MOBILE'; 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 BitcoinTarrifEnum = 'BUSINESS-PAYS' | 'CUSTOMER-PAYS'; export type AchTarrifEnum = 'BUSINESS-PAYS' | 'CUSTOMER-PAYS'; export type BankTarrifEnum = 'BUSINESS-PAYS' | 'CUSTOMER-PAYS'; export type CheckoutSer = {id: string, url: string, signature: string, methods: string, layout: string, styles: string, merchant_name: string, merchant_id: string, merchant_origin: string, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, phone_number?: (string | null) | undefined, email?: (string | null) | undefined, country?: (string | null) | undefined, address?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zipcode?: (string | null) | undefined, api_ref?: (string | null) | undefined, wallet_id?: (string | null) | undefined, method?: ('M-PESA' | 'PESALINK' | 'CARD-PAYMENT' | 'GOOGLE-PAY' | 'APPLE-PAY' | 'BITCOIN' | 'BANK-ACH' | 'COOP_B2B' | '' | unknown | null) | undefined, channel?: ChannelEnum | undefined, host?: (string | null) | undefined, is_mobile?: boolean | undefined, version: string | null, redirect_url?: (string | null) | undefined, amount?: unknown | undefined, currency?: CurrencyEnum | undefined, paid: boolean, mobile_tarrif?: MobileTarrifEnum | undefined, card_tarrif?: CardTarrifEnum | undefined, bitcoin_tarrif?: BitcoinTarrifEnum | undefined, ach_tarrif?: AchTarrifEnum | undefined, bank_tarrif?: BankTarrifEnum | undefined, created_at: string | null, updated_at: string | null}; export type SentStatusEnum = 'PENDING' | 'SENT' | 'DELIVERED' | 'OPENED' | 'CLICKED' | 'FAILED'; export type AutosendRemiderEnum = 0 | 1 | 2 | 3 | 7; export type PayRequestsSer = {request_id: string, checkout: CheckoutSer, sent_status?: SentStatusEnum | undefined, reason: string, autosend_remider?: AutosendRemiderEnum | undefined, autosend_remider_datetime?: (string | null) | undefined, reminder_sent?: boolean | undefined, archived?: boolean | undefined, failed_details?: (string | null) | undefined, created_at: string | null, updated_at: string | null}; export type CreateApiApiV1PaymentRequestsIdArchiveArgs = {id: string, body: PayRequestsSer}; export type CreateApiApiV1PaymentRequestsIdArchiveOptions = {baseUrl?: string | undefined, IntaSendBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const channelEnum = z.enum(["WEBSITE", "WOOCOMMERCE", "SHOPIFY", "WORDPRESS", "BUBBLE", "MOBILE"]); 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 bitcoinTarrifEnum = z.enum(["BUSINESS-PAYS", "CUSTOMER-PAYS"]); export const achTarrifEnum = z.enum(["BUSINESS-PAYS", "CUSTOMER-PAYS"]); export const bankTarrifEnum = z.enum(["BUSINESS-PAYS", "CUSTOMER-PAYS"]); export const checkoutSer = z.object({id: z.string(), url: z.string(), signature: z.string(), methods: z.string(), layout: z.string(), styles: z.string(), merchant_name: z.string(), merchant_id: z.string(), merchant_origin: z.string(), first_name: z.string().max(45).nullable().optional(), last_name: z.string().max(45).nullable().optional(), phone_number: z.string().max(30).nullable().optional(), email: z.string().max(254).nullable().optional(), country: z.string().max(2).nullable().optional(), address: z.string().max(140).nullable().optional(), city: z.string().max(70).nullable().optional(), state: z.string().max(70).nullable().optional(), zipcode: z.string().max(10).nullable().optional(), api_ref: z.string().max(140).nullable().optional(), wallet_id: z.string().max(10).nullable().optional(), method: z.union([z.enum(["M-PESA", "PESALINK", "CARD-PAYMENT", "GOOGLE-PAY", "APPLE-PAY", "BITCOIN", "BANK-ACH", "COOP_B2B"]), z.literal(""), z.unknown()]).nullable().optional(), channel: channelEnum.optional(), host: z.string().max(400).nullable().optional(), is_mobile: z.boolean().optional(), version: z.string().nullable(), redirect_url: z.string().max(400).nullable().optional(), amount: z.string().optional(), currency: currencyEnum.optional(), paid: z.boolean(), mobile_tarrif: mobileTarrifEnum.optional(), card_tarrif: cardTarrifEnum.optional(), bitcoin_tarrif: bitcoinTarrifEnum.optional(), ach_tarrif: achTarrifEnum.optional(), bank_tarrif: bankTarrifEnum.optional(), created_at: z.string().nullable(), updated_at: z.string().nullable()}); export const sentStatusEnum = z.enum(["PENDING", "SENT", "DELIVERED", "OPENED", "CLICKED", "FAILED"]); export const autosendRemiderEnum = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(7)]); export const payRequestsSer = z.object({request_id: z.string(), checkout: checkoutSer, sent_status: sentStatusEnum.optional(), reason: z.string().max(140), autosend_remider: autosendRemiderEnum.optional(), autosend_remider_datetime: z.string().nullable().optional(), reminder_sent: z.boolean().optional(), archived: z.boolean().optional(), failed_details: z.string().nullable().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 }; /** * Create Payment requests archive * * POST /api/v1/payment-requests/{id}/archive/ */ export const createApiApiV1PaymentRequestsIdArchive = async (args: CreateApiApiV1PaymentRequestsIdArchiveArgs, options?: CreateApiApiV1PaymentRequestsIdArchiveOptions) => { 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/payment-requests/${encodeURIComponent(String(args.id))}/archive/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(payRequestsSer, await res.json()) };