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."

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.

An error message is generic and shown to the customers for security purposes. In case you have questions about any error, log the exchange ID from the received failed response and send it to us.

The exchange ID may appear in the following format: ID-5ba9fd2f10ea-59988-1441133412260-0-1343.

Last updated

Was this helpful?