cancel
Showing results for 
Search instead for 
Did you mean: 

How to load Accept js dynamically based on your environment

<head>  
<script type="text/javascript" src="https://jstest.authorize.net/v1/Accept.js" charset="utf-8"></script>

</head>

 Works, however hard coding this is a really bad practice (just think if someone left the jstest url and deployed to prod!), and my Aurelia app has the ability to check which environment I'm in. So here's what I did 

 

<head>
</head

app.js:

addAuthNetScriptTag() {
let element = document.createElement('script')
element.charset = 'utf-8'
if (environment.debug || environment.testing) {
element.src = 'https://jstest.authorize.net/v1/Accept.js'
} else {
element.src = 'https://js.authorize.net/v1/Accept.js'
}

document.querySelector('head').appendChild(element)
}

^^^ This code puts the correct tag in the <head> element, but when I call Accept.dispatchData(), it returns the error code E_WC_14:Accept.js encryption failed. Surley there must be some way to switch CDN's based on environment. 

Coletrane
Member
5 REPLIES 5

Hi @Coletrane,

 

I'm afraid that's a known issue with Accept.js for now. "Lazy loading", conditional loading, or anything causing the Accept.js script to be loaded after the page load will cause problems. The good news is that the fix has been made on our end, and it's just winding its way through the release process. Expect an announcement of its availability soon.

Aaron
All Star

Just a heads up for anyone watching this thread that we've released code in sandbox that fixes the lazy loading issue and more issues brought up here, and this code should make it into the production environment within the next couple of days.

 

Specifically for Accept.js, there's no longer any "Access-Control-Allow-Origin" related error in the console, the accept.js script can now be loaded at any point in the workflow, and the response handler function can be passed directly in the function call instead of having to pass the name.

 

Of course, please let us know if anything's not working as expected!

Aaron, I am still getting the E_WC_14:Accept.js encryption failed error. I am including the accept.js script reference by hardcoding it on top of my file. The rest of the script is copied from your code samples. I can't beet this error no matter what I do. I read several posts claiming that with the recent new release, this error has been resolved.

 

Is still happens for me, though. Any suggestions?

Hi @msorokinecc1,

 

It sounds like in your case the error must be caused by something else.

 

Can you post the entire code you're using so that we can see if there's anything different going on there?

Hi All,

I am also facing this issue after hardcoding this script url in my script tag.

 

All code has been copied from the accept.js integration guid only.

Please help me.

 

 

raviparmarce88
Regular Contributor