Skip to content

Commit 923a5dc

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-96221
# Conflicts: # app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCategoryActionGroup.xml
2 parents 028df77 + 75c9b64 commit 923a5dc

File tree

238 files changed

+6330
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+6330
-662
lines changed

app/code/Magento/Authorizenet/view/adminhtml/templates/order/view/info/fraud_details.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ $fraudDetails = $payment->getAdditionalInformation('fraud_details');
4444
<?php endif; ?>
4545

4646
<?php if(!empty($fraudDetails['fraud_filters'])): ?>
47-
<b><?= $block->escapeHtml(__('Fraud Filters')) ?>:
48-
</b></br>
47+
<strong><?= $block->escapeHtml(__('Fraud Filters')) ?>:
48+
</strong></br>
4949
<?php foreach($fraudDetails['fraud_filters'] as $filter): ?>
5050
<?= $block->escapeHtml($filter['name']) ?>:
5151
<?= $block->escapeHtml($filter['action']) ?>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function __construct(
5454

5555
/**
5656
* @inheritdoc
57+
*
5758
* @throws LocalizedException
5859
*/
5960
public function execute()
@@ -71,7 +72,10 @@ public function execute()
7172
return $resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);
7273
} catch (\Exception $e) {
7374
$this->logger->critical($e);
74-
$this->messageManager->addExceptionMessage($e, $e->getMessage());
75+
$this->messageManager->addExceptionMessage(
76+
$e,
77+
'The order #' . $quote->getReservedOrderId() . ' cannot be processed.'
78+
);
7579
}
7680

7781
return $resultRedirect->setPath('checkout/cart', ['_secure' => true]);

app/code/Magento/Braintree/Model/Paypal/Helper/OrderPlace.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
*/
66
namespace Magento\Braintree\Model\Paypal\Helper;
77

8-
use Magento\Quote\Model\Quote;
8+
use Magento\Braintree\Model\Paypal\OrderCancellationService;
9+
use Magento\Checkout\Api\AgreementsValidatorInterface;
910
use Magento\Checkout\Helper\Data;
11+
use Magento\Checkout\Model\Type\Onepage;
1012
use Magento\Customer\Model\Group;
1113
use Magento\Customer\Model\Session;
12-
use Magento\Checkout\Model\Type\Onepage;
13-
use Magento\Quote\Api\CartManagementInterface;
1414
use Magento\Framework\Exception\LocalizedException;
15-
use Magento\Checkout\Api\AgreementsValidatorInterface;
15+
use Magento\Quote\Api\CartManagementInterface;
16+
use Magento\Quote\Model\Quote;
1617

1718
/**
1819
* Class OrderPlace
@@ -41,23 +42,29 @@ class OrderPlace extends AbstractHelper
4142
private $checkoutHelper;
4243

4344
/**
44-
* Constructor
45-
*
45+
* @var OrderCancellationService
46+
*/
47+
private $orderCancellationService;
48+
49+
/**
4650
* @param CartManagementInterface $cartManagement
4751
* @param AgreementsValidatorInterface $agreementsValidator
4852
* @param Session $customerSession
4953
* @param Data $checkoutHelper
54+
* @param OrderCancellationService $orderCancellationService
5055
*/
5156
public function __construct(
5257
CartManagementInterface $cartManagement,
5358
AgreementsValidatorInterface $agreementsValidator,
5459
Session $customerSession,
55-
Data $checkoutHelper
60+
Data $checkoutHelper,
61+
OrderCancellationService $orderCancellationService
5662
) {
5763
$this->cartManagement = $cartManagement;
5864
$this->agreementsValidator = $agreementsValidator;
5965
$this->customerSession = $customerSession;
6066
$this->checkoutHelper = $checkoutHelper;
67+
$this->orderCancellationService = $orderCancellationService;
6168
}
6269

6370
/**
@@ -66,7 +73,7 @@ public function __construct(
6673
* @param Quote $quote
6774
* @param array $agreement
6875
* @return void
69-
* @throws LocalizedException
76+
* @throws \Exception
7077
*/
7178
public function execute(Quote $quote, array $agreement)
7279
{
@@ -81,7 +88,12 @@ public function execute(Quote $quote, array $agreement)
8188
$this->disabledQuoteAddressValidation($quote);
8289

8390
$quote->collectTotals();
84-
$this->cartManagement->placeOrder($quote->getId());
91+
try {
92+
$this->cartManagement->placeOrder($quote->getId());
93+
} catch (\Exception $e) {
94+
$this->orderCancellationService->execute($quote->getReservedOrderId());
95+
throw $e;
96+
}
8597
}
8698

