From 31cc427fd27d4e5c7255308c581014036bea8049 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 29 Apr 2020 18:41:46 +0200 Subject: [PATCH] Implemented transferring money with pain.001.003.03 (outdated but the only version supported by most German banks) --- .../dankito/fints/messages/MessageBuilder.kt | 4 +++ .../sepa/SepaEinzelueberweisung.kt | 2 +- .../main/resources/sepa/pain.001.003.03.xml | 1 + .../sepa/SepaEinzelueberweisungTest.kt | 34 +++++++++++++++++-- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 fints4javaLib/src/main/resources/sepa/pain.001.003.03.xml diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt index 8c5a47b8..3bb16120 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt @@ -239,6 +239,10 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg return Pair(result, urn) } + getSepaUrnFor(CustomerSegmentId.SepaAccountInfoParameters, account, "pain.001.003.03")?.let { urn -> + return Pair(result, urn) + } + return Pair(MessageBuilderResult(true, false, result.allowedVersions, result.supportedVersions, null), null) // TODO: how to tell that we don't support required SEPA pain version? } diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisung.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisung.kt index adc8b064..ac8852fe 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisung.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisung.kt @@ -20,7 +20,7 @@ open class SepaEinzelueberweisung( CustomerSegmentId.SepaBankTransfer, 1, sepaDescriptorUrn, - "pain.001.001.03.xml", + if (sepaDescriptorUrn.contains("pain.001.003.03", true)) "pain.001.003.03.xml" else "pain.001.001.03.xml", account.iban ?: "", // TODO: what to do if iban is not set? debitorBic, mapOf( diff --git a/fints4javaLib/src/main/resources/sepa/pain.001.003.03.xml b/fints4javaLib/src/main/resources/sepa/pain.001.003.03.xml new file mode 100644 index 00000000..92a727ee --- /dev/null +++ b/fints4javaLib/src/main/resources/sepa/pain.001.003.03.xml @@ -0,0 +1 @@ +$MessageId$$CreationDateTime$$NumberOfTransactions$$DebitorName$$PaymentInformationId$TRFtrue$NumberOfTransactions$$Amount$SEPA$RequestedExecutionDate$$DebitorName$$DebitorIban$$DebitorBic$SLEVNOTPROVIDED$Amount$$CreditorBic$$CreditorName$$CreditorIban$$Usage$ \ No newline at end of file diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisungTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisungTest.kt index 40eb473a..7548322c 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisungTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaEinzelueberweisungTest.kt @@ -9,10 +9,8 @@ import org.junit.Test class SepaEinzelueberweisungTest { - @Test - fun format() { + companion object { - // given val segmentNumber = 7 val debitorName = "Nelson Mandela" val debitorIban = "ZA123456780987654321" @@ -23,6 +21,13 @@ class SepaEinzelueberweisungTest { val amount = 1234.56.toBigDecimal() val usage = "What should Mahatma Gandhi want with money?" + } + + + @Test + fun format_Pain001_001_03() { + + // given val underTest = SepaEinzelueberweisung(segmentNumber, "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03", CustomerData("", "", "", debitorName), @@ -40,4 +45,27 @@ class SepaEinzelueberweisungTest { assertThat(result).contains(debitorName, debitorIban, debitorBic, creditorName, creditorIban, creditorBic, amount.toString(), usage, "urn?:iso?:std?:iso?:20022?:tech?:xsd?:pain.001.001.03") } + + @Test + fun format_Pain001_003_03() { + + // given + val underTest = SepaEinzelueberweisung(segmentNumber, + "urn:iso:std:iso:20022:tech:xsd:pain.001.003.03", + CustomerData("", "", "", debitorName), + AccountData("", null, 0, "", debitorIban, "", null, null, "", null, null, listOf()), + debitorBic, + BankTransferData(creditorName, creditorIban, creditorBic, amount, usage) + ) + + + // when + val result = underTest.format() + + + // then + assertThat(result).contains(debitorName, debitorIban, debitorBic, creditorName, creditorIban, creditorBic, + amount.toString(), usage, "urn?:iso?:std?:iso?:20022?:tech?:xsd?:pain.001.003.03") + } + } \ No newline at end of file