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

Commit

Permalink
Merge pull request #6 from NamrataChangani/2.3-develop-PR-port-16181
Browse files Browse the repository at this point in the history
[Forwardport] Fixed syntax for before-after operators in less files.
  • Loading branch information
sanganinamrata authored Jun 22, 2018
2 parents 083447a + b01a948 commit 057a6b7
Show file tree
Hide file tree
Showing 275 changed files with 7,470 additions and 1,966 deletions.
6 changes: 6 additions & 0 deletions app/code/Magento/Backend/App/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
$this->_view->loadLayout(['default', 'adminhtml_denied'], true, true, false);
$this->_view->renderLayout();
$this->_request->setDispatched(true);

return $this->_response;
}

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

$this->_processLocaleSettings();

// Need to preload isFirstPageAfterLogin (see https://github.com/magento/magento2/issues/15510)
if ($this->_auth->isLoggedIn()) {
$this->_auth->getAuthStorage()->isFirstPageAfterLogin();
}

return parent::dispatch($request);
}

Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Backend/Block/GlobalSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getWidgetInitOptions()
'filterProperty' => 'name',
'preventClickPropagation' => false,
'minLength' => 2,
'submitInputOnEnter' => false,
]
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Gateway\Response;

use Magento\Braintree\Gateway\SubjectReader;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Sales\Model\Order\Payment;

/**
* Handles response details for order cancellation request.
*/
class CancelDetailsHandler implements HandlerInterface
{
/**
* @var SubjectReader
*/
private $subjectReader;

/**
* @param SubjectReader $subjectReader
*/
public function __construct(SubjectReader $subjectReader)
{
$this->subjectReader = $subjectReader;
}

/**
* @inheritdoc
*/
public function handle(array $handlingSubject, array $response)
{
$paymentDO = $this->subjectReader->readPayment($handlingSubject);
/** @var Payment $orderPayment */
$orderPayment = $paymentDO->getPayment();
$orderPayment->setIsTransactionClosed(true);
$orderPayment->setShouldCloseParentTransaction(true);
}
}
9 changes: 5 additions & 4 deletions app/code/Magento/Braintree/Gateway/SubjectReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ public function readPayment(array $subject)
}

/**
* Reads transaction from subject
* Reads transaction from the subject.
*
* @param array $subject
* @return \Braintree\Transaction
* @return Transaction
* @throws \InvalidArgumentException if the subject doesn't contain transaction details.
*/
public function readTransaction(array $subject)
{
if (!isset($subject['object']) || !is_object($subject['object'])) {
throw new \InvalidArgumentException('Response object does not exist');
throw new \InvalidArgumentException('Response object does not exist.');
}

if (!isset($subject['object']->transaction)
&& !$subject['object']->transaction instanceof Transaction
|| !$subject['object']->transaction instanceof Transaction
) {
throw new \InvalidArgumentException('The object is not a class \Braintree\Transaction.');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Gateway\Validator;

use Braintree\Error\ErrorCollection;
use Braintree\Error\Validation;
use Magento\Payment\Gateway\Validator\AbstractValidator;
use Magento\Payment\Gateway\Validator\ResultInterface;
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
use Magento\Braintree\Gateway\SubjectReader;

/**
* Decorates the general response validator to handle specific cases.
*
* This validator decorates the general response validator to handle specific cases like
* an expired or already voided on Braintree side authorization transaction.
*/
class CancelResponseValidator extends AbstractValidator
{
/**
* @var int
*/
private static $acceptableTransactionCode = 91504;

/**
* @var GeneralResponseValidator
*/
private $generalResponseValidator;

/**
* @var SubjectReader
*/
private $subjectReader;

/**
* @param ResultInterfaceFactory $resultFactory
* @param GeneralResponseValidator $generalResponseValidator
* @param SubjectReader $subjectReader
*/
public function __construct(
ResultInterfaceFactory $resultFactory,
GeneralResponseValidator $generalResponseValidator,
SubjectReader $subjectReader
) {
parent::__construct($resultFactory);
$this->generalResponseValidator = $generalResponseValidator;
$this->subjectReader = $subjectReader;
}

/**
* @inheritdoc
*/
public function validate(array $validationSubject): ResultInterface
{
$result = $this->generalResponseValidator->validate($validationSubject);
if (!$result->isValid()) {
$response = $this->subjectReader->readResponseObject($validationSubject);
if ($this->isErrorAcceptable($response->errors)) {
$result = $this->createResult(true, [__('Transaction is cancelled offline.')]);
}
}

return $result;
}

/**
* Checks if error collection has an acceptable error code.
*
* @param ErrorCollection $errorCollection
* @return bool
*/
private function isErrorAcceptable(ErrorCollection $errorCollection): bool
{
$errors = $errorCollection->deepAll();
// there is should be only one acceptable error
if (count($errors) > 1) {
return false;
}

/** @var Validation $error */
$error = array_pop($errors);

return (int)$error->code === self::$acceptableTransactionCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Gateway\Response;

use Magento\Braintree\Gateway\Response\CancelDetailsHandler;
use Magento\Braintree\Gateway\SubjectReader;
use Magento\Payment\Gateway\Data\OrderAdapterInterface;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Sales\Model\Order\Payment;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Tests \Magento\Braintree\Gateway\Response\CancelDetailsHandler.
*/
class CancelDetailsHandlerTest extends TestCase
{
/**
* @var CancelDetailsHandler
*/
private $handler;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->handler = new CancelDetailsHandler(new SubjectReader());
}

/**
* Checks a case when cancel handler closes the current and parent transactions.
*
* @return void
*/
public function testHandle(): void
{
/** @var OrderAdapterInterface|MockObject $order */
$order = $this->getMockForAbstractClass(OrderAdapterInterface::class);
/** @var Payment|MockObject $payment */
$payment = $this->getMockBuilder(Payment::class)
->disableOriginalConstructor()
->setMethods(['setOrder'])
->getMock();

$paymentDO = new PaymentDataObject($order, $payment);
$response = [
'payment' => $paymentDO,
];

$this->handler->handle($response, []);

self::assertTrue($payment->getIsTransactionClosed(), 'The current transaction should be closed.');
self::assertTrue($payment->getShouldCloseParentTransaction(), 'The parent transaction should be closed.');
}
}
Loading

0 comments on commit 057a6b7

Please sign in to comment.