import {z} from 'zod' export type Bill = {id?: string | undefined, business_type?: ('ecommerce' | 'retail' | 'food_and_beverage' | 'events') | undefined, business_category?: string | undefined, customer?: ({contact?: string | undefined, name?: string | undefined, email?: string | undefined, customer_id?: string | undefined, addresses?: Array> | undefined}) | undefined, employee?: ({id?: string | undefined, name?: string | undefined}) | undefined, loyalty?: ({points?: number | undefined, redeemed_points?: number | undefined}) | undefined, store_code?: string | undefined, receipt_timestamp?: number | undefined, receipt_number?: string | undefined, receipt_type?: ('tax_invoice' | 'sales_invoice' | 'bill_of_supply' | 'credit_note' | 'debit_note') | undefined, receipt_delivery?: ('digital' | 'print' | 'digital_and_print') | undefined, tags?: Record | undefined, bar_code_number?: string | undefined, qr_code_number?: string | undefined, billing_pos_number?: string | undefined, pos_category?: string | undefined, order_number?: string | undefined, order_service_type?: ('dine_in' | 'takeaway' | 'delivery') | undefined, delivery_status_url?: string | undefined, line_items?: (Array<{name?: string | undefined, quantity?: number | undefined, unit_amount?: number | undefined, unit?: string | undefined, hsn_code?: string | undefined, product_code?: string | undefined, total_amount?: number | undefined, taxes?: Array> | undefined, sub_items?: Array> | undefined, tags?: Record | undefined}>) | undefined, receipt_summary?: ({total_quantity?: number | undefined, sub_total_amount?: number | undefined, currency?: string | undefined, net_payable_amount?: number | undefined, payment_status?: string | undefined, discounts?: Array> | undefined, taxes?: Array> | undefined}) | undefined, taxes?: Array> | undefined, payments?: (Array<{method?: string | undefined, currency?: string | undefined, amount?: number | undefined, payment_reference_id?: string | undefined, financier_data?: Record | undefined}>) | undefined, event?: Record | undefined, irn?: string | undefined, receipt_url?: string | undefined, created_at?: number | undefined}; export type PatchApiBillsBillIdArgs = {bill_id: string, body: Bill}; export type PatchApiBillsBillIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const bill = z.object({id: z.string().optional(), business_type: z.enum(["ecommerce", "retail", "food_and_beverage", "events"]).optional(), business_category: z.string().optional(), customer: z.object({contact: z.string().optional(), name: z.string().optional(), email: z.string().optional(), customer_id: z.string().optional(), addresses: z.array(z.object({})).optional()}).optional(), employee: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), loyalty: z.object({points: z.number().int().optional(), redeemed_points: z.number().int().optional()}).optional(), store_code: z.string().optional(), receipt_timestamp: z.number().int().optional(), receipt_number: z.string().optional(), receipt_type: z.enum(["tax_invoice", "sales_invoice", "bill_of_supply", "credit_note", "debit_note"]).optional(), receipt_delivery: z.enum(["digital", "print", "digital_and_print"]).optional(), tags: z.object({}).optional(), bar_code_number: z.string().optional(), qr_code_number: z.string().optional(), billing_pos_number: z.string().optional(), pos_category: z.string().optional(), order_number: z.string().optional(), order_service_type: z.enum(["dine_in", "takeaway", "delivery"]).optional(), delivery_status_url: z.string().optional(), line_items: z.array(z.object({name: z.string().optional(), quantity: z.number().optional(), unit_amount: z.number().int().optional(), unit: z.string().optional(), hsn_code: z.string().optional(), product_code: z.string().optional(), total_amount: z.number().int().optional(), taxes: z.array(z.object({})).optional(), sub_items: z.array(z.object({})).optional(), tags: z.object({}).optional()})).optional(), receipt_summary: z.object({total_quantity: z.number().optional(), sub_total_amount: z.number().int().optional(), currency: z.string().optional(), net_payable_amount: z.number().int().optional(), payment_status: z.string().optional(), discounts: z.array(z.object({})).optional(), taxes: z.array(z.object({})).optional()}).optional(), taxes: z.array(z.object({})).optional(), payments: z.array(z.object({method: z.string().optional(), currency: z.string().optional(), amount: z.number().int().optional(), payment_reference_id: z.string().optional(), financier_data: z.object({}).optional()})).optional(), event: z.object({}).optional(), irn: z.string().optional(), receipt_url: z.string().optional(), created_at: z.number().int().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 }; /** * Update a bill * * PATCH /bills/{bill_id} */ export const patchApiBillsBillId = async (args: PatchApiBillsBillIdArgs, options?: PatchApiBillsBillIdOptions) => { const {baseUrl = "https://api.razorpay.com/v1", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/bills/${encodeURIComponent(String(args.bill_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(bill, await res.json()) };