Skip to content

Commit

Permalink
PP-5937: block prepaid cards if gateway configuration is set
Browse files Browse the repository at this point in the history
* add error code key for prepaid cards (en)
* logic for blocking cards if the gateway account configuration is set
to block
  • Loading branch information
sfount committed Dec 12, 2019
1 parent ed8a493 commit 6ec93b1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/models/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const i18nConfig = require('../../config/i18n')

i18n.configure(i18nConfig)

const checkCard = function (cardNo, allowed, language, correlationId, subSegment, loggingFields = {}) {
const checkCard = function (cardNo, allowed, blockPrepaidCards, language, correlationId, subSegment, loggingFields = {}) {
return new Promise(function (resolve, reject) {
const startTime = new Date()
const data = { cardNumber: parseInt(cardNo) }
Expand Down Expand Up @@ -79,6 +79,10 @@ const checkCard = function (cardNo, allowed, language, correlationId, subSegment
}
}

if(blockPrepaidCards && card.prepaid === 'PREPAID') {
return reject(new Error(i18n.__('fieldErrors.fields.cardNo.unsupportedPrepaidCard', changeCase.titleCase(card.brand))))
}

resolve(card)
})
.catch(error => {
Expand Down Expand Up @@ -106,7 +110,7 @@ const normaliseCardType = function (cardType) {
return undefined
}

module.exports = function (allowedCards, correlationId) {
module.exports = function (allowedCards, blockPrepaidCards, correlationId) {
const withdrawalTypes = []
const allowed = _.clone(allowedCards)
correlationId = correlationId || ''
Expand All @@ -118,7 +122,7 @@ module.exports = function (allowedCards, correlationId) {
withdrawalTypes: withdrawalTypes,
allowed: _.clone(allowed),
checkCard: (cardNo, language, subSegment, loggingFields = {}) => {
return checkCard(cardNo, allowed, language, correlationId, subSegment, loggingFields)
return checkCard(cardNo, allowed, blockPrepaidCards, language, correlationId, subSegment, loggingFields)
}
}
}
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"nonNumeric": "Enter a valid card number",
"unsupportedBrand": "%s is not supported",
"unsupportedDebitCard": "%s debit cards are not supported",
"unsupportedCreditCard": "%s credit cards are not supported"
"unsupportedCreditCard": "%s credit cards are not supported",
"unsupportedPrepaidCard": "Prepaid card payments are not accepted"
},
"cvc": {
"name": "card security code",
Expand Down
33 changes: 33 additions & 0 deletions test/models/card_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const { unexpectedPromise } = require(path.join(__dirname, '/../test_helpers/tes
const proxyquire = require('proxyquire')
const AWSXRay = require('aws-xray-sdk')

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)

const { expect } = chai

// Local dependencies
require(path.join(__dirname, '/../test_helpers/html_assertions.js'))

Expand Down Expand Up @@ -97,6 +103,33 @@ describe('card', function () {
})
})

// public enum PrepaidStatus { PREPAID, NOT_PREPAID, UNKNOWN}
describe('a prepaid card', () => {
const gatewayAccountAllowCardsConfiguration = [{ brand: 'bar', label: 'bar', type: 'CREDIT', id: 'id-0' }]

beforeEach(function () {
nock.cleanAll()
nock(process.env.CARDID_HOST)
.post('/v1/api/card')
.reply(200, { brand: 'bar', label: 'bar', prepaid: 'PREPAID', corporate: true })
})

it('should reject if gateway account `block_prepaid_cards` is set to true', () => {
const gatewayAccountBlockedPrepaid = true

const scenario = CardModel(gatewayAccountAllowCardsConfiguration, gatewayAccountBlockedPrepaid).checkCard(1234)

return expect(scenario).to.be.rejectedWith('Prepaid card payments are not accepted')
})

it('should allow if gateway account `block_prepaid_cards` is set to false', async () => {
const gatewayAccountBlockedPrepaid = false
const card = await CardModel(gatewayAccountAllowCardsConfiguration, gatewayAccountBlockedPrepaid).checkCard(1234)

expect(card.brand).is.equal.toString('bar')
})
})

describe('a card that is not allowed debit withdrawal type', function () {
before(function () {
nock.cleanAll()
Expand Down

0 comments on commit 6ec93b1

Please sign in to comment.