Skip to content

Commit

Permalink
Merge pull request #4389 from alphagov/PP-12416_card-payment-non-moto
Browse files Browse the repository at this point in the history
PP-12416: Card Payment page
  • Loading branch information
nataliecarey authored Dec 20, 2024
2 parents ab6bc1f + e1b6eec commit 2e947b1
Show file tree
Hide file tree
Showing 21 changed files with 308 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GOV.UK Pay Self Service admin tool (Node.js)
Start the backend services locally in docker, using the Pay CLI.

```
pay local launch admin
pay local launch --cluster admin
```

Generate the environment variables file. This only needs to be done the first time you run locally.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { response } = require('@utils/response')
const formatSimplifiedAccountPathsFor = require('@utils/simplified-account/format/format-simplified-account-paths-for')
const paths = require('@root/paths')

const GB_COUNTRY_CODE = 'GB'

function get (req, res) {
const serviceExternalId = req.service.externalId
const accountType = req.account.type
const cardPaymentsPaths = paths.simplifiedAccount.settings.cardPayments

const billing = req.service.collectBillingAddress
const country = req.service.defaultBillingAddressCountry === GB_COUNTRY_CODE ? 'United Kingdom' : req.service.defaultBillingAddressCountry
const raw = req.account?.rawResponse
const applePay = raw?.allow_apple_pay
const googlePay = raw?.allow_google_pay

response(req, res, 'simplified-account/settings/card-payments/index', {
collectBillingAddressEnabled: billing,
collectBillingAddressLink: formatSimplifiedAccountPathsFor(cardPaymentsPaths.collectBillingAddress, serviceExternalId, accountType),
defaultBillingAddressCountry: country,
defaultBillingAddressCountryLink: formatSimplifiedAccountPathsFor(cardPaymentsPaths.defaultBillingAddressCountry, serviceExternalId, accountType),
applePayEnabled: applePay,
applePayAddressLink: formatSimplifiedAccountPathsFor(cardPaymentsPaths.applePay, serviceExternalId, accountType),
googlePayEnabled: googlePay,
googlePayAddressLink: formatSimplifiedAccountPathsFor(cardPaymentsPaths.googlePay, serviceExternalId, accountType)
})
}

module.exports = {
get
}
1 change: 1 addition & 0 deletions app/controllers/simplified-account/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports.stripeDetails = require('./stripe-details/stripe-details.controll
module.exports.teamMembers = require('./team-members/team-members.controller')
module.exports.organisationDetails = require('./organisation-details/organisation-details.controller')
module.exports.cardTypes = require('./card-types/card-types.controller')
module.exports.cardPayments = require('./card-payments/card-payments.controller')
module.exports.worldpayDetails = require('./worldpay-details/worldpay-details.controller')
module.exports.apiKeys = require('./api-keys/api-keys.controller')
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const postErrorResponse = (req, res, errors) => {
workTelephoneNumber,
workEmail
},
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.responsiblePerson.homeAddress, req.service.externalId, req.account.type),
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.responsiblePerson.homeAddress, req.service.externalId, req.account.type)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const postErrorResponse = (req, res, errors) => {
homeAddressCity,
homeAddressPostcode
},
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.responsiblePerson.index, req.service.externalId, req.account.type),
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.responsiblePerson.index, req.service.externalId, req.account.type)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const postErrorResponse = (req, res, errors) => {
errors,
name: { firstName, lastName },
dob: { dobDay, dobMonth, dobYear },
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.index, req.service.externalId, req.account.type),
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.index, req.service.externalId, req.account.type)
})
}

