diff --git a/app/controllers/web-payments/payment-auth-request.controller.js b/app/controllers/web-payments/payment-auth-request.controller.js index adcc7673b..c55950166 100644 --- a/app/controllers/web-payments/payment-auth-request.controller.js +++ b/app/controllers/web-payments/payment-auth-request.controller.js @@ -9,29 +9,37 @@ const normaliseApplePayPayload = require('./apple-pay/normalise-apple-pay-payloa const normaliseGooglePayPayload = require('./google-pay/normalise-google-pay-payload') const { CORRELATION_HEADER } = require('../../../config/correlation-header') const { setSessionVariable } = require('../../utils/cookies') +const normalise = require("../../services/normalise-charge"); module.exports = (req, res) => { - const { chargeId, params, paymentProvider } = req - const { provider } = params + const { chargeData, chargeId, params } = req + const charge = normalise.charge(chargeData, chargeId) + const wallet = params.provider const { worldpay3dsFlexDdcStatus } = req.body if (worldpay3dsFlexDdcStatus) { logging.worldpay3dsFlexDdcStatus(worldpay3dsFlexDdcStatus, getLoggingFields(req)) } - const payload = provider === 'apple' ? normaliseApplePayPayload(req) : normaliseGooglePayPayload(req) + const payload = wallet === 'apple' ? normaliseApplePayPayload(req) : normaliseGooglePayPayload(req) - return connectorClient({ correlationId: req.headers[CORRELATION_HEADER] }).chargeAuthWithWallet({ chargeId, provider, paymentProvider, payload }, getLoggingFields(req)) + const walletAuthOpts = { + chargeId, + wallet, + paymentProvider: charge.paymentProvider, + payload + } + return connectorClient({ correlationId: req.headers[CORRELATION_HEADER] }).chargeAuthWithWallet(walletAuthOpts, getLoggingFields(req)) .then(data => { setSessionVariable(req, `ch_${(chargeId)}.webPaymentAuthResponse`, { statusCode: data.statusCode }) - logger.info(`Successful auth for ${provider} Pay payment. ChargeID: ${chargeId}`, getLoggingFields(req)) + logger.info(`Successful auth for ${wallet} Pay payment. ChargeID: ${chargeId}`, getLoggingFields(req)) res.status(200) res.send({ url: `/handle-payment-response/${chargeId}` }) }) .catch(err => { - logger.error(`Error while trying to authorise ${provider} Pay payment`, { + logger.error(`Error while trying to authorise ${wallet} Pay payment`, { ...getLoggingFields(req), error: err }) diff --git a/app/services/clients/connector.client.js b/app/services/clients/connector.client.js index 47e112797..5f173d0e2 100644 --- a/app/services/clients/connector.client.js +++ b/app/services/clients/connector.client.js @@ -231,7 +231,7 @@ const chargeAuth = (chargeOptions, loggingFields = {}) => { } const chargeAuthWithWallet = (chargeOptions, loggingFields = {}) => { - const authUrl = _getWalletAuthUrlFor(chargeOptions.chargeId, chargeOptions.provider, chargeOptions.paymentProvider) + const authUrl = _getWalletAuthUrlFor(chargeOptions.chargeId, chargeOptions.wallet, chargeOptions.paymentProvider) return _postConnector(authUrl, chargeOptions.payload, 'create charge using e-wallet payment', loggingFields, 'chargeAuthWithWallet') } diff --git a/test/controllers/web-payments/payment-auth-request.controller.test.js b/test/controllers/web-payments/payment-auth-request.controller.test.js index 34298bd3e..9a1646f93 100644 --- a/test/controllers/web-payments/payment-auth-request.controller.test.js +++ b/test/controllers/web-payments/payment-auth-request.controller.test.js @@ -5,6 +5,7 @@ const { expect } = require('chai') const nock = require('nock') const proxyquire = require('proxyquire') const sinon = require('sinon') +const paymentFixtures = require('../../fixtures/payment.fixtures') // Local dependencies require('../../test-helpers/html-assertions') @@ -20,7 +21,7 @@ describe('The web payments auth request controller', () => { 'x-request-id': 'aaa' }, chargeId, - paymentProvider: 'worldpay', + chargeData: paymentFixtures.validChargeDetails({ paymentProvider: 'worldpay' }), params: { provider }, @@ -87,7 +88,7 @@ describe('The web payments auth request controller', () => { 'x-request-id': 'aaa' }, chargeId, - paymentProvider: 'worldpay', + chargeData: paymentFixtures.validChargeDetails({ paymentProvider: 'worldpay' }), params: { provider }, @@ -115,7 +116,7 @@ describe('The web payments auth request controller', () => { statusCode: 200 } nock(process.env.CONNECTOR_HOST) - .post(`/v1/frontend/charges/${chargeId}/wallets/${provider}/worldpay`) + .post(`/v1/frontend/charges/${chargeId}/wallets/google/worldpay`) .reply(200) requirePaymentAuthRequestController(mockNormalise, mockCookies)(req, res).then(() => { expect(res.status.calledWith(200)).to.be.ok // eslint-disable-line diff --git a/test/unit/clients/connector-client-apple-authentication.pact.test.js b/test/unit/clients/connector-client-apple-authentication.pact.test.js index cfc2d36ca..31ecb25e3 100644 --- a/test/unit/clients/connector-client-apple-authentication.pact.test.js +++ b/test/unit/clients/connector-client-apple-authentication.pact.test.js @@ -61,7 +61,7 @@ describe('connectors client - apple authentication API', function () { const payload = appleAuthRequest connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'apple', + wallet: 'apple', payload: payload }).then(res => { expect(res.body.status).to.be.equal('AUTHORISATION SUCCESS') @@ -92,7 +92,7 @@ describe('connectors client - apple authentication API', function () { const payload = appleAuthRequest connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'apple', + wallet: 'apple', payload: payload }).then(res => { expect(res.body.status).to.be.equal('AUTHORISATION SUCCESS') @@ -124,7 +124,7 @@ describe('connectors client - apple authentication API', function () { const payload = appleAuthRequest connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'apple', + wallet: 'apple', payload: payload }).then(res => { expect(res.body.status).to.be.equal('AUTHORISATION SUCCESS') @@ -152,7 +152,7 @@ describe('connectors client - apple authentication API', function () { it('should return authorisation declined', function (done) { connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'apple', + wallet: 'apple', payload: appleAuthRequest }).then(() => { done() @@ -179,7 +179,7 @@ describe('connectors client - apple authentication API', function () { it('should return authorisation declined', function (done) { connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'apple', + wallet: 'apple', payload: appleAuthRequest }).then(() => { done() diff --git a/test/unit/clients/connector-client-google-authentication.pact.test.js b/test/unit/clients/connector-client-google-authentication.pact.test.js index dc15e1d26..30f3dce03 100644 --- a/test/unit/clients/connector-client-google-authentication.pact.test.js +++ b/test/unit/clients/connector-client-google-authentication.pact.test.js @@ -63,7 +63,7 @@ describe('connectors client - google authentication API', function () { const payload = successfulGoogleAuthRequest connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'google', + wallet: 'google', payload: payload, paymentProvider: 'worldpay' }).then(res => { @@ -98,7 +98,7 @@ describe('connectors client - google authentication API', function () { const payload = successfulGoogleAuthRequest connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'google', + wallet: 'google', payload: payload, paymentProvider: 'worldpay' }).then(res => { @@ -130,7 +130,7 @@ describe('connectors client - google authentication API', function () { it('should return authorisation declined', function (done) { connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'google', + wallet: 'google', payload: declinedGoogleAuthRequest, paymentProvider: 'worldpay' }).then(() => { @@ -161,7 +161,7 @@ describe('connectors client - google authentication API', function () { it('should return authorisation declined', function (done) { connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'google', + wallet: 'google', payload: errorGoogleAuthRequest, paymentProvider: 'worldpay' }).then(() => { @@ -192,7 +192,7 @@ describe('connectors client - google authentication API', function () { const payload = successfulGoogleAuthRequest connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({ chargeId: TEST_CHARGE_ID, - provider: 'google', + wallet: 'google', payload: payload, paymentProvider: 'worldpay' }).then(res => {