cancel
Showing results for 
Search instead for 
Did you mean: 

Accept.js error E_WC_14:Accept.js encryption failed.

Hello

what this error means (E_WC_14:Accept.js encryption failed) and how to solve it?

Thank you

zamiksica123
Contributor
42 REPLIES 42

It says here: 

 

http://developer.authorize.net/api/reference/features/acceptjs.html

 

That thje error  "XMLHttpRequest cannot load ... bla bla" is normal, and that it happens on localhost. Still not clue about the E_WC_14 ! 

 

Come to think about it, you guys should return more technical error descriptions, it's not like we're scared users, not knowing what to do when a fancy word comes up - we are developing integrations right ? 

 

Side note, I do not understand why on earth is it so difficult to come with a stable .js library. I have been implementing tens of integrations with numerous gateways, and 90% is the JavaScript approach. However, none of them throw so much errors. In fact most of them work from the 1st time. Point being that Authorize.NET developers certainly are not the first ones making this kind of wheel. 

 

 

 

 

Hello

I've reported this issue to the product team for analysis.

I'd recommend subscribing to this topic so that you'll be alerted via email if there are updates. To subscribe, click Topic Options at the top of this thread and then select Subscribe. You'll then receive an email once anyone replies to your post.

Thanks,

Richard

Hello,

 

The product team is asking how you are loading accept.js?

 

• By including the script tag and as described in documentation

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

• Or Dynamically loading the script after page load?

 

Richard

Hi,

 

I am loading it like this: 

 

 

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

But it is a One Page Checkout, so the Payment form is loaded with ajax at one step. So in the loaded HTML, I have the above script tag, and I also have an inline javascript section, where I have the following code: 

 

<script type="text/javascript">
    $(document).ready(function () {
        GetScriptCallback();
    });

    function sendPaymentDataToAnet() {
        var secureData = {}, authData = {}, cardData = {};

        cardData.cardNumber = document.getElementById('@ViewBag.FormInputIds[1]').value;
        cardData.month = document.getElementById('@ViewBag.FormInputIds[2]').value;
        cardData.year = document.getElementById('@ViewBag.FormInputIds[3]').value;
        cardData.fullName = document.getElementById('@ViewBag.FormInputIds[0]').value;
        cardData.cardCode = document.getElementById('@ViewBag.FormInputIds[4]').value;

        secureData.cardData = cardData;

        authData.clientKey = "@ViewBag.PublicClientKey";
        authData.apiLoginID = "@ViewBag.ApiLogin";
        secureData.authData = authData;

        console.log(secureData);
        console.log(Accept);

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

    function createTokenCallback(response) {

        if (response.messages.resultCode === 'Error') {
            $(".payment-errors").text("");
            var errorMessages = [];
            for (var i = 0; i < response.messages.message.length; i++) {
                errorMessages.push(response.messages.message[i].code + ':' + response.messages.message[i].text);
            }

            $(".payment-errors").append(errorMessages.join("<br />"));
            $(".payment-info-next-step-button").removeAttr("disabled");

        } else {
            var token = response.opaqueData.dataValue;

            $(".payment-errors").text("");
            var form = $(".payment-info-next-step-button").closest('form');

            $("#paymenttoken").val(token);
            //if (document.location.href.indexOf('onepagecheckout') > -1) {
            //    PaymentInfo.save();
            //}
            //else {
            //    form.submit();
            //}
        }
    }

    function GetScriptCallback() {
        $(".payment-info-next-step-button").removeAttr("onClick");
        $(".payment-info-next-step-button").unbind().click(function (event) {
            $('.submit-button').attr("disabled", "disabled");

            sendPaymentDataToAnet();

            return false;
        });
    };

</script>

I also tried loading the Accept.js using jquery, like this: 

 

  $(document).ready(function () {
        $.getScript("https://jstest.authorize.net/v1/Accept.js", function (data, textStatus, jqxhr) {
            GetScriptCallback();
        });
    });

But then it throws the following error: 

E_WC_01Please include Accept.js library from cdn.

 

 

 

 

@andronachev2016  Try adding Accept.js at the top of the main area of your one page checkout not dynamically within the page using AJAX.

 

Or another option might be to use the following:

 

dispatchEvent(new Event('load'));

 

Richard

I would try, but I cannot do that - because this is a plugin, it needs to render it's own resources. The HEADER section is part of the CMS that it plugs into, I don't have access to that one.

 

 

You may have missed my update to try:

 

dispatchEvent(new Event('load'));

Yes, it works with the dispatchEvent approach. However: 

 

It does not work if I include the script like this: 

 

 

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

Because then you need to listen to the 

 

 

 

$(window).load()

Event (this includes the loading time of the external resources - document ready only listens for the DOM). But this event is not firing, because of the XMLHttpRequest cannot load https://jstest.authorize.net/v1/AcceptCore.js. No 'Access-Control-Allow-Origin' ... error. So what I did was to load the script dynamically, like this: 

 

$(document).ready(function () {
        $.getScript(jsUrl, function (data, textStatus, jqxhr) {
dispatchEvent(new Event('load')); GetScriptCallback(); }); });

Which initially was throwing the CDN error, but if I add your event triggering, then it does work. 

 

 

Hope this makes sense.

 

Thans a lot ! 

 

Vlad

 

 

Actually the CDN is still an issue. I tested my dynamic loading of the script, whilst still having the <script> tag as well. 

 

So the solution is to use the <Script> tag.. but we can't use hte window.load, beacuse of the CORS error. so What I did was to use document ready, and add a sleep() function of 1 second, then I fire the load event. Therefore my javascript code runs after the <Script> tag has loaded.

Thanks @andronachev2016 for the detailed feedback.  I'll pass this information on to our product and documentation teams for future updates should developers have similar use cases.

 

Richard