Files
cfw-autumn/shared/models/cusModels/invoiceModels/invoiceModels.ts
Ayush Rodrigues 4256a3d860 Store invoice amount_paid to fix refund status when credits applied
Invoice credits reduce the charged amount below the invoice total,
causing refunds to show as "Partially Refunded" even when fully refunded.
Store Stripe's amount_paid alongside total and use it for refund status
comparisons in the dashboard.

Made-with: Cursor
2026-04-16 14:45:12 +01:00

53 lines
1.4 KiB
TypeScript

import { z } from "zod/v4";
export enum InvoiceStatus {
Draft = "draft",
Open = "open",
Void = "void",
Paid = "paid",
Uncollectible = "uncollectible",
}
export const InvoiceDiscountSchema = z.object({
stripe_coupon_id: z.string(), // Stripe ID
coupon_name: z.string(),
amount_off: z.number(),
amount_used: z.number(),
});
export const InvoiceItemSchema = z.object({
price_id: z.string().nullish(),
stripe_id: z.string(),
internal_feature_id: z.string().nullable(),
description: z.string(),
period_start: z.number(),
period_end: z.number(),
});
export const InvoiceSchema = z.object({
id: z.string(),
created_at: z.number(),
internal_customer_id: z.string(),
internal_entity_id: z.string().nullable(),
product_ids: z.array(z.string()),
internal_product_ids: z.array(z.string()),
// Stripe fields
stripe_id: z.string(),
status: z.nativeEnum(InvoiceStatus).nullable().optional(),
hosted_invoice_url: z.string().nullable(),
// Total amount of the invoice
total: z.number(),
amount_paid: z.number().nullish(),
refunded_amount: z.number().default(0),
currency: z.string(),
receipt_url: z.string().nullish(),
discounts: z.array(InvoiceDiscountSchema),
items: z.array(InvoiceItemSchema),
});
export type Invoice = z.infer<typeof InvoiceSchema>;
export type InvoiceDiscount = z.infer<typeof InvoiceDiscountSchema>;
export type InvoiceItem = z.infer<typeof InvoiceItemSchema>;