Code for billing services has been refactored for simplicity and improved organization. This includes updated locations for the 'loadTeamWorkspace' function and adjusted component imports. Redundant scripts have been eliminated and new schemas have been introduced for input data validation.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
'use server';
|
|
|
|
import { redirect } from 'next/navigation';
|
|
|
|
import { z } from 'zod';
|
|
|
|
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
|
|
|
import { TeamBillingPortalSchema } from '~/(dashboard)/home/[account]/_lib/schema/team-billing-portal.schema';
|
|
|
|
import { TeamCheckoutSchema } from '../_lib/schema/team-checkout.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);
|
|
}
|