Skip to content

Commit

Permalink
Merge pull request #944 from hmrc/DL-8900
Browse files Browse the repository at this point in the history
DL-8900 - added new data for 1811 call
  • Loading branch information
ahlee0 authored Oct 18, 2022
2 parents e866828 + 3c5f079 commit 6b0bff0
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 71 deletions.
94 changes: 60 additions & 34 deletions app/v1/models/response/financialData/FinancialDataResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,92 @@ import play.api.libs.json._
import v1.models.errors.MtdError
import play.api.libs.functional.syntax._

case class LineItemInterestDetails(interestKey: String,
interestStartDate: String)
case class LineItemInterestDetails(interestKey: Option[String],
currentInterestRate: Option[BigDecimal],
interestPostedAmount: Option[BigDecimal],
interestAccruingAmount: Option[BigDecimal],
interestStartDate: Option[String])

object LineItemInterestDetails {
implicit val format: OFormat[LineItemInterestDetails] = Json.format[LineItemInterestDetails]
}

case class LineItemDetail(periodFromDate: String,
periodToDate: String,
periodKey: String,
netDueDate: String,
amount: BigDecimal,
lineItemInterestDetails: LineItemInterestDetails)
case class LineItemDetail(
chargeDescription: Option[String],
periodFromDate: Option[String],
periodToDate: Option[String],
periodKey: Option[String],
netDueDate: Option[String],
amount: Option[BigDecimal],
lineItemInterestDetails: Option[LineItemInterestDetails])

object LineItemDetail {
implicit val format: OFormat[LineItemDetail] = Json.format[LineItemDetail]
}

case class DocumentDetail(postingDate: String,
issueDate: String,
documentTotalAmount: BigDecimal,
documentClearedAmount: BigDecimal,
documentOutstandingAmount: BigDecimal,
documentInterestTotal: BigDecimal,
lineItemDetails: Seq[LineItemDetail])
case class DocumentInterestTotals(interestPostedAmount: Option[BigDecimal],
interestAccruingAmount: Option[BigDecimal])

object DocumentInterestTotals {
implicit val format: OFormat[DocumentInterestTotals] = Json.format[DocumentInterestTotals]
}

case class DocumentDetail(postingDate: Option[String],
issueDate: Option[String],
documentTotalAmount: Option[BigDecimal],
documentClearedAmount: Option[BigDecimal],
documentInterestTotals: Option[DocumentInterestTotals],
documentOutstandingAmount: Option[BigDecimal],
documentInterestTotal: Option[BigDecimal],
lineItemDetails: Option[Seq[LineItemDetail]])

object DocumentDetail {
implicit val reads: Reads[DocumentDetail] = (
(JsPath \ "postingDate").read[String] and
(JsPath \ "issueDate").read[String] and
(JsPath \ "documentTotalAmount").read[BigDecimal] and
(JsPath \ "documentClearedAmount").read[BigDecimal] and
(JsPath \ "documentOutstandingAmount").read[BigDecimal] and
(JsPath \ "documentInterestTotals" \ "interestTotalAmount").read[BigDecimal] and
(JsPath \ "lineItemDetails").read[Seq[LineItemDetail]]
(JsPath \ "postingDate").readNullable[String] and
(JsPath \ "issueDate").readNullable[String] and
(JsPath \ "documentTotalAmount").readNullable[BigDecimal] and
(JsPath \ "documentClearedAmount").readNullable[BigDecimal] and
(JsPath \ "documentInterestTotals").readNullable[DocumentInterestTotals] and
(JsPath \ "documentOutstandingAmount").readNullable[BigDecimal] and
(JsPath \ "documentInterestTotals" \ "interestTotalAmount").readNullable[BigDecimal] and
(JsPath \ "lineItemDetails").readNullable[Seq[LineItemDetail]]
)(DocumentDetail.apply _)

implicit val writes: OWrites[DocumentDetail] = Json.writes[DocumentDetail]
}

