In my Typescript application, I have integrated Stripe subscriptions. Let's consider a scenario where a customer is on the monthly plan for $10 with auto-renewal set up. Now, if this customer has an expired card on file and misses payment on the auto-renew date (let's say 5th of January 2024) but updates their card details four days later (9th of Jan), there arises an issue. The current code doesn't update the next invoice date from 5th of February to 9th of February, causing the customer to miss out on 4 days of access even after paying for the full month.
To address this challenge, I made changes to my code by listening to the `invoice.payment_succeeded` webhook and updating the `billing_cycle_anchor` to 'now':
subscription = await this.stripeModule.updateSubscription(subscriptionId, {
billing_cycle_anchor: 'now',
proration_behavior: 'none',
});
While this modification resolves the date issue, it results in the customer being invoiced twice - once for the failed invoice marked as 'Paid' and another for the subscription update generated by Stripe, both charging $10.
My current solution involves issuing a refund for one of the invoices, but I am seeking advice on a more efficient way to prevent double invoicing and avoid the need for refunds. Any suggestions on how to handle this situation would be greatly appreciated.