Merge pull request #2219 from hongwei1/develop

refactor/added new connector method `getPaymentLimit`
This commit is contained in:
Simon Redfern 2023-05-04 10:43:25 +02:00 committed by GitHub
commit 42e0b0e5f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 133 additions and 36 deletions

View File

@ -294,6 +294,9 @@ transactionRequests_challenge_threshold_SEPA=1000
# To set a currency for the above value:
#transactionRequests_challenge_currency=KRW
# To set the payment limit, default is 100000. we only set the number here, currency is from the request json body.
#transactionRequests_payment_limit=100000
### Management modules
## RabbitMQ settings (used to communicate with HBCI project)

View File

@ -640,7 +640,8 @@ object ErrorMessages {
val InvalidConnectorResponseForCancelPayment = "OBP-50217: Connector did not return the transaction we requested."
val InvalidConnectorResponseForGetEndpointTags = "OBP-50218: Connector did not return the set of endpoint tags we requested."
val InvalidConnectorResponseForGetBankAccountsWithAttributes = "OBP-50219: Connector did not return the bank accounts we requested."
val InvalidConnectorResponseForGetPaymentLimit = "OBP-50220: Connector did not return the payment limit we requested."
// Adapter Exceptions (OBP-6XXXX)
// Reserved for adapter (south of Kafka) messages
// Also used for connector == mapped, and show it as the Internal errors.

View File

@ -338,6 +338,29 @@ trait Connector extends MdcLoggable {
callContext: Option[CallContext]
)
def getPaymentLimit(
bankId: String,
accountId: String,
viewId: String,
transactionRequestType: String,
currency: String,
userId: String,
username: String,
callContext: Option[CallContext]
): OBPReturnType[Box[AmountOfMoney]] = {
LocalMappedConnector.getPaymentLimit(
bankId: String,
accountId: String,
viewId: String,
transactionRequestType: String,
currency: String,
userId: String,
username: String,
callContext: Option[CallContext]
)
}
//Gets current charge level for transaction request
def getChargeLevel(bankId: BankId,
accountId: AccountId,

View File

@ -203,6 +203,46 @@ object LocalMappedConnector extends Connector with MdcLoggable {
}
}
override def getPaymentLimit(
bankId: String,
accountId: String,
viewId: String,
transactionRequestType: String,
currency: String,
userId: String,
username: String,
callContext: Option[CallContext]
): OBPReturnType[Box[AmountOfMoney]] = Future {
//Get the limit from userAttribute, default is 1
val userAttributeName = s"TRANSACTION_REQUESTS_PAYMENT_LIMIT_${currency}_" + transactionRequestType.toUpperCase
val userAttributes = UserAttribute.findAll(
By(UserAttribute.UserId, userId),
OrderBy(UserAttribute.createdAt, Descending)
)
val userAttributeValue = userAttributes.find(_.name == userAttributeName).map(_.value)
val paymentLimit = APIUtil.getPropsAsIntValue("transactionRequests_payment_limit",100000)
val paymentLimitBox = tryo (BigDecimal(userAttributeValue.getOrElse(paymentLimit.toString)))
logger.debug(s"getPaymentLimit: paymentLimitBox is $paymentLimitBox")
logger.debug(s"getPaymentLimit: currency is $currency")
paymentLimitBox match {
case Full(paymentLimitValue) =>
isValidCurrencyISOCode(currency) match {
case true =>
(Full(AmountOfMoney(currency, paymentLimitValue.toString())), callContext)
case false =>
val msg = s"$InvalidISOCurrencyCode ${currency}"
(Failure(msg), callContext)
}
case _ =>
val msg = s"$InvalidNumber Current user attribute ${userAttributeName}.value is (${userAttributeValue.getOrElse("")})"
(Failure(msg), callContext)
}
}
/**
* Steps To Create, Store and Send Challenge
* 1. Generate a random challenge
@ -4846,6 +4886,23 @@ object LocalMappedConnector extends Connector with MdcLoggable {
callContext: Option[CallContext]): OBPReturnType[Box[TransactionRequest]] = {
for {
transactionRequestCommonBodyAmount <- NewStyle.function.tryons(s"$InvalidNumber Request Json value.amount ${transactionRequestCommonBody.value.amount} not convertible to number", 400, callContext) {
BigDecimal(transactionRequestCommonBody.value.amount)
}
(paymentLimit, callContext) <- Connector.connector.vend.getPaymentLimit(fromAccount.bankId.value, fromAccount.accountId.value, viewId.value, transactionRequestType.value, transactionRequestCommonBody.value.currency, initiator.userId, initiator.name, callContext) map { i =>
(unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponseForGetPaymentLimit ", 400), i._2)
}
paymentLimitAmount <- NewStyle.function.tryons(s"$InvalidConnectorResponseForGetPaymentLimit. payment limit amount ${paymentLimit.amount} not convertible to number", 400, callContext) {
BigDecimal(paymentLimit.amount)
}
_ <- Helper.booleanToFuture(s"$InvalidJsonValue the payment amount is over the payment limit($paymentLimit)", 400, callContext) {
transactionRequestCommonBodyAmount <= paymentLimitAmount
}
// Get the threshold for a challenge. i.e. over what value do we require an out of Band security challenge to be sent?
(challengeThreshold, callContext) <- Connector.connector.vend.getChallengeThreshold(fromAccount.bankId.value, fromAccount.accountId.value, viewId.value, transactionRequestType.value, transactionRequestCommonBody.value.currency, initiator.userId, initiator.name, callContext) map { i =>
(unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponseForGetChallengeThreshold ", 400), i._2)
@ -4853,9 +4910,6 @@ object LocalMappedConnector extends Connector with MdcLoggable {
challengeThresholdAmount <- NewStyle.function.tryons(s"$InvalidConnectorResponseForGetChallengeThreshold. challengeThreshold amount ${challengeThreshold.amount} not convertible to number", 400, callContext) {
BigDecimal(challengeThreshold.amount)
}
transactionRequestCommonBodyAmount <- NewStyle.function.tryons(s"$InvalidNumber Request Json value.amount ${transactionRequestCommonBody.value.amount} not convertible to number", 400, callContext) {
BigDecimal(transactionRequestCommonBody.value.amount)
}
status <- getStatus(challengeThresholdAmount, transactionRequestCommonBodyAmount, transactionRequestType: TransactionRequestType)
(chargeLevel, callContext) <- Connector.connector.vend.getChargeLevel(BankId(fromAccount.bankId.value), AccountId(fromAccount.accountId.value), viewId, initiator.userId, initiator.name, transactionRequestType.value, fromAccount.currency, callContext) map { i =>
(unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponseForGetChargeLevel ", 400), i._2)
@ -4961,6 +5015,22 @@ object LocalMappedConnector extends Connector with MdcLoggable {
callContext: Option[CallContext]): OBPReturnType[Box[TransactionRequest]] = {
for {
transactionRequestCommonBodyAmount <- NewStyle.function.tryons(s"$InvalidNumber Request Json value.amount ${transactionRequestCommonBody.value.amount} not convertible to number", 400, callContext) {
BigDecimal(transactionRequestCommonBody.value.amount)
}
(paymentLimit, callContext) <- Connector.connector.vend.getPaymentLimit(fromAccount.bankId.value, fromAccount.accountId.value, viewId.value, transactionRequestType.value, transactionRequestCommonBody.value.currency, initiator.userId, initiator.name, callContext) map { i =>
(unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponseForGetPaymentLimit ", 400), i._2)
}
paymentLimitAmount <- NewStyle.function.tryons(s"$InvalidConnectorResponseForGetPaymentLimit. payment limit amount ${paymentLimit.amount} not convertible to number", 400, callContext) {
BigDecimal(paymentLimit.amount)
}
_ <- Helper.booleanToFuture(s"$InvalidJsonValue the payment amount is over the payment limit($paymentLimit)", 400, callContext) {
transactionRequestCommonBodyAmount <= paymentLimitAmount
}
// Get the threshold for a challenge. i.e. over what value do we require an out of Band security challenge to be sent?
(challengeThreshold, callContext) <- Connector.connector.vend.getChallengeThreshold(fromAccount.bankId.value, fromAccount.accountId.value, viewId.value, transactionRequestType.value, transactionRequestCommonBody.value.currency, initiator.userId, initiator.name, callContext) map { i =>
(unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponseForGetChallengeThreshold ", 400), i._2)
@ -4968,9 +5038,8 @@ object LocalMappedConnector extends Connector with MdcLoggable {
challengeThresholdAmount <- NewStyle.function.tryons(s"$InvalidConnectorResponseForGetChallengeThreshold. challengeThreshold amount ${challengeThreshold.amount} not convertible to number", 400, callContext) {
BigDecimal(challengeThreshold.amount)
}
transactionRequestCommonBodyAmount <- NewStyle.function.tryons(s"$InvalidNumber Request Json value.amount ${transactionRequestCommonBody.value.amount} not convertible to number", 400, callContext) {
BigDecimal(transactionRequestCommonBody.value.amount)
}
status <- getStatus(challengeThresholdAmount, transactionRequestCommonBodyAmount, transactionRequestType: TransactionRequestType)
(chargeLevel, callContext) <- Connector.connector.vend.getChargeLevelC2(
BankId(fromAccount.bankId.value),

View File

@ -155,7 +155,7 @@ class PaymentInitiationServicePISApiTest extends BerlinGroupServerSetupV1_3 with
| },
|"instructedAmount": {
| "currency": "EUR",
| "amount": "123324"
| "amount": "2001"
|},
|"creditorAccount": {
| "iban": "${acountRoutingIbanTo.accountRouting.address}"
@ -240,7 +240,7 @@ class PaymentInitiationServicePISApiTest extends BerlinGroupServerSetupV1_3 with
| },
|"instructedAmount": {
| "currency": "EUR",
| "amount": "123324"
| "amount": "2001"
|},
|"creditorAccount": {
| "iban": "${ibanTo}"
@ -297,7 +297,7 @@ class PaymentInitiationServicePISApiTest extends BerlinGroupServerSetupV1_3 with
| },
|"instructedAmount": {
| "currency": "EUR",
| "amount": "12355"
| "amount": "2001"
|},
|"creditorAccount": {
| "iban": "${acountRoutingIbanTo.accountRouting.address}"
@ -366,8 +366,8 @@ class PaymentInitiationServicePISApiTest extends BerlinGroupServerSetupV1_3 with
By(MappedBankAccount.theAccountId, acountRoutingIbanTo.accountId.value))
.map(_.balance).openOrThrowException("Can not be empty here")
afterPaymentFromAccountBalance-beforePaymentFromAccountBalance should be (BigDecimal(-12355.00))
afterPaymentToAccountBalacne-beforePaymentToAccountBalance should be (BigDecimal(12355.00))
afterPaymentFromAccountBalance-beforePaymentFromAccountBalance should be (BigDecimal(-2001.00))
afterPaymentToAccountBalacne-beforePaymentToAccountBalance should be (BigDecimal(2001.00))
}

View File

@ -460,7 +460,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -507,7 +507,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")
@ -629,7 +629,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -676,7 +676,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")
@ -798,7 +798,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "EUR"
val toCurrency = "EUR"
val amt = "50000.00"
val amt = "9000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -845,7 +845,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "EUR"
val toCurrency = "EUR"
val amt = "50000.00"
val amt = "9000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")
@ -967,7 +967,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -1014,7 +1014,7 @@ class TransactionRequestsTest extends V210ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V210 Create Transaction Request' endpoint")

View File

@ -520,7 +520,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -562,7 +562,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -602,7 +602,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -727,7 +727,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -775,7 +775,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -897,7 +897,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "EUR"
val toCurrency = "EUR"
val amt = "50000.00"
val amt = "9000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -944,7 +944,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "EUR"
val toCurrency = "EUR"
val amt = "50000.00"
val amt = "9000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -1066,7 +1066,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -1113,7 +1113,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -1163,7 +1163,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -1314,7 +1314,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -1361,7 +1361,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -1411,7 +1411,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -1573,7 +1573,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "AED"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
helper.bodyValue = AmountOfMoneyJsonV121(fromCurrency, amt.toString())
@ -1623,7 +1623,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")
@ -1676,7 +1676,7 @@ class TransactionRequestsTest extends V400ServerSetup with DefaultUsers {
And("We set the special conditions for different currencies")
val fromCurrency = "AED"
val toCurrency = "INR"
val amt = "50000.00"
val amt = "30000.00"
helper.setCurrencyAndAmt(fromCurrency, toCurrency, amt)
And("We set the special input JSON values for 'V400 Create Transaction Request' endpoint")

View File

@ -3,6 +3,7 @@
### Most recent changes at top of file
```
Date Commit Action
03/05/2023 bcb8fcfd Added props transactionRequests_payment_limit, default is 100000.
20/01/2023 c26226e6 Added props show_ip_address_change_warning, default is false.
29/09/2022 eaa32f41 Added props excluded.response.behaviour, default is false. Set it to true to activate the props: excluded.response.field.values. Note: excluded.response.field.values can also be activated on a per call basis by the url param ?exclude-optional-fields=true
07/09/2022 53564924 renamed props `language_tag` to `default_locale`, default is en_GB.