diff --git a/api/src/billing/billing.controller.ts b/api/src/billing/billing.controller.ts index 289c918..cb5a0a8 100644 --- a/api/src/billing/billing.controller.ts +++ b/api/src/billing/billing.controller.ts @@ -19,6 +19,13 @@ export class BillingController { return this.billingService.getPlans() } + + @Get('current-plan') + @UseGuards(AuthGuard) + async getCurrentPlan(@Request() req: any) { + return this.billingService.getCurrentPlan(req.user) + } + @Post('checkout') @UseGuards(AuthGuard) async getCheckoutUrl( diff --git a/api/src/billing/billing.service.ts b/api/src/billing/billing.service.ts index 19807e3..e81836b 100644 --- a/api/src/billing/billing.service.ts +++ b/api/src/billing/billing.service.ts @@ -70,6 +70,25 @@ export class BillingService { }) } + async getCurrentPlan(user: any) { + const subscription = await this.subscriptionModel.findOne({ + user: user._id, + isActive: true, + }) + + + + let plan = null + + if (!subscription) { + plan = await this.planModel.findOne({ name: 'free' }) + } else { + plan = await this.planModel.findById(subscription.plan) + } + + return plan + } + async getCheckoutUrl({ user, payload, @@ -105,10 +124,8 @@ export class BillingService { customerEmail: user.email, customerName: user.name, customerIpAddress: req.ip, - customerId: user._id?.toString(), metadata: { userId: user._id?.toString(), - customerId: user._id?.toString(), }, } const discount = await this.polarApi.discounts.get({ diff --git a/web/app/(app)/dashboard/(components)/account-settings.tsx b/web/app/(app)/dashboard/(components)/account-settings.tsx index 4c832bb..686717d 100644 --- a/web/app/(app)/dashboard/(components)/account-settings.tsx +++ b/web/app/(app)/dashboard/(components)/account-settings.tsx @@ -27,6 +27,7 @@ import { UserCircle, Loader2, Check, + Calendar, } from 'lucide-react' import { useForm } from 'react-hook-form' import { z } from 'zod' @@ -195,6 +196,106 @@ export default function AccountSettings() { }, }) + const CurrentPlan = () => { + + const { + data: currentPlan, + isLoading: isLoadingPlan, + error: planError, + } = useQuery({ + queryKey: ['currentPlan'], + queryFn: () => + httpBrowserClient + .get(ApiEndpoints.billing.currentPlan()) + .then((res) => res.data), + }) + + + if (isLoadingPlan) return
+ Failed to load plan information +
+ ) + + return ( ++ Current subscription +
+Next Payment
++ {currentPlan?.nextPaymentDate ?? '-:-'} +
+Quota
++ {currentPlan?.quota} +
+Daily
+{currentPlan?.dailyLimit}
+Monthly
+{currentPlan?.monthlyLimit}
+Bulk
+{currentPlan?.bulkSendLimit}
+