mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-11 07:26:39 +00:00
26 lines
764 B
TypeScript
26 lines
764 B
TypeScript
import Stripe from "stripe";
|
|
import { FeatureId, FeaturePriceSet } from "./features";
|
|
import { usageService } from "./usageService";
|
|
|
|
export async function getLineItems(
|
|
featurePriceSet: FeaturePriceSet,
|
|
orgId: string,
|
|
): Promise<Stripe.Checkout.SessionCreateParams.LineItem[]> {
|
|
const users = await usageService.getUsage(orgId, FeatureId.USERS);
|
|
|
|
return Object.entries(featurePriceSet).map(([featureId, priceId]) => {
|
|
let quantity: number | undefined;
|
|
|
|
if (featureId === FeatureId.USERS) {
|
|
quantity = users?.instantaneousValue || 1;
|
|
} else if (featureId === FeatureId.TIER1) {
|
|
quantity = 1;
|
|
}
|
|
|
|
return {
|
|
price: priceId,
|
|
quantity: quantity
|
|
};
|
|
});
|
|
}
|