Skip to content

Commit

Permalink
Merge pull request #2512 from alphagov/PP-7583-use-frontend-get-accou…
Browse files Browse the repository at this point in the history
…nt-by-external-id-endpoint

PP-7656 Use /v1/frontend/accounts/external-id endpoint
  • Loading branch information
stephencdaly authored Jan 19, 2021
2 parents 64a36ee + 49a8349 commit 3eb33a8
Show file tree
Hide file tree
Showing 22 changed files with 301 additions and 123 deletions.
11 changes: 1 addition & 10 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "package-lock.json",
"lines": null
},
"generated_at": "2021-01-18T10:18:13Z",
"generated_at": "2021-01-18T18:52:02Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -184,15 +184,6 @@
"type": "Secret Keyword"
}
],
"test/fixtures/gateway-account.fixtures.js": [
{
"hashed_secret": "cca5ec6518072e9005bd723123ec52b8e978a448",
"is_secret": false,
"is_verified": false,
"line_number": 10,
"type": "Hex High Entropy String"
}
],
"test/fixtures/invite.fixtures.js": [
{
"hashed_secret": "c2326bf719e924050321d3adb8d8d3a99723ee95",
Expand Down
4 changes: 2 additions & 2 deletions app/services/clients/connector.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const StripeAccount = require('../../models/StripeAccount.class')
const SERVICE_NAME = 'connector'
const ACCOUNTS_API_PATH = '/v1/api/accounts'
const ACCOUNT_API_PATH = ACCOUNTS_API_PATH + '/{accountId}'
const ACCOUNT_API_BY_EXTERNAL_ID_PATH = ACCOUNTS_API_PATH + '/external-id/{externalId}'
const CHARGES_API_PATH = ACCOUNT_API_PATH + '/charges'
const CHARGE_API_PATH = CHARGES_API_PATH + '/{chargeId}'
const CHARGE_REFUNDS_API_PATH = CHARGE_API_PATH + '/refunds'
Expand All @@ -19,6 +18,7 @@ const STRIPE_ACCOUNT_PATH = ACCOUNT_API_PATH + '/stripe-account'

const ACCOUNTS_FRONTEND_PATH = '/v1/frontend/accounts'
const ACCOUNT_FRONTEND_PATH = ACCOUNTS_FRONTEND_PATH + '/{accountId}'
const ACCOUNT_BY_EXTERNAL_ID_PATH = ACCOUNTS_FRONTEND_PATH + '/external-id/{externalId}'
const SERVICE_NAME_FRONTEND_PATH = ACCOUNT_FRONTEND_PATH + '/servicename'
const ACCEPTED_CARD_TYPES_FRONTEND_PATH = ACCOUNT_FRONTEND_PATH + '/card-types'
const ACCOUNT_NOTIFICATION_CREDENTIALS_PATH = '/v1/api/accounts' + '/{accountId}' + '/notification-credentials'
Expand All @@ -43,7 +43,7 @@ function _accountUrlFor (gatewayAccountId, url) {

/** @private */
function _accountByExternalIdUrlFor (gatewayAccountExternalId, url) {
return url + ACCOUNT_API_BY_EXTERNAL_ID_PATH.replace('{externalId}', gatewayAccountExternalId)
return url + ACCOUNT_BY_EXTERNAL_ID_PATH.replace('{externalId}', gatewayAccountExternalId)
}

/** @private */
Expand Down
4 changes: 2 additions & 2 deletions test/cypress/integration/settings/your-psp.cy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Your PSP settings page', () => {
}
const testNotificationCredentials = {
version: 1,
userName: 'someone',
username: 'someone',
password: 'email-me'
}
const testFlexCredentials = {
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('Your PSP settings page', () => {
cy.get('.value-merchant-id').should('contain', testCredentials.merchant_id)
cy.get('.value-username').should('contain', testCredentials.username)
cy.get('.value-password').should('contain', '●●●●●●●●')
cy.get('.value-notification-username').should('contain', testNotificationCredentials.userName)
cy.get('.value-notification-username').should('contain', testNotificationCredentials.username)
cy.get('.value-notification-password').should('contain', '●●●●●●●●')
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/cypress/stubs/gateway-account-stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function getGatewayAccountSuccess (opts) {

function getGatewayAccountByExternalIdSuccess (opts) {
const fixtureOpts = parseGatewayAccountOptions(opts)
const path = `/v1/api/accounts/external-id/${opts.gatewayAccountExternalId}`
const path = `/v1/frontend/accounts/external-id/${opts.gatewayAccountExternalId}`
return stubBuilder('GET', path, 200, {
response: gatewayAccountFixtures.validGatewayAccountResponse(fixtureOpts)
})
Expand Down
214 changes: 126 additions & 88 deletions test/fixtures/gateway-account.fixtures.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
'use strict'

function validCredentials (opts = {}) {
const credentials = {
merchant_id: opts.merchant_id || 'merchant-id',
username: opts.username || 'username'
}

if (opts.sha_in_passphrase) {
credentials.sha_in_passphrase = opts.sha_in_passphrase
}
if (opts.sha_out_passphrase) {
credentials.sha_out_passphrase = opts.sha_out_passphrase
}
return credentials
}

function validNotificationCredentials (opts = {}) {
return {
userName: opts.username || 'username',
}
}

function validWorldpay3dsFlexCredentials (opts = {}) {
return {
organisational_unit_id: opts.organisational_unit_id || '5bd9b55e4444761ac0af1c80',
issuer: opts.issuer || '5bd9e0e4444dce153428c940', // pragma: allowlist secret
exemption_engine_enabled: opts.exemption_engine_enabled || false
}
}

function validGatewayAccount (opts) {
const gatewayAccount = {
payment_provider: opts.payment_provider || 'sandbox',
gateway_account_id: opts.gateway_account_id || 31,
external_id: opts.external_id || 'a-valid-external-id',
allow_apple_pay: opts.allow_apple_pay || false,
allow_google_pay: opts.allow_google_pay || false,
service_name: opts.service_name || '8b9370c1a83c4d71a538a1691236acc2',
service_name: opts.service_name || 'A fabulous service',
type: opts.type || 'test',
analytics_id: opts.analytics_id || '8b02c7e542e74423aa9e6d0f0628fd58',
email_collection_mode: opts.email_collection_mode || 'MANDATORY',
email_notifications: opts.email_notifications || {
PAYMENT_CONFIRMED: {
Expand All @@ -24,7 +52,9 @@ function validGatewayAccount (opts) {
},
allow_moto: opts.allow_moto || false,
moto_mask_card_number_input: opts.moto_mask_card_number_input || false,
moto_mask_card_security_code_input: opts.moto_mask_card_security_code_input || false
moto_mask_card_security_code_input: opts.moto_mask_card_security_code_input || false,
requires3ds: opts.requires3ds || false,
integration_version_3ds: opts.integrationVersion3ds || 1
}

if (opts.description) {
Expand All @@ -33,101 +63,109 @@ function validGatewayAccount (opts) {
if (opts.analytics_id) {
gatewayAccount.analytics_id = opts.analytics_id
}
if (opts.toggle_3ds) {
gatewayAccount.toggle_3ds = opts.toggle_3ds
if (opts.credentials) {
gatewayAccount.credentials = validCredentials(opts.credentials)
}
if (opts.requires3ds) {
gatewayAccount.requires3ds = opts.requires3ds
if (opts.notificationCredentials) {
gatewayAccount.notificationCredentials = validNotificationCredentials(opts.notificationCredentials)
}
if (opts.requires3ds) {
gatewayAccount.integration_version_3ds = opts.integrationVersion3ds
if (opts.worldpay_3ds_flex) {
gatewayAccount.worldpay_3ds_flex = validWorldpay3dsFlexCredentials(opts.worldpay_3ds_flex)
}
if (opts.credentials) {
gatewayAccount.credentials = opts.credentials

return gatewayAccount
}

function validGatewayAccountPatchRequest (opts = {}) {
return {
op: 'replace',
path: opts.path,
value: opts.value
}
}

if (opts.notificationCredentials) {
gatewayAccount.notificationCredentials = opts.notificationCredentials
function validGatewayAccountEmailRefundToggleRequest (enabled = true) {
return {
op: 'replace',
path: '/refund/enabled',
value: enabled
}
}

if (opts.worldpay_3ds_flex) {
gatewayAccount.worldpay_3ds_flex = opts.worldpay_3ds_flex
function validGatewayAccountEmailConfirmationToggleRequest (enabled = true) {
return {
op: 'replace',
path: '/confirmation/enabled',
value: enabled
}
}

return gatewayAccount
function validGatewayAccountEmailCollectionModeRequest (collectionMode = 'MANDATORY') {
return {
op: 'replace',
path: 'email_collection_mode',
value: collectionMode
}
}

module.exports = {
validGatewayAccountPatchRequest: (opts = {}) => {
return {
op: 'replace',
path: opts.path,
value: opts.value
}
},
validGatewayAccountEmailRefundToggleRequest: (enabled = true) => {
return {
op: 'replace',
path: '/refund/enabled',
value: enabled
}
},
validGatewayAccountEmailConfirmationToggleRequest: (enabled = true) => {
return {
op: 'replace',
path: '/confirmation/enabled',
value: enabled
}
},
validGatewayAccountEmailCollectionModeRequest: (collectionMode = 'MANDATORY') => {
return {
op: 'replace',
path: 'email_collection_mode',
value: collectionMode
}
},
validGatewayAccountTokensResponse: (opts = {}) => {
return {
tokens:
[{
issued_date: opts.issued_date || '03 Sep 2018 - 10:05',
last_used: opts.last_used || null,
token_link: opts.token_link || '32fa3cdd-23c8-4602-a415-b48ede66b5e4',
description: opts.description || 'Created from command line',
token_type: opts.token_type || 'CARD',
created_by: opts.created_by || 'System generated'
}]
}
},
validGatewayAccountResponse: (opts = {}) => {
return validGatewayAccount(opts)
},
validGatewayAccountsResponse: (opts = {}) => {
const accounts = opts.accounts.map(validGatewayAccount)
return {
accounts: accounts
}
},
validDirectDebitGatewayAccountResponse: (opts = {}) => {
return {
gateway_account_id: opts.gateway_account_id || 73,
gateway_account_external_id: opts.gateway_account_external_id || 'DIRECT_DEBIT:' + 'a9c797ab271448bdba21359e15672076',
payment_provider: opts.payment_provider || 'sandbox',
type: opts.type || 'test',
analytics_id: opts.analytics_id || 'd82dae5bcb024828bb686574a932b5a5',
is_connected: opts.is_connected || false
}
},
validCreateGatewayAccountRequest: (opts = {}) => {
const data = {
payment_provider: opts.payment_provider || 'sandbox',
service_name: opts.service_name || 'This is an account for the GOV.UK Pay team',
type: opts.type || 'test'
}

if (opts.analytics_id) {
data.analytics_id = opts.analytics_id
}
return data
function validGatewayAccountTokensResponse (opts = {}) {
return {
tokens:
[{
issued_date: opts.issued_date || '03 Sep 2018 - 10:05',
last_used: opts.last_used || null,
token_link: opts.token_link || '32fa3cdd-23c8-4602-a415-b48ede66b5e4',
description: opts.description || 'Created from command line',
token_type: opts.token_type || 'CARD',
created_by: opts.created_by || 'System generated'
}]
}
}

function validGatewayAccountResponse (opts = {}) {
return validGatewayAccount(opts)
}

function validGatewayAccountsResponse (opts = {}) {
const accounts = opts.accounts.map(validGatewayAccount)
return {
accounts: accounts
}
}

function validDirectDebitGatewayAccountResponse (opts = {}) {
return {
gateway_account_id: opts.gateway_account_id || 73,
gateway_account_external_id: opts.gateway_account_external_id || 'DIRECT_DEBIT:' + 'a9c797ab271448bdba21359e15672076',
payment_provider: opts.payment_provider || 'sandbox',
type: opts.type || 'test',
analytics_id: opts.analytics_id || 'd82dae5bcb024828bb686574a932b5a5',
is_connected: opts.is_connected || false
}
}

function validCreateGatewayAccountRequest (opts = {}) {
const data = {
payment_provider: opts.payment_provider || 'sandbox',
service_name: opts.service_name || 'This is an account for the GOV.UK Pay team',
type: opts.type || 'test'
}

if (opts.analytics_id) {
data.analytics_id = opts.analytics_id
}
return data
}


module.exports = {
validGatewayAccountPatchRequest,
validGatewayAccountEmailRefundToggleRequest,
validGatewayAccountEmailConfirmationToggleRequest,
validGatewayAccountEmailCollectionModeRequest,
validGatewayAccountTokensResponse,
validGatewayAccountResponse,
validGatewayAccountsResponse,
validDirectDebitGatewayAccountResponse,
validCreateGatewayAccountRequest
}
4 changes: 2 additions & 2 deletions test/integration/credentials.ft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ describe('Credentials endpoints', () => {
'username': 'a-username',
'merchant_id': 'a-merchant-id'
},
'notification_credentials': { username: 'a-notification-username' }
'notificationCredentials': { username: 'a-notification-username' }
})

buildGetRequest(paths.notificationCredentials.index, app)
.expect(200)
.expect(response => {
expect(response.body.currentGatewayAccount.notification_credentials).to.deep.equal({ username: 'a-notification-username' })
expect(response.body.currentGatewayAccount.notificationCredentials).to.deep.equal({ username: 'a-notification-username' })
})
.end(done)
})
Expand Down
2 changes: 1 addition & 1 deletion test/integration/payment-types/payment-types.it.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const gatewayAccountId = '15486734'
const gatewayAccountExternalId = 'account-external-id'
const connectorMock = nock(process.env.CONNECTOR_URL)
const CONNECTOR_ACCOUNT_CARD_TYPES_PATH = `/v1/frontend/accounts/${gatewayAccountId}/card-types`
const CONNECTOR_ACCOUNT_BY_EXTERNAL_ID = `/v1/api/accounts/external-id/${gatewayAccountExternalId}`
const CONNECTOR_ACCOUNT_BY_EXTERNAL_ID = `/v1/frontend/accounts/external-id/${gatewayAccountExternalId}`

let app

Expand Down
Loading

0 comments on commit 3eb33a8

Please sign in to comment.