Skip to content

Commit

Permalink
Merge pull request #903 from recurly/fix-cybersource-preflight
Browse files Browse the repository at this point in the history
Fix bug when preflightDeviceData is set to false
  • Loading branch information
chrissrogers authored Oct 1, 2024
2 parents b1dd079 + 22d8dc1 commit 2973d0d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
5 changes: 3 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 @@ -106,8 +106,9 @@ export class ThreeDSecure extends RiskConcern {
const { gateway_code } = result.params;
const strategy = ThreeDSecure.getStrategyForGatewayType(gatewayType);
return strategy.preflight({ recurly, number, month, year, cvv, ...result.params })
.then(({ results, tokenType }) => {
// return finishedPreflights.concat([{ processor: type, gateway_code, results}]);
.then((preflightResponse) => {
if (!preflightResponse) return finishedPreflights;
const { results, tokenType } = preflightResponse;
return {
tokenType: finishedPreflights.tokenType || tokenType,
risk: finishedPreflights.risk.concat({
Expand Down
55 changes: 38 additions & 17 deletions test/unit/risk/three-d-secure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,57 @@ describe('ThreeDSecure', function () {

describe('ThreeDSecure.preflight', function () {
beforeEach(function () {
const { sandbox } = this;
this.bin = '411111';
this.preflights = [
{
gateway: { type: 'test-gateway-type' },
params: { arbitrary: 'test-params' }
}
];
sandbox.stub(ThreeDSecure, 'getStrategyForGatewayType').callsFake(() => ({
preflight: sandbox.stub().usingPromise(Promise).resolves({ results: { arbitrary: 'test-results' } })
}));
});

it('returns a promise', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights }).then(() => done());
assert(returnValue instanceof Promise);
context('when a strategy returns valid results', function () {
beforeEach(function () {
this.sandbox.stub(ThreeDSecure, 'getStrategyForGatewayType').callsFake(() => ({
preflight: this.sandbox.stub().usingPromise(Promise).resolves({ results: { arbitrary: 'test-results' } })
}));
});

it('returns a promise', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights }).then(() => done());
assert(returnValue instanceof Promise);
});

it('resolves with preflight results from strategies', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights })
.done(({ risk }) => {
const [{ processor, results }] = risk;
assert.strictEqual(Array.isArray(risk), true);
assert.strictEqual(processor, 'test-gateway-type');
assert.deepStrictEqual(results, { arbitrary: 'test-results' });
done();
});
});
});

it('resolves with preflight results from strategies', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights })
.done(({ risk }) => {
const [{ processor, results }] = risk;
assert.strictEqual(Array.isArray(risk), true);
assert.strictEqual(processor, 'test-gateway-type');
assert.deepStrictEqual(results, { arbitrary: 'test-results' });
context('when a strategy does not return results', function () {
beforeEach(function() {
this.sandbox.stub(ThreeDSecure, 'getStrategyForGatewayType').callsFake(() => ({
preflight: this.sandbox.stub().usingPromise(Promise).resolves(undefined)
}));
});

it('does not error out', function (done) {
const { recurly, bin, preflights } = this;
ThreeDSecure.preflight({ recurly, bin, preflights }).done(returnValue => {
assert(Array.isArray(returnValue.risk));
assert.strictEqual(returnValue.risk.length, 0);
done();
});
});
});
})
});

it('adds itself to the provided Risk instance', function () {
Expand Down

0 comments on commit 2973d0d

Please sign in to comment.