mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 19:16:53 +00:00
#399 Create Transaction Request should accept charge policy
This commit is contained in:
parent
c9441627ff
commit
e4c1e7c637
@ -171,7 +171,7 @@ object ErrorMessages {
|
||||
val InvalidTransactionRequesChallengeId = "OBP-40010: Invalid Challenge Id. Please specify a valid value for CHALLENGE_ID."
|
||||
val TransactionRequestStatusNotInitiated = "OBP-40011: Transaction Request Status is not initiated. This transaction request has been answered before"
|
||||
val CounterpartyNotFoundOtherAccountProvider = "OBP-40012: Please set up the OtherAccountProvider field of the Counterparty, the default value should be 'OBP'"
|
||||
|
||||
val InvalidChargePolicy = "OBP-40013: Invalid Charge Policy. Please specify a valid value for Charge_Policy: SHARED, SENDER or RECEIVER. "
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -375,8 +375,9 @@ trait APIMethods210 {
|
||||
Failure(ErrorMessages.CounterpartyNotFoundOtherAccountProvider)
|
||||
transactionRequestAccountJSON = TransactionRequestAccountJSON(toBankId.value, toAccountId.value)
|
||||
chargePolicy = transDetailsCounterpartyJson.charge_policy
|
||||
transactionRequestDetailsMapperCounterparty = TransactionRequestDetailsMapperCounterpartyJSON(toCounterpartyId.toString, transactionRequestAccountJSON, amountOfMoneyJSON, transDetailsCounterpartyJson.description, transDetailsCounterpartyJson.charge_policy)
|
||||
chargePolicyIsValid<-tryo(assert(ChargePolicy.values.contains(ChargePolicy.withName(chargePolicy))))?~! {ErrorMessages.InvalidChargePolicy}
|
||||
|
||||
transactionRequestDetailsMapperCounterparty = TransactionRequestDetailsMapperCounterpartyJSON(toCounterpartyId.toString, transactionRequestAccountJSON, amountOfMoneyJSON, transDetailsCounterpartyJson.description, transDetailsCounterpartyJson.charge_policy)
|
||||
//Serialize the transResponseDetails to String.
|
||||
transDetailsResponseSerialized <- tryo {write(transactionRequestDetailsMapperCounterparty)(Serialization.formats(NoTypeHints))}
|
||||
createdTransactionRequest <- Connector.connector.vend.createTransactionRequestv210(u, viewId.value, fromAccount, toAccount, toCounterparty, transactionRequestType, transDetailsCounterpartyJson, chargePolicy, transDetailsResponseSerialized)
|
||||
@ -397,6 +398,7 @@ trait APIMethods210 {
|
||||
toAccount <- BankAccount(toBankId, toAccountId) ?~! {ErrorMessages.CounterpartyNotFound}
|
||||
transactionRequestAccountJSON = TransactionRequestAccountJSON(toBankId.value, toAccountId.value)
|
||||
chargePolicy = transDetailsSEPAJson.charge_policy
|
||||
chargePolicyIsValid<-tryo(assert(ChargePolicy.values.contains(ChargePolicy.withName(chargePolicy))))?~! {ErrorMessages.InvalidChargePolicy}
|
||||
transactionRequestDetailsSEPAResponseJSON = TransactionRequestDetailsMapperSEPAJSON(toIban.toString, transactionRequestAccountJSON, amountOfMoneyJSON, transDetailsSEPAJson.description, chargePolicy)
|
||||
|
||||
//Serialize the transResponseDetails data to String.
|
||||
|
||||
@ -193,7 +193,9 @@ trait Connector {
|
||||
// Note for 'new MappedCounterparty()' in the following :
|
||||
// We update the makePaymentImpl in V210, added the new parameter 'toCounterparty: CounterpartyTrait' for V210
|
||||
// But in V200 or before, we do not used the new parameter toCounterparty. So just keep it empty.
|
||||
transactionId <- makePaymentImpl(fromAccount, toAccount, new MappedCounterparty(), amt, description, TransactionRequestType(""))
|
||||
transactionId <- makePaymentImpl(fromAccount, toAccount, new MappedCounterparty(), amt, description,
|
||||
TransactionRequestType(""), //Note TransactionRequestType only support in V210
|
||||
"") //Note chargePolicy only support in V210
|
||||
} yield transactionId
|
||||
}
|
||||
|
||||
@ -208,8 +210,7 @@ trait Connector {
|
||||
* @param transactionRequestType user input: SEPA, SANDBOX_TAN, FREE_FORM, COUNTERPARTY
|
||||
* @return The id of the sender's new transaction,
|
||||
*/
|
||||
def makePaymentv200(initiator: User, fromAccountUID: BankAccountUID, toAccountUID: BankAccountUID, toCounterparty: CounterpartyTrait,
|
||||
amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType): Box[TransactionId] = {
|
||||
def makePaymentv200(initiator: User, fromAccountUID: BankAccountUID, toAccountUID: BankAccountUID, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String): Box[TransactionId] = {
|
||||
for {
|
||||
// Note: These following guards are checked in AIP level (maybe some other function call it, so leave the guards here)
|
||||
fromAccount <- getBankAccount(fromAccountUID.bankId, fromAccountUID.accountId) ?~
|
||||
@ -235,12 +236,12 @@ trait Connector {
|
||||
isPositiveAmtToSend <- booleanToBox(amt > BigDecimal("0"), s"Can't send a payment with a value of 0 or less. ($amt)")
|
||||
//TODO: verify the amount fits with the currency -> e.g. 12.543 EUR not allowed, 10.00 JPY not allowed, 12.53 EUR allowed
|
||||
|
||||
transactionId <- makePaymentImpl(fromAccount, toAccount, toCounterparty, amt, description, transactionRequestType)
|
||||
transactionId <- makePaymentImpl(fromAccount, toAccount, toCounterparty, amt, description, transactionRequestType, chargePolicy)
|
||||
} yield transactionId
|
||||
}
|
||||
|
||||
|
||||
protected def makePaymentImpl(fromAccount: AccountType, toAccount: AccountType, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType): Box[TransactionId]
|
||||
protected def makePaymentImpl(fromAccount: AccountType, toAccount: AccountType, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String): Box[TransactionId]
|
||||
|
||||
|
||||
/*
|
||||
@ -356,7 +357,8 @@ trait Connector {
|
||||
new MappedCounterparty(),
|
||||
BigDecimal(body.value.amount),
|
||||
body.description,
|
||||
transactionRequestType)
|
||||
transactionRequestType,
|
||||
"") //Note chargePolicy only support in V210
|
||||
|
||||
//set challenge to null
|
||||
result = Full(result.get.copy(challenge = null))
|
||||
@ -440,28 +442,32 @@ trait Connector {
|
||||
toCounterparty,
|
||||
BigDecimal(details.value.amount),
|
||||
details.asInstanceOf[TransactionRequestDetailsSandBoxTanJSON].description,
|
||||
transactionRequestType)
|
||||
transactionRequestType,
|
||||
chargePolicy)
|
||||
case "COUNTERPARTY" => Connector.connector.vend.makePaymentv200(initiator,
|
||||
BankAccountUID(fromAccount.bankId, fromAccount.accountId),
|
||||
BankAccountUID(toAccount.bankId, toAccount.accountId),
|
||||
toCounterparty,
|
||||
BigDecimal(details.value.amount),
|
||||
details.asInstanceOf[TransactionRequestDetailsCounterpartyJSON].description,
|
||||
transactionRequestType)
|
||||
transactionRequestType,
|
||||
chargePolicy)
|
||||
case "SEPA" => Connector.connector.vend.makePaymentv200(initiator,
|
||||
BankAccountUID(fromAccount.bankId, fromAccount.accountId),
|
||||
BankAccountUID(toAccount.bankId, toAccount.accountId),
|
||||
toCounterparty,
|
||||
BigDecimal(details.value.amount),
|
||||
details.asInstanceOf[TransactionRequestDetailsSEPAJSON].description,
|
||||
transactionRequestType)
|
||||
transactionRequestType,
|
||||
chargePolicy)
|
||||
case "FREE_FORM" => Connector.connector.vend.makePaymentv200(initiator,
|
||||
BankAccountUID(fromAccount.bankId, fromAccount.accountId),
|
||||
BankAccountUID(toAccount.bankId, toAccount.accountId),
|
||||
toCounterparty,
|
||||
BigDecimal(details.value.amount),
|
||||
"", //no description part for FREE_FORM yet
|
||||
transactionRequestType)
|
||||
transactionRequestType,
|
||||
chargePolicy)
|
||||
}
|
||||
//set challenge to null
|
||||
result = Full(result.get.copy(challenge = null))
|
||||
@ -638,7 +644,13 @@ trait Connector {
|
||||
// Note for 'new MappedCounterparty()' in the following :
|
||||
// We update the makePaymentImpl in V210, added the new parameter 'toCounterparty: CounterpartyTrait' for V210
|
||||
// But in V200 or before, we do not used the new parameter toCounterparty. So just keep it empty.
|
||||
transId <- makePaymentv200(initiator, BankAccountUID(BankId(tr.from.bank_id), AccountId(tr.from.account_id)), BankAccountUID (BankId(tr.body.to.bank_id), AccountId(tr.body.to.account_id)), new MappedCounterparty() , BigDecimal (tr.body.value.amount), tr.body.description, transactionRequestType) ?~ "Couldn't create Transaction"
|
||||
transId <- makePaymentv200(initiator, BankAccountUID(BankId(tr.from.bank_id), AccountId(tr.from.account_id)),
|
||||
BankAccountUID (BankId(tr.body.to.bank_id), AccountId(tr.body.to.account_id)),
|
||||
new MappedCounterparty(), //Note MappedCounterparty only support in V210
|
||||
BigDecimal (tr.body.value.amount),
|
||||
tr.body.description, transactionRequestType,
|
||||
"" //Note chargePolicy only support in V210
|
||||
) ?~ "Couldn't create Transaction"
|
||||
didSaveTransId <- saveTransactionRequestTransaction(transReqId, transId)
|
||||
didSaveStatus <- saveTransactionRequestStatusImpl(transReqId, TransactionRequests.STATUS_COMPLETED)
|
||||
//get transaction request again now with updated values
|
||||
@ -681,14 +693,13 @@ trait Connector {
|
||||
Full(new MappedCounterparty())
|
||||
}
|
||||
|
||||
transId <- makePaymentv200(
|
||||
initiator,
|
||||
BankAccountUID(BankId(tr.from.bank_id), AccountId(tr.from.account_id)),
|
||||
transId <- makePaymentv200(initiator, BankAccountUID(BankId(tr.from.bank_id), AccountId(tr.from.account_id)),
|
||||
BankAccountUID(BankId(toBankId), AccountId(toAccountId)),
|
||||
new MappedCounterparty(),
|
||||
BigDecimal(valueAmount),
|
||||
description,
|
||||
transactionRequestType) ?~ "Couldn't create Transaction"
|
||||
toCounterparty,
|
||||
BigDecimal(valueAmount), description,
|
||||
transactionRequestType,
|
||||
tr.charge_policy
|
||||
) ?~ "Couldn't create Transaction"
|
||||
|
||||
didSaveTransId <- saveTransactionRequestTransaction(transReqId, transId)
|
||||
//dummy10 = print(s"didSaveTransId is ${didSaveTransId} \n")
|
||||
|
||||
@ -601,8 +601,8 @@ object KafkaMappedConnector extends Connector with Loggable {
|
||||
}
|
||||
|
||||
|
||||
override def makePaymentImpl(fromAccount: AccountType, toAccount: AccountType, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType): Box[TransactionId] = {
|
||||
val sentTransactionId = saveTransaction(fromAccount, toAccount, toCounterparty, -amt, description,transactionRequestType )
|
||||
protected override def makePaymentImpl(fromAccount: KafkaBankAccount, toAccount: KafkaBankAccount, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String): Box[TransactionId] = {
|
||||
val sentTransactionId = saveTransaction(fromAccount, toAccount, toCounterparty, -amt, description, transactionRequestType, chargePolicy)
|
||||
|
||||
sentTransactionId
|
||||
}
|
||||
@ -612,7 +612,7 @@ object KafkaMappedConnector extends Connector with Loggable {
|
||||
* Saves a transaction with amount @amt and counterparty @counterparty for account @account. Returns the id
|
||||
* of the saved transaction.
|
||||
*/
|
||||
private def saveTransaction(fromAccount: AccountType, toAccount: AccountType, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType) = {
|
||||
private def saveTransaction(fromAccount: KafkaBankAccount, toAccount: KafkaBankAccount, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String) = {
|
||||
|
||||
val transactionTime = now
|
||||
val currency = fromAccount.currency
|
||||
@ -646,7 +646,8 @@ object KafkaMappedConnector extends Connector with Loggable {
|
||||
"counterpartyOtherAccountRoutingScheme" -> toCounterparty.otherAccountRoutingScheme,
|
||||
"counterpartyOtherAccountRoutingAddress" -> toCounterparty.otherAccountRoutingAddress,
|
||||
"counterpartyOtherBankRoutingScheme" -> toCounterparty.otherBankRoutingScheme,
|
||||
"counterpartyOtherBankRoutingAddress" -> toCounterparty.otherBankRoutingAddress
|
||||
"counterpartyOtherBankRoutingAddress" -> toCounterparty.otherBankRoutingAddress,
|
||||
"chargePolicy" -> chargePolicy
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ private object LocalConnector extends Connector with Loggable {
|
||||
By(MappedAccountHolder.accountPermalink, accountId.value)).map(accHolder => accHolder.user.obj).flatten.toSet
|
||||
}
|
||||
|
||||
override protected def makePaymentImpl(fromAccount: Account, toAccount: Account, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType): Box[TransactionId] = {
|
||||
override protected def makePaymentImpl(fromAccount: Account, toAccount: Account, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String): Box[TransactionId] = {
|
||||
val fromTransAmt = -amt //from account balance should decrease
|
||||
val toTransAmt = amt //to account balance should increase
|
||||
|
||||
|
||||
@ -377,7 +377,7 @@ object LocalMappedConnector extends Connector with Loggable {
|
||||
Perform a payment (in the sandbox)
|
||||
Store one or more transactions
|
||||
*/
|
||||
override def makePaymentImpl(fromAccount: MappedBankAccount, toAccount: MappedBankAccount, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType): Box[TransactionId] = {
|
||||
protected override def makePaymentImpl(fromAccount: MappedBankAccount, toAccount: MappedBankAccount, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String): Box[TransactionId] = {
|
||||
|
||||
//we need to save a copy of this payment as a transaction in each of the accounts involved, with opposite amounts
|
||||
|
||||
@ -394,10 +394,10 @@ Store one or more transactions
|
||||
val toTransAmt = fx.convert(amt, rate.get)
|
||||
|
||||
// From
|
||||
val sentTransactionId = saveTransaction(fromAccount, toAccount, toCounterparty, fromTransAmt, description, transactionRequestType)
|
||||
val sentTransactionId = saveTransaction(fromAccount, toAccount, toCounterparty, fromTransAmt, description, transactionRequestType, chargePolicy)
|
||||
|
||||
// To
|
||||
val recievedTransactionId = saveTransaction(toAccount, fromAccount, toCounterparty, toTransAmt, description, transactionRequestType)
|
||||
val recievedTransactionId = saveTransaction(toAccount, fromAccount, toCounterparty, toTransAmt, description, transactionRequestType, chargePolicy)
|
||||
|
||||
// Return the sent transaction id
|
||||
sentTransactionId
|
||||
@ -412,7 +412,8 @@ Store one or more transactions
|
||||
toCounterparty: CounterpartyTrait,
|
||||
amt: BigDecimal,
|
||||
description: String,
|
||||
transactionRequestType: TransactionRequestType): Box[TransactionId] = {
|
||||
transactionRequestType: TransactionRequestType,
|
||||
chargePolicy: String): Box[TransactionId] = {
|
||||
|
||||
val transactionTime = now
|
||||
val currency = fromAccount.currency
|
||||
@ -448,7 +449,8 @@ Store one or more transactions
|
||||
.CPOtherAccountRoutingScheme(toCounterparty.otherAccountRoutingScheme)
|
||||
.CPOtherAccountRoutingAddress(toCounterparty.otherAccountRoutingAddress)
|
||||
.CPOtherBankRoutingScheme(toCounterparty.otherBankRoutingScheme)
|
||||
.CPOtherBankRoutingAddress(toCounterparty.otherBankRoutingAddress)
|
||||
.CPOtherBankRoutingAddress(toCounterparty.otherBankRoutingAddress)
|
||||
.chargePolicy(chargePolicy)
|
||||
.saveMe
|
||||
|
||||
Full(mappedTransaction.theTransactionId)
|
||||
|
||||
@ -568,7 +568,7 @@ object ObpJvmMappedConnector extends Connector with Loggable {
|
||||
}
|
||||
|
||||
|
||||
override def makePaymentImpl(fromAccount: AccountType, toAccount: AccountType, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType): Box[TransactionId] = {
|
||||
protected override def makePaymentImpl(fromAccount: ObpJvmBankAccount, toAccount: ObpJvmBankAccount, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String): Box[TransactionId] = {
|
||||
for {
|
||||
// TODO Do we charge +amt or -amt?
|
||||
sentTransactionId <- saveTransaction(fromAccount, toAccount, amt, description)
|
||||
|
||||
@ -34,6 +34,7 @@ class MappedTransaction extends LongKeyedMapper[MappedTransaction] with IdPK wit
|
||||
object tFinishDate extends MappedDateTime(this)
|
||||
|
||||
object description extends DefaultStringField(this)
|
||||
object chargePolicy extends DefaultStringField(this)
|
||||
|
||||
object counterpartyAccountNumber extends MappedAccountNumber(this)
|
||||
object counterpartyAccountHolder extends MappedString(this, 100)
|
||||
|
||||
@ -133,7 +133,7 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers with DefaultConne
|
||||
|
||||
override def getAccountHolders(bankId: BankId, accountID: AccountId) : Set[User] = Set.empty
|
||||
|
||||
override def makePaymentImpl(fromAccount: AccountType, toAccount: AccountType, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType): Box[TransactionId] =
|
||||
protected override def makePaymentImpl(fromAccount:AccountType, toAccount: AccountType, toCounterparty: CounterpartyTrait, amt: BigDecimal, description: String, transactionRequestType: TransactionRequestType, chargePolicy: String): Box[TransactionId] =
|
||||
Failure("not supported")
|
||||
override def createTransactionRequestImpl(transactionRequestId: TransactionRequestId, transactionRequestType: TransactionRequestType,
|
||||
account : BankAccount, counterparty : BankAccount, body: TransactionRequestBody,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user