@ovh-ux/ng-ovh-payment-method
Version:
Get payment methods from different OVHcloud APIs
1,415 lines (1,354 loc) • 1.64 MB
JavaScript
function cssInjectf6b23e0fefe4089e(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 axios from 'axios';
import '@ovh-ux/ui-kit';
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return _arrayLikeToArray(r);
}
function _classCallCheck$1(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties$1(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey$1(o.key), o);
}
}
function _createClass$1(e, r, t) {
return r && _defineProperties$1(e.prototype, r), t && _defineProperties$1(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _defineProperty$1(e, r, t) {
return (r = _toPropertyKey$1(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
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 _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.");
}
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 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$1(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$1(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 _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
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(o) {
"@babel/helpers - typeof";
return _typeof = "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(o);
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
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 asyncGeneratorStep(n, t, e, r, o, a, c) {
try {
var i = n[a](c),
u = i.value;
} catch (n) {
return void e(n);
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function () {
var t = this,
e = arguments;
return new Promise(function (r, o) {
var a = n.apply(t, e);
function _next(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
}
function _throw(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
}
_next(void 0);
});
};
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function ownKeys$1(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$1(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _regeneratorRuntime() {
_regeneratorRuntime = function _regeneratorRuntime() {
return e;
};
var t,
e = {},
r = Object.prototype,
n = r.hasOwnProperty,
o = Object.defineProperty || function (t, e, r) {
t[e] = r.value;
},
i = "function" == typeof Symbol ? Symbol : {},
a = i.iterator || "@@iterator",
c = i.asyncIterator || "@@asyncIterator",
u = i.toStringTag || "@@toStringTag";
function define(t, e, r) {
return Object.defineProperty(t, e, {
value: r,
enumerable: !0,
configurable: !0,
writable: !0
}), t[e];
}
try {
define({}, "");
} catch (t) {
define = function define(t, e, r) {
return t[e] = r;
};
}
function wrap(t, e, r, n) {
var i = e && e.prototype instanceof Generator ? e : Generator,
a = Object.create(i.prototype),
c = new Context(n || []);
return o(a, "_invoke", {
value: makeInvokeMethod(t, r, c)
}), a;
}
function tryCatch(t, e, r) {
try {
return {
type: "normal",
arg: t.call(e, r)
};
} catch (t) {
return {
type: "throw",
arg: t
};
}
}
e.wrap = wrap;
var h = "suspendedStart",
l = "suspendedYield",
f = "executing",
s = "completed",
y = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var p = {};
define(p, a, function () {
return this;
});
var d = Object.getPrototypeOf,
v = d && d(d(values([])));
v && v !== r && n.call(v, a) && (p = v);
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
function defineIteratorMethods(t) {
["next", "throw", "return"].forEach(function (e) {
define(t, e, function (t) {
return this._invoke(e, t);
});
});
}
function AsyncIterator(t, e) {
function invoke(r, o, i, a) {
var c = tryCatch(t[r], t, o);
if ("throw" !== c.type) {
var u = c.arg,
h = u.value;
return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
invoke("next", t, i, a);
}, function (t) {
invoke("throw", t, i, a);
}) : e.resolve(h).then(function (t) {
u.value = t, i(u);
}, function (t) {
return invoke("throw", t, i, a);
});
}
a(c.arg);
}
var r;
o(this, "_invoke", {
value: function value(t, n) {
function callInvokeWithMethodAndArg() {
return new e(function (e, r) {
invoke(t, n, e, r);
});
}
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
});
}
function makeInvokeMethod(e, r, n) {
var o = h;
return function (i, a) {
if (o === f) throw Error("Generator is already running");
if (o === s) {
if ("throw" === i) throw a;
return {
value: t,
done: !0
};
}
for (n.method = i, n.arg = a;;) {
var c = n.delegate;
if (c) {
var u = maybeInvokeDelegate(c, n);
if (u) {
if (u === y) continue;
return u;
}
}
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
if (o === h) throw o = s, n.arg;
n.dispatchException(n.arg);
} else "return" === n.method && n.abrupt("return", n.arg);
o = f;
var p = tryCatch(e, r, n);
if ("normal" === p.type) {
if (o = n.done ? s : l, p.arg === y) continue;
return {
value: p.arg,
done: n.done
};
}
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
}
};
}
function maybeInvokeDelegate(e, r) {
var n = r.method,
o = e.iterator[n];
if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
var i = tryCatch(o, e.iterator, r.arg);
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
var a = i.arg;
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
}
function pushTryEntry(t) {
var e = {
tryLoc: t[0]
};
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
}
function resetTryEntry(t) {
var e = t.completion || {};
e.type = "normal", delete e.arg, t.completion = e;
}
function Context(t) {
this.tryEntries = [{
tryLoc: "root"
}], t.forEach(pushTryEntry, this), this.reset(!0);
}
function values(e) {
if (e || "" === e) {
var r = e[a];
if (r) return r.call(e);
if ("function" == typeof e.next) return e;
if (!isNaN(e.length)) {
var o = -1,
i = function next() {
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
return next.value = t, next.done = !0, next;
};
return i.next = i;
}
}
throw new TypeError(_typeof(e) + " is not iterable");
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
value: GeneratorFunctionPrototype,
configurable: !0
}), o(GeneratorFunctionPrototype, "constructor", {
value: GeneratorFunction,
configurable: !0
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
var e = "function" == typeof t && t.constructor;
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
}, e.mark = function (t) {
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
}, e.awrap = function (t) {
return {
__await: t
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
return this;
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
void 0 === i && (i = Promise);
var a = new AsyncIterator(wrap(t, r, n, o), i);
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
return t.done ? t.value : a.next();
});
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
return this;
}), define(g, "toString", function () {
return "[object Generator]";
}), e.keys = function (t) {
var e = Object(t),
r = [];
for (var n in e) r.push(n);
return r.reverse(), function next() {
for (; r.length;) {
var t = r.pop();
if (t in e) return next.value = t, next.done = !1, next;
}
return next.done = !0, next;
};
}, e.values = values, Context.prototype = {
constructor: Context,
reset: function reset(e) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
},
stop: function stop() {
this.done = !0;
var t = this.tryEntries[0].completion;
if ("throw" === t.type) throw t.arg;
return this.rval;
},
dispatchException: function dispatchException(e) {
if (this.done) throw e;
var r = this;
function handle(n, o) {
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
}
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
var i = this.tryEntries[o],
a = i.completion;
if ("root" === i.tryLoc) return handle("end");
if (i.tryLoc <= this.prev) {
var c = n.call(i, "catchLoc"),
u = n.call(i, "finallyLoc");
if (c && u) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
} else if (c) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
} else {
if (!u) throw Error("try statement without catch or finally");
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
}
}
}
},
abrupt: function abrupt(t, e) {
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
var o = this.tryEntries[r];
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
var i = o;
break;
}
}
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
var a = i ? i.completion : {};
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
},
complete: function complete(t, e) {
if ("throw" === t.type) throw t.arg;
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
},
finish: function finish(t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
}
},
"catch": function _catch(t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.tryLoc === t) {
var n = r.completion;
if ("throw" === n.type) {
var o = n.arg;
resetTryEntry(r);
}
return o;
}
}
throw Error("illegal catch attempt");
},
delegateYield: function delegateYield(e, r, n) {
return this.delegate = {
iterator: values(e),
resultName: r,
nextLoc: n
}, "next" === this.method && (this.arg = t), y;
}
}, e;
}
function _toPrimitive(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(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
/**
* 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(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(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;
}
}]);
}();
/**
* Checks if a value is strictly null.
* @param value - The value to check.
* @returns Whether the value is null.
*/
var isNull = function isNull(value) {
return value === null;
};
/**
* 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(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(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.formSessionId The ID of the form session.
* @param {String} options.integration The integration type of the payment method.
* @param {String} options.merchantId The merchant ID of the payment method.
* @param {Boolean} options.oneclick The oneclick of the payment method.
* @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(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 ID of the form session.
* @type {String}
* @default null
*/
this.formSessionId = options.formSessionId || null;
/**
* The integration type of the payment method.
* @type {String}
* @default null
*/
this.integration = options.integration || null;
/**
* The merchant ID of the payment method.
* @type {String}
* @default null
*/
this.merchantId = options.merchantId || null;
/**
* The oneclick of the payment method.
* @type {Boolean}
* @default null
*/
this.oneclick = options.oneclick || 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(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_SSO_AUTH_URL = {
loginUrl: '/auth/',
logoutUrl: '/auth/?action=disconnect',
euLoginUrl: 'https://www.ovh.com/auth/',
euLogoutUrl: 'https://www.ovh.com/auth/?action=disconnect'
};
var loginUrl = DEFAULT_SSO_AUTH_URL.loginUrl,
logoutUrl = DEFAULT_SSO_AUTH_URL.logoutUrl,
euLoginUrl = DEFAULT_SSO_AUTH_URL.euLoginUrl,
euLogoutUrl = DEFAULT_SSO_AUTH_URL.euLogoutUrl;
var buildRedirectUrl = function buildRedirectUrl(url, params) {
return "".concat(url).concat(url.indexOf('?') > -1 ? '&' : '?').concat(params.join('&'));
};
var redirectTo = function redirectTo(url) {
return window.location.assign(url);
};
var isOvhTelecom = function isOvhTelecom() {
return window.location.host === 'www.ovhtelecom.fr';
};
var redirectToLoginPage = function redirectToLoginPage() {
var onsuccessUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var params = [];
if (loginUrl.indexOf('onsuccess') === -1) {
params.push("onsuccess=".concat(encodeURIComponent(onsuccessUrl || window.location.href)));
}
// redirect to login url
redirectTo(buildRedirectUrl(isOvhTelecom() ? euLoginUrl : loginUrl, params));
};
var redirectToLogoutPage = function redirectToLogoutPage() {
var onsuccessUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var params = [];
if (logoutUrl.indexOf('onsuccess') === -1) {
params.push("onsuccess=".concat(encodeURIComponent(onsuccessUrl || window.location.href)));
}
if (logoutUrl.indexOf('from') === -1 && document.referrer) {
params.push("from=".concat(encodeURIComponent(document.referrer)));
}
// redirect to login url
redirectTo(buildRedirectUrl(isOvhTelecom() ? euLogoutUrl : logoutUrl, params));
};
var Header;
(function (Header) {
Header["NAVIGATION_ID"] = "X-OVH-MANAGER-NAVIGATION-ID";
Header["REQUEST_ID"] = "X-OVH-MANAGER-REQUEST-ID";
Header["PAGE"] = "X-OVH-MANAGER-PAGE";
Header["VERSION"] = "X-OVH-MANAGER-VERSION";
})(Header || (Header = {}));
var ROUTES_PREFIX = ['/engine/apiv6', '/engine/2api', '/engine/api/v2'];
var DEFAULT_ROUTES_HEADERS_OVERRIDE = {};
var currentPage = 'bootstrap';
var headersOverride = DEFAULT_ROUTES_HEADERS_OVERRIDE;
var generateNavigationId = function generateNavigationId() {
window.top.ovhRequestTaggerNavigationId = Date.now().toString(36);
return window.top.ovhRequestTaggerNavigationId;
};
var getNavigationId = function getNavigationId() {
if (!window.top.ovhRequestTaggerNavigationId) return generateNavigationId();
return window.top.ovhRequestTaggerNavigationId;
};
var generateRequestId = function generateRequestId() {
window.top.ovhRequestTaggerRequestIndex = window.top.ovhRequestTaggerRequestIndex || 0;
window.top.ovhRequestTaggerRequestIndex += 1;
return "".concat(Date.now(), "-").concat(window.top.ovhRequestTaggerRequestIndex);
};
var isURLValid = function isURLValid(url) {
return ROUTES_PREFIX.some(function (prefix) {
return url === null || url === void 0 ? void 0 : url.startsWith(prefix);
});
};
var searchHeadersOverride = function searchHeadersOverride(url) {
var overridesKey = Object.keys(headersOverride).find(function (routePattern) {
return new RegExp(routePattern).test(url);
});
if (overridesKey) {
return headersOverride[overridesKey];
}
return {};
};
var getHeaders = function getHeaders(url) {
if (isURLValid(url)) {
return Object.assign(Object.assign(_defineProperty$1(_defineProperty$1(_defineProperty$1({}, Header.NAVIGATION_ID, getNavigationId()), Header.REQUEST_ID, generateRequestId()), Header.PAGE, currentPage), window.ovhRequestTaggerApplicationVersion ? _defineProperty$1({}, Header.VERSION, window.ovhRequestTaggerApplicationVersion) : {}), searchHeadersOverride(url));
}
return {};
};
var defaultAxiosConfig = {};
function handleAuthenticationError(error) {
var _response$config$head;
var response = error.response;
var status = response.status;
var hasCustomCredentials = !!((_response$config$head = response.config.headers) !== null && _response$config$head !== void 0 && _response$config$head.Authorization);
if (status === 403) {
var _response$data;
var message = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.message;
if (message === 'This session is forbidden' || message === 'This session is invalid') {
status = 401;
}
}
// redirect to auth page if the api credentials are invalid
if (status === 401 && !hasCustomCredentials) {
redirectToLogoutPage();
// never resolve since we are redirecting
return new Promise(function () {});
}
// low order session
if (status === 471) {
redirectToLoginPage();
// never resolve since we are redirecting
return new Promise(function () {});
}
return Promise.reject(error);
}
var v6 = axios.create(_objectSpread2$1(_objectSpread2$1({}, defaultAxiosConfig), {}, {
baseURL: '/engine/apiv6'
}));
var aapi = axios.create(_objectSpread2$1(_objectSpread2$1({}, defaultAxiosConfig), {}, {
baseURL: '/engine/2api'
}));
var ws$1 = axios.create(_objectSpread2$1(_objectSpread2$1({}, defaultAxiosConfig), {}, {
baseURL: '/engine/ws'
}));
var v2 = axios.create(_objectSpread2$1(_objectSpread2$1({}, defaultAxiosConfig), {}, {
baseURL: '/engine/api/v2'
}));
var apiClient = {
v6: v6,
aapi: aapi,
ws: ws$1,
v2: v2
};
Object.keys(apiClient).forEach(function (api) {
var _apiClient$api, _apiClient$api2;
(_apiClient$api = apiClient[api]) === null || _apiClient$api === void 0 || (_apiClient$api = _apiClient$api.interceptors) === null || _apiClient$api === void 0 || _apiClient$api.request.use(function (config) {
var headers = getHeaders(config === null || config === void 0 ? void 0 : config.baseURL);
Object.keys(headers).forEach(function (header) {
config.headers.set(header, headers[header]);
return header;
});
return _objectSpread2$1(_objectSpread2$1({}, config), {}, {
headers: _objectSpread2$1(_objectSpread2$1({}, config.headers), headers)
});
});
// Handle all response with authentification error
(_apiClient$api2 = apiClient[api]) === null || _apiClient$api2 === void 0 || (_apiClient$api2 = _apiClient$api2.interceptors) === null || _apiClient$api2 === void 0 || _apiClient$api2.response.use(null, handleAuthenticationError);
return api;
});
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() {
/*= ================================================
= Available Payment Methods =
================================================= */
/**
* Get the available payment methods
* @param {boolean} onlyRegisterable If true, only the registerable payment methods will be returned
* @returns {Promise<Array<AvailablePaymentMethod>>}
*/
var getAvailablePaymentMethods = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var onlyRegisterable,
_args = arguments;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
onlyRegisterable = _args.length > 0 && _args[0] !== undefined ? _args[0] : DEFAULT_GET_AVAILABLE_OPTIONS.onlyRegisterable;
return _context.abrupt("return", v6.get('/me/payment/availableMethods').then(function (_ref2) {
var availableMethods = _ref2.data;
var availablePaymentMethods = onlyRegisterable ? availableMethods.filter(function (_ref3) {
var registerable = _ref3.registerable;
return registerable;
}) : availableMethods;
return availablePaymentMethods.map(function (availableMethod) {
return new AvailablePaymentMethod(availableMethod);
});
})["catch"](function (error) {
var _error$response;
return ((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 404 ? [] : Promise.reject(error);
}));
case 2:
case "end":
return _context.stop();
}
}, _callee);
}));
return function getAvailablePaymentMethods() {
return _ref.apply(this, arguments);
};
}();
/**
* Get all the available payment methods that are registerable
* @return {Promise<Array<AvailablePaymentMethod>>} 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
* @param {Object} params The attributes of payment method to add
*/
var addPaymentMethod = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(availablePaymentMethod) {
var params,
_args2 = arguments;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
params = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
return _context2.abrupt("return", v6.post('/me/payment/method', _objectSpread2(_objectSpread2({}, params), {}, {
paymentType: availablePaymentMethod.paymentType
})).then(function (_ref5) {
var paymentMethod = _ref5.data;
if (params.orderId && paymentMethod.paymentMethodId) {
return v6.post("/me/order/".concat(params.orderId, "/pay"), {
paymentMethod: {
id: paymentMethod.paymentMethodId
}
}).then(function (_ref6) {
var data = _ref6.data;
return data;
});
}
return paymentMethod;
}));
case 2:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function addPaymentMethod(_x) {
return _ref4.apply(this, arguments);
};
}();
/**
* Edit given payment method
*
* @param {PaymentMethod} paymentMethod The payment method to edit
* @param {Object} params The attributes of payment method to edit
* @return {Promise<PaymentMethod>} That returns
*/
var editPaymentMethod = /*#__PURE__*/function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(paymentMethod, params) {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt("return", v6.put("/me/payment/method/".concat(paymentMethod.paymentMethodId), params).then(function (_ref8) {
var data = _ref8.data;
return new PaymentMethod(data);
}));
case 1:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return function editPaymentMethod(_x2, _x3) {
return _ref7.apply(this, arguments);
};
}();
/**
* Set given payment method as default.
*
* @param {PaymentMethod} paymentMethod The payment method to set as default
* @return {Promise<PaymentMethod>}
*/
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 = /*#__PURE__*/function () {
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(paymentMethod, challenge) {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt("return", v6.post("/me/payment/method/".concat(paymentMethod.paymentMethodId, "/challenge"), {
challenge: challenge
}).then(function (_ref10) {
var data = _ref10.data;
return data;
}));
case 1:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return function challengePaymentMethod(_x4, _x5) {
return _ref9.apply(this, arguments);
};
}();
/**
* 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 = /*#__PURE__*/function () {
var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(paymentMethodId, details) {
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
return _context5.abrupt("return", v6.post("/me/payment/method/".concat(paymentMethodId, "/details"), details).then(function (_ref12) {
var data = _ref12.data;
return data;
}));
case 1:
case "end":
return _context5.stop();
}
}, _callee5);
}));
return function addPaymentMethodDetails(_x6, _x7) {
return _ref11.apply(this, arguments);
};
}();
/**
* 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<PaymentMethod>} Which returns an instance of PaymentMethod.
*/
var finalizePaymentMethod = /*#__PURE__*/function () {
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(paymentMethodValidation) {
var finalizeData,
_args6 = arguments;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
finalizeData = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
return _context6.abrupt("return", v6.post("/me/payment/method/".concat(paymentMethodValidation.paymentMethodId, "/finalize"), finalizeData).then(function (_ref14) {
var data = _ref14.data;
return new PaymentMethod(data);
}));
case 2:
case "end":
return _context6.stop();
}
}, _callee6);
}));
return function finalizePaymentMethod(_x8) {
return _ref13.apply(this, arguments);
};
}();
/**
* Delete given payment method.
* @param {PaymentMethod} paymentMethod The paymentMethod to delete
* @return {Promise<PaymentMethod>}
*/
var de