Magento2: Credit Card Checkout Fails with 400 - Bad Request on Secure Gateway Providers

Created on 28 Jul 2017  路  18Comments  路  Source: magento/magento2


Preconditions

  1. CentOS 7.3 with Nginx 1.13.3, Varnish, Redis; store setup to run over SSL; proxy server terminate ssl, loop to Varnish-HTTP -> nginx-HTTPS bypassing checkout and cart all working as expected in multi-store environment
  2. Magento CE 2.1.17, PHP 7.0.18, mysql 5.6.36

Steps to reproduce

  1. Install Magento CE 2.1.17
  2. Use data tool to migrate from 1.9.1 to 2.1.17
  3. Enable Braintree (sandbox or production yield same result)
  4. Add product to cart and proceed to checkout
  5. Enter credit card information and submit order

Expected result

  1. Order should be processed and recorded successfully

Actual result

  1. Displays error message, "An error occurred on the server. Please try to place the order again."
    checkout

Steps I've Already Taken

  • I've checked the database and verified that sales_sequence_meta, sales_sequence_profile, and all the sequence_* tables have the correct values.
  • I have tried both Braintree and Authorize.net sandbox solutions. Interestingly, with Authorize.net it actually records the order in the system but not the invoice. Braintree doesn't record either. This only happens when a gateway processes something off-site in the background. With check or Paypal Express Checkout, it simply completes the checkout process successfully.
  • At one point I suspected Varnish and my caching system, but found that it's bypassing the checkout and cart pages all together

Three Clues

I have data from three separate sources that may help in pinpointing the problem:

1. Magento Exception Data:
Magento\Payment\Gateway\Http\ClientException: Sorry, but something went wrong in /home/mystore/public_html/vendor/magento/module-braintree/Gateway/Http/Client/AbstractTransaction.php:67
Stack trace:

0 /home/mystore/public_html/vendor/magento/module-payment/Gateway/Command/GatewayCommand.php(94): Magento\Braintree\Gateway\Http\Client\AbstractTransaction->placeRequest(Object(Magento\Payment\Gateway\Http\Transfer))

1 /home/mystore/public_html/vendor/magento/module-braintree/Gateway/Command/CaptureStrategyCommand.php(120): Magento\Payment\Gateway\Command\GatewayCommand->execute(Array)

2 /home/mystore/public_html/vendor/magento/module-payment/Model/Method/Adapter.php(530): Magento\Braintree\Gateway\Command\CaptureStrategyCommand->execute(Array)

3 /home/mystore/public_html/vendor/magento/module-payment/Model/Method/Adapter.php(445): Magento\Payment\Model\Method\Adapter->executeCommand('capture', Array)

4 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment/Operations/CaptureOperation.php(82): Magento\Payment\Model\Method\Adapter->capture(Object(Magento\Sales\Model\Order\Payment\Interceptor), '47.35')

5 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment/Processor.php(85): Magento\Sales\Model\Order\Payment\Operations\CaptureOperation->capture(Object(Magento\Sales\Model\Order\Payment\Interceptor), Object(Magento\Sales\Model\Order\Invoice))

6 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment.php(447): Magento\Sales\Model\Order\Payment\Processor->capture(Object(Magento\Sales\Model\Order\Payment\Interceptor), Object(Magento\Sales\Model\Order\Invoice))

7 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Invoice.php(342): Magento\Sales\Model\Order\Payment->capture(Object(Magento\Sales\Model\Order\Invoice))

8 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment/Operations/AbstractOperation.php(70): Magento\Sales\Model\Order\Invoice->capture()

9 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment/Operations/CaptureOperation.php(30): Magento\Sales\Model\Order\Payment\Operations\AbstractOperation->invoice(Object(Magento\Sales\Model\Order\Payment\Interceptor))

