UNPKG

@ovh-ux/ng-ovh-payment-method

Version:
1,665 lines (1,533 loc) 1.73 MB
function cssInjectd2eb86aab3d25bc2(css) { if (!css || typeof document === 'undefined') return ''; const head = document.head || document.getElementsByTagName('head')[0]; const style = document.createElement('style'); style.type = 'text/css'; if (style.styleSheet) { // for IE style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); return css; } function ___$insertStyle(css) { if (!css || typeof window === 'undefined') { return; } const style = document.createElement('style'); style.setAttribute('type', 'text/css'); style.innerHTML = css; document.head.appendChild(style); return css; } import angular from 'angular'; import 'angular-translate'; import '@ovh-ux/ng-translate-async-loader'; import '@ovh-ux/manager-core'; import '@ovh-ux/ui-kit'; function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread2$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty$3(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _toPrimitive$1(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toPropertyKey$1(t) { var i = _toPrimitive$1(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _typeof$3(o) { "@babel/helpers - typeof"; return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$3(o); } function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties$4(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, _toPropertyKey$1(descriptor.key), descriptor); } } function _createClass$4(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$4(Constructor.prototype, protoProps); if (staticProps) _defineProperties$4(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _defineProperty$3(obj, key, value) { key = _toPropertyKey$1(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var PAYMENT_MEAN_STATUS_ENUM = { BLOCKED_FOR_INCIDENTS: 'BLOCKED_FOR_INCIDENTS', PENDING_VALIDATION: 'PENDING_VALIDATION', VALID: 'VALID', EXPIRED: 'EXPIRED', TOO_MANY_FAILURES: 'TOO_MANY_FAILURES' }; var AVAILABLE_PAYMENT_METHOD_TYPE_ENUM = { BANK_ACCOUNT: 'BANK_ACCOUNT', CREDIT_CARD: 'CREDIT_CARD', DEFERRED_PAYMENT_ACCOUNT: 'DEFERRED_PAYMENT_ACCOUNT', PAYPAL: 'PAYPAL', SEPA_DIRECT_DEBIT: 'SEPA_DIRECT_DEBIT', RUPAY: 'RUPAY' }; var AVAILABLE_PAYMENT_METHOD_INTEGRATION_ENUM = { COMPONENT: 'COMPONENT', NONE: 'NONE', REDIRECT: 'REDIRECT', IFRAME_VANTIV: 'IFRAME_VANTIV', IN_CONTEXT: 'IN_CONTEXT', POST_FORM: 'POST_FORM' }; var PAYMENT_METHOD_STATUS_ENUM = { CANCELED: 'CANCELED', CANCELING: 'CANCELING', CREATED: 'CREATED', ERROR: 'ERROR', EXPIRED: 'EXPIRED', FAILED: 'FAILED', CREATING: 'CREATING', MAINTENANCE: 'MAINTENANCE', PAUSED: 'PAUSED', TOO_MANY_FAILURES: 'TOO_MANY_FAILURES', VALID: 'VALID' }; function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty$2(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _toPrimitive(t, r) { if ("object" != _typeof$3(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof$3(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof$3(i) ? i : i + ""; } function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties$3(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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass$3(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$3(Constructor.prototype, protoProps); if (staticProps) _defineProperties$3(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _defineProperty$2(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /** * Checks if `value` is `null`. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is `null`, else `false`. * @example * * _.isNull(null); * // => true * * _.isNull(void 0); * // => false */ function isNull(value) { return value === null; } /** * Describe a payment method type object. */ var PaymentMethodType = /*#__PURE__*/function () { /** * Create a OvhPaymentMethodType. * * @param {String} paymentType The name of the payment type. * @param {String} humanReadableName The human readable name of the payment type. */ function PaymentMethodType(paymentType, humanReadableName) { _classCallCheck$3(this, PaymentMethodType); /** * Name of the type of a payment method. * Will be use for helper class below. * @type {String} */ this.paymentType = paymentType; /** * The human readable name of the payment type * @type {String} */ this.humanReadableName = humanReadableName !== null && humanReadableName !== void 0 ? humanReadableName : ''; } /** * Determine if payment method type is a Bank Account. * * @return {Boolean} */ return _createClass$3(PaymentMethodType, [{ key: "isBankAccount", value: function isBankAccount() { return this.paymentType === AVAILABLE_PAYMENT_METHOD_TYPE_ENUM.BANK_ACCOUNT; } /** * Determine if payment method type is a SEPA direct debit. * * @return {Boolean} */ }, { key: "isSepaDirectDebit", value: function isSepaDirectDebit() { return this.paymentType === AVAILABLE_PAYMENT_METHOD_TYPE_ENUM.SEPA_DIRECT_DEBIT; } /** * Determine if payment method type is a Credit Card. * * @return {Boolean} */ }, { key: "isCreditCard", value: function isCreditCard() { return this.paymentType === AVAILABLE_PAYMENT_METHOD_TYPE_ENUM.CREDIT_CARD; } /** * Determine if payment method type is a RuPay card. * * @return {Boolean} */ }, { key: "isRupayCard", value: function isRupayCard() { return this.paymentType === AVAILABLE_PAYMENT_METHOD_TYPE_ENUM.RUPAY; } /** * Determine if payment method type is a Deferred Payment Account. * * @return {Boolean} */ }, { key: "isDeferredPaymentAccount", value: function isDeferredPaymentAccount() { return this.paymentType === AVAILABLE_PAYMENT_METHOD_TYPE_ENUM.DEFERRED_PAYMENT_ACCOUNT; } /** * Determine if payment method type is a Paypal account. * * @return {Boolean} */ }, { key: "isPaypal", value: function isPaypal() { return this.paymentType === AVAILABLE_PAYMENT_METHOD_TYPE_ENUM.PAYPAL; } }]); }(); /** * Describe an available payment method object. */ var AvailablePaymentMethod = /*#__PURE__*/function () { /** * Create a AvailablePaymentMethod. * * @param {Object} options Options for creating a new AvailablePaymentMethod object. * @param {Object} options.icon Informations about the payment method type icon. * @param {String} options.icon.name Name of the icon. * @param {String} options.icon.data Icon in base64. * @param {String} options.icon.className Icon css class name. * @param {String} options.integration Type of integration of the payment type. * @param {Boolean} options.oneshot Flag indicating if we can use the payment method type * for oneshot payment. * @param {String} options.paymentType The name of the payment method type. * @param {String} options.humanReadableName The human readable name of the payment type. * @param {Boolean} options.registerable Flag indicating if we can register the payment type. * @param {Boolean} options.registerableWithTransaction Flag indicating if we can register the * payment type and in the same time * pay an order. * @param {Object} [options.original] An OvhPaymentMeanType object instance if legacy. */ function AvailablePaymentMethod(options) { _classCallCheck$3(this, AvailablePaymentMethod); /** * Informations about the payment method type icon. * This object is represented by the icon name and the icon data. * @type {Object} */ this.icon = options.icon; /** * Type of integration of the payment type. * @type {String} */ this.integration = options.integration; /** * Merchant id to use in case of component integration type. * @type {String} */ this.merchantId = options.merchantId; /** * Flag indicating if we can use the payment method type for oneshot payment. * @type {Boolean} */ this.oneshot = options.oneshot; /** * The type of the payment method. * @type {PaymentMethodType} */ this.type = new PaymentMethodType(options.paymentType, options.humanReadableName); /** * Flag indicating if we can register the payment type. * @type {Boolean} */ this.registerable = options.registerable; /** * Flag indicating if we can register the payment type and in the same time pay an order. * @type {Boolean} */ this.registerableWithTransaction = options.registerableWithTransaction; /** * An OvhPaymentMeanType object instance representing a legacy payment mean type. * @type {Object} */ this.original = options.original || null; /** * The optional form session id required by some integration components * @type {String} */ this.formSessionId = options.formSessionId || null; } /** * Get the name of the payment type. For retro-compatibility. * @return {String} The name of the payment type. */ return _createClass$3(AvailablePaymentMethod, [{ key: "paymentType", get: function get() { return this.type.paymentType; } /** * Determine if payment method type is a legacy one (if original attribute is setted). * @return {Boolean} true if payment method type is legacy, false otherwise. */ }, { key: "isLegacy", value: function isLegacy() { return !isNull(this.original); } /** * Determine if payment method type require a billing contact id when creating it. * This method uses the integration attribute to determine it. * @return {Boolean} true if type requires a billing contact id false otherwise. */ }, { key: "isRequiringContactId", value: function isRequiringContactId() { return [AVAILABLE_PAYMENT_METHOD_INTEGRATION_ENUM.IFRAME_VANTIV].includes(this.integration); } /** * Determine if payment method type requires finalization. * This method uses the integration attribute to determine it. * @return {Boolean} true if type requires finalization false otherwise. */ }, { key: "isRequiringFinalization", value: function isRequiringFinalization() { return [AVAILABLE_PAYMENT_METHOD_INTEGRATION_ENUM.IFRAME_VANTIV, AVAILABLE_PAYMENT_METHOD_INTEGRATION_ENUM.IN_CONTEXT].includes(this.integration); } /** * Determine if payment method type requires component to handle the register. * The component may have its own submit logic. * This method uses the integration attribute to determine it. * @return {Boolean} true if type requires inputs false otherwise. */ }, { key: "isHandleByComponent", value: function isHandleByComponent() { return [AVAILABLE_PAYMENT_METHOD_INTEGRATION_ENUM.COMPONENT].includes(this.integration); } }]); }(); /** * Describe a payment method object. */ var PaymentMethod = /*#__PURE__*/function () { /** * Create a PaymentMethod. * * @param {Object} options Options for creating a new PaymentMethod object. * @param {Object} [options.icon] Informations about the payment method type icon. * @param {String} options.icon.name Name of the icon. * @param {String} options.icon.data Icon in base64. * @param {String} [options.paymentSubType] Subtype of the payment method. * eg: "VISA" for the payment type "CREDIT_CARD". * @param {String} options.status The status of the payment method. * @param {Number} options.paymentMethodId The unique payment method ID. * @param {Boolean} options.default Flag indicating if the payment method is the default one. * @param {String} [options.description] Custom customer description. * @param {String} [options.expirationDate] Expiration date of the payment method. * @param {String} options.paymentType Payment method type. * @param {Number} [options.billingContactId] The ID of the associated billing contact. * @param {String} [options.lastUpdate] Last update date of the payment method. * @param {String} [options.creationDate] Creation date of the payment method. * @param {Number} [options.paymentMeanId] Payment mean ID associated to this payment method. * Used to ensure migration. * @param {Number} [options.label] Payment method public label. * @param {Object} [options.original] An OvhPaymentMean object instance if legacy. */ function PaymentMethod(options) { _classCallCheck$3(this, PaymentMethod); /** * Informations about the payment method type icon. * This object is represented by the icon name and the icon data. * @type {Object} */ this.icon = options.icon; /** * Subtype of the payment method (eg: "VISA" for the payment type "CREDIT_CARD"). * @type {String} */ this.paymentSubType = options.paymentSubType; /** * The status of the payment method. * @type {String} */ this.status = options.status; /** * The unique payment method ID. * @type {Number} */ this.paymentMethodId = options.paymentMethodId; /** * Flag indicating if the payment method is the default one. * @type {Boolean} * @default false */ this["default"] = options["default"] || false; /** * Custom customer description. * @type {String} * @default null */ this.description = options.description; /** * Expiration date of the payment method. * @type {Date} * @default null */ this.expirationDate = options.expirationDate ? new Date(options.expirationDate) : null; /** * The type of the payment method. * @type {PaymentMethodType} */ this.type = new PaymentMethodType(options.paymentType); /** * The type of the payment method. * @type {PaymentMethodType} */ // this.type = new PaymentMethodType(options.paymentType); /** * The ID of the associated billing contact. * @type {Number} * @default null */ this.billingContactId = options.billingContactId || null; /** * Last update date of the payment method. * @type {Date} */ this.lastUpdate = new Date(options.lastUpdate); /** * Creation date of the payment method. * @type {Date} */ this.creationDate = new Date(options.creationDate); /** * Payment mean ID associated to this payment method. This is used to ensure migration * from paymentMean to paymentMethod. * @type {String} * @default null */ this.paymentMeanId = options.paymentMeanId || null; /** * Payment method public label. * @type {String} * @default null */ this.label = options.label || null; /** * An OvhPaymentMean object instance representing a legacy payment mean. * @type {Object} */ this.original = options.original || null; } /** * Get the name of the payment type. For retro-compatibility. * @return {String} The name of the payment type. */ return _createClass$3(PaymentMethod, [{ key: "paymentType", get: function get() { return this.type.paymentType; } /** * Determine if payment method is a legacy one (if original attribute is setted). * @return {Boolean} true if payment method is legacy, false otherwise. */ }, { key: "isLegacy", value: function isLegacy() { return !isNull(this.original); } }, { key: "isValid", value: function isValid() { return this.getStatusCategory() === 'success'; } /** * Returns the category of the status between : 'error', 'warning', 'info', 'success'. * The category is a pure frontend value and is set arbitrarily. It is meant to be used * for displaying and formatting the status correctly. * @return {String} category */ }, { key: "getStatusCategory", value: function getStatusCategory() { switch (this.status) { case PAYMENT_METHOD_STATUS_ENUM.CANCELED: case PAYMENT_METHOD_STATUS_ENUM.ERROR: case PAYMENT_METHOD_STATUS_ENUM.EXPIRED: case PAYMENT_METHOD_STATUS_ENUM.TOO_MANY_FAILURES: return 'error'; case PAYMENT_METHOD_STATUS_ENUM.CANCELING: case PAYMENT_METHOD_STATUS_ENUM.CREATING: case PAYMENT_METHOD_STATUS_ENUM.MAINTENANCE: case PAYMENT_METHOD_STATUS_ENUM.PAUSED: return 'warning'; case PAYMENT_METHOD_STATUS_ENUM.CREATED: case PAYMENT_METHOD_STATUS_ENUM.VALID: return 'success'; default: return 'info'; } } }]); }(); var DEFAULT_GET_OPTIONS = { onlyValid: false, transform: true // transform legacy payment methods to payment methods }; var DEFAULT_GET_AVAILABLE_OPTIONS = { onlyRegisterable: true, transform: true // transform legacy payment method types to payment method types }; var useOvhPaymentMethod = function useOvhPaymentMethod(_ref) { var reketInstance = _ref.reketInstance; var usedReketInstance = reketInstance; /*= ================================================ = Available Payment Methods = ================================================= */ var getAvailablePaymentMethods = function getAvailablePaymentMethods() { var onlyRegisterable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_GET_AVAILABLE_OPTIONS.onlyRegisterable; return usedReketInstance.get('/me/payment/availableMethods').then(function (availableMethods) { var availablePaymentMethods = onlyRegisterable ? availableMethods.filter(function (_ref2) { var registerable = _ref2.registerable; return registerable; }) : availableMethods; return availablePaymentMethods.map(function (availableMethod) { return new AvailablePaymentMethod(availableMethod); }); })["catch"](function (error) { return error.status === 404 ? [] : Promise.reject(error); }); }; /** * Get all the available payment method * @return {Promise} That returns a list of available payment methods */ var getAllAvailablePaymentMethods = function getAllAvailablePaymentMethods() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_GET_AVAILABLE_OPTIONS; return getAvailablePaymentMethods(options.onlyRegisterable).then(function (availablePaymentMethods) { return availablePaymentMethods; }); }; /* ----- End of Available Payment Methods ------*/ /*= ================================================= = Actions on payment methods = ================================================== */ /** * Add an new payment method */ var addPaymentMethod = function addPaymentMethod(availablePaymentMethod) { var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return usedReketInstance.post('/me/payment/method', _objectSpread2(_objectSpread2({}, params), {}, { paymentType: availablePaymentMethod.paymentType })).then(function (response) { if (params.orderId && response.paymentMethodId) { return usedReketInstance.post("/me/order/".concat(params.orderId, "/pay"), { paymentMethod: { id: response.paymentMethodId } }); } return response; }); }; /** * Edit given payment method * * @param {PaymentMethod} paymentMethod The payment method to edit * @param {Object} params The attributes of payment method to edit * @return {Promise} That returns */ var editPaymentMethod = function editPaymentMethod(paymentMethod, params) { return usedReketInstance.put("/me/payment/method/".concat(paymentMethod.paymentMethodId), params); }; /** * Set given payment method as default. * * @param {PaymentMethod} paymentMethod The payment method to set as default * @return {Promise} */ var setDefaultPaymentMethod = function setDefaultPaymentMethod(paymentMethod) { return editPaymentMethod(paymentMethod, { "default": true }); }; /** * Challenge given payment method. * @param {PaymentMethod} paymentMethod The payment method to challenge * @param {Object} challenge The challenge value * @return {Promise} */ var challengePaymentMethod = function challengePaymentMethod(paymentMethod, challenge) { return usedReketInstance.post("/me/payment/method/".concat(paymentMethod.paymentMethodId, "/challenge"), { challenge: challenge }); }; /** * Add details to your payment method challenge. * @param {Number} paymentMethodId The payment method to add details * @param {Object} details The details to add * @return {Promise} Which returns an object representing a payment method valdiation. */ var addPaymentMethodDetails = function addPaymentMethodDetails(paymentMethodId, details) { return usedReketInstance.post("/me/payment/method/".concat(paymentMethodId, "/details"), details); }; /** * Finalize given payment method registration * @param {Object} paymentMethodValidation The payment method validation object to finalize. * @param {Object} finalizeData The data needed for finalizing the payment method * registration. * @return {Promise} Which returns an instance of PaymentMethod. */ var finalizePaymentMethod = function finalizePaymentMethod(paymentMethodValidation) { var finalizeData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return usedReketInstance.post("/me/payment/method/".concat(paymentMethodValidation.paymentMethodId, "/finalize"), finalizeData).then(function (paymentMethodOptions) { return new PaymentMethod(paymentMethodOptions); }); }; /** * Delete given payment method. * @param {PaymentMethod} paymentMethod The paymentMethod to delete * @return {Promise} */ var deletePaymentMethod = function deletePaymentMethod(paymentMethod) { return usedReketInstance["delete"]("/me/payment/method/".concat(paymentMethod.paymentMethodId)); }; /* ----- End of Actions on payment methods ------*/ /** * Get the details of a single payment method. * This is the result of the call to GET /me/payment/method/{paymentMethodId} * * @param {Number} paymentMethodId The payment method id to get * @return {PaymentMethod} The details of the desired payment method */ var getPaymentMethod = function getPaymentMethod(paymentMethodId) { return usedReketInstance.get("/me/payment/method/".concat(paymentMethodId)).then(function (paymentMethodOptions) { return new PaymentMethod(paymentMethodOptions); }); }; /** * Get the payment methods returned by /me/payment/method APIs * * @param {Obejct} options Options to get the payment methods * @return {Promise} That returns an Array of PaymentMethod instances */ var getPaymentMethods = function getPaymentMethods() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_GET_OPTIONS; var params = options.onlyValid ? { status: PAYMENT_METHOD_STATUS_ENUM.VALID } : {}; return usedReketInstance.get('/me/payment/method', { params: params }).then(function (paymentMethodIds) { return Promise.all(paymentMethodIds.map(function (paymentMethodId) { return getPaymentMethod(paymentMethodId); })); })["catch"](function (error) { return error.status === 404 ? [] : Promise.reject(error); }); }; /*= ============================================= = Default payment method = ============================================== */ /** * Get the default payment method of the user. * @return {Promise} That returns the default payment method instance. */ var getDefaultPaymentMethod = function getDefaultPaymentMethod() { return getPaymentMethods({ onlyValid: true, transform: true }).then(function (paymentMethods) { return paymentMethods.find(function (method) { return method["default"]; }) || null; }); }; /** * Check if connected user has a default payment method. * @return {Promise} That returns a boolean */ var hasDefaultPaymentMethod = function hasDefaultPaymentMethod() { return getDefaultPaymentMethod().then(function (method) { return !!method; }); }; /* ----- End of Default payment method ------*/ return { addPaymentMethod: addPaymentMethod, editPaymentMethod: editPaymentMethod, setDefaultPaymentMethod: setDefaultPaymentMethod, challengePaymentMethod: challengePaymentMethod, addPaymentMethodDetails: addPaymentMethodDetails, finalizePaymentMethod: finalizePaymentMethod, deletePaymentMethod: deletePaymentMethod, getAvailablePaymentMethods: getAvailablePaymentMethods, getAllAvailablePaymentMethods: getAllAvailablePaymentMethods, getPaymentMethod: getPaymentMethod, getPaymentMethods: getPaymentMethods, getDefaultPaymentMethod: getDefaultPaymentMethod, hasDefaultPaymentMethod: hasDefaultPaymentMethod }; }; /** Detect free variable `global` from Node.js. */ var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof$3(global)) == 'object' && global && global.Object === Object && global; var freeGlobal$1 = freeGlobal; /** Detect free variable `self`. */ var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof$3(self)) == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ var root = freeGlobal$1 || freeSelf || Function('return this')(); var root$1 = root; /** Built-in value references. */ var _Symbol$5 = root$1.Symbol; var _Symbol$6 = _Symbol$5; /** Used for built-in method references. */ var objectProto$h = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$f = objectProto$h.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString$1 = objectProto$h.toString; /** Built-in value references. */ var symToStringTag$1 = _Symbol$6 ? _Symbol$6.toStringTag : undefined; /** * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. * * @private * @param {*} value The value to query. * @returns {string} Returns the raw `toStringTag`. */ function getRawTag(value) { var isOwn = hasOwnProperty$f.call(value, symToStringTag$1), tag = value[symToStringTag$1]; try { value[symToStringTag$1] = undefined; var unmasked = true; } catch (e) {} var result = nativeObjectToString$1.call(value); if (unmasked) { if (isOwn) { value[symToStringTag$1] = tag; } else { delete value[symToStringTag$1]; } } return result; } /** Used for built-in method references. */ var objectProto$g = Object.prototype; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString = objectProto$g.toString; /** * Converts `value` to a string using `Object.prototype.toString`. * * @private * @param {*} value The value to convert. * @returns {string} Returns the converted string. */ function objectToString$1(value) { return nativeObjectToString.call(value); } /** `Object#toString` result references. */ var nullTag = '[object Null]', undefinedTag = '[object Undefined]'; /** Built-in value references. */ var symToStringTag = _Symbol$6 ? _Symbol$6.toStringTag : undefined; /** * The base implementation of `getTag` without fallbacks for buggy environments. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ function baseGetTag(value) { if (value == null) { return value === undefined ? undefinedTag : nullTag; } return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString$1(value); } /** * Checks if `value` is object-like. A value is object-like if it's not `null` * and has a `typeof` result of "object". * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is object-like, else `false`. * @example * * _.isObjectLike({}); * // => true * * _.isObjectLike([1, 2, 3]); * // => true * * _.isObjectLike(_.noop); * // => false * * _.isObjectLike(null); * // => false */ function isObjectLike(value) { return value != null && _typeof$3(value) == 'object'; } /** `Object#toString` result references. */ var symbolTag$3 = '[object Symbol]'; /** * Checks if `value` is classified as a `Symbol` primitive or object. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * * _.isSymbol(Symbol.iterator); * // => true * * _.isSymbol('abc'); * // => false */ function isSymbol$2(value) { return _typeof$3(value) == 'symbol' || isObjectLike(value) && baseGetTag(value) == symbolTag$3; } /** * A specialized version of `_.map` for arrays without support for iteratee * shorthands. * * @private * @param {Array} [array] The array to iterate over. * @param {Function} iteratee The function invoked per iteration. * @returns {Array} Returns the new mapped array. */ function arrayMap(array, iteratee) { var index = -1, length = array == null ? 0 : array.length, result = Array(length); while (++index < length) { result[index] = iteratee(array[index], index, array); } return result; } /** * Checks if `value` is classified as an `Array` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array, else `false`. * @example * * _.isArray([1, 2, 3]); * // => true * * _.isArray(document.body.children); * // => false * * _.isArray('abc'); * // => false * * _.isArray(_.noop); * // => false */ var isArray$8 = Array.isArray; var isArray$9 = isArray$8; /** Used as references for various `Number` constants. */ var INFINITY$2 = 1 / 0; /** Used to convert symbols to primitives and strings. */ var symbolProto$2 = _Symbol$6 ? _Symbol$6.prototype : undefined, symbolToString = symbolProto$2 ? symbolProto$2.toString : undefined; /** * The base implementation of `_.toString` which doesn't convert nullish * values to empty strings. * * @private * @param {*} value The value to process. * @returns {string} Returns the string. */ function baseToString(value) { // Exit early for strings to avoid a performance hit in some environments. if (typeof value == 'string') { return value; } if (isArray$9(value)) { // Recursively convert values (susceptible to call stack limits). return arrayMap(value, baseToString) + ''; } if (isSymbol$2(value)) { return symbolToString ? symbolToString.call(value) : ''; } var result = value + ''; return result == '0' && 1 / value == -INFINITY$2 ? '-0' : result; } /** Used to match a single whitespace character. */ var reWhitespace = /\s/; /** * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace * character of `string`. * * @private * @param {string} string The string to inspect. * @returns {number} Returns the index of the last non-whitespace character. */ function trimmedEndIndex(string) { var index = string.length; while (index-- && reWhitespace.test(string.charAt(index))) {} return index; } /** Used to match leading whitespace. */ var reTrimStart = /^\s+/; /** * The base implementation of `_.trim`. * * @private * @param {string} string The string to trim. * @returns {string} Returns the trimmed string. */ function baseTrim(string) { return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') : string; } /** * Checks if `value` is the * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an object, else `false`. * @example * * _.isObject({}); * // => true * * _.isObject([1, 2, 3]); * // => true * * _.isObject(_.noop); * // => true * * _.isObject(null); * // => false */ function isObject$2(value) { var type = _typeof$3(value); return value != null && (type == 'object' || type == 'function'); } /** Used as references for various `Number` constants. */ var NAN = 0 / 0; /** Used to detect bad signed hexadecimal string values. */ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; /** Used to detect binary string values. */ var reIsBinary = /^0b[01]+$/i; /** Used to detect octal string values. */ var reIsOctal = /^0o[0-7]+$/i; /** Built-in method references without a dependency on `root`. */ var freeParseInt = parseInt; /** * Converts `value` to a number. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to process. * @returns {number} Returns the number. * @example * * _.toNumber(3.2); * // => 3.2 * * _.toNumber(Number.MIN_VALUE); * // => 5e-324 * * _.toNumber(Infinity); * // => Infinity * * _.toNumber('3.2'); * // => 3.2 */ function toNumber(value) { if (typeof value == 'number') { return value; } if (isSymbol$2(value)) { return NAN; } if (isObject$2(value)) { var other = typeof value.valueOf == 'function' ? value.valueOf() : value; value = isObject$2(other) ? other + '' : other; } if (typeof value != 'string') { return value === 0 ? value : +value; } value = baseTrim(value); var isBinary = reIsBinary.test(value); return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value; } /** Used as references for various `Number` constants. */ var INFINITY$1 = 1 / 0, MAX_INTEGER = 1.7976931348623157e+308; /** * Converts `value` to a finite number. * * @static * @memberOf _ * @since 4.12.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted number. * @example * * _.toFinite(3.2); * // => 3.2 * * _.toFinite(Number.MIN_VALUE); * // => 5e-324 * * _.toFinite(Infinity); * // => 1.7976931348623157e+308 * * _.toFinite('3.2'); * // => 3.2 */ function toFinite(value) { if (!value) { return value === 0 ? value : 0; } value = toNumber(value); if (value === INFINITY$1 || value === -INFINITY$1) { var sign = value < 0 ? -1 : 1; return sign * MAX_INTEGER; } return value === value ? value : 0; } /** * Converts `value` to an integer. * * **Note:** This method is loosely based on * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted integer. * @example * * _.toInteger(3.2); * // => 3 * * _.toInteger(Number.MIN_VALUE); * // => 0 * * _.toInteger(Infinity); * // => 1.7976931348623157e+308 * * _.toInteger('3.2'); * // => 3 */ function toInteger(value) { var result = toFinite(value), remainder = result % 1; return result === result ? remainder ? result - remainder : result : 0; } /** * This method returns the first argument it receives. * * @static * @since 0.1.0 * @memberOf _ * @category Util * @param {*} value Any value. * @returns {*} Returns `value`. * @example * * var object = { 'a': 1 }; * * console.log(_.identity(object) === object); * // => true */ function identity(value) { return value; } /** `Object#toString` result references. */ var asyncTag = '[object AsyncFunction]', funcTag$2 = '[object Function]', genTag$1 = '[object GeneratorFunction]', proxyTag = '[object Proxy]'; /** * Checks if `value` is classified as a `Function` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); * // => true * * _.isFunction(/abc/); * // => false */ function isFunction(value) { if (!isObject$2(value)) { return false; } // The use of `Object#toString` avoids issues with the `typeof` operator // in Safari 9 which returns 'object' for typed arrays and other constructors. var tag = baseGetTag(value); return tag == funcTag$2 || tag == genTag$1 || tag == asyncTag || tag == proxyTag; } /** Used to detect overreaching core-js shims. */ var coreJsData = root$1['__core-js_shared__']; var coreJsData$1 = coreJsData; /** Used to detect methods masquerading as native. */ var maskSrcKey = function () { var uid = /[^.]+$/.exec(coreJsData$1 && coreJsData$1.keys && coreJsData$1.keys.IE_PROTO || ''); return uid ? 'Symbol(src)_1.' + uid : ''; }(); /** * Checks if `func` has its source masked. * * @private * @param {Function} func The function to check. * @returns {boolean} Returns `true` if `func` is masked, else `false`. */ function isMasked(func) { return !!maskSrcKey && maskSrcKey in func; } /** Used for built-in method references. */ var funcProto$2 = Function.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString$2 = funcProto$2.toString; /** * Converts `func` to its source code. * * @private * @param {Function} func The function to convert. * @returns {string} Returns the source code. */ function toSource(func) { if (func != null) { try { return funcToString$2.call(func); } catch (e) {} try { return func + ''; } catch (e) {} } return ''; } /** * Used to match `RegExp` * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). */ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; /** Used to detect host constructors (Safari). */ var reIsHostCtor = /^\[object .+?Constructor\]$/; /** Used for built-in method references. */ var funcProto$1 = Function.prototype, objectProto$f = Object.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString$1 = funcProto$1.toString; /** Used to check objects for own properties. */ var hasOwnProperty$e = objectProto$f.hasOwnProperty; /** Used to detect if a method is native. */ var reIsNative = RegExp('^' + funcToString$1.call(hasOwnProperty$e).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'); /** * The base implementation of `_.isNative` without bad shim checks. * * @private * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a native function, * else `false`. */ function baseIsNative(value) { if (!isObject$2(value) || isMasked(value)) { return false; } var pattern = isFunction(value) ? reIsNative : reIsHostCtor; return pattern.test(toSource(value)); } /** * Gets the value at `key` of `object`. * * @private * @param {Object} [object] The object to query. * @param {string} key The key of the property to get. * @returns {*} Returns the property value. */ function getValue(object, key) { return object == null ? undefined : object[key]; } /** * Gets the native function at `key` of `object`. * * @private * @param {Object} object The object to query. * @param {string} key The key of the method to get. * @returns {*} Returns the function if it's native, else `undefined`. */ function getNative(object, key) { var value = getValue(object, key); return baseIsNative(value) ? value : undefined; } /* Built-in method references that are verified to be native. */ var WeakMap$3 = getNative(root$1, 'WeakMap'); var WeakMap$4 = WeakMap$3; /** Built-in value references. */ var objectCreate$1 = Object.create; /** * The base implementation of `_.create` without support for assigning * properties to the created object. * * @private * @param {Object} proto The object to inherit from. * @returns {Object} Returns the new object. */ var baseCreate = function () { function object() {} return function (proto) { if (!isObject$2(proto)) { return {}; } if (objectCreate$1) { return objectCreate$1(proto); } object.prototype = proto; var result = new object(); object.prototype = undefined; return result; }; }(); var baseCreate$1 = baseCreate; /** * A faster alternative to `Function#apply`, this function invokes `func` * with the `this` binding of `thisArg` and the arguments of `args`. * * @private * @param {Function} func The function to invoke. * @param {*} thisArg The `this` binding of `func`. * @param {Array} args The arguments to invoke `func` with. * @returns {*} Returns the result of `func`. */ function apply$2(func, thisArg, args) { switch (args.length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); case 2: return func.call(thisArg, args[0], args[1]); case 3: return func.call(thisArg, args[0], args[1], args[2]); } return func.apply(thisArg, args); } /** * This method returns `undefined`. * * @static * @memberOf _ * @since 2.3.0 * @category Util * @example * * _.times(2, _.noop); * // => [undefined, undefined] */ function noop$1() { // No operation performed. } /** * Copies the values of `source` to `array`. * * @private * @param {Array} source The array to copy values from. * @param {Array} [array=[]] The array to copy values to. * @returns {Array} Returns `array`. */ function copyArray(source, array) { var index = -1, length = source.length; array || (array = Array(length)); while (++index < length) { array[index] = source[index]; } return array; } /** Used to detect hot functions by number of calls within a span of milliseconds. */ var HOT_COUNT = 800, HOT_SPAN = 16; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeNow = Date.now; /** * Creates a function that'll short out and invoke `identity` instead * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` * milliseconds. * * @private * @param {Function} func The function to restrict. * @returns {Function} Returns the new shortable function. */ function shortOut(func) { var count = 0, lastCalled = 0; return function () { var stamp = nativeNow(), remaining = HOT_SPAN - (stamp - lastCalled); lastCalled = stamp; if (remaining > 0) { if (++count >= HOT_COUNT) { return arguments[0]; } } else { count = 0; } return func.apply(undefined, arguments); }; } /** * Creates a function that returns `value`. * * @static * @memberOf _ * @since 2.4.0 * @category Util * @param {*} value The value to return from the new function. * @returns {Function} Returns the new constant function. * @example * * var objects = _.times(2, _.constant({ 'a': 1 })); * * console.log(objects); * // => [{ 'a': 1 }, { 'a': 1 }] * * console.log(objects[0] === objects[1]); * // => true */ function constant(value) { return function () { return value; }; } var defineProperty$e = function () { try { var func = getNative(Object, 'definePr