Skip to content

Commit e456516

Browse files
authored
Merge pull request #2598 from hongwei1/feature/addNewMethod
Feature/add new method
2 parents 0481dd3 + 8077ac0 commit e456516

4 files changed

Lines changed: 79 additions & 5 deletions

File tree

‎obp-api/src/main/scala/code/api/util/NewStyle.scala‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ object NewStyle extends MdcLoggable{
450450
(unboxFullOrFail(i._1, callContext, s"$BankAccountNotFound Current BankId is $bankId and Current AccountNumber is $accountNumber", 404), i._2)
451451
}
452452

453+
// This method handles external bank accounts that may not exist in our database.
454+
// If the account is not found, we create an in-memory account using counterparty information for payment processing.
455+
def getOtherBankAccountByNumber(bankId : Option[BankId], accountNumber : String, counterparty: Option[CounterpartyTrait], callContext: Option[CallContext]) : OBPReturnType[(BankAccount)] = {
456+
Connector.connector.vend.getOtherBankAccountByNumber(bankId, accountNumber, counterparty, callContext) } map { i =>
457+
(unboxFullOrFail(i._1, callContext, s"$BankAccountNotFound Current BankId is $bankId and Current AccountNumber is $accountNumber", 404), i._2)
458+
}
459+
453460
def getBankSettlementAccounts(bankId: BankId, callContext: Option[CallContext]): OBPReturnType[List[BankAccount]] = {
454461
Connector.connector.vend.getBankSettlementAccounts(bankId: BankId, callContext: Option[CallContext]) map { i =>
455462
(unboxFullOrFail(i._1, callContext,s"$BankNotFound Current BankId is $bankId", 404 ), i._2)

‎obp-api/src/main/scala/code/bankconnectors/Connector.scala‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ trait Connector extends MdcLoggable {
530530

531531
def getBankAccountByNumber(bankId : Option[BankId], accountNumber : String, callContext: Option[CallContext]) : OBPReturnType[Box[(BankAccount)]] = Future {(Failure(setUnimplementedError(nameOf(getBankAccountByNumber _))), callContext)}
532532

533+
// This method handles external bank accounts that may not exist in our database.
534+
// If the account is not found, we create an in-memory account using counterparty information for payment processing.
535+
//TODO understand more about this method.
536+
def getOtherBankAccountByNumber(bankId : Option[BankId], accountNumber : String, counterparty: Option[CounterpartyTrait], callContext: Option[CallContext]) : OBPReturnType[Box[(BankAccount)]] = Future {(Failure(setUnimplementedError(nameOf(getOtherBankAccountByNumber _))), callContext)}
537+
533538
def getBankAccountByRoutings(bankAccountRoutings: BankAccountRoutings, callContext: Option[CallContext]) : OBPReturnType[Box[(BankAccount)]] = Future {(Failure(setUnimplementedError(nameOf(getBankAccountByRoutings _))), callContext)}
534539

535540
def getCounterpartyFromTransaction(bankId: BankId, accountId: AccountId, counterpartyId: String, callContext: Option[CallContext]): OBPReturnType[Box[Counterparty]] = Future {(Failure(setUnimplementedError(nameOf(checkBankAccountExists _))), callContext)}

‎obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala‎

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,15 +1026,76 @@ object LocalMappedConnector extends Connector with MdcLoggable {
10261026
else
10271027
s"$AccountNumberNotUniqueError, current BankId is ${bankId.head.value}, AccountNumber is $accountNumber"
10281028

1029-
if(bankAccounts.length > 1){
1029+
if(bankAccounts.length > 1){ // If the account number is not unique, return the error message
10301030
(Failure(errorMessage), callContext)
1031-
}else if (bankAccounts.length == 1){
1031+
}else if (bankAccounts.length == 1){ // If the account number is unique, return the account
10321032
(Full(bankAccounts.head), callContext)
1033-
}else{
1034-
(Failure(errorMessage), callContext)
1033+
}else{ // If the account number is not found, return the error message
1034+
(Failure(s"$InvalidAccountNumber, current AccountNumber is $accountNumber"), callContext)
10351035
}
10361036
}
10371037

1038+
// This method handles external bank accounts that may not exist in our database.
1039+
// If the account is not found, we create an in-memory account using counterparty information for payment processing.
1040+
override def getOtherBankAccountByNumber(bankId : Option[BankId], accountNumber : String, counterparty: Option[CounterpartyTrait], callContext: Option[CallContext]) : OBPReturnType[Box[(BankAccount)]] = {
1041+
1042+
for {
1043+
(existingAccountBox, updatedCallContext) <- getBankAccountByNumber(bankId, accountNumber, callContext)
1044+
(finalAccountBox, finalCallContext) <- existingAccountBox match {
1045+
case Full(account) =>
1046+
// If account found in database, return it
1047+
Future.successful((Full(account), updatedCallContext))
1048+
case _ =>
1049+
// If account not found, check if we can create in-memory account
1050+
counterparty match {
1051+
case Some(cp) =>
1052+
// Create in-memory account using counterparty information
1053+
Future {
1054+
val accountRouting1 =
1055+
if (cp.otherAccountRoutingScheme.isEmpty) Nil
1056+
else List(AccountRouting(cp.otherAccountRoutingScheme, cp.otherAccountRoutingAddress))
1057+
val accountRouting2 =
1058+
if (cp.otherAccountSecondaryRoutingScheme.isEmpty) Nil
1059+
else List(AccountRouting(cp.otherAccountSecondaryRoutingScheme, cp.otherAccountSecondaryRoutingAddress))
1060+
1061+
// Due to the new field in the database, old counterparty have void currency, so by default, we set it to EUR
1062+
val counterpartyCurrency = if (cp.currency.nonEmpty) cp.currency else "EUR"
1063+
1064+
val inMemoryAccount = BankAccountCommons(
1065+
AccountId(if (cp.otherAccountSecondaryRoutingAddress.nonEmpty) cp.otherAccountSecondaryRoutingAddress else accountNumber),
1066+
"", 0,
1067+
currency = counterpartyCurrency,
1068+
name = cp.name,
1069+
"", accountNumber,
1070+
BankId(cp.otherBankRoutingAddress),
1071+
new Date(), "",
1072+
accountRoutings = accountRouting1 ++ accountRouting2,
1073+
List.empty,
1074+
accountHolder = cp.name,
1075+
Some(List(Attribute(
1076+
name = "BANK_ROUTING_SCHEME",
1077+
`type` = "STRING",
1078+
value = cp.otherBankRoutingScheme
1079+
),
1080+
Attribute(
1081+
name = "BANK_ROUTING_ADDRESS",
1082+
`type` = "STRING",
1083+
value = cp.otherBankRoutingAddress
1084+
),
1085+
))
1086+
)
1087+
(Full(inMemoryAccount), updatedCallContext)
1088+
}
1089+
case None =>
1090+
// No counterparty provided, return failure
1091+
Future.successful((Failure(s"$InvalidAccountNumber, current AccountNumber is $accountNumber and no counterparty provided for creating in-memory account"), updatedCallContext))
1092+
}
1093+
}
1094+
} yield {
1095+
(finalAccountBox, finalCallContext)
1096+
}
1097+
}
1098+
10381099
override def getBankAccountByRoutings(
10391100
bankAccountRoutings: BankAccountRoutings,
10401101
callContext: Option[CallContext]

‎obp-api/src/main/scala/code/model/BankingData.scala‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,10 @@ object BankAccountX {
476476
else if (counterparty.otherAccountRoutingScheme.equalsIgnoreCase("ACCOUNT_NUMBER")|| counterparty.otherAccountRoutingScheme.equalsIgnoreCase("ACCOUNT_NO")){
477477
for{
478478
bankIdOption <- Future.successful(if(counterparty.otherBankRoutingAddress.isEmpty) None else Some(counterparty.otherBankRoutingAddress))
479-
(account, callContext) <- NewStyle.function.getBankAccountByNumber(
479+
(account, callContext) <- NewStyle.function.getOtherBankAccountByNumber(
480480
bankIdOption.map(BankId(_)),
481481
counterparty.otherAccountRoutingAddress,
482+
Some(counterparty),
482483
callContext)
483484
} yield {
484485
(Full(account), callContext)

0 commit comments

Comments
 (0)