From 4dc5ee052becbee21b95ceb6b0a386d8f6542f55 Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 8 Apr 2020 13:10:47 +0200 Subject: [PATCH] added the OBP_BANK_ID and OBP_ACCOUNT_ID guards for createCounterparty endpoint and also fixed the relevant payments apis. --- .../scala/code/api/v2_2_0/APIMethods220.scala | 22 +++++++++---------- .../main/scala/code/model/BankingData.scala | 16 ++++++++++---- .../api/v2_1_0/TransactionRequestsTest.scala | 4 ++-- .../api/v4_0_0/TransactionRequestsTest.scala | 4 ++-- .../setup/LocalMappedConnectorTestSetup.scala | 8 +++---- .../scala/code/setup/TestConnectorSetup.scala | 2 +- 6 files changed, 32 insertions(+), 24 deletions(-) diff --git a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala index fe5f11488..328da0445 100644 --- a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala +++ b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala @@ -1038,11 +1038,11 @@ trait APIMethods220 { | |is_beneficiary : must be set to `true` in order to send payments to this counterparty | - |bespoke: It support list of key-value, you can add it to the counterarty. + |bespoke: It support list of key-value, you can add it to the counterparty. | - |bespoke.key : any info-key you want to add to this counerparty + |bespoke.key : any info-key you want to add to this counterparty | - |bespoke.value : any info-value you want to add to this counerparty + |bespoke.value : any info-value you want to add to this counterparty | |The view specified by VIEW_ID must have the canAddCounterparty permission | @@ -1050,9 +1050,9 @@ trait APIMethods220 { | { | "name": "Tesobe1", | "description": "Good Company", - | "other_bank_routing_scheme": "bankId", + | "other_bank_routing_scheme": "OBP_BANK_ID", | "other_bank_routing_address": "gh.29.uk", - | "other_account_routing_scheme": "accountId", + | "other_account_routing_scheme": "OBP_ACCOUNT_ID", | "other_account_routing_address": "8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0", | "is_beneficiary": true, | "other_account_secondary_routing_scheme": "", @@ -1068,9 +1068,9 @@ trait APIMethods220 { | { | "name": "Tesobe2", | "description": "Good Company", - | "other_bank_routing_scheme": "bankId", + | "other_bank_routing_scheme": "OBP_BANK_ID", | "other_bank_routing_address": "gh.29.uk", - | "other_account_routing_scheme": "accountId", + | "other_account_routing_scheme": "OBP_ACCOUNT_ID", | "other_account_routing_address": "8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0", | "other_account_secondary_routing_scheme": "IBAN", | "other_account_secondary_routing_address": "DE89 3704 0044 0532 0130 00", @@ -1118,17 +1118,17 @@ trait APIMethods220 { _ <- booleanToBox(postJson.description.length <= 36, s"$InvalidValueLength. The maximum length of `description` field is ${MappedCounterparty.mDescription.maxLen}") //If other_account_routing_scheme=="OBP_ACCOUNT_ID" or other_account_secondary_routing_address=="OBP_ACCOUNT_ID" we will check if it is a real obp bank account. - _<- if (postJson.other_account_routing_scheme =="OBP_ACCOUNT_ID"){ + _<- if (postJson.other_bank_routing_scheme == "OBP_BANK_ID" && postJson.other_account_routing_scheme =="OBP_ACCOUNT_ID"){ for{ (bank, callContext) <- BankX(BankId(postJson.other_bank_routing_address), Some(cc)) ?~! s"$BankNotFound Current BANK_ID = ${postJson.other_bank_routing_address}." account <- Connector.connector.vend.checkBankAccountExistsLegacy(BankId(postJson.other_bank_routing_address), AccountId(postJson.other_account_routing_address), callContext) ?~! s"$BankAccountNotFound Current BANK_ID = ${postJson.other_bank_routing_address}. and Current ACCOUNT_ID = ${postJson.other_account_routing_address}. " } yield { account } - } else if (postJson.other_account_secondary_routing_address =="OBP_ACCOUNT_ID"){ + } else if (postJson.other_bank_routing_scheme == "OBP_BANK_ID" && postJson.other_account_secondary_routing_scheme=="OBP_ACCOUNT_ID"){ for{ - (bank, callContext) <- BankX(BankId(postJson.other_account_secondary_routing_address), Some(cc)) ?~! s"$BankNotFound Current BANK_ID = ${postJson.other_bank_routing_address}." - account <- Connector.connector.vend.checkBankAccountExistsLegacy(BankId(postJson.other_bank_routing_address), AccountId(postJson.other_account_routing_address), callContext) ?~! s"$BankAccountNotFound Current BANK_ID = ${postJson.other_bank_routing_address}. and Current ACCOUNT_ID = ${postJson.other_account_routing_address}. " + (bank, callContext) <- BankX(BankId(postJson.other_bank_routing_address), Some(cc)) ?~! s"$BankNotFound Current BANK_ID = ${postJson.other_bank_routing_address}." + account <- Connector.connector.vend.checkBankAccountExistsLegacy(BankId(postJson.other_bank_routing_address), AccountId(postJson.other_account_secondary_routing_address), callContext) ?~! s"$BankAccountNotFound Current BANK_ID = ${postJson.other_bank_routing_address}. and Current ACCOUNT_ID = ${postJson.other_account_routing_address}. " } yield { account } diff --git a/obp-api/src/main/scala/code/model/BankingData.scala b/obp-api/src/main/scala/code/model/BankingData.scala index a1451c376..9935f0487 100644 --- a/obp-api/src/main/scala/code/model/BankingData.scala +++ b/obp-api/src/main/scala/code/model/BankingData.scala @@ -499,15 +499,23 @@ object BankAccountX { * @return BankAccount */ def toBankAccount(counterparty: CounterpartyTrait) : Box[BankAccount] = { - if (APIUtil.isSandboxMode) + if (counterparty.otherBankRoutingScheme =="OBP_BANK_ID" && counterparty.otherAccountRoutingScheme =="OBP_ACCOUNT_ID") for{ toBankId <- Full(BankId(counterparty.otherBankRoutingAddress)) toAccountId <- Full(AccountId(counterparty.otherAccountRoutingAddress)) - toAccount <- BankAccountX(toBankId, toAccountId) ?~! s"${ErrorMessages.CounterpartyNotFound} Current Value: BANK_ID(counterparty.otherBankRoutingAddress=$toBankId) and ACCOUNT_ID(counterparty.otherAccountRoutingAddress=$toAccountId), please use correct OBP BankAccount to create the Counterparty.!!!!! " + toAccount <- BankAccountX(toBankId, toAccountId) ?~! s"${ErrorMessages.BankNotFound} Current Value: BANK_ID(counterparty.otherBankRoutingAddress=$toBankId) and ACCOUNT_ID(counterparty.otherAccountRoutingAddress=$toAccountId), please use correct OBP BankAccount to create the Counterparty.!!!!! " } yield{ toAccount } - else + else if (counterparty.otherBankRoutingScheme =="OBP_BANK_ID" && counterparty.otherAccountSecondaryRoutingScheme == "OBP_ACCOUNT_ID") + for{ + toBankId <- Full(BankId(counterparty.otherBankRoutingAddress)) + toAccountId <- Full(AccountId(counterparty.otherAccountSecondaryRoutingAddress)) + toAccount <- BankAccountX(toBankId, toAccountId) ?~! s"${ErrorMessages.BankNotFound} Current Value: BANK_ID(counterparty.otherBankRoutingAddress=$toBankId) and ACCOUNT_ID(counterparty.otherAccountRoutingAddress=$toAccountId), please use correct OBP BankAccount to create the Counterparty.!!!!! " + } yield{ + toAccount + } + else //If we can not create the `BankAccount` from the counterparty, then we just faked the object in memory. Full( BankAccountInMemory( @@ -523,7 +531,7 @@ object BankAccountX { ), - //Can not get from counterparty + bankId = BankId(""), accountId = AccountId(""), accountType = null, diff --git a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala index 48e7d8c75..d0fe5ac61 100644 --- a/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v2_1_0/TransactionRequestsTest.scala @@ -97,9 +97,9 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers { //prepare for counterparty and SEPA stuff //For SEPA, otherAccountRoutingScheme must be 'IBAN' - val counterpartySEPA = createCounterparty(bankId.value, accountId2.value, "IBAN", "IBAN", true, UUID.randomUUID.toString); + val counterpartySEPA = createCounterparty(bankId.value, accountId2.value, true, UUID.randomUUID.toString); //For Counterpart local mapper, the mOtherAccountRoutingScheme='OBP' and mOtherBankRoutingScheme = 'OBP' - val counterpartyCounterparty = createCounterparty(bankId.value, accountId2.value, "IBAN", "OBP", true, UUID.randomUUID.toString); + val counterpartyCounterparty = createCounterparty(bankId.value, accountId2.value, true, UUID.randomUUID.toString); var transactionRequestBodySEPA = TransactionRequestBodySEPAJSON(bodyValue, IbanJson(counterpartySEPA.otherAccountSecondaryRoutingAddress), description, sharedChargePolicy) diff --git a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala index d81c2b2b2..ddd2bb7f7 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/TransactionRequestsTest.scala @@ -111,9 +111,9 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers { //prepare for counterparty and SEPA stuff //For SEPA, otherAccountRoutingScheme must be 'IBAN' - val counterpartySEPA = createCounterparty(bankId.value, accountId2.value, "IBAN", "IBAN", true, UUID.randomUUID.toString); + val counterpartySEPA = createCounterparty(bankId.value, accountId2.value, true, UUID.randomUUID.toString); //For Counterpart local mapper, the mOtherAccountRoutingScheme='OBP' and mOtherBankRoutingScheme = 'OBP' - val counterpartyCounterparty = createCounterparty(bankId.value, accountId2.value, "IBAN", "OBP", true, UUID.randomUUID.toString); + val counterpartyCounterparty = createCounterparty(bankId.value, accountId2.value, true, UUID.randomUUID.toString); var transactionRequestBodySEPA = TransactionRequestBodySEPAJSON(bodyValue, IbanJson(counterpartySEPA.otherAccountSecondaryRoutingAddress), description, sharedChargePolicy) diff --git a/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala b/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala index 6b547c368..83abe726b 100644 --- a/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala +++ b/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala @@ -34,18 +34,18 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis .saveMe } - override protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait = { + override protected def createCounterparty(bankId: String, accountId: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait = { Counterparties.counterparties.vend.createCounterparty( createdByUserId = createdByUserId, thisBankId = bankId, thisAccountId = accountId, thisViewId = "", name = APIUtil.generateUUID(), - otherAccountRoutingScheme = otherAccountRoutingScheme, + otherAccountRoutingScheme = "OBP_ACCOUNT_ID", otherAccountRoutingAddress = accountId, - otherBankRoutingScheme = "OBP", + otherBankRoutingScheme = "OBP_BANK_ID", otherBankRoutingAddress = bankId, - otherBranchRoutingScheme ="OBP", + otherBranchRoutingScheme ="OBP_BRANCH_ID", otherBranchRoutingAddress ="Berlin", isBeneficiary = isBeneficiary, otherAccountSecondaryRoutingScheme ="IBAN", diff --git a/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala b/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala index 979b26a6c..ba3c22b2c 100644 --- a/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala +++ b/obp-api/src/test/scala/code/setup/TestConnectorSetup.scala @@ -20,7 +20,7 @@ trait TestConnectorSetup { protected def createTransactionRequest(account: BankAccount) protected def updateAccountCurrency(bankId: BankId, accountId : AccountId, currency : String) : BankAccount - protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait + protected def createCounterparty(bankId: String, accountId: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait /** * This method, will do 4 things: