Skip to content

Commit

Permalink
reorganized
Browse files Browse the repository at this point in the history
  • Loading branch information
arzitney committed Apr 1, 2024
1 parent eac3936 commit 1d9e828
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
49 changes: 28 additions & 21 deletions lib/recurly/risk/three-d-secure/strategy/braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy {

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
}).then(clientInstance => {
Expand All @@ -65,27 +90,9 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy {
version: 2
});
}).then(threeDSecureInstance => {
return threeDSecureInstance.verifyCard({
amount: amount,
nonce: nonce,
bin: bin,
challengeRequested: true,
collectDeviceData: true,
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
},
onLookupComplete: (data, next) => {
next();
}
});
return threeDSecureInstance.verifyCard(
verifyCardOptions,
);
}).then(({ nonce: paymentMethodNonce }) => this.emit('done', { paymentMethodNonce }))
.catch(cause => this.threeDSecure.error('3ds-auth-error', { cause }));
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/risk/three-d-secure/strategy/braintree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('BraintreeStrategy', function () {
nonce: "test-braintree-nonce",
bin: "test-braintree-bin",
challengeRequested: true,
collectDeviceData: true,
onLookupComplete: sinon.match.func
}));

Expand Down

0 comments on commit 1d9e828

Please sign in to comment.