10 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment/Processor.php(85): Magento\Sales\Model\Order\Payment\Operations\CaptureOperation->capture(Object(Magento\Sales\Model\Order\Payment\Interceptor), NULL)

11 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment.php(447): Magento\Sales\Model\Order\Payment\Processor->capture(Object(Magento\Sales\Model\Order\Payment\Interceptor), NULL)

12 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment.php(428): Magento\Sales\Model\Order\Payment->capture(NULL)

13 /home/mystore/public_html/vendor/magento/module-sales/Model/Order/Payment.php(348): Magento\Sales\Model\Order\Payment->processAction('authorize_captu...', Object(Magento\Sales\Model\Order))

14 /home/mystore/public_html/vendor/magento/module-sales/Model/Order.php(871): Magento\Sales\Model\Order\Payment->place()

15 /home/mystore/public_html/vendor/magento/module-sales/Model/Order.php(1060): Magento\Sales\Model\Order->_placePayment()

16 /home/mystore/public_html/vendor/magento/module-sales/Model/Service/OrderService.php(190): Magento\Sales\Model\Order->place()

17 /home/mystore/public_html/vendor/magento/module-quote/Model/QuoteManagement.php(488): Magento\Sales\Model\Service\OrderService->place(Object(Magento\Sales\Model\Order))

18 /home/mystore/public_html/vendor/magento/module-quote/Model/QuoteManagement.php(391): Magento\Quote\Model\QuoteManagement->submitQuote(Object(Magento\Quote\Model\Quote), Array)

19 /home/mystore/public_html/vendor/magento/module-quote/Model/QuoteManagement.php(349): Magento\Quote\Model\QuoteManagement->submit(Object(Magento\Quote\Model\Quote))

20 /home/mystore/public_html/vendor/magento/module-checkout/Model/PaymentInformationManagement.php(69): Magento\Quote\Model\QuoteManagement->placeOrder(12492)

21 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(146): Magento\Checkout\Model\PaymentInformationManagement->savePaymentInformationAndPlaceOrder(12492, Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))

22 /home/mystore/public_html/var/generation/Magento/Checkout/Model/PaymentInformationManagement/Interceptor.php(26): Magento\Checkout\Model\PaymentInformationManagement\Interceptor->___callPlugins('savePaymentInfo...', Array, Array)

23 [internal function]: Magento\Checkout\Model\PaymentInformationManagement\Interceptor->savePaymentInformationAndPlaceOrder(12492, Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))

24 /home/mystore/public_html/vendor/magento/module-webapi/Controller/Rest.php(307): call_user_func_array(Array, Array)

25 /home/mystore/public_html/vendor/magento/module-webapi/Controller/Rest.php(216): Magento\Webapi\Controller\Rest->processApiRequest()

26 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))

27 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Webapi\Controller\Rest\Interceptor->___callParent('dispatch', Array)

28 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Webapi\...', 'dispatch', Object(Magento\Webapi\Controller\Rest\Interceptor), Array, 'infortis_cgen_m...')

29 /home/mystore/public_html/app/code/Infortis/Cgen/Plugin/Magento/Framework/App/FrontController.php(32): Magento\Webapi\Controller\Rest\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http))

30 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(142): Infortis\Cgen\Plugin\Magento\Framework\App\FrontController->aroundDispatch(Object(Magento\Webapi\Controller\Rest\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))

31 /home/mystore/public_html/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(26): Magento\Webapi\Controller\Rest\Interceptor->___callPlugins('dispatch', Array, Array)

32 /home/mystore/public_html/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))

33 /home/mystore/public_html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()

34 /home/mystore/public_html/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))

35 {main}An error occurred on the server. Please try to place the order again.

2. Data from the browser itself on the error:
POST https://mystore.com/rest/kb_en/V1/carts/mine/payment-information 400 (Bad Request)

