Skip to content

Commit

Permalink
Merge pull request #2508 from alphagov/PP-7583-url-structure-demo-pay…
Browse files Browse the repository at this point in the history
…ments

PP-7583 URL Re-structure > Demo payments
  • Loading branch information
iqbalgds authored Jan 18, 2021
2 parents a076fd9 + 2b60797 commit 6c2a362
Show file tree
Hide file tree
Showing 25 changed files with 263 additions and 193 deletions.
2 changes: 1 addition & 1 deletion app/controllers/make-a-demo-payment/edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const lodash = require('lodash')

const { response } = require('../../utils/response.js')
const { editDescription } = require('../../paths').prototyping.demoPayment
const { editDescription } = require('../../paths').account.prototyping.demoPayment

module.exports = (req, res) => {
const pageData = lodash.get(req, 'session.pageData.makeADemoPayment', {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ const paths = require('../../paths')
const productsClient = require('../../services/clients/products.client.js')
const productTypes = require('../../utils/product-types')
const publicAuthClient = require('../../services/clients/public-auth.client')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')

module.exports = async function makeDemoPayment (req, res) {
const gatewayAccountId = req.account.gateway_account_id
const { paymentAmount, paymentDescription } = lodash.get(req, 'session.pageData.makeADemoPayment', {})

if (!paymentAmount || !paymentDescription) {
return res.redirect(paths.prototyping.demoPayment.index)
return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.index, req.account.external_id))
}

try {
Expand All @@ -40,6 +41,6 @@ module.exports = async function makeDemoPayment (req, res) {
} catch (error) {
logger.error(`[requestId=${req.correlationId}] Making a demo payment failed - ${error.message}`)
req.flash('genericError', 'Something went wrong. Please try again.')
res.redirect(paths.prototyping.demoPayment.index)
res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.index, req.account.external_id))
}
}
5 changes: 3 additions & 2 deletions app/controllers/make-a-demo-payment/index.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { response } = require('../../utils/response.js')
const paths = require('../../paths')
const { isCurrency, isAboveMaxAmount } = require('../../browsered/field-validation-checks')
const { safeConvertPoundsStringToPence } = require('../../utils/currency-formatter')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')

const DEFAULTS = {
paymentDescription: 'An example payment description',
Expand All @@ -20,13 +21,13 @@ module.exports = (req, res) => {
if (!paymentAmount || isCurrency(paymentAmount)) {
lodash.set(req, 'session.pageData.makeADemoPayment.paymentAmount', paymentAmount)
req.flash('genericError', isCurrency(paymentAmount))
return res.redirect(paths.prototyping.demoPayment.editAmount)
return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.editAmount, req.account.external_id))
}
const isAboveMaxAmountError = isAboveMaxAmount(paymentAmount)
if (isAboveMaxAmountError) {
lodash.set(req, 'session.pageData.makeADemoPayment.paymentAmount', paymentAmount)
req.flash('genericError', isAboveMaxAmountError)
return res.redirect(paths.prototyping.demoPayment.editAmount)
return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.editAmount, req.account.external_id))
}

if (req.body['payment-amount']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const lodash = require('lodash')

const { response } = require('../../utils/response.js')
const paths = require('../../paths')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')

module.exports = (req, res) => {
const { paymentAmount, paymentDescription } = lodash.get(req, 'session.pageData.makeADemoPayment', {})

if (!paymentAmount || !paymentDescription) {
return res.redirect(paths.prototyping.demoPayment.index)
return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.index, req.account.external_id))
}

response(req, res, 'dashboard/demo-payment/mock-card-details', {})
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/test-with-your-users/disable.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
const logger = require('../../utils/logger')(__filename)
const paths = require('../../paths')
const productsClient = require('../../services/clients/products.client.js')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')

module.exports = (req, res) => {
const gatewayAccountId = req.account.gateway_account_id
productsClient.product.disable(gatewayAccountId, req.params.productExternalId)
.then(() => {
req.flash('generic', 'Prototype link deleted')
res.redirect(paths.prototyping.demoService.links)
res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.links, 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 prototype link. Please try again or contact support.')
res.redirect(paths.prototyping.demoService.links)
res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.links, req.account.external_id))
})
}
7 changes: 4 additions & 3 deletions app/controllers/test-with-your-users/links.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ const { response } = require('../../utils/response.js')
const paths = require('../../paths')
const productsClient = require('../../services/clients/products.client.js')
const { renderErrorView } = require('../../utils/response.js')
const formatAccountPathsFor = require('../../../app/utils/format-account-paths-for')

