diff --git a/app/controllers/web-payments/handle-auth-response.controller.js b/app/controllers/web-payments/handle-auth-response.controller.js index 3233a21a5..6e17575d1 100644 --- a/app/controllers/web-payments/handle-auth-response.controller.js +++ b/app/controllers/web-payments/handle-auth-response.controller.js @@ -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)) diff --git a/test/controllers/web-payments/handle-auth-response.controller.test.js b/test/controllers/web-payments/handle-auth-response.controller.test.js index 27b458b03..3c2ee58ec 100644 --- a/test/controllers/web-payments/handle-auth-response.controller.test.js +++ b/test/controllers/web-payments/handle-auth-response.controller.test.js @@ -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 { @@ -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 { @@ -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(),