-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-84109: Merge branch '2.2-develop' of github.com:magento-engco…
…m/magento2ce into MAGETWO-84109-magento-magento2-12314
- Loading branch information
Showing
364 changed files
with
6,223 additions
and
2,097 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/code/Magento/Braintree/Gateway/Response/CancelDetailsHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/code/Magento/Braintree/Gateway/Validator/CancelResponseValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?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; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 0 additions & 94 deletions
94
app/code/Magento/Braintree/Test/Unit/Gateway/Helper/SubjectReaderTest.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.