Refactor billing gateway and enhance localization
Refactored the 'plan-picker' component in the billing gateway to remove unwanted line items and improve checkout session and subscription handling. Enhanced the localization support by adding translations in the plan picker and introduced a new function to check trial eligibility so that existing customers can't start a new trial period. These changes enhance the usability of the application across different regions and provide accurate trial period conditions.
This commit is contained in:
@@ -14,16 +14,24 @@ import appConfig from '~/config/app.config';
|
||||
import billingConfig from '~/config/billing.config';
|
||||
import pathsConfig from '~/config/paths.config';
|
||||
|
||||
const CreateCheckoutSchema = z.object({
|
||||
planId: z.string(),
|
||||
productId: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a checkout session for a personal account.
|
||||
*
|
||||
* @param {object} params - The parameters for creating the checkout session.
|
||||
* @param {string} params.planId - The ID of the plan to be associated with the account.
|
||||
*/
|
||||
export async function createPersonalAccountCheckoutSession(params: {
|
||||
planId: string;
|
||||
productId: string;
|
||||
}) {
|
||||
export async function createPersonalAccountCheckoutSession(
|
||||
params: z.infer<typeof CreateCheckoutSchema>,
|
||||
) {
|
||||
// parse the parameters
|
||||
const { planId, productId } = CreateCheckoutSchema.parse(params);
|
||||
|
||||
// get the authenticated user
|
||||
const client = getSupabaseServerActionClient();
|
||||
const { data: user, error } = await requireUser(client);
|
||||
|
||||
@@ -31,13 +39,6 @@ export async function createPersonalAccountCheckoutSession(params: {
|
||||
throw new Error('Authentication required');
|
||||
}
|
||||
|
||||
const { planId, productId } = z
|
||||
.object({
|
||||
planId: z.string().min(1),
|
||||
productId: z.string().min(1),
|
||||
})
|
||||
.parse(params);
|
||||
|
||||
Logger.info(
|
||||
{
|
||||
planId,
|
||||
|
||||
Reference in New Issue
Block a user