Skip to content

Commit

Permalink
refactor/added the currency to userAttributeName for getPaymentLimit …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
hongwei1 committed May 3, 2023
1 parent 21cd296 commit bcb8fcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
3 changes: 3 additions & 0 deletions obp-api/src/main/resources/props/sample.props.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
#transactionRequests_payment_limit=100000

### Management modules

## RabbitMQ settings (used to communicate with HBCI project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,30 +214,25 @@ object LocalMappedConnector extends Connector with MdcLoggable {
username: String,
callContext: Option[CallContext]
): OBPReturnType[Box[AmountOfMoney]] = Future {
//Get the limit from userAttribute, default is 10000 euros
val userAttributeName = "TRANSACTION_REQUESTS_PAYMENT_LIMIT_" + transactionRequestType.toUpperCase
val userAttributes = UserAttribute.findAll(By(UserAttribute.UserId, userId))

//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 paymentLimitBox = tryo (BigDecimal(userAttributeValue.getOrElse("10000")))
logger.debug(s"payment list is $paymentLimitBox")

val thresholdCurrency: String = APIUtil.getPropsValue("transactionRequests_challenge_currency", "EUR")
logger.debug(s"thresholdCurrency is $thresholdCurrency")
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(thresholdCurrency) match {
isValidCurrencyISOCode(currency) match {
case true =>
fx.exchangeRate(thresholdCurrency, currency, Some(bankId)) match {
case rate@Some(_) =>
val convertedThreshold = fx.convert(paymentLimitValue, rate)
logger.debug(s"getPaymentLimit for currency $currency is $convertedThreshold")
(Full(AmountOfMoney(currency, convertedThreshold.toString())), callContext)
case _ =>
val msg = s"$InvalidCurrency The requested currency conversion (${thresholdCurrency} to ${currency}) is not supported."
(Failure(msg), callContext)
}
(Full(AmountOfMoney(currency, paymentLimitValue.toString())), callContext)
case false =>
val msg = s"$InvalidISOCurrencyCode ${thresholdCurrency}"
val msg = s"$InvalidISOCurrencyCode ${currency}"
(Failure(msg), callContext)
}
case _ =>
Expand Down

0 comments on commit bcb8fcf

Please sign in to comment.