Update subscription cancellation logic
The previous implementation attempted to cancel a subscription without checking its status. This commit adds a check to see if the subscription is already cancelled before attempting to cancel it, avoiding unnecessary cancellation requests. This improves the efficiency and reliability of the subscription management process.
This commit is contained in:
@@ -23,7 +23,14 @@ class BillingWebhooksService {
|
||||
async handleSubscriptionDeletedWebhook(subscription: Subscription) {
|
||||
const gateway = createBillingGatewayService(subscription.billing_provider);
|
||||
|
||||
await gateway.cancelSubscription({
|
||||
const subscriptionData = await gateway.getSubscription(subscription.id);
|
||||
const isCanceled = subscriptionData.status === 'canceled';
|
||||
|
||||
if (isCanceled) {
|
||||
return;
|
||||
}
|
||||
|
||||
return gateway.cancelSubscription({
|
||||
subscriptionId: subscription.id,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user