From 255c33cdab17f9049cea8655bb4c58f19ef627cc Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 28 Feb 2025 09:04:25 +1100 Subject: [PATCH] fix: stripe price fetch (#1677) Currently Stripe prices search is omitting a price for an unknown reason. Changed our fetch logic to use `list` instead of `search` allows us to work around the issue. It's unknown on the performance impact of using `list` vs `search` --- packages/ee/server-only/stripe/get-prices-by-plan.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/ee/server-only/stripe/get-prices-by-plan.ts b/packages/ee/server-only/stripe/get-prices-by-plan.ts index 45906d54a..52c9d1e5e 100644 --- a/packages/ee/server-only/stripe/get-prices-by-plan.ts +++ b/packages/ee/server-only/stripe/get-prices-by-plan.ts @@ -4,15 +4,14 @@ import { stripe } from '@documenso/lib/server-only/stripe'; type PlanType = (typeof STRIPE_PLAN_TYPE)[keyof typeof STRIPE_PLAN_TYPE]; export const getPricesByPlan = async (plan: PlanType | PlanType[]) => { - const planTypes = typeof plan === 'string' ? [plan] : plan; + const planTypes: string[] = typeof plan === 'string' ? [plan] : plan; - const query = planTypes.map((planType) => `metadata['plan']:'${planType}'`).join(' OR '); - - const { data: prices } = await stripe.prices.search({ - query, + const prices = await stripe.prices.list({ expand: ['data.product'], limit: 100, }); - return prices.filter((price) => price.type === 'recurring'); + return prices.data.filter( + (price) => price.type === 'recurring' && planTypes.includes(price.metadata.plan), + ); };