diff --git a/app/uk/gov/hmrc/epayeapi/connectors/EpayeConnector.scala b/app/uk/gov/hmrc/epayeapi/connectors/EpayeConnector.scala index b28d3be..cca13d6 100644 --- a/app/uk/gov/hmrc/epayeapi/connectors/EpayeConnector.scala +++ b/app/uk/gov/hmrc/epayeapi/connectors/EpayeConnector.scala @@ -84,15 +84,9 @@ case class EpayeConnector @Inject() ( } def getPaymentHistory(empRef: EmpRef, taxYear: TaxYear, headers: HeaderCarrier): Future[EpayeResponse[EpayePaymentHistory]] = { - val url = s"${config.epayeBaseUrl}/epaye/${empRef.encodedValue}/api/v1/payment-history/${taxYear.asString}" - - get[EpayePaymentHistory](url, headers) - } - - def getPaymentHistoryWithAllocations(empRef: EmpRef, taxYear: TaxYear, headers: HeaderCarrier): Future[EpayeResponse[EpayePaymentHistoryWithAllocations]] = { val url = s"${config.epayeBaseUrl}/epaye/${empRef.encodedValue}/api/v1/payment-history-with-allocations/${taxYear.asString}" - get[EpayePaymentHistoryWithAllocations](url, headers) + get[EpayePaymentHistory](url, headers) } } diff --git a/app/uk/gov/hmrc/epayeapi/controllers/GetPaymentHistoryController.scala b/app/uk/gov/hmrc/epayeapi/controllers/GetPaymentHistoryController.scala index 6b5d354..cc1a2cf 100644 --- a/app/uk/gov/hmrc/epayeapi/controllers/GetPaymentHistoryController.scala +++ b/app/uk/gov/hmrc/epayeapi/controllers/GetPaymentHistoryController.scala @@ -16,9 +16,8 @@ package uk.gov.hmrc.epayeapi.controllers -import javax.inject.{Inject, Singleton} - import akka.stream.Materializer +import javax.inject.{Inject, Singleton} import play.api.libs.json.Json import play.api.mvc.{Action, EssentialAction, Result} import uk.gov.hmrc.auth.core.AuthConnector @@ -32,7 +31,7 @@ import uk.gov.hmrc.epayeapi.models.out.PaymentHistoryJson import scala.concurrent.ExecutionContext @Singleton -case class GetPaymentHistoryController @Inject() ( +case class GetPaymentHistoryController @Inject()( config: EpayeApiConfig, authConnector: AuthConnector, epayeConnector: EpayeConnector, diff --git a/app/uk/gov/hmrc/epayeapi/controllers/GetPaymentHistoryWithAllocationsController.scala b/app/uk/gov/hmrc/epayeapi/controllers/GetPaymentHistoryWithAllocationsController.scala deleted file mode 100644 index 7de00a4..0000000 --- a/app/uk/gov/hmrc/epayeapi/controllers/GetPaymentHistoryWithAllocationsController.scala +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2018 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.epayeapi.controllers - -import javax.inject.{Inject, Singleton} - -import akka.stream.Materializer -import play.api.libs.json.Json -import play.api.mvc.{Action, EssentialAction, Result} -import uk.gov.hmrc.auth.core.AuthConnector -import uk.gov.hmrc.domain.EmpRef -import uk.gov.hmrc.epayeapi.connectors.{EpayeApiConfig, EpayeConnector} -import uk.gov.hmrc.epayeapi.models.Formats.paymentHistoryWithAllocationsJsonWrites -import uk.gov.hmrc.epayeapi.models.TaxYear -import uk.gov.hmrc.epayeapi.models.in.{EpayePaymentHistory, EpayePaymentHistoryWithAllocations, EpayeResponse, EpayeSuccess} -import uk.gov.hmrc.epayeapi.models.out.PaymentHistoryWithAllocationsJson - -import scala.concurrent.ExecutionContext - -@Singleton -case class GetPaymentHistoryWithAllocationsController @Inject() ( - config: EpayeApiConfig, - authConnector: AuthConnector, - epayeConnector: EpayeConnector, - implicit val ec: ExecutionContext, - implicit val mat: Materializer -) - extends ApiController - with EpayeErrorHandler { - - def getPaymentHistoryWithAllocations(empRef: EmpRef, taxYear: TaxYear): EssentialAction = { - EmpRefAction(empRef) { - Action.async { implicit request => - val epayePaymentHistory = epayeConnector.getPaymentHistoryWithAllocations(empRef, taxYear, hc) - epayePaymentHistory.map { - successHandler(empRef, taxYear) orElse errorHandler - } - } - } - } - - private def successHandler(empRef: EmpRef, taxYear: TaxYear): PartialFunction[EpayeResponse[EpayePaymentHistoryWithAllocations], Result] = { - case EpayeSuccess(epayePaymentHistory) => - val paymentHistory = PaymentHistoryWithAllocationsJson.transform(config.apiBaseUrl, empRef, taxYear, epayePaymentHistory) - - Ok(Json.toJson(paymentHistory)) - } -} diff --git a/app/uk/gov/hmrc/epayeapi/models/in/EpayePaymentHistory.scala b/app/uk/gov/hmrc/epayeapi/models/in/EpayePaymentHistory.scala index bd65257..fe5b124 100644 --- a/app/uk/gov/hmrc/epayeapi/models/in/EpayePaymentHistory.scala +++ b/app/uk/gov/hmrc/epayeapi/models/in/EpayePaymentHistory.scala @@ -17,11 +17,39 @@ package uk.gov.hmrc.epayeapi.models.in import org.joda.time.LocalDate +import uk.gov.hmrc.epayeapi.models.TaxYear -case class EpayePaymentHistory(payments: Seq[EpayePaymentHistoryPayment]) +case class EpayePaymentHistory( + taxYear: TaxYear, + payments: Seq[EpayePaymentHistoryPayment] +) case class EpayePaymentHistoryPayment( - dateOfPayment: Option[LocalDate], - amount: BigDecimal + paymentDate: Option[LocalDate], + method: Option[String], + amount: BigDecimal, + allocatedAmount: BigDecimal, + allocations: Seq[EpayePaymentAllocation] ) +trait EpayePaymentAllocation { + def period: EpayeTaxPeriod + def amount: BigDecimal + def code: Option[EpayeCode] + + lazy val taxYear: TaxYear = TaxYear(period.startingTaxYear) + lazy val taxMonth: EpayeTaxMonth = EpayeTaxMonth.fromLocalDate(period.taxFrom) +} + +case class EpayeRtiPaymentAllocation( + period: EpayeTaxPeriod, + amount: BigDecimal +) extends EpayePaymentAllocation { + lazy val code: Option[EpayeCode] = None +} + +case class EpayeNonRtiPaymentAllocation( + period: EpayeTaxPeriod, + amount: BigDecimal, + code: Option[EpayeCode] +) extends EpayePaymentAllocation \ No newline at end of file diff --git a/app/uk/gov/hmrc/epayeapi/models/in/EpayePaymentHistoryWithAllocations.scala b/app/uk/gov/hmrc/epayeapi/models/in/EpayePaymentHistoryWithAllocations.scala deleted file mode 100644 index 3739a9f..0000000 --- a/app/uk/gov/hmrc/epayeapi/models/in/EpayePaymentHistoryWithAllocations.scala +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2018 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.epayeapi.models.in - -import org.joda.time.LocalDate -import uk.gov.hmrc.epayeapi.models.TaxYear - -case class EpayePaymentHistoryWithAllocations( - taxYear: TaxYear, - payments: Seq[EpayePaymentHistoryWithAllocationsPayment] -) - -case class EpayePaymentHistoryWithAllocationsPayment( - paymentDate: Option[LocalDate], - method: Option[String], - amount: BigDecimal, - allocatedAmount: BigDecimal, - allocations: Seq[EpayePaymentAllocation] -) - -trait EpayePaymentAllocation { - def period: EpayeTaxPeriod - def amount: BigDecimal - def code: Option[EpayeCode] - - lazy val taxYear: TaxYear = TaxYear(period.startingTaxYear) - lazy val taxMonth: EpayeTaxMonth = EpayeTaxMonth.fromLocalDate(period.taxFrom) -} - -case class EpayeRtiPaymentAllocation( - period: EpayeTaxPeriod, - amount: BigDecimal -) extends EpayePaymentAllocation { - lazy val code: Option[EpayeCode] = None -} - -case class EpayeNonRtiPaymentAllocation( - period: EpayeTaxPeriod, - amount: BigDecimal, - code: Option[EpayeCode] -) extends EpayePaymentAllocation \ No newline at end of file diff --git a/app/uk/gov/hmrc/epayeapi/models/in/EpayeReads.scala b/app/uk/gov/hmrc/epayeapi/models/in/EpayeReads.scala index 7f553dd..d6d180c 100644 --- a/app/uk/gov/hmrc/epayeapi/models/in/EpayeReads.scala +++ b/app/uk/gov/hmrc/epayeapi/models/in/EpayeReads.scala @@ -57,9 +57,6 @@ trait EpayeReads { implicit lazy val epayePaymentHistoryReads: Reads[EpayePaymentHistory] = reads[EpayePaymentHistory] implicit lazy val epayePaymentHistoryPaymentReads: Reads[EpayePaymentHistoryPayment] = reads[EpayePaymentHistoryPayment] - - implicit lazy val epayePaymentHistoryWithAllocationsReads: Reads[EpayePaymentHistoryWithAllocations] = reads[EpayePaymentHistoryWithAllocations] - implicit lazy val epayePaymentHistoryWithAllocationsPaymentReads: Reads[EpayePaymentHistoryWithAllocationsPayment] = reads[EpayePaymentHistoryWithAllocationsPayment] implicit lazy val epayeRtiPaymentAllocationReads: Reads[EpayeRtiPaymentAllocation] = reads[EpayeRtiPaymentAllocation] implicit lazy val epayeNonRtiPaymentAllocationReads: Reads[EpayeNonRtiPaymentAllocation] = reads[EpayeNonRtiPaymentAllocation] implicit lazy val epayePaymentAllocationReads: Reads[EpayePaymentAllocation] = new Reads[EpayePaymentAllocation]() { diff --git a/app/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJson.scala b/app/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJson.scala index 998b569..4bc3ba4 100644 --- a/app/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJson.scala +++ b/app/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJson.scala @@ -122,7 +122,8 @@ case class AnnualStatementLinksJson( statements: Link, self: Link, next: Link, - previous: Link + previous: Link, + paymentHistory: Link ) case class AnnualStatementJson( @@ -151,7 +152,8 @@ object AnnualStatementJson { statements = Link.statementsLink(empRef), self = Link.annualStatementLink(empRef, taxYear), next = Link.annualStatementLink(empRef, taxYear.next), - previous = Link.annualStatementLink(empRef, taxYear.previous) + previous = Link.annualStatementLink(empRef, taxYear.previous), + paymentHistory = Link.paymentHistoryLink(empRef, taxYear) ) ) diff --git a/app/uk/gov/hmrc/epayeapi/models/out/JsonWrites.scala b/app/uk/gov/hmrc/epayeapi/models/out/JsonWrites.scala index fb367b3..5263d67 100644 --- a/app/uk/gov/hmrc/epayeapi/models/out/JsonWrites.scala +++ b/app/uk/gov/hmrc/epayeapi/models/out/JsonWrites.scala @@ -77,10 +77,7 @@ trait JsonWrites { implicit lazy val statementsLinksJsonWrites: Writes[StatementLinks] = writes[StatementLinks] implicit lazy val paymentHistoryJsonWrites: Writes[PaymentHistoryJson] = writes[PaymentHistoryJson] - implicit lazy val paymentHistoryLinksJsonWrites: Writes[PaymentHistoryLinks] = writes[PaymentHistoryLinks] - - implicit lazy val paymentHistoryWithAllocationsJsonWrites: Writes[PaymentHistoryWithAllocationsJson] = writes[PaymentHistoryWithAllocationsJson] - implicit lazy val paymentWithAllocationsJsonWrites: Writes[PaymentWithAllocations] = writes[PaymentWithAllocations] + implicit lazy val paymentJsonWrites: Writes[PaymentJson] = writes[PaymentJson] implicit lazy val paymentAllocationJsonWrites: Writes[PaymentAllocation] = writes[PaymentAllocation] - implicit lazy val paymentHistoryWithAllocationsLinksJsonWrites: Writes[PaymentHistoryWithAllocationsLinks] = writes[PaymentHistoryWithAllocationsLinks] + implicit lazy val paymentHistoryLinksJsonWrites: Writes[PaymentHistoryLinks] = writes[PaymentHistoryLinks] } diff --git a/app/uk/gov/hmrc/epayeapi/models/out/Link.scala b/app/uk/gov/hmrc/epayeapi/models/out/Link.scala index c8d1c7c..2d44880 100644 --- a/app/uk/gov/hmrc/epayeapi/models/out/Link.scala +++ b/app/uk/gov/hmrc/epayeapi/models/out/Link.scala @@ -41,7 +41,4 @@ object Link { def paymentHistoryLink(empRef: EmpRef, taxYear: TaxYear): Link = Link(s"$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}") - - def paymentHistoryWithAllocationsLink(empRef: EmpRef, taxYear: TaxYear): Link = - Link(s"$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}/allocations") } diff --git a/app/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJson.scala b/app/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJson.scala index b6c86f4..9c2f7ef 100644 --- a/app/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJson.scala +++ b/app/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJson.scala @@ -16,51 +16,131 @@ package uk.gov.hmrc.epayeapi.models.out +import org.joda.time.LocalDate +import play.api.Logger import uk.gov.hmrc.domain.EmpRef -import uk.gov.hmrc.epayeapi.models.TaxYear -import uk.gov.hmrc.epayeapi.models.in.EpayePaymentHistory +import uk.gov.hmrc.epayeapi.models.{TaxMonth, TaxYear} +import uk.gov.hmrc.epayeapi.models.in.{EpayePaymentAllocation, EpayePaymentHistory, EpayePaymentHistoryPayment, EpayeRtiPaymentAllocation} -case class PaymentHistoryJson ( +case class PaymentHistoryJson( taxOfficeNumber: String, taxOfficeReference: String, taxYear: TaxYear, - payments: Seq[Payment], + payments: Seq[PaymentJson], _links: PaymentHistoryLinks ) -case class PaymentHistoryLinks ( +case class PaymentJson( + paymentDate: LocalDate, + method: Option[String], + amount: BigDecimal, + allocatedAmount: BigDecimal, + allocations: Seq[PaymentAllocation] +) + +case class PaymentAllocation( + taxYear: TaxYear, + taxMonth: TaxMonth, + amount: BigDecimal, + code: Option[String] +) + +object PaymentAllocation { + def transform(epayePaymentAllocation: EpayePaymentAllocation): PaymentAllocation = { + PaymentAllocation( + epayePaymentAllocation.taxYear, + TaxMonth(epayePaymentAllocation.taxYear, epayePaymentAllocation.taxMonth.month), + epayePaymentAllocation.amount, + epayePaymentAllocation.code.map { _.name } + ) + } +} + +case class PaymentHistoryLinks( empRefs: Link, summary: Link, statements: Link, + statement: Link, self: Link, next: Link, previous: Link ) +object PaymentJson { + import uk.gov.hmrc.epayeapi.models.ImplicitOrderings.localDateDescendingOrdering + + implicit val paymentDescendingOrdering = Ordering.by[PaymentJson, (LocalDate, BigDecimal)](payment => (payment.paymentDate, -payment.amount)) + + private lazy val paymentMethods: Map[String, String] = Map( + "TPS RECEIPTS BY DEBIT CARD" -> "Debit Card", + "PAYMENTS MADE BY CHEQUE" -> "Cheque", + "CHEQUE RECEIPTS" -> "Cheque", + "BACS RECEIPTS" -> "BACS", + "CHAPS" -> "CHAPS", + "TPS RECEIPTS BY CREDIT CARD" -> "Credit Card", + "NATIONAL DIRECT DEBIT RECEIPTS" -> "Direct Debit", + "BILLPAY/OLPG/GIROBANK" -> "Online Payment", + "BANK LODGEMENT PAYMENT" -> "Bank Lodgement", + "BANK GIRO RECEIPTS" -> "Giro Receipts", + "BANK GIRO IN CREDITS" -> "Giro Credits", + "FPS RECEIPTS" -> "FPS Receipts", + "CREDIT FOR INTERNET RECEIPTS" -> "Internet Receipts", + "GIROBANK RECEIPTS" -> "Girobank", + "GIROBANK/ POST OFFICE" -> "Post Office", + "NIL DECLARATIONS" -> "Nil Declarations", + "PAYMASTER" -> "Paymaster", + "VOLUNTARY DIRECT PAYMENTS" -> "Voluntary Payments" + ) withDefault { unknown => + Logger.warn(s"Invalid payment method: [${unknown}].") + "UNKNOWN" + } + + def transform(paymentMethodMaybe: Option[String]): Option[String] = { + paymentMethodMaybe.map { paymentMethods } + } +} + object PaymentHistoryJson { def transform( apiBaseUrl: String, empRef: EmpRef, taxYear: TaxYear, - epayePaymentHistory: EpayePaymentHistory): PaymentHistoryJson = { + epayePaymentHistory: EpayePaymentHistory + ): PaymentHistoryJson = { - val payments: Seq[Payment] = for { + val payments: Seq[PaymentJson] = for { epayePayment <- epayePaymentHistory.payments - } yield Payment(epayePayment.dateOfPayment, epayePayment.amount) + epayePaymentDate <- epayePayment.paymentDate + } yield toPayment(epayePayment, epayePaymentDate) PaymentHistoryJson( empRef.taxOfficeNumber, empRef.taxOfficeReference, taxYear, - payments.sorted(Payment.paymentDescendingOrdering), + payments.sorted(PaymentJson.paymentDescendingOrdering), PaymentHistoryLinks( empRefs = Link.empRefsLink, summary = Link.summaryLink(empRef), statements = Link.statementsLink(empRef), + statement = Link.annualStatementLink(empRef, taxYear), self = Link.paymentHistoryLink(empRef, taxYear), next = Link.paymentHistoryLink(empRef, taxYear.next), previous = Link.paymentHistoryLink(empRef, taxYear.previous) ) ) } -} \ No newline at end of file + + private def toPayment( + epayePaymentHistoryPayment: EpayePaymentHistoryPayment, + epayePaymentDate: LocalDate + ): PaymentJson = { + + PaymentJson( + epayePaymentDate, + PaymentJson.transform(epayePaymentHistoryPayment.method), + epayePaymentHistoryPayment.amount, + epayePaymentHistoryPayment.allocatedAmount, + epayePaymentHistoryPayment.allocations.map { PaymentAllocation.transform } + ) + } +} diff --git a/app/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryWithAllocationsJson.scala b/app/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryWithAllocationsJson.scala deleted file mode 100644 index 98f74db..0000000 --- a/app/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryWithAllocationsJson.scala +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2018 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.epayeapi.models.out - -import org.joda.time.LocalDate -import play.api.Logger -import uk.gov.hmrc.domain.EmpRef -import uk.gov.hmrc.epayeapi.models.{TaxMonth, TaxYear} -import uk.gov.hmrc.epayeapi.models.in.{EpayePaymentAllocation, EpayePaymentHistoryWithAllocations, EpayePaymentHistoryWithAllocationsPayment, EpayeRtiPaymentAllocation} - -case class PaymentHistoryWithAllocationsJson ( - taxOfficeNumber: String, - taxOfficeReference: String, - taxYear: TaxYear, - payments: Seq[PaymentWithAllocations], - _links: PaymentHistoryWithAllocationsLinks -) - -case class PaymentWithAllocations( - paymentDate: LocalDate, - method: Option[String], - amount: BigDecimal, - allocatedAmount: BigDecimal, - allocations: Seq[PaymentAllocation] -) - -case class PaymentAllocation( - taxYear: TaxYear, - taxMonth: TaxMonth, - amount: BigDecimal, - code: Option[String] -) - -object PaymentAllocation{ - def transform(epayePaymentAllocation: EpayePaymentAllocation): PaymentAllocation = { - PaymentAllocation( - epayePaymentAllocation.taxYear, - TaxMonth(epayePaymentAllocation.taxYear, epayePaymentAllocation.taxMonth.month), - epayePaymentAllocation.amount, - epayePaymentAllocation.code.map{_.name} - ) - } -} - -case class PaymentHistoryWithAllocationsLinks ( - empRefs: Link, - summary: Link, - statements: Link, - payments: Link, - self: Link, - next: Link, - previous: Link -) - -object PaymentWithAllocations { - import uk.gov.hmrc.epayeapi.models.ImplicitOrderings.localDateDescendingOrdering - - implicit val paymentDescendingOrdering = Ordering.by[PaymentWithAllocations, (LocalDate, BigDecimal)](payment => (payment.paymentDate, -payment.amount)) - - private lazy val paymentMethods: Map[String, String] = Map( - "TPS RECEIPTS BY DEBIT CARD" -> "Debit Card", - "PAYMENTS MADE BY CHEQUE" -> "Cheque", - "CHEQUE RECEIPTS" -> "Cheque", - "BACS RECEIPTS" -> "BACS", - "CHAPS" -> "CHAPS", - "TPS RECEIPTS BY CREDIT CARD" -> "Credit Card", - "NATIONAL DIRECT DEBIT RECEIPTS" -> "Direct Debit", - "BILLPAY/OLPG/GIROBANK" -> "Online Payment", - "BANK LODGEMENT PAYMENT" -> "Bank Lodgement", - "BANK GIRO RECEIPTS" -> "Giro Receipts", - "BANK GIRO IN CREDITS" -> "Giro Credits", - "FPS RECEIPTS" -> "FPS Receipts", - "CREDIT FOR INTERNET RECEIPTS" -> "Internet Receipts", - "GIROBANK RECEIPTS" -> "Girobank", - "GIROBANK/ POST OFFICE" -> "Post Office", - "NIL DECLARATIONS" -> "Nil Declarations", - "PAYMASTER" -> "Paymaster", - "VOLUNTARY DIRECT PAYMENTS" -> "Voluntary Payments" - ) withDefault { unknown => - Logger.warn(s"Invalid payment method: [${unknown}].") - "UNKNOWN" - } - - def transform(paymentMethodMaybe: Option[String]): Option[String] = { - paymentMethodMaybe.map { paymentMethods } - } -} - -object PaymentHistoryWithAllocationsJson { - def transform( - apiBaseUrl: String, - empRef: EmpRef, - taxYear: TaxYear, - epayePaymentHistory: EpayePaymentHistoryWithAllocations): PaymentHistoryWithAllocationsJson = { - - val payments: Seq[PaymentWithAllocations] = for { - epayePayment <- epayePaymentHistory.payments - epayePaymentDate <- epayePayment.paymentDate - } yield toPaymentWithAllocations(epayePayment, epayePaymentDate) - - PaymentHistoryWithAllocationsJson( - empRef.taxOfficeNumber, - empRef.taxOfficeReference, - taxYear, - payments.sorted(PaymentWithAllocations.paymentDescendingOrdering), - PaymentHistoryWithAllocationsLinks( - empRefs = Link.empRefsLink, - summary = Link.summaryLink(empRef), - statements = Link.statementsLink(empRef), - payments = Link.paymentHistoryLink(empRef, taxYear), - self = Link.paymentHistoryWithAllocationsLink(empRef, taxYear), - next = Link.paymentHistoryWithAllocationsLink(empRef, taxYear.next), - previous = Link.paymentHistoryWithAllocationsLink(empRef, taxYear.previous) - ) - ) - } - - private def toPaymentWithAllocations( - epayePaymentWithAllocations: EpayePaymentHistoryWithAllocationsPayment, - epayePaymentDate: LocalDate): PaymentWithAllocations = { - - PaymentWithAllocations( - epayePaymentDate, - PaymentWithAllocations.transform(epayePaymentWithAllocations.method), - epayePaymentWithAllocations.amount, - epayePaymentWithAllocations.allocatedAmount, - epayePaymentWithAllocations.allocations.map{ PaymentAllocation.transform }) - } -} diff --git a/app/uk/gov/hmrc/epayeapi/router/ApiRouter.scala b/app/uk/gov/hmrc/epayeapi/router/ApiRouter.scala index ca9d746..f19684f 100644 --- a/app/uk/gov/hmrc/epayeapi/router/ApiRouter.scala +++ b/app/uk/gov/hmrc/epayeapi/router/ApiRouter.scala @@ -33,31 +33,27 @@ case class ApiRouter @Inject() ( getAnnualStatementController: GetAnnualStatementController, getMonthlyStatementController: GetMonthlyStatementController, getStatementsController: GetStatementsController, - getPaymentHistoryController: GetPaymentHistoryController, - getPaymentHistoryWithAllocationsController: GetPaymentHistoryWithAllocationsController + getPaymentHistoryController: GetPaymentHistoryController ) extends SimpleRouter { val appRoutes = Router.from { case GET(p"/") => getEmpRefsController.getEmpRefs() - case GET(p"/${TaxOfficeNumber(ton)}/${TaxOfficeReference(tor)}") => + case GET(p"/${ TaxOfficeNumber(ton) }/${ TaxOfficeReference(tor) }") => getSummaryController.getSummary(EmpRef(ton, tor)) - case GET(p"/${TaxOfficeNumber(ton)}/${TaxOfficeReference(tor)}/statements") => + case GET(p"/${ TaxOfficeNumber(ton) }/${ TaxOfficeReference(tor) }/statements") => getStatementsController.getStatements(EmpRef(ton, tor)) - case GET(p"/${TaxOfficeNumber(ton)}/${TaxOfficeReference(tor)}/statements/${ ExtractTaxYear(taxYear) }") => + case GET(p"/${ TaxOfficeNumber(ton) }/${ TaxOfficeReference(tor) }/statements/${ ExtractTaxYear(taxYear) }") => getAnnualStatementController.getAnnualStatement(EmpRef(ton, tor), taxYear) - case GET(p"/${TaxOfficeNumber(ton)}/${TaxOfficeReference(tor)}/statements/${ ExtractTaxYear(taxYear) }/${ int(month) }") if 1 <= month && month <= 12 => + case GET(p"/${ TaxOfficeNumber(ton) }/${ TaxOfficeReference(tor) }/statements/${ ExtractTaxYear(taxYear) }/${ int(month) }") if 1 <= month && month <= 12 => getMonthlyStatementController.getStatement(EmpRef(ton, tor), taxYear, TaxMonth(taxYear, month)) - case GET(p"/${TaxOfficeNumber(ton)}/${TaxOfficeReference(tor)}/payment-history/${ ExtractTaxYear(taxYear) }") => + case GET(p"/${ TaxOfficeNumber(ton) }/${ TaxOfficeReference(tor) }/payment-history/${ ExtractTaxYear(taxYear) }") => getPaymentHistoryController.getPaymentHistory(EmpRef(ton, tor), taxYear) - - case GET(p"/${TaxOfficeNumber(ton)}/${TaxOfficeReference(tor)}/payment-history/${ ExtractTaxYear(taxYear) }/allocations") => - getPaymentHistoryWithAllocationsController.getPaymentHistoryWithAllocations(EmpRef(ton, tor), taxYear) } val routes: Routes = prodRoutes.routes.orElse(appRoutes.routes) diff --git a/resources/public/api/conf/1.0/application.raml b/resources/public/api/conf/1.0/application.raml index 0c1f3bc..5611483 100644 --- a/resources/public/api/conf/1.0/application.raml +++ b/resources/public/api/conf/1.0/application.raml @@ -234,42 +234,6 @@ types: application/json: type: !include schemas/PaymentHistory.schema.json example: !include examples/PaymentHistory.get.json - 403: - body: - application/json: - type: !include schemas/ErrorCodes.schema.json - examples: - notOpenStatus: - description: You don't currently have an ePAYE enrolment on this account. - value: | - { - "code" : "INVALID_EMPREF", - "message" : "Provided EmpRef is not associated with your account" - } - /{taxOfficeNumber}/{taxOfficeReference}/payment-history/{taxYear}/allocations: - uriParameters: - taxOfficeNumber: - description: A unique identifier made up of tax office number - type: TaxOfficeNumber - example: "001" - taxOfficeReference: - description: A unique identifier made up of the tax office reference - type: TaxOfficeReference - example: "A000001" - taxYear: - type: TaxYear - example: "2015-16" - get: - is: [ headers.acceptHeader ] - displayName: Get ePAYE payment history for the requested tax year - (annotations.scope): "read:epaye" - securedBy: [ sec.oauth_2_0: { scopes: [ "read:epaye" ] } ] - responses: - 200: - body: - application/json: - type: !include schemas/PaymentHistoryWithAllocations.schema.json - example: !include examples/PaymentHistoryWithAllocations.get.json 403: body: application/json: diff --git a/resources/public/api/conf/1.0/examples/AnnualStatement.get.json b/resources/public/api/conf/1.0/examples/AnnualStatement.get.json index ffb5723..09b3d0e 100644 --- a/resources/public/api/conf/1.0/examples/AnnualStatement.get.json +++ b/resources/public/api/conf/1.0/examples/AnnualStatement.get.json @@ -66,6 +66,9 @@ }, "previous": { "href": "/organisations/paye/001/AB00001/statements/2015-16" + }, + "paymentHistory": { + "href": "/organisations/paye/001/AB00001/payment-history/2016-16" } } } \ No newline at end of file diff --git a/resources/public/api/conf/1.0/examples/PaymentHistory.get.json b/resources/public/api/conf/1.0/examples/PaymentHistory.get.json index 0b27be7..f59069c 100644 --- a/resources/public/api/conf/1.0/examples/PaymentHistory.get.json +++ b/resources/public/api/conf/1.0/examples/PaymentHistory.get.json @@ -9,15 +9,81 @@ "payments": [ { "paymentDate": "2016-11-08", - "amount": 1400.00 + "amount": 1400.00, + "allocatedAmount": 1000.00, + "method": "Debit Card", + "allocations": [ + { + "taxYear": { + "year": "2016-17", + "firstDay": "2016-04-06", + "lastDay": "2017-04-05" + }, + "taxMonth": { + "month": 3, + "firstDay": "2016-06-06", + "lastDay": "2017-07-05" + }, + "amount": 600.00 + }, + { + "taxYear": { + "year": "2016-17", + "firstDay": "2016-04-06", + "lastDay": "2017-04-05" + }, + "taxMonth": { + "month": 2, + "firstDay": "2016-05-06", + "lastDay": "2017-06-05" + }, + "amount": 400.00, + "code": "NON_RTI_APPRENTICESHIP_LEVY_INTEREST" + } + ] }, { "paymentDate": "2016-09-07", - "amount": 900.00 + "amount": 900.00, + "allocatedAmount": 900.00, + "method": "BACS", + "allocations": [ + { + "taxYear": { + "year": "2016-17", + "firstDay": "2016-04-06", + "lastDay": "2017-04-05" + }, + "taxMonth": { + "month": 3, + "firstDay": "2016-06-06", + "lastDay": "2017-07-05" + }, + "amount": 900.00 + } + ] }, { "paymentDate": "2016-05-17", - "amount": 100.00 + "amount": 100.00, + "allocatedAmount": 70.00, + "method": "Cheque", + "allocations": [ + { + "taxYear": { + "year": "2016-17", + "firstDay": "2016-04-06", + "lastDay": "2017-04-05" + }, + "taxMonth": { + "month": 1, + "firstDay": "2016-04-06", + "lastDay": "2017-05-05" + }, + "amount": 70.00, + "code": "NON_RTI_CIS_FIXED_PENALTY" + } + ] } ], "_links": { @@ -30,6 +96,9 @@ "statements": { "href": "/organisations/paye/001/AB00001/statements" }, + "statement": { + "href": "/organisations/paye/001/AB00001/statements/2016-17" + }, "self": { "href": "/organisations/paye/001/AB00001/payment-history/2016-17" }, diff --git a/resources/public/api/conf/1.0/examples/PaymentHistoryWithAllocations.get.json b/resources/public/api/conf/1.0/examples/PaymentHistoryWithAllocations.get.json deleted file mode 100644 index 9df8aea..0000000 --- a/resources/public/api/conf/1.0/examples/PaymentHistoryWithAllocations.get.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "taxOfficeNumber": "001", - "taxOfficeReference": "AB00001", - "taxYear": { - "year": "2016-17", - "firstDay": "2016-04-06", - "lastDay": "2017-04-05" - }, - "payments": [ - { - "paymentDate": "2016-11-08", - "amount": 1400.00, - "allocatedAmount": 1000.00, - "method": "Debit Card", - "allocations": [ - { - "taxYear": { - "year": "2016-17", - "firstDay": "2016-04-06", - "lastDay": "2017-04-05" - }, - "taxMonth": { - "month": 3, - "firstDay": "2016-06-06", - "lastDay": "2017-07-05" - }, - "amount": 600.00 - }, - { - "taxYear": { - "year": "2016-17", - "firstDay": "2016-04-06", - "lastDay": "2017-04-05" - }, - "taxMonth": { - "month": 2, - "firstDay": "2016-05-06", - "lastDay": "2017-06-05" - }, - "amount": 400.00, - "code": "NON_RTI_APPRENTICESHIP_LEVY_INTEREST" - } - ] - }, - { - "paymentDate": "2016-09-07", - "amount": 900.00, - "allocatedAmount": 900.00, - "method": "BACS", - "allocations": [ - { - "taxYear": { - "year": "2016-17", - "firstDay": "2016-04-06", - "lastDay": "2017-04-05" - }, - "taxMonth": { - "month": 3, - "firstDay": "2016-06-06", - "lastDay": "2017-07-05" - }, - "amount": 900.00 - } - ] - }, - { - "paymentDate": "2016-05-17", - "amount": 100.00, - "allocatedAmount": 70.00, - "method": "Cheque", - "allocations": [ - { - "taxYear": { - "year": "2016-17", - "firstDay": "2016-04-06", - "lastDay": "2017-04-05" - }, - "taxMonth": { - "month": 1, - "firstDay": "2016-04-06", - "lastDay": "2017-05-05" - }, - "amount": 70.00, - "code": "NON_RTI_CIS_FIXED_PENALTY" - } - ] - } - ], - "_links": { - "empRefs": { - "href": "/organisations/paye/" - }, - "summary": { - "href": "/organisations/paye/001/AB00001" - }, - "statements": { - "href": "/organisations/paye/001/AB00001/statements/2016-17" - }, - "payments": { - "href": "/organisations/paye/001/AB00001/payment-history/2016-17" - }, - "self": { - "href": "/organisations/paye/001/AB00001/payment-history/2016-17/allocations" - }, - "next": { - "href": "/organisations/paye/001/AB00001/payment-history/2017-18/allocations" - }, - "previous": { - "href": "/organisations/paye/001/AB00001/payment-history/2015-16/allocations" - } - } -} \ No newline at end of file diff --git a/resources/public/api/conf/1.0/schemas/AnnualStatement.get.schema.json b/resources/public/api/conf/1.0/schemas/AnnualStatement.get.schema.json index eb4acca..9679043 100644 --- a/resources/public/api/conf/1.0/schemas/AnnualStatement.get.schema.json +++ b/resources/public/api/conf/1.0/schemas/AnnualStatement.get.schema.json @@ -158,6 +158,10 @@ "previous": { "description": "Link to the Annual Statement for the previous tax year", "$ref": "Definitions.schema.json#/definitions/link" + }, + "paymentHistory": { + "description": "Link to the payment history for the given empRef and year", + "$ref": "Definitions.schema.json#/definitions/link" } }, "required": [ @@ -166,7 +170,8 @@ "statements", "self", "next", - "previous" + "previous", + "paymentHistory" ] }, "chargeSummary": { diff --git a/resources/public/api/conf/1.0/schemas/PaymentHistory.schema.json b/resources/public/api/conf/1.0/schemas/PaymentHistory.schema.json index ac02e08..3161df9 100644 --- a/resources/public/api/conf/1.0/schemas/PaymentHistory.schema.json +++ b/resources/public/api/conf/1.0/schemas/PaymentHistory.schema.json @@ -14,7 +14,7 @@ "type": "array", "description": "Sequence of payments received in the requested tax year", "items": { - "$ref": "Definitions.schema.json#/definitions/payment", + "$ref": "#/definitions/payment", "minItems": 0 } }, @@ -30,6 +30,12 @@ "statements": { "$ref": "Definitions.schema.json#/definitions/link" }, + "statement": { + "href": "/organisations/paye/001/AB00001/statements/2016-17" + }, + "payments": { + "$ref": "Definitions.schema.json#/definitions/link" + }, "self": { "$ref": "Definitions.schema.json#/definitions/link" }, @@ -54,5 +60,83 @@ "taxYear", "payments", "_links" - ] + ], + "definitions": { + "payment": { + "type": "object", + "description": "A payment, with allocations, made by the client", + "title": "Description of a payment and allocations received", + "properties": { + "paymentDate": { + "description": "The date the payment was received", + "$ref": "Definitions.schema.json#/definitions/date" + }, + "amount": { + "description": "The payment amount", + "type": "number" + }, + "allocatedAmount": { + "description": "The amount from the original payment that has been allocated to charges", + "type": "number" + }, + "method": { + "description": "Method of payment", + "type": "string", + "enum": [ + "Debit Card", + "Cheque", + "BACS", + "CHAPS", + "Credit Card", + "Direct Debit", + "Online Payment", + "Bank Lodgement", + "Giro Receipts", + "Giro Credits", + "FPS Receipts", + "Internet Receipts", + "Girobank", + "Post Office", + "Nil Declarations", + "Paymaster", + "Voluntary Payments" + ] + }, + "allocations": { + "type": "array", + "description": "Sequence of allocations made from the payment", + "items": { + "type": "object", + "properties": { + "taxYear": { + "$ref": "Definitions.schema.json#/definitions/taxYear" + }, + "taxMonth": { + "$ref": "Definitions.schema.json#/definitions/taxMonth" + }, + "amount": { + "description": "The allocation amount", + "type": "number" + }, + "code": { + "$ref": "Definitions.schema.json#/definitions/chargeCode" + } + }, + "minItems": 0, + "required": [ + "taxYear", + "taxMonth", + "amount" + ] + } + } + }, + "required": [ + "paymentDate", + "amount", + "allocatedAmount", + "allocations" + ] + } + } } \ No newline at end of file diff --git a/resources/public/api/conf/1.0/schemas/PaymentHistoryWithAllocations.schema.json b/resources/public/api/conf/1.0/schemas/PaymentHistoryWithAllocations.schema.json deleted file mode 100644 index 3d2f786..0000000 --- a/resources/public/api/conf/1.0/schemas/PaymentHistoryWithAllocations.schema.json +++ /dev/null @@ -1,139 +0,0 @@ -{ - "type": "object", - "properties": { - "taxOfficeNumber": { - "$ref": "Definitions.schema.json#/definitions/taxOfficeNumber" - }, - "taxOfficeReference": { - "$ref": "Definitions.schema.json#/definitions/taxOfficeReference" - }, - "taxYear": { - "$ref": "Definitions.schema.json#/definitions/taxYear" - }, - "payments": { - "type": "array", - "description": "Sequence of payments received in the requested tax year", - "items": { - "$ref": "#/definitions/paymentWithAllocations", - "minItems": 0 - } - }, - "_links": { - "type": "object", - "properties": { - "empRefs": { - "$ref": "Definitions.schema.json#/definitions/link" - }, - "summary": { - "$ref": "Definitions.schema.json#/definitions/link" - }, - "statements": { - "$ref": "Definitions.schema.json#/definitions/link" - }, - "payments": { - "$ref": "Definitions.schema.json#/definitions/link" - }, - "self": { - "$ref": "Definitions.schema.json#/definitions/link" - }, - "next": { - "$ref": "Definitions.schema.json#/definitions/link" - }, - "previous": { - "$ref": "Definitions.schema.json#/definitions/link" - } - }, - "required": [ - "empRefs", - "summary", - "statements", - "self" - ] - } - }, - "required": [ - "taxOfficeNumber", - "taxOfficeReference", - "taxYear", - "payments", - "_links" - ], - "definitions": { - "paymentWithAllocations": { - "type": "object", - "description": "A payment, with allocations, made by the client", - "title": "Description of a payment and allocations received", - "properties": { - "paymentDate": { - "description": "The date the payment was received", - "$ref": "Definitions.schema.json#/definitions/date" - }, - "amount": { - "description": "The payment amount", - "type": "number" - }, - "allocatedAmount": { - "description": "The amount from the original payment that has been allocated to charges", - "type": "number" - }, - "method": { - "description": "Method of payment", - "type": "string", - "enum": [ - "Debit Card", - "Cheque", - "BACS", - "CHAPS", - "Credit Card", - "Direct Debit", - "Online Payment", - "Bank Lodgement", - "Giro Receipts", - "Giro Credits", - "FPS Receipts", - "Internet Receipts", - "Girobank", - "Post Office", - "Nil Declarations", - "Paymaster", - "Voluntary Payments" - ] - }, - "allocations": { - "type": "array", - "description": "Sequence of allocations made from the payment", - "items": { - "type": "object", - "properties": { - "taxYear": { - "$ref": "Definitions.schema.json#/definitions/taxYear" - }, - "taxMonth": { - "$ref": "Definitions.schema.json#/definitions/taxMonth" - }, - "amount": { - "description": "The allocation amount", - "type": "number" - }, - "code": { - "$ref": "Definitions.schema.json#/definitions/chargeCode" - } - }, - "minItems": 0, - "required": [ - "taxYear", - "taxMonth", - "amount" - ] - } - } - }, - "required": [ - "paymentDate", - "amount", - "allocatedAmount", - "allocations" - ] - } - } -} \ No newline at end of file diff --git a/resources/public/api/conf/1.0/schemas/Statements.schema.json b/resources/public/api/conf/1.0/schemas/Statements.schema.json index fd61c39..55b8aa8 100644 --- a/resources/public/api/conf/1.0/schemas/Statements.schema.json +++ b/resources/public/api/conf/1.0/schemas/Statements.schema.json @@ -44,7 +44,7 @@ "$ref": "Definitions.schema.json#/definitions/taxYear" }, "_links": { - "$ref": "#/definitions/annualStatementLinks" + "$ref": "#/definitions/annualStatementLink" } }, "required": [ @@ -53,9 +53,9 @@ ] } }, - "annualStatementLinks": { + "annualStatementLink": { "type": "object", - "description": "Links related to this annual statement", + "description": "Link related to this annual statement", "properties": { "self": { "$ref": "Definitions.schema.json#/definitions/link" diff --git a/test/common/Fixtures.scala b/test/common/Fixtures.scala index a4de36a..97a7db4 100644 --- a/test/common/Fixtures.scala +++ b/test/common/Fixtures.scala @@ -120,26 +120,6 @@ object Fixtures { """.stripMargin def epayePaymentHistory(empRef: EmpRef, taxYear: TaxYear): String = - s""" - |{ - | "payments": [ - | { - | "dateOfPayment": "${taxYear.yearFrom}-06-17", - | "amount": "123.45" - | }, - | { - | "dateOfPayment": "${taxYear.yearFrom}-10-07", - | "amount": "456.78" - | }, - | { - | "dateOfPayment": "${taxYear.yearFrom}-12-08", - | "amount": "999.00" - | } - | ] - |} - """.stripMargin - - def epayePaymentHistoryWithAllocations(empRef: EmpRef, taxYear: TaxYear): String = s""" |{ | "taxYear": { @@ -301,6 +281,9 @@ object Fixtures { | }, | "previous": { | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements/2016-17" + | }, + | "paymentHistory": { + | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/2017-18" | } | } |} @@ -361,54 +344,6 @@ object Fixtures { ) def expectedPaymentHistoryJson(empRef: EmpRef, taxYear: TaxYear): JsValue = Json.parse( - s""" - |{ - | "taxOfficeNumber": "${empRef.taxOfficeNumber}", - | "taxOfficeReference": "${empRef.taxOfficeReference}", - | "taxYear": { - | "year": "${taxYear.asString}", - | "firstDay": "${taxYear.firstDay}", - | "lastDay": "${taxYear.lastDay}" - | }, - | "payments": [ - | { - | "paymentDate": "${taxYear.yearFrom}-12-08", - | "amount": 999.00 - | }, - | { - | "paymentDate": "${taxYear.yearFrom}-10-07", - | "amount": 456.78 - | }, - | { - | "paymentDate": "${taxYear.yearFrom}-06-17", - | "amount": 123.45 - | } - | ], - | "_links": { - | "empRefs": { - | "href": "/organisations/paye/" - | }, - | "summary": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}" - | }, - | "statements": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements" - | }, - | "self": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}" - | }, - | "next": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.next.asString}" - | }, - | "previous": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.previous.asString}" - | } - | } - |} - """.stripMargin - ) - - def expectedPaymentHistoryWithAllocationsJson(empRef: EmpRef, taxYear: TaxYear): JsValue = Json.parse( s""" |{ | "taxOfficeNumber": "${empRef.taxOfficeNumber}", @@ -522,17 +457,17 @@ object Fixtures { | "statements": { | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements" | }, - | "payments": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}" + | "statement": { + | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements/${taxYear.asString}" | }, | "self": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}/allocations" + | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}" | }, | "next": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.next.asString}/allocations" + | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.next.asString}" | }, | "previous": { - | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.previous.asString}/allocations" + | "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.previous.asString}" | } | } |} diff --git a/test/common/RestAssertions.scala b/test/common/RestAssertions.scala index 7c4b5df..2aaad27 100644 --- a/test/common/RestAssertions.scala +++ b/test/common/RestAssertions.scala @@ -172,21 +172,6 @@ class ClientWithEmpRefGivens(empRef: EmpRef) extends BaseClientGivens[ClientWith } def epayePaymentHistoryReturns(body: String, status: Int = 200)(implicit taxYear: TaxYear): ClientWithEmpRefGivens = { - stubFor( - get( - urlPathEqualTo(s"/epaye/${empRef.encodedValue}/api/v1/payment-history/${taxYear.asString}") - ).willReturn( - aResponse() - .withBody(body) - .withHeader("Content-Type", "application/json") - .withStatus(status) - ) - ) - - this - } - - def epayePaymentHistoryWithAllocationsReturns(body: String, status: Int = 200)(implicit taxYear: TaxYear): ClientWithEmpRefGivens = { stubFor( get( urlPathEqualTo(s"/epaye/${empRef.encodedValue}/api/v1/payment-history-with-allocations/${taxYear.asString}") diff --git a/test/contract/GetPaymentHistoryWithAllocationsSpec.scala b/test/contract/GetPaymentHistoryWithAllocationsSpec.scala deleted file mode 100644 index 245f37f..0000000 --- a/test/contract/GetPaymentHistoryWithAllocationsSpec.scala +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2018 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package contract - -import common._ -import org.scalatest.{Matchers, WordSpec} -import play.api.Application -import play.api.inject.bind -import play.api.inject.guice.GuiceApplicationBuilder -import play.api.routing.Router -import uk.gov.hmrc.epayeapi.models.TaxYear -import uk.gov.hmrc.epayeapi.router.RoutesProvider - -class GetPaymentHistoryWithAllocationsSpec - extends WordSpec - with Matchers - with WSClientSetup - with WiremockSetup - with EmpRefGenerator - with RestAssertions { - - override implicit lazy val app: Application = - new GuiceApplicationBuilder().overrides(bind[Router].toProvider[RoutesProvider]).build() - - "/organisations/epaye/{ton}/{tor}/payment-history/2016-17/allocations" should { - val empRef = randomEmpRef() - implicit val taxYear = TaxYear(2016) - - val paymentHistoryWithAllocationsSchemaPath = s"${app.path.toURI}/resources/public/api/conf/1.0/schemas/PaymentHistoryWithAllocations.schema.json" - - val paymentHistoryWithAllocationsUrl = - s"$baseUrl/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}/allocations" - - "return a response body that conforms to the Payment History schema" in { - given() - .clientWith(empRef).isAuthorized - .and() - .epayePaymentHistoryWithAllocationsReturns(Fixtures.epayePaymentHistoryWithAllocations(empRef, taxYear)) - .when - .get(paymentHistoryWithAllocationsUrl).withAuthHeader() - .thenAssertThat() - .bodyIsOfSchema(paymentHistoryWithAllocationsSchemaPath) - } - } -} diff --git a/test/integration/GetPaymentHistoryWithAllocationsSpec.scala b/test/integration/GetPaymentHistoryWithAllocationsSpec.scala deleted file mode 100644 index 864eada..0000000 --- a/test/integration/GetPaymentHistoryWithAllocationsSpec.scala +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2018 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package integration - -import common.Fixtures.{epayePaymentHistoryWithAllocations, expectedPaymentHistoryWithAllocationsJson} -import play.api.libs.json.Json -import uk.gov.hmrc.epayeapi.models.Formats._ -import uk.gov.hmrc.epayeapi.models.TaxYear -import uk.gov.hmrc.epayeapi.models.out.ApiErrorJson - -class GetPaymentHistoryWithAllocationsSpec extends IntegrationTestBase { - - "payment-history" should { - "return 200 OK with payment history" in new Setup { - given() - .clientWith(empRef).isAuthorized - .and() - .epayePaymentHistoryWithAllocationsReturns(epayePaymentHistoryWithAllocations(empRef, taxYear)) - .when() - .get(url) - .thenAssertThat() - .statusCodeIs(200) - .bodyIsOfJson(expectedPaymentHistoryWithAllocationsJson(empRef, taxYear)) - } - - "return 500 Internal Server Error if upstream returns invalid JSON" in new Setup { - given() - .clientWith(empRef).isAuthorized - .and() - .epayePaymentHistoryWithAllocationsReturns("{not json}") - .when() - .get(url) - .withAuthHeader() - .thenAssertThat() - .statusCodeIs(500) - .bodyIsOfJson(Json.toJson(ApiErrorJson.InternalServerError)) - } - - "return 404 Not Found if upstream returns a 404" in new Setup { - given() - .clientWith(empRef).isAuthorized - .and() - .epayePaymentHistoryWithAllocationsReturns("", 404) - .when() - .get(url) - .withAuthHeader() - .thenAssertThat() - .statusCodeIs(404) - .bodyIsOfJson(Json.toJson(ApiErrorJson.EmpRefNotFound)) - } - - "return a 500 Internal Server Error on errors from upstream" in new Setup { - for (status <- Seq(400, 401, 402, 403, 502, 503)) { - given() - .clientWith(empRef).isAuthorized - .and() - .epayePaymentHistoryWithAllocationsReturns("", status) - .when() - .get(url) - .withAuthHeader() - .thenAssertThat() - .statusCodeIs(500) - .bodyIsOfJson(Json.toJson(ApiErrorJson.InternalServerError)) - } - } - } - - it should new Setup { - haveAuthentication(url) - } - - trait Setup { - val empRef = getEmpRef - implicit val taxYear = TaxYear(2016) - val url = s"$baseUrl/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/${taxYear.asString}/allocations" - } -} diff --git a/test/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJsonSpec.scala b/test/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJsonSpec.scala index b3f6e03..282e174 100644 --- a/test/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJsonSpec.scala +++ b/test/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJsonSpec.scala @@ -39,7 +39,8 @@ class AnnualStatementJsonSpec extends WordSpec with Matchers { statements = Link.statementsLink(empRef), self = Link.annualStatementLink(empRef, taxYear), next = Link.annualStatementLink(empRef, taxYear.next), - previous = Link.annualStatementLink(empRef, taxYear.previous) + previous = Link.annualStatementLink(empRef, taxYear.previous), + paymentHistory = Link.paymentHistoryLink(empRef, taxYear) ) } } diff --git a/test/uk/gov/hmrc/epayeapi/models/out/LinkSpecs.scala b/test/uk/gov/hmrc/epayeapi/models/out/LinkSpecs.scala index 074450d..adece4a 100644 --- a/test/uk/gov/hmrc/epayeapi/models/out/LinkSpecs.scala +++ b/test/uk/gov/hmrc/epayeapi/models/out/LinkSpecs.scala @@ -43,5 +43,9 @@ class LinkSpecs extends UnitSpec { "generate the monthly statement link" in { Link.monthlyStatementLink(empRef, TaxYear(2017), TaxMonth(TaxYear(2017), 1)) shouldEqual Link(s"/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements/2017-18/1") } + + "generate the payment history link" in { + Link.paymentHistoryLink(empRef, TaxYear(2017)) shouldEqual Link(s"/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/payment-history/2017-18") + } } } diff --git a/test/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJsonSpec.scala b/test/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJsonSpec.scala index 86f2779..2da91de 100644 --- a/test/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJsonSpec.scala +++ b/test/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryJsonSpec.scala @@ -19,8 +19,8 @@ package uk.gov.hmrc.epayeapi.models.out import common.EmpRefGenerator import org.joda.time.LocalDate import org.scalatest.{Matchers, WordSpec} -import uk.gov.hmrc.epayeapi.models.TaxYear -import uk.gov.hmrc.epayeapi.models.in.{EpayePaymentHistory, EpayePaymentHistoryPayment} +import uk.gov.hmrc.epayeapi.models.{TaxMonth, TaxYear} +import uk.gov.hmrc.epayeapi.models.in._ class PaymentHistoryJsonSpec extends WordSpec with Matchers { val apiBaseUrl = "[API_BASE_URL]" @@ -33,13 +33,14 @@ class PaymentHistoryJsonSpec extends WordSpec with Matchers { Link.empRefsLink, Link.summaryLink(empRef), Link.statementsLink(empRef), + Link.annualStatementLink(empRef, taxYear), Link.paymentHistoryLink(empRef, taxYear), Link.paymentHistoryLink(empRef, taxYear.next), Link.paymentHistoryLink(empRef, taxYear.previous) ) "return empty payment history for tax year 2016-17" in { - val epayePaymentHistory = EpayePaymentHistory(Seq.empty) + val epayePaymentHistory = EpayePaymentHistory(taxYear, Seq.empty) val expectedPaymentHistory = PaymentHistoryJson( empRef.taxOfficeNumber, @@ -49,32 +50,58 @@ class PaymentHistoryJsonSpec extends WordSpec with Matchers { _links ) - PaymentHistoryJson.transform(apiBaseUrl, empRef, taxYear, epayePaymentHistory) shouldBe expectedPaymentHistory + PaymentHistoryJson.transform(apiBaseUrl, empRef, taxYear, epayePaymentHistory) shouldBe + expectedPaymentHistory } "return payments, sorted by date & amount, for tax year 2016-17" in { + val taxMonth1 = EpayeTaxPeriod(taxYear.firstDay, taxYear.firstDay.plusMonths(1).minusDays(1)) + val taxMonth2 = taxMonth1.plusTaxMonths(1) + val taxMonth3 = taxMonth2.plusTaxMonths(1) + val taxMonth4 = taxMonth3.plusTaxMonths(1) + val taxMonth5 = taxMonth4.plusTaxMonths(1) + val taxMonth10 = taxMonth5.plusTaxMonths(5) + val taxMonth11 = taxMonth10.plusTaxMonths(1) val epayePaymentHistory = EpayePaymentHistory( + taxYear, Seq( EpayePaymentHistoryPayment( - dateOfPayment = Some(new LocalDate(2016,6,17)), - amount = 123.45 - ), - EpayePaymentHistoryPayment( - dateOfPayment = None, - amount = 666.69 + paymentDate = Some(new LocalDate(2016,6,17)), + method = Some("TPS RECEIPTS BY DEBIT CARD"), + amount = 123.45, + allocatedAmount = 123.45, + allocations = Seq( + EpayeRtiPaymentAllocation(taxMonth2, 100.00), + EpayeRtiPaymentAllocation(taxMonth1, 23.45) + ) ), EpayePaymentHistoryPayment( - dateOfPayment = Some(new LocalDate(2016,10,7)), - amount = 456.78 + paymentDate = Some(new LocalDate(2016,10,7)), + method = Some("PAYMENTS MADE BY CHEQUE"), + amount = 456.78, + allocatedAmount = 456.78, + allocations = Seq( + EpayeNonRtiPaymentAllocation(taxMonth4, 400.00, Some(EpayeCode("NON_RTI_CIS_FIXED_PENALTY"))), + EpayeRtiPaymentAllocation(taxMonth5, 56.78) + ) ), EpayePaymentHistoryPayment( - dateOfPayment = Some(new LocalDate(2016,12,8)), - amount = 999.00 + paymentDate = Some(new LocalDate(2016,12,8)), + method = Some("TPS RECEIPTS BY CREDIT CARD"), + amount = 999.00, + allocatedAmount = 999.00, + allocations = Seq( + EpayeRtiPaymentAllocation(taxMonth10, 900.00), + EpayeNonRtiPaymentAllocation(taxMonth11, 99.00, Some(EpayeCode("NON_RTI_EI_LATE_REPORT_DAILY_PENALTY"))) + ) ), EpayePaymentHistoryPayment( - dateOfPayment = Some(new LocalDate(2016,10,7)), - amount = 111.11 + paymentDate = Some(new LocalDate(2016,10,7)), + method = Some("BACS RECEIPTS"), + amount = 111.11, + allocatedAmount = 111.11, + allocations = Seq() ) ) ) @@ -84,16 +111,31 @@ class PaymentHistoryJsonSpec extends WordSpec with Matchers { empRef.taxOfficeReference, taxYear, Seq( - Payment(Some(new LocalDate(2016,12,8)), 999.00), - Payment(Some(new LocalDate(2016,10,7)), 456.78), - Payment(Some(new LocalDate(2016,10,7)), 111.11), - Payment(Some(new LocalDate(2016,6,17)), 123.45), - Payment(None, 666.69) + PaymentJson(new LocalDate(2016,12,8), Some("Credit Card"), 999.00, 999.00, Seq( + PaymentAllocation(taxYear, TaxMonth(taxYear, 10), 900.00, None), + PaymentAllocation(taxYear, TaxMonth(taxYear, 11), 99.00, Some("NON_RTI_EI_LATE_REPORT_DAILY_PENALTY")) + )), + PaymentJson(new LocalDate(2016,10,7), Some("Cheque"), 456.78, 456.78, Seq( + PaymentAllocation(taxYear, TaxMonth(taxYear, 4), 400.00, Some("NON_RTI_CIS_FIXED_PENALTY")), + PaymentAllocation(taxYear, TaxMonth(taxYear, 5), 56.78, None) + )), + PaymentJson(new LocalDate(2016,10,7), Some("BACS"), 111.11, 111.11, Seq()), + PaymentJson(new LocalDate(2016,6,17), Some("Debit Card"), 123.45, 123.45, Seq( + PaymentAllocation(taxYear, TaxMonth(taxYear, 2), 100.00, None), + PaymentAllocation(taxYear, TaxMonth(taxYear, 1), 23.45, None) + )) ), _links ) - PaymentHistoryJson.transform(apiBaseUrl, empRef, taxYear, epayePaymentHistory) shouldBe expectedPaymentHistory + PaymentHistoryJson.transform(apiBaseUrl, empRef, taxYear, epayePaymentHistory) shouldBe + expectedPaymentHistory + } + } + + implicit class EpayeTaxPeriodOps(period: EpayeTaxPeriod) { + def plusTaxMonths(months: Int): EpayeTaxPeriod = { + period.copy(taxFrom = period.taxFrom.plusMonths(months), taxTo = period.taxTo.plusMonths(months)) } } } diff --git a/test/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryWithAllocationsJsonSpec.scala b/test/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryWithAllocationsJsonSpec.scala deleted file mode 100644 index 772afa5..0000000 --- a/test/uk/gov/hmrc/epayeapi/models/out/PaymentHistoryWithAllocationsJsonSpec.scala +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2018 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.epayeapi.models.out - -import common.EmpRefGenerator -import org.joda.time.LocalDate -import org.scalatest.{Matchers, WordSpec} -import uk.gov.hmrc.epayeapi.models.{TaxMonth, TaxYear} -import uk.gov.hmrc.epayeapi.models.in._ - -class PaymentHistoryWithAllocationsJsonSpec extends WordSpec with Matchers { - val apiBaseUrl = "[API_BASE_URL]" - val empRef = EmpRefGenerator.getEmpRef - - "PaymentHistoryWithAllocationsJson.transform" should { - val taxYear = TaxYear(2016) - - val _links = PaymentHistoryWithAllocationsLinks( - Link.empRefsLink, - Link.summaryLink(empRef), - Link.statementsLink(empRef), - Link.paymentHistoryLink(empRef, taxYear), - Link.paymentHistoryWithAllocationsLink(empRef, taxYear), - Link.paymentHistoryWithAllocationsLink(empRef, taxYear.next), - Link.paymentHistoryWithAllocationsLink(empRef, taxYear.previous) - ) - - "return empty payment history for tax year 2016-17" in { - val epayePaymentHistoryWithAllocations = EpayePaymentHistoryWithAllocations(taxYear, Seq.empty) - - val expectedPaymentHistoryWithAllocations = PaymentHistoryWithAllocationsJson( - empRef.taxOfficeNumber, - empRef.taxOfficeReference, - taxYear, - Seq.empty, - _links - ) - - PaymentHistoryWithAllocationsJson.transform(apiBaseUrl, empRef, taxYear, epayePaymentHistoryWithAllocations) shouldBe - expectedPaymentHistoryWithAllocations - } - - "return payments, sorted by date & amount, for tax year 2016-17" in { - val taxMonth1 = EpayeTaxPeriod(taxYear.firstDay, taxYear.firstDay.plusMonths(1).minusDays(1)) - val taxMonth2 = taxMonth1.plusTaxMonths(1) - val taxMonth3 = taxMonth2.plusTaxMonths(1) - val taxMonth4 = taxMonth3.plusTaxMonths(1) - val taxMonth5 = taxMonth4.plusTaxMonths(1) - val taxMonth10 = taxMonth5.plusTaxMonths(5) - val taxMonth11 = taxMonth10.plusTaxMonths(1) - - val epayePaymentHistory = EpayePaymentHistoryWithAllocations( - taxYear, - Seq( - EpayePaymentHistoryWithAllocationsPayment( - paymentDate = Some(new LocalDate(2016,6,17)), - method = Some("TPS RECEIPTS BY DEBIT CARD"), - amount = 123.45, - allocatedAmount = 123.45, - allocations = Seq( - EpayeRtiPaymentAllocation(taxMonth2, 100.00), - EpayeRtiPaymentAllocation(taxMonth1, 23.45) - ) - ), - EpayePaymentHistoryWithAllocationsPayment( - paymentDate = Some(new LocalDate(2016,10,7)), - method = Some("PAYMENTS MADE BY CHEQUE"), - amount = 456.78, - allocatedAmount = 456.78, - allocations = Seq( - EpayeNonRtiPaymentAllocation(taxMonth4, 400.00, Some(EpayeCode("NON_RTI_CIS_FIXED_PENALTY"))), - EpayeRtiPaymentAllocation(taxMonth5, 56.78) - ) - ), - EpayePaymentHistoryWithAllocationsPayment( - paymentDate = Some(new LocalDate(2016,12,8)), - method = Some("TPS RECEIPTS BY CREDIT CARD"), - amount = 999.00, - allocatedAmount = 999.00, - allocations = Seq( - EpayeRtiPaymentAllocation(taxMonth10, 900.00), - EpayeNonRtiPaymentAllocation(taxMonth11, 99.00, Some(EpayeCode("NON_RTI_EI_LATE_REPORT_DAILY_PENALTY"))) - ) - ), - EpayePaymentHistoryWithAllocationsPayment( - paymentDate = Some(new LocalDate(2016,10,7)), - method = Some("BACS RECEIPTS"), - amount = 111.11, - allocatedAmount = 111.11, - allocations = Seq() - ) - ) - ) - - val expectedPaymentHistoryWithAllocations = PaymentHistoryWithAllocationsJson( - empRef.taxOfficeNumber, - empRef.taxOfficeReference, - taxYear, - Seq( - PaymentWithAllocations(new LocalDate(2016,12,8), Some("Credit Card"), 999.00, 999.00, Seq( - PaymentAllocation(taxYear, TaxMonth(taxYear, 10), 900.00, None), - PaymentAllocation(taxYear, TaxMonth(taxYear, 11), 99.00, Some("NON_RTI_EI_LATE_REPORT_DAILY_PENALTY")) - )), - PaymentWithAllocations(new LocalDate(2016,10,7), Some("Cheque"), 456.78, 456.78, Seq( - PaymentAllocation(taxYear, TaxMonth(taxYear, 4), 400.00, Some("NON_RTI_CIS_FIXED_PENALTY")), - PaymentAllocation(taxYear, TaxMonth(taxYear, 5), 56.78, None) - )), - PaymentWithAllocations(new LocalDate(2016,10,7), Some("BACS"), 111.11, 111.11, Seq()), - PaymentWithAllocations(new LocalDate(2016,6,17), Some("Debit Card"), 123.45, 123.45, Seq( - PaymentAllocation(taxYear, TaxMonth(taxYear, 2), 100.00, None), - PaymentAllocation(taxYear, TaxMonth(taxYear, 1), 23.45, None) - )) - ), - _links - ) - - PaymentHistoryWithAllocationsJson.transform(apiBaseUrl, empRef, taxYear, epayePaymentHistory) shouldBe - expectedPaymentHistoryWithAllocations - } - } - - implicit class EpayeTaxPeriodOps(period: EpayeTaxPeriod) { - def plusTaxMonths(months: Int): EpayeTaxPeriod = { - period.copy(taxFrom = period.taxFrom.plusMonths(months), taxTo = period.taxTo.plusMonths(months)) - } - } -} diff --git a/test/uk/gov/hmrc/epayeapi/models/out/PaymentWithAllocationsSpec.scala b/test/uk/gov/hmrc/epayeapi/models/out/PaymentJsonSpec.scala similarity index 84% rename from test/uk/gov/hmrc/epayeapi/models/out/PaymentWithAllocationsSpec.scala rename to test/uk/gov/hmrc/epayeapi/models/out/PaymentJsonSpec.scala index 983384b..82abdea 100644 --- a/test/uk/gov/hmrc/epayeapi/models/out/PaymentWithAllocationsSpec.scala +++ b/test/uk/gov/hmrc/epayeapi/models/out/PaymentJsonSpec.scala @@ -18,8 +18,8 @@ package uk.gov.hmrc.epayeapi.models.out import org.scalatest.{Matchers, WordSpec} -class PaymentWithAllocationsSpec extends WordSpec with Matchers { - "PaymentWithAllocationsJson.transform" should { +class PaymentJsonSpec extends WordSpec with Matchers { + "PaymentJson.transform" should { "convert each payment method code to a text string" in { @@ -45,16 +45,16 @@ class PaymentWithAllocationsSpec extends WordSpec with Matchers { ) expectedMappings foreach { - case (code, text) => PaymentWithAllocations.transform(Some(code)) shouldBe Some(text) + case (code, text) => PaymentJson.transform(Some(code)) shouldBe Some(text) } } "convert unknown payment code to UNKNOWN" in { - PaymentWithAllocations.transform(Some("Blah")) shouldBe Some("UNKNOWN") + PaymentJson.transform(Some("Blah")) shouldBe Some("UNKNOWN") } "convert missing payment code to None" in { - PaymentWithAllocations.transform(None) shouldBe None + PaymentJson.transform(None) shouldBe None } } }