Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions .docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,20 @@ stop injection where the text is used:

The same holds for the symbols, which are digits only, and the account numbers, which are checked, only less so.

`BankAccount` is `[prefix-]number/bankCode`, without leading zeros, so the same account is equal however it was written,
and it checks the Czech National Bank's modulo 11 rule: an account number misread from an e-mail is refused, not handed
out. `BankAccount.parse("19-2000145399/0800")` reads one, for comparing against yours. `Money` and `PaymentSymbols` have
the same shape as in `moneta-api-java`.
`BankAccount` is a Czech or Slovak account, its `country()` with `[prefix-]number/bankCode`, without leading zeros, so
the same account is equal however it was written: its local form and its IBAN compare equal. It checks the modulo 11
rule both countries share, and an IBAN's modulo 97 digits, so an account number misread from an e-mail is refused, not
handed out. To compare against yours:

| You have | Read it with |
|---|---|
| `19-2000145399/0800`, Czech | `BankAccount.parse("19-2000145399/0800", Country.CZ)` |
| `4019425381/7500`, Slovak | `BankAccount.parse("4019425381/7500", Country.SK)` |
| `CZ65 0800 0000 1920 0014 5399` | `BankAccount.parseIban("CZ65 0800 0000 1920 0014 5399")`, with or without spaces; the IBAN says the country |

A local form does not say its country, so `parse` takes it: there is no default. `iban()` writes the IBAN back,
`toString()` the local form. The same digits under a Czech and a Slovak bank code are two
accounts. `Money` and `PaymentSymbols` have the same shape as in `moneta-api-java`.