case class Totalisation(totalOverdue: BigDecimal,
totalNotYetDue: BigDecimal,
totalBalance: BigDecimal,
totalCredit: BigDecimal,
totalCleared: BigDecimal)

case class AdditionalReceivableTotalisations(totalAccountPostedInterest: Option[BigDecimal],
totalAccountAccruingInterest: Option[BigDecimal])

object AdditionalReceivableTotalisations {
implicit val format: OFormat[AdditionalReceivableTotalisations] = Json.format[AdditionalReceivableTotalisations]

}

case class Totalisation(totalOverdue: Option[BigDecimal],
totalNotYetDue: Option[BigDecimal],
totalBalance: Option[BigDecimal],
totalCredit: Option[BigDecimal],
totalCleared: Option[BigDecimal],
additionalReceivableTotalisations: Option[AdditionalReceivableTotalisations])

object Totalisation {
implicit val reads: Reads[Totalisation] = (
(JsPath \ "targetedSearch" \ "totalOverdue").read[BigDecimal] and
(JsPath \ "targetedSearch" \ "totalNotYetDue").read[BigDecimal] and
(JsPath \ "targetedSearch" \ "totalBalance").read[BigDecimal] and
(JsPath \ "targetedSearch" \ "totalCredit").read[BigDecimal] and
(JsPath \ "targetedSearch" \ "totalCleared").read[BigDecimal]
(JsPath \ "targetedSearch_SelectionCriteriaTotalisation" \ "totalOverdue").readNullable[BigDecimal] and
(JsPath \ "targetedSearch_SelectionCriteriaTotalisation" \ "totalNotYetDue").readNullable[BigDecimal] and
(JsPath \ "targetedSearch_SelectionCriteriaTotalisation" \ "totalBalance").readNullable[BigDecimal] and
(JsPath \ "targetedSearch_SelectionCriteriaTotalisation" \ "totalCredit").readNullable[BigDecimal] and
(JsPath \ "targetedSearch_SelectionCriteriaTotalisation" \ "totalCleared").readNullable[BigDecimal] and
(JsPath \ "additionalReceivableTotalisations").readNullable[AdditionalReceivableTotalisations]
)(Totalisation.apply _)

implicit val writes: OWrites[Totalisation] = Json.writes[Totalisation]
}

case class FinancialDataResponse(totalisation: Totalisation,
documentDetails: Seq[DocumentDetail])

case class FinancialDataResponse(totalisation: Option[Totalisation],
documentDetails: Option[Seq[DocumentDetail]])

