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:
@@ -26,8 +26,7 @@ interface CustomHandlersParams {
|
||||
) => Promise<unknown>;
|
||||
onPaymentSucceeded: (sessionId: string) => Promise<unknown>;
|
||||
onPaymentFailed: (sessionId: string) => Promise<unknown>;
|
||||
onInvoicePaid: (data: UpsertSubscriptionParams) => Promise<unknown>;
|
||||
onEvent?: (event: string, data: unknown) => Promise<unknown>;
|
||||
onEvent?: <Data>(data: Data) => Promise<unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +62,7 @@ class BillingEventHandlerService {
|
||||
*/
|
||||
async handleWebhookEvent(
|
||||
request: Request,
|
||||
params: Partial<CustomHandlersParams> = {},
|
||||
params: Partial<CustomHandlersParams> = {}
|
||||
) {
|
||||
const event = await this.strategy.verifyWebhookSignature(request);
|
||||
|
||||
@@ -274,24 +273,6 @@ class BillingEventHandlerService {
|
||||
|
||||
logger.info(ctx, 'Successfully updated payment status');
|
||||
},
|
||||
onInvoicePaid: async (data) => {
|
||||
const logger = await getLogger();
|
||||
|
||||
const ctx = {
|
||||
namespace: this.namespace,
|
||||
subscriptionId: data.target_subscription_id,
|
||||
};
|
||||
|
||||
logger.info(ctx, 'Processing invoice paid event...');
|
||||
|
||||
// by default we don't need to do anything here
|
||||
// but we allow consumers to provide custom handlers for the event
|
||||
if (params.onInvoicePaid) {
|
||||
await params.onInvoicePaid(data);
|
||||
}
|
||||
|
||||
logger.info(ctx, 'Invoice paid event processed successfully');
|
||||
},
|
||||
onEvent: params.onEvent,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user