#antonio-giano_best-practices
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1227022076272054303
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- antonio-giano_code, 3 days ago, 18 messages
- antonio-giano_unexpected, 3 days ago, 19 messages
- antonio-giano_best-practices, 4 days ago, 17 messages
- antonio-giano_best-practices, 4 days ago, 9 messages
Hi, it sounds like you're trying to distinguish between an initial payment of a Subscriptions vs. a recurring payment. If that is the case, listening to invoice event is what you should continue doing. You would look at the billing_reason:subscription_create when it's the initial payment. Invoices created by recurring subscriptions will show subscription_cycle , https://docs.stripe.com/api/invoices/object#invoice_object-billing_reason. Let me know if that is not what you're asking.
I took a look
Let us know if that does not solve your ask after taking a look
I have had a look and it would appear that it deals better with the highlighted case. However, how can I deal with the case where the payment fails? To give an example: let us assume the case where the subscription is in its second month and the customer has to make the payment. The payment does not go through, so I have to handle this case on the back-end to run my own logic. Having a look at the link you sent me, the subscription_cycle event does not specifically handle such a case.
If you're trying to identify how to distinguish failed payments, you can listen to invoice.payment_failed: https://docs.stripe.com/api/events/types#event_types-invoice.payment_failed. You can also use Stripe sutomatic payment retry: https://docs.stripe.com/billing/revenue-recovery/smart-retries.
I handled this event in case the payment fails. However, my intention is to handle the specific case that the payment of the next invoice does not go through, so the subscription remains on hold. So I wonder if there is a specific event for the latter case?
Again taking an example from before, the payment for the next invoice does not take place because there are no funds available. So the subscription remains on hold. Does this case exist?
I say this, as I need to distinguish such cases since in my web-app I have provided for the customer account to be deleted when the initial payment fails, as opposed to subsequent invoices where the customer account remains but with a different logic handled
Because the invoice.payment_failed event will certainly be issued for the next invoice if the payment fails. However, there would be some mess in the back-end to make the distinction.
Are you saying that you want to cancel a subscription after the subsequent invoice payment fails?
No. Basically, I would like to put the subscription on hold until the second invoice is paid so that the customer can use the services.
I don't know if I have given an idea of the logic I would like to implement. Taking another example, we can refer to Netflix, on how on the failed attempt, it prompts the customer via a UI/UX interface to update the payment method.
If you want to hold the subscription, that would have to come from your end. When a payment fails, the status of the subscription on Stripe is in past_due https://docs.stripe.com/billing/subscriptions/overview#subscription-statuses. Once it's in a past due status, you can use Customer Portal, https://docs.stripe.com/customer-management for instance to ask for payment method details and they can manage their Subscription on there.
If I understand correctly, the change of subscription status to expired is done automatically. So, if the customer wants to take advantage of the subscription, he has to provide the information of the new payment method. Once this is done, the function stripe.invoices.finalizeInvoice is used to finalise the last invoice. Right?
I wonder if there is a related event. By chance, it is as follows: customer.subscription.deleted?
No, the invoice is already finalized. You would use the new payment method details to attempt to pay that failed invoice.
Can you clarify what you mean with 'I wonder if there is a related event. By chance, it is as follows: customer.subscription.deleted'?
What do you mean it is already finalised? Perhaps you mean that the invoice is realised but is waiting for the customer to finalise payment before the invoice can be considered paid, right?
I mentioned that event as an example because I would like to handle the logic in my back-end when the subscription expires.
Giving an example, at the moment when the subscription expires, I have to handle that event in my back-end to perform my own operations.
yes, that is right. The invoice is finalized, it is waiting for a new payment method
I think adding your own operation after getting invoice.payment_failed would be better as you would already know if it's failure from a recurring payment: https://docs.stripe.com/api/invoices/object#invoice_object-billing_reason
May I ask on what basis you would know if the payment is the one that is being made? From some field contained within the event object?
I do not understand the follow up question, can you reword this please?
You mentioned the fact that you know what the failure is due to, i.e. a recurrent payment. To that end, I asked how is it possible to know this? If it is a recurrent payment or a single payment?
You would look at the billing_reason:subscription_create when it's the initial payment. Invoices created by recurring subscriptions will show subscription_cycle , https://docs.stripe.com/api/invoices/object#invoice_object-billing_reason
OK, I will take a closer look at the guides you recommended. In case I have any more questions on that, I will make another thread.
in the meantime, thank you for your availability