module.exports = (req, res) => {
const params = {
productsTab: true,
createPage: paths.prototyping.demoService.create,
indexPage: paths.prototyping.demoService.index,
linksPage: paths.prototyping.demoService.links
createPage: formatAccountPathsFor(paths.account.prototyping.demoService.create, req.account.external_id),
indexPage: formatAccountPathsFor(paths.account.prototyping.demoService.index, req.account.external_id),
linksPage: formatAccountPathsFor(paths.account.prototyping.demoService.links, req.account.external_id)
}

productsClient.product.getByGatewayAccountId(req.account.gateway_account_id)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/test-with-your-users/submit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const productTypes = require('../../utils/product-types')
const publicAuthClient = require('../../services/clients/public-auth.client')
const { isCurrency, isHttps, isAboveMaxAmount } = require('../../browsered/field-validation-checks')
const { penceToPounds, safeConvertPoundsStringToPence } = require('../../utils/currency-formatter')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')

module.exports = async (req, res) => {
const gatewayAccountId = req.account.gateway_account_id
Expand All @@ -29,7 +30,7 @@ module.exports = async (req, res) => {
}

if (lodash.get(req, 'session.flash.genericError.length')) {
return res.redirect(paths.prototyping.demoService.create)
return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.create, req.account.external_id))
}

