Skip to content

Commit

Permalink
Fixed error in NZBN validation algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Wharton committed Jul 11, 2024
1 parent 3ab3075 commit c5e82f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Model/TaxSchemes/NewZealandGst.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ public function isValidNzbn(?string $nzbn): bool
foreach (str_split($withoutcheck) as $key => $digit) {
$sum += ((int) $digit * $weights[$key]);
}
$remainder = $sum % 10;
$calculatedCheck = 10 - $remainder;
$calculatedCheck = (ceil($sum/10) * 10) - $sum;
if ($calculatedCheck == $check) {
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions Test/Unit/CheckNzGstTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function testIsValidNzbn($number, $valid): void
public function isValidNZBNDataProvider(): array
{
return [
["9429039098740", true],
["9429034243282", true],
["9429041535110", true],
["9429049999198", true],
["6291041500213", true],
["6291041500212", false],
["123456789", false],
Expand All @@ -80,3 +84,4 @@ public function isValidNZBNDataProvider(): array
];
}
}

0 comments on commit c5e82f1

Please sign in to comment.