Request URL:https://mystore.com/rest/kb_en/V1/carts/mine/payment-information
Request Method:POST
Status Code:400 Bad Request
Remote Address:52.11.179.183:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Cache-Control:no-store, no-cache, must-revalidate
Connection:keep-alive
Content-Length:7452
Content-Type:application/json; charset=utf-8
Date:Fri, 28 Jul 2017 17:17:17 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:nginx
X-Processing-Time:3.242
X-Request-ID:d48411160573198738d94af5b7b800da
Request Headers
view source
Accept:/
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:435
Content-Type:application/json
Cookie:mage-translation-storage=%7B%7D; mage-translation-file-version=%7B%7D; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; mage-cache-sessid=true; _gat=1; PHPSESSID=g3ssj58thnbfvctsphns999560; mage-messages=%5B%5D; _ga=GA1.2.1748383495.1501258582; _gid=GA1.2.2028506524.1501258582; form_key=BHvS9SRr1DAA1Jt1; X-Magento-Vary=2005483da9402c52e2c0a90126d61a2e8296ebba; section_data_ids=%7B%22cart%22%3A1501262204%2C%22messages%22%3A1501262217%2C%22customer%22%3A1501262207%2C%22last-ordered-items%22%3A1501262207%7D
Host:mystore.com
Origin:https://mystore.com
Referer:https://mystore.com/checkout/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
view source
{cartId: "12492",鈥
billingAddress
:
{customerAddressId: "3", countryId: "US", regionId: "56", regionCode: "TN", region: "Tennessee",鈥
cartId
:
"12492"
paymentMethod
:
{method: "braintree", additional_data: {payment_method_nonce: "b9310f04-1154-0a48-2893-9795e6515bb6"}}

3. Debug data from Magento:

[2017-07-28 17:43:12] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["catalog_product_2189","catalog_product_2189"],"mode":"matchingAnyTag"},"is_exception":false} []
[2017-07-28 18:02:26] main.DEBUG: array (
'request' =>
array (
'customer' =>
array (
'firstName' => 'Bruce',
'lastName' => 'Willis',
'company' => NULL,
'phone' => '615-123-1234',
'email' => '[email protected]',
),
'amount' => '47.35',
'paymentMethodNonce' => '718ed74e-1b8a-0538-2aef-d91ca9a27ccc',
'orderId' => '5000027514',
'merchantAccountId' => 'Kitchen Brunch',
'channel' => 'Magento2_Cart_Community_BT',
'billing' =>
array (
'firstName' => 'Bruce',
'lastName' => 'Willis',
'company' => NULL,
'streetAddress' => '50 N Main St',
'extendedAddress' => '',
'locality' => 'Nashville',
'region' => 'TN',
'postalCode' => '37214',
'countryCodeAlpha2' => 'US',
),
'shipping' =>
array (
'firstName' => 'Bruce',
'lastName' => 'Willis',
'company' => NULL,
'streetAddress' => '50 N Main St',
'extendedAddress' => '',
'locality' => 'Nashville',
'region' => 'TN',
'postalCode' => '37214',
'countryCodeAlpha2' => 'US',
),
'options' =>
array (
'storeInVaultOnSuccess' => true,
'submitForSettlement' => true,
),
'descriptor' =>
array (
'name' => 'Kitchen Brunch',
'phone' => '615-224-7768脗聽',
'url' => 'https://mystore.com.com',
),
),
'client' => 'Magento\Braintree\Gateway\Http\Client\TransactionSale',
'response' =>
array (
),
) {"is_exception":false} []
[2017-07-28 18:03:08] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["catalog_product_2189","catalog_product_2189"],"mode":"matchingAnyTag"},"is_exception":false} []

Payment needs update

Most helpful comment

It was the dynamic descriptors that weren't passing appropriate values. I wish Magento would make these errors more prominent and descriptive besides the generic, "server error."

All 18 comments

Have you validated your settings in M2 with braintree support? They can see the logs as far as the error message go, and perhaps have to activate a setting on their side?