Expand Down
6 changes: 5 additions & 1 deletion app/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ module.exports = {
oneOffCustomerInitiated: '/settings/worldpay-details/one-off-customer-initiated'
},
cardPayments: {
index: '/settings/card-payments'
index: '/settings/card-payments',
collectBillingAddress: '/settings/card-payments/collect-billing-address',
defaultBillingAddressCountry: '/settings/card-payments/default-billing-address-country',
applePay: '/settings/card-payments/apple-pay',
googlePay: '/settings/card-payments/google-pay'
},
cardTypes: {
index: '/settings/card-types'
Expand Down
3 changes: 3 additions & 0 deletions app/simplified-account-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ simplifiedAccount.post(paths.simplifiedAccount.settings.organisationDetails.edit
simplifiedAccount.get(paths.simplifiedAccount.settings.cardTypes.index, permission('transactions:read'), serviceSettingsController.cardTypes.get)
simplifiedAccount.post(paths.simplifiedAccount.settings.cardTypes.index, permission('payment-types:update'), serviceSettingsController.cardTypes.post)

// card payments
simplifiedAccount.get(paths.simplifiedAccount.settings.cardPayments.index, permission('payment-types:read'), serviceSettingsController.cardPayments.get)

// worldpay details
simplifiedAccount.get(paths.simplifiedAccount.settings.worldpayDetails.index, enforcePaymentProviderType(WORLDPAY), permission('gateway-credentials:read'), serviceSettingsController.worldpayDetails.get)
simplifiedAccount.get(paths.simplifiedAccount.settings.worldpayDetails.oneOffCustomerInitiated, enforcePaymentProviderType(WORLDPAY), permission('gateway-credentials:update'), serviceSettingsController.worldpayDetails.worldpayCredentials.get)
Expand Down
8 changes: 8 additions & 0 deletions app/utils/bool-to-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const boolToText = (input, trueText, falseText) => {
return input === true ? trueText : falseText
}

module.exports = {
boolToText,
boolToOnOrOff: (input) => boolToText(input, 'On', 'Off')
}
15 changes: 6 additions & 9 deletions app/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ const logger = createLogger({
]
})

const nsDebugFormat = printf(({ level, message, timestamp, ...metadata }) => {
const metadataStr = Object.keys(metadata).length
? JSON.stringify(metadata, null, 2)
: ''

return metadataStr
? `${timestamp} [${level}]: ${message}\n${metadataStr}`
: `${timestamp} [${level}]: ${message}`
const nsDebugFormat = printf(({ level, message, timestamp }) => {
return `${timestamp} [${level}]: ${message}`
})

const nsDebugLogger = createLogger({
Expand All @@ -56,9 +50,12 @@ const nsDebugLogger = createLogger({
]
})

const nsDebug = process.env.NS_DEBUG === 'true'
const nsDebug = process.env.GOVUK_PAY__USE_BASIC_LOGGER === 'true'

module.exports = (loggerName) => {
if (process.env.GOVUK_PAY__USE_BASIC_LOGGER === 'true') {
return console
}
const childLogger = nsDebug
? nsDebugLogger.child({ logger_name: loggerName })
: logger.child({ logger_name: loggerName })
Expand Down
14 changes: 7 additions & 7 deletions app/views/settings/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
classes: 'govuk-!-width-one-half'
},
value: {
text: "On" if currentGatewayAccount.allow_apple_pay else "Off",
text: currentGatewayAccount.allow_apple_pay | boolToOnOrOff,
classes: 'govuk-!-width-one-quarter'
},
actions: {
Expand All @@ -47,7 +47,7 @@
classes: 'govuk-!-width-one-half'
},
value: {
text: "On" if currentGatewayAccount.allow_google_pay else "Off",
text: currentGatewayAccount.allow_google_pay | boolToOnOrOff,
classes: 'govuk-!-width-one-quarter'
},
actions: {
Expand All @@ -56,7 +56,7 @@
{
href: formatAccountPathsFor(routes.account.digitalWallet.googlePay, currentGatewayAccount.external_id),
classes: 'govuk-link--no-visited-state',
text: 'Change' if permissions.toggle_billing_address_update else 'View',
text: permissions.toggle_billing_address_update | boolToText('Change', 'View'),
visuallyHiddenText: 'Google Pay settings'
}
]
Expand All @@ -81,7 +81,7 @@
classes: 'govuk-!-width-one-half'
},
value: {
text: 'On' if requires3ds else 'Off',
text: requires3ds | boolToOnOrOff,
classes: 'govuk-!-width-one-quarter'
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@
classes: 'govuk-!-width-one-half'
},
value: {
text: 'On' if refundEmailEnabled else 'Off',
text: refundEmailEnabled | boolToOnOrOff,
classes: 'govuk-!-width-one-quarter'
},
actions: {
Expand Down Expand Up @@ -235,7 +235,7 @@
classes: 'govuk-!-width-one-half'
},
value: {
text: 'On' if motoMaskCardNumberInputEnabled else 'Off',
text: motoMaskCardNumberInputEnabled | boolToOnOrOff,
classes: 'govuk-!-width-one-quarter'
},
actions: {
Expand All @@ -256,7 +256,7 @@
classes: 'govuk-!-width-one-half'
},
value: {
text: 'On' if motoMaskSecurityCodeInputEnabled else 'Off',
text: motoMaskSecurityCodeInputEnabled | boolToOnOrOff,
classes: 'govuk-!-width-one-quarter'
},
actions: {
Expand Down
100 changes: 100 additions & 0 deletions app/views/simplified-account/settings/card-payments/index.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{% extends "../settings-layout.njk" %}

{% block settingsPageTitle %}
Card payments
{% endblock %}

{% block settingsContent %}
<h1 class="govuk-heading-l">Card payments</h1>
<p class="govuk-body">GOV.UK Pay uses 3D Secure for all card payments. 3D Secure (3DS) adds an extra layer of
authentication to user payments.</p>


{{ govukSummaryList({
classes: "govuk-!-margin-bottom-9",
rows: [
{
key: {
text: "Collect billing address"
},
value: {
text: collectBillingAddressEnabled | boolToOnOrOff
},
actions: {
items: [
{
href: collectBillingAddressLink,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "collect billing address"
}
]
}
},
{
key: {
text: "Default billing address country"
},
value: {
text: defaultBillingAddressCountry
},
actions: {
items: [
{
href: defaultBillingAddressCountryLink,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "default billing address country"
}
]
}
}
]
}) }}
<h3 class="govuk-heading-m">Digital wallets</h3>
<p class="govuk-body">Let users pay with Apple Pay and Google Pay.</p>


{{ govukSummaryList({
classes: "govuk-!-margin-bottom-9",
rows: [
{
key: {
text: "Apple Pay"
},
value: {
text: applePayEnabled | boolToOnOrOff
},
actions: {
items: [
{
href: applePayAddressLink,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "Apple Pay"
}
]
}
},
{
key: {
text: "Google Pay"
},
value: {
text: googlePayEnabled | boolToOnOrOff
},
actions: {
items: [
{
href: googlePayAddressLink,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "Google Pay"
}
]
}
}
]
}) }}

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
href: editEmailCollectionHref,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "Edit collect email addresses"
visuallyHiddenText: "collect email addresses"
} if isAdminUser else {}
]
}
Expand All @@ -49,7 +49,7 @@
href: editPaymentConfirmationEmailToggleHref,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "Payment confirmation emails settings"
visuallyHiddenText: "payment confirmation emails settings"
} if (isAdminUser and emailCollectionMode !== 'OFF') else {}
]
}
Expand All @@ -68,7 +68,7 @@
href: editRefundEmailToggleHref,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "Refund emails settings"
visuallyHiddenText: "refund emails settings"
} if (isAdminUser and emailCollectionMode !== 'OFF') else {}
]
}
Expand Down
4 changes: 2 additions & 2 deletions app/views/simplified-account/settings/service-name/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
href: manageEn,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "Edit English service name",
visuallyHiddenText: "English service name",
attributes: { 'data-cy': 'edit-english-name' }
}
]
Expand All @@ -48,7 +48,7 @@
href: manageCy,
text: "Change",
classes: "govuk-link--no-visited-state",
visuallyHiddenText: "Edit Welsh service name",
visuallyHiddenText: "Welsh service name",
attributes: { 'data-cy': 'edit-welsh-name' }
}
] if serviceNameCy else []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
href: changeResponsiblePersonLink,
text: "Change",
visuallyHiddenText: "change name",
visuallyHiddenText: "name",
classes: "govuk-link--no-visited-state"
}
]
Expand All @@ -40,7 +40,7 @@
{
href: changeResponsiblePersonLink,
text: "Change",
visuallyHiddenText: "change date of birth",
visuallyHiddenText: "date of birth",
classes: "govuk-link--no-visited-state"
}
]
Expand All @@ -58,7 +58,7 @@
{
href: changeHomeAddressLink,
text: "Change",
visuallyHiddenText: "change address",
visuallyHiddenText: "address",
classes: "govuk-link--no-visited-state"
}
]
Expand All @@ -76,7 +76,7 @@
{
href: changeContactDetailsLink,
text: "Change",
visuallyHiddenText: "change contact details",
visuallyHiddenText: "contact details",
classes: "govuk-link--no-visited-state"
}
]
Expand All @@ -94,7 +94,7 @@
{
href: changeContactDetailsLink,
text: "Change",
visuallyHiddenText: "change contact details",
visuallyHiddenText: "contact details",
classes: "govuk-link--no-visited-state"
}
]
Expand Down
Loading

0 comments on commit 2e947b1

Please sign in to comment.