Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
})