Skip to content

Commit

Permalink
Pass billingAddress fields for Proactive 3DS
Browse files Browse the repository at this point in the history
  • Loading branch information
gilv93 committed Dec 13, 2024
1 parent ea57ff2 commit 7053471
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/recurly/risk/risk.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Risk {
* @param {String} options.bin credit card BIN
* @return {Promise}
*/
static preflight ({ recurly, number, month, year, cvv }) {
static preflight ({ recurly, number, month, year, cvv, addressFields }) {
const data = {};

if (recurly.config.risk.threeDSecure.proactive.enabled) {
Expand All @@ -66,7 +66,7 @@ export class Risk {
return recurly.request.get({ route: '/risk/preflights', data })
.then(({ preflights }) => {
debug('received preflight instructions', preflights);
return ThreeDSecure.preflight({ recurly, number, month, year, cvv, preflights });
return ThreeDSecure.preflight({ recurly, number, month, year, cvv, preflights, addressFields });
})
.then(({ tokenType, risk }) => ({
risk: risk.filter(maybeErr => {
Expand Down
7 changes: 4 additions & 3 deletions lib/recurly/risk/three-d-secure/strategy/braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy {
return BraintreeLoader.loadModules('threeDSecure');
}

static preflight ({ recurly, number, month, year, cvv }) {
static preflight ({ recurly, number, month, year, cvv, addressFields }) {
const { enabled, gatewayCode, amount, currency } = recurly.config.risk.threeDSecure.proactive;

debug('performing preflight for', { gatewayCode });
Expand All @@ -22,11 +22,12 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy {
const data = {
gateway_type: BraintreeStrategy.strategyName,
gateway_code: gatewayCode,
currency: currency,
currency,
number,
month,
year,
cvv
cvv,
...addressFields
};

// we don't really need to do anything once we get a response except
Expand Down
4 changes: 2 additions & 2 deletions lib/recurly/risk/three-d-secure/three-d-secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ export class ThreeDSecure extends RiskConcern {
* @param {Preflights} options.preflights
* @return {Promise}
*/
static preflight ({ recurly, number, month, year, cvv, preflights }) {
static preflight ({ recurly, number, month, year, cvv, preflights, addressFields }) {
return preflights.reduce((preflight, result) => {
return preflight.then((finishedPreflights) => {
const { type: gatewayType } = result.gateway;
const { gateway_code } = result.params;
const strategy = ThreeDSecure.getStrategyForGatewayType(gatewayType);
return strategy.preflight({ recurly, number, month, year, cvv, ...result.params })
return strategy.preflight({ recurly, number, month, year, cvv, addressFields, ...result.params })
.then((preflightResponse) => {
if (!preflightResponse) return finishedPreflights;
const { results, tokenType } = preflightResponse;
Expand Down
29 changes: 27 additions & 2 deletions lib/recurly/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,34 @@ function token (customerData, bus, done) {
}));
}

const { number, month, year, cvv } = inputs;
const {
number,
month,
year,
cvv,
first_name,
last_name,
address1,
address2,
city,
country,
postal_code,
state
} = inputs;

const addressFields = {
first_name,
last_name,
address1,
address2,
city,
country,
postal_code,
state,
};

if (number && month && year) {
Risk.preflight({ recurly: this, number, month, year, cvv })
Risk.preflight({ recurly: this, number, month, year, cvv, addressFields })
.then(({ risk, tokenType }) => {
inputs.risk = risk;
if (tokenType) inputs.type = tokenType;
Expand Down
21 changes: 17 additions & 4 deletions test/unit/risk/three-d-secure/strategy/braintree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ describe('BraintreeStrategy', function () {
this.month = '01';
this.year = '2023';
this.cvv = '737'

this.addressFields = {
first_name: 'John',
last_name: 'Doe',
address1: '123 Main St',
address2: 'Suite 100',
city: 'San Francisco',
country: 'US',
postal_code: '94105',
state: 'CA',
}

recurly.config.risk.threeDSecure.proactive = {
enabled: true,
gatewayCode: 'test-gateway-code',
Expand All @@ -142,10 +154,10 @@ describe('BraintreeStrategy', function () {
});

it('sends the correct data', function (done) {
const { recurly, number, month, year, cvv } = this;
const { recurly, number, month, year, cvv, addressFields } = this;

BraintreeStrategy.preflight({ recurly, number, month, year, cvv }).then(() => {
sinon.assert.calledWithMatch(recurly.request.post, {
BraintreeStrategy.preflight({ recurly, number, month, year, cvv, addressFields }).then(() => {
sinon.assert.calledWithExactly(recurly.request.post, {
route: '/risk/authentications',
data: {
gateway_type: BraintreeStrategy.strategyName,
Expand All @@ -154,7 +166,8 @@ describe('BraintreeStrategy', function () {
number,
month,
year,
cvv
cvv,
...addressFields
}
});
done();
Expand Down

0 comments on commit 7053471

Please sign in to comment.