Skip to content

Commit

Permalink
Consolidate Braintree client version constants to a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasmiller committed Jul 17, 2023
1 parent 46ff06c commit 917b815
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions lib/const/gateway-constants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"braintree": {
"clientVersion": "3.96.0",
}
}
7 changes: 4 additions & 3 deletions lib/recurly/apple-pay/apple-pay.braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import Promise from 'promise';
import { ApplePay } from './apple-pay';
import loadScriptPromise from '../../util/load-script-promise';
import Debug from 'debug';
import { GATEWAY_CONSTANTS } from '../../../const/gateway-constants.json';

const debug = Debug('recurly:apple-pay:braintree');

const CLIENT_VERSION = '3.76.0';
const braintreeClientVersion = GATEWAY_CONSTANTS.braintree.clientVersion;
const LIBS = {
client: 'client',
applePay: 'apple-pay',
Expand All @@ -14,7 +15,7 @@ const LIBS = {

const loadBraintree = (...libs) => {
const loadLib = lib => {
const isLibPresent = window.braintree?.client?.VERSION === CLIENT_VERSION &&
const isLibPresent = window.braintree?.client?.VERSION === braintreeClientVersion &&
lib in window.braintree;

return isLibPresent
Expand All @@ -28,7 +29,7 @@ const loadBraintree = (...libs) => {

export class ApplePayBraintree extends ApplePay {
static libUrl (lib) {
return `https://js.braintreegateway.com/web/${CLIENT_VERSION}/js/${LIBS[lib]}.min.js`;
return `https://js.braintreegateway.com/web/${braintreeClientVersion}/js/${LIBS[lib]}.min.js`;
}

configure (options) {
Expand Down
7 changes: 4 additions & 3 deletions lib/recurly/paypal/strategy/braintree.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import loadScript from 'load-script';
import after from '../../../util/after';
import { PayPalStrategy } from './index';
import { GATEWAY_CONSTANTS } from '../../../const/gateway-constants.json';

const debug = require('debug')('recurly:paypal:strategy:braintree');

export const BRAINTREE_CLIENT_VERSION = '3.96.0';
const braintreeClientVersion = GATEWAY_CONSTANTS.braintree.clientVersion;

/**
* Braintree-specific PayPal handler
Expand Down Expand Up @@ -34,7 +35,7 @@ export class BraintreeStrategy extends PayPalStrategy {

const part = after(2, () => this.initialize());
const get = (lib, done = () => {}) => {
const uri = `https://js.braintreegateway.com/web/${BRAINTREE_CLIENT_VERSION}/js/${lib}.min.js`;
const uri = `https://js.braintreegateway.com/web/${braintreeClientVersion}/js/${lib}.min.js`;
loadScript(uri, error => {
if (error) this.error('paypal-load-error', { cause: error });
else done();
Expand Down Expand Up @@ -117,6 +118,6 @@ export class BraintreeStrategy extends PayPalStrategy {

braintreeClientAvailable (module) {
const bt = window.braintree;
return bt && bt.client && bt.client.VERSION === BRAINTREE_CLIENT_VERSION && (module ? module in bt : true);
return bt && bt.client && bt.client.VERSION === braintreeClientVersion && (module ? module in bt : true);
}
}
5 changes: 3 additions & 2 deletions lib/recurly/risk/three-d-secure/strategy/braintree.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import loadScript from 'load-script';
import Promise from 'promise';
import ThreeDSecureStrategy from './strategy';
import { GATEWAY_CONSTANTS } from '../../../const/gateway-constants.json';

const debug = require('debug')('recurly:risk:three-d-secure:braintree');
const BRAINTREE_CLIENT_VERSION = '3.76.0';
const braintreeClientVersion = GATEWAY_CONSTANTS.braintree.clientVersion;

export default class BraintreeStrategy extends ThreeDSecureStrategy {

Expand Down Expand Up @@ -76,7 +77,7 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy {
}

urlForResource (type) {
return `https://js.braintreegateway.com/web/${BRAINTREE_CLIENT_VERSION}/js/${type}.min.js`;
return `https://js.braintreegateway.com/web/${braintreeClientVersion}/js/${type}.min.js`;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions lib/recurly/venmo/strategy/braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import loadScript from 'load-script';
import after from '../../../util/after';
import { VenmoStrategy } from './index';
import { normalize } from '../../../util/normalize';
import { GATEWAY_CONSTANTS } from '../../../const/gateway-constants.json';

export const BRAINTREE_CLIENT_VERSION = '3.96.0';
const braintreeClientVersion = GATEWAY_CONSTANTS.braintree.clientVersion;

const debug = require('debug')('recurly:paypal:strategy:braintree');

Expand Down Expand Up @@ -36,7 +37,7 @@ export class BraintreeStrategy extends VenmoStrategy {

const part = after(2, () => this.initialize());
const get = (lib, done = () => {}) => {
const uri = `https://js.braintreegateway.com/web/${BRAINTREE_CLIENT_VERSION}/js/${lib}.min.js`;
const uri = `https://js.braintreegateway.com/web/${braintreeClientVersion}/js/${lib}.min.js`;
loadScript(uri, error => {
if (error) this.error('venmo-load-error', { cause: error });
else done();
Expand Down Expand Up @@ -109,6 +110,6 @@ export class BraintreeStrategy extends VenmoStrategy {

braintreeClientAvailable (module) {
const bt = window.braintree;
return bt && bt.client && bt.client.VERSION === BRAINTREE_CLIENT_VERSION && (module ? module in bt : true);
return bt && bt.client && bt.client.VERSION === braintreeClientVersion && (module ? module in bt : true);
}
}
2 changes: 1 addition & 1 deletion test/unit/apple-pay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ApplePaySessionStub.canMakePayments = () => true;

const getBraintreeStub = () => ({
client: {
VERSION: '3.76.0',
VERSION: '3.96.0',
create: sinon.stub().resolves('CLIENT'),
},
dataCollector: {
Expand Down
7 changes: 5 additions & 2 deletions test/unit/support/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import bowser from 'bowser';
import merge from 'lodash.merge';
import { Recurly } from '../../../lib/recurly';
import { BRAINTREE_CLIENT_VERSION } from '../../../lib/recurly/paypal/strategy/braintree';
import { GATEWAY_CONSTANTS } from '../../../lib/const/gateway-constants.json';

import Promise from 'promise';

const braintreeClientVersion = GATEWAY_CONSTANTS.braintree.clientVersion;

/**
* initializes a Recurly instance designed for testing
* @param {[Recurly]} recurly
Expand Down Expand Up @@ -59,7 +62,7 @@ export function stubBraintree () {

window.braintree = {
client: {
VERSION: BRAINTREE_CLIENT_VERSION,
VERSION: braintreeClientVersion,
create
},
venmo: {
Expand Down

0 comments on commit 917b815

Please sign in to comment.