#cho_invoice-attempts

1 messages ยท Page 1 of 1 (latest)

wild hollyBOT
#

๐Ÿ‘‹ 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/1224751262373773362

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

compact epochBOT
#

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.

ashen sparrow
#

In a little more detail:

  • our product charges subscription and sells an e-commerce good on subscription every month/quarter.

I create a subscription object of my own in database
Sometimes, the customer's payment fails, and so when the invoice clears I need to invoke a function that will make a subscription object in db.

Therefore I need to distinguish which ones are Failed ones retrying and succeeding

late sable
#

Hello! Generally we recommend listening for the invoice.paid webhook event if you want to be notified of invoice payment succeeding. If you want to know if it's been retried, you can check attempt_count on the Invoice

ashen sparrow
#

so technically if, I get the invoice.paid, it will have "subscription_create" billing_reason and I can check this "attempt_count" > 1 and it should theoretically be it?

late sable
#

Yup

ashen sparrow
#

I guess my ask is do I do attempt_count >1 or >=1 ? As in, if it clears the first time is it 1

#

I just looked at a different charge event and it says "1" on the attempt_count, but I just wanted to confirm

late sable
#

Actually attempt_count may not be the best one to use since it'll only be increased with automatic payment attempts, not manual ones

#

GIve me a minute to find a better option

ashen sparrow
#

I was going to wonder, because atm our customers Do get comms when it fails and we send them the invoice pdf for them to try

#

My customers are automatically charged on their card and that is the most standard way for them to pay.

Alternative methods after failure are: manually paying invoice via pdf / retry

In this case, then would this code be sufficient:

case 'subscription_create':
if (invoicePaid.attempt_count > 1 || ``invoicePaid.collection_method === 'send_invoice') {
console.log('attempt count was greater than 1');
}

#

invoicePaid is the invoice obj

#

oh, this is js

late sable
#

No, I don't think that'll work - a manual payment attempt after initial failure will have attempt_count=1. If you really want to be sure you'd have to list all the charges associated with the Payment Intent to see how many attempts there were, or you could update the Invoice with metadata after the initial failure and then check to see if that metadata is present on future attempts

ashen sparrow
#

hmm, in that case would our original solution work if I disabled sending the customer a pdf copy and asked them to instead, update their default payment method for the subscription and then they did that and the retry succeeded will it have attempt_count = 1

late sable
#

Yes it would still have attempt_count=1

#

So I don't think my original suggestion of relying on attempt_count will work

#

It'll be much safer for you to set your own metadata that you're in control of

ashen sparrow
#

ouch haha

#

then could you help me with what webhook to listen to for the failures

#

I see invoice.finalization_failed is that it?

late sable
#

No, you want invoice.payment_failed

ashen sparrow
#

okay fantastic

#

I will work through with that

#

the metadata idea was ๐Ÿ”ฅ saves our space complexity

#

ty ty

late sable
#

๐Ÿ‘