Files
myeasycms-v2/apps/web/app/(dashboard)/home/[account]/billing/server-actions.ts
giancarlo 0002ac6255 Refactor billing imports, reorganize package scripts and improve action structure
Deleted unnecessary schema files and reorganized their imports into more logical order. Modified the package script structure to align more accurately with standard conventions. Also refactored the team-billing.service file to improve action structure, making it easier to understand and edit. Furthermore, upgraded various dependencies, reflecting their new versions in the lockfile.
2024-04-07 12:47:29 +08:00

43 lines
1.2 KiB
TypeScript

'use server';
import { redirect } from 'next/navigation';
import { z } from 'zod';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
// billing imports
import {
TeamBillingPortalSchema,
TeamCheckoutSchema,
} from '../_lib/schema/team-billing.schema';
import { TeamBillingService } from '../_lib/server/team-billing.service';
/**
* @name createTeamAccountCheckoutSession
* @description Creates a checkout session for a team account.
*/
export async function createTeamAccountCheckoutSession(
params: z.infer<typeof TeamCheckoutSchema>,
) {
const data = TeamCheckoutSchema.parse(params);
const service = new TeamBillingService(getSupabaseServerActionClient());
return service.createCheckout(data);
}
/**
* @name createBillingPortalSession
* @description Creates a Billing Session Portal and redirects the user to the
* provider's hosted instance
*/
export async function createBillingPortalSession(formData: FormData) {
const params = TeamBillingPortalSchema.parse(Object.fromEntries(formData));
const service = new TeamBillingService(getSupabaseServerActionClient());
// get url to billing portal
const url = await service.createBillingPortalSession(params);
return redirect(url);
}