From a02f597f578501b61b489e3127c907eb2de374b1 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Sat, 30 Mar 2024 15:02:30 +0800 Subject: [PATCH] Update billing card display and server actions The code changes update the way the billing details are fetched and displayed in the system. In the billing card component, the baseLineItem price is replaced with the cost. For the server actions, getLineItemsFromPlanId is replaced with getProductPlanPair to fetch the product plan more efficiently. The change reduces unnecessary details, simplifying the code and possibly speeding up the operation. --- .../app/(dashboard)/home/(user)/billing/server-actions.ts | 8 +++----- .../billing-gateway/src/components/current-plan-card.tsx | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/web/app/(dashboard)/home/(user)/billing/server-actions.ts b/apps/web/app/(dashboard)/home/(user)/billing/server-actions.ts index 3d552fb0d..96443a083 100644 --- a/apps/web/app/(dashboard)/home/(user)/billing/server-actions.ts +++ b/apps/web/app/(dashboard)/home/(user)/billing/server-actions.ts @@ -4,7 +4,7 @@ import { redirect } from 'next/navigation'; import { z } from 'zod'; -import { getLineItemsFromPlanId } from '@kit/billing'; +import { getProductPlanPair } from '@kit/billing'; import { getBillingGatewayProvider } from '@kit/billing-gateway'; import { Logger } from '@kit/shared/logger'; import { requireUser } from '@kit/supabase/require-user'; @@ -65,17 +65,15 @@ export async function createPersonalAccountCheckoutSession(params: { throw new Error('Product not found'); } - const { lineItems, trialDays } = getLineItemsFromPlanId(product, planId); + const { plan } = getProductPlanPair(billingConfig, planId); // call the payment gateway to create the checkout session const { checkoutToken } = await service.createCheckoutSession({ - lineItems, returnUrl, accountId, - trialDays, - paymentType: product.paymentType, customerEmail: user.email, customerId, + plan, }); Logger.info( diff --git a/packages/billing-gateway/src/components/current-plan-card.tsx b/packages/billing-gateway/src/components/current-plan-card.tsx index a1384f3b6..a76560430 100644 --- a/packages/billing-gateway/src/components/current-plan-card.tsx +++ b/packages/billing-gateway/src/components/current-plan-card.tsx @@ -67,7 +67,7 @@ export function CurrentPlanCard({ i18nKey="billing:planRenewal" values={{ interval: subscription.interval, - price: formatCurrency(product.currency, baseLineItem.price), + price: formatCurrency(product.currency, baseLineItem.cost), }} />