Skip to content

Commit

Permalink
Merge pull request #869 from recurly/amazon_pay_3ds
Browse files Browse the repository at this point in the history
Handle Amazon Pay 3DS action tokens
  • Loading branch information
arzitney authored Feb 14, 2024
2 parents 14e1121 + 6965daf commit 3a29a1d
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 @@ -24,6 +24,7 @@ class AmazonPay extends Emitter {
return this.recurly.request.get({ route: '/amazon_pay/button_render', data: { region: this.options.region } })
.then((data) => {
this.options.merchantId = data.merchant_id;
this.options.sandbox = data.sandbox;
});
}

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 3a29a1d

Please sign in to comment.