Total Complexity | 5 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | class ResponseCodeValidator extends AbstractValidator |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | public const RESULT_CODE = 'RESULT_CODE'; |
||
24 | |||
25 | /** |
||
26 | * Validation. |
||
27 | * |
||
28 | * @param array $validationSubject |
||
29 | * |
||
30 | * @return ResultInterface |
||
31 | */ |
||
32 | public function validate(array $validationSubject) |
||
33 | { |
||
34 | if (!isset($validationSubject['response']) || !is_array($validationSubject['response'])) { |
||
35 | throw new InvalidArgumentException('Response does not exist'); |
||
36 | } |
||
37 | |||
38 | $response = $validationSubject['response']; |
||
39 | |||
40 | if ($this->isSuccessfulTransaction($response)) { |
||
41 | return $this->createResult( |
||
42 | true, |
||
43 | [] |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | return $this->createResult( |
||
48 | false, |
||
49 | [__('Gateway rejected the transaction.')] |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Is Successful Transaction. |
||
55 | * |
||
56 | * @param array $response |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | private function isSuccessfulTransaction(array $response) |
||
63 | } |
||
64 | } |
||
65 |