Merge pull request #1454 from constantine2nd/develop

Standing Order - POC
This commit is contained in:
Simon Redfern 2019-11-12 17:50:08 +01:00 committed by GitHub
commit 291b64867a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 132 additions and 26 deletions

View File

@ -15,7 +15,7 @@ import code.api.v3_0_0.JSONFactory300.createBranchJsonV300
import code.api.v3_0_0.custom.JSONFactoryCustom300
import code.api.v3_0_0.{LobbyJsonV330, _}
import code.api.v3_1_0.{AccountBalanceV310, AccountsBalancesV310Json, BadLoginStatusJson, ContactDetailsJson, InviteeJson, ObpApiLoopbackJson, PhysicalCardWithAttributesJsonV310, PutUpdateCustomerEmailJsonV310, _}
import code.api.v4_0_0.{APIInfoJson400, AccountTagJSON, AccountTagsJSON, DirectDebitJsonV400, EnergySource400, HostedAt400, HostedBy400, ModeratedAccountJSON400, ModeratedCoreAccountJsonV400, PostAccountTagJSON, PostCustomerPhoneNumberJsonV400, PostDirectDebitJsonV400, PostStandingOrderJsonV400, StandingOrderJsonV400}
import code.api.v4_0_0.{APIInfoJson400, AccountTagJSON, AccountTagsJSON, DirectDebitJsonV400, EnergySource400, HostedAt400, HostedBy400, ModeratedAccountJSON400, ModeratedCoreAccountJsonV400, PostAccountTagJSON, PostCustomerPhoneNumberJsonV400, PostDirectDebitJsonV400, PostStandingOrderJsonV400, StandingOrderJsonV400, When}
import code.branches.Branches.{Branch, DriveUpString, LobbyString}
import code.consent.ConsentStatus
import code.sandbox.SandboxData
@ -3528,16 +3528,21 @@ object SwaggerDefinitionsJSON {
val postStandingOrderJsonV400 = PostStandingOrderJsonV400(
customer_id = customerIdExample.value,
user_id = userIdExample.value,
counterparty_id = counterpartyIdExample.value,
amount = amountOfMoneyJsonV121,
when = When(frequency = "YEARLY", detail = "LAST_DAY"),
date_signed = Some(DateWithDayExampleObject),
date_starts = DateWithDayExampleObject,
date_expires = Some(DateWithDayExampleObject)
)
val standingrderJsonV400 = StandingOrderJsonV400(
direct_debit_id = "aa0533bd-eb22-4bff-af75-d45240361b05",
val standingOrderJsonV400 = StandingOrderJsonV400(
standing_order_id = "aa0533bd-eb22-4bff-af75-d45240361b05",
bank_id = bankIdExample.value,
account_id = accountIdExample.value,
customer_id = customerIdExample.value,
user_id = userIdExample.value,
counterparty_id = counterpartyIdExample.value,
amount = amountOfMoneyJsonV121,
date_signed = new Date(),
date_starts = new Date(),
date_expires = new Date(),

View File

@ -43,6 +43,7 @@ import org.apache.commons.lang3.StringUtils
import scala.collection.immutable.List
import scala.concurrent.Future
import scala.math.BigDecimal
object NewStyle {
lazy val endpoints: List[(String, String)] = List(
@ -1566,6 +1567,11 @@ object NewStyle {
accountId: String,
customerId: String,
userId: String,
couterpartyId: String,
amountValue: BigDecimal,
amountCurrency: String,
whenFrequency: String,
whenDetail: String,
dateSigned: Date,
dateStarts: Date,
dateExpires: Option[Date],
@ -1575,6 +1581,11 @@ object NewStyle {
accountId,
customerId,
userId,
couterpartyId,
amountValue,
amountCurrency,
whenFrequency,
whenDetail,
dateSigned,
dateStarts,
dateExpires,

View File

@ -1599,18 +1599,23 @@ trait APIMethods400 {
"/banks/BANK_ID/accounts/ACCOUNT_ID/VIEW_ID/standing-order",
"Create Standing Order",
s"""Create standing order for an account.
|
|when -> frequency = {YEARLY,MONTHLY, WEEKLY, BI-WEEKLY, DAILY}
|when -> detail = { FIRST_MONDAY, FIRST_DAY, LAST_DAY}}
|
|${authenticationRequiredMessage(true)}
|
|""",
postStandingOrderJsonV400,
standingrderJsonV400,
standingOrderJsonV400,
List(
UserNotLoggedIn,
BankNotFound,
BankAccountNotFound,
NoViewPermission,
InvalidJsonFormat,
InvalidNumber,
InvalidISOCurrencyCode,
CustomerNotFoundByCustomerId,
UserNotFoundByUserId,
UnknownError
@ -1633,15 +1638,27 @@ trait APIMethods400 {
postJson <- NewStyle.function.tryons(failMsg, 400, callContext) {
json.extract[PostStandingOrderJsonV400]
}
amountValue <- NewStyle.function.tryons(s"$InvalidNumber Current input is ${postJson.amount.amount} ", 400, callContext) {
BigDecimal(postJson.amount.amount)
}
_ <- Helper.booleanToFuture(s"${InvalidISOCurrencyCode} Current input is: '${postJson.amount.currency}'") {
isValidCurrencyISOCode(postJson.amount.currency)
}
(_, callContext) <- NewStyle.function.getCustomerByCustomerId(postJson.customer_id, callContext)
_ <- Users.users.vend.getUserByUserIdFuture(postJson.user_id) map {
x => unboxFullOrFail(x, callContext, s"$UserNotFoundByUserId Current UserId(${postJson.user_id})")
}
(_, callContext) <- NewStyle.function.getCounterpartyByCounterpartyId(CounterpartyId(postJson.counterparty_id), callContext)
(directDebit, callContext) <- NewStyle.function.createStandingOrder(
bankId.value,
accountId.value,
postJson.customer_id,
postJson.user_id,
postJson.counterparty_id,
amountValue,
postJson.amount.currency,
postJson.when.frequency,
postJson.when.detail,
if (postJson.date_signed.isDefined) postJson.date_signed.get else new Date(),
postJson.date_starts,
postJson.date_expires,
@ -1660,18 +1677,23 @@ trait APIMethods400 {
"/management/banks/BANK_ID/accounts/ACCOUNT_ID/standing-order",
"Create Standing Order(management)",
s"""Create standing order for an account.
|
|when -> frequency = {YEARLY,MONTHLY, WEEKLY, BI-WEEKLY, DAILY}
|when -> detail = { FIRST_MONDAY, FIRST_DAY, LAST_DAY}}
|
|${authenticationRequiredMessage(true)}
|
|""",
postStandingOrderJsonV400,
standingrderJsonV400,
standingOrderJsonV400,
List(
UserNotLoggedIn,
BankNotFound,
BankAccountNotFound,
NoViewPermission,
InvalidJsonFormat,
InvalidNumber,
InvalidISOCurrencyCode,
CustomerNotFoundByCustomerId,
UserNotFoundByUserId,
UnknownError
@ -1691,15 +1713,27 @@ trait APIMethods400 {
postJson <- NewStyle.function.tryons(failMsg, 400, callContext) {
json.extract[PostStandingOrderJsonV400]
}
amountValue <- NewStyle.function.tryons(s"$InvalidNumber Current input is ${postJson.amount.amount} ", 400, callContext) {
BigDecimal(postJson.amount.amount)
}
_ <- Helper.booleanToFuture(s"${InvalidISOCurrencyCode} Current input is: '${postJson.amount.currency}'") {
isValidCurrencyISOCode(postJson.amount.currency)
}
(_, callContext) <- NewStyle.function.getCustomerByCustomerId(postJson.customer_id, callContext)
_ <- Users.users.vend.getUserByUserIdFuture(postJson.user_id) map {
x => unboxFullOrFail(x, callContext, s"$UserNotFoundByUserId Current UserId(${postJson.user_id})")
}
(_, callContext) <- NewStyle.function.getCounterpartyByCounterpartyId(CounterpartyId(postJson.counterparty_id), callContext)
(directDebit, callContext) <- NewStyle.function.createStandingOrder(
bankId.value,
accountId.value,
postJson.customer_id,
postJson.user_id,
postJson.counterparty_id,
amountValue,
postJson.amount.currency,
postJson.when.frequency,
postJson.when.detail,
if (postJson.date_signed.isDefined) postJson.date_signed.get else new Date(),
postJson.date_starts,
postJson.date_expires,

View File

@ -165,19 +165,24 @@ case class DirectDebitJsonV400(direct_debit_id: String,
date_expires: Date,
date_cancelled: Date,
active: Boolean)
case class When(frequency: String, detail: String)
case class PostStandingOrderJsonV400(customer_id: String,
user_id: String,
counterparty_id: String,
amount : AmountOfMoneyJsonV121,
when: When,
date_signed: Option[Date],
date_starts: Date,
date_expires: Option[Date]
)
case class StandingOrderJsonV400(direct_debit_id: String,
case class StandingOrderJsonV400(standing_order_id: String,
bank_id: String,
account_id: String,
customer_id: String,
user_id: String,
counterparty_id: String,
amount: AmountOfMoneyJsonV121,
date_signed: Date,
date_starts: Date,
date_expires: Date,
@ -332,11 +337,13 @@ object JSONFactory400 {
active = directDebit.active)
}
def createStandingOrderJSON(standingOrder: StandingOrderTrait): StandingOrderJsonV400 = {
StandingOrderJsonV400(direct_debit_id = standingOrder.standingOrderId,
StandingOrderJsonV400(standing_order_id = standingOrder.standingOrderId,
bank_id = standingOrder.bankId,
account_id = standingOrder.accountId,
customer_id = standingOrder.customerId,
user_id = standingOrder.userId,
counterparty_id = standingOrder.counterpartyId,
amount = AmountOfMoneyJsonV121(standingOrder.amountValue.toString(), standingOrder.amountCurrency),
date_signed = standingOrder.dateSigned,
date_cancelled = standingOrder.dateCancelled,
date_starts = standingOrder.dateStarts,

View File

@ -49,7 +49,7 @@ import scala.collection.mutable.ArrayBuffer
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.math.BigInt
import scala.math.{BigDecimal, BigInt}
import scala.util.Random
/*
@ -1896,6 +1896,11 @@ trait Connector extends MdcLoggable with CustomJsonFormats{
accountId: String,
customerId: String,
userId: String,
counterpartyId: String,
amountValue: BigDecimal,
amountCurrency: String,
whenFrequency: String,
whenDetail: String,
dateSigned: Date,
dateStarts: Date,
dateExpires: Option[Date],

View File

@ -77,7 +77,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
import scala.concurrent.duration._
import scala.language.postfixOps
import scala.math.BigInt
import scala.math.{BigDecimal, BigInt}
import scala.util.Random
@ -2892,6 +2892,11 @@ object LocalMappedConnector extends Connector with MdcLoggable {
accountId: String,
customerId: String,
userId: String,
counterpartyId: String,
amountValue: BigDecimal,
amountCurrency: String,
whenFrequency: String,
whenDetail: String,
dateSigned: Date,
dateStarts: Date,
dateExpires: Option[Date],
@ -2901,6 +2906,11 @@ object LocalMappedConnector extends Connector with MdcLoggable {
accountId,
customerId,
userId,
counterpartyId,
amountValue,
amountCurrency,
whenFrequency,
whenDetail,
dateSigned,
dateStarts,
dateExpires)

View File

@ -3,24 +3,36 @@ package code.standingorders
import java.util.Date
import code.api.util.APIUtil
import code.util.UUIDString
import code.util.Helper.convertToSmallestCurrencyUnits
import code.util.{Helper, UUIDString}
import net.liftweb.common.Box
import net.liftweb.mapper._
import scala.math.BigDecimal
object MappedStandingOrderProvider extends StandingOrderProvider {
def createStandingOrder(bankId: String,
accountId: String,
customerId: String,
userId: String,
dateSigned: Date,
dateStarts: Date,
dateExpires: Option[Date]
): Box[StandingOrder] = Box.tryo {
accountId: String,
customerId: String,
userId: String,
couterpartyId: String,
amountValue: BigDecimal,
amountCurrency: String,
whenFrequency: String,
whenDetail: String,
dateSigned: Date,
dateStarts: Date,
dateExpires: Option[Date]
): Box[StandingOrder] = Box.tryo {
StandingOrder.create
.BankId(bankId)
.AccountId(accountId)
.CustomerId(customerId)
.UserId(userId)
.CouterpartyId(couterpartyId)
.AmountValue(convertToSmallestCurrencyUnits(amountValue, amountCurrency))
.AmountCurrency(amountCurrency)
.WhenFrequency(whenFrequency)
.DateSigned(dateSigned)
.DateStarts(dateStarts)
.DateExpires(if (dateExpires.isDefined) dateExpires.get else null)
@ -56,6 +68,11 @@ class StandingOrder extends StandingOrderTrait with LongKeyedMapper[StandingOrde
object AccountId extends UUIDString(this)
object CustomerId extends UUIDString(this)
object UserId extends UUIDString(this)
object CouterpartyId extends UUIDString(this)
object AmountValue extends MappedLong(this)
object AmountCurrency extends MappedString(this, 3)
object WhenFrequency extends MappedString(this, 50)
object WhenDetail extends MappedString(this, 50)
object DateSigned extends MappedDateTime(this)
object DateCancelled extends MappedDateTime(this)
object DateStarts extends MappedDateTime(this)
@ -67,6 +84,11 @@ class StandingOrder extends StandingOrderTrait with LongKeyedMapper[StandingOrde
override def accountId: String = AccountId.get
override def customerId: String = CustomerId.get
override def userId: String = UserId.get
override def counterpartyId: String = CouterpartyId.get
override def amountValue: BigDecimal = Helper.smallestCurrencyUnitToBigDecimal(AmountValue.get, AmountCurrency.get)
override def amountCurrency: String = AmountCurrency.get
override def whenFrequency: String = WhenFrequency.get
override def whenDetail: String = WhenDetail.get
override def dateSigned: Date = DateSigned.get
override def dateCancelled: Date = DateCancelled.get
override def dateExpires: Date = DateExpires.get
@ -75,5 +97,5 @@ class StandingOrder extends StandingOrderTrait with LongKeyedMapper[StandingOrde
}
object StandingOrder extends StandingOrder with LongKeyedMetaMapper[StandingOrder] {
override def dbIndexes: List[BaseIndex[StandingOrder]] = UniqueIndex(BankId, AccountId, CustomerId) :: super.dbIndexes
override def dbIndexes: List[BaseIndex[StandingOrder]] = super.dbIndexes
}

View File

@ -5,6 +5,8 @@ import java.util.Date
import net.liftweb.common.Box
import net.liftweb.util.SimpleInjector
import scala.math.BigDecimal
object StandingOrders extends SimpleInjector {
val provider = new Inject(buildOne _) {}
@ -12,13 +14,18 @@ object StandingOrders extends SimpleInjector {
}
trait StandingOrderProvider {
def createStandingOrder(bankId: String,
accountId: String,
customerId: String,
userId: String,
dateSigned: Date,
dateStarts: Date,
dateExpires: Option[Date]
def createStandingOrder(bankId: String,
accountId: String,
customerId: String,
userId: String,
counterpartyId: String,
amountValue: BigDecimal,
amountCurrency: String,
whenFrequency: String,
whenDetail: String,
dateSigned: Date,
dateStarts: Date,
dateExpires: Option[Date]
): Box[StandingOrderTrait]
def getStandingOrdersByCustomer(customerId: String) : List[StandingOrderTrait]
def getStandingOrdersByUser(userId: String) : List[StandingOrderTrait]
@ -30,6 +37,11 @@ trait StandingOrderTrait {
def accountId: String
def customerId: String
def userId: String
def counterpartyId: String
def amountValue : BigDecimal
def amountCurrency: String
def whenFrequency: String
def whenDetail: String
def dateSigned: Date
def dateCancelled: Date
def dateStarts: Date