Skip to content

Commit

Permalink
mandatory DbtrAgt (backport)
Browse files Browse the repository at this point in the history
fixes #17
  • Loading branch information
pblanchardie committed Jan 3, 2025
1 parent 3b07f50 commit 2f1ff15
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
23 changes: 17 additions & 6 deletions src/main/java/io/inisos/bank4j/impl/JAXBCreditTransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private CustomerCreditTransferInitiationV03 build() {
paymentInstructionInformationSCT3.setCtrlSum(this.getTotalAmount());
paymentInstructionInformationSCT3.setDbtr(partyIdentification(this.debtor));
paymentInstructionInformationSCT3.setDbtrAcct(cashAccount(this.debtorAccount));
branchAndFinancialInstitutionIdentification(this.debtorAccount).ifPresent(paymentInstructionInformationSCT3::setDbtrAgt);
paymentInstructionInformationSCT3.setDbtrAgt(mandatoryBranchAndFinancialInstitutionIdentification(this.debtorAccount));

if(this.serviceLevelCode != null) {
ServiceLevel8Choice serviceLevel = new ServiceLevel8Choice();
Expand Down Expand Up @@ -179,28 +179,28 @@ private CreditTransferTransactionInformation10 transaction(Transaction transacti

transaction.getChargeBearerCode().ifPresent(creditTransferTransactionInformation::setChrgBr);

branchAndFinancialInstitutionIdentification(transaction.getAccount()).ifPresent(creditTransferTransactionInformation::setCdtrAgt);
optionalBranchAndFinancialInstitutionIdentificationOpt(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);
optionalBranchAndFinancialInstitutionIdentificationOpt(first).ifPresent(creditTransferTransactionInformation::setIntrmyAgt1);
}
if (intermediaryAgentsIterator.hasNext()) {
BankAccount second = intermediaryAgentsIterator.next();
creditTransferTransactionInformation.setIntrmyAgt2Acct(cashAccount(second));
branchAndFinancialInstitutionIdentification(second).ifPresent(creditTransferTransactionInformation::setIntrmyAgt2);
optionalBranchAndFinancialInstitutionIdentificationOpt(second).ifPresent(creditTransferTransactionInformation::setIntrmyAgt2);
}
if (intermediaryAgentsIterator.hasNext()) {
BankAccount third = intermediaryAgentsIterator.next();
creditTransferTransactionInformation.setIntrmyAgt3Acct(cashAccount(third));
branchAndFinancialInstitutionIdentification(third).ifPresent(creditTransferTransactionInformation::setIntrmyAgt3);
optionalBranchAndFinancialInstitutionIdentificationOpt(third).ifPresent(creditTransferTransactionInformation::setIntrmyAgt3);
}

return creditTransferTransactionInformation;
}

private Optional<BranchAndFinancialInstitutionIdentification4> branchAndFinancialInstitutionIdentification(BankAccount bankAccount) {
private Optional<BranchAndFinancialInstitutionIdentification4> optionalBranchAndFinancialInstitutionIdentificationOpt(BankAccount bankAccount) {
return bankAccount.getBic().map(bic -> {
BicUtil.validate(bic);
FinancialInstitutionIdentification7 financialInstitutionIdentification = new FinancialInstitutionIdentification7();
Expand All @@ -211,6 +211,17 @@ private Optional<BranchAndFinancialInstitutionIdentification4> branchAndFinancia
});
}

private BranchAndFinancialInstitutionIdentification4 mandatoryBranchAndFinancialInstitutionIdentification(BankAccount bankAccount) {
BranchAndFinancialInstitutionIdentification4 branchAndFinancialInstitutionIdentification = new BranchAndFinancialInstitutionIdentification4();
FinancialInstitutionIdentification7 financialInstitutionIdentification = new FinancialInstitutionIdentification7();
bankAccount.getBic().ifPresent(bic -> {
BicUtil.validate(bic);
financialInstitutionIdentification.setBIC(bic);
});
branchAndFinancialInstitutionIdentification.setFinInstnId(financialInstitutionIdentification);
return branchAndFinancialInstitutionIdentification;
}

private PartyIdentification32 partyIdentification(Party party) {
PartyIdentification32 partyIdentification = new PartyIdentification32();
if (party != null) {
Expand Down
Loading

0 comments on commit 2f1ff15

Please sign in to comment.