From f4b1e5104e3b6c89fc48efea924a0e7dc4b83b7a Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Wed, 4 Dec 2024 15:42:03 +0900 Subject: [PATCH] feat: add platform plan pricing (#1505) Add platform plan to the billing page. --- apps/web/src/app/(dashboard)/settings/billing/page.tsx | 2 +- packages/ee/server-only/stripe/get-prices-by-interval.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/(dashboard)/settings/billing/page.tsx b/apps/web/src/app/(dashboard)/settings/billing/page.tsx index 05be0c6cb..128761589 100644 --- a/apps/web/src/app/(dashboard)/settings/billing/page.tsx +++ b/apps/web/src/app/(dashboard)/settings/billing/page.tsx @@ -41,7 +41,7 @@ export default async function BillingSettingsPage() { const [subscriptions, prices, primaryAccountPlanPrices] = await Promise.all([ getSubscriptionsByUserId({ userId: user.id }), - getPricesByInterval({ plan: STRIPE_PLAN_TYPE.REGULAR }), + getPricesByInterval({ plans: [STRIPE_PLAN_TYPE.REGULAR, STRIPE_PLAN_TYPE.PLATFORM] }), getPrimaryAccountPlanPrices(), ]); diff --git a/packages/ee/server-only/stripe/get-prices-by-interval.ts b/packages/ee/server-only/stripe/get-prices-by-interval.ts index 462e74a1c..41bf88248 100644 --- a/packages/ee/server-only/stripe/get-prices-by-interval.ts +++ b/packages/ee/server-only/stripe/get-prices-by-interval.ts @@ -12,10 +12,10 @@ export type GetPricesByIntervalOptions = { /** * Filter products by their meta 'plan' attribute. */ - plan?: STRIPE_PLAN_TYPE.COMMUNITY | STRIPE_PLAN_TYPE.REGULAR; + plans?: STRIPE_PLAN_TYPE[]; }; -export const getPricesByInterval = async ({ plan }: GetPricesByIntervalOptions = {}) => { +export const getPricesByInterval = async ({ plans }: GetPricesByIntervalOptions = {}) => { let { data: prices } = await stripe.prices.search({ query: `active:'true' type:'recurring'`, expand: ['data.product'], @@ -27,7 +27,8 @@ export const getPricesByInterval = async ({ plan }: GetPricesByIntervalOptions = // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const product = price.product as Stripe.Product; - const filter = !plan || product.metadata?.plan === plan; + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + const filter = !plans || plans.includes(product.metadata?.plan as STRIPE_PLAN_TYPE); // Filter out prices for products that are not active. return product.active && filter;