Skip to content

Commit

Permalink
PP-7583 Move your psp routes
Browse files Browse the repository at this point in the history
Update your psp routes to use the new account URL structure.
  • Loading branch information
stephencdaly committed Jan 18, 2021
1 parent d9130ae commit f86dee8
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 167 deletions.
12 changes: 6 additions & 6 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "package-lock.json",
"lines": null
},
"generated_at": "2021-01-18T10:18:13Z",
"generated_at": "2021-01-18T11:24:19Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -150,21 +150,21 @@
"hashed_secret": "d0be4e729498f4cfe8a72a28d4fceae35bd8bb27",
"is_secret": false,
"is_verified": false,
"line_number": 14,
"line_number": 16,
"type": "Secret Keyword"
},
{
"hashed_secret": "2c877f34a0f47f32a5f3c77e398938b3cdc32221",
"is_secret": false,
"is_verified": false,
"line_number": 19,
"line_number": 21,
"type": "Secret Keyword"
},
{
"hashed_secret": "379f1968f09d8a343338667844e01a2f433f0a3f",
"is_secret": false,
"is_verified": false,
"line_number": 23,
"line_number": 25,
"type": "Hex High Entropy String"
}
],
Expand Down Expand Up @@ -232,14 +232,14 @@
"hashed_secret": "0ea7458942ab65e0a340cf4fd28ca00d93c494f3",
"is_secret": false,
"is_verified": false,
"line_number": 502,
"line_number": 513,
"type": "Secret Keyword"
},
{
"hashed_secret": "1695899a3d59e9fe2af1cdf242d8c451b8506173",
"is_secret": false,
"is_verified": false,
"line_number": 546,
"line_number": 556,
"type": "Secret Keyword"
}
],
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/credentials.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const EDIT_NOTIFICATION_CREDENTIALS_MODE = 'editNotificationCredentials'

const _ = require('lodash')
const paths = require('../paths')
const formatAccountPathsFor = require('../utils/format-account-paths-for')
const { response } = require('../utils/response')
const { renderErrorView } = require('../utils/response')
const { ConnectorClient } = require('../services/clients/connector.client')
const router = require('../routes')
const { CONNECTOR_URL } = process.env
const { CORRELATION_HEADER } = require('../utils/correlation-header')
const { isPasswordLessThanTenChars } = require('../browsered/field-validation-checks')
Expand Down Expand Up @@ -109,7 +109,7 @@ module.exports = {
gatewayAccountId: accountId
})

return res.redirect(303, router.paths.yourPsp.index)
return res.redirect(303, formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id))
} catch (err) {
return renderErrorView(req, res)
}
Expand All @@ -124,7 +124,7 @@ module.exports = {
payload: credentialsPatchRequestValueOf(req), correlationId: correlationId, gatewayAccountId: accountId
})

return res.redirect(303, router.paths.yourPsp.index)
return res.redirect(303, formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id))
} catch (err) {
return renderErrorView(req, res)
}
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/your-psp/post-flex.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const lodash = require('lodash')

const paths = require('../../paths')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')
const { renderErrorView } = require('../../utils/response')
const { ConnectorClient } = require('../../services/clients/connector.client')
const { correlationHeader } = require('../../utils/correlation-header')
Expand All @@ -17,8 +18,9 @@ const JWT_MAC_KEY_FIELD = 'jwt-mac-key'

module.exports = async (req, res) => {
const correlationId = req.headers[correlationHeader] || ''

const accountId = req.account.gateway_account_id
const flexUrl = formatAccountPathsFor(paths.account.yourPsp.flex, req.account && req.account.external_id)
const indexUrl = formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id)

const orgUnitId = lodash.get(req.body, ORGANISATIONAL_UNIT_ID_FIELD, '').trim()
const issuer = lodash.get(req.body, ISSUER_FIELD, '').trim()
Expand All @@ -32,7 +34,7 @@ module.exports = async (req, res) => {
orgUnitId: orgUnitId,
issuer: issuer
})
return res.redirect(303, paths.yourPsp.flex)
return res.redirect(303, flexUrl)
}

