#pilly_best-practices

1 messages ยท Page 1 of 1 (latest)

kind auroraBOT
#

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

shadow dew
#

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?

jaunty elm
#

Hi ๐Ÿ‘‹

We document how to achive this here

kind auroraBOT
shadow dew
#

I can't attach an expired card to a customer to test a charge though?

jaunty elm
#

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

shadow dew
#

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.

jaunty elm
#

You will need to use the API for that

#

Our dashboard will not allow it

shadow dew
#

I get an API error too? Stripe\Exception\CardException

Your card's expiration month is invalid.

fallen pewter
shadow dew
#

req_ySIVPC6n8h9mMw

fallen pewter
#

I just read through the thread. Essentially you're looking to simulate the return of expired_card?

shadow dew
#

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

fallen pewter
#

Try using 4000000000000069

shadow dew
#

Elements blocks that so we can't attach it to a customer

fallen pewter
#

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.

shadow dew
#

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

fallen pewter
#

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.

shadow dew
#

Seems like test clocks are limited to subscriptions?

fallen pewter
shadow dew
#

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?

fallen pewter
#

Can you share the Request ID for this attempt?

shadow dew
#

req_WrZ5xW4VsJUOYt

#

The test clock request is req_4W0EuNGiGzFojP

fallen pewter
#

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

kind auroraBOT
fallen pewter
#

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.

shadow dew
#

Seems insane that we can't test something as simple as charging an expired, saved card ๐Ÿ˜•

last granite
#

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

kind auroraBOT