Update and refactor billing services and types

Several updates and refactorings have been made to the billing services and types. The "onInvoicePaid" method and some types related to line items have been removed. The comments and arguments for the "verifyWebhookSignature" and "handleWebhookEvent" methods in service classes have been updated for clarity. The "onEvent" method's arguments have also been adjusted in multiple places to improve consistency.
This commit is contained in:
gbuomprisco
2024-06-11 23:35:32 +08:00
parent ce18a342ba
commit bb6f26f240
5 changed files with 29 additions and 52 deletions

View File

@@ -58,6 +58,12 @@ export class StripeWebhookHandlerService
return event;
}
/**
* @name handleWebhookEvent
* @description Handle the webhook event from the billing provider
* @param event
* @param params
*/
async handleWebhookEvent(
event: Stripe.Event,
params: {
@@ -70,8 +76,7 @@ export class StripeWebhookHandlerService
onSubscriptionDeleted: (subscriptionId: string) => Promise<unknown>;
onPaymentSucceeded: (sessionId: string) => Promise<unknown>;
onPaymentFailed: (sessionId: string) => Promise<unknown>;
onInvoicePaid: (data: UpsertSubscriptionParams) => Promise<unknown>;
onEvent: (eventType: string) => Promise<unknown>;
onEvent?: (event: Stripe.Event) => Promise<unknown>;
},
) {
switch (event.type) {
@@ -109,7 +114,7 @@ export class StripeWebhookHandlerService
default: {
if (params.onEvent) {
return params.onEvent(event.type);
return params.onEvent(event);
}
const Logger = await getLogger();