-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PP-13313: Validations for Worldpay credentials for a MOTO gateway acc…
…ount
- Loading branch information
1 parent
f6b71fd
commit cc92ca9
Showing
8 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...mplified-account/settings/worldpay-details/credentials/worldpay-credentials.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const { response } = require('@utils/response') | ||
const formatSimplifiedAccountPathsFor = require('../../../../../utils/simplified-account/format/format-simplified-account-paths-for') | ||
const paths = require('@root/paths') | ||
const { body, validationResult } = require('express-validator') | ||
const formatValidationErrors = require('@utils/simplified-account/format/format-validation-errors') | ||
|
||
function get (req, res) { | ||
return response(req, res, 'simplified-account/settings/worldpay-details/credentials', { | ||
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.worldpayDetails.index, | ||
req.service.externalId, req.account.type) | ||
}) | ||
} | ||
|
||
const worldpayCredentialsValidations = [ | ||
body('merchantCode').not().isEmpty().withMessage('Enter your merchant code').bail() | ||
.custom((value, { req }) => { | ||
const merchantCode = req.body.merchantCode | ||
if (req.account.allowMoto && !merchantCode.endsWith('MOTO') && !merchantCode.endsWith('MOTOGBP')) { | ||
throw new Error('Enter a MOTO merchant code. MOTO payments are enabled for the account') | ||
} | ||
}), | ||
body('username').not().isEmpty().withMessage('Enter your username'), | ||
body('password').not().isEmpty().withMessage('Enter your password') | ||
] | ||
|
||
async function post (req, res) { | ||
await Promise.all(worldpayCredentialsValidations.map(validation => validation.run(req))) | ||
const validationErrors = validationResult(req) | ||
if (!validationErrors.isEmpty()) { | ||
const formattedErrors = formatValidationErrors(validationErrors) | ||
return errorResponse(req, res, { | ||
summary: formattedErrors.errorSummary, | ||
formErrors: formattedErrors.formErrors | ||
}) | ||
} | ||
} | ||
|
||
const errorResponse = (req, res, errors) => { | ||
return response(req, res, 'simplified-account/settings/worldpay-details/credentials', { | ||
errors, | ||
merchantCode: req.body.merchantCode, | ||
username: req.body.username, | ||
password: req.body.password, | ||
backLink: formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.worldpayDetails.index, | ||
req.service.externalId, req.account.type) | ||
}) | ||
} | ||
|
||
module.exports = { | ||
get, | ||
post | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/views/simplified-account/settings/worldpay-details/credentials.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{% extends "../settings-layout.njk" %} | ||
|
||
{% block settingsPageTitle %} | ||
Worldpay details | ||
{% endblock %} | ||
|
||
{% block settingsContent %} | ||
|
||
{{ govukBackLink({ | ||
text: "Back", | ||
href: backLink | ||
}) }} | ||
|
||
{% if errors %} | ||
{{ govukErrorSummary({ | ||
titleText: "There is a problem", | ||
errorList: errors.summary | ||
}) }} | ||
{% endif %} | ||
|
||
<h1 class="govuk-heading-l">Your Worldpay credentials</h1> | ||
|
||
<p class="govuk-body govuk-!-margin-bottom-6 hint-and-body-width"> | ||
Go to your <a class="govuk-link" href="https://secure.worldpay.com/sso/public/auth/login.html">Worldpay account</a> | ||
to get the details you need to enter here or | ||
<a class="govuk-link" href="https://docs.payments.service.gov.uk/switching_to_live/set_up_a_live_worldpay_account/#connect-your-live-account-to-worldpay">read more in our documentation</a>. | ||
</p> | ||
|
||
<form id="credentials-form" method="post" novalidate> | ||
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}" /> | ||
|
||
{{ govukInput({ | ||
label: { | ||
text: 'Merchant code' | ||
}, | ||
id: 'merchantCode', | ||
name: 'merchantCode', | ||
classes: 'govuk-input--width-20', | ||
type: 'text', | ||
value: merchantCode, | ||
errorMessage: form.errors.merchantId and { | ||
text: form.errors.merchantId | ||
} | ||
}) | ||
}} | ||
|
||
{{ govukInput({ | ||
label: { | ||
text: 'Username' | ||
}, | ||
id: 'username', | ||
name: 'username', | ||
classes: 'govuk-input--width-20', | ||
type: 'text', | ||
value: username, | ||
errorMessage: form.errors.username and { | ||
text: form.errors.username | ||
}, | ||
autocomplete: 'off' | ||
}) | ||
}} | ||
|
||
{{ govukInput({ | ||
label: { | ||
text: 'Password' | ||
}, | ||
id: 'password', | ||
name: 'password', | ||
classes: "govuk-input--width-20", | ||
type: 'password', | ||
value: password, | ||
errorMessage: form.errors.password and { | ||
text: form.errors.password | ||
}, | ||
autocomplete: 'off' | ||
}) | ||
}} | ||
|
||
{{ | ||
govukButton({ | ||
text: 'Save credentials', | ||
attributes: { | ||
id: 'submitCredentials' | ||
} | ||
}) | ||
}} | ||
</form> | ||
{% endblock %} |