Reply
Highlighted
New Member
Posts: 1
Registered: ‎12-06-2018

Accept.js is not loaded correctly

Hello,

I using an Accept.js method to accept an payment, but in few of the transactions its not getting the tokenize data. Its seems that it fails to load/call Accept.js file due to which its fails to create the tocken data (datavalue & dataDescriptor).

When we clear the browser caches and again if we try to make the transactions its working fine.

 

Following is the code i am using,

 

<script>
    directPost.prototype.saveOnepageOrder = function() {

        if(lotusOSC.onestepcheckout('validate')){
            console.log(this.orderSaveUrl);
           
            var authData = {};
                authData.clientKey = "<?php echo $clientKey; ?>";
                authData.apiLoginID = "<?php echo $apiLoginId; ?>";

            var cardData = {};
                cardData.cardNumber = document.getElementById("authorizenet_directpost_cc_number").value;
                cardData.month = document.getElementById("authorizenet_directpost_expiration").value;
                cardData.year = document.getElementById("authorizenet_directpost_expiration_yr").value;
                cardData.cardCode = document.getElementById("authorizenet_directpost_cc_cid").value;
            
            var secureData = {};
                secureData.authData = authData;
                secureData.cardData = cardData;
                
            Accept.dispatchData(secureData, responseHandler);
            console.log(secureData);
            return false;
        }

    };
    
    function responseHandler(response) {
        console.log(response);
        var msg = {};
        var i = 0;
        if (response.messages.resultCode === "Error") {
            while (i < response.messages.message.length) {
                console.log(
                    response.messages.message[i].code + ": " +
                    response.messages.message[i].text
                );
                msg[response.messages.message[i].code] = response.messages.message[i].text;
                i = i + 1;
            }
            document.getElementById("authorizenet_accept_response").value = JSON.stringify(msg);
        } else {
            while (i < response.messages.message.length) {
                msg[response.messages.message[i].code] = response.messages.message[i].text;
                i = i + 1;
            }
            document.getElementById("authorizenet_accept_response").value = JSON.stringify(msg);
            paymentFormUpdate(response.opaqueData);
        }
    }
    
    function paymentFormUpdate(opaqueData) {
        document.getElementById("dataDescriptor").value = opaqueData.dataDescriptor;
        document.getElementById("dataValue").value = opaqueData.dataValue;

        // If using your own form to collect the sensitive data from the customer,
        // blank out the fields before submitting them to your server.
        document.getElementById("authorizenet_directpost_cc_type").value = "";
        document.getElementById("authorizenet_directpost_cc_number").value = "";
        document.getElementById("authorizenet_directpost_expiration").value = "";
        document.getElementById("authorizenet_directpost_expiration_yr").value = "";
        document.getElementById("authorizenet_directpost_cc_cid").value = "";
        /*document.getElementById("routingNumber").value = "";
        document.getElementById("nameOnAccount").value = "";
        document.getElementById("accountType").value = "";*/
        
        console.log('accept call finish');

        lotusOSC.onestepcheckout("placeOrder");
    }
    directPost.prototype.saveOnepageOrderSuccess = function(transport) {

        if (transport.status == 403) {
            alert('fail');
        }

        try {
            response = eval('(' + transport.responseText + ')');
        } catch (e) {
            response = {};
        }
        console.log(response);
        if (response.success && response.directpost) {
            this.orderIncrementId = response.directpost.fields.x_invoice_num;
            var paymentData = {};
            for ( var key in response.directpost.fields) {
                paymentData[key] = response.directpost.fields[key];
            }
            console.log(paymentData);
            var preparedData = this.preparePaymentRequest(paymentData);
            this.sendPaymentRequest(preparedData);
            console.log(preparedData);
            lotusOSC.onestepcheckout('removeWait');
        } else {
            ///console.log('test');
            var msg = response.error_messages;
            if (typeof (msg) == 'object') {
                msg = msg.join("\n");
            }
            if (msg) {
                alert(msg);
            }

        }
    };

 

I had used the logs to get the exact issue for same, and I found that its not going to function function responseHandler(response) due to which its not create or gives an error, while createing the tockenize data, by Accept.js method.

Its not having the issue for every time, but also for major time we were getting the issue. Due to which we can't able to processs further for such transacitons.

I think its an issue with handshake between Accept.js and AcceptCore.js for some of the cases.