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-11578 Support Google Pay for sandbox #3762

Merged
merged 2 commits into from
Nov 10, 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
6 changes: 6 additions & 0 deletions app/assets/javascripts/browsered/web-payments/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ const getGooglePaymentsConfiguration = (paymentProvider) => {
...(paymentProvider === 'worldpay' && {
gateway: 'worldpay',
gatewayMerchantId: window.googlePayGatewayMerchantID
}),
// In order to initiate a Google Pay payment in the Google Pay test environment without going to a real payment
// provider, the workaround is to specify ‘worldpay’ without a merchant id.
...(paymentProvider === 'sandbox' && {
gateway: 'worldpay',
gatewayMerchantId: ''
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/utils/wallet-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function googlePayEnabled (charge) {
const googlePayEnabledForStripe = (process.env.STRIPE_GOOGLE_PAY_ENABLED || 'true') === 'true'

const globallyEnabledForProvider = (charge.paymentProvider === 'worldpay' && googlePayEnabledForWorldpay) ||
(charge.paymentProvider === 'stripe' && googlePayEnabledForStripe)
(charge.paymentProvider === 'stripe' && googlePayEnabledForStripe) ||
charge.paymentProvider === 'sandbox'

return (globallyEnabledForProvider || shouldOverrideGlobalWalletFlagForGatewayAccount(charge)) &&
charge.gatewayAccount.allowGooglePay
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wallet-payment.fixtures.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const successfulLastDigitsCardNumber = '4242'

const fixtures = {
worldpayGoogleAuthRequestDetails: (ops = {}) => {
worldpayOrSandboxGoogleAuthRequestDetails: (ops = {}) => {
const data = {
payment_info: {
last_digits_card_number: ops.lastDigitsCardNumber !== undefined ? ops.lastDigitsCardNumber : successfulLastDigitsCardNumber,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict'

const path = require('path')
const { Pact } = require('@pact-foundation/pact')
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')

const connectorClient = require('../../../app/services/clients/connector.client')
const fixtures = require('../../fixtures/wallet-payment.fixtures')
const { PactInteractionBuilder } = require('../../test-helpers/pact/pact-interaction-builder')
const { pactify } = require('../../test-helpers/pact/pact-base')()

const expect = chai.expect
chai.use(chaiAsPromised)

const TEST_CHARGE_ID = 'testChargeId'
const GOOGLE_AUTH_PATH = `/v1/frontend/charges/${TEST_CHARGE_ID}/wallets/google`
const PORT = Math.floor(Math.random() * 48127) + 1024
const BASEURL = `http://127.0.0.1:${PORT}`

describe('Connector Client - Google Pay authorisation API - Sandbox payment', function () {
const provider = new Pact({
consumer: 'frontend',
provider: 'connector',
port: PORT,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
pactfileWriteMode: 'merge'
})

before(() => provider.setup())
after(() => provider.finalize())

describe('Authorise Sandbox Google Pay payment', function () {
describe('authorisation success', function () {
const successfulGoogleAuthRequest = fixtures.worldpayOrSandboxGoogleAuthRequestDetails()
const authorisationSuccessResponse = fixtures.webPaymentSuccessResponse()
before(() => {
const builder = new PactInteractionBuilder(GOOGLE_AUTH_PATH)
.withRequestBody(successfulGoogleAuthRequest)
.withMethod('POST')
.withState('a sandbox account exists with a charge with id testChargeId that is in state ENTERING_CARD_DETAILS.')
.withUponReceiving('a valid sandbox google pay auth request which should be authorised')
.withResponseBody(pactify(authorisationSuccessResponse))
.withStatusCode(200)
.build()
return provider.addInteraction(builder)
})

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

it('should return authorisation success', function (done) {
const payload = successfulGoogleAuthRequest
connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({
chargeId: TEST_CHARGE_ID,
wallet: 'google',
payload: payload
}).then(res => {
expect(res.body.status).to.be.equal('AUTHORISATION SUCCESS')
done()
}).catch((err) => done(new Error('should not be hit: ' + JSON.stringify(err))))
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const { pactify } = require('../../test-helpers/pact/pact-base')()
const expect = chai.expect
chai.use(chaiAsPromised)

describe('connectors client - stripe google authentication API', function () {
describe('Connectors Client - Google Pay authorisation API - Stripe payment', function () {
const provider = new Pact({
consumer: 'frontend',
provider: 'connector',
Expand All @@ -43,7 +43,7 @@ describe('connectors client - stripe google authentication API', function () {
before(() => provider.setup())
after(() => provider.finalize())

describe('Authenticate Stripe google payment', function () {
describe('Authorise Stripe Google Pay payment', function () {
describe('authorisation success', function () {
const successfulGoogleAuthRequest = fixtures.stripeGoogleAuthRequestDetails()
const authorisationSuccessResponse = fixtures.webPaymentSuccessResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ chai.use(chaiAsPromised)

const GOOGLE_DDC_RESULT = 'some long opaque string that’s a device data collection result'

describe('connectors client - worldpay google authentication API', function () {
describe('Connector Client - Google Pay authorisation API - Worldpay payment', function () {
const provider = new Pact({
consumer: 'frontend',
provider: 'connector',
Expand All @@ -40,9 +40,9 @@ describe('connectors client - worldpay google authentication API', function () {
before(() => provider.setup())
after(() => provider.finalize())

describe('Authenticate Worldpay google payment', function () {
describe('Authorise Worldpay Google Pay payment', function () {
describe('authorisation success', function () {
const successfulGoogleAuthRequest = fixtures.worldpayGoogleAuthRequestDetails({ worldpay3dsFlexDdcResult: GOOGLE_DDC_RESULT })
const successfulGoogleAuthRequest = fixtures.worldpayOrSandboxGoogleAuthRequestDetails({ worldpay3dsFlexDdcResult: GOOGLE_DDC_RESULT })
const authorisationSuccessResponse = fixtures.webPaymentSuccessResponse()
before(() => {
const builder = new PactInteractionBuilder(GOOGLE_AUTH_PATH)
Expand All @@ -63,8 +63,7 @@ describe('connectors client - worldpay google authentication API', function () {
connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({
chargeId: TEST_CHARGE_ID,
wallet: 'google',
payload: payload,
paymentProvider: 'worldpay'
payload: payload
}).then(res => {
expect(res.body.status).to.be.equal('AUTHORISATION SUCCESS')
done()
Expand All @@ -73,7 +72,7 @@ describe('connectors client - worldpay google authentication API', function () {
})

describe('authorisation success with no last card digits', function () {
const successfulGoogleAuthRequest = fixtures.worldpayGoogleAuthRequestDetails({
const successfulGoogleAuthRequest = fixtures.worldpayOrSandboxGoogleAuthRequestDetails({
lastDigitsCardNumber: '',
worldpay3dsFlexDdcResult: GOOGLE_DDC_RESULT
})
Expand All @@ -98,8 +97,7 @@ describe('connectors client - worldpay google authentication API', function () {
connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({
chargeId: TEST_CHARGE_ID,
wallet: 'google',
payload: payload,
paymentProvider: 'worldpay'
payload: payload
}).then(res => {
expect(res.body.status).to.be.equal('AUTHORISATION SUCCESS')
done()
Expand All @@ -108,7 +106,7 @@ describe('connectors client - worldpay google authentication API', function () {
})

describe('authorisation success with no ddc result', function () {
const successfulGoogleAuthRequest = fixtures.worldpayGoogleAuthRequestDetails()
const successfulGoogleAuthRequest = fixtures.worldpayOrSandboxGoogleAuthRequestDetails()
const authorisationSuccessResponse = fixtures.webPaymentSuccessResponse()

before(() => {
Expand All @@ -130,8 +128,7 @@ describe('connectors client - worldpay google authentication API', function () {
connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({
chargeId: TEST_CHARGE_ID,
wallet: 'google',
payload: payload,
paymentProvider: 'worldpay'
payload: payload
}).then(res => {
expect(res.body.status).to.be.equal('AUTHORISATION SUCCESS')
done()
Expand Down
57 changes: 57 additions & 0 deletions test/utils/wallet-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,43 @@ describe('Wallet utils', () => {
expect(applePayEnabled(charge)).to.eq(false)
})
})

describe('Sandbox account', () => {
it('should return true if globally enabled for Worldpay (and sandbox) and enabled for account', () => {
process.env.WORLDPAY_APPLE_PAY_ENABLED = 'true'
process.env.WORLDPAY_GOOGLE_PAY_ENABLED = 'false'
process.env.STRIPE_APPLE_PAY_ENABLED = 'false'
process.env.STRIPE_GOOGLE_PAY_ENABLED = 'false'
const charge = createChargeWithApplePayEnabled('sandbox')
expect(applePayEnabled(charge)).to.eq(true)
})

it('should return true if environment variable not set and enabled for account', () => {
const charge = createChargeWithApplePayEnabled('sandbox')
expect(applePayEnabled(charge)).to.eq(true)
})

it('should return false if globally disabled for Worldpay (and sandbox) and account is not in test account list', () => {
process.env.WORLDPAY_APPLE_PAY_ENABLED = 'false'
process.env.PAY_TEST_GATEWAY_ACCOUNTS = ['33']
const charge = createChargeWithApplePayEnabled('sandbox')
expect(applePayEnabled(charge)).to.eq(false)
})

it('should return true if globally disabled for Worldpay (and sandbox) but account is in test account list', () => {
process.env.WORLDPAY_APPLE_PAY_ENABLED = 'false'
process.env.PAY_TEST_GATEWAY_ACCOUNTS = [gatewayAccountId.toString()]

const charge = createChargeWithApplePayEnabled('sandbox')
expect(applePayEnabled(charge)).to.eq(true)
})

it('should return false if not enabled for account', () => {
process.env.WORLDPAY_APPLE_PAY_ENABLED = 'true'
const charge = createCharge('sandbox', false, true)
expect(applePayEnabled(charge)).to.eq(false)
})
})
})

describe('googlePayEnabled', () => {
Expand Down Expand Up @@ -167,6 +204,26 @@ describe('Wallet utils', () => {
expect(googlePayEnabled(charge)).to.eq(false)
})
})

describe('Sandbox account', () => {
it('should return true if enabled for gateway account', () => {
process.env.WORLDPAY_APPLE_PAY_ENABLED = 'false'
process.env.WORLDPAY_GOOGLE_PAY_ENABLED = 'false'
process.env.STRIPE_APPLE_PAY_ENABLED = 'false'
process.env.STRIPE_GOOGLE_PAY_ENABLED = 'false'
const charge = createChargeWithGooglePayEnabled('sandbox')
expect(googlePayEnabled(charge)).to.eq(true)
})

it('should return false if not enabled for gateway account', () => {
process.env.WORLDPAY_APPLE_PAY_ENABLED = 'false'
process.env.WORLDPAY_GOOGLE_PAY_ENABLED = 'false'
process.env.STRIPE_APPLE_PAY_ENABLED = 'false'
process.env.STRIPE_GOOGLE_PAY_ENABLED = 'false'
const charge = createCharge('sandbox', true, false)
expect(googlePayEnabled(charge)).to.eq(false)
})
})
})
})

Expand Down