mirror of
https://github.com/documenso/documenso.git
synced 2025-11-17 10:11:35 +10:00
feat: wip
This commit is contained in:
26
packages/lib/utils/billing.ts
Normal file
26
packages/lib/utils/billing.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { AppError } from '../errors/app-error';
|
||||
import type { Subscription } from '.prisma/client';
|
||||
import { SubscriptionStatus } from '.prisma/client';
|
||||
|
||||
export const isPriceIdCommunityPlan = (priceId: string) =>
|
||||
priceId === process.env.NEXT_PUBLIC_STRIPE_COMMUNITY_PLAN_MONTHLY_PRICE_ID ||
|
||||
priceId === process.env.NEXT_PUBLIC_STRIPE_COMMUNITY_PLAN_YEARLY_PRICE_ID;
|
||||
|
||||
/**
|
||||
* Returns true if there is a subscription that is active and is a community plan.
|
||||
*/
|
||||
export const isSomeSubscriptionsActiveAndCommunityPlan = (subscriptions: Subscription[]) => {
|
||||
return subscriptions.some(
|
||||
(subscription) =>
|
||||
subscription.status === SubscriptionStatus.ACTIVE &&
|
||||
isPriceIdCommunityPlan(subscription.planId),
|
||||
);
|
||||
};
|
||||
|
||||
export const getTeamSeatPriceId = () => {
|
||||
if (!process.env.NEXT_PUBLIC_STRIPE_TEAM_SEAT_PRICE_ID) {
|
||||
throw new AppError('MISSING_STRIPE_TEAM_SEAT_PRICE_ID');
|
||||
}
|
||||
|
||||
return process.env.NEXT_PUBLIC_STRIPE_TEAM_SEAT_PRICE_ID;
|
||||
};
|
||||
Reference in New Issue
Block a user