Skip to content

Commit

Permalink
Merge pull request #2448 from hongwei1/feature/AddedPaymentAgent
Browse files Browse the repository at this point in the history
Feature/added payment agent tweaks
  • Loading branch information
simonredfern authored Nov 25, 2024
2 parents 3a41f09 + 374ca72 commit e723c3f
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 44 deletions.
3 changes: 2 additions & 1 deletion obp-api/src/main/scala/code/api/util/ErrorMessages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ object ErrorMessages {
val AgentsNotFound = "OBP-30326: Agents not found."
val CreateAgentAccountLinkError = "OBP-30327: Could not create the agent account link."
val AgentNumberAlreadyExists = "OBP-30328: Agent Number already exists. Please specify a different value for BANK_ID or AGENT_NUMBER."
val GetAgentAccountLinksError = "OBP-30226: Could not get the agent account links."
val GetAgentAccountLinksError = "OBP-30329: Could not get the agent account links."
val AgentBeneficiaryPermit = "OBP-30330: The account can not send money to the Agent. Please set the Agent 'is_confirmed_agent' true and `is_pending_agent` false."

// Branch related messages
val BranchesNotFoundLicense = "OBP-32001: No branches available. License may not be set."
Expand Down
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2844,14 +2844,14 @@ object NewStyle extends MdcLoggable{
bankId: String,
legalName : String,
mobileNumber : String,
number : String,
agentNumber : String,
callContext: Option[CallContext]
): OBPReturnType[Agent] =
Connector.connector.vend.createAgent(
bankId: String,
legalName : String,
mobileNumber : String,
number : String,
agentNumber : String,
callContext: Option[CallContext]
) map {
i => (unboxFullOrFail(i._1, callContext, CreateAgentError), i._2)
Expand Down
12 changes: 8 additions & 4 deletions obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12632,11 +12632,15 @@ object APIMethods400 extends RestHelper with APIMethods400 {
json.extract[TransactionRequestBodyAgentJsonV400]
}
(agent, callContext) <- NewStyle.function.getAgentByAgentNumber(BankId(transactionRequestBodyAgent.to.bank_id),transactionRequestBodyAgent.to.agent_number, callContext)
(customerAccountLinks, callContext) <- NewStyle.function.getCustomerAccountLinksByCustomerId(agent.agentId, callContext)
customerAccountLink <- NewStyle.function.tryons(AgentAccountLinkNotFound, 400, callContext) {
customerAccountLinks.head
(agentAccountLinks, callContext) <- NewStyle.function.getAgentAccountLinksByAgentId(agent.agentId, callContext)
agentAccountLink <- NewStyle.function.tryons(AgentAccountLinkNotFound, 400, callContext) {
agentAccountLinks.head
}
(toAccount, callContext) <- NewStyle.function.getBankAccount(BankId(customerAccountLink.bankId), AccountId(customerAccountLink.accountId), callContext)
// Check we can send money to it.
_ <- Helper.booleanToFuture(s"$AgentBeneficiaryPermit", cc=callContext) {
!agent.isPendingAgent && agent.isConfirmedAgent
}
(toAccount, callContext) <- NewStyle.function.getBankAccount(BankId(agentAccountLink.bankId), AccountId(agentAccountLink.accountId), callContext)
chargePolicy = transactionRequestBodyAgent.charge_policy
_ <- Helper.booleanToFuture(s"$InvalidChargePolicy", cc=callContext) {
ChargePolicy.values.contains(ChargePolicy.withName(chargePolicy))
Expand Down
29 changes: 9 additions & 20 deletions obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala
Original file line number Diff line number Diff line change
@@ -1,59 +1,48 @@
package code.api.v5_0_0

import java.util.concurrent.ThreadLocalRandom
import code.accountattribute.AccountAttributeX
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._
import code.api.util.APIUtil._
import code.api.util.ApiRole._
import code.api.util.ApiTag._
import code.api.util.ErrorMessages._
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util.NewStyle.function.extractQueryParams
import code.api.util._
import code.api.v2_1_0.JSONFactory210
import code.api.v3_0_0.JSONFactory300
import code.api.v3_1_0._
import code.api.v4_0_0.JSONFactory400.createCustomersMinimalJson
import code.api.v4_0_0.{JSONFactory400, OBPAPI4_0_0, PostCounterpartyJson400, PutProductJsonV400}
import code.api.v4_0_0.{JSONFactory400, PostCounterpartyJson400}
import code.api.v5_0_0.JSONFactory500.{createPhysicalCardJson, createViewJsonV500, createViewsIdsJsonV500, createViewsJsonV500}
import code.api.v5_1_0.{CreateCustomViewJson, PostCounterpartyLimitV510, PostVRPConsentRequestJsonV510}
import code.bankconnectors.Connector
import code.consent.{ConsentRequest, ConsentRequests, Consents}
import code.consent.{ConsentRequests, Consents}
import code.consumer.Consumers
import code.entitlement.Entitlement
import code.metadata.counterparties.MappedCounterparty
import code.metrics.APIMetrics
import code.model._
import code.model.dataAccess.BankAccountCreation
import com.openbankproject.commons.model.enums.TransactionRequestTypes._
import com.openbankproject.commons.model.enums.TransactionRequestTypes
import code.util.Helper
import code.util.Helper.{SILENCE_IS_GOLDEN, booleanToFuture}
import code.views.Views
import code.views.system.ViewDefinition
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.ExecutionContext.Implicits.global
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication
import com.openbankproject.commons.model._
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication
import com.openbankproject.commons.util.ApiVersion
import com.openbankproject.commons.model.enums.TransactionRequestTypes._
import com.openbankproject.commons.model.enums.PaymentServiceTypes._
import net.liftweb.common.{Empty, Full}
import net.liftweb.http.Req
import net.liftweb.http.rest.RestHelper
import net.liftweb.json
import net.liftweb.json.{Extraction, compactRender, prettyRender}
import net.liftweb.util.Helpers.tryo
import net.liftweb.util.{Helpers, Props, StringHelpers}
import java.util.concurrent.ThreadLocalRandom

import code.accountattribute.AccountAttributeX
import code.api.Constant.SYSTEM_OWNER_VIEW_ID
import code.api.util.FutureUtil.EndpointContext
import code.api.v5_1_0.{CreateCustomViewJson, PostVRPConsentRequestJsonV510, PostCounterpartyLimitV510}
import code.consumer.Consumers
import code.metadata.counterparties.MappedCounterparty
import code.util.Helper.booleanToFuture
import code.views.system.{AccountAccess, ViewDefinition}

import java.util.UUID
import java.util.concurrent.ThreadLocalRandom
import scala.collection.immutable.{List, Nil}
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.Future
Expand Down
5 changes: 2 additions & 3 deletions obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import code.api.util.newstyle.RegulatedEntityNewStyle.{createRegulatedEntityNewS
import code.api.v2_1_0.ConsumerRedirectUrlJSON
import code.api.v3_0_0.JSONFactory300
import code.api.v3_0_0.JSONFactory300.createAggregateMetricJson
import code.api.v3_1_0.{ConsentJsonV310, JSONFactory310}
import code.api.v3_1_0.ConsentJsonV310
import code.api.v3_1_0.JSONFactory310.createBadLoginStatusJson
import code.api.v4_0_0.APIMethods400.{createTransactionRequest, transactionRequestGeneralText}
import code.api.v4_0_0.JSONFactory400.{createAccountBalancesJson, createBalancesJson, createNewCoreBankAccountJson}
import code.api.v4_0_0.{JSONFactory400, PostAccountAccessJsonV400, PostApiCollectionJson400, RevokedJsonV400}
import code.api.v5_0_0.JSONFactory500
Expand Down Expand Up @@ -381,7 +380,7 @@ trait APIMethods510 {
bankId = bankId.value,
legalName = putData.legal_name,
mobileNumber = putData.mobile_phone_number,
number = putData.agent_number,
agentNumber = putData.agent_number,
callContext,
)
(bankAccount, callContext) <- NewStyle.function.createBankAccount(
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/bankconnectors/Connector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ trait Connector extends MdcLoggable {
bankId: String,
legalName : String,
mobileNumber : String,
number : String,
agentNumber : String,
callContext: Option[CallContext]
): OBPReturnType[Box[Agent]] = Future{(Failure(setUnimplementedError(nameOf(createAgent _))), callContext)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1629,14 +1629,14 @@ object LocalMappedConnector extends Connector with MdcLoggable {
bankId: String,
legalName : String,
mobileNumber : String,
number : String,
agentNumber : String,
callContext: Option[CallContext]
): OBPReturnType[Box[Agent]] = {
AgentX.agentProvider.vend.createAgent(
bankId: String,
legalName : String,
mobileNumber : String,
number : String,
agentNumber : String,
callContext: Option[CallContext]
).map((_, callContext))
}
Expand Down Expand Up @@ -4757,11 +4757,11 @@ object LocalMappedConnector extends Connector with MdcLoggable {
body.to_agent.get
}
(agent, callContext) <- NewStyle.function.getAgentByAgentNumber(BankId(bodyToAgent.bank_id), bodyToAgent.agent_number, callContext)
(customerAccountLinks, callContext) <- NewStyle.function.getCustomerAccountLinksByCustomerId(agent.agentId, callContext)
customerAccountLink <- NewStyle.function.tryons(AgentAccountLinkNotFound, 400, callContext) {
customerAccountLinks.head
(agentAccountLinks, callContext) <- NewStyle.function.getAgentAccountLinksByAgentId(agent.agentId, callContext)
agentAccountLink <- NewStyle.function.tryons(AgentAccountLinkNotFound, 400, callContext) {
agentAccountLinks.head
}
(toAccount, callContext) <- NewStyle.function.getBankAccount(BankId(customerAccountLink.bankId), AccountId(customerAccountLink.accountId), callContext)
(toAccount, callContext) <- NewStyle.function.getBankAccount(BankId(agentAccountLink.bankId), AccountId(agentAccountLink.accountId), callContext)

agentRequestJsonBody = TransactionRequestBodyAgentJsonV400(
to = AgentCashWithdrawalJson(bodyToAgent.bank_id, bodyToAgent.agent_number),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait AgentProvider {
bankId: String,
legalName : String,
mobileNumber : String,
number : String,
agentNumber : String,
callContext: Option[CallContext]
): Future[Box[Agent]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ object MappedAgentProvider extends AgentProvider with MdcLoggable {
}


override def checkAgentNumberAvailable(bankId: BankId, customerNumber: String): Boolean = {
override def checkAgentNumberAvailable(bankId: BankId, agentNumber: String): Boolean = {
val customers = MappedCustomer.findAll(
By(MappedCustomer.mBank, bankId.value),
By(MappedCustomer.mNumber, customerNumber)
By(MappedCustomer.mNumber, agentNumber)
)

val available: Boolean = customers.size match {
Expand Down Expand Up @@ -87,7 +87,7 @@ object MappedAgentProvider extends AgentProvider with MdcLoggable {
bankId: String,
legalName: String,
mobileNumber: String,
number: String,
agentNumber: String,
callContext: Option[CallContext]
): Future[Box[Agent]] = Future {
tryo {
Expand All @@ -96,7 +96,7 @@ object MappedAgentProvider extends AgentProvider with MdcLoggable {
.mBank(bankId)
.mLegalName(legalName)
.mMobileNumber(mobileNumber)
.mNumber(number)
.mNumber(agentNumber)
.mIsPendingAgent(true) //default value
.mIsConfirmedAgent(false) // default value
.saveMe()
Expand Down
Binary file modified obp-api/src/test/resources/frozen_type_meta_data
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package code.api.v4_0_0

import code.api.Constant

import java.util.{Date, UUID}
import code.api.ChargePolicy
import code.api.Constant._
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.{createPhysicalCardJsonV500, postAgentJsonV510}
import code.api.util.APIUtil.OAuth._
import code.api.util.APIUtil.extractErrorMessageCode
import code.api.util.ApiRole.{CanCreateAnyTransactionRequest, CanCreateCardsForBank}
import code.api.util.ApiRole.{CanCreateAnyTransactionRequest, CanCreateCardsForBank, canUpdateAgentStatusAtAnyBank}
import code.api.util.ErrorMessages._
import code.api.util.{APIUtil, ErrorMessages}
import code.api.v1_4_0.JSONFactory1_4_0.{ChallengeAnswerJSON, TransactionRequestAccountJsonV140}
import code.api.v2_0_0.TransactionRequestBodyJsonV200
import code.api.v2_1_0._
import code.api.v4_0_0.APIMethods400.Implementations4_0_0
import code.api.v5_0_0.PhysicalCardJsonV500
import code.api.v5_1_0.AgentJsonV510
import code.api.v5_1_0.{AgentJsonV510, PutAgentJsonV510}
import code.bankconnectors.Connector
import code.entitlement.Entitlement
import code.fx.fx
Expand Down Expand Up @@ -134,6 +135,19 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
val request = (v5_1_0_Request / "banks" / bankId.value / "agents").POST <@ (user1)
val response = makePostRequest(request, write(postAgentJsonV510.copy(currency=fromAccount.currency)))
val agentCashWithdrawalAgent = response.body.extract[AgentJsonV510]

{
val putAgentJsonV510 = PutAgentJsonV510(
is_pending_agent = false,
is_confirmed_agent = true
)
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, canUpdateAgentStatusAtAnyBank.toString)
val request = (v5_1_0_Request / "banks" / bankId.value / "agents"/ agentCashWithdrawalAgent.agent_id).PUT <@ user1
val response = makePutRequest(request, write(putAgentJsonV510))
response.code should equal(200)
response.body.extract[AgentJsonV510].is_pending_agent should equal(putAgentJsonV510.is_pending_agent)
response.body.extract[AgentJsonV510].is_confirmed_agent should equal(putAgentJsonV510.is_confirmed_agent)
}

var transactionRequestBodySEPA = TransactionRequestBodySEPAJSON(bodyValue, IbanJson(counterpartySEPA.otherAccountSecondaryRoutingAddress), description, sharedChargePolicy)

Expand Down
Binary file not shown.

0 comments on commit e723c3f

Please sign in to comment.