cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

how to handle connection error in accept.js?

I am following the tutorial to integrate Accept.js

https://developer.authorize.net/api/reference/features/acceptjs.html

let me get to the point

Here is the form

 

<form id="paymentForm"
    method="POST"
    action="https://YourServer/PathToExistingPaymentProcessingScript" >
    <input type="text" name="cardNumber" id="cardNumber" placeholder="cardNumber"/> <br><br>
    <input type="text" name="expMonth" id="expMonth" placeholder="expMonth"/> <br><br>
    <input type="text" name="expYear" id="expYear" placeholder="expYear"/> <br><br>
    <input type="text" name="cardCode" id="cardCode" placeholder="cardCode"/> <br><br>
    <input type="hidden" name="dataValue" id="dataValue" />
    <input type="hidden" name="dataDescriptor" id="dataDescriptor" />
    <button type="button" onclick="sendPaymentDataToAnet()">Pay</button>
</form>

and here is the function called

 

<script type="text/javascript">
function sendPaymentDataToAnet() {
    var authData = {};
        authData.clientKey = "YOUR PUBLIC CLIENT KEY";
        authData.apiLoginID = "YOUR API LOGIN ID";
    var cardData = {};
        cardData.cardNumber = document.getElementById("cardNumber").value;
        cardData.month = document.getElementById("expMonth").value;
        cardData.year = document.getElementById("expYear").value;
        cardData.cardCode = document.getElementById("cardCode").value;

    // If using banking information instead of card information,
    // build a bankData object instead of a cardData object.
    //
    // var bankData = {};
    //     bankData.accountNumber = document.getElementById('accountNumber').value;
    //     bankData.routingNumber = document.getElementById('routingNumber').value;
    //     bankData.nameOnAccount = document.getElementById('nameOnAccount').value;
    //     bankData.accountType = document.getElementById('accountType').value;

    var secureData = {};
        secureData.authData = authData;
        secureData.cardData = cardData;
        // If using banking information instead of card information,
        // send the bankData object instead of the cardData object.
        //
        // secureData.bankData = bankData;

        Accept.dispatchData(secureData, responseHandler);
}
</script>

Now sometimes there is connection problem and Accept.dispatchData fails. i.e you get connection error in javascript console.

I have tried wrapping the Accept.dispatch code in try catch block but it doesnt catch the exception. So i am wondering how to catch the net connection error when Accept.dispatchData is executing and there is connection problem. I appreciate any help! Thanks!

Here is the connection error i am getting.

 

I cannot upload the image so please check here for the error image. 

 

https://stackoverflow.com/questions/49444998/how-to-handle-connection-error-in-accept-js

kofhearts
Contributor
Who Me Too'd this topic