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

@@ -2,8 +2,6 @@ import 'server-only';
import { cache } from 'react';
import { SupabaseClient } from '@supabase/supabase-js';
import { z } from 'zod';
import { createAccountsApi } from '@kit/accounts/api';

View File

@@ -5,15 +5,27 @@ 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';
import { PersonalAccountCheckoutSchema } from '../schema/personal-account-checkout.schema';
import { createUserBillingService } from './user-billing.service';
/**
* @name enabled
* @description This feature flag is used to enable or disable personal account billing.
*/
const enabled = featureFlagsConfig.enablePersonalAccountBilling;
/**
* @name createPersonalAccountCheckoutSession
* @description Creates a checkout session for a personal account.
*/
export const createPersonalAccountCheckoutSession = enhanceAction(
async function (data) {
if (!enabled) {
throw new Error('Personal account billing is not enabled');
}
const client = getSupabaseServerActionClient();
const service = createUserBillingService(client);
@@ -30,6 +42,10 @@ export const createPersonalAccountCheckoutSession = enhanceAction(
*/
export const createPersonalAccountBillingPortalSession = enhanceAction(
async () => {
if (!enabled) {
throw new Error('Personal account billing is not enabled');
}
const client = getSupabaseServerActionClient();
const service = createUserBillingService(client);