Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-11638 Add wallet path param for logging #3768

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = (allowedCardTypes, provider) => {
module.exports = (allowedCardTypes, wallet) => {
if (!allowedCardTypes) {
return []
}
Expand All @@ -16,11 +16,11 @@ module.exports = (allowedCardTypes, provider) => {
.filter(brand => brand !== 'diners-club')
.filter(brand => brand !== 'unionpay')

if (provider === 'google') {
if (wallet === 'google') {
filteredAvailableNetworks = filteredAvailableNetworks.filter(brand => brand !== 'maestro')
}

if (provider === 'apple' && filteredAvailableNetworks.includes('visa')) {
if (wallet === 'apple' && filteredAvailableNetworks.includes('visa')) {
filteredAvailableNetworks.push('electron')
}

Expand All @@ -29,6 +29,6 @@ module.exports = (allowedCardTypes, provider) => {
let formattedBrand = brand
if (brand === 'master-card') formattedBrand = 'masterCard'
if (brand === 'american-express') formattedBrand = 'amex'
return provider === 'google' ? formattedBrand.toUpperCase() : formattedBrand
return wallet === 'google' ? formattedBrand.toUpperCase() : formattedBrand
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const normalise = require('../../services/normalise-charge')
module.exports = (req, res, next) => {
const { chargeData, chargeId, params } = req
const charge = normalise.charge(chargeData, chargeId)
const wallet = params.provider
const { wallet } = params
const paymentProvider = charge.paymentProvider
let payload

Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = (req, res, next) => {

// Always return 200 - the redirect checks if there are any errors
res.status(200)
res.send({ url: `/handle-payment-response/${chargeId}` })
res.send({ url: `/handle-payment-response/${wallet}/${chargeId}` })
})
.catch(err => {
logger.error(`Error while trying to authorise ${wallet} Pay payment`, {
Expand All @@ -58,6 +58,6 @@ module.exports = (req, res, next) => {
})
res.status(200)
// Always return 200 - the redirect handles the error
res.send({ url: `/handle-payment-response/${chargeId}` })
res.send({ url: `/handle-payment-response/${wallet}/${chargeId}` })
})
}
6 changes: 1 addition & 5 deletions app/middleware/retrieve-charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
const {
GATEWAY_ACCOUNT_ID,
GATEWAY_ACCOUNT_TYPE,
PROVIDER,
WALLET
PROVIDER
} = require('@govuk-pay/pay-js-commons').logging.keys

// Local dependencies
Expand All @@ -24,9 +23,6 @@ module.exports = (req, res, next) => {
setLoggingField(req, GATEWAY_ACCOUNT_ID, data.gateway_account.gateway_account_id)
setLoggingField(req, GATEWAY_ACCOUNT_TYPE, data.gateway_account.type)
setLoggingField(req, PROVIDER, data.payment_provider)
if (data.wallet_type) {
setLoggingField(req, WALLET, data.wallet_type)
}
next()
})
.catch((err) => {
Expand Down
6 changes: 5 additions & 1 deletion app/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ const paths = {
},
webPayments: {
authRequest: {
path: '/web-payments-auth-request/:provider/:chargeId',
path: '/web-payments-auth-request/:wallet/:chargeId',
action: 'post'
},
handlePaymentResponse: {
path: '/handle-payment-response/:chargeId',
action: 'get'
},
handlePaymentResponseNew: {
path: '/handle-payment-response/:wallet/:chargeId',
action: 'get'
}
},
secure: {
Expand Down
1 change: 1 addition & 0 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ exports.bind = function (app) {
// Generic Web payments endpoint
app.post(paths.webPayments.authRequest.path, chargeCookieRequiredMiddlewareStack, webPaymentsMakePayment)
app.get(paths.webPayments.handlePaymentResponse.path, chargeCookieRequiredMiddlewareStack, webPaymentsHandlePaymentResponse)
app.get(paths.webPayments.handlePaymentResponseNew.path, chargeCookieRequiredMiddlewareStack, webPaymentsHandlePaymentResponse)

// secure controller
app.get(paths.secure.get.path, secure.new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const chargeId = 'chargeId'

describe('The web payments auth request controller', () => {
describe('when processing an Apple Pay payment', () => {
const provider = 'apple'
const wallet = 'apple'
const req = {
headers: {
'x-request-id': 'aaa'
},
chargeId,
chargeData: paymentFixtures.validChargeDetails({ paymentProvider: 'worldpay' }),
params: {
provider
wallet
},
body: {}
}
Expand All @@ -49,11 +49,11 @@ describe('The web payments auth request controller', () => {
statusCode: 200
}
nock(process.env.CONNECTOR_HOST)
.post(`/v1/frontend/charges/${chargeId}/wallets/${provider}`)
.post(`/v1/frontend/charges/${chargeId}/wallets/${wallet}`)
.reply(200)
requirePaymentAuthRequestController(mockNormalise, mockCookies)(req, res).then(() => {
expect(res.status.calledWith(200)).to.be.ok // eslint-disable-line
expect(res.send.calledWith({url: `/handle-payment-response/${chargeId}`})).to.be.ok // eslint-disable-line
expect(res.send.calledWith({url: `/handle-payment-response/apple/${chargeId}`})).to.be.ok // eslint-disable-line
expect(mockCookies.setSessionVariable.calledWith(req, `ch_${chargeId}.webPaymentAuthResponse`, expectedBodySavedInSession)).to.be.ok // eslint-disable-line
done()
}
Expand Down Expand Up @@ -82,15 +82,15 @@ describe('The web payments auth request controller', () => {
})

describe('when processing a Google Pay payment', () => {
const provider = 'google'
const wallet = 'google'
const req = {
headers: {
'x-request-id': 'aaa'
},
chargeId,
chargeData: paymentFixtures.validChargeDetails({ paymentProvider: 'worldpay' }),
params: {
provider
wallet
},
body: {}
}
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('The web payments auth request controller', () => {
.reply(200)
requirePaymentAuthRequestController(mockNormalise, mockCookies)(req, res).then(() => {
expect(res.status.calledWith(200)).to.be.ok // eslint-disable-line
expect(res.send.calledWith({ url: `/handle-payment-response/${chargeId}` })).to.be.ok // eslint-disable-line
expect(res.send.calledWith({ url: `/handle-payment-response/google/${chargeId}` })).to.be.ok // eslint-disable-line
expect(mockCookies.setSessionVariable.calledWith(req, `ch_${chargeId}.webPaymentAuthResponse`, expectedBodySavedInSession)).to.be.ok // eslint-disable-line
done()
}
Expand All @@ -146,7 +146,7 @@ describe('The web payments auth request controller', () => {

requirePaymentAuthRequestController(mockNormalise, mockCookies)(req, res).then(() => {
expect(res.status.calledWith(200)).to.be.ok // eslint-disable-line
expect(res.send.calledWith({ url: `/handle-payment-response/${chargeId}` })).to.be.ok // eslint-disable-line
expect(res.send.calledWith({ url: `/handle-payment-response/google/${chargeId}` })).to.be.ok // eslint-disable-line
expect(mockCookies.setSessionVariable.calledWith(req, `ch_${chargeId}.webPaymentAuthResponse`, expectedBodySavedInSession)).to.be.ok // eslint-disable-line
done()
}
Expand All @@ -166,7 +166,7 @@ describe('The web payments auth request controller', () => {
.replyWithError('oops')
requirePaymentAuthRequestController(mockNormalise, mockCookies)(req, res).then(() => {
expect(res.status.calledWith(200)).to.be.ok // eslint-disable-line
expect(res.send.calledWith({ url: `/handle-payment-response/${chargeId}` })).to.be.ok // eslint-disable-line
expect(res.send.calledWith({ url: `/handle-payment-response/google/${chargeId}` })).to.be.ok // eslint-disable-line
expect(mockCookies.setSessionVariable.called).to.be.false // eslint-disable-line
done()
}
Expand Down