I have verified all the API credentials with Braintree on the phone for both for sandbox and production and both give me this same result. But it's not just Braintree, it's any secure gateway that does calls in the background to process credit cards. Authorize.net has the same kind of error when I try using their sandbox. The request is being made, and with Authorize.net the result is returned as successful, and although Magento creates the order, it never creates the invoice or logs the successful response from the gateway API. It simply throws the above error. There's a disconnect somewhere and I can't pinpoint it.

Comment out the exception catcher in vendor/magento/module-checkout/Model/PaymentInformationManagement.php

try to comment out the try and catch exception in this routine and try again:
` public function savePaymentInformationAndPlaceOrder(
$cartId,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
$sam=NULL;
$sam=$this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);

// try {
$orderId=NULL;
$orderId = $this->cartManagement->placeOrder($cartId);
/* } catch (\Exception $e) {
throw new CouldNotSaveException(
__('CNSE1: An error occurred on the server. Please try to place the order again.'),
$e
);
}
*/
return $orderId;
}

`

the // and /* and */ remove the exception coding and you will see the actual error in developer mode when trying to checkout whilst logged in!

Oh don't be surprised if it throws an error about duplicate order # in exception.log that is an old bug!

Commented out the code, flushed the cache and sessions and now the error simply says, "Sorry, but something went wrong." Debug logs and browser console stills how same type of output without any noticeable change.

You are using https right? I'm thinking its having a hard time reaching braintree using tls 1.2 !

You sure you have talked to them because their side should be logging errors!!

you check out exception.log debug.log support_report.log and /var/log/nginx/error.log ??!!

Braintree support is closed until Monday. I will talk to them again on Monday to see what they're seeing on their end. On my end the debug.log is the only file where anything is being logged. When using Braintree the exemption and nginx's error logs are empty. Now, if I use Authorize.net's sandbox, the order is created and on the Authorize.net end, they're showing it processing successfully. However, on Magento's end, the exemption log posts the following:

[2017-07-29 21:29:33] main.CRITICAL: Magento\Framework\Exception\LocalizedException: The transaction was declined because the response hash validation failed. in /home/mystore/public_html/vendor/magento/module-authorizene$
Stack trace:

0 /home/mystore/public_html/vendor/magento/module-authorizenet/Model/Directpost.php(564): Magento\Authorizenet\Model\Directpost->validateResponse()

1 /home/mystore/public_html/vendor/magento/module-authorizenet/Controller/Directpost/Payment.php(90): Magento\Authorizenet\Model\Directpost->process(Array)

2 /home/mystore/public_html/vendor/magento/module-authorizenet/Controller/Directpost/Payment/Response.php(19): Magento\Authorizenet\Controller\Directpost\Payment->_responseAction('frontend')

3 /home/mystore/public_html/vendor/magento/framework/App/Action/Action.php(102): Magento\Authorizenet\Controller\Directpost\Payment\Response->execute()

4 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))

5 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Authorizenet\Controller\Directpost\Payment\Response\Interceptor->___callParent('dispatch', Array)

6 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Authori...', 'dispatch', Object(Magento\Authorizenet\Controller\Dire$

7 /home/mystore/public_html/vendor/magento/module-store/App/Action/Plugin/Context.php(106): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\$

