From 8b3755b9ab0eec224e95d074cd7b27863ec90adb Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 18 Jan 2021 15:41:14 +0000 Subject: [PATCH 1/3] PP-7583: update payment links to new account URL structure Update all payment links routes and references to point to the new account URL structure. --- .../payment-links/get-amount.controller.js | 7 +-- .../payment-links/get-delete.controller.js | 5 +- .../payment-links/get-disable.controller.js | 5 +- .../get-edit-amount.controller.js | 6 +-- .../get-edit-information.controller.js | 7 +-- .../get-edit-reference.controller.js | 7 +-- .../payment-links/get-edit.controller.js | 16 +++--- .../payment-links/get-review.controller.js | 5 +- .../payment-links/post-amount.controller.js | 5 +- .../post-edit-amount.controller.js | 8 +-- .../post-edit-information.controller.js | 8 +-- .../post-edit-reference.controller.js | 8 +-- .../payment-links/post-edit.controller.js | 6 ++- .../post-information.controller.js | 10 ++-- .../post-reference.controller.js | 8 +-- .../payment-links/post-review.controller.js | 9 ++-- .../post-web-address.controller.js | 6 ++- app/paths.js | 51 +++++++++---------- app/routes.js | 41 ++------------- app/utils/nav-builder.js | 5 +- app/utils/payment-links.js | 16 +++--- app/views/dashboard/_links.njk | 4 +- app/views/payment-links/_nav.njk | 4 +- app/views/payment-links/amount.njk | 2 +- app/views/payment-links/edit-amount.njk | 2 +- app/views/payment-links/edit-information.njk | 2 +- app/views/payment-links/edit-reference.njk | 2 +- app/views/payment-links/edit.njk | 2 +- app/views/payment-links/index.njk | 4 +- app/views/payment-links/information.njk | 4 +- app/views/payment-links/manage.njk | 2 +- app/views/payment-links/reference.njk | 4 +- app/views/payment-links/review.njk | 12 ++--- app/views/payment-links/web-address.njk | 4 +- 34 files changed, 135 insertions(+), 152 deletions(-) diff --git a/app/controllers/payment-links/get-amount.controller.js b/app/controllers/payment-links/get-amount.controller.js index 0a283680f6..eb9bee8edd 100644 --- a/app/controllers/payment-links/get-amount.controller.js +++ b/app/controllers/payment-links/get-amount.controller.js @@ -4,6 +4,7 @@ const lodash = require('lodash') const { response } = require('../../utils/response.js') const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = function showAmountPage (req, res, next) { const sessionData = lodash.get(req, 'session.pageData.createPaymentLink') @@ -20,9 +21,9 @@ module.exports = function showAmountPage (req, res, next) { return response(req, res, 'payment-links/amount', { paymentLinkAmount, paymentAmountType, - nextPage: paths.paymentLinks.amount, - returnToStart: paths.paymentLinks.start, - manage: paths.paymentLinks.manage.index, + nextPage: formatAccountPathsFor(paths.account.paymentLinks.amount, req.account && req.account.external_id), + returnToStart: formatAccountPathsFor(paths.account.paymentLinks.start, req.account && req.account.external_id), + manage: formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id), isWelsh: sessionData.isWelsh, errors: recovered.errors }) diff --git a/app/controllers/payment-links/get-delete.controller.js b/app/controllers/payment-links/get-delete.controller.js index bd45e6ad10..9f6b1b5edc 100644 --- a/app/controllers/payment-links/get-delete.controller.js +++ b/app/controllers/payment-links/get-delete.controller.js @@ -2,6 +2,7 @@ const logger = require('../../utils/logger')(__filename) const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const productsClient = require('../../services/clients/products.client.js') const publicAuthClient = require('../../services/clients/public-auth.client.js') @@ -22,10 +23,10 @@ module.exports = async (req, res) => { await Promise.all([deleteToken, deleteProduct]) req.flash('generic', 'The payment link was successfully deleted') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } catch (err) { logger.error(`[requestId=${req.correlationId}] Delete product failed - ${err.message}`) req.flash('genericError', 'Something went wrong when deleting the payment link. Please try again or contact support.') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } } diff --git a/app/controllers/payment-links/get-disable.controller.js b/app/controllers/payment-links/get-disable.controller.js index 4eac60f576..093cd6e097 100644 --- a/app/controllers/payment-links/get-disable.controller.js +++ b/app/controllers/payment-links/get-disable.controller.js @@ -2,6 +2,7 @@ const logger = require('../../utils/logger')(__filename) const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const productsClient = require('../../services/clients/products.client.js') module.exports = async (req, res) => { @@ -10,10 +11,10 @@ module.exports = async (req, res) => { try { await productsClient.product.disable(gatewayAccountId, req.params.productExternalId) req.flash('generic', 'The payment link was successfully deleted') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } catch (err) { logger.error(`[requestId=${req.correlationId}] Disable product failed - ${err.message}`) req.flash('genericError', 'Something went wrong when deleting the payment link. Please try again or contact support.') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } } diff --git a/app/controllers/payment-links/get-edit-amount.controller.js b/app/controllers/payment-links/get-edit-amount.controller.js index ae3be44076..3705dad350 100644 --- a/app/controllers/payment-links/get-edit-amount.controller.js +++ b/app/controllers/payment-links/get-edit-amount.controller.js @@ -4,7 +4,7 @@ const lodash = require('lodash') const { response } = require('../../utils/response.js') const paths = require('../../paths') -const formattedPathFor = require('../../utils/replace-params-in-path') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const supportedLanguage = require('../../models/supported-language') module.exports = function showEditAmountPage (req, res) { @@ -13,13 +13,13 @@ module.exports = function showEditAmountPage (req, res) { const sessionData = lodash.get(req, 'session.editPaymentLinkData') if (!sessionData || sessionData.externalId !== productExternalId) { req.flash('genericError', 'Something went wrong. Please try again.') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } const recovered = sessionData.amountPageRecovered || {} delete sessionData.amountPageRecovered - const self = formattedPathFor(paths.paymentLinks.manage.editAmount, productExternalId) + const self = formatAccountPathsFor(paths.account.paymentLinks.manage.editAmount, req.account && req.account.external_id, productExternalId) const change = lodash.get(req, 'query.field', {}) const amountType = recovered.type || sessionData.price ? 'fixed' : 'variable' const amountInPence = recovered.amount || sessionData.price diff --git a/app/controllers/payment-links/get-edit-information.controller.js b/app/controllers/payment-links/get-edit-information.controller.js index 74679def0d..6bcf9dde4e 100644 --- a/app/controllers/payment-links/get-edit-information.controller.js +++ b/app/controllers/payment-links/get-edit-information.controller.js @@ -4,7 +4,7 @@ const lodash = require('lodash') const { response } = require('../../utils/response.js') const paths = require('../../paths') -const formattedPathFor = require('../../utils/replace-params-in-path') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const supportedLanguage = require('../../models/supported-language') module.exports = function showEditInformationPage (req, res, next) { @@ -13,13 +13,14 @@ module.exports = function showEditInformationPage (req, res, next) { const sessionData = lodash.get(req, 'session.editPaymentLinkData') if (!sessionData || sessionData.externalId !== productExternalId) { req.flash('genericError', 'Something went wrong. Please try again.') - return res.redirect(paths.paymentLinks.manage.index) + + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } const recovered = sessionData.informationPageRecovered || {} delete sessionData.informationPageRecovered - const self = formattedPathFor(paths.paymentLinks.manage.editInformation, productExternalId) + const self = formatAccountPathsFor(paths.account.paymentLinks.manage.editInformation, req.account && req.account.external_id, productExternalId) const change = lodash.get(req, 'query.field', {}) const paymentLinkTitle = recovered.name || sessionData.name const paymentLinkDescription = recovered.description || sessionData.description diff --git a/app/controllers/payment-links/get-edit-reference.controller.js b/app/controllers/payment-links/get-edit-reference.controller.js index 469b86cc8f..b422cdd5e5 100644 --- a/app/controllers/payment-links/get-edit-reference.controller.js +++ b/app/controllers/payment-links/get-edit-reference.controller.js @@ -4,7 +4,7 @@ const lodash = require('lodash') const { response } = require('../../utils/response.js') const paths = require('../../paths') -const formattedPathFor = require('../../utils/replace-params-in-path') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const supportedLanguage = require('../../models/supported-language') module.exports = function showEditReferencePage (req, res, next) { @@ -13,13 +13,14 @@ module.exports = function showEditReferencePage (req, res, next) { const sessionData = lodash.get(req, 'session.editPaymentLinkData') if (!sessionData || sessionData.externalId !== productExternalId) { req.flash('genericError', 'Something went wrong. Please try again.') - return res.redirect(paths.paymentLinks.manage.index) + + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } const recovered = sessionData.referencePageRecovered || {} delete sessionData.referencePageRecovered - const self = formattedPathFor(paths.paymentLinks.manage.editReference, productExternalId) + const self = formatAccountPathsFor(paths.account.paymentLinks.manage.editReference, req.account && req.account.external_id, productExternalId) const change = lodash.get(req, 'query.field', {}) const referenceLabel = recovered.referenceLabel || sessionData.referenceLabel const referenceHint = recovered.referenceHint || sessionData.referenceHint diff --git a/app/controllers/payment-links/get-edit.controller.js b/app/controllers/payment-links/get-edit.controller.js index 79c8cacc86..24b863c42b 100644 --- a/app/controllers/payment-links/get-edit.controller.js +++ b/app/controllers/payment-links/get-edit.controller.js @@ -5,10 +5,11 @@ const lodash = require('lodash') const { response } = require('../../utils/response.js') const paths = require('../../paths') const productsClient = require('../../services/clients/products.client.js') -const formattedPathFor = require('../../utils/replace-params-in-path') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = async function showEditPaymentLink (req, res, next) { const { productExternalId } = req.params + const accountExternalId = req.account && req.account.external_id let editPaymentLinkData = lodash.get(req, 'session.editPaymentLinkData', {}) if (editPaymentLinkData.externalId && editPaymentLinkData.externalId !== productExternalId) { @@ -18,16 +19,15 @@ module.exports = async function showEditPaymentLink (req, res, next) { editPaymentLinkData = {} } - const addMetadataUrl = formattedPathFor(paths.paymentLinks.manage.addMetadata, productExternalId) - const editMetadataPath = paths.paymentLinks.manage.editMetadata + const addMetadataUrl = formatAccountPathsFor(paths.account.paymentLinks.manage.addMetadata, accountExternalId, productExternalId) + const editMetadataPath = formatAccountPathsFor(paths.account.paymentLinks.manage.editMetadata, accountExternalId) const pageData = { - self: formattedPathFor(paths.paymentLinks.manage.edit, productExternalId), - editInformation: formattedPathFor(paths.paymentLinks.manage.editInformation, productExternalId), - editReference: formattedPathFor(paths.paymentLinks.manage.editReference, productExternalId), - editAmount: formattedPathFor(paths.paymentLinks.manage.editAmount, productExternalId), + self: formatAccountPathsFor(paths.account.paymentLinks.manage.edit, accountExternalId, productExternalId), + editInformation: formatAccountPathsFor(paths.account.paymentLinks.manage.editInformation, accountExternalId, productExternalId), + editReference: formatAccountPathsFor(paths.account.paymentLinks.manage.editReference, accountExternalId, productExternalId), + editAmount: formatAccountPathsFor(paths.account.paymentLinks.manage.editAmount, accountExternalId, productExternalId), addMetadata: addMetadataUrl, editMetadata: editMetadataPath, - formattedPathFor, paths } const gatewayAccountId = req.account.gateway_account_id diff --git a/app/controllers/payment-links/get-review.controller.js b/app/controllers/payment-links/get-review.controller.js index e1cd404c0a..8456b9d44d 100644 --- a/app/controllers/payment-links/get-review.controller.js +++ b/app/controllers/payment-links/get-review.controller.js @@ -3,6 +3,7 @@ const lodash = require('lodash') const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const { response } = require('../../utils/response.js') @@ -11,8 +12,8 @@ module.exports = (req, res) => { return response(req, res, 'payment-links/review', { pageData, - addMetadata: paths.paymentLinks.addMetadata, - editMetadata: paths.paymentLinks.editMetadata, + addMetadata: formatAccountPathsFor(paths.account.paymentLinks.addMetadata, req.account && req.account.external_id), + editMetadata: formatAccountPathsFor(paths.account.paymentLinks.editMetadata, req.account && req.account.external_id), metadata: pageData.metadata }) } diff --git a/app/controllers/payment-links/post-amount.controller.js b/app/controllers/payment-links/post-amount.controller.js index 1353f2aadb..7c1450d748 100644 --- a/app/controllers/payment-links/post-amount.controller.js +++ b/app/controllers/payment-links/post-amount.controller.js @@ -3,6 +3,7 @@ const lodash = require('lodash') const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const { safeConvertPoundsStringToPence } = require('../../utils/currency-formatter') module.exports = function postAmount (req, res, next) { @@ -30,7 +31,7 @@ module.exports = function postAmount (req, res, next) { errors, type } - return res.redirect(paths.paymentLinks.amount) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.amount, req.account && req.account.external_id)) } sessionData.paymentLinkAmount = amountInPence @@ -40,5 +41,5 @@ module.exports = function postAmount (req, res, next) { req.flash('generic', 'The details have been updated') } - return res.redirect(paths.paymentLinks.review) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.review, req.account && req.account.external_id)) } diff --git a/app/controllers/payment-links/post-edit-amount.controller.js b/app/controllers/payment-links/post-edit-amount.controller.js index 6824418698..28b2b5d661 100644 --- a/app/controllers/payment-links/post-edit-amount.controller.js +++ b/app/controllers/payment-links/post-edit-amount.controller.js @@ -3,7 +3,7 @@ const lodash = require('lodash') const paths = require('../../paths') -const formattedPathFor = require('../../utils/replace-params-in-path') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const { safeConvertPoundsStringToPence } = require('../../utils/currency-formatter') module.exports = function postEditAmount (req, res) { @@ -12,7 +12,7 @@ module.exports = function postEditAmount (req, res) { const sessionData = lodash.get(req, 'session.editPaymentLinkData') if (!sessionData || sessionData.externalId !== productExternalId) { req.flash('genericError', 'Something went wrong. Please try again.') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } const type = req.body['amount-type-group'] @@ -35,11 +35,11 @@ module.exports = function postEditAmount (req, res) { type, amount: '' } - return res.redirect(formattedPathFor(paths.paymentLinks.manage.editAmount, productExternalId)) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.editAmount, req.account && req.account.external_id, productExternalId)) } sessionData.price = amountInPence lodash.set(req, 'session.editPaymentLinkData', sessionData) - return res.redirect(formattedPathFor(paths.paymentLinks.manage.edit, productExternalId)) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.edit, req.account && req.account.external_id, productExternalId)) } diff --git a/app/controllers/payment-links/post-edit-information.controller.js b/app/controllers/payment-links/post-edit-information.controller.js index e18c1ac10d..3611c25fa3 100644 --- a/app/controllers/payment-links/post-edit-information.controller.js +++ b/app/controllers/payment-links/post-edit-information.controller.js @@ -3,7 +3,7 @@ const lodash = require('lodash') const paths = require('../../paths') -const formattedPathFor = require('../../utils/replace-params-in-path') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = function postEditInformation (req, res) { const { productExternalId } = req.params @@ -11,7 +11,7 @@ module.exports = function postEditInformation (req, res) { const sessionData = lodash.get(req, 'session.editPaymentLinkData') if (!sessionData || sessionData.externalId !== productExternalId) { req.flash('genericError', 'Something went wrong. Please try again.') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } const name = req.body['payment-link-title'] @@ -26,11 +26,11 @@ module.exports = function postEditInformation (req, res) { name, description } - return res.redirect(formattedPathFor(paths.paymentLinks.manage.editInformation, productExternalId)) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.editInformation, req.account && req.account.external_id, productExternalId)) } sessionData.name = name sessionData.description = description - return res.redirect(formattedPathFor(paths.paymentLinks.manage.edit, productExternalId)) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.edit, req.account && req.account.external_id, productExternalId)) } diff --git a/app/controllers/payment-links/post-edit-reference.controller.js b/app/controllers/payment-links/post-edit-reference.controller.js index a7dea10c10..46babb7666 100644 --- a/app/controllers/payment-links/post-edit-reference.controller.js +++ b/app/controllers/payment-links/post-edit-reference.controller.js @@ -3,7 +3,7 @@ const lodash = require('lodash') const paths = require('../../paths') -const formattedPathFor = require('../../utils/replace-params-in-path') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = function postEditReference (req, res) { const { productExternalId } = req.params @@ -11,7 +11,7 @@ module.exports = function postEditReference (req, res) { const sessionData = lodash.get(req, 'session.editPaymentLinkData') if (!sessionData || sessionData.externalId !== productExternalId) { req.flash('genericError', 'Something went wrong. Please try again.') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } const referenceEnabled = req.body['reference-type-group'] === 'custom' @@ -28,12 +28,12 @@ module.exports = function postEditReference (req, res) { referenceLabel, referenceHint } - return res.redirect(formattedPathFor(paths.paymentLinks.manage.editReference, productExternalId)) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.editReference, req.account && req.account.external_id, productExternalId)) } sessionData.referenceEnabled = referenceEnabled sessionData.referenceLabel = referenceLabel sessionData.referenceHint = referenceHint - return res.redirect(formattedPathFor(paths.paymentLinks.manage.edit, productExternalId)) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.edit, req.account && req.account.external_id, productExternalId)) } diff --git a/app/controllers/payment-links/post-edit.controller.js b/app/controllers/payment-links/post-edit.controller.js index f6b2fa150e..afb71c5e00 100644 --- a/app/controllers/payment-links/post-edit.controller.js +++ b/app/controllers/payment-links/post-edit.controller.js @@ -3,6 +3,7 @@ const lodash = require('lodash') const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const productsClient = require('../../services/clients/products.client.js') const logger = require('../../utils/logger')(__filename) const { keys } = require('@govuk-pay/pay-js-commons').logging @@ -14,7 +15,8 @@ module.exports = async function updatePaymentLink (req, res, next) { const editPaymentLinkData = lodash.get(req, 'session.editPaymentLinkData') if (!editPaymentLinkData || editPaymentLinkData.externalId !== productExternalId) { req.flash('genericError', 'Something went wrong. Please try again.') - return res.redirect(paths.paymentLinks.manage.index) + + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } try { @@ -35,7 +37,7 @@ module.exports = async function updatePaymentLink (req, res, next) { lodash.unset(req, 'session.editPaymentLinkData') req.flash('generic', 'Your payment link has been updated') - return res.redirect(paths.paymentLinks.manage.index) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } catch (err) { return next(new Error(`Update of payment link failed. Error: ${err.message}`)) } diff --git a/app/controllers/payment-links/post-information.controller.js b/app/controllers/payment-links/post-information.controller.js index b2ec47cc69..4934aa9f6b 100644 --- a/app/controllers/payment-links/post-information.controller.js +++ b/app/controllers/payment-links/post-information.controller.js @@ -4,6 +4,8 @@ const lodash = require('lodash') const { slugify, removeIndefiniteArticles } = require('@govuk-pay/pay-js-commons').nunjucksFilters const paths = require('../../paths') + +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const productsClient = require('../../services/clients/products.client.js') const makeNiceURL = string => { @@ -29,7 +31,7 @@ module.exports = async function postInformation (req, res, next) { title, description } - return res.redirect(paths.paymentLinks.information) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.information, req.account && req.account.external_id)) } sessionData.paymentLinkTitle = title @@ -39,15 +41,15 @@ module.exports = async function postInformation (req, res, next) { if (req.body['change'] === 'true') { req.flash('generic', 'The details have been updated') - return res.redirect(paths.paymentLinks.review) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.review, req.account && req.account.external_id)) } try { await productsClient.product.getByProductPath(sessionData.serviceNamePath, sessionData.productNamePath) // if product exists we need to alert the user they must use a different URL - return res.redirect(paths.paymentLinks.webAddress) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.webAddress, req.account && req.account.external_id)) } catch (err) { // if it errors then it means no product was found and that’s good - return res.redirect(paths.paymentLinks.reference) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.reference, req.account && req.account.external_id)) } } diff --git a/app/controllers/payment-links/post-reference.controller.js b/app/controllers/payment-links/post-reference.controller.js index 9a1fec62f2..ed7009f488 100644 --- a/app/controllers/payment-links/post-reference.controller.js +++ b/app/controllers/payment-links/post-reference.controller.js @@ -3,6 +3,8 @@ const lodash = require('lodash') const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') + module.exports = function postReference (req, res, next) { const sessionData = lodash.get(req, 'session.pageData.createPaymentLink') if (!sessionData) { @@ -27,7 +29,7 @@ module.exports = function postReference (req, res, next) { label, hint } - return res.redirect(paths.paymentLinks.reference) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.reference, req.account && req.account.external_id)) } sessionData.paymentReferenceType = type @@ -36,8 +38,8 @@ module.exports = function postReference (req, res, next) { if (req.body['change'] === 'true') { req.flash('generic', 'The details have been updated') - return res.redirect(paths.paymentLinks.review) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.review, req.account && req.account.external_id)) } - return res.redirect(paths.paymentLinks.amount) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.amount, req.account && req.account.external_id)) } diff --git a/app/controllers/payment-links/post-review.controller.js b/app/controllers/payment-links/post-review.controller.js index c2f8049f32..9d478a8a87 100644 --- a/app/controllers/payment-links/post-review.controller.js +++ b/app/controllers/payment-links/post-review.controller.js @@ -3,6 +3,8 @@ const lodash = require('lodash') const logger = require('../../utils/logger')(__filename) const paths = require('../../paths') + +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const productsClient = require('../../services/clients/products.client.js') const productTypes = require('../../utils/product-types') const publicAuthClient = require('../../services/clients/public-auth.client') @@ -25,7 +27,7 @@ module.exports = async function createPaymentLink (req, res) { } = lodash.get(req, 'session.pageData.createPaymentLink', {}) if (!paymentLinkTitle) { - return res.redirect(paths.paymentLinks.start) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.start, req.account && req.account.external_id)) } try { @@ -80,10 +82,11 @@ module.exports = async function createPaymentLink (req, res) { lodash.unset(req, 'session.pageData.createPaymentLink') req.flash('createPaymentLinkSuccess', true) - res.redirect(paths.paymentLinks.manage.index) + + res.redirect(formatAccountPathsFor(paths.account.paymentLinks.manage.index, req.account && req.account.external_id)) } catch (error) { logger.error(`[requestId=${req.correlationId}] Creating a payment link failed - ${error.message}`) req.flash('genericError', 'Something went wrong. Please try again or contact support.') - res.redirect(paths.paymentLinks.review) + res.redirect(formatAccountPathsFor(paths.account.paymentLinks.review, req.account && req.account.external_id)) } } diff --git a/app/controllers/payment-links/post-web-address.controller.js b/app/controllers/payment-links/post-web-address.controller.js index eb0e5dfdda..78c5c9054b 100644 --- a/app/controllers/payment-links/post-web-address.controller.js +++ b/app/controllers/payment-links/post-web-address.controller.js @@ -6,6 +6,8 @@ const paths = require('../../paths') const productsClient = require('../../services/clients/products.client.js') const { slugify, removeIndefiniteArticles } = require('@govuk-pay/pay-js-commons').nunjucksFilters +const formatAccountPathsFor = require('../../utils/format-account-paths-for') + const makeNiceURL = string => { return slugify(removeIndefiniteArticles(string)) } @@ -32,7 +34,7 @@ module.exports = async function postWebAddress (req, res, next) { } catch (err) { // URL not in use, continue paymentLinkData.productNamePath = resolvedURLPath - return res.redirect(paths.paymentLinks.reference) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.reference, req.account && req.account.external_id)) } } @@ -41,5 +43,5 @@ module.exports = async function postWebAddress (req, res, next) { errors, paymentLinkURLPath }) - return res.redirect(paths.paymentLinks.webAddress) + return res.redirect(formatAccountPathsFor(paths.account.paymentLinks.webAddress, req.account && req.account.external_id)) } diff --git a/app/paths.js b/app/paths.js index a2d3a6bc92..48e57e5dbd 100644 --- a/app/paths.js +++ b/app/paths.js @@ -66,6 +66,29 @@ module.exports = { create: '/api-keys/create', revoke: '/api-keys/revoke', update: '/api-keys/update' + }, + paymentLinks: { + start: '/create-payment-link', + information: '/create-payment-link/information', + webAddress: '/create-payment-link/web-address', + reference: '/create-payment-link/reference', + amount: '/create-payment-link/amount', + review: '/create-payment-link/review', + addMetadata: '/create-payment-link/add-reporting-column', + editMetadata: '/create-payment-link/add-reporting-column/:metadataKey', + deleteMetadata: '/create-payment-link/add-reporting-column/:metadataKey/delete', + manage: { + index: '/create-payment-link/manage', + edit: '/create-payment-link/manage/edit/:productExternalId', + disable: '/create-payment-link/manage/disable/:productExternalId', + delete: '/create-payment-link/manage/delete/:productExternalId', + editInformation: '/create-payment-link/manage/edit/information/:productExternalId', + editReference: '/create-payment-link/manage/edit/reference/:productExternalId', + editAmount: '/create-payment-link/manage/edit/amount/:productExternalId', + addMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column', + editMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey', + deleteMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey/delete' + } } }, transactions: { @@ -161,34 +184,6 @@ module.exports = { staticPaths: { naxsiError: '/request-denied' }, - paymentLinks: { - start: '/create-payment-link', - information: '/create-payment-link/information', - webAddress: '/create-payment-link/web-address', - reference: '/create-payment-link/reference', - amount: '/create-payment-link/amount', - review: '/create-payment-link/review', - addMetadata: '/create-payment-link/add-reporting-column', - editMetadata: '/create-payment-link/add-reporting-column/:metadataKey', - deleteMetadata: '/create-payment-link/add-reporting-column/:metadataKey/delete', - manage: { - index: '/create-payment-link/manage', - edit: '/create-payment-link/manage/edit/:productExternalId', - disable: '/create-payment-link/manage/disable/:productExternalId', - delete: '/create-payment-link/manage/delete/:productExternalId', - editInformation: '/create-payment-link/manage/edit/information/:productExternalId', - editReference: '/create-payment-link/manage/edit/reference/:productExternalId', - editAmount: '/create-payment-link/manage/edit/amount/:productExternalId', - addMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column', - editMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey', - deleteMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey/delete' - }, - metadata: { - add: '/create-payment-link/manage/edit/:productExternalId/metadata', - edit: '/create-payment-link/manage/edit/:productExternalId/metadata/:metadataKey', - delete: '/create-payment-link/manage/edit/:productExternalId/metadata/:metadataKey/delete' - } - }, feedback: '/feedback', generateRoute: generateRoute, formattedPathFor: formattedPathFor, diff --git a/app/routes.js b/app/routes.js index 9e2bcbeb4b..f956729e9a 100644 --- a/app/routes.js +++ b/app/routes.js @@ -88,7 +88,7 @@ const stripeSetupDashboardRedirectController = require('./controllers/stripe-set const { healthcheck, registerUser, user, dashboard, selfCreateService, transactions, credentials, serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails, - notificationCredentials, paymentLinks, + notificationCredentials, requestToGoLive, policyPages, stripeSetup, stripe, yourPsp, allServiceTransactions, payouts } = paths @@ -101,7 +101,8 @@ const { settings, toggle3ds, toggleBillingAddress, - toggleMotoMaskCardNumberAndSecurityCode + toggleMotoMaskCardNumberAndSecurityCode, + paymentLinks } = paths.account // Exports @@ -369,41 +370,7 @@ module.exports.bind = function (app) { account.get(prototyping.demoPayment.mockCardDetails, permission('transactions:read'), restrictToSandbox, makeADemoPaymentController.mockCardDetails) account.post(prototyping.demoPayment.goToPaymentScreens, permission('transactions:read'), restrictToSandbox, makeADemoPaymentController.goToPayment) - // Payment links - app.get(paymentLinks.start, permission('tokens:create'), getAccount, paymentLinksController.getStart) - app.get(paymentLinks.information, permission('tokens:create'), getAccount, paymentLinksController.getInformation) - app.post(paymentLinks.information, permission('tokens:create'), getAccount, paymentLinksController.postInformation) - app.get(paymentLinks.webAddress, permission('tokens:create'), getAccount, paymentLinksController.getWebAddress) - app.post(paymentLinks.webAddress, permission('tokens:create'), getAccount, paymentLinksController.postWebAddress) - app.get(paymentLinks.reference, permission('tokens:create'), getAccount, paymentLinksController.getReference) - app.post(paymentLinks.reference, permission('tokens:create'), getAccount, paymentLinksController.postReference) - app.get(paymentLinks.amount, permission('tokens:create'), getAccount, paymentLinksController.getAmount) - app.post(paymentLinks.amount, permission('tokens:create'), getAccount, paymentLinksController.postAmount) - app.get(paymentLinks.review, permission('tokens:create'), getAccount, paymentLinksController.getReview) - app.post(paymentLinks.review, permission('tokens:create'), getAccount, paymentLinksController.postReview) - app.get(paymentLinks.addMetadata, permission('tokens:create'), getAccount, paymentLinksController.getAddReportingColumn.showAddMetadataPage) - app.get(paymentLinks.editMetadata, permission('tokens:create'), getAccount, paymentLinksController.getAddReportingColumn.showEditMetadataPage) - app.post(paymentLinks.addMetadata, permission('tokens:create'), getAccount, paymentLinksController.postUpdateReportingColumn.addMetadata) - app.post(paymentLinks.editMetadata, permission('tokens:create'), getAccount, paymentLinksController.postUpdateReportingColumn.editMetadata) - app.post(paymentLinks.deleteMetadata, permission('tokens:create'), getAccount, paymentLinksController.postUpdateReportingColumn.deleteMetadata) - - app.get(paymentLinks.manage.index, permission('transactions:read'), getAccount, paymentLinksController.getManage) - app.get(paymentLinks.manage.disable, permission('tokens:create'), getAccount, paymentLinksController.getDisable) - app.get(paymentLinks.manage.delete, permission('tokens:create'), getAccount, paymentLinksController.getDelete) - app.get(paymentLinks.manage.edit, permission('tokens:create'), getAccount, paymentLinksController.getEdit) - app.post(paymentLinks.manage.edit, permission('tokens:create'), getAccount, paymentLinksController.postEdit) - app.get(paymentLinks.manage.editInformation, permission('tokens:create'), getAccount, paymentLinksController.getEditInformation) - app.post(paymentLinks.manage.editInformation, permission('tokens:create'), getAccount, paymentLinksController.postEditInformation) - app.get(paymentLinks.manage.editReference, permission('tokens:create'), getAccount, paymentLinksController.getEditReference) - app.post(paymentLinks.manage.editReference, permission('tokens:create'), getAccount, paymentLinksController.postEditReference) - app.get(paymentLinks.manage.editAmount, permission('tokens:create'), getAccount, paymentLinksController.getEditAmount) - app.post(paymentLinks.manage.editAmount, permission('tokens:create'), getAccount, paymentLinksController.postEditAmount) - app.get(paymentLinks.manage.addMetadata, permission('tokens:create'), getAccount, paymentLinksController.getAddReportingColumn.showAddMetadataPage) - app.post(paymentLinks.manage.addMetadata, permission('tokens:create'), getAccount, paymentLinksController.postUpdateReportingColumn.addMetadata) - app.get(paymentLinks.manage.editMetadata, permission('tokens:create'), getAccount, paymentLinksController.getAddReportingColumn.showEditMetadataPage) - app.post(paymentLinks.manage.editMetadata, permission('tokens:create'), getAccount, paymentLinksController.postUpdateReportingColumn.editMetadata) - app.post(paymentLinks.manage.deleteMetadata, permission('tokens:create'), getAccount, paymentLinksController.postUpdateReportingColumn.deleteMetadata) - + // Create payment link account.get(paymentLinks.start, permission('tokens:create'), paymentLinksController.getStart) account.get(paymentLinks.information, permission('tokens:create'), paymentLinksController.getInformation) account.post(paymentLinks.information, permission('tokens:create'), paymentLinksController.postInformation) diff --git a/app/utils/nav-builder.js b/app/utils/nav-builder.js index deff51746d..ddd1dec105 100644 --- a/app/utils/nav-builder.js +++ b/app/utils/nav-builder.js @@ -31,6 +31,7 @@ const serviceNavigationItems = (currentPath, permissions, type, account = {}) => permissions: true }) if (type === 'card') { + const paymentLinksStartUrl = formatAccountPathsFor(paths.account.paymentLinks.start, account.external_id) navigationItems.push({ id: 'navigation-menu-transactions', name: 'Transactions', @@ -41,8 +42,8 @@ const serviceNavigationItems = (currentPath, permissions, type, account = {}) => navigationItems.push({ id: 'navigation-menu-payment-links', name: 'Payment links', - url: paths.paymentLinks.start, - current: pathLookup(currentPath, paths.paymentLinks.start), + url: paymentLinksStartUrl, + current: pathLookup(currentPath, paymentLinksStartUrl), permissions: permissions.tokens_create }) } diff --git a/app/utils/payment-links.js b/app/utils/payment-links.js index 5b215ae06a..43ad0b7191 100644 --- a/app/utils/payment-links.js +++ b/app/utils/payment-links.js @@ -4,12 +4,14 @@ const lodash = require('lodash') const paths = require('../paths') +const formatAccountPathsFor = require('../utils/format-account-paths-for') // the edit and create flows handle storing cookie session data in separate places, // abstract this away from the controller by adding accessors that can be based // based on the request function getPaymentLinksContext (req) { - const isCreatingPaymentLink = !Object.values(paths.paymentLinks.manage).includes(req.route && req.route.path) + const isCreatingPaymentLink = !Object.values(paths.account.paymentLinks.manage).includes(req.route && req.route.path) + const accountExternalId = req.account && req.account.external_id const params = req.params || {} if (isCreatingPaymentLink) { @@ -17,9 +19,9 @@ function getPaymentLinksContext (req) { return { sessionData: lodash.get(req, 'session.pageData.createPaymentLink'), - addMetadataPageUrl: paths.paymentLinks.addMetadata, - editMetadataPageUrl: paths.formattedPathFor(paths.paymentLinks.editMetadata, metadataKey), - listMetadataPageUrl: paths.paymentLinks.review, + addMetadataPageUrl: formatAccountPathsFor(paths.account.paymentLinks.addMetadata, accountExternalId), + editMetadataPageUrl: formatAccountPathsFor(paths.account.paymentLinks.editMetadata, accountExternalId, metadataKey), + listMetadataPageUrl: formatAccountPathsFor(paths.account.paymentLinks.review, accountExternalId), isCreatingPaymentLink } } else { @@ -27,9 +29,9 @@ function getPaymentLinksContext (req) { return { sessionData: lodash.get(req, 'session.editPaymentLinkData'), - addMetadataPageUrl: paths.generateRoute(paths.paymentLinks.manage.addMetadata, { productExternalId }), - editMetadataPageUrl: paths.formattedPathFor(paths.paymentLinks.manage.editMetadata, productExternalId, metadataKey), - listMetadataPageUrl: paths.generateRoute(paths.paymentLinks.manage.edit, { productExternalId }), + addMetadataPageUrl: formatAccountPathsFor(paths.account.paymentLinks.manage.addMetadata, accountExternalId, productExternalId), + editMetadataPageUrl: formatAccountPathsFor(paths.account.paymentLinks.manage.editMetadata, accountExternalId, productExternalId, metadataKey), + listMetadataPageUrl: formatAccountPathsFor(paths.account.paymentLinks.manage.edit, accountExternalId, productExternalId), isCreatingPaymentLink } } diff --git a/app/views/dashboard/_links.njk b/app/views/dashboard/_links.njk index 548b14ead8..91a172b632 100644 --- a/app/views/dashboard/_links.njk +++ b/app/views/dashboard/_links.njk @@ -28,10 +28,10 @@ {% if links.paymentLinks in linksToDisplay %}