Skip to content

Commit

Permalink
Merge pull request #3663 from alphagov/PP-11394-fix-making-google-pay…
Browse files Browse the repository at this point in the history
…-request

PP-11494 Fix Google Pay authorisation
  • Loading branch information
kbottla authored Sep 7, 2023
2 parents 4d28d75 + 3c2c26e commit 449abd7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
20 changes: 14 additions & 6 deletions app/controllers/web-payments/payment-auth-request.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion app/services/clients/connector.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 449abd7

Please sign in to comment.