Refactor billing schema for increased flexibility

The billing schema has been revamped to allow more flexible billing setups, supporting multiple line items per plan. Changes extend to related app and UI components for a seamless experience. As a result, the previously used 'line-items-mapper.ts' is no longer needed and has been removed.
This commit is contained in:
giancarlo
2024-03-30 00:59:06 +08:00
parent 163eff6583
commit f93af31009
18 changed files with 1120 additions and 1213 deletions

View File

@@ -62,7 +62,11 @@ export async function createTeamAccountCheckoutSession(params: {
throw new Error('Product not found');
}
const { lineItems, trialDays } = getLineItemsFromPlanId(product, planId);
const plan = product?.plans.find((plan) => plan.id === planId);
if (!plan) {
throw new Error('Plan not found');
}
// find the customer ID for the account if it exists
// (eg. if the account has been billed before)
@@ -75,12 +79,10 @@ export async function createTeamAccountCheckoutSession(params: {
// call the payment gateway to create the checkout session
const { checkoutToken } = await service.createCheckoutSession({
accountId,
lineItems,
plan,
returnUrl,
customerEmail,
customerId,
trialDays,
paymentType: product.paymentType,
});
// return the checkout token to the client