Files
cfw-autumn/shared/utils/cusEntUtils/convertCusEntUtils/cusEntToStripeIds.ts
John Yeo 07340cd79b wip
2025-12-16 13:05:57 +00:00

27 lines
862 B
TypeScript

import { InternalError } from "../../../api/errors/base/InternalError";
import type { FullCusEntWithFullCusProduct } from "../../../models/cusProductModels/cusEntModels/cusEntWithProduct";
import { cusEntToCusPrice } from "../../productUtils/convertUtils";
export const cusEntToStripeIds = ({
cusEnt,
}: {
cusEnt: FullCusEntWithFullCusProduct;
}) => {
const cusPrice = cusEntToCusPrice({ cusEnt });
if (!cusPrice) {
throw new InternalError({
message: `[cusEntToStripeIds] No cus price found for cus ent (feature: ${cusEnt.entitlement.feature_id})`,
});
}
const stripePriceId = cusPrice.price.config.stripe_price_id;
const stripeProductId =
cusPrice.price.config.stripe_product_id ||
cusEnt.customer_product.product.processor?.id;
return {
stripePriceId: stripePriceId ?? undefined,
stripeProductId: stripeProductId ?? undefined,
};
};