Skip to content

Commit f7892fc

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-53457: [COMMUNITY] [FEEDBACK] Improve error reporting for failed order placement (checkout) #4682
added exception logging
1 parent f4c95fc commit f7892fc

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Place.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Magento\Payment\Model\IframeConfigProvider;
1717
use Magento\Quote\Api\CartManagementInterface;
1818
use Magento\Framework\Exception\LocalizedException;
19+
use Psr\Log\LoggerInterface;
20+
use Magento\Framework\App\ObjectManager;
1921

2022
/**
2123
* Class Place
@@ -44,26 +46,36 @@ class Place extends Payment
4446
*/
4547
protected $jsonHelper;
4648

49+
/**
50+
* Logger for exception details
51+
*
52+
* @var LoggerInterface
53+
*/
54+
private $logger;
55+
4756
/**
4857
* @param Context $context
4958
* @param Registry $coreRegistry
5059
* @param DataFactory $dataFactory
5160
* @param CartManagementInterface $cartManagement
5261
* @param Onepage $onepageCheckout
5362
* @param JsonHelper $jsonHelper
63+
* @param LoggerInterface|null $logger
5464
*/
5565
public function __construct(
5666
Context $context,
5767
Registry $coreRegistry,
5868
DataFactory $dataFactory,
5969
CartManagementInterface $cartManagement,
6070
Onepage $onepageCheckout,
61-
JsonHelper $jsonHelper
71+
JsonHelper $jsonHelper,
72+
LoggerInterface $logger = null
6273
) {
6374
$this->eventManager = $context->getEventManager();
6475
$this->cartManagement = $cartManagement;
6576
$this->onepageCheckout = $onepageCheckout;
6677
$this->jsonHelper = $jsonHelper;
78+
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
6779
parent::__construct($context, $coreRegistry, $dataFactory);
6880
}
6981

@@ -127,9 +139,11 @@ protected function placeCheckoutOrder()
127139
]
128140
);
129141
} catch (LocalizedException $exception) {
142+
$this->logger->critical($exception);
130143
$result->setData('error', true);
131144
$result->setData('error_messages', $exception->getMessage());
132145
} catch (\Exception $exception) {
146+
$this->logger->critical($exception);
133147
$result->setData('error', true);
134148
$result->setData(
135149
'error_messages',

app/code/Magento/Braintree/Controller/Paypal/PlaceOrder.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\Controller\ResultFactory;
1212
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Braintree\Gateway\Config\PayPal\Config;
14+
use Psr\Log\LoggerInterface;
15+
use Magento\Framework\App\ObjectManager;
1416

1517
/**
1618
* Class PlaceOrder
@@ -22,22 +24,32 @@ class PlaceOrder extends AbstractAction
2224
*/
2325
private $orderPlace;
2426

27+
/**
28+
* Logger for exception details
29+
*
30+
* @var LoggerInterface
31+
*/
32+
private $logger;
33+
2534
/**
2635
* Constructor
2736
*
2837
* @param Context $context
2938
* @param Config $config
3039
* @param Session $checkoutSession
3140
* @param Helper\OrderPlace $orderPlace
41+
* @param LoggerInterface|null $logger
3242
*/
3343
public function __construct(
3444
Context $context,
3545
Config $config,
3646
Session $checkoutSession,
37-
Helper\OrderPlace $orderPlace
47+
Helper\OrderPlace $orderPlace,
48+
LoggerInterface $logger = null
3849
) {
3950
parent::__construct($context, $config, $checkoutSession);
4051
$this->orderPlace = $orderPlace;
52+
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
4153
}
4254

4355
/**
@@ -58,6 +70,7 @@ public function execute()
5870
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
5971
return $resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);
6072
} catch (\Exception $e) {
73+
$this->logger->critical($e);
6174
$this->messageManager->addExceptionMessage($e, $e->getMessage());
6275
}
6376

app/code/Magento/Payment/Model/Method/Adapter.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Payment\Gateway\Data\PaymentDataObjectFactory;
1818
use Magento\Payment\Gateway\Config\ValueHandlerPoolInterface;
1919
use Magento\Payment\Gateway\Validator\ValidatorPoolInterface;
20+
use Psr\Log\LoggerInterface;
21+
use Magento\Framework\App\ObjectManager;
2022

2123
/**
2224
* Payment method facade. Abstract method adapter
@@ -81,16 +83,24 @@ class Adapter implements MethodInterface
8183
*/
8284
private $commandExecutor;
8385

86+
/**
87+
* Logger for exception details
88+
*
89+
* @var LoggerInterface
90+
*/
91+
private $logger;
92+
8493
/**
8594
* @param ManagerInterface $eventManager
8695
* @param ValueHandlerPoolInterface $valueHandlerPool
8796
* @param PaymentDataObjectFactory $paymentDataObjectFactory
8897
* @param string $code
8998
* @param string $formBlockType
9099
* @param string $infoBlockType
91-
* @param CommandPoolInterface $commandPool
92-
* @param ValidatorPoolInterface $validatorPool
93-
* @param CommandManagerInterface $commandExecutor
100+
* @param CommandPoolInterface|null $commandPool
101+
* @param ValidatorPoolInterface|null $validatorPool
102+
* @param CommandManagerInterface|null $commandExecutor
103+
* @param LoggerInterface|null $logger
94104
*/
95105
public function __construct(
96106
ManagerInterface $eventManager,
@@ -101,7 +111,8 @@ public function __construct(
101111
$infoBlockType,
102112
CommandPoolInterface $commandPool = null,
103113
ValidatorPoolInterface $validatorPool = null,
104-
CommandManagerInterface $commandExecutor = null
114+
CommandManagerInterface $commandExecutor = null,
115+
LoggerInterface $logger = null
105116
) {
106117
$this->valueHandlerPool = $valueHandlerPool;
107118
$this->validatorPool = $validatorPool;
@@ -112,6 +123,7 @@ public function __construct(
112123
$this->eventManager = $eventManager;
113124
$this->paymentDataObjectFactory = $paymentDataObjectFactory;
114125
$this->commandExecutor = $commandExecutor;
126+
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
115127
}
116128

117129
/**
@@ -382,6 +394,7 @@ public function validate()
382394
try {
383395
$validator = $this->getValidatorPool()->get('global');
384396
} catch (\Exception $e) {
397+
$this->logger->critical($e);
385398
return $this;
386399
}
387400

0 commit comments

Comments
 (0)