#antonio-giano_best-practices

1 messages ¡ Page 1 of 1 (latest)

hearty scrollBOT
#

👋 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.

quartz knollBOT
#

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.

rich shard
#

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.

ancient berry
#

I took a look

rich shard
#

Let us know if that does not solve your ask after taking a look

ancient berry
#

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.

rich shard
ancient berry
#

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.

rich shard
#

Are you saying that you want to cancel a subscription after the subsequent invoice payment fails?

ancient berry
#

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.

rich shard
ancient berry
#

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?

rich shard
#

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'?

ancient berry
ancient berry
rich shard
#

yes, that is right. The invoice is finalized, it is waiting for a new payment method

ancient berry
rich shard
#

I do not understand the follow up question, can you reword this please?

ancient berry
#

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?

rich shard
ancient berry
#

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