Skip to content

Commit

Permalink
handle amazon 3ds challenges
Browse files Browse the repository at this point in the history
pass back sandbox true or false for button rendering
  • Loading branch information
gilv93 committed Jan 31, 2024
1 parent 14e1121 commit 35e9918
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/recurly/amazon/amazon-pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AmazonPay extends Emitter {
obtainMerchantId () {
return this.recurly.request.get({ route: '/amazon_pay/button_render', data: { region: this.options.region } })
.then((data) => {
this.options.sandbox = data.sandbox;
this.options.merchantId = data.merchant_id;
});
}
Expand Down
53 changes: 53 additions & 0 deletions lib/recurly/risk/three-d-secure/strategy/amazon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import ThreeDSecureStrategy from './strategy';
import { Frame } from '../../../frame';

const debug = require('debug')('recurly:risk:three-d-secure:amazon');

export default class AmazonStrategy extends ThreeDSecureStrategy {
static strategyName = 'amazon';

constructor (...args) {
super(...args);
this.markReady();
}

get redirectParams () {
return this.actionToken.three_d_secure.params.redirect;
}

/**
* Provides the target DOM element for which we will apply
* fingerprint detection, challenge flows, and results.
*
* @param {HTMLElement} element
*/
attach (element) {
super.attach(element);
debug('Initiating 3D Secure frame');

const { redirectParams, container, threeDSecure } = this;
const { recurly } = threeDSecure.risk;
const payload = {
redirect_url: redirectParams.url,
three_d_secure_action_token_id: this.actionToken.id
};

this.frame = recurly.Frame({
path: '/three_d_secure/start',
payload,
container,
type: Frame.TYPES.WINDOW,
defaultEventName: 'amazon-3ds-challenge'
}).on('error', cause => threeDSecure.error('3ds-auth-error', { cause }))
.on('done', results => this.emit('done', results));
}

/**
* Removes DOM elements
*/
remove () {
const { frame } = this;
if (frame) frame.destroy();
super.remove();
}
}
2 changes: 2 additions & 0 deletions lib/recurly/risk/three-d-secure/three-d-secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import WirecardStrategy from './strategy/wirecard';
import WorldpayStrategy from './strategy/worldpay';
import OrbitalStrategy from './strategy/orbital';
import PayPalCompleteStrategy from './strategy/paypal-complete';
import AmazonStrategy from './strategy/amazon';

const debug = require('debug')('recurly:risk:three-d-secure');

Expand Down Expand Up @@ -52,6 +53,7 @@ export class ThreeDSecure extends RiskConcern {
WorldpayStrategy,
OrbitalStrategy,
PayPalCompleteStrategy,
AmazonStrategy,
];

static CHALLENGE_WINDOW_SIZE_01_250_X_400 = '01';
Expand Down

0 comments on commit 35e9918

Please sign in to comment.