diff --git a/lib/recurly.js b/lib/recurly.js index aa2c87d1e..114ab927d 100644 --- a/lib/recurly.js +++ b/lib/recurly.js @@ -25,6 +25,7 @@ import { factory as Frame } from './recurly/frame'; import { factory as PayPal } from './recurly/paypal'; import { factory as Venmo } from './recurly/venmo'; import { factory as Risk } from './recurly/risk'; +import { factory as AmazonPay } from './recurly/amazon'; import { deprecated as deprecatedPaypal } from './recurly/paypal/strategy/direct'; import { Bus } from './recurly/bus'; import { Reporter } from './recurly/reporter'; @@ -125,6 +126,7 @@ export class Recurly extends Emitter { Risk = Risk; tax = tax; token = token; + AmazonPay = AmazonPay; validate = require('./recurly/validate').publicMethods; /** diff --git a/lib/recurly/amazon/amazon-pay.js b/lib/recurly/amazon/amazon-pay.js new file mode 100644 index 000000000..bd938895f --- /dev/null +++ b/lib/recurly/amazon/amazon-pay.js @@ -0,0 +1,27 @@ +import Emitter from 'component-emitter'; +import { Frame } from '../frame'; + +class AmazonPay extends Emitter { + constructor (recurly, options) { + super(); + this.recurly = recurly; + this.options = options; + } + + attach (element) { + this.parent = element; + this.region = this.options?.region || 'us'; + const defaultEventName = 'amazon-pay'; + + this.frame = this.recurly.Frame({ + path: `/amazon_pay/start?region=${this.region}`, + type: Frame.TYPES.WINDOW, + defaultEventName + }).on('error', cause => console.log(cause)) + .on('done', results => { + this.emit('token', results); + }); + } +} + +export default AmazonPay; diff --git a/lib/recurly/amazon/index.js b/lib/recurly/amazon/index.js new file mode 100644 index 000000000..bfa65ce92 --- /dev/null +++ b/lib/recurly/amazon/index.js @@ -0,0 +1,13 @@ +import AmazonPay from './amazon-pay'; +/** + * Returns an Amazon instance. + * + * @param {Object} options + * @return {AmazonPay} + */ + +export function factory (options) { + const recurly = this; + + return new AmazonPay(recurly, options); +}