|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\Payone\Form\Constraint; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
|
|
11
|
|
|
use SprykerEco\Shared\Payone\PayoneApiConstants; |
|
12
|
|
|
use Symfony\Component\Form\Exception\UnexpectedTypeException; |
|
13
|
|
|
use Symfony\Component\Validator\Constraint; |
|
14
|
|
|
use Symfony\Component\Validator\ConstraintValidator; |
|
15
|
|
|
|
|
16
|
|
|
class BankAccountValidator extends ConstraintValidator |
|
17
|
|
|
{ |
|
18
|
|
|
public const INVALID_STATUSES = [ |
|
19
|
|
|
PayoneApiConstants::RESPONSE_TYPE_ERROR, |
|
20
|
|
|
PayoneApiConstants::RESPONSE_TYPE_INVALID, |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param string $value |
|
25
|
|
|
* @param \Symfony\Component\Validator\Constraint|\SprykerEco\Yves\Payone\Form\Constraint\BankAccount $constraint |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \Symfony\Component\Form\Exception\UnexpectedTypeException |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
public function validate($value, Constraint $constraint) |
|
32
|
|
|
{ |
|
33
|
|
|
if (!$constraint instanceof BankAccount) { |
|
34
|
|
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\BankAccount'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if ($value === null || $value === '') { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** @var \Symfony\Component\Form\Form $root */ |
|
42
|
|
|
$root = $this->context->getRoot(); |
|
43
|
|
|
|
|
44
|
|
|
/** @var \Generated\Shared\Transfer\QuoteTransfer $data */ |
|
45
|
|
|
$data = $root->getData(); |
|
46
|
|
|
|
|
47
|
|
|
$validationMessages = $this->validateBankAccount($data, $constraint); |
|
48
|
|
|
|
|
49
|
|
|
if (count($validationMessages) > 0) { |
|
50
|
|
|
foreach ($validationMessages as $validationMessage) { |
|
51
|
|
|
$this->buildViolation($validationMessage) |
|
|
|
|
|
|
52
|
|
|
->addViolation(); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $data |
|
59
|
|
|
* @param \SprykerEco\Yves\Payone\Form\Constraint\BankAccount $constraint |
|
60
|
|
|
* |
|
61
|
|
|
* @return string[] |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function validateBankAccount(QuoteTransfer $data, BankAccount $constraint) |
|
64
|
|
|
{ |
|
65
|
|
|
$response = $constraint->getPayoneClient()->bankAccountCheck($data); |
|
66
|
|
|
if (in_array($response->getStatus(), static::INVALID_STATUSES)) { |
|
67
|
|
|
return [$response->getCustomerErrorMessage()]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return []; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths