"use strict";
var basicComponentVerification = require("../lib/basic-component-verification");
var BraintreeError = require("../lib/braintree-error");
var createDeferredClient = require("../lib/create-deferred-client");
var createAssetsUrl = require("../lib/create-assets-url");
var errors = require("./errors");
var USBankAccount = require("./us-bank-account");
var VERSION = process.env.npm_package_version;
var wrapPromise = require("@braintree/wrap-promise");
function create(options) {
var name = "US Bank Account";
return basicComponentVerification
.verify({
name: name,
client: options.client,
authorization: options.authorization,
})
.then(function () {
return createDeferredClient.create({
authorization: options.authorization,
client: options.client,
debug: options.debug,
assetsUrl: createAssetsUrl.create(options.authorization),
name: name,
});
})
.then(function (client) {
var usBankAccount;
options.client = client;
usBankAccount =
options.client.getConfiguration().gatewayConfiguration.usBankAccount;
if (!usBankAccount) {
return Promise.reject(
new BraintreeError(errors.US_BANK_ACCOUNT_NOT_ENABLED)
);
}
return new USBankAccount(options);
});
}
module.exports = {
create: wrapPromise(create),
VERSION: VERSION,
};