According to stripe's dashboard (test mode), customer's next subscription invoice should have been created on April 28th at 5AM but it's April 29th today and the invoice has not been created yet and when I am trying to update the customer's subscription with stripe api for node js, I get the following error :
StripeInvalidRequestError: The subscription is currently invoicing and thus cannot be updated.
Then I tried to force to create an invoice but got the following error :
StripeInvalidRequestError: Nothing to invoice for customer
I have not Idea why stripe doesn't want to create this invoice and I don't know how I can force it to be created.
Any idea ?
When an invoice is created, Stripe will send an invoice.created event and wait for a successful webhook response to finalize and attempt to pay the invoice.
If the Stripe doesn't receive a successful webhook response, it will wait for 72 hours before finalizing the invoice. This is a long delay that you want to avoid.
You might want to check if your webhook endpoint and see if it's responding to invoice.created events quickly.
Related
My use-case is that whenever I have a trial subscription, once the trial ends and the user has no payment method on stripe, I simply want to cancel the subscription instead of generating an invoice. Is there a way to configure this on Stripe or would it need an external task to run each day and do this for me?
A new invoice will always be generated when a payment is due, and Stripe will try to charge the customer for it. If you want to avoid it, you will need to check if the customer has a PaymentMethod on the last day of the trial, and update the Subscription to set the cancel_at_period_end property to true.
Alternatively, you can listen to customer.subscription.updated webhook event - when the status changes from trialing to active and the customer does not have a PaymentMethod, you can cancel the Subscription manually. In this case, however, a draft Invoice will still be created, but automatic collection will be stopped - the invoice will stay as a draft and will never be finalized.
I'm new to stripe webhooks. My application runs with user subsctipns. I got the user successfully use strie to activate their subscription plan monthly. now all i want is when ever stripe chargers the user with a monthly subscription, I want to update my database with the next payment date.
Ex: If user was charged on 27th July and the next payment date would be 27th Aug, I want to update my database with the customer's next payment date and send the user the notification regarding the same, as. you have been charged by your monthly subscription o plan(on 27th July) and your next payment date would next month(27 Aug).
I have an idea of how can i send user notifications but the problem I'm facing is the stripe is not updated by the database. I have used webhooks to get the notifications and update method but am unable to do so.
If anyone could guide me with this,
Thanks
To be notified when customers pay an invoice, you can listen to the webhook event invoice.payment_succeeded. In the payload you will get an invoice object, which has a subscription property.
If you retrieve that subscription, then you can find the current_period_end property to know when the next invoice will be created.
I am creating a subscription from a Stripe checkout session. After a customer goes through the checkout session, an invoice is then created and triggers invoice.created. On this event, I have a webhook that is attempting to update the invoice, however, by the time it gets here, the invoice is already set to finalized and I cannot update it.
How do I get around this?
I contacted Stripe support and their recommendation (for our situation) is to give the subscription a trial period and then set the trial end to a few minutes from that point in time so that the invoice can go through each event properly.
I am using stripe for a subscription based project and recently found out that you can subscribe without the user requiring payment information with a trial period.
How does stripe handle the user once the trial period ends but didn't any payment information?
When I look at customers it says that there isn't any default source.
At the end of the trial period, the Subscription would renew its billing cycle. This would make the Subscription move to status: "active" and send customer.subscription.updated. A new Invoice would also be created. This would send the invoice.created event.
An hour or two later, the Invoice would be automatically finalized and Stripe would attempt to pay it. The payment would fail since the Customer has no payment method attached. This would send an invoice.payment_failed event. The Invoice would be retried multiple times as documented here. Stripe can even send emails to your Customer asking them to add/update their card.
If all payment retries fail, the Subscription would then be canceled automatically.
What event should my webhook look for in order to update a customer's subscription in my database? I would assume customer.subscription.updated as it contains the current_period_start and current_period_end items. However, my concern is that customer.subscription.updated is apparently fired an hour or so before invoice.payment_succeeded is fired. I wouldn't want to update a customer's subscription if the payment then failed an hour later.
As duck stated in his/her comment, I think the best way to update a subscription if the payment of the invoice failed or succeeded is to listen to these events:
invoice.payment_succeeded: Occurs whenever an invoice payment attempt succeeds.
invoice.payment_failed: Occurs whenever an invoice payment attempt fails, due either to a declined payment or to the lack of a stored payment method.
Actually this is the way I handle things in production, and it is very effective. I would recommend the Stripe documentation's article Billing Lifecycle and Events, especially the section The subscription lifecycle:
After this first invoice, the following cycle of events repeats every
billing period:
When the subscription approaches its renewal date, an invoice.upcoming event is sent.
When the subscription period elapses, an invoice.created event is sent, indicating the creation of a draft invoice.
About an hour after the invoice is created, it is finalized (changes are no longer permitted), and an invoice.finalized event is
sent. A charge is attempted, and a charge.succeeded event is sent to
indicate that the payment was successful.
An invoice.payment_succeeded event is sent to indicate that the invoice was marked paid.