0

I've configured Authorize.net Direct Post as a payment method in Magento 2.1. This is a fairly restrictive account that requires a lot of fields and requests are failing because some data is not being sent to authorize.net.

In particular, it looks like x_country and x_ship_to_country are never sent. How can I configure the payments module to collect and send this information? I know it's captured in the checkout module.

This is the response from https://test.authorize.net/gateway/transact.dll:

window.location="https://mywebsite.tld/authorizenet/directpost_payment/redirect/x_invoice_num/000000007/success/0/error_msg/Gateway error: Bill To Country is required./controller_action_name/directpost_payment/is_secure/1/";

And here's the debug log for one transaction, note that x_country and x_ship_to_country are blank:

[2017-05-30 18:57:54] main.DEBUG: array (
  'response' =>
  array (
    'x_response_code' => '3',
    'x_response_reason_code' => '33',
    'x_response_reason_text' => 'Bill To Country is required.',
    'x_avs_code' => 'P',
    'x_auth_code' => '',
    'x_trans_id' => '0',
    'x_method' => 'CC',
    'x_card_type' => 'MasterCard',
    'x_account_number' => 'XXXX0015',
    'x_first_name' => 'User',
    'x_last_name' => 'Lname',
    'x_company' => '',
    'x_address' => '1234 Sesame St',
    'x_city' => 'Houston',
    'x_state' => 'Texas',
    'x_zip' => '77013',
    'x_country' => '',
    'x_phone' => '1234567890',
    'x_fax' => '',
    'x_email' => 'dummy@data.com',
    'x_invoice_num' => '000000006',
    'x_description' => '',
    'x_type' => 'auth_capture',
    'x_cust_id' => '',
    'x_ship_to_first_name' => 'User',
    'x_ship_to_last_name' => 'Lname',
    'x_ship_to_company' => '',
    'x_ship_to_address' => '1234 Sesame St',
    'x_ship_to_city' => 'Houston',
    'x_ship_to_state' => 'Texas',
    'x_ship_to_zip' => '77013',
    'x_ship_to_country' => '',
    'x_amount' => '46.50',
    'x_tax' => '0.00',
    'x_duty' => '0.00',
    'x_freight' => '7.50',
    'x_tax_exempt' => 'FALSE',
    'x_po_num' => '',
    'x_MD5_Hash' => '706C267F8CA31058A740E0FC4BBCCB93',
    'x_SHA2_Hash' => '',
    'x_cvv2_resp_code' => '',
    'x_cavv_response' => '',
    'x_test_request' => 'false',
    'controller_action_name' => 'directpost_payment',
    'is_secure' => '1',
  ),
)
0

This is a bug with this version of Magento 2. The fix is on Github but I've added it manually since a newer version of Magento is not available and there's no ETA for it.

Here's a summary of the changes:

In app/code/Authorizenet/Model/Authorizenet.php (or vendor/magento/module-authorizenet/Model/Authorizenet.php depending on your installation method) find these two lines:

->setXCountry($billing->getCountry())
...
->setXShipToCountry($shipping->getCountry());

And update them to

->setXCountry($billing->getCountryId())
...
->setXShipToCountry($shipping->getCountryId());

Then, for app/code/Authorizenet/Model/Directpost/Request.php find these two lines:

->setXCountry(strval($billing->getCountry()))
->setXShipToCountry(
            strval($shipping->getCountry())
         );

and update them to:

->setXCountry(strval($billing->getCountryId()))
->setXShipToCountry(
            strval($shipping->getCountryId())
         );

There may be a better way of doing this, but as Magento development isn't a primary focus for me this is good enough for now.

| improve this answer | |
0

Additionally, the x_description field is not being set in the API DirectPost call to Authorize.net in Magento CE 2.2.2, so similarly to @charmeleon's solution, you can extend the Directpost/Request class, but it's probably more 'Magento-y' to write a plug in to attach the additional setX[thing] calls in an afterSetDataFromOrder() method, but either way works.

| improve this answer | |

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.