Testing API Purchase Transaction with a Decline/Failed credit card
The API docs have a dedicated sections for Response Codes that include several HTTP status codes -e.g. 401, 402, 404, etc., and in all cases the response body is a json like this:
{
"errors": [
{
"key": "errors.access_denied",
"message": "Unable to authenticate using the given environment_key and access_token. Please check your credentials."
}
]
}
When testing a Purchase transaction using the token of a retained payment method associated with one of the testing credit card numbers in your docs -e.g Visa 4012888888881881, the response we get has an HTTP status 422, but instead of the json with an array of errors like the example above, we get a json with a transaction as one would normally get when the Purchase transaction succeeded, except that the status, etc. say it failed.
We would expect the response to be HTTP 200, and then extract the success/failure from the transaction json.
The questions is: how do we know when HTTP status codes that reflect problems -e.g. 400, 401, etc., have a response that is an array of errors or has a transaction response ?
Thanks !
-
Hi Fernando,
We already responded via email, but we thought we would include our response here as well in case others come across the same question:
The short answer is you should be prepared to receive both.
For the most part, an array of error messages will be returned if the error occurs before Spreedly has a chance to send the request to the gateway. Otherwise, the transaction JSON response (`state`) and transcript should be used to determine the status of a transaction.
Please sign in to leave a comment.
Comments
1 comment