8 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\Action\Plugin\Context->aroundDispatch(Object(Magento\Authorizenet\Controller\Directpost\Payment\Response\Intercepto$

9 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Authori...', 'dispatch', Object(Magento\Authorizenet\Controller\Dire$

10 /home/mystore/public_html/vendor/magento/module-customer/Model/App/Action/ContextPlugin.php(61): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\$

11 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Customer\Model\App\Action\ContextPlugin->aroundDispatch(Object(Magento\Authorizenet\Controller\Directpost\Payment\Response\I$

12 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Authori...', 'dispatch', Object(Magento\Authorizenet\Controller\Dir$

13 /home/mystore/public_html/vendor/magento/module-store/App/Action/Plugin/StoreCheck.php(44): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Reque$

14 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\Action\Plugin\StoreCheck->aroundDispatch(Object(Magento\Authorizenet\Controller\Directpost\Payment\Response\Interc$

15 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Authori...', 'dispatch', Object(Magento\Authorizenet\Controller\Dir$

16 /home/mystore/public_html/vendor/magento/module-weee/Model/App/Action/ContextPlugin.php(112): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Req$

17 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Weee\Model\App\Action\ContextPlugin->aroundDispatch(Object(Magento\Authorizenet\Controller\Directpost\Payment\Response\Inter$

18 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Authori...', 'dispatch', Object(Magento\Authorizenet\Controller\Di$

19 /home/mystore/public_html/vendor/magento/module-tax/Model/App/Action/ContextPlugin.php(91): Magento\Authorizenet\Controller\Directpost\Payment\Response\Interceptor->Magento\Framework\Interception{closure}(Object(Mage$

20 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(142): Magento\Tax\Model\App\Action\ContextPlugin->aroundDispatch(Object(Magento\Authorizenet\Controller\Directpost\Payment\Response\Inter$

21 /home/mystore/public_html/var/generation/Magento/Authorizenet/Controller/Directpost/Payment/Response/Interceptor.php(26): Magento\Authorizenet\Controller\Directpost\Payment\Response\Interceptor->___callPlugins('dispat$

22 /home/mystore/public_html/vendor/magento/framework/App/FrontController.php(55): Magento\Authorizenet\Controller\Directpost\Payment\Response\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))

23 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))

24 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)

25 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontControll$

26 /home/mystore/public_html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\F$

27 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Intercepto$

28 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontControll$

29 /home/mystore/public_html/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Reque$

30 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object($

31 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontControll$

32 /home/mystore/public_html/vendor/magento/module-page-cache/Model/App/FrontController/VarnishPlugin.php(55): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Fra$

33 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor),$

34 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontControll$

35 /home/mystore/public_html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(68): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Fra$

36 /home/mystore/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor),$

37 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontControl$

38 /home/mystore/public_html/app/code/Infortis/Cgen/Plugin/Magento/Framework/App/FrontController.php(32): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framewo$

39 /home/mystore/public_html/vendor/magento/framework/Interception/Interceptor.php(142): Infortis\Cgen\Plugin\Magento\Framework\App\FrontController->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor$

40 /home/mystore/public_html/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)

41 /home/mystore/public_html/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))

42 /home/mystore/public_html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()

43 /home/mystore/public_html/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))

44 {main} [] []

And the debug.log shows that the response is successful:

[2017-07-29 21:29:33] main.DEBUG: array (
'response' =>
array (
'x_response_code' => '1',
'x_response_reason_code' => '1',
'x_response_reason_text' => 'This transaction has been approved.',
'x_avs_code' => 'Y',
'x_auth_code' => 'Z40SFK',
'x_trans_id' => '40005608989',
'x_method' => 'CC',
'x_card_type' => 'Visa',
'x_account_number' => 'XXXX1111',
'x_first_name' => 'Bruce',
'x_last_name' => 'Willis',
'x_company' => '',
'x_address' => '50 N Main St',
'x_city' => 'Nashville',
'x_state' => 'Tennessee',
'x_zip' => '37214',
'x_country' => '',
'x_phone' => '615-123-1234',
'x_fax' => '',
'x_email' => '[email protected]',
'x_invoice_num' => '5000027521',
'x_description' => '',
'x_type' => 'auth_capture',
'x_cust_id' => '',
'x_ship_to_first_name' => 'Bruce',
'x_ship_to_last_name' => 'Willis',
'x_ship_to_company' => '',
'x_ship_to_address' => '50 N Main St',
'x_ship_to_city' => 'Nashville',
'x_ship_to_state' => 'Tennessee',
'x_ship_to_zip' => '37214',
'x_ship_to_country' => '',
'x_amount' => '47.35',
'x_tax' => '0.00',
'x_duty' => '0.00',
'x_freight' => '7.45',
'x_tax_exempt' => 'FALSE',
'x_po_num' => '',
'x_MD5_Hash' => 'EF04B4AD2015D97AAE727F5E0A225961',
'x_SHA2_Hash' => '',
'x_cvv2_resp_code' => 'P',
'x_cavv_response' => '2',
'x_test_request' => 'false',
'controller_action_name' => 'directpost_payment',
'is_secure' => '1',
),
) {"is_exception":false} []

So although Authorize.net shows the transaction being successful, Magento's exemption log is recording it as declined because the response hash validation failed. What would cause the response hash to fail?

public function isValidHash($merchantMd5, $merchantApiLogin)
{
$hash = $this->generateHash($merchantMd5, $merchantApiLogin, $this->getXAmount(), $this->getXTransId());
return Security::compareStrings($hash, $this->getData('x_MD5_Hash'));
}

That's not a hard one, your (configuration) transmd5 and/or login is invalid! it verifies it by hashing against the amount/xtransid.

Again i'd go over your setup and make sure your credentials are accurate!

Btw check that an order and or/invoice with those numbers don't exist already. This is a known bug with magento that happens when errors occur during payment processing! Always a simple check but usually it would say so since you took the exception checking off! The CC providers don't like it when you submit multiple transactions against the same order/invoice # as well!

The order, invoice, and all sequence tables were updated last week to ensure no duplicate numbers. The orders are being recorded in the DB. Authorize.net API credentials and keys are valid and the sandbox gateway is accepting the Magento requests and returning a valid response with an "approved" message. Magento, however, isn't recording the invoice (which it does on valid payment) and throws that exemption about the hash values. Magento 1 was never this problematic :-(

Looking at the MD5 hashing right now. Trying to figure out where it's failing...

Why don't you set a new 10 digit trans_md5 on magento and on authorize.net - they have to be the same and 10digits like 1234567890

It's just failing because authorize.net is hashing differently than magento and that is the only defense against hackers forging response codes I guess an md5 hash!

Hi, @lee586, thanks for reporting.

As I see from provided debug.log the response from Braintree is empty. One of the possible reasons - outdated curl library. I suggest you use xdebug to find the original reason of request failing. You need to debug \Braintree\Http::post method during place order flow.

Spent 20 minutes on the phone with Braintree support and on their end they are seeing the account authenticate successfully but no transaction data being posted. The tech suggested that perhaps the transaction data was failing internal validation on the Magento side and wasn't being included in the Braintree request.

try this patch vendor/magento/module-braintree/Gateway/Http/Client/AbstractTransaction.php

` public function placeRequest(TransferInterface $transferObject)
{
$data = $transferObject->getBody();
$log = [
'request' => $data,
'client' => static::class
];
$response['object'] = [];

// try {
$response['object'] = $this->process($data);
// } catch (\Exception $e) {
// $message = __($e->getMessage() ?: 'Sorry, but something went wrong');
// $this->logger->critical($message);
// throw new ClientException($message);
// } finally {
$log['response'] = (array) $response['object'];
$this->customLogger->debug($log);
// }

    return $response;
}

`

The curl version is 7.54.1 and was last updated on June 14, 2017--pretty current. Did debugging and found internal validation errors about company name and URL:

Company name/DBA section must be either 3, 7 or 12 characters and the product descriptor can be up to 18, 14, or 9 characters respectively (with an * in between for a total descriptor name of 22 characters) Url must be 13 characters or shorter and can only contain letters, numbers and periods.

It was the dynamic descriptors that weren't passing appropriate values. I wish Magento would make these errors more prominent and descriptive besides the generic, "server error."

Was this page helpful?
0 / 5 - 0 ratings