Skip to content

Commit

Permalink
[JB][OPS-12861] wire up payments survey for Sa Origins (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnesjake authored Nov 7, 2024
1 parent 99d805e commit acbec88
Show file tree
Hide file tree
Showing 36 changed files with 824 additions and 24 deletions.
7 changes: 5 additions & 2 deletions app/uk/gov/hmrc/cardpaymentfrontend/actions/Actions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import javax.inject.{Inject, Singleton}

@Singleton
class Actions @Inject() (
actionBuilder: DefaultActionBuilder,
getJourneyActionRefiner: GetJourneyActionRefiner
actionBuilder: DefaultActionBuilder,
getJourneyActionRefiner: GetJourneyActionRefiner,
journeyFinishedActionRefiner: JourneyFinishedActionRefiner
) {

val default: ActionBuilder[Request, AnyContent] = actionBuilder

val journeyAction: ActionBuilder[JourneyRequest, AnyContent] = default.andThen[JourneyRequest](getJourneyActionRefiner)

val journeyFinishedAction: ActionBuilder[JourneyRequest, AnyContent] = journeyAction.andThen[JourneyRequest](journeyFinishedActionRefiner)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 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.cardpaymentfrontend.actions

import play.api.mvc.{ActionRefiner, Result, Results}

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class JourneyFinishedActionRefiner @Inject() ()(implicit ec: ExecutionContext) extends ActionRefiner[JourneyRequest, JourneyRequest] {

override protected[actions] def refine[A](request: JourneyRequest[A]): Future[Either[Result, JourneyRequest[A]]] = {
if (request.journey.status.isTerminalState) Future.successful(Right(request))
else Future.successful(Left(Results.NotFound("Journey not in valid state")))
}

override protected def executionContext: ExecutionContext = ec
}
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/cardpaymentfrontend/config/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AppConfig @Inject() (config: Configuration, servicesConfig: ServicesConfig

val payApiBaseUrl: String = servicesConfig.baseUrl("pay-api")
val openBankingBaseUrl: String = servicesConfig.baseUrl("open-banking")
val paymentsSurveyBaseUrl: String = servicesConfig.baseUrl("payments-survey")

val payFrontendBaseUrl: String = config.get[String]("urls.pay-frontend.base-url") + "/pay"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 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.cardpaymentfrontend.connectors

import play.api.libs.json.Json
import uk.gov.hmrc.cardpaymentfrontend.config.AppConfig
import uk.gov.hmrc.cardpaymentfrontend.models.paymentssurvey.{PaymentSurveyJourneyRequest, SsjResponse}
import uk.gov.hmrc.http.{HeaderCarrier, StringContextOps}
import uk.gov.hmrc.http.client.HttpClientV2
import uk.gov.hmrc.http.HttpReads.Implicits._

import java.net.URL
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class PaymentsSurveyConnector @Inject() (
appConfig: AppConfig,
httpClient: HttpClientV2
)(
implicit
ec: ExecutionContext
) {

private val serviceURL: URL = url"${appConfig.paymentsSurveyBaseUrl}/payments-survey/journey/start"

def startSurvey(surveyRequest: PaymentSurveyJourneyRequest)(implicit headerCarrier: HeaderCarrier): Future[SsjResponse] = {
httpClient.post(serviceURL).withBody(Json.toJson(surveyRequest)).execute[SsjResponse]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 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.cardpaymentfrontend.controllers

import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.cardpaymentfrontend.actions.{Actions, JourneyRequest}
import uk.gov.hmrc.cardpaymentfrontend.services.PaymentsSurveyService
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext

@Singleton
class PaymentsSurveyController @Inject() (
actions: Actions,
mcc: MessagesControllerComponents,
paymentsSurveyService: PaymentsSurveyService
)(implicit executionContext: ExecutionContext) extends FrontendController(mcc) {

def startSurvey(): Action[AnyContent] = actions.journeyFinishedAction.async { implicit journeyRequest: JourneyRequest[AnyContent] =>
paymentsSurveyService
.startPaySurvey(journeyRequest.journey)
.map(surveyStartUrl => Redirect(surveyStartUrl.value))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ class DefaultExtendedOrigin extends ExtendedOrigin {
def checkYourAnswersRows(): Seq[CheckYourAnswersRow] = Seq.empty[CheckYourAnswersRow]

override def openBankingOriginSpecificSessionData: JourneySpecificData => Option[OriginSpecificSessionData] = _ => None

override def surveyAuditName: String = ""
override def surveyReturnHref: String = "https://www.gov.uk/government/organisations/hm-revenue-customs"
override def surveyReturnMessageKey: String = "payments-survey.other.return-message"
override def surveyIsWelshSupported: Boolean = false
override def surveyBannerTitle: String = serviceNameMessageKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ class ExtendedBtaSa extends ExtendedOrigin {
case j: JsdBtaSa => Some(BtaSaSessionData(j.utr))
case _ => throw new RuntimeException("Incorrect origin found")
}

override def surveyAuditName: String = "self-assessment"
override def surveyReturnHref: String = "/business-account"
override def surveyReturnMessageKey: String = "payments-survey.bta.return-message"
override def surveyIsWelshSupported: Boolean = true
override def surveyBannerTitle: String = serviceNameMessageKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ class ExtendedItSa extends ExtendedOrigin {
case j: JsdItSa => Some(ItSaSessionData(j.utr))
case _ => throw new RuntimeException("Incorrect origin found")
}

override def surveyAuditName: String = "self-assessment"
override def surveyReturnHref: String = "https://www.gov.uk/government/organisations/hm-revenue-customs"
override def surveyReturnMessageKey: String = "payments-survey.other.return-message"
override def surveyIsWelshSupported: Boolean = true
override def surveyBannerTitle: String = serviceNameMessageKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ trait ExtendedOrigin {
def paymentMethods(): Set[PaymentMethod]
def checkYourAnswersRows(): Seq[CheckYourAnswersRow]
def openBankingOriginSpecificSessionData: JourneySpecificData => Option[OriginSpecificSessionData]

//payments survey stuff
def surveyAuditName: String
def surveyReturnHref: String
def surveyReturnMessageKey: String
def surveyIsWelshSupported: Boolean
def surveyBannerTitle: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ class ExtendedPfP800 extends ExtendedOrigin {
}

override def openBankingOriginSpecificSessionData: JourneySpecificData => Option[OriginSpecificSessionData] = _ => None

override def surveyAuditName: String = "p800-or-pa302"
override def surveyReturnHref: String = "https://www.gov.uk/government/organisations/hm-revenue-customs"
override def surveyReturnMessageKey: String = "payments-survey.other.return-message"
override def surveyIsWelshSupported: Boolean = true
override def surveyBannerTitle: String = serviceNameMessageKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ class ExtendedPfSa extends ExtendedOrigin {
case j: JsdPfSa => j.utr.map(PfSaSessionData(_))
case _ => throw new RuntimeException("Incorrect origin found")
}

override def surveyAuditName: String = "self-assessment"
override def surveyReturnHref: String = "https://www.gov.uk/government/organisations/hm-revenue-customs"
override def surveyReturnMessageKey: String = "payments-survey.other.return-message"
override def surveyIsWelshSupported: Boolean = true
override def surveyBannerTitle: String = serviceNameMessageKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ class ExtendedPfVat extends ExtendedOrigin {
case j: JsdPfVat => Some(PfVatSessionData(j.vrn, j.chargeRef))
case _ => throw new RuntimeException("Incorrect origin found")
}

override def surveyAuditName: String = "vat"
override def surveyReturnHref: String = "https://www.gov.uk/government/organisations/hm-revenue-customs"
override def surveyReturnMessageKey: String = "payments-survey.other.return-message"
override def surveyIsWelshSupported: Boolean = true
override def surveyBannerTitle: String = serviceNameMessageKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ class ExtendedPtaSa extends ExtendedOrigin {
case j: JsdPtaSa => Some(PtaSaSessionData(j.utr))
case _ => throw new RuntimeException("Incorrect origin found")
}

override def surveyAuditName: String = "self-assessment"
override def surveyReturnHref: String = "/personal-account"
override def surveyReturnMessageKey: String = "payments-survey.pta.return-message"
override def surveyIsWelshSupported: Boolean = true
override def surveyBannerTitle: String = serviceNameMessageKey
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 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.cardpaymentfrontend.models.paymentssurvey

import payapi.cardpaymentjourney.model.journey.{Journey, JourneySpecificData}
import play.api.libs.json.{Json, OFormat}
import play.api.mvc.Request
import uk.gov.hmrc.cardpaymentfrontend.models.extendedorigins.ExtendedOrigin
import uk.gov.hmrc.cardpaymentfrontend.requests.RequestSupport

final case class AuditOptions(
userType: String,
journey: Option[String] = None,
orderId: Option[String] = None,
liability: Option[String] = None
)

object AuditOptions {

@SuppressWarnings(Array("org.wartremover.warts.Any"))
implicit val format: OFormat[AuditOptions] = Json.format[AuditOptions]

def default(implicit r: Request[_]): AuditOptions = AuditOptions(
userType = if (RequestSupport.isLoggedIn) "LoggedIn" else "LoggedOut"
)

def getAuditOptions(journey: Journey[JourneySpecificData], extendedOrigin: ExtendedOrigin)(implicit r: Request[_]): AuditOptions = {
AuditOptions(
userType = if (RequestSupport.isLoggedIn) "LoggedIn" else "LoggedOut",
journey = Option(journey.status.entryName),
orderId = journey.reference.map(_.value),
liability = Some(extendedOrigin.surveyAuditName)
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 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.cardpaymentfrontend.models.paymentssurvey

import play.api.libs.json.{Json, Format}

final case class PaymentSurveyJourneyRequest(
origin: String,
returnMsg: String,
returnHref: String,
auditName: String,
audit: AuditOptions,
contentOptions: SurveyContentOptions
)

@SuppressWarnings(Array("org.wartremover.warts.Any"))
object PaymentSurveyJourneyRequest {
implicit val format: Format[PaymentSurveyJourneyRequest] = Json.format[PaymentSurveyJourneyRequest]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 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.cardpaymentfrontend.models.paymentssurvey

import payapi.cardpaymentjourney.model.journey.Url
import play.api.libs.json.{Format, Json}

final case class SsjResponse(journeyId: SurveyJourneyId, nextUrl: Url)

@SuppressWarnings(Array("org.wartremover.warts.Any"))
object SsjResponse {
implicit val format: Format[SsjResponse] = Json.format
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 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.cardpaymentfrontend.models.paymentssurvey

import play.api.libs.json.{Json, Format}

final case class SurveyBannerTitle(englishValue: String, welshValue: Option[String] = None)

@SuppressWarnings(Array("org.wartremover.warts.Any"))
object SurveyBannerTitle {
implicit val format: Format[SurveyBannerTitle] = Json.format[SurveyBannerTitle]
}
Loading

0 comments on commit acbec88

Please sign in to comment.