Skip to content

Commit

Permalink
Fix basic sub
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed May 30, 2024
1 parent 37d2013 commit 760d087
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 0 additions & 2 deletions apps/web/app/(app)/usage/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use server";

import { auth } from "@/app/api/auth/[...nextauth]/auth";
import { getUsage } from "@/utils/redis/usage";
import { TopSection } from "@/components/TopSection";
Expand Down
16 changes: 14 additions & 2 deletions apps/web/app/api/lemon-squeezy/webhook/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ async function subscriptionCreated({
if (!payload.data.attributes.first_subscription_item)
throw new Error("No subscription item");

const tier = getTier({ variantId: payload.data.attributes.variant_id });
const tier = getSubscriptionTier({
variantId: payload.data.attributes.variant_id,
});

const updatedPremium = await upgradeToPremium({
userId,
Expand Down Expand Up @@ -272,12 +274,22 @@ function getEmailFromPremium(premium: {
return premium.users?.[0]?.email;
}

function getTier({ variantId }: { variantId: number }): PremiumTier {
function getSubscriptionTier({
variantId,
}: {
variantId: number;
}): PremiumTier {
switch (variantId) {
case env.NEXT_PUBLIC_BASIC_MONTHLY_VARIANT_ID:
return PremiumTier.BASIC_MONTHLY;
case env.NEXT_PUBLIC_BASIC_ANNUALLY_VARIANT_ID:
return PremiumTier.BASIC_ANNUALLY;

case env.NEXT_PUBLIC_PRO_MONTHLY_VARIANT_ID:
return PremiumTier.PRO_MONTHLY;
case env.NEXT_PUBLIC_PRO_ANNUALLY_VARIANT_ID:
return PremiumTier.PRO_ANNUALLY;

case env.NEXT_PUBLIC_BUSINESS_MONTHLY_VARIANT_ID:
return PremiumTier.BUSINESS_MONTHLY;
case env.NEXT_PUBLIC_BUSINESS_ANNUALLY_VARIANT_ID:
Expand Down

0 comments on commit 760d087

Please sign in to comment.