@@ -1035,6 +1035,62 @@ object LocalMappedConnector extends Connector with MdcLoggable {
10351035 }
10361036 }
10371037
1038+ // this is for the bankAccount from external, maybe can not get any account, so we will create a in-memory account for payments.
1039+ override def getOtherBankAccountByNumber (bankId : Option [BankId ], accountNumber : String , counterparty : Option [CounterpartyTrait ], callContext : Option [CallContext ]) : OBPReturnType [Box [(BankAccount )]] =
1040+ Future {
1041+ // First try to get the account using existing method
1042+ val existingAccount = getBankAccountByNumber(bankId, accountNumber, callContext)
1043+
1044+ Await .result(existingAccount, 5 .seconds)._1 match {
1045+ case Full (account) =>
1046+ // If account found, return it
1047+ (Full (account), callContext)
1048+ case _ =>
1049+ // If account not found, create in-memory account from counterparty if available
1050+ counterparty match {
1051+ case Some (cp) =>
1052+ // Create in-memory account similar to BankingData.getBankAccountFromCounterparty
1053+ val accountRouting1 =
1054+ if (cp.otherAccountRoutingScheme.isEmpty) Nil
1055+ else List (AccountRouting (cp.otherAccountRoutingScheme, cp.otherAccountRoutingAddress))
1056+ val accountRouting2 =
1057+ if (cp.otherAccountSecondaryRoutingScheme.isEmpty) Nil
1058+ else List (AccountRouting (cp.otherAccountSecondaryRoutingScheme, cp.otherAccountSecondaryRoutingAddress))
1059+
1060+ // Due to the new field in the database, old counterparty have void currency, so by default, we set it to EUR
1061+ val counterpartyCurrency = if (cp.currency.nonEmpty) cp.currency else " EUR"
1062+
1063+ val inMemoryAccount = BankAccountCommons (
1064+ AccountId (if (cp.otherAccountSecondaryRoutingAddress.nonEmpty) cp.otherAccountSecondaryRoutingAddress else accountNumber),
1065+ " " , 0 ,
1066+ currency = counterpartyCurrency,
1067+ name = cp.name,
1068+ " " , accountNumber,
1069+ BankId (cp.otherBankRoutingAddress),
1070+ new Date (), " " ,
1071+ accountRoutings = accountRouting1 ++ accountRouting2,
1072+ List .empty,
1073+ accountHolder = cp.name,
1074+ Some (List (Attribute (
1075+ name = " BANK_ROUTING_SCHEME" ,
1076+ `type` = " STRING" ,
1077+ value = cp.otherBankRoutingScheme
1078+ ),
1079+ Attribute (
1080+ name = " BANK_ROUTING_ADDRESS" ,
1081+ `type` = " STRING" ,
1082+ value = cp.otherBankRoutingAddress
1083+ ),
1084+ ))
1085+ )
1086+ (Full (inMemoryAccount), callContext)
1087+ case None =>
1088+ // No counterparty provided, return failure
1089+ (Failure (s " $InvalidAccountNumber, current AccountNumber is $accountNumber and no counterparty provided for creating in-memory account " ), callContext)
1090+ }
1091+ }
1092+ }
1093+
10381094 override def getBankAccountByRoutings (
10391095 bankAccountRoutings : BankAccountRoutings ,
10401096 callContext : Option [CallContext ]
0 commit comments