Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gilv93 committed Sep 27, 2024
1 parent 7973024 commit 9a728f3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
15 changes: 9 additions & 6 deletions lib/recurly/risk/risk.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ export class Risk {
debug('received preflight instructions', preflights);
return ThreeDSecure.preflight({ recurly, number, month, year, cvv, preflights });
})
.then(results => results.filter(maybeErr => {
if (maybeErr.code === 'risk-preflight-timeout') {
debug('timeout encountered', maybeErr);
return false;
}
return true;
.then(({ tokenType, risk }) => ({
risk: risk.filter(maybeErr => {
if (maybeErr.code === 'risk-preflight-timeout') {
debug('timeout encountered', maybeErr);
return false;
}
return true;
}),
tokenType
}));
}

Expand Down
12 changes: 8 additions & 4 deletions lib/recurly/risk/three-d-secure/strategy/braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy {
}

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

debug('performing preflight for', { gatewayCode });

Expand All @@ -32,9 +32,13 @@ export default class BraintreeStrategy extends ThreeDSecureStrategy {
// resolve with relevant data instead of session_id
return recurly.request.post({ route: '/risk/authentications', data })
.then(({ paymentMethodNonce, clientToken, bin }) => ({
payment_method_nonce: paymentMethodNonce,
client_token: clientToken,
bin,
results: {
payment_method_nonce: paymentMethodNonce,
client_token: clientToken,
bin,
amount: amount
},
tokenType: 'three_d_secure_proactive_action'
}));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/risk/three-d-secure/strategy/cybersource.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class CybersourceStrategy extends ThreeDSecureStrategy {
const body = JSON.parse(data);
if (body.MessageType === 'profile.completed') {
debug('received device data session id', body);
resolve({ session_id: body.SessionId });
resolve({ results: { session_id: body.SessionId }});
frame.destroy();
recurly.bus.off('raw-message', listener);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/risk/three-d-secure/strategy/worldpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class WorldpayStrategy extends ThreeDSecureStrategy {
const body = JSON.parse(data);
if (body.MessageType === 'profile.completed') {
debug('received device data session id', body);
resolve({ session_id: body.SessionId });
resolve({ results: { session_id: body.SessionId }});
recurly.bus.off('raw-message', listener);
frame.destroy();
}
Expand Down
28 changes: 21 additions & 7 deletions lib/recurly/risk/three-d-secure/three-d-secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,29 @@ export class ThreeDSecure extends RiskConcern {
static preflight ({ recurly, number, month, year, cvv, preflights }) {
return preflights.reduce((preflight, result) => {
return preflight.then((finishedPreflights) => {
const { type } = result.gateway;
const { type: gatewayType } = result.gateway;
const { gateway_code } = result.params;
const strategy = ThreeDSecure.getStrategyForGatewayType(type);
const strategy = ThreeDSecure.getStrategyForGatewayType(gatewayType);
return strategy.preflight({ recurly, number, month, year, cvv, ...result.params })
.then(results => {
return finishedPreflights.concat([{ processor: type, gateway_code, results }]);
.then(({ results, tokenType }) => {
// return finishedPreflights.concat([{ processor: type, gateway_code, results}]);
return {
tokenType: finishedPreflights.tokenType || tokenType,
// risk: {
// processor: gatewayType,
// gateway_code,
// risk
// // finishedPreflights.risk.concat(risk)
// }
risk: finishedPreflights.risk.concat({
processor: gatewayType,
gateway_code,
results
})
}
});
});
}, Promise.resolve([]));
}, Promise.resolve({risk: []}));
}

constructor ({ risk, actionTokenId, challengeWindowSize }) {
Expand Down Expand Up @@ -225,10 +239,10 @@ export class ThreeDSecure extends RiskConcern {
}

function assertIsActionToken (token) {
if (VALID_ACTION_TOKEN_TYPES.includes(token?.type)) return;
if (ThreeDSecure.VALID_ACTION_TOKEN_TYPES.includes(token?.type)) return;

throw errors('invalid-option', {
name: 'actionTokenId',
expect: `a token of type: ${VALID_ACTION_TOKEN_TYPES.join(',')}`
expect: `a token of type: ${ThreeDSecure.VALID_ACTION_TOKEN_TYPES.join(',')}`
});
}
5 changes: 4 additions & 1 deletion lib/recurly/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ function token (customerData, bus, done) {

const { number, month, year, cvv } = inputs;
Risk.preflight({ recurly: this, number, month, year, cvv })
.then(results => inputs.risk = results)
.then(({ risk, tokenType }) => {
inputs.risk = risk
if (tokenType) inputs.type = tokenType
})
.then(() => this.request.post({ route: '/token', data: inputs, done: complete }))
.done();
}
Expand Down

0 comments on commit 9a728f3

Please sign in to comment.