2

We setup a fresh install of Magento 1.9.3.4

We're trying to create admin orders using Authorize.net Direct Post and it's not working.

We get an error in the console

Uncaught ReferenceError: transport is not defined

Looking @ the code in /js/mage/directpost.js we found on line 309

saveAdminOrderSuccess : function(data) {
    var response = transport.responseJSON || transport.responseText.evalJSON(true) || {};

    if (response.directpost) {
        this.orderIncrementId = response.directpost.fields.x_invoice_num;
        var paymentData = {};
        for ( var key in response.directpost.fields) {
            if(response.directpost.fields.hasOwnProperty(key)) {
                paymentData[key] = response.directpost.fields[key];
            }
        }
        var preparedData = this.preparePaymentRequest(paymentData);
        this.sendPaymentRequest(preparedData);
    } else {
        if (response.redirect) {
            window.location = response.redirect;
        }
        if (response.error_messages) {
            var msg = response.error_messages;
            if (Object.isArray(msg)) {
                msg = msg.join("\n");
            }
            if (msg) {
                alert(msg.stripTags().toString());
            }
        }
    }
},

Something is clearly wrong here, because the variable data passed in in saveAdminOrderSuccess : function(data) is not being used anywhere in the function.

Has anyone gotten Authorize.net Direct Post to work for admin orders?

Strangely enough, this works just fine on the front end, in that code the functions variable is named transport

saveOnepageOrderSuccess : function(transport) {
    if (transport.status == 403) {
        checkout.ajaxFailure();
    }
    var response = transport.responseJSON || transport.responseText.evalJSON(true) || {};

    if (response.success && response.directpost) {
        this.orderIncrementId = response.directpost.fields.x_invoice_num;
        var paymentData = {};
        for ( var key in response.directpost.fields) {
            if(response.directpost.fields.hasOwnProperty(key)) {
                paymentData[key] = response.directpost.fields[key];
            }
        }
        var preparedData = this.preparePaymentRequest(paymentData);
        this.sendPaymentRequest(preparedData);
    } else {
        var msg = response.error_messages;
        if (Object.isArray(msg)) {
            msg = msg.join("\n");
        }
        if (msg) {
            alert(msg.stripTags().toString());
        }

        if (response.update_section) {
            $('checkout-' + response.update_section.name + '-load').update(response.update_section.html);
            response.update_section.html.evalScripts();
        }

        if (response.goto_section) {
            checkout.gotoSection(response.goto_section);
            checkout.reloadProgressBlock();
        }
    }
},

I tried switching out data for transport in the saveAdminOrderSuccess function but that didn't help.

2
  • debug mode yes and then check what is issue. Oct 25 '17 at 9:27
  • @RavindrasinhZala the debug mode only collects data from when Magento starts submitting the payment to authorize.net - since the method never goes through, there is no debug.
    – Haim
    Oct 25 '17 at 21:39
1
+50

I got it to work by replacing:

var response = transport.responseJSON || transport.responseText.evalJSON(true) || {};

with:

var response = data.responseJSON || data.evalJSON(true) || {};
  • Notice that I removed responseText as well.
3
  • you got it to create an order for you? I tried your edit and it's still now working :(
    – Haim
    Oct 30 '17 at 17:17
  • Yes. Are you seeing any more console errors? What happens when you try to submit an order?
    – Joe
    Oct 30 '17 at 17:51
  • Are you getting redirected to admin_urlsales_order/view/order_id/order_number? I'm not
    – Haim
    Oct 30 '17 at 21:11
1

as @joe wrote above you need to replace
var response = transport.responseJSON || transport.responseText.evalJSON(true) || {};
with:
var response = data.responseJSON || data.evalJSON(true) || {};

But, you also need to update the admin helper in app/code/core/Mage/Authorizenet/Helper/Data.php

replace
public function getRedirectIframeUrl($params) { return $this->_getUrl('authorizenet/directpost_payment/redirect', $params); }
with:

     public function getRedirectIframeUrl($params)
{
    switch ($params['controller_action_name']) {
        case 'onepage':
            $route = 'authorizenet/directpost_payment/redirect';
            break;

        case 'sales_order_create':
        case 'sales_order_edit':
            $route = 'adminhtml/authorizenet_directpost_payment/redirect';
            break;

        default:
            $route = 'authorizenet/directpost_payment/redirect';
            break;
    }

    return $this->_getUrl($route, $params);
}

This was an oversight by the Magento core team when they updated the module to have two separate helpers for admin and for the front end.

The Proper way of doing this would be to put this in a module, if I have time I will post an update with the module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.