8799
/**
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Braintree\Model\Paypal;
8+
9+
use Magento\Framework\Api\SearchCriteriaBuilder;
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
use Magento\Sales\Api\OrderRepositoryInterface;
12+
13+
/**
14+
* The service to cancel an order and void authorization transaction.
15+
*/
16+
class OrderCancellationService
17+
{
18+
/**
19+
* @var OrderRepositoryInterface
20+
*/
21+
private $orderRepository;
22+
23+
/**
24+
* @var SearchCriteriaBuilder
25+
*/
26+
private $searchCriteriaBuilder;
27+
28+
/**
29+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
30+
* @param OrderRepositoryInterface $orderRepository
31+
*/
32+
public function __construct(
33+
SearchCriteriaBuilder $searchCriteriaBuilder,
34+
OrderRepositoryInterface $orderRepository
35+
) {
36+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
37+
$this->orderRepository = $orderRepository;
38+
}
39+
40+
/**
41+
* Cancels an order and authorization transaction.
42+
*
43+
* @param string $incrementId
44+
* @return bool
45+
*/
46+
public function execute($incrementId): bool
47+
{
48+
$order = $this->getOrder($incrementId);
49+
if ($order === null) {
50+
return false;
51+
}
52+
53+
// `\Magento\Sales\Model\Service\OrderService::cancel` cannot be used for cancellation as the service uses
54+
// the order repository with outdated payment method instance (ex. contains Vault instead of Braintree)
55+
$order->cancel();
56+
$this->orderRepository->save($order);
57+
return true;
58+
}
59+
60+
/**
61+
* Gets order by increment ID.
62+
*
63+
* @param string $incrementId
64+
* @return OrderInterface|null
65+
*/
66+
private function getOrder(string $incrementId)
67+
{
68+
$searchCriteria = $this->searchCriteriaBuilder->addFilter(OrderInterface::INCREMENT_ID, $incrementId)
69+
->create();
70+
71+
$items = $this->orderRepository->getList($searchCriteria)
72+
->getItems();
73+
74+
return array_pop($items);
75+
}
76+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Braintree\Plugin;
8+
9+
use Magento\Braintree\Model\Paypal\OrderCancellationService;
10+
use Magento\Braintree\Model\Ui\ConfigProvider;
11+
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PayPalConfigProvider;
12+
use Magento\Quote\Api\CartManagementInterface;
13+
use Magento\Quote\Api\CartRepositoryInterface;
14+
use Magento\Quote\Api\Data\PaymentInterface;
15+
16+
/**
17+
* Cancels an order and an authorization transaction.
18+
*/
19+
class OrderCancellation
20+
{
21+
/**
22+
* @var OrderCancellationService
23+
*/
24+
private $orderCancellationService;
25+
26+
/**
27+
* @var CartRepositoryInterface
28+
*/
29+
private $quoteRepository;
30+
31+
/**
32+
* @param OrderCancellationService $orderCancellationService
33+
* @param CartRepositoryInterface $quoteRepository
34+
*/
35+
public function __construct(
36+
OrderCancellationService $orderCancellationService,
37+
CartRepositoryInterface $quoteRepository
38+
) {
39+
$this->orderCancellationService = $orderCancellationService;
40+
$this->quoteRepository = $quoteRepository;
41+
}
42+
43+
/**
44+
* Cancels an order if an exception occurs during the order creation.
45+
*
46+
* @param CartManagementInterface $subject
47+
* @param \Closure $proceed
48+
* @param int $cartId
49+
* @param PaymentInterface $payment
50+
* @return int
51+
* @throws \Exception
52+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
53+
*/
54+
public function aroundPlaceOrder(
55+
CartManagementInterface $subject,
56+
\Closure $proceed,
57+
$cartId,
58+
PaymentInterface $payment = null
59+
) {
60+
try {
61+
return $proceed($cartId, $payment);
62+
} catch (\Exception $e) {
63+
$quote = $this->quoteRepository->get((int) $cartId);
64+
$payment = $quote->getPayment();
65+
$paymentCodes = [
66+
ConfigProvider::CODE,
67+
ConfigProvider::CC_VAULT_CODE,
68+
PayPalConfigProvider::PAYPAL_CODE,
69+
PayPalConfigProvider::PAYPAL_VAULT_CODE
70+
];
71+
if (in_array($payment->getMethod(), $paymentCodes)) {
72+
$incrementId = $quote->getReservedOrderId();
73+
$this->orderCancellationService->execute($incrementId);
74+
}
75+
76+
throw $e;
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)