#pilly_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/1422269744433860730
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Should clarify; I want to save a card to a customer but then simulate it failing specifically for due to expiry, but if there is no card to simulate this then can someone confirm if when this happens the $e->getError()->code is equal to expired_card?
I can't attach an expired card to a customer to test a charge though?
Our elements won't premit it, no
You can update the expiry of a saved payment method but this won't automatically trigger a failure.
This is because banks often permit expired cards to continue charging
Can I actually test that scenario? A saved card on a customer, and then charge it?
I can't edit the expiry to a past date through the dashboard.
I get an API error too? Stripe\Exception\CardException
Your card's expiration month is invalid.
Hi there, I'm taking over from my colleague. Can you provide the request ID for the API error?
You can find the API request ID in the dashboard by navigating to the Logs, or if you have access to network requests, this is found in the response headers as Request-Id [0].
[0] https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_ySIVPC6n8h9mMw
I just read through the thread. Essentially you're looking to simulate the return of expired_card?
Yes
We are saving cards to customers; I need to simulate that so I can test how my app deals with expired cards in our database.
4000000000000341 is just a generic card_declined
Try using 4000000000000069
Elements blocks that so we can't attach it to a customer
Understood. I'm not sure you'll be able to simulate this on attachment to a customer. I'm seeing the error returned when I attempt to confirm a PaymentIntent but this does not include attaching to the customer which makes sense.
Sorry I'm a bit confused, not sure if we're on the same page.
Assume a customer has saved a card to their account; at the time of adding it, it's a valid card that hasn't expired. Several months pass and now the card has expired.
We attempt to charge the card and it fails due to expiry.
This is what I need to simulate.
I'd expect to be able to simulate this, seems like a common scenario? But if we can't, can you confirm how we check for expiry from the CardException that is thrown?
Is it $e->getError()->code === 'expired_card' ?
Have you attempted to simulate this using test clocks? So attach the card, give it a short expiry (10/25), and advance the time to after expiry and attempt to charge the card.
Seems like test clocks are limited to subscriptions?
I can confirm the code is expired_card when an expired card is used to make payment. From my testing:
{
error: {
charge: "ch_3SClA5KStpj00Lbw1YN*****",
code: "expired_card",
decline_code: "expired_card",
doc_url: "https://stripe.com/docs/error-codes/expired-card",
message: "Your card has expired.",
param: "exp_month",
...
The test clock doesn't seem to work? I added a card that expires 09/25, set the simulation time to 2030, and then charged the card with no errors.
So, there's really no way to actually test this?
Can you share the Request ID for this attempt?
I just tested this flow on my end and I'm getting the same results you are.
Let me double check with colleagues.
Ok, unfortunately there isn't a way to test this specific use case. It's worth noting that often times a card that was previously charged may go through successfully even though the card is expired. Also, we work with card networks to automatically update save card details [0].
[0] https://docs.stripe.com/payments/cards/overview#automatic-card-updates
If you need to see how the error is returned, the work around is to use the expired card, do not attach it to a customer and review what is being returned.
Seems insane that we can't test something as simple as charging an expired, saved card ๐
I'll share your feedback here, but the error would be same. Since expired cards can still be charged, it would not be a fully accurate representation