Add handling for paid invoices in billing services

In response to paid invoices, a new callback method has been introduced in the billing services. This feature includes changes in billing-webhook-handler.service.ts, lemon-squeezy-webhook-handler.service.ts, and other related files. The new method fetches and handles paid invoice information from Stripe and LemonSqueezy subscriptions.
This commit is contained in:
gbuomprisco
2024-06-20 00:02:25 +08:00
parent 73c721557f
commit 95fa8fb7c6
5 changed files with 205 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ interface CustomHandlersParams {
) => Promise<unknown>;
onPaymentSucceeded: (sessionId: string) => Promise<unknown>;
onPaymentFailed: (sessionId: string) => Promise<unknown>;
onInvoicePaid: (subscription: UpsertSubscriptionParams) => Promise<unknown>;
onEvent(event: unknown): Promise<unknown>;
}
@@ -62,7 +63,7 @@ class BillingEventHandlerService {
*/
async handleWebhookEvent(
request: Request,
params: Partial<CustomHandlersParams> = {}
params: Partial<CustomHandlersParams> = {},
) {
const event = await this.strategy.verifyWebhookSignature(request);
@@ -273,6 +274,11 @@ class BillingEventHandlerService {
logger.info(ctx, 'Successfully updated payment status');
},
onInvoicePaid: async (payload) => {
if (params.onInvoicePaid) {
return params.onInvoicePaid(payload);
}
},
onEvent: params.onEvent,
});
}