object FinancialDataResponse {
implicit val format: OFormat[FinancialDataResponse] = Json.format[FinancialDataResponse]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"totalNotYetDue": 12.34,
"totalBalance": 12.45,
"totalCredit": 13.46,
"totalCleared": 12.35
"totalCleared": 12.35,
"additionalReceivableTotalisations" :{
"totalAccountPostedInterest": 10.1,
"totalAccountAccruingInterest": 11.2
}
},
"documentDetails": [
{
Expand All @@ -13,17 +17,25 @@
"documentTotalAmount": 123.45,
"documentClearedAmount": 111.11,
"documentOutstandingAmount": 12.34,
"documentInterestTotals": {
"interestPostedAmount": 13.12,
"interestAccruingAmount": 12.10
},
"documentInterestTotal": 1.23,
"lineItemDetails": [
{
"chargeDescription": "VAT Return",
"periodFromDate": "2022-03-01",
"periodToDate": "2022-03-01",
"periodKey": "13RL",
"netDueDate": "2022-03-01",
"amount": 123.45,
"lineItemInterestDetails": {
"interestKey": "01",
"interestStartDate": "2022-03-01"
"interestStartDate": "2022-03-01",
"currentInterestRate": 2,
"interestPostedAmount": 12,
"interestAccruingAmount": 13.1
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@
"description": "The amount that has been paid, reversed, removed or cleared. The value must be between -99999999999.99 and 99999999999.99 to 2 decimal places.",
"type": "number",
"example": "5009.99"
},
"additionalReceivableTotalisations" : {
"description": "Interest totals that relate to the VAT account.",
"type": "object",
"properties": {
"totalAccountPostedInterest": {
"description": "The total amount of interest that has been posted to the account.",
"type": "number",
"example": "5009.99"
},
"totalAccountAccruingInterest": {
"description": "The total amount of interest that the account has accrued since interest was last posted to it. This amount is yet to be posted to the account.",
"type": "number",
"example": "5009.99"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -51,6 +68,23 @@
"type": "string",
"example": "2022-08-16"
},
"documentInterestTotals": {
"description": "Interest totals that relate to the charge.",
"type": "object",
"properties": {
"interestPostedAmount": {
"description": "The amount of interest, relating to the charge, that has been posted to the account.",
"type": "number",
"example": "5009.99"
},
"interestAccruingAmount": {
"description": "The amount of interest that has accrued since interest on the charge was last posted to the account.",
"type": "number",
"example": "5009.99"
}
},
"additionalProperties": false
},
"documentTotalAmount": {
"description": "The total sum of the line items within the document. The value must be between -99999999999.99 and 99999999999.99 to 2 decimal places.",
"type": "number",
Expand All @@ -77,6 +111,11 @@
"items": {
"type": "object",
"properties": {
"chargeDescription": {
"description": "Describes what the charge relates to.",
"type": "string",
"example": "VAT Return"
},
"periodFromDate": {
"description": "The start date of this period.",
"type": "string",
Expand All @@ -103,7 +142,7 @@
"example": "5009.99"
},
"lineItemInterestDetails": {
"description": "",
"description": "Details of the interest that relates to the line item.",
"type": "object",
"properties": {
"interestKey": {
Expand All @@ -115,6 +154,21 @@
"description": "The date that the interest charges started.",
"type": "string",
"example": "2022-08-16"
},
"currentInterestRate": {
"description": "The rate of interest that currently applies to the line item.",
"type": "number",
"example": "2"
},
"interestPostedAmount": {
"description": "The amount of interest, relating to the line item, that has been posted to the account.",
"type": "number",
"example": "10"
},
"interestAccruingAmount": {
"description": "The amount of interest that has accrued since interest on the line item was last posted to the account.",
"type": "number",
"example": "10"
}
},
"additionalProperties": false
Expand Down
26 changes: 23 additions & 3 deletions test/v1/connectors/httpparsers/FinancialDataHttpParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,38 @@ class FinancialDataHttpParserSpec extends UnitSpec {

result shouldBe Right(FinancialDataConstants.wrappedFinancialDataResponse(FinancialDataConstants.testFinancialDataResponse))
}

"return Right(FinancialDataResponse) No Document Details" in {

val result = FinancialDataHttpReads.read("", "",
HttpResponse(
status = Status.OK,
json = FinancialDataConstants.testDownstreamFinancialDetailsNoDocumentDetails,
headers = Map(
"CorrelationId" -> Seq(FinancialDataConstants.correlationId)
)
)
)

result shouldBe Right(FinancialDataConstants.wrappedFinancialDataResponse(FinancialDataConstants.testFinancialNoDocumentDetailsDataResponse))
}
}

"json is invalid" must {

"return Left(InvalidJson)" in {

val jsonObject =
Json.parse("""
| "totalisations" {
| "test": "test"
| }
|""".stripMargin)

val result = FinancialDataHttpReads.read("", "",
HttpResponse(
status = Status.OK,
json = Json.obj(
"totalisations" -> "test"
),
json = jsonObject,
headers = Map(
"CorrelationId" -> Seq(FinancialDataConstants.correlationId)
)
Expand Down
Loading

0 comments on commit 6b0bff0

Please sign in to comment.