2024-02-06 16:16:10 +11:00
|
|
|
import type { STRIPE_PLAN_TYPE } from '@documenso/lib/constants/billing';
|
|
|
|
|
import { stripe } from '@documenso/lib/server-only/stripe';
|
|
|
|
|
|
2024-02-17 12:42:00 +11:00
|
|
|
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 query = planTypes.map((planType) => `metadata['plan']:'${planType}'`).join(' OR ');
|
|
|
|
|
|
2024-02-06 16:16:10 +11:00
|
|
|
const { data: prices } = await stripe.prices.search({
|
2024-02-17 12:42:00 +11:00
|
|
|
query,
|
2024-02-06 16:16:10 +11:00
|
|
|
expand: ['data.product'],
|
|
|
|
|
limit: 100,
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-17 12:42:00 +11:00
|
|
|
return prices.filter((price) => price.type === 'recurring');
|
2024-02-06 16:16:10 +11:00
|
|
|
};
|