Skip to content

Commit

Permalink
add intermediary agents on transactions
Browse files Browse the repository at this point in the history
resolves #9
  • Loading branch information
pblanchardie committed Oct 31, 2023
1 parent 9ca2962 commit 7183874
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 12 deletions.
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ class MyApp {
.currency("EUR") // Currency code
.endToEndId("Transfer reference 2") // End to end identifier
.id("Optional identifier 2") // Optional transaction identifier
.intermediaryAgent(Bank.simpleBankAccount() // Optional intermediary agent 1
.name("BNP PARIBAS") // Optional name
.otherId("12345") // Optional other identification
.bic("BNPAFRPP") // Optional BIC
.build())
.intermediaryAgent(Bank.simpleBankAccount() // Optional intermediary agent 2
.name("BNP PARIBAS") // Optional name
.otherId("67890") // Optional other identification
.bic("BNPAFRPP") // Optional BIC
.build())
.intermediaryAgent(Bank.simpleBankAccount() // Optional intermediary agent 3
.name("BNP PARIBAS") // Optional name
.otherId("00000") // Optional other identification
.bic("BNPAFRPP") // Optional BIC
.build())
.build();

// Transfer
Expand Down Expand Up @@ -122,7 +137,7 @@ Output with formatting:
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>MYID</MsgId>
<CreDtTm>2023-10-25T09:47:05.187</CreDtTm>
<CreDtTm>2023-10-31T11:09:49.921</CreDtTm>
<NbOfTxs>2</NbOfTxs>
<CtrlSum>69.12</CtrlSum>
<InitgPty>
Expand All @@ -140,7 +155,7 @@ Output with formatting:
<Cd>SEPA</Cd>
</SvcLvl>
</PmtTpInf>
<ReqdExctnDt>2023-10-26</ReqdExctnDt>
<ReqdExctnDt>2023-11-01</ReqdExctnDt>
<Dbtr>
<Nm>Debtor Name</Nm>
</Dbtr>
Expand Down Expand Up @@ -190,6 +205,45 @@ Output with formatting:
<Amt>
<InstdAmt Ccy="EUR">56.78</InstdAmt>
</Amt>
<IntrmyAgt1>
<FinInstnId>
<BIC>BNPAFRPP</BIC>
</FinInstnId>
</IntrmyAgt1>
<IntrmyAgt1Acct>
<Id>
<Othr>
<Id>12345</Id>
</Othr>
</Id>
<Nm>BNP PARIBAS</Nm>
</IntrmyAgt1Acct>
<IntrmyAgt2>
<FinInstnId>
<BIC>BNPAFRPP</BIC>
</FinInstnId>
</IntrmyAgt2>
<IntrmyAgt2Acct>
<Id>
<Othr>
<Id>67890</Id>
</Othr>
</Id>
<Nm>BNP PARIBAS</Nm>
</IntrmyAgt2Acct>
<IntrmyAgt3>
<FinInstnId>
<BIC>BNPAFRPP</BIC>
</FinInstnId>
</IntrmyAgt3>
<IntrmyAgt3Acct>
<Id>
<Othr>
<Id>00000</Id>
</Othr>
</Id>
<Nm>BNP PARIBAS</Nm>
</IntrmyAgt3Acct>
<CdtrAgt>
<FinInstnId>
<BIC>BDFEFRPP</BIC>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/inisos/bank4j/Transaction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.inisos.bank4j;

import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

/**
Expand Down Expand Up @@ -37,4 +38,9 @@ public interface Transaction {
* @return optional identifier
*/
Optional<String> getId();

/**
* @return intermediary agents
*/
List<BankAccount> getIntermediaryAgents();
}
5 changes: 5 additions & 0 deletions src/main/java/io/inisos/bank4j/TransactionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigDecimal;
import java.util.Currency;
import java.util.List;

