File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 55 "require" : {
66 "guzzlehttp/guzzle" : " ^7.0" ,
77 "php" : " ^8.0" ,
8- "ext-simplexml" : " *"
8+ "ext-simplexml" : " *" ,
9+ "jschaedl/iban-validation" : " ^2.5"
910 },
1011 "require-dev" : {
1112 "phpunit/phpunit" : " ^9.5.25"
Original file line number Diff line number Diff line change 44namespace FastBillSdk \Customer ;
55
66use FastBillSdk \Common \MissingPropertyException ;
7+ use Iban \Validation \Iban ;
8+ use Iban \Validation \Validator ;
79
810class CustomerValidator
911{
@@ -35,6 +37,12 @@ public function validateRequiredCreationProperties(CustomerEntity $entity): arra
3537 $ errorMessages [] = $ exception ->getMessage ();
3638 }
3739
40+ try {
41+ $ this ->checkIban ($ entity );
42+ } catch (MissingPropertyException $ exception ) {
43+ $ errorMessages [] = $ exception ->getMessage ();
44+ }
45+
3846 return $ errorMessages ;
3947 }
4048
@@ -108,4 +116,15 @@ private function isBusiness(CustomerEntity $entity): bool
108116 {
109117 return $ entity ->customerType === CustomerEntity::CUSTOMER_TYPE_BUSINESS ;
110118 }
119+
120+ private function checkIban (CustomerEntity $ entity )
121+ {
122+ if ($ entity ->bankIban ) {
123+ $ iban = new Iban ($ entity ->bankIban );
124+ $ validator = new Validator ();
125+ if (!$ validator ->validate ($ iban )) {
126+ throw new MissingPropertyException ('The property bankIban is not valid! ' );
127+ }
128+ }
129+ }
111130}
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace FastBillSdkTest \Customer ;
5+
6+ use FastBillSdk \Customer \CustomerEntity ;
7+ use FastBillSdk \Customer \CustomerValidator ;
8+ use FastBillSdkTest \Common \BaseTestTrait ;
9+ use PHPUnit \Framework \TestCase ;
10+
11+ class CustomerValidationTest extends TestCase
12+ {
13+ use BaseTestTrait;
14+
15+ public function testIbanValidation ()
16+ {
17+ $ customer = new CustomerEntity ();
18+ $ customer ->bankIban = 'DE99370400440532013000 ' ; // Example wrong IBAN
19+
20+ $ validator = new CustomerValidator ();
21+ $ errors = $ validator ->validateRequiredCreationProperties ($ customer );
22+
23+ self ::assertContains ('The property bankIban is not valid! ' , $ errors );
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments