Refactor billing system and enhance logging
Updated the billing system's schema to change 'storeId' to a string type, and improved the cleanliness and readability of the code. Enhanced the logging system within the billing service for better tracking and debugging. In line with these changes, added corresponding error pages in the client side to handle any errors.
This commit is contained in:
@@ -9,19 +9,16 @@ import { initializeLemonSqueezyClient } from './lemon-squeezy-sdk';
|
||||
* Creates a LemonSqueezy billing portal session for the given parameters.
|
||||
*
|
||||
* @param {object} params - The parameters required to create the billing portal session.
|
||||
* @return {Promise<string>} - A promise that resolves to the URL of the customer portal.
|
||||
* @throws {Error} - If no customer is found with the given customerId.
|
||||
*/
|
||||
export async function createLemonSqueezyBillingPortalSession(
|
||||
params: z.infer<typeof CreateBillingPortalSessionSchema>,
|
||||
) {
|
||||
await initializeLemonSqueezyClient();
|
||||
|
||||
const customer = await getCustomer(params.customerId);
|
||||
const { data, error } = await getCustomer(params.customerId);
|
||||
|
||||
if (!customer?.data) {
|
||||
throw new Error('No customer found');
|
||||
}
|
||||
|
||||
return customer.data.data.attributes.urls.customer_portal;
|
||||
return {
|
||||
data: data?.data.attributes.urls.customer_portal,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user