From f0526b868a49dbd994f806214da153819d574e6b Mon Sep 17 00:00:00 2001 From: Jake Barnes <33868990+barnesjake@users.noreply.github.com> Date: Fri, 1 Nov 2024 09:29:19 +0000 Subject: [PATCH] [JB][OPS-12927] wire up card fees page for sa origins (#13) --- .../config/AppConfig.scala | 7 +- .../controllers/FeesController.scala | 63 ++- .../controllers/PaymentFailedController.scala | 3 +- .../DefaultExtendedOrigin.scala | 2 +- .../extendedorigins/ExtendedBtaSa.scala | 2 + .../models/extendedorigins/ExtendedItSa.scala | 2 + .../extendedorigins/ExtendedOrigin.scala | 2 + .../extendedorigins/ExtendedPfP800.scala | 3 +- .../models/extendedorigins/ExtendedPfSa.scala | 4 +- .../extendedorigins/ExtendedPfVat.scala | 4 +- .../extendedorigins/ExtendedPtaSa.scala | 2 + .../utils/OriginExtraInfo.scala | 27 +- .../views/FeesPage.scala.html | 8 +- conf/app.routes | 2 + conf/application.conf | 9 + conf/messages | 11 +- conf/messages.cy | 5 + .../controllers/FeesControllerSpec.scala | 480 +++++++++++++++++- 18 files changed, 602 insertions(+), 34 deletions(-) diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/config/AppConfig.scala b/app/uk/gov/hmrc/cardpaymentfrontend/config/AppConfig.scala index dab422f..97cd458 100755 --- a/app/uk/gov/hmrc/cardpaymentfrontend/config/AppConfig.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/config/AppConfig.scala @@ -22,9 +22,14 @@ import uk.gov.hmrc.play.bootstrap.config.ServicesConfig @Singleton class AppConfig @Inject() (config: Configuration, servicesConfig: ServicesConfig) { - val welshLanguageSupportEnabled: Boolean = config.getOptional[Boolean]("features.welsh-language-support").getOrElse(false) + val payAnotherWayLink: String = config.get[String]("urls.govuk.pay-another-way") val payApiBaseUrl: String = servicesConfig.baseUrl("pay-api") + val payFrontendBaseUrl: String = servicesConfig.baseUrl("pay-frontend") + "/pay" + + val bankTransferRelativeUrl: String = config.get[String]("urls.pay-frontend.bank-transfer") + val oneOffDirectDebitRelativeUrl: String = config.get[String]("urls.pay-frontend.one-off-direct-debit") + } diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/controllers/FeesController.scala b/app/uk/gov/hmrc/cardpaymentfrontend/controllers/FeesController.scala index b0f6535..573f2cd 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/controllers/FeesController.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/controllers/FeesController.scala @@ -18,8 +18,12 @@ package uk.gov.hmrc.cardpaymentfrontend.controllers import payapi.corcommon.model.{Origin, Origins} import play.api.mvc.{Action, AnyContent, Call, MessagesControllerComponents} +import uk.gov.hmrc.cardpaymentfrontend.actions.{Actions, JourneyRequest} +import uk.gov.hmrc.cardpaymentfrontend.config.AppConfig import uk.gov.hmrc.cardpaymentfrontend.models.Link -import uk.gov.hmrc.cardpaymentfrontend.utils.OriginExtraInfo +import uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins.ExtendedOrigin +import uk.gov.hmrc.cardpaymentfrontend.requests.RequestSupport +import uk.gov.hmrc.cardpaymentfrontend.utils.{OriginExtraInfo, PaymentMethod, PaymentMethods} import uk.gov.hmrc.cardpaymentfrontend.views.html.FeesPage import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController @@ -27,10 +31,14 @@ import javax.inject.{Inject, Singleton} @Singleton class FeesController @Inject() ( - originExtraInfo: OriginExtraInfo, + actions: Actions, + appConfig: AppConfig, + feesPage: FeesPage, mcc: MessagesControllerComponents, - feesPage: FeesPage + originExtraInfo: OriginExtraInfo, + requestSupport: RequestSupport ) extends FrontendController(mcc) { + private[controllers] def twoDirectDebitsPrimaryLink(origin: Origin): Option[Link] = { origin match { case Origins.BtaEpayeBill => Some(Link( @@ -128,4 +136,53 @@ class FeesController @Inject() ( // Two kinds of DD with secondary link def renderPage5(): Action[AnyContent] = renderPage(Origins.PfMgd) + import requestSupport._ + + def renderPageNew(): Action[AnyContent] = actions.journeyAction { implicit journeyRequest: JourneyRequest[AnyContent] => + val altPayments = linksAvailableOnFeesPage(journeyRequest.journey.origin) + if (altPayments.isEmpty) Redirect("http://nextpage.html") + else Ok(feesPage(altPayments)) + } + + def submit: Action[AnyContent] = actions.journeyAction { _ => + Redirect(routes.EmailAddressController.renderPage) + } + + private[controllers] def paymentMethodToBeShown(paymentMethod: PaymentMethod, paymentMethods: Set[PaymentMethod]): Boolean = paymentMethods.contains(paymentMethod) + + private[controllers] def linksAvailableOnFeesPage(origin: Origin): Seq[Link] = { + + val extendedOrigin: ExtendedOrigin = originExtraInfo.lift(origin) + val paymentMethodsToShow: Set[PaymentMethod] = extendedOrigin.cardFeesPagePaymentMethods + val showOpenBankingLink: Boolean = paymentMethodToBeShown(PaymentMethods.OpenBanking, paymentMethodsToShow) + val showBankTransferLink: Boolean = paymentMethodToBeShown(PaymentMethods.Bacs, paymentMethodsToShow) + val showOneOffDirectDebitLink: Boolean = paymentMethodToBeShown(PaymentMethods.OneOffDirectDebit, paymentMethodsToShow) + + val maybeOpenBankingLink = if (showOpenBankingLink) { + Seq(Link( + href = Call("GET", "https://open_banking_url_goes_here"), + linkId = "open-banking-link", + messageKey = "card-fees.para2.open-banking" + )) + } else Seq.empty[Link] + + val maybeBankTransferLink = if (showBankTransferLink) { + Seq(Link( + href = Call("GET", appConfig.payFrontendBaseUrl + appConfig.bankTransferRelativeUrl), + linkId = "bank-transfer-link", + messageKey = "card-fees.para2.bank-transfer" + )) + } else Seq.empty[Link] + + val maybeOneOffDirectDebitLink = if (showOneOffDirectDebitLink) { + Seq(Link( + href = Call("GET", appConfig.payFrontendBaseUrl + appConfig.oneOffDirectDebitRelativeUrl), + linkId = "one-off-direct-debit-link", + messageKey = "card-fees.para2.one-off-direct-debit" + )) + } else Seq.empty[Link] + + maybeOpenBankingLink ++ maybeBankTransferLink ++ maybeOneOffDirectDebitLink + } + } diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/controllers/PaymentFailedController.scala b/app/uk/gov/hmrc/cardpaymentfrontend/controllers/PaymentFailedController.scala index d24e94d..2ad393b 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/controllers/PaymentFailedController.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/controllers/PaymentFailedController.scala @@ -21,7 +21,8 @@ import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.cardpaymentfrontend.forms.ChooseAPaymentMethodForm import uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins.ExtendedOrigin -import uk.gov.hmrc.cardpaymentfrontend.utils.{OpenBanking, OriginExtraInfo, PaymentMethod} +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethods.OpenBanking +import uk.gov.hmrc.cardpaymentfrontend.utils.{OriginExtraInfo, PaymentMethod} import uk.gov.hmrc.cardpaymentfrontend.views.html.PaymentFailedPage import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/DefaultExtendedOrigin.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/DefaultExtendedOrigin.scala index c9e8058..2d70cf6 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/DefaultExtendedOrigin.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/DefaultExtendedOrigin.scala @@ -23,7 +23,7 @@ class DefaultExtendedOrigin extends ExtendedOrigin { def serviceNameMessageKey = "" def taxNameMessageKey: String = "" def reference(): String = "" + def cardFeesPagePaymentMethods: Set[PaymentMethod] = Set.empty[PaymentMethod] def paymentMethods(): Set[PaymentMethod] = Set.empty[PaymentMethod] - def checkYourAnswersRows(): Seq[CheckYourAnswersRow] = Seq.empty[CheckYourAnswersRow] } diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedBtaSa.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedBtaSa.scala index f81cd9b..0909de3 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedBtaSa.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedBtaSa.scala @@ -17,12 +17,14 @@ package uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins import uk.gov.hmrc.cardpaymentfrontend.models.CheckYourAnswersRow +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethods.{OneOffDirectDebit, OpenBanking} import uk.gov.hmrc.cardpaymentfrontend.utils._ object ExtendedBtaSa extends ExtendedOrigin { override val serviceNameMessageKey: String = "service-name.BtaSa" override val taxNameMessageKey: String = "payment-complete.tax-name.BtaSa" def reference(): String = "1097172564" //This would really come from the journey either pay-api or stored locally + def cardFeesPagePaymentMethods: Set[PaymentMethod] = Set(OpenBanking, OneOffDirectDebit) //todo add these when we do that ticket def paymentMethods(): Set[PaymentMethod] = Set.empty //todo add this when we do that ticket diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedItSa.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedItSa.scala index 883953f..be083b5 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedItSa.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedItSa.scala @@ -17,12 +17,14 @@ package uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins import uk.gov.hmrc.cardpaymentfrontend.models.CheckYourAnswersRow +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethods.Bacs import uk.gov.hmrc.cardpaymentfrontend.utils._ object ExtendedItSa extends ExtendedOrigin { override val serviceNameMessageKey: String = "service-name.ItSa" override val taxNameMessageKey: String = "payment-complete.tax-name.ItSa" def reference(): String = "1097172564" //This would really come from the journey either pay-api or stored locally + def cardFeesPagePaymentMethods: Set[PaymentMethod] = Set(Bacs) //todo add these when we do that ticket def paymentMethods(): Set[PaymentMethod] = Set.empty //todo add this when we do that ticket diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedOrigin.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedOrigin.scala index a052276..cdf5676 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedOrigin.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedOrigin.scala @@ -23,6 +23,8 @@ trait ExtendedOrigin { def serviceNameMessageKey: String def taxNameMessageKey: String def reference(): String + //denotes which links/payment methods to show on the card-fees page. + def cardFeesPagePaymentMethods: Set[PaymentMethod] def paymentMethods(): Set[PaymentMethod] def checkYourAnswersRows(): Seq[CheckYourAnswersRow] } diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfP800.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfP800.scala index 94a2e18..5b236e7 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfP800.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfP800.scala @@ -23,7 +23,8 @@ class ExtendedPfP800 extends ExtendedOrigin { override val serviceNameMessageKey: String = "add.message.key.here" override val taxNameMessageKey: String = "payment-complete.tax-name.PfP800" def reference(): String = "ma000003AP3022016" //This would really come from the journey either pay-api or stored locally - def paymentMethods(): Set[PaymentMethod] = Set(Card, Bacs) + def cardFeesPagePaymentMethods: Set[PaymentMethod] = Set.empty[PaymentMethod] + def paymentMethods(): Set[PaymentMethod] = Set() //Set(Card, Bacs)//todo will we use this? def checkYourAnswersRows(): Seq[CheckYourAnswersRow] = { Seq.empty diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfSa.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfSa.scala index abcebbd..22afaac 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfSa.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfSa.scala @@ -18,12 +18,14 @@ package uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins import play.api.mvc.Call import uk.gov.hmrc.cardpaymentfrontend.models.{CheckYourAnswersRow, Link} -import uk.gov.hmrc.cardpaymentfrontend.utils.{Bacs, Card, OneOffDirectDebit, OpenBanking, PaymentMethod} +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethods.{Bacs, Card, OneOffDirectDebit, OpenBanking} +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethod object ExtendedPfSa extends ExtendedOrigin { override val serviceNameMessageKey: String = "service-name.PfSa" override val taxNameMessageKey: String = "payment-complete.tax-name.PfSa" def reference(): String = "1097172564" //This would really come from the journey either pay-api or stored locally + def cardFeesPagePaymentMethods: Set[PaymentMethod] = Set(OpenBanking, OneOffDirectDebit) def paymentMethods(): Set[PaymentMethod] = Set(Card, OpenBanking, OneOffDirectDebit, Bacs) def checkYourAnswersRows(): Seq[CheckYourAnswersRow] = { diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfVat.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfVat.scala index ecc5cec..fa5178c 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfVat.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPfVat.scala @@ -18,12 +18,14 @@ package uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins import play.api.mvc.Call import uk.gov.hmrc.cardpaymentfrontend.models.{CheckYourAnswersRow, Link} -import uk.gov.hmrc.cardpaymentfrontend.utils.{Bacs, Card, OpenBanking, PaymentMethod, VariableDirectDebit} +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethods._ +import uk.gov.hmrc.cardpaymentfrontend.utils._ class ExtendedPfVat extends ExtendedOrigin { override val serviceNameMessageKey: String = "add.message.key.here" override val taxNameMessageKey: String = "payment-complete.tax-name.PfVat" def reference(): String = "999964805" + def cardFeesPagePaymentMethods: Set[PaymentMethod] = Set.empty[PaymentMethod] def paymentMethods(): Set[PaymentMethod] = Set(Card, OpenBanking, VariableDirectDebit, Bacs) def checkYourAnswersRows(): Seq[CheckYourAnswersRow] = { diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPtaSa.scala b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPtaSa.scala index ba610ae..9b43dc0 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPtaSa.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedPtaSa.scala @@ -17,12 +17,14 @@ package uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins import uk.gov.hmrc.cardpaymentfrontend.models.CheckYourAnswersRow +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethods.{OneOffDirectDebit, OpenBanking} import uk.gov.hmrc.cardpaymentfrontend.utils._ object ExtendedPtaSa extends ExtendedOrigin { override val serviceNameMessageKey: String = "service-name.PtaSa" override val taxNameMessageKey: String = "payment-complete.tax-name.PtaSa" def reference(): String = "1097172564" //This would really come from the journey either pay-api or stored locally + def cardFeesPagePaymentMethods: Set[PaymentMethod] = Set(OpenBanking, OneOffDirectDebit) //todo add these when we do that ticket def paymentMethods(): Set[PaymentMethod] = Set.empty //todo add this when we do that ticket diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/utils/OriginExtraInfo.scala b/app/uk/gov/hmrc/cardpaymentfrontend/utils/OriginExtraInfo.scala index e8cd553..5678cd8 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/utils/OriginExtraInfo.scala +++ b/app/uk/gov/hmrc/cardpaymentfrontend/utils/OriginExtraInfo.scala @@ -18,21 +18,27 @@ package uk.gov.hmrc.cardpaymentfrontend.utils import uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins.{DefaultExtendedOrigin, ExtendedBtaSa, ExtendedItSa, ExtendedOrigin, ExtendedPfP800, ExtendedPfSa, ExtendedPfVat, ExtendedPtaSa} import payapi.corcommon.model.{Origin, Origins} +import uk.gov.hmrc.cardpaymentfrontend.utils.PaymentMethods.{Bacs, Card, OneOffDirectDebit, OpenBanking, PrintableDirectDebit, VariableDirectDebit} import javax.inject.{Inject, Singleton} -trait PaymentMethod -case object Card extends PaymentMethod +//todo should probably be in it's own file. +sealed trait PaymentMethod -case object OpenBanking extends PaymentMethod +object PaymentMethods { -case object OneOffDirectDebit extends PaymentMethod + case object Card extends PaymentMethod -case object VariableDirectDebit extends PaymentMethod + case object OpenBanking extends PaymentMethod -case object PrintableDirectDebit extends PaymentMethod + case object OneOffDirectDebit extends PaymentMethod -case object Bacs extends PaymentMethod + case object VariableDirectDebit extends PaymentMethod + + case object PrintableDirectDebit extends PaymentMethod + + case object Bacs extends PaymentMethod +} //Probably a temporary class - it will be subsumed by the ExtendedOrigins in due course @@ -126,13 +132,6 @@ class OriginExtraInfo @Inject() () { def variableDirectDebitAllowed(origin: Origin): Boolean = paymentMethod(origin).contains(VariableDirectDebit) - // def lift(origin: Origin): ExtendedOrigin = { - // origin match { - // case Origins.PfSa => new ExtendedPfSa() - // case _ => new DefaultExtendedOrigin() - // } - // } - def lift(origin: Origin): ExtendedOrigin = { origin match { case Origins.PfSa => ExtendedPfSa diff --git a/app/uk/gov/hmrc/cardpaymentfrontend/views/FeesPage.scala.html b/app/uk/gov/hmrc/cardpaymentfrontend/views/FeesPage.scala.html index 30d7023..3d568cb 100644 --- a/app/uk/gov/hmrc/cardpaymentfrontend/views/FeesPage.scala.html +++ b/app/uk/gov/hmrc/cardpaymentfrontend/views/FeesPage.scala.html @@ -16,7 +16,6 @@ @import uk.gov.hmrc.cardpaymentfrontend.models.Link @import uk.gov.hmrc.cardpaymentfrontend.views.html.Layout -@import uk.gov.hmrc.cardpaymentfrontend.utils.{PaymentMethod, OpenBanking, VariableDirectDebit, OneOffDirectDebit} @import uk.gov.hmrc.govukfrontend.views.Aliases.{Button, ErrorSummary, Hint, Input, Label} @import uk.gov.hmrc.govukfrontend.views.html.components.{FormWithCSRF, GovukButton, GovukErrorSummary, GovukInput} @import uk.gov.hmrc.govukfrontend.views.Implicits.{RichFormErrors, RichInput} @@ -39,16 +38,17 @@

@heading

@messages("card-fees.para1")

@messages("card-fees.para2")

-