Skip to content

Commit

Permalink
Merge pull request #671 from recurly/implementer-specified-device-dat…
Browse files Browse the repository at this point in the history
…a-collection

Allow recurly.js implementer to specify if 3ds2 device data collection calls occur
  • Loading branch information
chrissrogers authored Apr 5, 2021
2 parents 9e2e2ab + 575d9cc commit 47f224e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/recurly.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const DEFAULTS = {
litle: { sessionId: undefined },
braintree: { deviceData: undefined }
},
risk: {
threeDSecure: { preflightDeviceDataCollector: true }
},
api: 'https://api.recurly.com/js/v1',
fields: {
all: {
Expand Down Expand Up @@ -240,6 +243,10 @@ export class Recurly extends Emitter {
deepAssign(this.config.fraud, options.fraud);
}

if ('risk' in options) {
deepAssign(this.config.risk, options.risk);
}

if ('parent' in options) {
this.config.parent = options.parent;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/recurly/risk/three-d-secure/strategy/cybersource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export default class CybersourceStrategy extends ThreeDSecureStrategy {
static strategyName = 'cybersource';

static preflight ({ recurly, number, month, year, gateway_code }) {
const { preflightDeviceDataCollector } = recurly.config.risk.threeDSecure;

if(!preflightDeviceDataCollector) {
return Promise.resolve();
}

const { PREFLIGHT_TIMEOUT } = CybersourceStrategy;
const data = {
gatewayType: CybersourceStrategy.strategyName,
Expand Down
6 changes: 6 additions & 0 deletions lib/recurly/risk/three-d-secure/strategy/worldpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default class WorldpayStrategy extends ThreeDSecureStrategy {
* @return {Promise}
*/
static preflight ({ recurly, number, jwt }) {
const { preflightDeviceDataCollector } = recurly.config.risk.threeDSecure;

if(!preflightDeviceDataCollector) {
return Promise.resolve();
}

const { PREFLIGHT_TIMEOUT } = WorldpayStrategy;
const bin = number.substr(0, 6);
const frame = recurly.Frame({
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/recurly.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Recurly.js', async function () {
await (await $(sel.lastName)).setValue('Doe');

const withCvv = [
['4111111111111111', '4111 1111 1111 1111'],
['4111111111111111', '4111 1111 1111 1111 '],
['10', '10'],
['28', '28'],
['123', '123']
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const SELECTORS = {

const EXAMPLES = {
NUMBER: '4111111111111111',
NUMBER_FORMATTED: '4111 1111 1111 1111',
NUMBER_FORMATTED: '4111 1111 1111 1111 ',
MONTH: '10',
YEAR: '28',
CVV: '123'
Expand Down
15 changes: 15 additions & 0 deletions test/unit/risk/three-d-secure/strategy/cybersource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ describe('CybersourceStrategy', function () {
done();
});
});

describe('device data collection disabled', function () {
beforeEach(function() {
this.recurly.config.risk.threeDSecure.preflightDeviceDataCollector = false;
});

it('does not construct a frame to collect a session id', function (done) {
const { recurly, Strategy, number, month, year, gateway_code, jwt, poll } = this;

Strategy.preflight({ recurly, number, month, year, gateway_code }).then(() => {
sinon.assert.callCount(recurly.Frame, 0);
done();
});
});
});
});

describe('attach', function () {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/risk/three-d-secure/strategy/worldpay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ describe('WorldpayStrategy', function () {

simulatePreflightResponse();
});

describe('device data collection disabled', function () {
beforeEach(function() {
this.recurly.config.risk.threeDSecure.preflightDeviceDataCollector = false;
});

it('does not construct a frame to collect a session id', function (done) {
const { recurly, Strategy, number, month, year, gateway_code, jwt, poll } = this;

Strategy.preflight({ recurly, number, month, year, gateway_code }).then(() => {
sinon.assert.callCount(recurly.Frame, 0);
done();
});
});
});
});

describe('attach', function () {
Expand Down
5 changes: 5 additions & 0 deletions types/lib/configure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export type RecurlyOptions = {
sessionId?: string;
};
};
risk?: {
threeDSecure?: {
preflightDeviceDataCollector?: boolean;
}
};

/**
* @deprecated Use {@link https://developers.recurly.com/reference/recurly-js/index.html#elements|Elements} instead.
Expand Down

0 comments on commit 47f224e

Please sign in to comment.