Skip to content

Commit

Permalink
PP-11594 - Allow enabling Apple Pay and Google Pay for Sandbox gatewa…
Browse files Browse the repository at this point in the history
…y accounts (#4153)

* PP-11594 Allow enabling Apple Pay and Google Pay for Sandbox gateway accounts

- Extend existing 'isDigitalWalletsSuported' test for 'Stripe' and 'Worldpay' accounts to include 'sandbox' accounts
- Add feature flag 'ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT' as part of test condition
- Remove ‘ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT’ feature toggle as wallet payments for stripe are now live

* PP-11594 Allow enabling Apple Pay and Google Pay for Sandbox gateway accounts

- Add unit tests for all sandbox feature flag states
- Amend tests referring to ‘ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT’ feature flag as wallet payments for Stripe are now live

* PP-11594 Allow enabling Apple Pay and Google Pay for Sandbox gateway accounts

Fix linting errors

* PP-11594 Allow enabling Apple Pay and Google Pay for Sandbox gateway accounts

Remove Pact tests that are no longer required
- Remove ‘apple pay toggle with unsupported payment provider request’ test
- Remove ‘google pay toggle with unsupported payment provider request' test
  • Loading branch information
JFSGDS authored Nov 3, 2023
1 parent c463f0f commit 9e34e96
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 67 deletions.
4 changes: 2 additions & 2 deletions app/utils/display-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ module.exports = function (req, data, template) {
convertedData.isTestGateway = _.get(convertedData, 'currentGatewayAccount.type') === 'test'
convertedData.isSandbox = paymentProvider === 'sandbox'
convertedData.isDigitalWalletSupported = paymentProvider === 'worldpay' ||
(paymentProvider === 'stripe' && process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT === 'true') ||
(paymentProvider === 'stripe' && convertedData.isTestGateway === true)
(paymentProvider === 'sandbox' && process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT === 'true') ||
paymentProvider === 'stripe'
convertedData.currentService = service
convertedData.isLive = req.isLive
convertedData.humanReadableEnvironment = convertedData.isLive ? 'Live' : 'Test'
Expand Down
64 changes: 52 additions & 12 deletions app/utils/display-converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const expect = chai.expect
describe('Display converter', function () {
afterEach(() => {
process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT = undefined
process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT = undefined
})

it('should add full_type to account if type is test', function () {
Expand Down Expand Up @@ -38,29 +39,37 @@ describe('Display converter', function () {
})
})

it('should return isDigitalWalletSupported=false for Stripe account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT is not set', () => {
const data = displayConverter({
it('should add full_type with value live to account if type is live', function () {
let data = displayConverter({
account: {
type: 'live',
payment_provider: 'stripe'
}
}, {}, {})
expect(data.isDigitalWalletSupported).to.equal(false)

expect(data.currentGatewayAccount).to.deep.equal({
type: 'live',
payment_provider: 'stripe',
full_type: 'live'
})
})

it('should return isDigitalWalletSupported=false for Stripe account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT is false', () => {
process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT = 'false'
const data = displayConverter({
it('should add full_type with value test to account if type is test', function () {
let data = displayConverter({
account: {
type: 'live',
type: 'test',
payment_provider: 'stripe'
}
}, {}, {})
expect(data.isDigitalWalletSupported).to.equal(false)

expect(data.currentGatewayAccount).to.deep.equal({
type: 'test',
payment_provider: 'stripe',
full_type: 'Stripe test'
})
})

it('should return isDigitalWalletSupported=true for Stripe account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT is true', () => {
process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT = 'true'
it('should return isDigitalWalletSupported=true for Stripe account when when gateway type is live', () => {
const data = displayConverter({
account: {
type: 'live',
Expand All @@ -70,8 +79,7 @@ describe('Display converter', function () {
expect(data.isDigitalWalletSupported).to.equal(true)
})

it('should return isDigitalWalletSupported=true for Stripe account when gateway type is test and ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT is false', () => {
process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT = 'false'
it('should return isDigitalWalletSupported=true for Stripe account when gateway type is test', () => {
const data = displayConverter({
account: {
type: 'test',
Expand All @@ -80,4 +88,36 @@ describe('Display converter', function () {
}, {}, {})
expect(data.isDigitalWalletSupported).to.equal(true)
})

it('should return isDigitalWalletSupported=false for sandbox account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT is not set', () => {
const data = displayConverter({
account: {
type: 'test',
payment_provider: 'sandbox'
}
}, {}, {})
expect(data.isDigitalWalletSupported).to.equal(false)
})

it('should return isDigitalWalletSupported=false for sandbox account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT is false', () => {
process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT = 'false'
const data = displayConverter({
account: {
type: 'test',
payment_provider: 'sandbox'
}
}, {}, {})
expect(data.isDigitalWalletSupported).to.equal(false)
})

it('should return isDigitalWalletSupported=true for sandbox account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT is true', () => {
process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT = 'true'
const data = displayConverter({
account: {
type: 'test',
payment_provider: 'sandbox'
}
}, {}, {})
expect(data.isDigitalWalletSupported).to.equal(true)
})
})
6 changes: 3 additions & 3 deletions test/cypress/integration/demo-payment/mock-cards-stripe.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ function setupYourPspStubs (opts = {}) {
gatewayAccountId,
gatewayAccountExternalId,
type: 'test',
paymentProvider: 'stripe',
paymentProvider: 'stripe'
})

const stripeAccountSetup = stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({
gatewayAccountId,
gatewayAccountId
})

const stubs = [
user,
gatewayAccountByExternalId,
stripeAccountSetup,
stripeAccountSetup
]

cy.task('setupStubs', stubs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const gatewayAccountFixtures = require('../../fixtures/gateway-account.fixtures'
// Constants
const ACCOUNTS_RESOURCE = '/v1/api/accounts'
let connectorClient
const expect = chai.expect
const existingGatewayAccountId = 666

// Global setup
Expand Down Expand Up @@ -61,28 +60,4 @@ describe('connector client - patch apple pay toggle (enabled) request', () => {
.notify(done)
})
})

describe('apple pay toggle with unsupported payment provider request', () => {
const applePayToggleUnsupportedPaymentProviderState = `User ${existingGatewayAccountId} exists in the database`

before(() => {
return provider.addInteraction(
new PactInteractionBuilder(`${ACCOUNTS_RESOURCE}/${existingGatewayAccountId}`)
.withUponReceiving('a valid patch apple pay toggle (enabled) request')
.withState(applePayToggleUnsupportedPaymentProviderState)
.withMethod('PATCH')
.withRequestBody(request)
.withStatusCode(400)
.build())
})

afterEach(() => provider.verify())

it('should respond bad request for unsupported payment provider', done => {
connectorClient.toggleApplePay(existingGatewayAccountId, true, null)
.should.be.rejected.then(response => {
expect(response.errorCode).to.equal(400)
}).should.notify(done)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const gatewayAccountFixtures = require('../../fixtures/gateway-account.fixtures'
// Constants
const ACCOUNTS_RESOURCE = '/v1/api/accounts'
let connectorClient
const expect = chai.expect
const existingGatewayAccountId = 666

// Global setup
Expand Down Expand Up @@ -61,28 +60,4 @@ describe('connector client - patch google pay toggle (enabled) request', () => {
.notify(done)
})
})

describe('google pay toggle with unsupported payment provider request', () => {
const googlePayToggleUnsupportedPaymentProviderState = `User ${existingGatewayAccountId} exists in the database`

before(() => {
return provider.addInteraction(
new PactInteractionBuilder(`${ACCOUNTS_RESOURCE}/${existingGatewayAccountId}`)
.withUponReceiving('a valid patch google pay toggle (enabled) request')
.withState(googlePayToggleUnsupportedPaymentProviderState)
.withMethod('PATCH')
.withRequestBody(request)
.withStatusCode(400)
.build())
})

afterEach(() => provider.verify())

it('should respond bad request for unsupported payment provider', done => {
connectorClient.toggleGooglePay(existingGatewayAccountId, true, null)
.should.be.rejected.then(response => {
expect(response.errorCode).to.equal(400)
}).should.notify(done)
})
})
})

0 comments on commit 9e34e96

Please sign in to comment.