Skip to content
This repository was archived by the owner on May 20, 2019. It is now read-only.

Commit 057a6b7

Browse files
Merge pull request #6 from NamrataChangani/2.3-develop-PR-port-16181
[Forwardport] Fixed syntax for before-after operators in less files.
2 parents 083447a + b01a948 commit 057a6b7

File tree

275 files changed

+7470
-1966
lines changed

Some content is hidden

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

275 files changed

+7470
-1966
lines changed

app/code/Magento/Backend/App/AbstractAction.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
217217
$this->_view->loadLayout(['default', 'adminhtml_denied'], true, true, false);
218218
$this->_view->renderLayout();
219219
$this->_request->setDispatched(true);
220+
220221
return $this->_response;
221222
}
222223

@@ -226,6 +227,11 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
226227

227228
$this->_processLocaleSettings();
228229

230+
// Need to preload isFirstPageAfterLogin (see https://github.com/magento/magento2/issues/15510)
231+
if ($this->_auth->isLoggedIn()) {
232+
$this->_auth->getAuthStorage()->isFirstPageAfterLogin();
233+
}
234+
229235
return parent::dispatch($request);
230236
}
231237

app/code/Magento/Backend/Block/GlobalSearch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function getWidgetInitOptions()
3131
'filterProperty' => 'name',
3232
'preventClickPropagation' => false,
3333
'minLength' => 2,
34+
'submitInputOnEnter' => false,
3435
]
3536
];
3637
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Gateway\Response;
9+
10+
use Magento\Braintree\Gateway\SubjectReader;
11+
use Magento\Payment\Gateway\Response\HandlerInterface;
12+
use Magento\Sales\Model\Order\Payment;
13+
14+
/**
15+
* Handles response details for order cancellation request.
16+
*/
17+
class CancelDetailsHandler implements HandlerInterface
18+
{
19+
/**
20+
* @var SubjectReader
21+
*/
22+
private $subjectReader;
23+
24+
/**
25+
* @param SubjectReader $subjectReader
26+
*/
27+
public function __construct(SubjectReader $subjectReader)
28+
{
29+
$this->subjectReader = $subjectReader;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function handle(array $handlingSubject, array $response)
36+
{
37+
$paymentDO = $this->subjectReader->readPayment($handlingSubject);
38+
/** @var Payment $orderPayment */
39+
$orderPayment = $paymentDO->getPayment();
40+
$orderPayment->setIsTransactionClosed(true);
41+
$orderPayment->setShouldCloseParentTransaction(true);
42+
}
43+
}

app/code/Magento/Braintree/Gateway/SubjectReader.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ public function readPayment(array $subject)
4343
}
4444

