mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 01:32:06 +10:00
fix: filter out inactive products
This commit is contained in:
@ -8,12 +8,21 @@ type PriceWithProduct = Stripe.Price & { product: Stripe.Product };
|
|||||||
export type PriceIntervals = Record<Stripe.Price.Recurring.Interval, PriceWithProduct[]>;
|
export type PriceIntervals = Record<Stripe.Price.Recurring.Interval, PriceWithProduct[]>;
|
||||||
|
|
||||||
export const getPricesByInterval = async () => {
|
export const getPricesByInterval = async () => {
|
||||||
const { data: prices } = await stripe.prices.search({
|
let { data: prices } = await stripe.prices.search({
|
||||||
query: `active:'true' type:'recurring'`,
|
query: `active:'true' type:'recurring'`,
|
||||||
expand: ['data.product'],
|
expand: ['data.product'],
|
||||||
limit: 100,
|
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 = {
|
const intervals: PriceIntervals = {
|
||||||
day: [],
|
day: [],
|
||||||
week: [],
|
week: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user