cancel
Showing results for 
Search instead for 
Did you mean: 

getting an error with the new accept.js solution

I am trying to test the new accept.js solution. I am copying/pasting the example code. I am just trying to log the results to the console, at this point.

 

However, when I load the page in FF or Chrome, I get the following error:

 

Chrome: Accept.js:1 Uncaught SyntaxError: Invalid or unexpected token

 

FireFox:  SyntaxError: illegal character

 
 
...4>s;s++){var t=q+g.Σ1(n)+g.Ch(n,o,p)+b[s]+r[s],u=g.Σ0(j)+g.Maj(j,k,l);q=p,p=o

 

 

Here is the code from the page I'm testing (of course I put my key/api login):

 

<!DOCTYPE HTML>

<html>

<head>
        <title>Auth.net Accept.js</title>
        <script type="text/javascript" src="https://jstest.authorize.net/v1/Accept.js"></script>
        <script type="text/javascript">
        function sendPaymentDataToAnet() {
        	var secureData = {}, authData = {}, cardData = {};

        	cardData.cardNumber = document.getElementById('CARDNUMBER_ID').value;
	        cardData.month = document.getElementById('EXPIRY_MONTH_ID').value;
	        cardData.year = document.getElementById('EXPIRY_YEAR_ID').value;
        	secureData.cardData = cardData;

        	authData.clientKey = 'my_client_key';
        	authData.apiLoginID = 'my_api_login';
        	secureData.authData = authData;

        	Accept.dispatchData(secureData, 'responseHandler');
                }

        function  responseHandler(response) {
        	if (response.messages.resultCode === 'Error') {
        		for (var i = 0; i < response.messages.message.length; i++) {
        			console.log(response.messages.message[i].code + ':' + response.messages.message[i].text);
        		        }
        		alert('acceptJS library error!');
        	        }
                else {
        		postBackToMyServer(response.opaqueData);
                        console.log(response.opaque.Data);
        	        }
                }
        </script>

</head>

<body>


<form>

CC#: <input type="text" id="CARDNUMBER_ID" />
MM: <input type="text" id="EXPIRY_MONTH_ID" />
YY: <input type="text" id="EXPIRY_YEAR_ID" />
<button type="submit" onclick="sendPaymentDataToAnet()">Pay</button>
</form>


</body>

</html>

Any ideas?

 

Thanks,

 

Joe

joekerns168
Member
1 ACCEPTED SOLUTION

Accepted Solutions

@Aaron wrote:

Hi @JimM,

 

The way the Accept.js script is written, the E_WC_14 error becomes a sort of fallback error for any error condition that's not caught and reported by some other function.

 

In your case, your line

amount.value = document.getElementById('AMOUNT').value;

is failing, because it's looking for an element with ID "AMOUNT", but your form field has the ID "amount". Change one or the other case to match and all should be well. It appears that error comes right from one of our samples, so we'll fix that right away.

 

 

I also noticed you have a "useOpaqueData()" function that's not being called anywhere. Feel free to remove that.

 

 

 


Thank you, Aaron. That did the trick. Can't believe I missed the capitalization issue. I already knew about the extra function from another sample, but forgot to delete it - thanks for pointing that out also. So now my test code works and I can get to work on replacing our AIM integration with this. We are currently using AuthorizeNetAIM.php from the old SDK for processing AuthorizeAndCapture transactions. It looks like I'll need to integrate the code found in transactionCaller.php in the Accept.js GitHub sample to process the payment using the response from Accept.js.

View solution in original post

23 REPLIES 23

Make sure you include the UTF-8 charset meta tag:

 

<meta charset="utf-8">

 

Brian

 

brianmc
Administrator Administrator
Administrator

Utf-8 tag seems to be the solution.


Next, can ayone help with this error:  E_WC_14:Accept.js encryption failed.

All form validation is working so it appears accept.js is loading but error above is coming on submit.

 

 

 

 

earthskater1
Member
Can you post your html/javascript?

Hello,

I'm also getting error  E_WC_14:Accept.js encryption failed.

using https localhost

 

in Chrome, showing this message in the js console on page load:

XMLHttpRequest cannot load https://jstest.authorize.net/v1/AcceptCore.js. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost' is therefore not allowed access.

 

anyone have suggestions ?

 

-thanks

Hi Matt,

 

We have some updates to our documentation page coming today which should help greatly.  Right now I can tell you that the CORS warning "cannot load" is actually correct behaviour in that it's alerting the fact that the page cannot call our core js library only the Accept.js library.  So that will not impact functionality (we are nonetheless looking at ways to stop the browser doing this).

 

On the WC_14 error, we have an error in our sample code, if you make the response handler like this it should work:

 

function responseHandler(response) {
if (response.messages.resultCode === 'Error') {
for (var i = 0; i < response.messages.message.length; i++) {
console.log(response.messages.message[i].code + ':' + response.messages.message[i].text);
$("#blob").val(response.messages.message[i].code + ':' + response.messages.message[i].text);
}
} else {
useOpaqueData(response.opaqueData)
}
}
function useOpaqueData(responseData) {
console.log(responseData.dataDescriptor);
console.log(responseData.dataValue);
alert(responseData.dataValue);
}

 

With sandbox and "https://jstest.authorize.net/v1/Accept.js", getting this error: E_WC_03:Accept.js is not loaded correctly. 

With the same code using sandbox and "https://jstest.authorize.net/v1/Accept.js", most of the times getting error: E_WC_03:Accept.js is not loaded correctly. 

Hi @ali25000, can you post your code or send it to developer@authorize.net?

 

Also, have you looked at our sample app code?  https://github.com/AuthorizeNet/accept-sample-app/blob/master/acceptJSCaller.js   Lines 68 - 93

 

 

Thanks,

 

Brian

One more thing to check is that you haven't downloaded or altered the Authorize.Net javascript libraries.  That would cause E_WC03

 

Brian