-
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.
[EngCom] Public Pull Requests - 2.2-develop
- merged latest code from mainline branch
- Loading branch information
Showing
24 changed files
with
839 additions
and
430 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
app/code/Magento/Braintree/Gateway/Validator/ErrorCodeValidator.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,49 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Braintree\Gateway\Validator; | ||
|
||
use Braintree\Error\ErrorCollection; | ||
use Braintree\Error\Validation; | ||
use Braintree\Result\Error; | ||
use Braintree\Result\Successful; | ||
|
||
/** | ||
* Processes errors codes from Braintree response. | ||
*/ | ||
class ErrorCodeValidator | ||
{ | ||
/** | ||
* Invokes validation. | ||
* | ||
* @param Successful|Error $response | ||
* @return array | ||
*/ | ||
public function __invoke($response) | ||
{ | ||
if (!$response instanceof Error) { | ||
return [true, [__('Transaction is successful.')]]; | ||
} | ||
|
||
return [false, $this->getErrorCodes($response->errors)]; | ||
} | ||
|
||
/** | ||
* Retrieves list of error codes from Braintree response. | ||
* | ||
* @param ErrorCollection $collection | ||
* @return array | ||
*/ | ||
private function getErrorCodes(ErrorCollection $collection) | ||
{ | ||
$result = []; | ||
/** @var Validation $error */ | ||
foreach ($collection->deepAll() as $error) { | ||
$result[] = $error->code; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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
Oops, something went wrong.