| Total Complexity | 6 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class ResponseCodeValidator extends AbstractValidator |
||
| 13 | { |
||
| 14 | const RESULT_CODE = 'RESULT_CODE'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Performs validation of result code |
||
| 18 | * |
||
| 19 | * @param array $validationSubject |
||
| 20 | * @return ResultInterface |
||
| 21 | */ |
||
| 22 | public function validate(array $validationSubject) |
||
| 23 | { |
||
| 24 | if (!isset($validationSubject['response']) || !is_array($validationSubject['response'])) { |
||
| 25 | throw new \InvalidArgumentException('Response does not exist'); |
||
| 26 | } |
||
| 27 | |||
| 28 | $response = $validationSubject['response']; |
||
| 29 | |||
| 30 | if ($this->isSuccessfulTransaction($response)) { |
||
| 31 | return $this->createResult( |
||
| 32 | true, |
||
| 33 | [] |
||
| 34 | ); |
||
| 35 | } else { |
||
| 36 | return $this->createResult( |
||
| 37 | false, |
||
| 38 | [__('Gateway rejected the transaction.')] |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param array $response |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | private function isSuccessfulTransaction(array $response) |
||
| 51 | } |
||
| 52 | } |
||
| 53 |