Add custom handlers for billing events

The code introduces custom handlers for different billing events like subscription deletion, subscription update, checkout session completion, payment successes and failures, invoice payment,  and a generic event handler. These customer handlers allow consumers to add their own custom behaviors when certain billing events occur. This flexibility can be utilized to better adapt the system to various business requirements and rules. Also, the invoice payment event and a generic event handler were added.
This commit is contained in:
giancarlo
2024-04-16 11:55:43 +08:00
parent 761c5d6080
commit ebb8fc08fe
5 changed files with 150 additions and 19 deletions

View File

@@ -36,9 +36,15 @@ export abstract class BillingWebhookHandlerService {
// one-time payments
onPaymentSucceeded: (sessionId: string) => Promise<unknown>;
// this method is called when an invoice is paid. This is used for
onInvoicePaid: (data: UpsertSubscriptionParams) => Promise<unknown>;
// this method is called when a payment is failed. This is used for
// one-time payments
onPaymentFailed: (sessionId: string) => Promise<unknown>;
// generic handler for any event
onEvent?: (event: string, data: unknown) => Promise<unknown>;
},
): Promise<unknown>;
}