Skip to content

Commit

Permalink
Merge pull request #2509 from alphagov/PP-7583-payment-links-account-…
Browse files Browse the repository at this point in the history
…url-structure

PP-7583 Payment links account url structure
  • Loading branch information
sfount authored Jan 19, 2021
2 parents cef8ec4 + 17543a4 commit 64a36ee
Show file tree
Hide file tree
Showing 58 changed files with 247 additions and 2,798 deletions.
7 changes: 4 additions & 3 deletions app/controllers/payment-links/get-amount.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
})
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/payment-links/get-delete.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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))
}
}
5 changes: 3 additions & 2 deletions app/controllers/payment-links/get-disable.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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))
}
}
6 changes: 3 additions & 3 deletions app/controllers/payment-links/get-edit-amount.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/payment-links/get-edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/payment-links/get-review.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 { response } = require('../../utils/response.js')

Expand All @@ -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
})
}
5 changes: 3 additions & 2 deletions app/controllers/payment-links/post-amount.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 { safeConvertPoundsStringToPence } = require('../../utils/currency-formatter')

module.exports = function postAmount (req, res, next) {
Expand Down Expand Up @@ -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
Expand All @@ -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))
}
8 changes: 4 additions & 4 deletions app/controllers/payment-links/post-edit-amount.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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']
Expand All @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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

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']
Expand All @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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

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'
Expand All @@ -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))
}
6 changes: 4 additions & 2 deletions app/controllers/payment-links/post-edit.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 productsClient = require('../../services/clients/products.client.js')
const logger = require('../../utils/logger')(__filename)
const { keys } = require('@govuk-pay/pay-js-commons').logging
Expand All @@ -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 {
Expand All @@ -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}`))
}
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/payment-links/post-information.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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
Expand All @@ -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))
}
}
Loading

0 comments on commit 64a36ee

Please sign in to comment.