## Two checks stay with you

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public Transaction parse(@Nullable String subject, String body) {
// Both lines this parser reads say "úhrada", a transfer. A card payment or a direct debit, once
// seen, is a line of its own.
Transaction.Type.TRANSFER,
BankAccount.parse(summary.group(1)),
BankAccount.parse(counterAccount),
BankAccount.parse(summary.group(1), Country.CZ),
BankAccount.parse(counterAccount, Country.CZ),
counterName,
direction == Direction.INCOMING ? signed : signed.negate(),
new PaymentSymbols(variableSymbol, constantSymbol, specificSymbol),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void readsAnIncomingPayment() throws IOException {
"airbank.cz",
Direction.INCOMING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/3030"),
BankAccount.parse("9876543211/2010"),
BankAccount.parse("1234567899/3030", Country.CZ),
BankAccount.parse("9876543211/2010", Country.CZ),
"Novák, Jan",
czk("1.00"),
new PaymentSymbols("1337", null, null),
Expand All @@ -59,8 +59,8 @@ void readsAnOutgoingPaymentAsANegativeAmount() throws IOException {
"airbank.cz",
Direction.OUTGOING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/3030"),
BankAccount.parse("9876543211/2010"),
BankAccount.parse("1234567899/3030", Country.CZ),
BankAccount.parse("9876543211/2010", Country.CZ),
null,
czk("-1.00"),
new PaymentSymbols("7331", null, null),
Expand All @@ -81,8 +81,8 @@ void readsTheMessageAndAllThreeSymbolsOfAnIncomingPayment() throws IOException {
"airbank.cz",
Direction.INCOMING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/3030"),
BankAccount.parse("9876543211/2010"),
BankAccount.parse("1234567899/3030", Country.CZ),
BankAccount.parse("9876543211/2010", Country.CZ),
"Novák, Jan",
czk("1.00"),
new PaymentSymbols("1337", "1234", "123456789"),
Expand Down Expand Up @@ -183,7 +183,7 @@ void readsTheRecipientsNameOfAnOutgoingPaymentWhenTheBankPrintsIt() throws IOExc
Transaction parsed = BankNotifications.parseUnverified(bytes(changed));

assertEquals("Wayne Enterprises s.r.o.", parsed.counterName());
assertEquals(BankAccount.parse("9876543211/2010"), parsed.counterAccount());
assertEquals(BankAccount.parse("9876543211/2010", Country.CZ), parsed.counterAccount());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public Transaction parse(@Nullable String subject, String body) {
DOMAIN,
direction,
kind.equals("Příchozí úhrada") ? Transaction.Type.TRANSFER : Transaction.Type.GENERAL,
BankAccount.parse(summary.group(1)),
BankAccount.parse(summary.group(1), Country.CZ),
counterNumber == null || counterBank == null
? null
: BankAccount.parse(counterNumber + "/" + counterBank),
: BankAccount.parse(counterNumber + "/" + counterBank, Country.CZ),
null,
direction == Direction.INCOMING ? amount : amount.negate(),
new PaymentSymbols(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void readsAnIncomingPaymentFromItsSentenceAndList() throws IOException {
"creditas.cz",
Direction.INCOMING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/2250"),
BankAccount.parse("9876543211/0800"),
BankAccount.parse("1234567899/2250", Country.CZ),
BankAccount.parse("9876543211/0800", Country.CZ),
null,
czk("1000.00"),
new PaymentSymbols("123456", null, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ private static Block block(List<String> block) {
DOMAIN,
direction,
kind.equals(CARD) ? Transaction.Type.CARD : Transaction.Type.TRANSFER,
BankAccount.parse(own.group(1) + "/" + BANK_CODE),
counter == null ? null : BankAccount.parse(counter),
BankAccount.parse(own.group(1) + "/" + BANK_CODE, Country.CZ),
counter == null ? null : BankAccount.parse(counter, Country.CZ),
fields.get(COUNTER_NAME),
amount,
new PaymentSymbols(
Expand Down Expand Up @@ -195,8 +195,8 @@ private static Transaction ownBanking(String body) {
DOMAIN,
direction,
Transaction.Type.TRANSFER,
BankAccount.parse(own.group(1) + "/" + BANK_CODE),
counter == null ? null : BankAccount.parse(counter),
BankAccount.parse(own.group(1) + "/" + BANK_CODE, Country.CZ),
counter == null ? null : BankAccount.parse(counter, Country.CZ),
fields.get(COUNTER_NAME),
amount,
new PaymentSymbols(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void readsOneBookedPayment() throws IOException {
"csob.cz",
Direction.INCOMING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/0300"),
BankAccount.parse("9876543211/0800"),
BankAccount.parse("1234567899/0300", Country.CZ),
BankAccount.parse("9876543211/0800", Country.CZ),
"Pennyworth Alfred",
czk("1234.56"),
new PaymentSymbols("23456789", "3456", null),
Expand Down Expand Up @@ -59,7 +59,8 @@ void readsEveryTransactionOfAnEMailThatListsSeveral() throws IOException {
assertEquals(2, all.size());
assertEquals(czk("1234.56"), all.get(0).amount());
assertEquals(czk("987.65"), all.get(1).amount());
assertEquals(BankAccount.parse("5555555002/0100"), all.get(1).counterAccount());
assertEquals(
BankAccount.parse("5555555002/0100", Country.CZ), all.get(1).counterAccount());
assertEquals(all.get(0).messageId(), all.get(1).messageId());
}

Expand Down Expand Up @@ -141,8 +142,8 @@ void readsTheOwnBankingNotice() throws IOException {
"csob.cz",
Direction.INCOMING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/0300"),
BankAccount.parse("9876543211/2700"),
BankAccount.parse("1234567899/0300", Country.CZ),
BankAccount.parse("9876543211/2700", Country.CZ),
"WAYNE ENTERPRISES",
czk("10000.00"),
PaymentSymbols.NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Transaction parse(@Nullable String subject, String body) {
if (counterParty != null) {
Matcher counter = COUNTER.matcher(counterParty);
if (!counter.matches()) throw new Unparsed("counter-party not in the known format");
counterAccount = BankAccount.parse(counter.group(1));
counterAccount = BankAccount.parse(counter.group(1), Country.CZ);
counterName = counter.group(2);
}
String balance = fields.get(BALANCE);
Expand All @@ -111,7 +111,7 @@ public Transaction parse(@Nullable String subject, String body) {
DOMAIN,
direction,
type(fields.get(TYPE)),
BankAccount.parse(summary.group("account") + "/" + BANK_CODE),
BankAccount.parse(summary.group("account") + "/" + BANK_CODE, Country.CZ),
counterAccount,
counterName,
direction == Direction.INCOMING ? amount : amount.negate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void readsAnInstantIncomingPayment() throws IOException {
"fio.cz",
Direction.INCOMING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/2010"),
BankAccount.parse("5555555002/0800"),
BankAccount.parse("1234567899/2010", Country.CZ),
BankAccount.parse("5555555002/0800", Country.CZ),
"pennyworth alfred",
czk("1000.00"),
new PaymentSymbols(null, "0", null),
Expand Down Expand Up @@ -65,8 +65,8 @@ void readsAnOutgoingTransferAsANegativeAmount() throws IOException {
"fio.cz",
Direction.OUTGOING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/2010"),
BankAccount.parse("1939000008/5500"),
BankAccount.parse("1234567899/2010", Country.CZ),
BankAccount.parse("1939000008/5500", Country.CZ),
null,
czk("-2768.00"),
PaymentSymbols.NONE,
Expand Down Expand Up @@ -97,7 +97,7 @@ void readsADirectDebit() throws IOException {
assertEquals(Transaction.Type.DIRECT_DEBIT, parsed.type());
assertEquals(czk("-602.00"), parsed.amount());
assertEquals(new PaymentSymbols("1000000042", "0308", null), parsed.symbols());
assertEquals(BankAccount.parse("270000000/0300"), parsed.counterAccount());
assertEquals(BankAccount.parse("270000000/0300", Country.CZ), parsed.counterAccount());
}

@Test
Expand Down Expand Up @@ -211,8 +211,8 @@ void readsTheEnglishTemplate() throws IOException {
"fio.cz",
Direction.INCOMING,
Transaction.Type.GENERAL,
BankAccount.parse("1234567899/2010"),
BankAccount.parse("9876543211/2010"),
BankAccount.parse("1234567899/2010", Country.CZ),
BankAccount.parse("9876543211/2010", Country.CZ),
"Pennyworth, Alfred",
czk("1.00"),
new PaymentSymbols("123456", null, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Transaction parse(@Nullable String subject, String body) {
stated,
Transaction.Type.GENERAL,
null,
counter == null ? null : BankAccount.parse(counter),
counter == null ? null : BankAccount.parse(counter, Country.CZ),
null,
stated == Direction.INCOMING ? value : value.negate(),
new PaymentSymbols(variableSymbol, null, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void readsAnIncomingPaymentWithoutAccountOrTransactionId() throws IOException {
Direction.INCOMING,
Transaction.Type.GENERAL,
null,
BankAccount.parse("9876543211/0300"),
BankAccount.parse("9876543211/0300", Country.CZ),
null,
czk("35000.00"),
new PaymentSymbols("202600009", null, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public Transaction parse(@Nullable String subject, String body) {
DOMAIN,
direction,
card ? Transaction.Type.CARD : Transaction.Type.TRANSFER,
BankAccount.parse(own.group(1)),
counter == null ? null : BankAccount.parse(counter.group(1)),
BankAccount.parse(own.group(1), Country.CZ),
counter == null ? null : BankAccount.parse(counter.group(1), Country.CZ),
counter == null || counter.group(2).isBlank()
? null
: counter.group(2).strip(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void readsAnIncomingPaymentFromHtml() throws IOException {
"rb.cz",
Direction.INCOMING,
Transaction.Type.TRANSFER,
BankAccount.parse("1234567899/5500"),
BankAccount.parse("9876543211/0100"),
BankAccount.parse("1234567899/5500", Country.CZ),
BankAccount.parse("9876543211/0100", Country.CZ),
"Pennyworth Alfred",
czk("1234.56"),
new PaymentSymbols("2606001", "308", null),
Expand All @@ -53,7 +53,7 @@ void readsACardPaymentWithItsDetailsAsTheMessage() throws IOException {
assertEquals(Transaction.Type.CARD, card.type());
assertEquals(Direction.OUTGOING, card.direction());
assertEquals(czk("-1234.56"), card.amount());
assertEquals(BankAccount.parse("1234567899/5500"), card.account());
assertEquals(BankAccount.parse("1234567899/5500", Country.CZ), card.account());
assertNull(card.counterAccount());
assertEquals("DEMO SOFTWARE; PRAHA; CZE", card.message());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public Transaction parse(@Nullable String subject, String body) {
DOMAIN,
direction,
Transaction.Type.GENERAL,
BankAccount.parse(sentence.group(1) + "/" + BANK_CODE),
counter == null ? null : BankAccount.parse(counter),
BankAccount.parse(sentence.group(1) + "/" + BANK_CODE, Country.CZ),
counter == null ? null : BankAccount.parse(counter, Country.CZ),
fields.get(COUNTER_NAME),
direction == Direction.INCOMING ? value : value.negate(),
new PaymentSymbols(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void readsAnIncomingPaymentWithAnEnglishAmount() throws IOException {
"unicreditgroup.cz",
Direction.INCOMING,
Transaction.Type.GENERAL,
BankAccount.parse("1234567899/2700"),
BankAccount.parse("9876543211/0600"),
BankAccount.parse("1234567899/2700", Country.CZ),
BankAccount.parse("9876543211/0600", Country.CZ),
"WAYNE ENTERPRISES s.r.o.",
czk("20546.00"),
new PaymentSymbols("0002026017", null, null),
Expand Down
Loading
Loading