hyperwallet-sdk
Version:
A library to manage users, transfer methods and payments through the Hyperwallet API
1,253 lines (1,109 loc) • 108 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _objectAssign = require("object-assign");
var _objectAssign2 = _interopRequireDefault(_objectAssign);
var _ApiClient = require("./utils/ApiClient");
var _ApiClient2 = _interopRequireDefault(_ApiClient);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The Hyperwallet SDK Client
*/
var Hyperwallet = function () {
/**
* Create a instance of the SDK Client
*
* @param {Object} config - The API config
* @param {string} config.username - The API username
* @param {string} config.password - The API password
* @param {string} [config.programToken] - The program token that is used for some API calls
* @param {Object} [config.encryptionData] - The JSON object of encryption data
* @param {string} [config.server=https://api.sandbox.hyperwallet.com] - The API server to connect to
*/
function Hyperwallet(_ref) {
var username = _ref.username,
password = _ref.password,
programToken = _ref.programToken,
encryptionData = _ref.encryptionData,
_ref$server = _ref.server,
server = _ref$server === undefined ? "https://api.sandbox.hyperwallet.com" : _ref$server;
_classCallCheck(this, Hyperwallet);
if (!username || !password) {
throw new Error("You need to specify your API username and password!");
}
/**
* The instance of the ApiClient
*
* @type {ApiClient}
* @protected
*/
this.client = new _ApiClient2.default(username, password, server, encryptionData);
/**
* The program token that is used for some API calls
*
* @type {string}
* @protected
*/
this.programToken = programToken;
}
//--------------------------------------
// Users
//--------------------------------------
/**
* Create a user
*
* @param {Object} data - The user data
* @param {api-callback} callback - The callback for this call
*/
_createClass(Hyperwallet, [{
key: "createUser",
value: function createUser(data, callback) {
this.addProgramToken(data);
this.client.doPost("users", data, {}, callback);
}
/**
* Load a user
*
* @param {string} userToken - The user token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "getUser",
value: function getUser(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken), {}, callback);
}
/**
* Update a user
*
* @param {string} userToken - The user token
* @param {Object} data - The user data that should be updated
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "updateUser",
value: function updateUser(userToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.addProgramToken(data);
this.client.doPut("users/" + encodeURIComponent(userToken), data, {}, callback);
}
/**
* List all users
*
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
*/
}, {
key: "listUsers",
value: function listUsers(options, callback) {
var LIST_USER_FILTERS = ["clientUserId", "email", "programToken", "status", "verificationStatus", "taxVerificationStatus", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_USER_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_FILTERS));
}
this.client.doGet("users", options, Hyperwallet.handle204Response(callback));
}
/**
* Activate a user
*
* @param {string} userToken - user token
* @param {api-callback} callback - callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "activateUser",
value: function activateUser(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var transition = {
transition: "ACTIVATED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/status-transitions", transition, {}, callback);
}
/**
* Deactivate a user
*
* @param {string} userToken - user token
* @param {api-callback} callback - callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "deactivateUser",
value: function deactivateUser(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var transition = {
transition: "DE_ACTIVATED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/status-transitions", transition, {}, callback);
}
/**
* Lock a user account
*
* @param {string} userToken - user token
* @param {api-callback} callback - callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "lockUser",
value: function lockUser(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var transition = {
transition: "LOCKED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/status-transitions", transition, {}, callback);
}
/**
* Freeze a user account
*
* @param {string} userToken - user token
* @param {api-callback} callback - callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "freezeUser",
value: function freezeUser(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var transition = {
transition: "FROZEN"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/status-transitions", transition, {}, callback);
}
/**
* Pre-activate a user account
*
* @param {string} userToken - user token
* @param {api-callback} callback - callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "preactivateUser",
value: function preactivateUser(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var transition = {
transition: "PRE_ACTIVATED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/status-transitions", transition, {}, callback);
}
/**
* Create a user status transition
*
* @param {string} userToken - user token
* @param {Object} data - user status transition data
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "createUserStatusTransition",
value: function createUserStatusTransition(userToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/status-transitions", data, {}, callback);
}
/**
* Get user status transition
*
* @param {string} userToken - The user token
* @param {string} statusTransitionToken - The user status transition token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "getUserStatusTransition",
value: function getUserStatusTransition(userToken, statusTransitionToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!statusTransitionToken) {
throw new Error("statusTransitionToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/status-transitions/" + encodeURIComponent(statusTransitionToken), {}, callback);
}
/**
* List all user status transitions
*
* @param {string} userToken - The user token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "listUserStatusTransitions",
value: function listUserStatusTransitions(userToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var LIST_USER_STATUS_TRANSITION_FILTERS = ["transition", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_USER_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_STATUS_TRANSITION_FILTERS));
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/status-transitions", options, Hyperwallet.handle204Response(callback));
}
/**
* Upload Documents to User
*
* @param {string} userToken - The user token
* @param {Object} data - JSON object of the data and files to be uploaded
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "uploadDocuments",
value: function uploadDocuments(userToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!data || Object.keys(data).length < 1) {
throw new Error("Files for upload are required");
}
this.client.doPutMultipart("users/" + encodeURIComponent(userToken), data, callback);
}
//--------------------------------------
// Prepaid Cards
//--------------------------------------
/**
* Create a prepaid card
*
* @param {string} userToken - The user token
* @param {Object} data - The prepaid card data
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "createPrepaidCard",
value: function createPrepaidCard(userToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards", data, {}, callback);
}
/**
* Get a prepaid card
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "getPrepaidCard",
value: function getPrepaidCard(userToken, prepaidCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken), {}, callback);
}
/**
* Update a prepaid card
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {Object} data - The prepaid card data to update
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "updatePrepaidCard",
value: function updatePrepaidCard(userToken, prepaidCardToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
this.client.doPut("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken), data, {}, callback);
}
/**
* List all prepaid cards
*
* @param {string} userToken - The user token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "listPrepaidCards",
value: function listPrepaidCards(userToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var LIST_PREPAID_CARDS_FILTERS = ["status", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_PREPAID_CARDS_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_PREPAID_CARDS_FILTERS));
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/prepaid-cards", options, Hyperwallet.handle204Response(callback));
}
/**
* Suspend a prepaid card
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "suspendPrepaidCard",
value: function suspendPrepaidCard(userToken, prepaidCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
var transition = {
transition: "SUSPENDED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", transition, {}, callback);
}
/**
* Unsuspend a prepaid card
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "unsuspendPrepaidCard",
value: function unsuspendPrepaidCard(userToken, prepaidCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
var transition = {
transition: "UNSUSPENDED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", transition, {}, callback);
}
/**
* Mark a prepaid card as lost or stolen
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "lostOrStolenPrepaidCard",
value: function lostOrStolenPrepaidCard(userToken, prepaidCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
var transition = {
transition: "LOST_OR_STOLEN"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", transition, {}, callback);
}
/**
* Deactivate a prepaid card
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "deactivatePrepaidCard",
value: function deactivatePrepaidCard(userToken, prepaidCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
var transition = {
transition: "DE_ACTIVATED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", transition, {}, callback);
}
/**
* Lock a prepaid card
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "lockPrepaidCard",
value: function lockPrepaidCard(userToken, prepaidCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
var transition = {
transition: "LOCKED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", transition, {}, callback);
}
/**
* Unlock a prepaid card
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "unlockPrepaidCard",
value: function unlockPrepaidCard(userToken, prepaidCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
var transition = {
transition: "UNLOCKED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", transition, {}, callback);
}
/**
* Create a prepaid card status transition
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {Object} data - The prepaid card status transition data
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "createPrepaidCardStatusTransition",
value: function createPrepaidCardStatusTransition(userToken, prepaidCardToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", data, {}, callback);
}
/**
* Get a prepaid card status transition
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {string} statusTransitionToken - The prepaid card status transition token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken, prepaidCardToken or statusTransitionToken is not provided
*/
}, {
key: "getPrepaidCardStatusTransition",
value: function getPrepaidCardStatusTransition(userToken, prepaidCardToken, statusTransitionToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
if (!statusTransitionToken) {
throw new Error("statusTransitionToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions/" + encodeURIComponent(statusTransitionToken), {}, callback);
}
/**
* List all prepaid card status transitions
*
* @param {string} userToken - The user token
* @param {string} prepaidCardToken - The prepaid card token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or prepaidCardToken is not provided
*/
}, {
key: "listPrepaidCardStatusTransitions",
value: function listPrepaidCardStatusTransitions(userToken, prepaidCardToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!prepaidCardToken) {
throw new Error("prepaidCardToken is required");
}
var LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS = ["transition", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS));
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/prepaid-cards/" + encodeURIComponent(prepaidCardToken) + "/status-transitions", options, Hyperwallet.handle204Response(callback));
}
//--------------------------------------
// Bank Cards
//--------------------------------------
/**
* Create a Bank card
*
* @param {string} userToken - The user token
* @param {Object} data - The bank card data
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "createBankCard",
value: function createBankCard(userToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/bank-cards", data, {}, callback);
}
/**
* Get a bank card
*
* @param {string} userToken - The user token
* @param {string} bankCardToken - The bank card token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or bankCardToken is not provided
*/
}, {
key: "getBankCard",
value: function getBankCard(userToken, bankCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!bankCardToken) {
throw new Error("bankCardToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/bank-cards/" + encodeURIComponent(bankCardToken), {}, callback);
}
/**
* Update a bank card
*
* @param {string} userToken - The user token
* @param {string} bankCardToken - The bank card token
* @param {Object} data - The bank card data to update
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or bankCardToken is not provided
*/
}, {
key: "updateBankCard",
value: function updateBankCard(userToken, bankCardToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!bankCardToken) {
throw new Error("bankCardToken is required");
}
this.client.doPut("users/" + encodeURIComponent(userToken) + "/bank-cards/" + encodeURIComponent(bankCardToken), data, {}, callback);
}
/**
* List all bank cards
*
* @param {string} userToken - The user token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "listBankCards",
value: function listBankCards(userToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var LIST_BANK_CARDS_FILTERS = ["status", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_BANK_CARDS_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_CARDS_FILTERS));
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/bank-cards", options, Hyperwallet.handle204Response(callback));
}
/**
* Deactivate a bank card
*
* @param {string} userToken - The user token
* @param {string} bankCardToken - The bank card token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or bankCardToken is not provided
*/
}, {
key: "deactivateBankCard",
value: function deactivateBankCard(userToken, bankCardToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!bankCardToken) {
throw new Error("bankCardToken is required");
}
var transition = {
transition: "DE_ACTIVATED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/bank-cards/" + encodeURIComponent(bankCardToken) + "/status-transitions", transition, {}, callback);
}
/**
* Create a bank card status transition
*
* @param {string} userToken - The user token
* @param {string} bankCardToken - The bank card token
* @param {Object} data - The bank card status transition data
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or bankCardToken is not provided
*/
}, {
key: "createBankCardStatusTransition",
value: function createBankCardStatusTransition(userToken, bankCardToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!bankCardToken) {
throw new Error("bankCardToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/bank-cards/" + encodeURIComponent(bankCardToken) + "/status-transitions", data, {}, callback);
}
/**
* Get a bank card status transition
*
* @param {string} userToken - The user token
* @param {string} bankCardToken - The bank card token
* @param {string} statusTransitionToken - The bank card status transition token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken, bankCardToken or statusTransitionToken is not provided
*/
}, {
key: "getBankCardStatusTransition",
value: function getBankCardStatusTransition(userToken, bankCardToken, statusTransitionToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!bankCardToken) {
throw new Error("bankCardToken is required");
}
if (!statusTransitionToken) {
throw new Error("statusTransitionToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/bank-cards/" + encodeURIComponent(bankCardToken) + "/status-transitions/" + encodeURIComponent(statusTransitionToken), {}, callback);
}
/**
* List all bank card status transitions
*
* @param {string} userToken - The user token
* @param {string} bankCardToken - The bank card token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or bankCardToken is not provided
*/
}, {
key: "listBankCardStatusTransitions",
value: function listBankCardStatusTransitions(userToken, bankCardToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!bankCardToken) {
throw new Error("bankCardToken is required");
}
var LIST_BANK_CARD_STATUS_TRANSITION_FILTERS = ["transition", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_BANK_CARD_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_CARD_STATUS_TRANSITION_FILTERS));
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/bank-cards/" + encodeURIComponent(bankCardToken) + "/status-transitions", options, Hyperwallet.handle204Response(callback));
}
//--------------------------------------
// Authentication Token
//--------------------------------------
/**
* Get authentication token
*
* @param {string} userToken - The user token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "getAuthenticationToken",
value: function getAuthenticationToken(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/authentication-token", {}, {}, callback);
}
//--------------------------------------
// Paper Checks
//--------------------------------------
/**
* Create a paper check
*
* @param {string} userToken - The user token
* @param {Object} data - The paper check data
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "createPaperCheck",
value: function createPaperCheck(userToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/paper-checks", data, {}, callback);
}
/**
* Get a paper check
*
* @param {string} userToken - The user token
* @param {string} paperCheckToken - The paper check token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or paperCheckToken is not provided
*/
}, {
key: "getPaperCheck",
value: function getPaperCheck(userToken, paperCheckToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!paperCheckToken) {
throw new Error("paperCheckToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/paper-checks/" + encodeURIComponent(paperCheckToken), {}, callback);
}
/**
* Update a paper check
*
* @param {string} userToken - The user token
* @param {string} paperCheckToken - The paper check token
* @param {Object} data - The paper check data to update
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or paperCheckToken is not provided
*/
}, {
key: "updatePaperCheck",
value: function updatePaperCheck(userToken, paperCheckToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!paperCheckToken) {
throw new Error("paperCheckToken is required");
}
this.client.doPut("users/" + encodeURIComponent(userToken) + "/paper-checks/" + encodeURIComponent(paperCheckToken), data, {}, callback);
}
/**
* List all paper checks
*
* @param {string} userToken - The user token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "listPaperChecks",
value: function listPaperChecks(userToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
var LIST_PAPER_CHECKS_FILTERS = ["status", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_PAPER_CHECKS_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_PAPER_CHECKS_FILTERS));
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/paper-checks", options, Hyperwallet.handle204Response(callback));
}
/**
* Deactivate a paper check
*
* @param {string} userToken - The user token
* @param {string} paperCheckToken - The paper check token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or paperCheckToken is not provided
*/
}, {
key: "deactivatePaperCheck",
value: function deactivatePaperCheck(userToken, paperCheckToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!paperCheckToken) {
throw new Error("paperCheckToken is required");
}
var transition = {
transition: "DE_ACTIVATED"
};
this.client.doPost("users/" + encodeURIComponent(userToken) + "/paper-checks/" + encodeURIComponent(paperCheckToken) + "/status-transitions", transition, {}, callback);
}
/**
* Create a paper check status transition
*
* @param {string} userToken - The user token
* @param {string} paperCheckToken - The paper check token
* @param {Object} data - The paper check status transition data
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or paperCheckToken is not provided
*/
}, {
key: "createPaperCheckStatusTransition",
value: function createPaperCheckStatusTransition(userToken, paperCheckToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!paperCheckToken) {
throw new Error("paperCheckToken is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/paper-checks/" + encodeURIComponent(paperCheckToken) + "/status-transitions", data, {}, callback);
}
/**
* Get a paper check status transition
*
* @param {string} userToken - The user token
* @param {string} paperCheckToken - The paper check token
* @param {string} statusTransitionToken - The paper check status transition token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken, paperCheckToken or statusTransitionToken is not provided
*/
}, {
key: "getPaperCheckStatusTransition",
value: function getPaperCheckStatusTransition(userToken, paperCheckToken, statusTransitionToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!paperCheckToken) {
throw new Error("paperCheckToken is required");
}
if (!statusTransitionToken) {
throw new Error("statusTransitionToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/paper-checks/" + encodeURIComponent(paperCheckToken) + "/status-transitions/" + encodeURIComponent(statusTransitionToken), {}, callback);
}
/**
* List all paper check status transitions
*
* @param {string} userToken - The user token
* @param {string} paperCheckToken - The paper check token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or paperCheckToken is not provided
*/
}, {
key: "listPaperCheckStatusTransitions",
value: function listPaperCheckStatusTransitions(userToken, paperCheckToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!paperCheckToken) {
throw new Error("paperCheckToken is required");
}
var LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS = ["transition", "createdBefore", "createdAfter", "sortBy", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS));
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/paper-checks/" + encodeURIComponent(paperCheckToken) + "/status-transitions", options, Hyperwallet.handle204Response(callback));
}
//--------------------------------------
// Transfers
//--------------------------------------
/**
* Create a transfer
*
* @param {Object} data - The transfer data
* @param {api-callback} callback - The callback for this call
*/
}, {
key: "createTransfer",
value: function createTransfer(data, callback) {
if (!data.sourceToken) {
throw new Error("sourceToken is required");
}
if (!data.destinationToken) {
throw new Error("destinationToken is required");
}
if (!data.clientTransferId) {
throw new Error("clientTransferId is required");
}
this.client.doPost("transfers", data, {}, callback);
}
/**
* Get a transfer
*
* @param {string} transferToken - The transfer token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if transferToken is not provided
*/
}, {
key: "getTransfer",
value: function getTransfer(transferToken, callback) {
if (!transferToken) {
throw new Error("transferToken is required");
}
this.client.doGet("transfers/" + encodeURIComponent(transferToken), {}, callback);
}
/**
* List all transfers
*
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
*/
}, {
key: "listTransfers",
value: function listTransfers(options, callback) {
var LIST_TRANSFERS_FILTERS = ["clientTransferId", "sourceToken", "destinationToken", "createdBefore", "createdAfter", "limit"];
if (options && !Hyperwallet.isValidFilter(options, LIST_TRANSFERS_FILTERS)) {
throw new Error("Invalid Filter. Expected - ".concat(LIST_TRANSFERS_FILTERS));
}
this.client.doGet("transfers", options, Hyperwallet.handle204Response(callback));
}
/**
* Create a transfer status transition
*
* @param {string} transferToken - The transfer token
* @param {Object} data - The transfer status transition data
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if transferToken is not provided
*/
}, {
key: "createTransferStatusTransition",
value: function createTransferStatusTransition(transferToken, data, callback) {
if (!transferToken) {
throw new Error("transferToken is required");
}
this.client.doPost("transfers/" + encodeURIComponent(transferToken) + "/status-transitions", data, {}, callback);
}
//--------------------------------------
// Transfer Refunds
//--------------------------------------
/**
* Create a transfer refund
*
* @param {string} transferToken - The transfer token
* @param {Object} data - The transfer refund data
* @param {api-callback} callback - The callback for this call
*/
}, {
key: "createTransferRefund",
value: function createTransferRefund(transferToken, data, callback) {
if (!transferToken) {
throw new Error("transferToken is required");
}
if (!data.clientRefundId) {
throw new Error("clientRefundId is required");
}
this.client.doPost("transfers/" + encodeURIComponent(transferToken) + "/refunds", data, {}, callback);
}
/**
* Get a transfer
*
* @param {string} transferToken - The transfer token
* @param {string} transferRefundToken - The transfer refund token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if transferToken is not provided
*/
}, {
key: "getTransferRefund",
value: function getTransferRefund(transferToken, transferRefundToken, callback) {
if (!transferToken) {
throw new Error("transferToken is required");
}
if (!transferRefundToken) {
throw new Error("transferRefundToken is required");
}
this.client.doGet("transfers/" + encodeURIComponent(transferToken) + "/refunds/" + encodeURIComponent(transferRefundToken), {}, callback);
}
/**
* List all transfers
*
* @param {string} transferToken - The transfer token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
*/
}, {
key: "listTransferRefunds",
value: function listTransferRefunds(transferToken, options, callback) {
if (!transferToken) {
throw new Error("transferToken is required");
}
this.client.doGet("transfers/" + encodeURIComponent(transferToken) + "/refunds", options, Hyperwallet.handle204Response(callback));
}
//--------------------------------------
// PayPal Accounts
//--------------------------------------
/**
* Create a PayPal account
*
* @param {string} userToken - The user token
* @param {Object} data - The PayPal account data
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "createPayPalAccount",
value: function createPayPalAccount(userToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!data.transferMethodCountry) {
throw new Error("transferMethodCountry is required");
}
if (!data.transferMethodCurrency) {
throw new Error("transferMethodCurrency is required");
}
if (!data.email && !data.accountId) {
throw new Error("email or accountId is required");
}
this.client.doPost("users/" + encodeURIComponent(userToken) + "/paypal-accounts", data, {}, callback);
}
/**
* Get a PayPal account
*
* @param {string} userToken - The user token
* @param {string} payPalAccountToken - The PayPal account token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or payPalAccountToken is not provided
*/
}, {
key: "getPayPalAccount",
value: function getPayPalAccount(userToken, payPalAccountToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!payPalAccountToken) {
throw new Error("payPalAccountToken is required");
}
this.client.doGet("users/" + encodeURIComponent(userToken) + "/paypal-accounts/" + encodeURIComponent(payPalAccountToken), {}, callback);
}
/**
* List all PayPal accounts
*
* @param {string} userToken - The user token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken is not provided
*/
}, {
key: "listPayPalAccounts",
value: function listPayPalAccounts(userToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");