Refactor code and simplify billing services
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.
This commit is contained in:
@@ -9,4 +9,10 @@ export const CreateBillingCheckoutSchema = z.object({
|
||||
trialDays: z.number().optional(),
|
||||
customerId: z.string().optional(),
|
||||
customerEmail: z.string().email().optional(),
|
||||
variantQuantities: z.array(
|
||||
z.object({
|
||||
variantId: z.string().min(1),
|
||||
quantity: z.number(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -55,6 +55,12 @@ export async function createLemonSqueezyCheckout(
|
||||
},
|
||||
checkoutData: {
|
||||
email: customerEmail,
|
||||
variantQuantities: params.variantQuantities.map((item) => {
|
||||
return {
|
||||
quantity: item.quantity,
|
||||
variantId: Number(item.variantId),
|
||||
};
|
||||
}),
|
||||
custom: {
|
||||
account_id: params.accountId,
|
||||
},
|
||||
|
||||
@@ -61,9 +61,16 @@ export async function createStripeCheckout(
|
||||
};
|
||||
}
|
||||
|
||||
// if we pass a custom quantity for the item ID
|
||||
// we use that - otherwise we set it to 1 by default
|
||||
const quantity =
|
||||
params.variantQuantities.find((variant) => {
|
||||
return variant.variantId === item.id;
|
||||
})?.quantity ?? 1;
|
||||
|
||||
return {
|
||||
price: item.id,
|
||||
quantity: 1,
|
||||
quantity,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user