UNPKG

@vulog/aima-billing

Version:

Invoice management, credits, wallets, and refunds.

38 lines (31 loc) 1.07 kB
import { Client } from '@vulog/aima-client'; import { z } from 'zod'; interface Payload { invoiceId: string; amount?: number; note?: string | null; paymentIntentPspReference?: string; } const schema = z.object({ amount: z.number().min(0).optional(), note: z.string().trim().nullable().optional(), paymentIntentPspReference: z.string().trim().min(1).optional(), }); export const refund = async (client: Client, payload: Payload): Promise<void> => { const result = schema.safeParse(payload); if (!result.success) { throw new TypeError('Invalid args', { cause: result.error.issues, }); } const filteredData = Object.fromEntries( Object.entries(result.data).filter(([_, value]) => value !== undefined && value !== null) ); return client .post<void>( `/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${payload.invoiceId}/refund`, // filter boolean fields filteredData ) .then(({ data }) => data); };