try {
Expand All @@ -58,7 +60,7 @@ module.exports = async (req, res) => {
orgUnitId: orgUnitId,
issuer: issuer
})
return res.redirect(303, paths.yourPsp.flex)
return res.redirect(303, flexUrl)
}
}

Expand All @@ -68,7 +70,7 @@ module.exports = async (req, res) => {

await connector.post3dsFlexAccountCredentials(flexParams)
req.flash('generic', 'Your Worldpay 3DS Flex settings have been updated')
return res.redirect(paths.yourPsp.index)
return res.redirect(indexUrl)
} catch (error) {
return renderErrorView(req, res, false, error.errorCode)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict'

const paths = require('../../paths')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')
const { renderErrorView } = require('../../utils/response')
const { ConnectorClient } = require('../../services/clients/connector.client')
const connector = new ConnectorClient(process.env.CONNECTOR_URL)

module.exports = async function toggleWorldpay3dsFlex (req, res) {
const accountId = req.account.gateway_account_id
const toggleWorldpay3dsFlex = req.body['toggle-worldpay-3ds-flex']
const indexUrl = formatAccountPathsFor(paths.account.yourPsp.index, req.account && req.account.external_id)

if (req.body['toggle-worldpay-3ds-flex'] === 'on' || req.body['toggle-worldpay-3ds-flex'] === 'off') {
const enabling3dsFlex = toggleWorldpay3dsFlex === 'on'
Expand All @@ -16,7 +18,7 @@ module.exports = async function toggleWorldpay3dsFlex (req, res) {
try {
await connector.updateIntegrationVersion3ds(accountId, integrationVersion3ds, req.correlationId)
req.flash('generic', message)
return res.redirect(303, paths.yourPsp.index)
return res.redirect(303, indexUrl)
} catch (error) {
return renderErrorView(req, res, false, error.errorCode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const proxyquire = require('proxyquire')
const sinon = require('sinon')
const paths = require('../../paths')

describe('Toggle Worldpay 3DS Flex controller', () => {
const gatewayAccountExternalId = 'a-gateway-account-external-id'
let req
let res
let updateIntegrationVersion3dsMock
Expand All @@ -14,7 +14,8 @@ describe('Toggle Worldpay 3DS Flex controller', () => {
req = {
correlationId: 'correlation-id',
account: {
gateway_account_id: '1'
gateway_account_id: '1',
external_id: gatewayAccountExternalId
},
flash: sinon.spy(),
body: {}
Expand All @@ -36,7 +37,7 @@ describe('Toggle Worldpay 3DS Flex controller', () => {

sinon.assert.calledWith(updateIntegrationVersion3dsMock, req.account.gateway_account_id, 2, req.correlationId)
sinon.assert.calledWith(req.flash, 'generic', '3DS Flex has been turned on.')
sinon.assert.calledWith(res.redirect, 303, paths.yourPsp.index)
sinon.assert.calledWith(res.redirect, 303, `/account/${gatewayAccountExternalId}/your-psp`)
})

it('should toggle 3DS Flex off by setting 3DS integration version to 1', async () => {
Expand All @@ -48,7 +49,7 @@ describe('Toggle Worldpay 3DS Flex controller', () => {

sinon.assert.calledWith(updateIntegrationVersion3dsMock, req.account.gateway_account_id, 1, req.correlationId)
sinon.assert.calledWith(req.flash, 'generic', '3DS Flex has been turned off. Your payments will now use 3DS only.')
sinon.assert.calledWith(res.redirect, 303, paths.yourPsp.index)
sinon.assert.calledWith(res.redirect, 303, `/account/${gatewayAccountExternalId}/your-psp`)
})

it('should render an error if problem calling connector', async () => {
Expand Down
22 changes: 11 additions & 11 deletions app/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module.exports = {
keys,
account: {
root: `/account/:${keys.GATEWAY_ACCOUNT_EXTERNAL_ID}`,
apiKeys: {
index: '/api-keys',
revoked: '/api-keys/revoked',
create: '/api-keys/create',
revoke: '/api-keys/revoke',
update: '/api-keys/update'
},
digitalWallet: {
applePay: '/digital-wallet/apple-pay',
googlePay: '/digital-wallet/google-pay'
Expand Down Expand Up @@ -44,12 +51,10 @@ module.exports = {
cardNumber: '/moto-hide-card-number',
securityCode: '/moto-hide-security-code'
},
apiKeys: {
index: '/api-keys',
revoked: '/api-keys/revoked',
create: '/api-keys/create',
revoke: '/api-keys/revoke',
update: '/api-keys/update'
yourPsp: {
index: '/your-psp',
flex: '/your-psp/flex',
worldpay3dsFlex: '/your-psp/worldpay-3ds-flex'
}
},
transactions: {
Expand All @@ -63,11 +68,6 @@ module.exports = {
index: '/all-service-transactions',
download: '/all-service-transactions/download'
},
yourPsp: {
index: '/your-psp',
flex: '/your-psp/flex',
worldpay3dsFlex: '/your-psp/worldpay-3ds-flex'
},
credentials: {
index: '/credentials',
edit: '/credentials/edit',
Expand Down
12 changes: 3 additions & 9 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const {
serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails,
notificationCredentials, prototyping, paymentLinks,
requestToGoLive, policyPages, stripeSetup, stripe,
yourPsp, allServiceTransactions, payouts
allServiceTransactions, payouts
} = paths
const {
apiKeys,
Expand All @@ -100,7 +100,8 @@ const {
settings,
toggle3ds,
toggleBillingAddress,
toggleMotoMaskCardNumberAndSecurityCode
toggleMotoMaskCardNumberAndSecurityCode,
yourPsp
} = paths.account

// Exports
Expand Down Expand Up @@ -180,7 +181,6 @@ module.exports.bind = function (app) {
...lodash.values(allServiceTransactions),
...lodash.values(credentials),
...lodash.values(notificationCredentials),
...lodash.values(apiKeys),
...lodash.values(editServiceName),
...lodash.values(serviceSwitcher),
...lodash.values(teamMembers),
Expand All @@ -193,7 +193,6 @@ module.exports.bind = function (app) {
...lodash.values(policyPages),
...lodash.values(stripeSetup),
...lodash.values(stripe),
...lodash.values(yourPsp),
...lodash.values(payouts),
paths.feedback
] // Extract all the authenticated paths as a single array
Expand Down Expand Up @@ -285,11 +284,6 @@ module.exports.bind = function (app) {
account.get(settings.index, permission('transactions-details:read'), settingsController.index)

// Your PSP
app.get(yourPsp.index, permission('gateway-credentials:read'), getAccount, paymentMethodIsCard, yourPspController.getIndex)
app.post(yourPsp.worldpay3dsFlex, permission('toggle-3ds:update'), getAccount, paymentMethodIsCard, yourPspController.postToggleWorldpay3dsFlex)
app.get(yourPsp.flex, permission('gateway-credentials:update'), getAccount, paymentMethodIsCard, yourPspController.getFlex)
app.post(yourPsp.flex, permission('gateway-credentials:update'), getAccount, paymentMethodIsCard, yourPspController.postFlex)

account.get(yourPsp.index, permission('gateway-credentials:read'), paymentMethodIsCard, yourPspController.getIndex)
account.post(yourPsp.worldpay3dsFlex, permission('toggle-3ds:update'), paymentMethodIsCard, yourPspController.postToggleWorldpay3dsFlex)
account.get(yourPsp.flex, permission('gateway-credentials:update'), paymentMethodIsCard, yourPspController.getFlex)
Expand Down
4 changes: 2 additions & 2 deletions app/utils/nav-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const mainSettingsPaths = [
]

const yourPspPaths = [
paths.yourPsp,
paths.account.yourPsp,
paths.credentials,
paths.notificationCredentials
]
Expand Down Expand Up @@ -89,7 +89,7 @@ const adminNavigationItems = (currentPath, permissions, type, paymentProvider, a
{
id: 'navigation-menu-your-psp',
name: `Your PSP - ${formatPSPname(paymentProvider)}`,
url: paths.yourPsp.index,
url: formatAccountPathsFor(paths.account.yourPsp.index, account.external_id),
current: pathLookup(currentPath, yourPspPaths),
permissions: permissions.gateway_credentials_update && type === 'card' && (paymentProvider !== 'stripe') && (paymentProvider !== 'sandbox')
},
Expand Down
2 changes: 1 addition & 1 deletion app/views/credentials/worldpay.njk
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</form>

<p class="govuk-body">
<a class="govuk-link govuk-link--no-visited-state" href="{{ routes.yourPsp.index }}">Cancel</a>
<a class="govuk-link govuk-link--no-visited-state" href="{{ formatAccountPathsFor(routes.account.yourPsp.index, currentGatewayAccount.external_id) }}">Cancel</a>
</p>
{% endif %}
{% endblock %}
8 changes: 4 additions & 4 deletions app/views/your-psp/_worldpay-flex.njk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
actions: {
items: [
{
href: routes.yourPsp.flex + "?change=organisationalUnitId",
href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=organisationalUnitId",
text: "Change",
visuallyHiddenText: "3DS Flex credentials",
attributes: {
Expand All @@ -50,7 +50,7 @@
actions: {
items: [
{
href: routes.yourPsp.flex + "?change=issuer",
href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=issuer",
text: "Change",
visuallyHiddenText: "3DS Flex credentials"
}
Expand All @@ -68,7 +68,7 @@
actions: {
items: [
{
href: routes.yourPsp.flex + "?change=password",
href: formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) + "?change=password",
text: "Change",
visuallyHiddenText: "3DS Flex credentials"
}
Expand All @@ -80,7 +80,7 @@
}}

{% if (is3dsEnabled and isWorldpay3dsFlexCredentialsConfigured) or isWorldpay3dsFlexEnabled %}
<form method="post" action="{{routes.yourPsp.worldpay3dsFlex}}">
<form method="post" action="{{ formatAccountPathsFor(routes.account.yourPsp.worldpay3dsFlex, currentGatewayAccount.external_id) }}">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}">
{% if is3dsEnabled and isWorldpay3dsFlexCredentialsConfigured and not isWorldpay3dsFlexEnabled %}
<input id="toggle-worldpay-3ds-flex" name="toggle-worldpay-3ds-flex" type="hidden" value="on">
Expand Down
4 changes: 2 additions & 2 deletions app/views/your-psp/flex.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% block mainContent %}
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Your Worldpay 3DS Flex credentials</h1>
<form method="post" action="{{routes.yourPsp.flex}}">
<form method="post" action="{{ formatAccountPathsFor(routes.account.yourPsp.flex, currentGatewayAccount.external_id) }}">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}" />
{% if errors %}
{% set errorList = [] %}
Expand Down Expand Up @@ -174,7 +174,7 @@
}}
</form>
<p class="govuk-body">
<a class="govuk-link govuk-link--no-visited-state" href="{{ routes.yourPsp.index }}">Cancel</a>
<a class="govuk-link govuk-link--no-visited-state" href="{{ formatAccountPathsFor(routes.account.yourPsp.index, currentGatewayAccount.external_id) }}">Cancel</a>
</p>
</div>
{% endblock %}
Loading

0 comments on commit f86dee8

Please sign in to comment.