From 0d026f347674c28b1070431dd30a485e81af3612 Mon Sep 17 00:00:00 2001 From: Mythie Date: Sat, 14 Oct 2023 13:02:36 +1100 Subject: [PATCH] fix: filter out inactive products --- .../ee/server-only/stripe/get-prices-by-interval.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 5dfc3d7ea..f621425cc 100644 --- a/packages/ee/server-only/stripe/get-prices-by-interval.ts +++ b/packages/ee/server-only/stripe/get-prices-by-interval.ts @@ -8,12 +8,21 @@ type PriceWithProduct = Stripe.Price & { product: Stripe.Product }; export type PriceIntervals = Record; export const getPricesByInterval = async () => { - const { data: prices } = await stripe.prices.search({ + let { data: prices } = await stripe.prices.search({ query: `active:'true' type:'recurring'`, expand: ['data.product'], limit: 100, }); + prices = prices.filter((price) => { + // We use `expand` to get the product, but it's not typed as part of the Price type. + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + const product = price.product as Stripe.Product; + + // Filter out prices for products that are not active. + return product.active; + }); + const intervals: PriceIntervals = { day: [], week: [],