Skip to content

Commit

Permalink
PP-11470 show auth rejected page
Browse files Browse the repository at this point in the history
We would expect to see an error page when payment was declined after clicking “Pay” in the Google Pay dialog, instead we see a technical problems page.

- refactor auth response controller to handle 400 return code
- add a relevant test
  • Loading branch information
SandorArpa committed Sep 21, 2023
1 parent 1624cd9 commit d99584d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const handleAuthResponse = (req, res, charge) => response => {
}
break
case 400:
logging.failedChargePost(response.statusCode, getLoggingFields(req))
return responseRouter.response(req, res, 'AUTHORISATION_REJECTED', withAnalytics(
charge,
{ returnUrl: routeFor('return', charge.id) },
webPaymentsRouteFor('handlePaymentResponse', charge.id))
)
case 402:
case 500:
logging.failedChargePost(response.statusCode, getLoggingFields(req))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,41 @@ describe('The web payments handle auth response controller', () => {
expect(res.redirect.calledWith(303, '/card_details/chargeId/auth_waiting')).to.be.ok // eslint-disable-line
done()
})

it('should redirect to the the auth_failure view and delete connector response if connector response is in the session and status code is 202', done => {
const mockCharge = () => {
return {
capture: () => {
return {
then: function (success, fail) {
return fail({
message: 'AUTHORISATION_REJECTED'
})
}
}
}
}
}
const res = {
redirect: sinon.spy(),
render: sinon.spy(),
status: sinon.spy()
}
const mockCookies = {
getSessionVariable: () => {
return {
statusCode: 400
}
},
deleteSessionVariable: sinon.spy()
}

requireHandleAuthResponseController(mockCharge, mockNormaliseCharge, mockCookies)(req, res)
expect(mockCookies.deleteSessionVariable.calledWith(req, `ch_${chargeId}.webPaymentAuthResponse`)).to.be.ok // eslint-disable-line
expect(res.render.calledWith('errors/incorrect-state/auth-failure')).to.be.true // eslint-disable-line
done()
})

it('show capture failed page and delete connector response if connector response is in the session and and capture failed', done => {
const mockCharge = () => {
return {
Expand Down Expand Up @@ -171,6 +206,7 @@ describe('The web payments handle auth response controller', () => {
expect(res.render.calledWith('errors/incorrect-state/capture-failure', systemErrorObj)).to.be.true // eslint-disable-line
done()
})

it('show error page and delete connector response if connector response is in the session and error', done => {
const mockCharge = () => {
return {
Expand Down Expand Up @@ -291,6 +327,7 @@ describe('The web payments handle auth response controller', () => {
expect(res.render.calledWith('errors/system-error', systemErrorObj)).to.be.true // eslint-disable-line
done()
})

it('should return error if connector response has not been saved in the session', done => {
const res = {
redirect: sinon.spy(),
Expand Down

0 comments on commit d99584d

Please sign in to comment.