Update error handling and function calls in billing services

Minor modifications made to the billing service handlers to improve data interpretation and error processing. The 'getLineItemTypeById' function now uses 'item.variant' for more accurate line item type identification. Unnecessary 'Crypto' object instantiation has been removed in 'createHmac', while improved formatting applied to the error logging within the billing webhook.
This commit is contained in:
giancarlo
2024-05-21 20:41:41 +07:00
parent 70f5ff42df
commit a115e37535
3 changed files with 2 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ export const POST = enhanceRouteHandler(
return new Response('OK', { status: 200 });
} catch (error) {
logger.error(ctx, `Failed to process billing webhook`, error);
logger.error({ ...ctx, error }, `Failed to process billing webhook`);
return new Response('Failed to process billing webhook', {
status: 500,

View File

@@ -345,7 +345,7 @@ export class LemonSqueezyWebhookHandlerService
product_id: item.product,
variant_id: item.variant,
price_amount: item.priceAmount,
type: getLineItemTypeById(this.config, item.id),
type: getLineItemTypeById(this.config, item.variant),
};
});

View File

@@ -6,7 +6,6 @@ function bufferToHex(buffer: ArrayBuffer) {
export async function createHmac({ key, data }: { key: string; data: string }) {
const encoder = new TextEncoder();
const crypto = new Crypto();
const encodedKey = encoder.encode(key);
const encodedData = encoder.encode(data);