4545
/**
46-
* Reads transaction from subject
46+
* Reads transaction from the subject.
4747
*
4848
* @param array $subject
49-
* @return \Braintree\Transaction
49+
* @return Transaction
50+
* @throws \InvalidArgumentException if the subject doesn't contain transaction details.
5051
*/
5152
public function readTransaction(array $subject)
5253
{
5354
if (!isset($subject['object']) || !is_object($subject['object'])) {
54-
throw new \InvalidArgumentException('Response object does not exist');
55+
throw new \InvalidArgumentException('Response object does not exist.');
5556
}
5657

5758
if (!isset($subject['object']->transaction)
58-
&& !$subject['object']->transaction instanceof Transaction
59+
|| !$subject['object']->transaction instanceof Transaction
5960
) {
6061
throw new \InvalidArgumentException('The object is not a class \Braintree\Transaction.');
6162
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Gateway\Validator;
9+
10+
use Braintree\Error\ErrorCollection;
11+
use Braintree\Error\Validation;
12+
use Magento\Payment\Gateway\Validator\AbstractValidator;
13+
use Magento\Payment\Gateway\Validator\ResultInterface;
14+
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
15+
use Magento\Braintree\Gateway\SubjectReader;
16+
17+
/**
18+
* Decorates the general response validator to handle specific cases.
19+
*
20+
* This validator decorates the general response validator to handle specific cases like
21+
* an expired or already voided on Braintree side authorization transaction.
22+
*/
23+
class CancelResponseValidator extends AbstractValidator
24+
{
25+
/**
26+
* @var int
27+
*/
28+
private static $acceptableTransactionCode = 91504;
29+
30+
/**
31+
* @var GeneralResponseValidator
32+
*/
33+
private $generalResponseValidator;
34+
35+
/**
36+
* @var SubjectReader
37+
*/
38+
private $subjectReader;
39+
40+
/**
41+
* @param ResultInterfaceFactory $resultFactory
42+
* @param GeneralResponseValidator $generalResponseValidator
43+
* @param SubjectReader $subjectReader
44+
*/
45+
public function __construct(
46+
ResultInterfaceFactory $resultFactory,
47+
GeneralResponseValidator $generalResponseValidator,
48+
SubjectReader $subjectReader
49+
) {
50+
parent::__construct($resultFactory);
51+
$this->generalResponseValidator = $generalResponseValidator;
52+
$this->subjectReader = $subjectReader;
53+
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function validate(array $validationSubject): ResultInterface
59+
{
60+
$result = $this->generalResponseValidator->validate($validationSubject);
61+
if (!$result->isValid()) {
62+
$response = $this->subjectReader->readResponseObject($validationSubject);
63+
if ($this->isErrorAcceptable($response->errors)) {
64+
$result = $this->createResult(true, [__('Transaction is cancelled offline.')]);
65+
}
66+
}
67+
68+
return $result;
69+
}
70+
71+
/**
72+
* Checks if error collection has an acceptable error code.
73+
*
74+
* @param ErrorCollection $errorCollection
75+
* @return bool
76+
*/
77+
private function isErrorAcceptable(ErrorCollection $errorCollection): bool
78+
{
79+
$errors = $errorCollection->deepAll();
80+
// there is should be only one acceptable error
81+
if (count($errors) > 1) {
82+
return false;
83+
}
84+
85+
/** @var Validation $error */
86+
$error = array_pop($errors);
87+
88+
return (int)$error->code === self::$acceptableTransactionCode;
89+
}
90+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Test\Unit\Gateway\Response;
9+
10+
use Magento\Braintree\Gateway\Response\CancelDetailsHandler;
11+
use Magento\Braintree\Gateway\SubjectReader;
12+
use Magento\Payment\Gateway\Data\OrderAdapterInterface;
13+
use Magento\Payment\Gateway\Data\PaymentDataObject;
14+
use Magento\Sales\Model\Order\Payment;
15+
use PHPUnit\Framework\TestCase;
16+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
17+
18+
/**
19+
* Tests \Magento\Braintree\Gateway\Response\CancelDetailsHandler.
20+
*/
21+
class CancelDetailsHandlerTest extends TestCase
22+
{
23+
/**
24+
* @var CancelDetailsHandler
25+
*/
26+
private $handler;
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function setUp()
32+
{
33+
$this->handler = new CancelDetailsHandler(new SubjectReader());
34+
}
35+
36+
/**
37+
* Checks a case when cancel handler closes the current and parent transactions.
38+
*
39+
* @return void
40+
*/
41+
public function testHandle(): void
42+
{
43+
/** @var OrderAdapterInterface|MockObject $order */
44+
$order = $this->getMockForAbstractClass(OrderAdapterInterface::class);
45+
/** @var Payment|MockObject $payment */
46+
$payment = $this->getMockBuilder(Payment::class)
47+
->disableOriginalConstructor()
48+
->setMethods(['setOrder'])
49+
->getMock();
50+
51+
$paymentDO = new PaymentDataObject($order, $payment);
52+
$response = [
53+
'payment' => $paymentDO,
54+
];
55+
56+
$this->handler->handle($response, []);
57+
58+
self::assertTrue($payment->getIsTransactionClosed(), 'The current transaction should be closed.');
59+
self::assertTrue($payment->getShouldCloseParentTransaction(), 'The parent transaction should be closed.');
60+
}
61+
}

0 commit comments

Comments
 (0)