try {
Expand Down Expand Up @@ -59,6 +60,6 @@ module.exports = async (req, res) => {
} catch (err) {
logger.error(`[requestId=${req.correlationId}] Create product failed - ${err.message}`)
req.flash('genericError', 'Something went wrong. Please try again or contact support.')
return res.redirect(paths.prototyping.demoService.create)
return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.create, req.account.external_id))
}
}
32 changes: 16 additions & 16 deletions app/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ module.exports = {
paymentTypes: {
index: '/payment-types'
},
prototyping: {
demoService: {
index: '/test-with-your-users',
links: '/test-with-your-users/links',
create: '/test-with-your-users/create',
confirm: '/test-with-your-users/confirm',
disable: '/test-with-your-users/links/disable/:productExternalId'
},
demoPayment: {
index: '/make-a-demo-payment',
editDescription: '/make-a-demo-payment/edit-description',
editAmount: '/make-a-demo-payment/edit-amount',
mockCardDetails: '/make-a-demo-payment/mock-card-numbers',
goToPaymentScreens: '/make-a-demo-payment/go-to-payment'
}
},
settings: {
index: '/settings'
},
Expand Down Expand Up @@ -145,22 +161,6 @@ module.exports = {
staticPaths: {
naxsiError: '/request-denied'
},
prototyping: {
demoService: {
index: '/test-with-your-users',
links: '/test-with-your-users/links',
create: '/test-with-your-users/create',
confirm: '/test-with-your-users/confirm',
disable: '/test-with-your-users/links/disable/:productExternalId'
},
demoPayment: {
index: '/make-a-demo-payment',
editDescription: '/make-a-demo-payment/edit-description',
editAmount: '/make-a-demo-payment/edit-amount',
mockCardDetails: '/make-a-demo-payment/mock-card-numbers',
goToPaymentScreens: '/make-a-demo-payment/go-to-payment'
}
},
paymentLinks: {
start: '/create-payment-link',
information: '/create-payment-link/information',
Expand Down
18 changes: 2 additions & 16 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, prototyping, paymentLinks,
notificationCredentials, paymentLinks,
requestToGoLive, policyPages, stripeSetup, stripe,
yourPsp, allServiceTransactions, payouts
} = paths
Expand All @@ -97,6 +97,7 @@ const {
digitalWallet,
emailNotifications,
paymentTypes,
prototyping,
settings,
toggle3ds,
toggleBillingAddress,
Expand Down Expand Up @@ -185,8 +186,6 @@ module.exports.bind = function (app) {
...lodash.values(serviceSwitcher),
...lodash.values(teamMembers),
...lodash.values(merchantDetails),
...lodash.values(prototyping.demoPayment),
...lodash.values(prototyping.demoService),
...lodash.values(paymentLinks),
...lodash.values(user.profile),
...lodash.values(requestToGoLive),
Expand Down Expand Up @@ -357,19 +356,6 @@ module.exports.bind = function (app) {
account.post(toggleBillingAddress.index, permission('toggle-billing-address:update'), toggleBillingAddressController.postIndex)

// Prototype links
app.get(prototyping.demoService.index, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.index)
app.get(prototyping.demoService.links, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.links)
app.get(prototyping.demoService.create, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.create)
app.post(prototyping.demoService.confirm, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.submit)
app.get(prototyping.demoService.disable, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.disable)

app.get(prototyping.demoPayment.index, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.index)
app.post(prototyping.demoPayment.index, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.index)
app.get(prototyping.demoPayment.editDescription, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.edit)
app.get(prototyping.demoPayment.editAmount, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.edit)
app.get(prototyping.demoPayment.mockCardDetails, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.mockCardDetails)
app.post(prototyping.demoPayment.goToPaymentScreens, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.goToPayment)

account.get(prototyping.demoService.index, permission('transactions:read'), restrictToSandbox, testWithYourUsersController.index)
account.get(prototyping.demoService.links, permission('transactions:read'), restrictToSandbox, testWithYourUsersController.links)
account.get(prototyping.demoService.create, permission('transactions:read'), restrictToSandbox, testWithYourUsersController.create)
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/_links.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="flex-grid--row">
{% if links.demoPayment in linksToDisplay %}
<article class="{{columnClass}} links__box" id="demo-payment-link">
<a href="{{routes.prototyping.demoPayment.index}}">
<a href="{{formatAccountPathsFor(routes.account.prototyping.demoPayment.index, currentGatewayAccount.external_id)}}">
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">Make a demo payment</h2>
<p class="govuk-body govuk-!-margin-bottom-0">Try the payment experience as a user. Then view the completed payment as an administrator on GOV.UK&nbsp;Pay.</p>
</a>
Expand All @@ -18,7 +18,7 @@

{% if links.testPaymentLink in linksToDisplay %}
<article class="{{columnClass}} links__box" id="test-payment-link-link">
<a href="{{routes.prototyping.demoService.index}}">
<a href="{{formatAccountPathsFor(routes.account.prototyping.demoService.index, currentGatewayAccount.external_id)}}">
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">Test with your users</h2>
<p class="govuk-body govuk-!-margin-bottom-0">Create a reusable link to integrate your service prototype with GOV.UK&nbsp;Pay and test with users.</p>
</a>
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/demo-payment/edit-amount.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
{{
govukBackLink({
text: "Back to make a demo payment",
href: routes.prototyping.demoPayment.index
href: formatAccountPathsFor(routes.account.prototyping.demoPayment.index, currentGatewayAccount.external_id)
})
}}
{% endblock %}

{% block mainContent %}
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Edit payment amount</h1>
<form method="post" action="{{routes.prototyping.demoPayment.index}}" data-validate="true">
<form method="post" action="{{formatAccountPathsFor(routes.account.prototyping.demoPayment.index, currentGatewayAccount.external_id)}}" data-validate="true">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>

<div class="currency-input govuk-form-group">
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/demo-payment/edit-description.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
{{
govukBackLink({
text: "Back to make a demo payment",
href: routes.prototyping.demoPayment.index
href: formatAccountPathsFor(routes.account.prototyping.demoPayment.index, currentGatewayAccount.external_id)
})
}}
{% endblock %}

{% block mainContent %}
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Edit payment description</h1>
<form method="post" action="{{routes.prototyping.demoPayment.index}}" data-validate="true">
<form method="post" action="{{formatAccountPathsFor(routes.account.prototyping.demoPayment.index, currentGatewayAccount.external_id)}}" data-validate="true">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>
{{
govukTextarea({
Expand Down
6 changes: 3 additions & 3 deletions app/views/dashboard/demo-payment/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Make a demo payment - {{currentService.name}} {{currentGatewayAccount.full_type}
<div class="govuk-body govuk-!-margin-0" id="payment-description">
{{ paymentDescription | striptags(true) | escape | nl2br }}
<span class="demo-payment-settings__edit-link">
<a class="govuk-link govuk-link--no-visited-state" href="{{routes.prototyping.demoPayment.editDescription}}">
<a class="govuk-link govuk-link--no-visited-state" href="{{formatAccountPathsFor(routes.account.prototyping.demoPayment.editDescription, currentGatewayAccount.external_id)}}">
Edit <span class="govuk-visually-hidden">description</span>
</a>
</span>
Expand All @@ -44,7 +44,7 @@ Make a demo payment - {{currentService.name}} {{currentGatewayAccount.full_type}
<div class="govuk-body govuk-!-margin-0" id="payment-amount">
{{ paymentAmount | penceToPoundsWithCurrency }}
<span class="demo-payment-settings__edit-link">
<a class="govuk-link govuk-link--no-visited-state" href="{{routes.prototyping.demoPayment.editAmount}}">
<a class="govuk-link govuk-link--no-visited-state" href="{{formatAccountPathsFor(routes.account.prototyping.demoPayment.editAmount, currentGatewayAccount.external_id)}}">
Edit <span class="govuk-visually-hidden">amount</span>
</a>
</span>
Expand All @@ -57,7 +57,7 @@ Make a demo payment - {{currentService.name}} {{currentGatewayAccount.full_type}
{{
govukButton({
text: "Continue",
href: routes.prototyping.demoPayment.mockCardDetails,
href: formatAccountPathsFor(routes.account.prototyping.demoPayment.mockCardDetails, currentGatewayAccount.external_id),
attributes: {
id: "prototyping__continue"
}
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/demo-payment/mock-card-details.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{
govukBackLink({
text: "Back to make a demo payment",
href: routes.prototyping.demoPayment.index
href: formatAccountPathsFor(routes.account.prototyping.demoPayment.index, currentGatewayAccount.external_id)
})
}}
{% endblock %}
Expand All @@ -28,7 +28,7 @@
<p class="govuk-body">You can enter any valid value for the other details. For example, it doesn’t matter what expiry date you enter, but it must be in the future.</p>
<p class="govuk-body">You can also use other card types and see errors. <a class="govuk-link" href="https://docs.payments.service.gov.uk/testing_govuk_pay/#mock-card-numbers-for-testing-purposes">See more card types in our documentation</a>.</p>

<form method="post" action="{{routes.prototyping.demoPayment.goToPaymentScreens}}" >
<form method="post" action="{{formatAccountPathsFor(routes.account.prototyping.demoPayment.goToPaymentScreens, currentGatewayAccount.external_id)}}" >
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>
{{
govukButton({
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/demo-service/confirm.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{
govukBackLink({
text: "Back to prototype links",
href: routes.prototyping.demoService.links,
href: formatAccountPathsFor(routes.account.prototyping.demoService.links, currentGatewayAccount.external_id),
attributes: {
id: "prototyping__links-link-back"
}
Expand Down Expand Up @@ -37,7 +37,7 @@
{{
govukButton({
text: "See prototype links",
href: routes.prototyping.demoService.links,
href: formatAccountPathsFor(routes.account.prototyping.demoService.links, currentGatewayAccount.external_id),
attributes: {
id: "see-prototype-links"
}
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/demo-service/create.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
{{
govukBackLink({
text: "Back to prototype links",
href: routes.prototyping.demoService.links
href: formatAccountPathsFor(routes.account.prototyping.demoService.links, currentGatewayAccount.external_id)
})
}}
{% endblock %}

{% block mainContent %}
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Create a prototype link</h1>
<form method="post" action="{{routes.prototyping.demoService.confirm}}" data-validate>
<form method="post" action="{{formatAccountPathsFor(routes.account.prototyping.demoService.confirm, currentGatewayAccount.external_id)}}" data-validate>
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>

{{
Expand Down
6 changes: 3 additions & 3 deletions app/views/dashboard/demo-service/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{{
govukButton({
text: "Create prototype link",
href: routes.prototyping.demoService.create,
href: formatAccountPathsFor(routes.account.prototyping.demoService.create, currentGatewayAccount.external_id),
attributes: {
id: "prototyping__links-button-create"
}
Expand All @@ -32,13 +32,13 @@
<ul class="govuk-tabs__list">
<li class="govuk-tabs__list-item">
<a class="govuk-tabs__tab {% if not productsTab %}
govuk-tabs__tab--selected{% endif %}" href="{{routes.prototyping.demoService.index}}">
govuk-tabs__tab--selected{% endif %}" href="{{formatAccountPathsFor(routes.account.prototyping.demoService.index, currentGatewayAccount.external_id)}}">
Mock card numbers
</a>
</li>
<li class="govuk-tabs__list-item">
<a class="govuk-tabs__tab {% if productsTab %}
govuk-tabs__tab--selected{% endif %}" href="{{routes.prototyping.demoService.links}}">
govuk-tabs__tab--selected{% endif %}" href="{{formatAccountPathsFor(routes.account.prototyping.demoService.links, currentGatewayAccount.external_id)}}">
Prototype links
</a>
</li>
Expand Down
Loading

0 comments on commit 6c2a362

Please sign in to comment.