Skip to content

Commit 3b5497b

Browse files
[MG] [OPS-13150] Origins with no OpenBanking payment-failed TryAgain submission fix
1 parent f144714 commit 3b5497b

File tree

2 files changed

+75
-18
lines changed

2 files changed

+75
-18
lines changed

app/uk/gov/hmrc/cardpaymentfrontend/views/PaymentFailedPage.scala.html

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@import uk.gov.hmrc.govukfrontend.views.html.components._
2121
@import uk.gov.hmrc.govukfrontend.views.html.components.implicits.RichFormErrors
2222
@import payapi.corcommon.model.Origin
23-
@import payapi.corcommon.model.Origins
23+
@import payapi.corcommon.model.Origins._
2424

2525
@this(
2626
errorSummary: GovukErrorSummary,
@@ -32,23 +32,22 @@
3232

3333
@(origin: Origin, hasOpenBanking: Boolean, form: Form[ChooseAPaymentMethodFormValues])(implicit request: RequestHeader, messages: Messages)
3434

35-
@import payapi.corcommon.model.Origins.BcPngr
3635
@heading= @{messages("payment-failed.heading")}
3736

3837
@layout(pageTitle = Some(heading)) {
3938

40-
@if(form.hasErrors) {
41-
@errorSummary(ErrorSummary(errorList =
42-
form.errors.asTextErrorLinks, title = Text(messages("error.there-is-a-problem")))
43-
)
44-
}
45-
4639
<h1 class="govuk-heading-xl">@{
4740
messages("payment-failed.heading")
4841
}</h1>
4942

5043
@if(hasOpenBanking) {
5144

45+
@if(form.hasErrors) {
46+
@errorSummary(ErrorSummary(errorList =
47+
form.errors.asTextErrorLinks, title = Text(messages("error.there-is-a-problem")))
48+
)
49+
}
50+
5251
<p class="govuk-body govuk-!-padding-bottom-6" id="sub-heading">@{
5352
messages("payment-failed.sub-heading")
5453
}</p>
@@ -83,17 +82,27 @@ <h1 class="govuk-heading-xl">@{
8382
}
8483
} else {
8584

86-
<p class="govuk-body" id="sub-heading">@{messages("payment-failed.sub-heading")}</p>
85+
<p class="govuk-body" id="sub-heading">@{messages("payment-failed.sub-heading")}</p>
86+
87+
<p class="govuk-body" id="line1">@{messages("payment-failed.failed1")}</p>
88+
<ul class="govuk-list--bullet govuk-!-static-padding-left-7">
89+
<li class="govuk-body" id="line2">@{messages("payment-failed.failed2")}</li>
90+
<li class="govuk-body" id="line3">@{messages("payment-failed.failed3")}</li>
91+
@if(origin != BcPngr){ <li class="govuk-body" id="line4">@{messages("payment-failed.failed4")}</li> }
92+
</ul>
93+
<p class="govuk-body" id="check-again">@{messages("payment-failed.failed-check-again")}</p>
8794

88-
<p class="govuk-body" id="line1">@{messages("payment-failed.failed1")}</p>
89-
<ul class="govuk-list--bullet govuk-!-static-padding-left-7">
90-
<li class="govuk-body" id="line2">@{messages("payment-failed.failed2")}</li>
91-
<li class="govuk-body" id="line3">@{messages("payment-failed.failed3")}</li>
92-
@if(origin != BcPngr){ <li class="govuk-body" id="line4">@{messages("payment-failed.failed4")}</li> }
93-
</ul>
94-
<p class="govuk-body" id="check-again">@{messages("payment-failed.failed-check-again")}</p>
9595

96-
@govukButton(Button(content = Text(Messages("payment-failed.failed-check-details")), id = Some("submit")))
96+
@formWithCsrf(
97+
action = uk.gov.hmrc.cardpaymentfrontend.controllers.routes.PaymentFailedController.submit
98+
) {
99+
@govukButton(Button(
100+
content = Text(Messages("payment-failed.failed-check-details")),
101+
value = Some(ChooseAPaymentMethodFormValues.TryAgain.entryName),
102+
name = Some("payment_method"),
103+
attributes = Map("id" -> "next")
104+
))
105+
}
97106

98107
<div><br></div>
99108

test/uk/gov/hmrc/cardpaymentfrontend/controllers/PaymentFailedControllerSpec.scala

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,54 @@ class PaymentFailedControllerSpec extends ItSpec {
157157

158158
}
159159

160+
"GET /payment-failed with No Open Banking as a Payment Method" - {
161+
162+
val fakeGetRequest: FakeRequest[AnyContentAsFormUrlEncoded] = FakeRequest("POST", "/payment-failed").withSessionId().withFormUrlEncodedBody(("payment_method", ChooseAPaymentMethodFormValues.TryAgain.entryName))
163+
val fakeGetRequestInWelsh: FakeRequest[AnyContentAsEmpty.type] = FakeRequest("GET", "/payment-failed").withSessionId().withLangWelsh()
164+
165+
"should return 200 OK" in {
166+
PayApiStub.stubForFindBySessionId2xx(TestJourneys.ItSa.journeyAfterFailWebPayment)
167+
val result = systemUnderTest.renderPage()(fakeGetRequest)
168+
status(result) shouldBe Status.OK
169+
}
170+
171+
"render the page with the correct sub heading in English" in {
172+
PayApiStub.stubForFindBySessionId2xx(TestJourneys.ItSa.journeyAfterFailWebPayment)
173+
val result = systemUnderTest.renderPage(fakeGetRequest)
174+
val document = Jsoup.parse(contentAsString(result))
175+
document.selectXpath("//*[@id=\"main-content\"]/div/div/p[1]").text() shouldBe "No payment has been taken from your card."
176+
}
177+
178+
"render the page with the correct sub heading in Welsh" in {
179+
PayApiStub.stubForFindBySessionId2xx(TestJourneys.ItSa.journeyAfterFailWebPayment)
180+
val result = systemUnderTest.renderPage()(fakeGetRequestInWelsh)
181+
val document = Jsoup.parse(contentAsString(result))
182+
document.selectXpath("//*[@id=\"main-content\"]/div/div/p[1]").text() shouldBe "Nid oes taliad wedi’i dynnu o’ch cerdyn."
183+
}
184+
185+
"render the page with the correct button content in English" in {
186+
PayApiStub.stubForFindBySessionId2xx(TestJourneys.ItSa.journeyAfterFailWebPayment)
187+
val result = systemUnderTest.renderPage(fakeGetRequest)
188+
val document = Jsoup.parse(contentAsString(result))
189+
println(document)
190+
document.select(".govuk-button").first().text() shouldBe "Check details and try again"
191+
}
192+
193+
"render the page with the correct button content in Welsh" in {
194+
PayApiStub.stubForFindBySessionId2xx(TestJourneys.ItSa.journeyAfterFailWebPayment)
195+
val result = systemUnderTest.renderPage(fakeGetRequestInWelsh)
196+
val document = Jsoup.parse(contentAsString(result))
197+
document.select(".govuk-button").first().text() shouldBe "Gwiriwch y manylion a rhowch gynnig arall arni"
198+
}
199+
200+
"Button should redirect to TryAgain - Enter Email Address page" in {
201+
PayApiStub.stubForFindBySessionId2xx(TestJourneys.ItSa.journeyAfterFailWebPayment)
202+
val result = systemUnderTest.submit(fakeGetRequest)
203+
redirectLocation(result) shouldBe Some("/pay-by-card/email-address")
204+
}
205+
206+
}
207+
160208
"When Open Banking is selected" - {
161209
val fakeGetRequest: FakeRequest[AnyContentAsFormUrlEncoded] = FakeRequest("POST", "/payment-failed").withSessionId().withFormUrlEncodedBody(("payment_method", ChooseAPaymentMethodFormValues.OpenBanking.entryName))
162210

@@ -172,7 +220,7 @@ class PaymentFailedControllerSpec extends ItSpec {
172220
val fakeGetRequest: FakeRequest[AnyContentAsFormUrlEncoded] = FakeRequest("POST", "/payment-failed").withSessionId().withFormUrlEncodedBody(("payment_method", ChooseAPaymentMethodFormValues.TryAgain.entryName))
173221

174222
"Should redirect to the Enter Email Address page" in {
175-
PayApiStub.stubForFindBySessionId2xx(TestJourneys.PfSa.journeyAfterFailWebPayment)
223+
PayApiStub.stubForFindBySessionId2xx(TestJourneys.ItSa.journeyAfterFailWebPayment)
176224
val result = systemUnderTest.submit(fakeGetRequest)
177225
redirectLocation(result) shouldBe Some("/pay-by-card/email-address")
178226
}

0 commit comments

Comments
 (0)