Failed Transaction Response Validation
An error message appears on your website when a transaction fails, such as the following:
Error message: "We were unable to process your payment. Please verify your card details and try again or contact us to complete your order."
You can configure an error message with different text. For more information, see Configuring Hosted Payment Page Using Methods and Configuring Hosted Payment Page Using Functions.
Add the ClearentOnError
function to your website to detect failed transactions and return a JSON object with the raw and signed server response.
The following sample code includes the raw and JSON-formatted response, along with the error message and transaction ID for a failed transaction:
<script>
// called after failed complete
function ClearentOnError(responseRaw,ResponseJSON)
{
console.log("transaction failed");
console.log(responseRaw);
console.log(ResponseJSON);
// use JS short-circuiting to determine if we have an error message
if(ResponseJSON.payload && ResponseJSON.payload.error && ResponseJSON.payload.error['error-message'])
{
console.log("error = " + ResponseJSON.payload.error['error-message']);
}
else
{
console.log("unable to determine error");
}
// use JS short-circuiting to determine if we have a transaction id
if(ResponseJSON.payload && ResponseJSON.payload.transaction && ResponseJSON.payload.transaction.id)
{
console.log("transaction id = " + ResponseJSON.payload.transaction.id);
}
else
{
console.log("transaction id not found");
}
}
<script/>
You can validate the response for a failed or unsuccessful transaction:
Using an error message: The response object with an error message that is intentionally vague to prevent scammers from using the service to test cards and security codes.
Using the Virtual Terminal: You can search for the transaction ID manually to validate the failed transaction details.
The response does not include transaction information for transactions not attempted due to an invalid or expired public key or an unrecoverable server error.
Last updated
Was this helpful?