Reply
New 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. 

Highlighted
Developer
Posts: 143
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!