Skip to content

Commit 2f7c772

Browse files
author
AlexRogalskiy
committed
Added info on workflows
Updates on github-actions
1 parent fd3a8b2 commit 2f7c772

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.nullables.api.playground.commons.utils
2+
3+
/**
4+
* NUBAN standards: https://www.cbn.gov.ng/Out/2020/PSMD/REVISED%20STANDARDS%20ON%20NIGERIA%20UNIFORM%20BANK%20ACCOUNT%20NUMBER%20(NUBAN)%20FOR%20BANKS%20AND%20OTHER%20FINANCIAL%20INSTITUTIONS%20.pdf
5+
*/
6+
class NubanValidator {
7+
8+
private companion object {
9+
/**
10+
* DMB: Deposit Money Banks
11+
*/
12+
private const val DMB_BANK_CODE_LENGTH = 3
13+
14+
/**
15+
* OFI: Other Financial Institutions
16+
*/
17+
private const val OFI_BANK_CODE_LENGTH = 5
18+
private val ALGORITHM = intArrayOf(3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3)
19+
}
20+
21+
fun validate(bankCode: String, accountNumber: String): Boolean {
22+
require(accountNumber.length == 10) { "Account number must be 10 digits long" }
23+
24+
val formattedBankCode = when (bankCode.length) {
25+
DMB_BANK_CODE_LENGTH -> "000$bankCode"
26+
OFI_BANK_CODE_LENGTH -> "9$bankCode"
27+
else -> throw IllegalArgumentException("Bank code must be 3 or 5 digits")
28+
}
29+
30+
val nubanSerialNumber = accountNumber.take(9)
31+
val checkDigit = Character.getNumericValue(accountNumber.last())
32+
33+
val validatedCheckDigit = 10
34+
.minus(
35+
(formattedBankCode + nubanSerialNumber)
36+
.mapIndexed { index, char -> Character.getNumericValue(char) * ALGORITHM[index] }
37+
.sum()
38+
.rem(10)
39+
)
40+
.rem(10)
41+
42+
return checkDigit == validatedCheckDigit
43+
}
44+
}

0 commit comments

Comments
 (0)