質問

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

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.

他のヒント

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.
ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top