Enforce config for billing; updated packages

This commit is contained in:
giancarlo
2024-05-08 21:47:17 +07:00
parent a501bb5444
commit b81cc94800
21 changed files with 393 additions and 252 deletions

View File

@@ -5,6 +5,8 @@ import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
import featureFlagsConfig from '~/config/feature-flags.config';
// billing imports
import {
TeamBillingPortalSchema,
@@ -12,12 +14,22 @@ import {
} from '../schema/team-billing.schema';
import { createTeamBillingService } from './team-billing.service';
/**
* @name enabled
* @description This feature flag is used to enable or disable team account billing.
*/
const enabled = featureFlagsConfig.enableTeamAccountBilling;
/**
* @name createTeamAccountCheckoutSession
* @description Creates a checkout session for a team account.
*/
export const createTeamAccountCheckoutSession = enhanceAction(
(data) => {
if (!enabled) {
throw new Error('Team account billing is not enabled');
}
const client = getSupabaseServerActionClient();
const service = createTeamBillingService(client);
@@ -35,6 +47,10 @@ export const createTeamAccountCheckoutSession = enhanceAction(
*/
export const createBillingPortalSession = enhanceAction(
async (formData: FormData) => {
if (!enabled) {
throw new Error('Team account billing is not enabled');
}
const params = TeamBillingPortalSchema.parse(Object.fromEntries(formData));
const client = getSupabaseServerActionClient();