#artdudejoe

1 messages ยท Page 1 of 1 (latest)

grim shardBOT
rapid walrus
#

Hi ๐Ÿ‘‹ my understanding is that you can't do that because it's not how the flow works. You need to reference the error object rather than the instance of Stripe.

Is there a reason you were hoping to be able to handle that differently?

crystal sand
#

Hi @rapid walrus. Yes, I am trying to give my customers better feedback and the instances of errors are a bit complex where the response JSON looks simple enough.

#

I have two errors that come up. resource_missing and card declines. the catch method for distinguishing them is eluding me.

rapid walrus
# crystal sand I have two errors that come up. resource_missing and card declines. the catch me...

Those should be two different types of errors, with resource_missing being an InvalidRequestException (I believe) and card declines being of the type CardException.

Are you starting from our sample code that is shown here?
https://stripe.com/docs/api/errors/handling

crystal sand
#

That's where I am starting, yes

#

So, your response is indicative of my frustration. Is it InvalidRequestException? Or something else? I can see from the logs that the JSON response clearly states the issue.

#

Or is it ApiErrorException?

rapid walrus
#

Can you share the ID of the request that is returning the error?

crystal sand
#

Here is one that is on a live Connect account req_me1EedBdpDrhe2

rapid walrus
#

Thank you, InvalidRequestException is what you're looking for regarding that one.

Have you tried adding a logging line to each of the catch statements that we provide to see which one catches each error you're encountering?

crystal sand
#

Yep.

#

I will work with InvalidRequestException for that one.

#

Here is an evt_ in Test Mode that is a decline. This event is not catch/caught by any of the error handling methods but the JSON clearly states last_payment_error->message that it was declined. Do I need to add another layer to confirm success by parsing the JSON?

#

evt_3MlucWCzypCT1CCI1IcRtyIW

rapid walrus
#

Events are distinct from error messages. Errors are provided in response to requests, Events must be listened for by a Webhook Endpoint.
https://stripe.com/docs/webhooks

This is the request that was made to confirm the associated Payment Intent, which returned the error. Are you working on a server-driven terminal integration?

grim shardBOT
crystal sand
#

Yes, server-driven terminal integration.

#

I used the amount $30.01 to make the test mode decline the payment.

rapid walrus
#

Gotcha, in that case you will want to either use webhook events or poll the API to determine whether a payment was successful, more on those options can be found here:
https://stripe.com/docs/terminal/payments/collect-payment?terminal-sdk-platform=server-driven#verify-reader

You can't listen for errors directly, because those are being returned to the reader that is making the request rather than to your server.

Prepare your application and backend to collect payments using Stripe Terminal.

crystal sand
#

Yeah. I poll Stripe by retrieving the PI looking but I look for status when I need to look at last_payment_error->code and last_payment_error->message to see if it was declined? There's no catch statement that definitively confirms success or failure?

rapid walrus
#

No, you cannot use catch here because the request is being made by our code that is running on the reader, not by the code running on your server.

You look at the status field to determine what state the Payment Intent is currently in and whether the payment method was captured successfully, if you want to pull more information than that from the intent then you can read from additional fields.

crystal sand
#

Looks like my webhook / poll needs to do the catch portion just to make sure I get connected and my request is well formed but to fully confirm that the payment went through I need to parse out some additional things. Combine catch with JSON parse.

#

Is CardException going to work in this case

daring gazelle
#

๐Ÿ‘‹ stepping in here

#

Catching up

crystal sand
#

Hi @daring gazelle

daring gazelle
#

Gotcha so sounds like it has already been explained above that you are going to mostly rely on the reader state or use PaymentIntent webhooks here to get the error info you need

#

Yes CardException should work for those types of errors

crystal sand
#

Yes. And if CardException works I don't need to do a bunch of parsing to confirm -- but it shouldn't hurt to double check the status of the payment with a little extra layer of assurance?

daring gazelle
#

Yep

#

That's what I'd do

crystal sand
#

Got it. Thanks for the clarifications.