public interface TransactionBuilder {

Expand Down Expand Up @@ -37,5 +38,9 @@ default TransactionBuilder currency(String currencyCode) {

TransactionBuilder id(String id);

TransactionBuilder intermediaryAgents(List<BankAccount> intermediaryAgents);

TransactionBuilder intermediaryAgent(BankAccount intermediaryAgent);

Transaction build();
}
21 changes: 17 additions & 4 deletions src/main/java/io/inisos/bank4j/impl/JAXBCreditTransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.*;

/**
* A JAXB ISO 20022 Credit Transfer with PAIN.001.001.03
Expand Down Expand Up @@ -170,6 +167,22 @@ private CreditTransferTransactionInformation10 transaction(Transaction transacti
creditTransferTransactionInformation.setCdtr(partyIdentification(transaction.getParty().orElse(null)));
creditTransferTransactionInformation.setCdtrAcct(cashAccount(transaction.getAccount()));
branchAndFinancialInstitutionIdentification(transaction.getAccount()).ifPresent(creditTransferTransactionInformation::setCdtrAgt);
Iterator<BankAccount> intermediaryAgentsIterator = transaction.getIntermediaryAgents().iterator();
if (intermediaryAgentsIterator.hasNext()) {
BankAccount first = intermediaryAgentsIterator.next();
creditTransferTransactionInformation.setIntrmyAgt1Acct(cashAccount(first));
branchAndFinancialInstitutionIdentification(first).ifPresent(creditTransferTransactionInformation::setIntrmyAgt1);
}
if (intermediaryAgentsIterator.hasNext()) {
BankAccount second = intermediaryAgentsIterator.next();
creditTransferTransactionInformation.setIntrmyAgt2Acct(cashAccount(second));
branchAndFinancialInstitutionIdentification(second).ifPresent(creditTransferTransactionInformation::setIntrmyAgt2);
}
if (intermediaryAgentsIterator.hasNext()) {
BankAccount third = intermediaryAgentsIterator.next();
creditTransferTransactionInformation.setIntrmyAgt3Acct(cashAccount(third));
branchAndFinancialInstitutionIdentification(third).ifPresent(creditTransferTransactionInformation::setIntrmyAgt3);
}

return creditTransferTransactionInformation;
}
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/io/inisos/bank4j/impl/SimpleTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import io.inisos.bank4j.Transaction;

import java.math.BigDecimal;
import java.util.Currency;
import java.util.Objects;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.*;

/**
* Simple Transaction
Expand All @@ -23,14 +20,19 @@ public class SimpleTransaction implements Transaction {
private final Currency currency;
private final String endToEndId;
private final String id;
private final List<BankAccount> intermediaryAgents;

public SimpleTransaction(Party party, BankAccount account, BigDecimal amount, Currency currency, String endToEndId, String id) {
public SimpleTransaction(Party party, BankAccount account, BigDecimal amount, Currency currency, String endToEndId, String id, List<BankAccount> intermediaryAgents) {
this.party = party;
this.account = Objects.requireNonNull(account, "Account cannot be null");
this.amount = Objects.requireNonNull(amount, "Amount cannot be null");
this.currency = Objects.requireNonNull(currency, "Currency cannot be null");
this.endToEndId = Objects.requireNonNull(endToEndId, "End to end id cannot be null");
this.id = id;
this.intermediaryAgents = Optional.ofNullable(intermediaryAgents).orElse(Collections.emptyList());
if (this.intermediaryAgents.size() > 3) {
throw new IllegalArgumentException("Intermediary agents cannot be more than 3");
}
}

@Override
Expand Down Expand Up @@ -63,6 +65,11 @@ public Optional<String> getId() {
return Optional.ofNullable(id);
}

@Override
public List<BankAccount> getIntermediaryAgents() {
return intermediaryAgents;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.inisos.bank4j.TransactionBuilder;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Currency;
import java.util.List;

public class SimpleTransactionBuilder implements TransactionBuilder {
private Party party;
Expand All @@ -14,6 +16,7 @@ public class SimpleTransactionBuilder implements TransactionBuilder {
private Currency currency;
private String endToEndId;
private String id;
private final List<BankAccount> intermediaryAgents = new ArrayList<>();

@Override
public SimpleTransactionBuilder party(Party party) {
Expand Down Expand Up @@ -51,8 +54,20 @@ public SimpleTransactionBuilder id(String id) {
return this;
}

@Override
public TransactionBuilder intermediaryAgents(List<BankAccount> intermediaryAgents) {
this.intermediaryAgents.addAll(intermediaryAgents);
return this;
}

@Override
public TransactionBuilder intermediaryAgent(BankAccount intermediaryAgent) {
this.intermediaryAgents.add(intermediaryAgent);
return this;
}

@Override
public SimpleTransaction build() {
return new SimpleTransaction(party, account, amount, currency, endToEndId, id);
return new SimpleTransaction(party, account, amount, currency, endToEndId, id, intermediaryAgents);
}
}

0 comments on commit 7183874

Please sign in to comment.