Add refinement to ensure metered line items have zero cost

The billing schema has been updated to include a refinement that ensures metered line items have a cost of zero. To clarify, a different line item type should be added for a flat fee in Stripe. Additionally, unnecessary verifications and logic regarding item costs have been removed from the PlanPicker and LineItemDetails components.
This commit is contained in:
giancarlo
2024-06-01 17:03:20 +07:00
parent 2c52a06536
commit ced1b4f7e3
3 changed files with 14 additions and 19 deletions

View File

@@ -72,6 +72,20 @@ export const LineItemSchema = z
message: 'Metered line items must have a unit and tiers',
path: ['type', 'unit', 'tiers'],
},
)
.refine(
(data) => {
if (data.type === LineItemType.Metered) {
return data.cost === 0;
}
return true;
},
{
message:
'Metered line items must have a cost of 0. Please add a different line item type for a flat fee (Stripe)',
path: ['type', 'cost'],
},
);
export const PlanSchema = z