From 03cd38c23b198cc0f33e5f81123c7b44d5ee3337 Mon Sep 17 00:00:00 2001 From: Andi Zitney Date: Tue, 2 Apr 2024 17:57:32 -0700 Subject: [PATCH] Upgrade Braintree SDK --- lib/const/gateway-constants.js | 2 +- .../risk/three-d-secure/strategy/braintree.js | 43 ++++++++++++++----- test/unit/apple-pay.test.js | 2 +- .../three-d-secure/strategy/braintree.test.js | 1 + 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/lib/const/gateway-constants.js b/lib/const/gateway-constants.js index ed164263a..eb2dc1e3a 100644 --- a/lib/const/gateway-constants.js +++ b/lib/const/gateway-constants.js @@ -1 +1 @@ -export const BRAINTREE_CLIENT_VERSION = '3.96.1'; +export const BRAINTREE_CLIENT_VERSION = '3.101.0'; diff --git a/lib/recurly/risk/three-d-secure/strategy/braintree.js b/lib/recurly/risk/three-d-secure/strategy/braintree.js index 2dbd2b946..8a653cd31 100644 --- a/lib/recurly/risk/three-d-secure/strategy/braintree.js +++ b/lib/recurly/risk/three-d-secure/strategy/braintree.js @@ -34,6 +34,10 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy { return this.actionToken.transaction.amount; } + get billingInfo () { + return this.actionToken.billing_info; + } + get bin () { return this.actionToken.three_d_secure.params.bin; } @@ -51,7 +55,32 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy { this.whenReady(() => { debug('Attempting to load braintree'); - const { braintree, braintreeClientToken, amount, nonce, bin } = this; + const { braintree, braintreeClientToken, amount, nonce, bin, billingInfo } = this; + + const verifyCardOptions = { + amount: amount, + nonce: nonce, + bin: bin, + challengeRequested: true, + collectDeviceData: true, + onLookupComplete: (data, next) => { + next(); + } + }; + + if(billingInfo != null) { + verifyCardOptions.billingAddress = { + givenName: billingInfo.first_name, + surname: billingInfo.last_name, + phoneNumber: billingInfo.phone, + streetAddress: billingInfo.address1, + extendedAddress: billingInfo.address2, + locality: billingInfo.city, + region: billingInfo.state, + postalCode: billingInfo.zip, + countryCodeAlpha2: billingInfo.country + }; + } braintree.client.create({ authorization: braintreeClientToken @@ -61,15 +90,9 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy { version: 2 }); }).then(threeDSecureInstance => { - return threeDSecureInstance.verifyCard({ - amount: amount, - nonce: nonce, - bin: bin, - challengeRequested: true, - onLookupComplete: (data, next) => { - next(); - } - }); + return threeDSecureInstance.verifyCard( + verifyCardOptions, + ); }).then(({ nonce: paymentMethodNonce }) => this.emit('done', { paymentMethodNonce })) .catch(cause => this.threeDSecure.error('3ds-auth-error', { cause })); }); diff --git a/test/unit/apple-pay.test.js b/test/unit/apple-pay.test.js index 26be96d77..d5c922c9f 100644 --- a/test/unit/apple-pay.test.js +++ b/test/unit/apple-pay.test.js @@ -64,7 +64,7 @@ ApplePaySessionStub.canMakePayments = () => true; const getBraintreeStub = () => ({ client: { - VERSION: '3.96.1', + VERSION: '3.101.0', create: sinon.stub().resolves('CLIENT'), }, dataCollector: { diff --git a/test/unit/risk/three-d-secure/strategy/braintree.test.js b/test/unit/risk/three-d-secure/strategy/braintree.test.js index e66154f23..4f83a1574 100644 --- a/test/unit/risk/three-d-secure/strategy/braintree.test.js +++ b/test/unit/risk/three-d-secure/strategy/braintree.test.js @@ -84,6 +84,7 @@ describe('BraintreeStrategy', function () { nonce: "test-braintree-nonce", bin: "test-braintree-bin", challengeRequested: true, + collectDeviceData: true, onLookupComplete: sinon.match.func }));