Page 1 of 1

Cannot handle Stripe API's legitimate card declined response

Posted: Mon Jun 18, 2018 2:57 pm
by Fivable
Hello,

We are transacting with the Stripe API through REST modules, and when a call to charge a card receives what is a legitimate (though non-200) response the IVR system errors out without allowing the opportunity for us to handle the response (as far as we can tell). This does not happen with Authorize.net because they return their card declined message as a 2xx response and we are able to handle it and forward to customer service. Is there any way to accomplish this with such a response from Stripe? The response we get for a declined card is below.

Thanks for your time,
Fivable

-----
(This is a 402 HTTP status response)
Server: nginx
Date: Mon, 18 Jun 2018 19:10:42 GMT
Content-Type: application/json
Content-Length: 259
Connection: keep-alive
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
Access-Control-Max-Age: 300
Cache-Control: no-cache, no-store
Request-Id: req_T78ZJxMFecRu7m
Stripe-Version: 2016-07-06

Response
Raw
{
"error": {
"charge": "ch_D4byCRFgbj8n3g",
"code": "card_declined",
"decline_code": "generic_decline",
"doc_url": "https://stripe.com/docs/error-codes/card-declined",
"message": "Your card was declined.",
"type": "card_error"
}
}

Re: Cannot handle Stripe API's legitimate card declined resp

Posted: Tue Jun 19, 2018 11:29 am
by admin
In the REST module, you should turn on custom errors. You can do this by clicking on the gear icon on the upper-right of the REST module. This will catch every sort of error, even non 2xx responses. From there, you can handle the error as you wish.

REST modules also have some shadow variables you may find handy. You can use [rest_module$.http_code] to access the HTTP code of the response.

Re: Cannot handle Stripe API's legitimate card declined resp

Posted: Tue Jun 19, 2018 1:22 pm
by Fivable
Thanks!

Re: Cannot handle Stripe API's legitimate card declined resp

Posted: Tue Jun 19, 2018 2:03 pm
by Fivable
Also I'm now wondering if there is a way to set a default path for any custom errors that are unhandled.

Re: Cannot handle Stripe API's legitimate card declined resp

Posted: Wed Jun 20, 2018 10:27 am
by admin
A standard practice is to create a page in your application dedicated to handling webservice errors. Typically it plays a message like "I'm sorry, we are having technical difficulties," then either prompts the user to try their call again later, or transfers them to customer service.

Then for all your REST modules, you would connect the error path to a Go To Page module that jumps to that dedicated page.