Reply
Highlighted
Member
Posts: 1
Registered: ‎02-16-2017

How to load Accept js dynamically based on your environment

[ Edited ]
<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. 

Administrator
Posts: 312
Registered: ‎11-03-2016

Re: How to load Accept js dynamically based on your environment

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

Aaron Wright
Developer Evangelist - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Administrator
Posts: 312
Registered: ‎11-03-2016

Re: How to load Accept js dynamically based on your environment

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

Aaron Wright
Developer Evangelist - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Member
Posts: 1
Registered: ‎03-15-2017

Re: How to load Accept js dynamically based on your environment

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?

Administrator
Posts: 312
Registered: ‎11-03-2016

Re: How to load Accept js dynamically based on your environment

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?

-Aaron

Aaron Wright
Developer Evangelist - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Contributor
Posts: 18
Registered: ‎03-21-2017

Re: How to load Accept js dynamically based on your environment

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.