From dd795be893faac732aebf6d268c6fc4390e21403 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sun, 1 Jun 2025 19:45:30 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/lib/billing/upsert-stripe-pricing.ts | 10 ---------- packages/platform/src/validate-pricing.ts | 11 +++++------ packages/types/src/pricing.ts | 2 +- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/apps/api/src/lib/billing/upsert-stripe-pricing.ts b/apps/api/src/lib/billing/upsert-stripe-pricing.ts index 13b73420..96d3a722 100644 --- a/apps/api/src/lib/billing/upsert-stripe-pricing.ts +++ b/apps/api/src/lib/billing/upsert-stripe-pricing.ts @@ -182,11 +182,6 @@ export async function upsertStripePricing({ 400, `Invalid pricing plan metric "${pricingPlanLineItemSlug}" for pricing plan "${pricingPlanSlug}": tiered billing schemes must have at least one tier.` ) - assert( - !pricingPlanLineItem.transformQuantity, - 400, - `Invalid pricing plan metric "${pricingPlanLineItemSlug}" for pricing plan "${pricingPlanSlug}": tiered billing schemes cannot have transformQuantity.` - ) priceParams.tiers_mode = pricingPlanLineItem.tiersMode priceParams.tiers = pricingPlanLineItem.tiers.map((tierData) => { @@ -215,11 +210,6 @@ export async function upsertStripePricing({ 400, `Invalid pricing plan metric "${pricingPlanLineItemSlug}" for pricing plan "${pricingPlanSlug}": unitAmount is required for per_unit billing schemes.` ) - assert( - !(pricingPlanLineItem as any).tiers, - 400, - `Invalid pricing plan metric "${pricingPlanLineItemSlug}" for pricing plan "${pricingPlanSlug}": per_unit billing schemes cannot have tiers.` - ) priceParams.unit_amount_decimal = pricingPlanLineItem.unitAmount.toFixed(12) diff --git a/packages/platform/src/validate-pricing.ts b/packages/platform/src/validate-pricing.ts index 23dcf1c9..8665aaf6 100644 --- a/packages/platform/src/validate-pricing.ts +++ b/packages/platform/src/validate-pricing.ts @@ -170,12 +170,11 @@ export function validatePricing({ `Invalid PricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must specify a valid "tiersMode" when using "tiered" billing scheme.` ) - // TODO: Not sure if this is a valid requirement or not. If it is, update - // the corresponding type in the schemas package. - // assert( - // lineItem.transformQuantity === undefined, - // `Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "transformQuantity" when using "tiered" billing scheme.` - // ) + // TODO: Not sure if this is a valid requirement or not. + assert( + (lineItem as any).transformQuantity === undefined, + `Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "transformQuantity" when using "tiered" billing scheme.` + ) break default: diff --git a/packages/types/src/pricing.ts b/packages/types/src/pricing.ts index 9a3ede84..dfa7a20c 100644 --- a/packages/types/src/pricing.ts +++ b/packages/types/src/pricing.ts @@ -225,7 +225,7 @@ export const pricingPlanMeteredLineItemSchema = * * This field requires `billingScheme` to be set to `tiered`. */ - tiers: z.array(pricingPlanTierSchema).optional(), + tiers: z.array(pricingPlanTierSchema).nonempty().optional(), // TODO: add support for tiered rate limits?