Skip to content

Commit

Permalink
PP-5937: pass gateway account configuration into card model
Browse files Browse the repository at this point in the history
  • Loading branch information
sfount committed Dec 13, 2019
1 parent 6ec93b1 commit 882f2bb
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controllers/charge_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = {
},
create: async (req, res) => {
const charge = normalise.charge(req.chargeData, req.chargeId)
const cardModel = Card(req.chargeData.gateway_account.card_types, req.headers[CORRELATION_HEADER])
const cardModel = Card(req.chargeData.gateway_account.card_types, req.chargeData.gateway_account.block_prepaid_cards, req.headers[CORRELATION_HEADER])
const chargeOptions = {
email_collection_mode: charge.gatewayAccount.emailCollectionMode,
collect_billing_address: res.locals.service.collectBillingAddress
Expand Down Expand Up @@ -200,7 +200,7 @@ module.exports = {
const namespace = getNamespace(clsXrayConfig.nameSpaceName)
const clsSegment = namespace.get(clsXrayConfig.segmentKeyName)
AWSXRay.captureAsyncFunc('Card_checkCard', function (subSegment) {
Card(req.chargeData.gateway_account.card_types, req.headers[CORRELATION_HEADER])
Card(req.chargeData.gateway_account.card_types, req.chargeData.gateway_account.block_prepaid_cards, req.headers[CORRELATION_HEADER])
.checkCard(normalise.creditCard(req.body.cardNo), req.chargeData.language, subSegment, getLoggingFields(req))
.then(
card => {
Expand Down
3 changes: 2 additions & 1 deletion locales/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"nonNumeric": "Rhowch rif cerdyn dilys",
"unsupportedBrand": "Ni dderbynnir %s",
"unsupportedDebitCard": "Ni dderbynnir cardiau debyd %s",
"unsupportedCreditCard": "Ni dderbynnir cardiau credyd %s"
"unsupportedCreditCard": "Ni dderbynnir cardiau credyd %s",
"unsupportedPrepaidCard": "Ni dderbynnir cardiau rhagdaledig"
},
"cvc": {
"name": "god diogelwch cerdyn",
Expand Down
2 changes: 1 addition & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"unsupportedBrand": "%s is not supported",
"unsupportedDebitCard": "%s debit cards are not supported",
"unsupportedCreditCard": "%s credit cards are not supported",
"unsupportedPrepaidCard": "Prepaid card payments are not accepted"
"unsupportedPrepaidCard": "Prepaid cards are not accepted"
},
"cvc": {
"name": "card security code",
Expand Down
32 changes: 32 additions & 0 deletions test/cypress/integration/card/payment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,38 @@ describe('Standard card payment flow', () => {
})
})

describe('Prepaid card blocking', () => {
it('should block a prepaid card if gateway account is configured not allow them', () => {
const blockedPrepaidStubs = cardPaymentStubs.buildCreatePaymentChargeStubs(tokenId, chargeId, 'en', 42, {}, { blockPrepaidCards: true })
cy.task('setupStubs', blockedPrepaidStubs)

cy.visit(`/secure/${tokenId}`)
cy.location('pathname').should('eq', `/card_details/${chargeId}`)
cy.server()

cy.route('POST', `/check_card/${chargeId}`).as('checkCard')
cy.get('#card-no').type('4000160000000004')
cy.get('#card-no').blur()
cy.wait('@checkCard')
cy.get('#card-no-lbl').should('contain', 'Prepaid cards are not accepted')
})

it('should allow prepaid cards if gateway account is confgirued to allow', () => {
const blockedPrepaidStubs = cardPaymentStubs.buildCreatePaymentChargeStubs(tokenId, chargeId, 'en', 42, {}, { blockPrepaidCards: false })
cy.task('setupStubs', blockedPrepaidStubs)

cy.visit(`/secure/${tokenId}`)
cy.location('pathname').should('eq', `/card_details/${chargeId}`)
cy.server()

cy.route('POST', `/check_card/${chargeId}`).as('checkCard')
cy.get('#card-no').type('4000160000000004')
cy.get('#card-no').blur()
cy.wait('@checkCard')
cy.get('#card-no-lbl').should('not.contain', 'Prepaid cards are not accepted')
})
})

describe('Secure card payment page should show error', () => {
it('Should setup the payment and load the page', () => {
cy.task('setupStubs', createPaymentChargeStubsEnglish)
Expand Down
4 changes: 3 additions & 1 deletion test/cypress/utils/card-payment-stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const buildCreatePaymentChargeStubs = function buildCreatePaymentChargeStubs (to
language: language || 'en',
paymentProvider: providerOpts.paymentProvider,
requires3ds: providerOpts.requires3ds,
integrationVersion3ds: providerOpts.integrationVersion3ds
integrationVersion3ds: providerOpts.integrationVersion3ds,
blockPrepaidCards: providerOpts.blockPrepaidCards
}
},
{ name: 'cardIdValidCardDetails' },
{ name: 'connectorUpdateChargeStatus', opts: { chargeId } },

// @TODO(sfount) this should pass the service to be queried relative to the charge - right now it just returns a default service
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/payment_fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const buildGatewayAccount = function buildGatewayAccount (opts = {}) {
'corporate_prepaid_credit_card_surcharge_amount': 0,
'corporate_prepaid_debit_card_surcharge_amount': 0,
'email_collection_mode': opts.emailCollectionMode || 'MANDATORY',
'block_prepaid_cards': opts.blockPrepaidCards || false,
'live': false,
'payment_provider': opts.paymentProvider || 'sandbox',
'requires3ds': opts.requires3ds || false,
Expand Down Expand Up @@ -347,7 +348,7 @@ const fixtures = {
'type': 'C',
'label': 'VISA CREDIT',
'corporate': false,
'prepaid': 'UNKNOWN'
'prepaid': 'PREPAID'
}
return data
}
Expand Down
2 changes: 1 addition & 1 deletion test/models/card_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('card', function () {

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

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

it('should allow if gateway account `block_prepaid_cards` is set to false', async () => {
Expand Down

0 comments on commit 882f2bb

Please sign in to comment.