Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Amazon Pay 3DS action tokens #869

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading