|
7 | 7 |
|
8 | 8 | use Magento\Backend\App\Area\FrontNameResolver; |
9 | 9 | use Magento\Framework\App\Config\ScopeConfigInterface; |
| 10 | +use Magento\Framework\App\ObjectManager; |
10 | 11 | use Magento\Framework\Mail\Template\TransportBuilder; |
11 | 12 | use Magento\Framework\Stdlib\DateTime\TimezoneInterface; |
12 | 13 | use Magento\Framework\Translate\Inline\StateInterface; |
|
15 | 16 | use Magento\Sales\Api\PaymentFailuresInterface; |
16 | 17 | use Magento\Store\Model\ScopeInterface; |
17 | 18 | use Magento\Store\Model\Store; |
| 19 | +use Psr\Log\LoggerInterface; |
18 | 20 |
|
19 | 21 | /** |
20 | 22 | * Service is responsible for handling failed payment transactions. |
21 | 23 | * |
22 | 24 | * It depends on Stores > Configuration > Sales > Checkout > Payment Failed Emails configuration. |
| 25 | + * |
| 26 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
23 | 27 | */ |
24 | 28 | class PaymentFailuresService implements PaymentFailuresInterface |
25 | 29 | { |
@@ -50,25 +54,33 @@ class PaymentFailuresService implements PaymentFailuresInterface |
50 | 54 | */ |
51 | 55 | private $cartRepository; |
52 | 56 |
|
| 57 | + /** |
| 58 | + * @var LoggerInterface |
| 59 | + */ |
| 60 | + private $logger; |
| 61 | + |
53 | 62 | /** |
54 | 63 | * @param ScopeConfigInterface $scopeConfig |
55 | 64 | * @param StateInterface $inlineTranslation |
56 | 65 | * @param TransportBuilder $transportBuilder |
57 | 66 | * @param TimezoneInterface $localeDate |
58 | 67 | * @param CartRepositoryInterface $cartRepository |
| 68 | + * @param LoggerInterface|null $logger |
59 | 69 | */ |
60 | 70 | public function __construct( |
61 | 71 | ScopeConfigInterface $scopeConfig, |
62 | 72 | StateInterface $inlineTranslation, |
63 | 73 | TransportBuilder $transportBuilder, |
64 | 74 | TimezoneInterface $localeDate, |
65 | | - CartRepositoryInterface $cartRepository |
| 75 | + CartRepositoryInterface $cartRepository, |
| 76 | + LoggerInterface $logger = null |
66 | 77 | ) { |
67 | 78 | $this->scopeConfig = $scopeConfig; |
68 | 79 | $this->inlineTranslation = $inlineTranslation; |
69 | 80 | $this->transportBuilder = $transportBuilder; |
70 | 81 | $this->localeDate = $localeDate; |
71 | 82 | $this->cartRepository = $cartRepository; |
| 83 | + $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class); |
72 | 84 | } |
73 | 85 |
|
74 | 86 | /** |
@@ -126,7 +138,11 @@ public function handle( |
126 | 138 | ->addBcc($bcc) |
127 | 139 | ->getTransport(); |
128 | 140 |
|
129 | | - $transport->sendMessage(); |
| 141 | + try { |
| 142 | + $transport->sendMessage(); |
| 143 | + } catch (\Exception $e) { |
| 144 | + $this->logger->critical($e->getMessage()); |
| 145 | + } |
130 | 146 | } |
131 | 147 |
|
132 | 148 | $this->inlineTranslation->resume(); |
|
0 commit comments