-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix client import, move checkUserHasMonthlySubscription from universa…
…l to server function (#4890)
- Loading branch information
Showing
3 changed files
with
46 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { Session } from "next-auth"; | ||
import { getBillingAndSubscriptions } from "../../../utils/fxa"; | ||
|
||
/* c8 ignore start */ | ||
export async function checkUserHasMonthlySubscription(user: Session["user"]) { | ||
if (!user.subscriber?.fxa_access_token) { | ||
console.error("FXA token not set"); | ||
return false; | ||
} | ||
|
||
if (!process.env.PREMIUM_PLAN_ID_MONTHLY_US) { | ||
console.error("Monthly Plan ID not set"); | ||
return false; | ||
} | ||
|
||
const billingAndSubscriptionInfo = await getBillingAndSubscriptions( | ||
user.subscriber.fxa_access_token, | ||
); | ||
|
||
if (billingAndSubscriptionInfo === null) { | ||
return false; | ||
} | ||
|
||
const monthlyPlanId = process.env.PREMIUM_PLAN_ID_MONTHLY_US; | ||
const yearlyPlanId = process.env.PREMIUM_PLAN_ID_YEARLY_US ?? ""; | ||
|
||
const subscriptions = billingAndSubscriptionInfo.subscriptions; | ||
|
||
const planIds: string[] = []; | ||
subscriptions.forEach((subscription) => { | ||
planIds.push(subscription.plan_id); | ||
}); | ||
|
||
if (planIds.includes(yearlyPlanId)) { | ||
console.error("User has yearly plan set"); | ||
return false; | ||
} | ||
|
||
return planIds.includes(monthlyPlanId); | ||
} | ||
/* c8 ignore stop */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters