'use strict';
/**
* @module braintree-web/american-express
* @description This module is for use with Amex Express Checkout. To accept American Express cards, use Hosted Fields.
*/
var VERSION = require('package.version');
var BraintreeError = require('../lib/error');
var AmericanExpress = require('./american-express');
/**
* @function
* @param {object} options Object containing all {@link AmericanExpress} options
* @param {Client} options.client A {@link Client} instance
* @param {errback} callback The second argument, <code>data</code>, is the {@link AmericanExpress} instance
* @returns {void}
* @static
*/
function create(options, callback) {
if (typeof callback !== 'function') {
throw new BraintreeError({
type: BraintreeError.types.MERCHANT,
message: 'create must include a callback function.'
});
}
if (options.client == null) {
callback(new BraintreeError({
type: BraintreeError.types.MERCHANT,
message: 'A Client is required when instantiating American Express.'
}));
return;
}
if (options.client.getConfiguration().analyticsMetadata.sdkVersion !== VERSION) {
callback(new BraintreeError({
type: BraintreeError.types.MERCHANT,
message: 'Client and American Express components must be from the same SDK version.'
}));
return;
}
callback(null, new AmericanExpress(options));
}
module.exports = {
create: create,
/**
* @description The current version of the SDK, i.e. `{@pkg version}`.
* @type {string}
*/
VERSION: VERSION
};