#paulo-lacerda_code
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/1403041636799479929
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
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
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.
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
When you call the /pay endpoint you should see the error in the response, ex: https://dashboard.stripe.com/logs/req_NKOh39oxveIEjQ
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
There should be a decline_code and message present.
You are saying you aren't seeing that?
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
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?
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."
Hmm yeah that's strange because I do see two errors on July 22nd: https://dashboard.stripe.com/logs/req_hhctjxDVpZdv1n and https://dashboard.stripe.com/logs/req_i4zlyzfSwVK3SR
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
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...
ok, thanks, if it helps this is sdk version we are using: "stripe": "17.7.0",
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
I tested now using the "Decline after attaching" test card in a blank project and it does go to the catch
Hmm yeah okay that is what I would expect
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
Yeah I might try to simplify some of your logging in that case.
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
You are talking about pi_3RiM9NGF9ZPA9WP50ACCWXbd ?
yes
Hmm okay when I look in the Dashboard for that PaymentIntent it does just show 10 attempts.
Or 10 declines rather
yes, I see that, but we are trying since jul 8
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.
ok, good to know
do you know if this is fixed or if it can change?
considering the account size won't change
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.
Happy to help!