Skip to content

Commit b50442a

Browse files
committed
Merge remote-tracking branch 'mpi/MC-19542' into Chaika-PR-2019-09-01-2.3
2 parents 3b446a8 + 18a83d6 commit b50442a

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/**
2020
* Class OrderPlace
2121
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2223
*/
2324
class OrderPlace extends AbstractHelper
2425
{
@@ -79,9 +80,10 @@ public function __construct(
7980
public function execute(Quote $quote, array $agreement)
8081
{
8182
if (!$this->agreementsValidator->isValid($agreement)) {
82-
throw new LocalizedException(__(
83+
$errorMsg = __(
8384
"The order wasn't placed. First, agree to the terms and conditions, then try placing your order again."
84-
));
85+
);
86+
throw new LocalizedException($errorMsg);
8587
}
8688

8789
if ($this->getCheckoutMethod($quote) === Onepage::METHOD_GUEST) {
@@ -91,12 +93,7 @@ public function execute(Quote $quote, array $agreement)
9193
$this->disabledQuoteAddressValidation($quote);
9294

9395
$quote->collectTotals();
94-
try {
95-
$this->cartManagement->placeOrder($quote->getId());
96-
} catch (\Exception $e) {
97-
$this->orderCancellationService->execute($quote->getReservedOrderId());
98-
throw $e;
99-
}
96+
$this->cartManagement->placeOrder($quote->getId());
10097
}
10198

10299
/**

app/code/Magento/Braintree/Plugin/OrderCancellation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public function aroundPlaceOrder(
7272
];
7373
if (in_array($payment->getMethod(), $paymentCodes)) {
7474
$incrementId = $quote->getReservedOrderId();
75-
$this->orderCancellationService->execute($incrementId);
75+
if ($incrementId) {
76+
$this->orderCancellationService->execute($incrementId);
77+
}
7678
}
7779

7880
throw $e;

dev/tests/integration/testsuite/Magento/Braintree/Controller/Paypal/PlaceOrderTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ protected function tearDown()
7676
/**
7777
* Tests a negative scenario for a place order flow when exception throws after placing an order.
7878
*
79-
*
8079
* @magentoAppArea frontend
8180
* @magentoAppIsolation enabled
8281
* @magentoDataFixture Magento/Braintree/Fixtures/paypal_quote.php
@@ -113,6 +112,43 @@ public function testExecuteWithFailedOrder()
113112
self::assertEquals('canceled', $order->getState());
114113
}
115114

115+
/**
116+
* Tests a negative scenario for a place order flow when exception throws before order creation.
117+
*
118+
* @magentoAppArea frontend
119+
* @magentoAppIsolation enabled
120+
* @magentoDataFixture Magento/Braintree/Fixtures/paypal_quote.php
121+
*/
122+
public function testExecuteWithFailedQuoteValidation()
123+
{
124+
$reservedOrderId = null;
125+
$quote = $this->getQuote('test01');
126+
$quote->setReservedOrderId($reservedOrderId);
127+
128+
$this->session->method('getQuote')
129+
->willReturn($quote);
130+
$this->session->method('getQuoteId')
131+
->willReturn($quote->getId());
132+
133+
$this->adapter->method('sale')
134+
->willReturn($this->getTransactionStub('authorized'));
135+
$this->adapter->method('void')
136+
->willReturn($this->getTransactionStub('voided'));
137+
138+
// emulates an error after placing the order
139+
$this->session->method('setLastOrderStatus')
140+
->willThrowException(new \Exception('Test Exception'));
141+
142+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
143+
$this->dispatch('braintree/paypal/placeOrder');
144+
145+
self::assertRedirect(self::stringContains('checkout/cart'));
146+
self::assertSessionMessages(
147+
self::equalTo(['The order #' . $reservedOrderId . ' cannot be processed.']),
148+
MessageInterface::TYPE_ERROR
149+
);
150+
}
151+
116152
/**
117153
* Gets quote by reserved order ID.
118154
*

0 commit comments

Comments
 (0)