#paulo-lacerda_code

1 messages ¡ Page 1 of 1 (latest)

austere creekBOT
#

👋 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/1403041636799479929

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

zinc dome
#

Hi there

#

Yes there is a 10 attempt limit for PaymentIntents before they cancel.

heady gorge
#

is that configurable somehow? or maybe is it 10 times in a specific period? I ask that because it's actually failing after way more than 10 times

#

we are running this code once every day for every past due invoice that is at least one day older, so for this case: pi_3RiM9NGF9ZPA9WP50ACCWXbd, we were trying two different cards once a day for 14 days and then it got canceled

#

and besides that, I'm trying to understand how I can get the reason the payment failed, because this catch in the real code actually has a log, but I don't see it being triggered until the payment got canceled, so the payment.paid was returning false without throwing an error

zinc dome
#

It is not configurable, no.

#

Overall you shouldn't be spamming retries like that. It makes your account look like it is doing card testing.

heady gorge
#

that makes sense, we are trying to improve this retry logic, that's why I'm trying to understand how I should get the reason the payment failed so I can stop trying the card in case it returned certain errors

#

and we are also going to try less times, we are just trying to get the right number

zinc dome
#

There should be a decline_code and message present.

#

You are saying you aren't seeing that?

heady gorge
#

I'm not, at least not for the last payment intent I sent you

#

in my logs I don't see the error log until jul 23rd

zinc dome
#

Cna you send me the specific request you are referencing?

#

Ah sorry yeah I was looking at a different PaymentIntent

#

To be clear, are you looking for the error specific to the automatic retries or your manual retries?

heady gorge
#

my manual retries

#

this is the actual code in production:
for (const pm of otherCardsOnFile) {
try {
if (attempts + initialOttoPaymentAttempts >= 21) {
logger.info(
'Reached maximum number of payment attempts (21), stopping.',
{
careEnrollmentPaymentId,
totalAttempts: attempts + initialOttoPaymentAttempts,
}
);
break;
}
attempts++;
logger.info('Attempting to pay invoice with alternate payment method.', {
careEnrollmentPaymentId,
paymentMethodId: pm.id,
});
const payment = await stripe.invoices.pay(
careEnrollmentPayment.stripeInvoice!.stripeId,
{
payment_method: pm.id,
}
);
if (payment.paid) {
logger.info(
'Successfully paid invoice with alternate payment method.',
{
careEnrollmentPaymentId,
paymentMethodId: pm.id,
}
);
paid = true;
break;
}
} catch (error: any) {
if (error instanceof InvoiceAlreadyPaidError) {
logger.info('Invoice has already been paid.', {
careEnrollmentPaymentId,
});
break;
}
logger.error('Failed to pay invoice with alternate payment method.', {
careEnrollmentPaymentId,
paymentMethodId: pm.id,
error,
});
}

#

for july 22 I see the "Attempting to pay invoice with alternate payment method" and nothing else

#

so it wasn't paid, which makes sense, but I also don't see the logger.error

#

for july 23 I do see the logger.error, and the error message is this: "This PaymentIntent's payment_method could not be updated because it has a status of canceled. You may only update the payment_method of a PaymentIntent with one of the following statuses: requires_payment_method, requires_confirmation, requires_action."

zinc dome
heady gorge
#

is it possible that the stripe sdk I'm using is handling this error in a different way instead of throwing it?

#

because the request returns the boolean paid, so I guess there are situations where the payment isn't successful but it doesn't throw an error

#

and all the logged errors I have are either the one I sent you or "This invoice can no longer be paid. Consider voiding, marking as uncollectible, or marking as paid out of band instead."

#

another theory is that maybe for those other errors the way I'm logging them it's making the log method not work for some reason

zinc dome
#

Hmm yeah let me look. I didn't think we handled the /pay endpoint any differently and it should be catching errors just fine here...

heady gorge
#

ok, thanks, if it helps this is sdk version we are using: "stripe": "17.7.0",

zinc dome
#

While I'm looking, have you tested this in test mode?

#

Like using that same code but also adding a log for payment after calling /pay

heady gorge
#

I tested now using the "Decline after attaching" test card in a blank project and it does go to the catch

zinc dome
#

Hmm yeah okay that is what I would expect

heady gorge
#

I'm starting to think that maybe it is a problem with the error object and the library we use for logging

#

and for some reson for those decline errors I can't see the log

#

but it is weird that it works for when the invoice is not collectable anymore

zinc dome
#

Yeah I might try to simplify some of your logging in that case.

heady gorge
#

I'll do that

#

so the only last thing that I'm still wondering is if the limit is supposed to be 10 before canceling the intent/invoice, why did it only canceled after more than 20 attempts

zinc dome
#

You are talking about pi_3RiM9NGF9ZPA9WP50ACCWXbd ?

heady gorge
#

yes

zinc dome
#

Hmm okay when I look in the Dashboard for that PaymentIntent it does just show 10 attempts.

#

Or 10 declines rather

heady gorge
#

yes, I see that, but we are trying since jul 8

zinc dome
#

But I do see that there were more than 10 attempted payments

#

Ah okay the limit for you is actually 30

#

That's why

#

There is some dynamism with the limit based on account size I believe.

heady gorge
#

ok, good to know

#

do you know if this is fixed or if it can change?

#

considering the account size won't change

zinc dome
#

As far as I know it won't change. But you could reach out to our Support team via https://support.stripe.com/contact/login for more information about those limits and to see if it can be raised any further.

heady gorge
#

ok, thank you

#

you helped me a lot!

#

great job

zinc dome
#

Happy to help!