cancel
Showing results for 
Search instead for 
Did you mean: 

Accept.js and ACH/echeck integration - E_WC_04: Please provide mandatory field to library.

I believe I have accept.js working for credit card processing, at least that is how it appears in the java console, and I think I am close to having it working for ach/echeck, but I must be missing something.

 

For testing I am loading accept.js like this:

<!-- Authorize.NET libraries -->
<!-- SANDBOX -->
<script type="text/javascript" src="https://jstest.authorize.net/v2/Accept.js" charset="utf-8"></script> <!-- Integrated -->

and then when a user hits our form they can choose to process the transaction with either a credit card or bank account.  Transmitting to Authorize.Net is done using this code:

 

    function sendPaymentDataToAnet() {
                    console.log("sending data start");
        var authData = {};
        authData.clientKey = "xxxyyyyclientkeyishere";
        authData.apiLoginID = "zzzzloginIDishere";

// check for what pay method was selected card or bank and populate appropriately
 var list = document.getElementById("rbnlistPayType"); //Client ID of the radiolist
 var inputs = list.getElementsByTagName("input");
 var selected;

var secureData = {};
    secureData.authData = authData;


for (var i = 0; i < inputs.length; i++) {
      if (inputs[i].checked) {
          selected = inputs[i];
          break;
       }
  }
        if (selected) {
            alert(selected.value.trim());
            if (selected.value.trim() === "Bank Account") {
                alert(selected.value);
                var bankData = {};
                bankData.accountNumber = parseInt(document.getElementById('txtAcctNumber').value);
                bankData.routingNumber = parseInt(document.getElementById('txtRouteNumber').value);
                bankData.nameOnAccount = document.getElementById('txtAcctName').value;
                bankData.accountType = document.getElementById('txtAcctType').value;
                console.log(bankData.accountNumber);
                console.log(bankData.routingNumber);
                console.log(bankData.nameOnAccount);
                console.log(bankData.accountType);
                console.log("sending bank data");
                secureData.bankData = bankData;

            } else {
                alert('Card Data');
                var cardData = {};
                cardData.cardNumber = document.getElementById('tbxCardNumber').value;
                cardData.month = document.getElementById('txtExpMnth').value;
                cardData.year = document.getElementById('txtExpYr').value;
                cardData.cardCode = document.getElementById('txtCVV').value;
                console.log(cardData.cardNumber);
                console.log(cardData.month);
                console.log(cardData.year);
                console.log(cardData.cardCode);
                console.log("sending card data");
                secureData.cardData = cardData;
            }
        }

       // 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.
        
        
        
		Accept.dispatchData(secureData, responseHandler);
    }

    function responseHandler(response) {
        try {
            console.log(response.messages.resultCode);
            if (response.messages.resultCode === "Error") {
                console.log('in error handler')
                var i = 0;
                while (i < response.messages.message.length) {
                    console.log(
                        response.messages.message[i].code + ": " +
                        response.messages.message[i].text
                    );
                    i = i + 1;
                }
            } else
                console.log('normal processing');
                console.log(response.messages.resultCode);
        } catch (error) {
    console.log(error);
  }

}

 When I run the code with a test credit card I get the following in my browser console log:

 

09:08:20.994 sending data start
09:08:24.353 370000000000002
09:08:24.354 11
09:08:24.354 22
09:08:24.354 123
09:08:24.354 sending card data
09:08:25.868 Ok
09:08:25.868 normal processing
09:08:25.868 Ok

 

When I use a bank account I get:

 

09:06:45.783 sending data start
09:06:48.595 1234567890123456
09:06:48.595 273976369
09:06:48.595 Test Test
09:06:48.595 checking
09:06:48.596 sending bank data
09:06:49.597 Error
09:06:49.597 in error handler
09:06:49.597 E_WC_04: Please provide mandatory field to library.
09:06:49.597 Error

 

I'm not sure what mandatory field I am supposed to send. What am I missing? Anyone have any ideas? 

emlinney
Contributor
0 REPLIES 0