boxpay-checkout-web-sdk 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -7
- package/dist/boxpay-checkout-web-sdk.js +1 -1
- package/dist/boxpay.esm.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,13 +20,7 @@ A lightweight, secure, and customizable checkout experience for payments — bui
|
|
|
20
20
|
### Via CDN
|
|
21
21
|
|
|
22
22
|
```html
|
|
23
|
-
<script src="https://cdn.jsdelivr.net/npm/boxpay-checkout-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### Local Script
|
|
27
|
-
|
|
28
|
-
```html
|
|
29
|
-
<script src="path-to/boxpay-checkout-js-sdk.js"></script>
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/boxpay-checkout-web-sdk/dist/boxpay.esm.min.js"></script>
|
|
30
24
|
```
|
|
31
25
|
|
|
32
26
|
---
|
|
@@ -1510,7 +1510,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
1510
1510
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1511
1511
|
|
|
1512
1512
|
"use strict";
|
|
1513
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../services/apiService/common.service */ \"./src/services/apiService/common.service.ts\");\n/* harmony import */ var _rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @rajesh896/broprint.js */ \"./node_modules/@rajesh896/broprint.js/lib/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _loader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../loader */ \"./src/components/loader.ts\");\n/* harmony import */ var _utils_domUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../utils/domUtils */ \"./src/utils/domUtils.ts\");\n/* harmony import */ var _utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../utils/paymentHandlers */ \"./src/utils/paymentHandlers.ts\");\n/* harmony import */ var _utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../utils/paymentInstanceFactory */ \"./src/utils/paymentInstanceFactory.ts\");\n/* harmony import */ var _state_globalState__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../state/globalState */ \"./src/state/globalState.ts\");\n/* harmony import */ var _utils_themeController__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../utils/themeController */ \"./src/utils/themeController.ts\");\n/* harmony import */ var _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../utils/EventBus */ \"./src/utils/EventBus.ts\");\nfunction _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); }\nfunction _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = \"function\" == typeof Symbol ? Symbol : {}, n = r.iterator || \"@@iterator\", o = r.toStringTag || \"@@toStringTag\"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, \"_invoke\", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError(\"Generator is already running\"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = \"next\"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError(\"iterator result is not an object\"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i[\"return\"]) && t.call(i), c < 2 && (u = TypeError(\"The iterator does not provide a '\" + o + \"' method\"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, \"GeneratorFunction\")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, \"constructor\", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, \"constructor\", GeneratorFunction), GeneratorFunction.displayName = \"GeneratorFunction\", _regeneratorDefine2(GeneratorFunctionPrototype, o, \"GeneratorFunction\"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, \"Generator\"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, \"toString\", function () { return \"[object Generator]\"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }\nfunction _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, \"\", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o(\"next\", 0), o(\"throw\", 1), o(\"return\", 2)); }, _regeneratorDefine2(e, r, n, t); }\nfunction 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); }\nfunction _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); }); }; }\nfunction _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError(\"Cannot call a class as a function\"); }\nfunction _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); } }\nfunction _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, \"prototype\", { writable: !1 }), e; }\nfunction _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; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == _typeof(i) ? i : i + \"\"; }\nfunction _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); }\n\n\n\n\n\n\n\n\n\n\nvar notAllowedPaymentStatuses = [\"EXPIRED\", \"PAID\", \"PROCESSING\", \"EXPIRED\", \"DISABLED\"];\nvar MAX_WIDTH = 1400;\nvar PaymentElements = /*#__PURE__*/function () {\n function PaymentElements(props) {\n var _props$options, _props$options2, _props$options3;\n _classCallCheck(this, PaymentElements);\n _defineProperty(this, \"activePaymentMethod\", \"\");\n _defineProperty(this, \"browserFingerprint\", \"\");\n _defineProperty(this, \"sessionDetails\", {});\n _defineProperty(this, \"paymentInstances\", {});\n _defineProperty(this, \"formValidity\", {\n isValid: false,\n invalidFields: []\n });\n // private oneTimePayment: boolean = false;\n _defineProperty(this, \"paymentMethodsToShow\", {});\n _defineProperty(this, \"showPayButton\", true);\n Object.assign(this, props);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('mode', this.mode);\n this.maxWidth = MAX_WIDTH;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('MAX_WIDTH', MAX_WIDTH);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('oneTimePayment', ((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.oneTimePayment) || false);\n this.initiatePayment = function () {};\n this.showPayButton = (_props$options2 = props.options) === null || _props$options2 === void 0 || (_props$options2 = _props$options2.payButton) === null || _props$options2 === void 0 ? void 0 : _props$options2.show;\n this.onPaymentButtonValidity = (_props$options3 = props.options) === null || _props$options3 === void 0 || (_props$options3 = _props$options3.payButton) === null || _props$options3 === void 0 ? void 0 : _props$options3.onPaymentButtonValidity;\n if (this.showPayButton === false) {\n this.initiatePayment = this.handlePayButtonClick.bind(this);\n }\n void this.initialize();\n }\n return _createClass(PaymentElements, [{\n key: \"handleThemeColors\",\n value: function handleThemeColors() {\n var theme = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get('appearance');\n document.querySelectorAll(\".label\").forEach(function (label) {\n return label.style.color = (theme === null || theme === void 0 ? void 0 : theme.primaryTextColor) || \"#333\";\n });\n }\n }, {\n key: \"initialize\",\n value: function () {\n var _initialize = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {\n var _resp$paymentDetails,\n _resp$paymentDetails2,\n _resp$merchantDetails,\n _resp$configs,\n _resp$paymentDetails3,\n _resp$paymentDetails4,\n _this = this,\n _this$onLoad3;\n var rootDiv, container, resp, isSubscription, _this$onLoad, merchantTheme, _this$onLoad2, _resp$paymentDetails$, amount, currencySymbol, currencyCode, formattedAmount, tabsContainer, formContainer, payDiv, _i, _Object$keys, method, instance;\n return _regenerator().w(function (_context) {\n while (1) switch (_context.n) {\n case 0:\n rootDiv = document.getElementById(this.container);\n container = document.createElement(\"div\");\n rootDiv.style.maxWidth = this.maxWidth + \"px\";\n rootDiv.classList.add(\"payment-elements-root\");\n rootDiv.innerHTML = '';\n container.classList.add(\"payment-elements-container\");\n if (container) {\n _context.n = 1;\n break;\n }\n throw new Error(\"\".concat(this.container, \" not found\"));\n case 1:\n (0,_loader__WEBPACK_IMPORTED_MODULE_3__.getLoaderTemplate)(container, \"Loading payment options...\");\n rootDiv.append(container);\n _context.n = 2;\n return (0,_rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__.getCurrentBrowserFingerPrint)();\n case 2:\n this.browserFingerprint = _context.v;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionToken\", this.sessionToken);\n _context.n = 3;\n return (0,_services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__.getSession)(this.sessionToken);\n case 3:\n resp = _context.v;\n // check for subscription\n isSubscription = !(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(resp === null || resp === void 0 || (_resp$paymentDetails = resp.paymentDetails) === null || _resp$paymentDetails === void 0 ? void 0 : _resp$paymentDetails.subscriptionDetails);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"isSubscription\", isSubscription);\n if (!notAllowedPaymentStatuses.includes(resp.status)) {\n _context.n = 4;\n break;\n }\n return _context.a(2, (_this$onLoad = this.onLoad) === null || _this$onLoad === void 0 ? void 0 : _this$onLoad.call(this, {\n message: \"This checkout token is \".concat(resp === null || resp === void 0 ? void 0 : resp.status)\n }));\n case 4:\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('currencySymbol', resp === null || resp === void 0 || (_resp$paymentDetails2 = resp.paymentDetails) === null || _resp$paymentDetails2 === void 0 || (_resp$paymentDetails2 = _resp$paymentDetails2.money) === null || _resp$paymentDetails2 === void 0 ? void 0 : _resp$paymentDetails2.currencySymbol);\n this.sessionDetails = resp;\n merchantTheme = resp === null || resp === void 0 || (_resp$merchantDetails = resp.merchantDetails) === null || _resp$merchantDetails === void 0 ? void 0 : _resp$merchantDetails.checkoutTheme;\n (0,_utils_themeController__WEBPACK_IMPORTED_MODULE_8__.handleAppearanceOptions)({\n appearance: this.appearance,\n theme: {\n themePrimaryColor: merchantTheme.primaryButtonColor,\n themeSecondaryColor: merchantTheme.secondaryButtonColor,\n themePrimaryTextColor: merchantTheme.primaryButtonColor,\n themeSecondaryTextColor: merchantTheme.secondaryButtonColor\n }\n });\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionDetails\", resp);\n this.paymentMethodsToShow = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.orderPaymentMethodsByUserPreference)((0,_utils__WEBPACK_IMPORTED_MODULE_2__.getPaymentOptionsToDisplay)(resp === null || resp === void 0 || (_resp$configs = resp.configs) === null || _resp$configs === void 0 ? void 0 : _resp$configs.paymentMethods, this.paymentMethods), this.paymentMethods);\n // this.paymentMethodsToShow = orderPaymentMethodsByUserPreference(\n // getPaymentOptionsToDisplay(resp?.configs?.paymentMethods, this.paymentMethods.includes('card') ? ['card'] : []),\n // this.paymentMethods\n // );\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"paymentMethodsToShow\", this.paymentMethodsToShow);\n if (!(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(this.paymentMethodsToShow)) {\n _context.n = 5;\n break;\n }\n return _context.a(2, (_this$onLoad2 = this.onLoad) === null || _this$onLoad2 === void 0 ? void 0 : _this$onLoad2.call(this, {\n message: \"No valid payment methods found\"\n }));\n case 5:\n this.shopper = this.shopperDetails || (resp === null || resp === void 0 || (_resp$paymentDetails3 = resp.paymentDetails) === null || _resp$paymentDetails3 === void 0 ? void 0 : _resp$paymentDetails3.shopper);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"shopper\", this.shopper);\n _resp$paymentDetails$ = resp === null || resp === void 0 || (_resp$paymentDetails4 = resp.paymentDetails) === null || _resp$paymentDetails4 === void 0 ? void 0 : _resp$paymentDetails4.money, amount = _resp$paymentDetails$.amount, currencySymbol = _resp$paymentDetails$.currencySymbol, currencyCode = _resp$paymentDetails$.currencyCode;\n formattedAmount = String((0,_utils__WEBPACK_IMPORTED_MODULE_2__.numberToCurrency)(amount, currencyCode));\n container.innerHTML = \"\";\n tabsContainer = undefined;\n this.activePaymentMethod = Object.keys(this.paymentMethodsToShow)[0];\n if (Object.keys(this.paymentMethodsToShow).length > 1) {\n tabsContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createTabsContainer)(this.paymentMethodsToShow, this.activePaymentMethod, this.switchPaymentMethod.bind(this));\n }\n formContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createFormContainer)();\n if (this.showPayButton) {\n payDiv = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayButton)(function () {\n return (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayLabel)(currencySymbol, formattedAmount);\n }, function (e) {\n e.preventDefault();\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(_this.boxpayPayButton, true);\n void _this.handlePayButtonClick();\n });\n payDiv.style.maxWidth = this.maxWidth + \"px\";\n this.boxpayPayButton = payDiv.querySelector(\"button\");\n }\n if (tabsContainer) {\n container.append(tabsContainer, formContainer);\n } else {\n container.append(formContainer);\n }\n this.handleSubscriptionCheckBox(rootDiv);\n if (this.showPayButton) {\n rootDiv.append(payDiv);\n }\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n for (_i = 0, _Object$keys = Object.keys(this.paymentMethodsToShow); _i < _Object$keys.length; _i++) {\n method = _Object$keys[_i];\n instance = (0,_utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__.createPaymentInstance)(method, formContainer, payDiv, this.paymentMethodsToShow, this.options || {}, this.handleFormValidityChange.bind(this), this.updatePayButtonText.bind(this), this);\n this.paymentInstances[method] = instance;\n }\n this.mountActiveMethod();\n (_this$onLoad3 = this.onLoad) === null || _this$onLoad3 === void 0 || _this$onLoad3.call(this, {\n message: \"Payment Elements Loaded\"\n });\n case 6:\n return _context.a(2);\n }\n }, _callee, this);\n }));\n function initialize() {\n return _initialize.apply(this, arguments);\n }\n return initialize;\n }()\n }, {\n key: \"handleSubscriptionCheckBox\",\n value: function handleSubscriptionCheckBox(rootDiv) {\n var isSubscription = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"isSubscription\");\n var oneTimePayment = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"oneTimePayment\");\n if (isSubscription && oneTimePayment) {\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('isOneTimePaymentChecked', true);\n // globalState.set('sendSiFlag', true);\n } else if (isSubscription && !oneTimePayment) {\n var siElement = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createCheckBox)(\"Setup automatic payments\", function () {});\n rootDiv.appendChild(siElement);\n // globalState.set('sendSiFlag', true);\n } else {\n // globalState.set('sendSiFlag', false);\n }\n }\n }, {\n key: \"switchPaymentMethod\",\n value: function switchPaymentMethod(method) {\n if (this.activePaymentMethod === method) return;\n this.activePaymentMethod = method;\n this.mountActiveMethod();\n this.handleFormValidityChange({\n isValid: false,\n invalidFields: []\n });\n this.updatePayButtonText();\n\n // stop if any status polling is going on\n var controller = {\n cancelled: true\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n }\n }, {\n key: \"mountActiveMethod\",\n value: function mountActiveMethod() {\n var _activeInstance$rende;\n var formContainer = document.getElementById(\"payment-form-container\");\n if (!formContainer) return;\n formContainer.innerHTML = \"\";\n var activeInstance = this.paymentInstances[this.activePaymentMethod];\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"CURRENT_PAYMENT_METHOD\", this.activePaymentMethod);\n activeInstance === null || activeInstance === void 0 || (_activeInstance$rende = activeInstance.render) === null || _activeInstance$rende === void 0 || _activeInstance$rende.call(activeInstance);\n (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.updateActiveTab)(this.activePaymentMethod);\n this.handleThemeColors();\n }\n }, {\n key: \"handleFormValidityChange\",\n value: function handleFormValidityChange(_ref) {\n var isValid = _ref.isValid,\n invalidFields = _ref.invalidFields;\n this.formValidity = {\n isValid: isValid,\n invalidFields: invalidFields\n };\n if (this.boxpayPayButton) this.boxpayPayButton.disabled = !isValid;\n if (!this.showPayButton) {\n if (typeof this.onPaymentButtonValidity === 'function') {\n this.onPaymentButtonValidity(isValid);\n }\n }\n }\n }, {\n key: \"handlePayButtonClick\",\n value: function () {\n var _handlePayButtonClick = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {\n var controller, res;\n return _regenerator().w(function (_context2) {\n while (1) switch (_context2.n) {\n case 0:\n console.log(\"PAY btn clicked\");\n if (!this.boxpayPayButton) {\n _context2.n = 2;\n break;\n }\n if (!this.boxpayPayButton.disabled) {\n _context2.n = 1;\n break;\n }\n return _context2.a(2);\n case 1:\n this.boxpayPayButton.disabled = true;\n case 2:\n controller = {\n cancelled: false\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"PAY_BTN_CLICKED\", {});\n _context2.n = 3;\n return (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handlePayClick)(this);\n case 3:\n res = _context2.v;\n return _context2.a(2, res);\n }\n }, _callee2, this);\n }));\n function handlePayButtonClick() {\n return _handlePayButtonClick.apply(this, arguments);\n }\n return handlePayButtonClick;\n }()\n }, {\n key: \"sendResponse\",\n value: function sendResponse(response) {\n if (this.boxpayPayButton) {\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(this.boxpayPayButton, false);\n }\n if ((response === null || response === void 0 ? void 0 : response.status) !== \"ERROR\") {\n var _this$onPayment;\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"SENDING_RESPONSE\", response);\n (_this$onPayment = this.onPayment) === null || _this$onPayment === void 0 || _this$onPayment.call(this, response);\n }\n return response;\n }\n }, {\n key: \"updatePayButtonText\",\n value: function updatePayButtonText(text) {\n var _this$sessionDetails;\n if (!this.boxpayPayButton) return;\n var _ref2 = ((_this$sessionDetails = this.sessionDetails) === null || _this$sessionDetails === void 0 || (_this$sessionDetails = _this$sessionDetails.paymentDetails) === null || _this$sessionDetails === void 0 ? void 0 : _this$sessionDetails.money) || {},\n amount = _ref2.amount,\n currencySymbol = _ref2.currencySymbol;\n this.boxpayPayButton.textContent = text || \"Pay \".concat(currencySymbol, \" \").concat(amount);\n }\n }]);\n}();\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (PaymentElements);\n\n//# sourceURL=webpack://BoxPayCheckout/./src/components/paymentElements/PaymentElement.controller.ts?\n}");
|
|
1513
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../services/apiService/common.service */ \"./src/services/apiService/common.service.ts\");\n/* harmony import */ var _rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @rajesh896/broprint.js */ \"./node_modules/@rajesh896/broprint.js/lib/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _loader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../loader */ \"./src/components/loader.ts\");\n/* harmony import */ var _utils_domUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../utils/domUtils */ \"./src/utils/domUtils.ts\");\n/* harmony import */ var _utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../utils/paymentHandlers */ \"./src/utils/paymentHandlers.ts\");\n/* harmony import */ var _utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../utils/paymentInstanceFactory */ \"./src/utils/paymentInstanceFactory.ts\");\n/* harmony import */ var _state_globalState__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../state/globalState */ \"./src/state/globalState.ts\");\n/* harmony import */ var _utils_themeController__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../utils/themeController */ \"./src/utils/themeController.ts\");\n/* harmony import */ var _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../utils/EventBus */ \"./src/utils/EventBus.ts\");\nfunction _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); }\nfunction _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = \"function\" == typeof Symbol ? Symbol : {}, n = r.iterator || \"@@iterator\", o = r.toStringTag || \"@@toStringTag\"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, \"_invoke\", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError(\"Generator is already running\"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = \"next\"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError(\"iterator result is not an object\"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i[\"return\"]) && t.call(i), c < 2 && (u = TypeError(\"The iterator does not provide a '\" + o + \"' method\"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, \"GeneratorFunction\")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, \"constructor\", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, \"constructor\", GeneratorFunction), GeneratorFunction.displayName = \"GeneratorFunction\", _regeneratorDefine2(GeneratorFunctionPrototype, o, \"GeneratorFunction\"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, \"Generator\"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, \"toString\", function () { return \"[object Generator]\"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }\nfunction _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, \"\", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o(\"next\", 0), o(\"throw\", 1), o(\"return\", 2)); }, _regeneratorDefine2(e, r, n, t); }\nfunction 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); }\nfunction _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); }); }; }\nfunction _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError(\"Cannot call a class as a function\"); }\nfunction _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); } }\nfunction _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, \"prototype\", { writable: !1 }), e; }\nfunction _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; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == _typeof(i) ? i : i + \"\"; }\nfunction _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); }\n\n\n\n\n\n\n\n\n\n\nvar notAllowedPaymentStatuses = [\"EXPIRED\", \"PAID\", \"PROCESSING\", \"EXPIRED\", \"DISABLED\"];\nvar MAX_WIDTH = 1400;\nvar PaymentElements = /*#__PURE__*/function () {\n function PaymentElements(props) {\n var _props$options, _props$options2, _props$options3;\n _classCallCheck(this, PaymentElements);\n _defineProperty(this, \"activePaymentMethod\", \"\");\n _defineProperty(this, \"browserFingerprint\", \"\");\n _defineProperty(this, \"sessionDetails\", {});\n _defineProperty(this, \"paymentInstances\", {});\n _defineProperty(this, \"formValidity\", {\n isValid: false,\n invalidFields: []\n });\n // private oneTimePayment: boolean = false;\n _defineProperty(this, \"paymentMethodsToShow\", {});\n _defineProperty(this, \"showPayButton\", true);\n Object.assign(this, props);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('mode', this.mode);\n this.maxWidth = MAX_WIDTH;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('MAX_WIDTH', MAX_WIDTH);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('oneTimePayment', ((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.oneTimePayment) || false);\n this.initiatePayment = function () {};\n this.showPayButton = (_props$options2 = props.options) === null || _props$options2 === void 0 || (_props$options2 = _props$options2.payButton) === null || _props$options2 === void 0 ? void 0 : _props$options2.show;\n this.onPaymentButtonValidity = (_props$options3 = props.options) === null || _props$options3 === void 0 || (_props$options3 = _props$options3.payButton) === null || _props$options3 === void 0 ? void 0 : _props$options3.onPaymentButtonValidity;\n if (this.showPayButton === false) {\n this.initiatePayment = this.handlePayButtonClick.bind(this);\n }\n void this.initialize();\n }\n return _createClass(PaymentElements, [{\n key: \"handleThemeColors\",\n value: function handleThemeColors() {\n var theme = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get('appearance');\n document.querySelectorAll(\".label\").forEach(function (label) {\n return label.style.color = (theme === null || theme === void 0 ? void 0 : theme.primaryTextColor) || \"#333\";\n });\n }\n }, {\n key: \"initialize\",\n value: function () {\n var _initialize = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {\n var _resp$paymentDetails,\n _resp$paymentDetails2,\n _resp$merchantDetails,\n _resp$configs,\n _resp$paymentDetails3,\n _resp$paymentDetails4,\n _this = this,\n _this$onLoad3;\n var rootDiv, container, resp, isSubscription, _this$onLoad, merchantTheme, _this$onLoad2, _resp$paymentDetails$, amount, currencySymbol, currencyCode, formattedAmount, tabsContainer, formContainer, payDiv, _i, _Object$keys, method, instance;\n return _regenerator().w(function (_context) {\n while (1) switch (_context.n) {\n case 0:\n rootDiv = document.getElementById(this.container);\n container = document.createElement(\"div\");\n rootDiv.style.maxWidth = this.maxWidth + \"px\";\n rootDiv.classList.add(\"payment-elements-root\");\n rootDiv.innerHTML = '';\n container.classList.add(\"payment-elements-container\");\n if (container) {\n _context.n = 1;\n break;\n }\n throw new Error(\"\".concat(this.container, \" not found\"));\n case 1:\n (0,_loader__WEBPACK_IMPORTED_MODULE_3__.getLoaderTemplate)(container, \"Loading payment options...\");\n rootDiv.append(container);\n _context.n = 2;\n return (0,_rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__.getCurrentBrowserFingerPrint)();\n case 2:\n this.browserFingerprint = _context.v;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionToken\", this.sessionToken);\n _context.n = 3;\n return (0,_services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__.getSession)(this.sessionToken);\n case 3:\n resp = _context.v;\n // check for subscription\n isSubscription = !(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(resp === null || resp === void 0 || (_resp$paymentDetails = resp.paymentDetails) === null || _resp$paymentDetails === void 0 ? void 0 : _resp$paymentDetails.subscriptionDetails);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"isSubscription\", isSubscription);\n if (!notAllowedPaymentStatuses.includes(resp.status)) {\n _context.n = 4;\n break;\n }\n return _context.a(2, (_this$onLoad = this.onLoad) === null || _this$onLoad === void 0 ? void 0 : _this$onLoad.call(this, {\n message: \"This checkout token is \".concat(resp === null || resp === void 0 ? void 0 : resp.status)\n }));\n case 4:\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('currencySymbol', resp === null || resp === void 0 || (_resp$paymentDetails2 = resp.paymentDetails) === null || _resp$paymentDetails2 === void 0 || (_resp$paymentDetails2 = _resp$paymentDetails2.money) === null || _resp$paymentDetails2 === void 0 ? void 0 : _resp$paymentDetails2.currencySymbol);\n this.sessionDetails = resp;\n merchantTheme = resp === null || resp === void 0 || (_resp$merchantDetails = resp.merchantDetails) === null || _resp$merchantDetails === void 0 ? void 0 : _resp$merchantDetails.checkoutTheme;\n (0,_utils_themeController__WEBPACK_IMPORTED_MODULE_8__.handleAppearanceOptions)({\n appearance: this.appearance,\n theme: {\n themePrimaryColor: merchantTheme.primaryButtonColor,\n themeSecondaryColor: merchantTheme.secondaryButtonColor,\n themePrimaryTextColor: merchantTheme.primaryButtonColor,\n themeSecondaryTextColor: merchantTheme.secondaryButtonColor\n }\n });\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionDetails\", resp);\n // this.paymentMethodsToShow = orderPaymentMethodsByUserPreference(\n // getPaymentOptionsToDisplay(resp?.configs?.paymentMethods, this.paymentMethods),\n // this.paymentMethods\n // );\n this.paymentMethodsToShow = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.orderPaymentMethodsByUserPreference)((0,_utils__WEBPACK_IMPORTED_MODULE_2__.getPaymentOptionsToDisplay)(resp === null || resp === void 0 || (_resp$configs = resp.configs) === null || _resp$configs === void 0 ? void 0 : _resp$configs.paymentMethods, this.paymentMethods.includes('card') ? ['card'] : []), this.paymentMethods);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"paymentMethodsToShow\", this.paymentMethodsToShow);\n if (!(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(this.paymentMethodsToShow)) {\n _context.n = 5;\n break;\n }\n return _context.a(2, (_this$onLoad2 = this.onLoad) === null || _this$onLoad2 === void 0 ? void 0 : _this$onLoad2.call(this, {\n message: \"No valid payment methods found\"\n }));\n case 5:\n this.shopper = this.shopperDetails || (resp === null || resp === void 0 || (_resp$paymentDetails3 = resp.paymentDetails) === null || _resp$paymentDetails3 === void 0 ? void 0 : _resp$paymentDetails3.shopper);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"shopper\", this.shopper);\n _resp$paymentDetails$ = resp === null || resp === void 0 || (_resp$paymentDetails4 = resp.paymentDetails) === null || _resp$paymentDetails4 === void 0 ? void 0 : _resp$paymentDetails4.money, amount = _resp$paymentDetails$.amount, currencySymbol = _resp$paymentDetails$.currencySymbol, currencyCode = _resp$paymentDetails$.currencyCode;\n formattedAmount = String((0,_utils__WEBPACK_IMPORTED_MODULE_2__.numberToCurrency)(amount, currencyCode));\n container.innerHTML = \"\";\n tabsContainer = undefined;\n this.activePaymentMethod = Object.keys(this.paymentMethodsToShow)[0];\n if (Object.keys(this.paymentMethodsToShow).length > 1) {\n tabsContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createTabsContainer)(this.paymentMethodsToShow, this.activePaymentMethod, this.switchPaymentMethod.bind(this));\n }\n formContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createFormContainer)();\n if (this.showPayButton) {\n payDiv = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayButton)(function () {\n return (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayLabel)(currencySymbol, formattedAmount);\n }, function (e) {\n e.preventDefault();\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(_this.boxpayPayButton, true);\n void _this.handlePayButtonClick();\n });\n payDiv.style.maxWidth = this.maxWidth + \"px\";\n this.boxpayPayButton = payDiv.querySelector(\"button\");\n }\n if (tabsContainer) {\n container.append(tabsContainer, formContainer);\n } else {\n container.append(formContainer);\n }\n this.handleSubscriptionCheckBox(rootDiv);\n if (this.showPayButton) {\n rootDiv.append(payDiv);\n }\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n for (_i = 0, _Object$keys = Object.keys(this.paymentMethodsToShow); _i < _Object$keys.length; _i++) {\n method = _Object$keys[_i];\n instance = (0,_utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__.createPaymentInstance)(method, formContainer, payDiv, this.paymentMethodsToShow, this.options || {}, this.handleFormValidityChange.bind(this), this.updatePayButtonText.bind(this), this);\n this.paymentInstances[method] = instance;\n }\n this.mountActiveMethod();\n (_this$onLoad3 = this.onLoad) === null || _this$onLoad3 === void 0 || _this$onLoad3.call(this, {\n message: \"Payment Elements Loaded\"\n });\n case 6:\n return _context.a(2);\n }\n }, _callee, this);\n }));\n function initialize() {\n return _initialize.apply(this, arguments);\n }\n return initialize;\n }()\n }, {\n key: \"handleSubscriptionCheckBox\",\n value: function handleSubscriptionCheckBox(rootDiv) {\n var isSubscription = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"isSubscription\");\n var oneTimePayment = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"oneTimePayment\");\n if (isSubscription && oneTimePayment) {\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('isOneTimePaymentChecked', true);\n // globalState.set('sendSiFlag', true);\n } else if (isSubscription && !oneTimePayment) {\n var siElement = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createCheckBox)(\"Setup automatic payments\", function () {});\n rootDiv.appendChild(siElement);\n // globalState.set('sendSiFlag', true);\n } else {\n // globalState.set('sendSiFlag', false);\n }\n }\n }, {\n key: \"switchPaymentMethod\",\n value: function switchPaymentMethod(method) {\n if (this.activePaymentMethod === method) return;\n this.activePaymentMethod = method;\n this.mountActiveMethod();\n this.handleFormValidityChange({\n isValid: false,\n invalidFields: []\n });\n this.updatePayButtonText();\n\n // stop if any status polling is going on\n var controller = {\n cancelled: true\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n }\n }, {\n key: \"mountActiveMethod\",\n value: function mountActiveMethod() {\n var _activeInstance$rende;\n var formContainer = document.getElementById(\"payment-form-container\");\n if (!formContainer) return;\n formContainer.innerHTML = \"\";\n var activeInstance = this.paymentInstances[this.activePaymentMethod];\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"CURRENT_PAYMENT_METHOD\", this.activePaymentMethod);\n activeInstance === null || activeInstance === void 0 || (_activeInstance$rende = activeInstance.render) === null || _activeInstance$rende === void 0 || _activeInstance$rende.call(activeInstance);\n (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.updateActiveTab)(this.activePaymentMethod);\n this.handleThemeColors();\n }\n }, {\n key: \"handleFormValidityChange\",\n value: function handleFormValidityChange(_ref) {\n var isValid = _ref.isValid,\n invalidFields = _ref.invalidFields;\n this.formValidity = {\n isValid: isValid,\n invalidFields: invalidFields\n };\n if (this.boxpayPayButton) this.boxpayPayButton.disabled = !isValid;\n if (!this.showPayButton) {\n if (typeof this.onPaymentButtonValidity === 'function') {\n this.onPaymentButtonValidity(isValid);\n }\n }\n }\n }, {\n key: \"handlePayButtonClick\",\n value: function () {\n var _handlePayButtonClick = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {\n var controller, res;\n return _regenerator().w(function (_context2) {\n while (1) switch (_context2.n) {\n case 0:\n console.log(\"PAY btn clicked\");\n if (!this.boxpayPayButton) {\n _context2.n = 2;\n break;\n }\n if (!this.boxpayPayButton.disabled) {\n _context2.n = 1;\n break;\n }\n return _context2.a(2);\n case 1:\n this.boxpayPayButton.disabled = true;\n case 2:\n controller = {\n cancelled: false\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"PAY_BTN_CLICKED\", {});\n _context2.n = 3;\n return (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handlePayClick)(this);\n case 3:\n res = _context2.v;\n return _context2.a(2, res);\n }\n }, _callee2, this);\n }));\n function handlePayButtonClick() {\n return _handlePayButtonClick.apply(this, arguments);\n }\n return handlePayButtonClick;\n }()\n }, {\n key: \"sendResponse\",\n value: function sendResponse(response) {\n if (this.boxpayPayButton) {\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(this.boxpayPayButton, false);\n }\n if ((response === null || response === void 0 ? void 0 : response.status) !== \"ERROR\") {\n var _this$onPayment;\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"SENDING_RESPONSE\", response);\n (_this$onPayment = this.onPayment) === null || _this$onPayment === void 0 || _this$onPayment.call(this, response);\n }\n return response;\n }\n }, {\n key: \"updatePayButtonText\",\n value: function updatePayButtonText(text) {\n var _this$sessionDetails;\n if (!this.boxpayPayButton) return;\n var _ref2 = ((_this$sessionDetails = this.sessionDetails) === null || _this$sessionDetails === void 0 || (_this$sessionDetails = _this$sessionDetails.paymentDetails) === null || _this$sessionDetails === void 0 ? void 0 : _this$sessionDetails.money) || {},\n amount = _ref2.amount,\n currencySymbol = _ref2.currencySymbol;\n this.boxpayPayButton.textContent = text || \"Pay \".concat(currencySymbol, \" \").concat(amount);\n }\n }]);\n}();\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (PaymentElements);\n\n//# sourceURL=webpack://BoxPayCheckout/./src/components/paymentElements/PaymentElement.controller.ts?\n}");
|
|
1514
1514
|
|
|
1515
1515
|
/***/ }),
|
|
1516
1516
|
|
package/dist/boxpay.esm.js
CHANGED
|
@@ -1500,7 +1500,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
1500
1500
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1501
1501
|
|
|
1502
1502
|
"use strict";
|
|
1503
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../services/apiService/common.service */ \"./src/services/apiService/common.service.ts\");\n/* harmony import */ var _rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @rajesh896/broprint.js */ \"./node_modules/@rajesh896/broprint.js/lib/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _loader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../loader */ \"./src/components/loader.ts\");\n/* harmony import */ var _utils_domUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../utils/domUtils */ \"./src/utils/domUtils.ts\");\n/* harmony import */ var _utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../utils/paymentHandlers */ \"./src/utils/paymentHandlers.ts\");\n/* harmony import */ var _utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../utils/paymentInstanceFactory */ \"./src/utils/paymentInstanceFactory.ts\");\n/* harmony import */ var _state_globalState__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../state/globalState */ \"./src/state/globalState.ts\");\n/* harmony import */ var _utils_themeController__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../utils/themeController */ \"./src/utils/themeController.ts\");\n/* harmony import */ var _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../utils/EventBus */ \"./src/utils/EventBus.ts\");\nfunction _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); }\nfunction _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = \"function\" == typeof Symbol ? Symbol : {}, n = r.iterator || \"@@iterator\", o = r.toStringTag || \"@@toStringTag\"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, \"_invoke\", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError(\"Generator is already running\"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = \"next\"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError(\"iterator result is not an object\"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i[\"return\"]) && t.call(i), c < 2 && (u = TypeError(\"The iterator does not provide a '\" + o + \"' method\"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, \"GeneratorFunction\")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, \"constructor\", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, \"constructor\", GeneratorFunction), GeneratorFunction.displayName = \"GeneratorFunction\", _regeneratorDefine2(GeneratorFunctionPrototype, o, \"GeneratorFunction\"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, \"Generator\"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, \"toString\", function () { return \"[object Generator]\"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }\nfunction _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, \"\", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o(\"next\", 0), o(\"throw\", 1), o(\"return\", 2)); }, _regeneratorDefine2(e, r, n, t); }\nfunction 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); }\nfunction _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); }); }; }\nfunction _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError(\"Cannot call a class as a function\"); }\nfunction _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); } }\nfunction _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, \"prototype\", { writable: !1 }), e; }\nfunction _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; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == _typeof(i) ? i : i + \"\"; }\nfunction _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); }\n\n\n\n\n\n\n\n\n\n\nvar notAllowedPaymentStatuses = [\"EXPIRED\", \"PAID\", \"PROCESSING\", \"EXPIRED\", \"DISABLED\"];\nvar MAX_WIDTH = 1400;\nvar PaymentElements = /*#__PURE__*/function () {\n function PaymentElements(props) {\n var _props$options, _props$options2, _props$options3;\n _classCallCheck(this, PaymentElements);\n _defineProperty(this, \"activePaymentMethod\", \"\");\n _defineProperty(this, \"browserFingerprint\", \"\");\n _defineProperty(this, \"sessionDetails\", {});\n _defineProperty(this, \"paymentInstances\", {});\n _defineProperty(this, \"formValidity\", {\n isValid: false,\n invalidFields: []\n });\n // private oneTimePayment: boolean = false;\n _defineProperty(this, \"paymentMethodsToShow\", {});\n _defineProperty(this, \"showPayButton\", true);\n Object.assign(this, props);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('mode', this.mode);\n this.maxWidth = MAX_WIDTH;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('MAX_WIDTH', MAX_WIDTH);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('oneTimePayment', ((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.oneTimePayment) || false);\n this.initiatePayment = function () {};\n this.showPayButton = (_props$options2 = props.options) === null || _props$options2 === void 0 || (_props$options2 = _props$options2.payButton) === null || _props$options2 === void 0 ? void 0 : _props$options2.show;\n this.onPaymentButtonValidity = (_props$options3 = props.options) === null || _props$options3 === void 0 || (_props$options3 = _props$options3.payButton) === null || _props$options3 === void 0 ? void 0 : _props$options3.onPaymentButtonValidity;\n if (this.showPayButton === false) {\n this.initiatePayment = this.handlePayButtonClick.bind(this);\n }\n void this.initialize();\n }\n return _createClass(PaymentElements, [{\n key: \"handleThemeColors\",\n value: function handleThemeColors() {\n var theme = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get('appearance');\n document.querySelectorAll(\".label\").forEach(function (label) {\n return label.style.color = (theme === null || theme === void 0 ? void 0 : theme.primaryTextColor) || \"#333\";\n });\n }\n }, {\n key: \"initialize\",\n value: function () {\n var _initialize = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {\n var _resp$paymentDetails,\n _resp$paymentDetails2,\n _resp$merchantDetails,\n _resp$configs,\n _resp$paymentDetails3,\n _resp$paymentDetails4,\n _this = this,\n _this$onLoad3;\n var rootDiv, container, resp, isSubscription, _this$onLoad, merchantTheme, _this$onLoad2, _resp$paymentDetails$, amount, currencySymbol, currencyCode, formattedAmount, tabsContainer, formContainer, payDiv, _i, _Object$keys, method, instance;\n return _regenerator().w(function (_context) {\n while (1) switch (_context.n) {\n case 0:\n rootDiv = document.getElementById(this.container);\n container = document.createElement(\"div\");\n rootDiv.style.maxWidth = this.maxWidth + \"px\";\n rootDiv.classList.add(\"payment-elements-root\");\n rootDiv.innerHTML = '';\n container.classList.add(\"payment-elements-container\");\n if (container) {\n _context.n = 1;\n break;\n }\n throw new Error(\"\".concat(this.container, \" not found\"));\n case 1:\n (0,_loader__WEBPACK_IMPORTED_MODULE_3__.getLoaderTemplate)(container, \"Loading payment options...\");\n rootDiv.append(container);\n _context.n = 2;\n return (0,_rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__.getCurrentBrowserFingerPrint)();\n case 2:\n this.browserFingerprint = _context.v;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionToken\", this.sessionToken);\n _context.n = 3;\n return (0,_services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__.getSession)(this.sessionToken);\n case 3:\n resp = _context.v;\n // check for subscription\n isSubscription = !(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(resp === null || resp === void 0 || (_resp$paymentDetails = resp.paymentDetails) === null || _resp$paymentDetails === void 0 ? void 0 : _resp$paymentDetails.subscriptionDetails);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"isSubscription\", isSubscription);\n if (!notAllowedPaymentStatuses.includes(resp.status)) {\n _context.n = 4;\n break;\n }\n return _context.a(2, (_this$onLoad = this.onLoad) === null || _this$onLoad === void 0 ? void 0 : _this$onLoad.call(this, {\n message: \"This checkout token is \".concat(resp === null || resp === void 0 ? void 0 : resp.status)\n }));\n case 4:\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('currencySymbol', resp === null || resp === void 0 || (_resp$paymentDetails2 = resp.paymentDetails) === null || _resp$paymentDetails2 === void 0 || (_resp$paymentDetails2 = _resp$paymentDetails2.money) === null || _resp$paymentDetails2 === void 0 ? void 0 : _resp$paymentDetails2.currencySymbol);\n this.sessionDetails = resp;\n merchantTheme = resp === null || resp === void 0 || (_resp$merchantDetails = resp.merchantDetails) === null || _resp$merchantDetails === void 0 ? void 0 : _resp$merchantDetails.checkoutTheme;\n (0,_utils_themeController__WEBPACK_IMPORTED_MODULE_8__.handleAppearanceOptions)({\n appearance: this.appearance,\n theme: {\n themePrimaryColor: merchantTheme.primaryButtonColor,\n themeSecondaryColor: merchantTheme.secondaryButtonColor,\n themePrimaryTextColor: merchantTheme.primaryButtonColor,\n themeSecondaryTextColor: merchantTheme.secondaryButtonColor\n }\n });\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionDetails\", resp);\n this.paymentMethodsToShow = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.orderPaymentMethodsByUserPreference)((0,_utils__WEBPACK_IMPORTED_MODULE_2__.getPaymentOptionsToDisplay)(resp === null || resp === void 0 || (_resp$configs = resp.configs) === null || _resp$configs === void 0 ? void 0 : _resp$configs.paymentMethods, this.paymentMethods), this.paymentMethods);\n // this.paymentMethodsToShow = orderPaymentMethodsByUserPreference(\n // getPaymentOptionsToDisplay(resp?.configs?.paymentMethods, this.paymentMethods.includes('card') ? ['card'] : []),\n // this.paymentMethods\n // );\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"paymentMethodsToShow\", this.paymentMethodsToShow);\n if (!(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(this.paymentMethodsToShow)) {\n _context.n = 5;\n break;\n }\n return _context.a(2, (_this$onLoad2 = this.onLoad) === null || _this$onLoad2 === void 0 ? void 0 : _this$onLoad2.call(this, {\n message: \"No valid payment methods found\"\n }));\n case 5:\n this.shopper = this.shopperDetails || (resp === null || resp === void 0 || (_resp$paymentDetails3 = resp.paymentDetails) === null || _resp$paymentDetails3 === void 0 ? void 0 : _resp$paymentDetails3.shopper);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"shopper\", this.shopper);\n _resp$paymentDetails$ = resp === null || resp === void 0 || (_resp$paymentDetails4 = resp.paymentDetails) === null || _resp$paymentDetails4 === void 0 ? void 0 : _resp$paymentDetails4.money, amount = _resp$paymentDetails$.amount, currencySymbol = _resp$paymentDetails$.currencySymbol, currencyCode = _resp$paymentDetails$.currencyCode;\n formattedAmount = String((0,_utils__WEBPACK_IMPORTED_MODULE_2__.numberToCurrency)(amount, currencyCode));\n container.innerHTML = \"\";\n tabsContainer = undefined;\n this.activePaymentMethod = Object.keys(this.paymentMethodsToShow)[0];\n if (Object.keys(this.paymentMethodsToShow).length > 1) {\n tabsContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createTabsContainer)(this.paymentMethodsToShow, this.activePaymentMethod, this.switchPaymentMethod.bind(this));\n }\n formContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createFormContainer)();\n if (this.showPayButton) {\n payDiv = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayButton)(function () {\n return (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayLabel)(currencySymbol, formattedAmount);\n }, function (e) {\n e.preventDefault();\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(_this.boxpayPayButton, true);\n void _this.handlePayButtonClick();\n });\n payDiv.style.maxWidth = this.maxWidth + \"px\";\n this.boxpayPayButton = payDiv.querySelector(\"button\");\n }\n if (tabsContainer) {\n container.append(tabsContainer, formContainer);\n } else {\n container.append(formContainer);\n }\n this.handleSubscriptionCheckBox(rootDiv);\n if (this.showPayButton) {\n rootDiv.append(payDiv);\n }\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n for (_i = 0, _Object$keys = Object.keys(this.paymentMethodsToShow); _i < _Object$keys.length; _i++) {\n method = _Object$keys[_i];\n instance = (0,_utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__.createPaymentInstance)(method, formContainer, payDiv, this.paymentMethodsToShow, this.options || {}, this.handleFormValidityChange.bind(this), this.updatePayButtonText.bind(this), this);\n this.paymentInstances[method] = instance;\n }\n this.mountActiveMethod();\n (_this$onLoad3 = this.onLoad) === null || _this$onLoad3 === void 0 || _this$onLoad3.call(this, {\n message: \"Payment Elements Loaded\"\n });\n case 6:\n return _context.a(2);\n }\n }, _callee, this);\n }));\n function initialize() {\n return _initialize.apply(this, arguments);\n }\n return initialize;\n }()\n }, {\n key: \"handleSubscriptionCheckBox\",\n value: function handleSubscriptionCheckBox(rootDiv) {\n var isSubscription = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"isSubscription\");\n var oneTimePayment = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"oneTimePayment\");\n if (isSubscription && oneTimePayment) {\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('isOneTimePaymentChecked', true);\n // globalState.set('sendSiFlag', true);\n } else if (isSubscription && !oneTimePayment) {\n var siElement = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createCheckBox)(\"Setup automatic payments\", function () {});\n rootDiv.appendChild(siElement);\n // globalState.set('sendSiFlag', true);\n } else {\n // globalState.set('sendSiFlag', false);\n }\n }\n }, {\n key: \"switchPaymentMethod\",\n value: function switchPaymentMethod(method) {\n if (this.activePaymentMethod === method) return;\n this.activePaymentMethod = method;\n this.mountActiveMethod();\n this.handleFormValidityChange({\n isValid: false,\n invalidFields: []\n });\n this.updatePayButtonText();\n\n // stop if any status polling is going on\n var controller = {\n cancelled: true\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n }\n }, {\n key: \"mountActiveMethod\",\n value: function mountActiveMethod() {\n var _activeInstance$rende;\n var formContainer = document.getElementById(\"payment-form-container\");\n if (!formContainer) return;\n formContainer.innerHTML = \"\";\n var activeInstance = this.paymentInstances[this.activePaymentMethod];\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"CURRENT_PAYMENT_METHOD\", this.activePaymentMethod);\n activeInstance === null || activeInstance === void 0 || (_activeInstance$rende = activeInstance.render) === null || _activeInstance$rende === void 0 || _activeInstance$rende.call(activeInstance);\n (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.updateActiveTab)(this.activePaymentMethod);\n this.handleThemeColors();\n }\n }, {\n key: \"handleFormValidityChange\",\n value: function handleFormValidityChange(_ref) {\n var isValid = _ref.isValid,\n invalidFields = _ref.invalidFields;\n this.formValidity = {\n isValid: isValid,\n invalidFields: invalidFields\n };\n if (this.boxpayPayButton) this.boxpayPayButton.disabled = !isValid;\n if (!this.showPayButton) {\n if (typeof this.onPaymentButtonValidity === 'function') {\n this.onPaymentButtonValidity(isValid);\n }\n }\n }\n }, {\n key: \"handlePayButtonClick\",\n value: function () {\n var _handlePayButtonClick = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {\n var controller, res;\n return _regenerator().w(function (_context2) {\n while (1) switch (_context2.n) {\n case 0:\n console.log(\"PAY btn clicked\");\n if (!this.boxpayPayButton) {\n _context2.n = 2;\n break;\n }\n if (!this.boxpayPayButton.disabled) {\n _context2.n = 1;\n break;\n }\n return _context2.a(2);\n case 1:\n this.boxpayPayButton.disabled = true;\n case 2:\n controller = {\n cancelled: false\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"PAY_BTN_CLICKED\", {});\n _context2.n = 3;\n return (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handlePayClick)(this);\n case 3:\n res = _context2.v;\n return _context2.a(2, res);\n }\n }, _callee2, this);\n }));\n function handlePayButtonClick() {\n return _handlePayButtonClick.apply(this, arguments);\n }\n return handlePayButtonClick;\n }()\n }, {\n key: \"sendResponse\",\n value: function sendResponse(response) {\n if (this.boxpayPayButton) {\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(this.boxpayPayButton, false);\n }\n if ((response === null || response === void 0 ? void 0 : response.status) !== \"ERROR\") {\n var _this$onPayment;\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"SENDING_RESPONSE\", response);\n (_this$onPayment = this.onPayment) === null || _this$onPayment === void 0 || _this$onPayment.call(this, response);\n }\n return response;\n }\n }, {\n key: \"updatePayButtonText\",\n value: function updatePayButtonText(text) {\n var _this$sessionDetails;\n if (!this.boxpayPayButton) return;\n var _ref2 = ((_this$sessionDetails = this.sessionDetails) === null || _this$sessionDetails === void 0 || (_this$sessionDetails = _this$sessionDetails.paymentDetails) === null || _this$sessionDetails === void 0 ? void 0 : _this$sessionDetails.money) || {},\n amount = _ref2.amount,\n currencySymbol = _ref2.currencySymbol;\n this.boxpayPayButton.textContent = text || \"Pay \".concat(currencySymbol, \" \").concat(amount);\n }\n }]);\n}();\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (PaymentElements);\n\n//# sourceURL=webpack://boxpay-checkout-web-sdk/./src/components/paymentElements/PaymentElement.controller.ts?\n}");
|
|
1503
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../services/apiService/common.service */ \"./src/services/apiService/common.service.ts\");\n/* harmony import */ var _rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @rajesh896/broprint.js */ \"./node_modules/@rajesh896/broprint.js/lib/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _loader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../loader */ \"./src/components/loader.ts\");\n/* harmony import */ var _utils_domUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../utils/domUtils */ \"./src/utils/domUtils.ts\");\n/* harmony import */ var _utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../utils/paymentHandlers */ \"./src/utils/paymentHandlers.ts\");\n/* harmony import */ var _utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../utils/paymentInstanceFactory */ \"./src/utils/paymentInstanceFactory.ts\");\n/* harmony import */ var _state_globalState__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../state/globalState */ \"./src/state/globalState.ts\");\n/* harmony import */ var _utils_themeController__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../utils/themeController */ \"./src/utils/themeController.ts\");\n/* harmony import */ var _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../utils/EventBus */ \"./src/utils/EventBus.ts\");\nfunction _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); }\nfunction _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = \"function\" == typeof Symbol ? Symbol : {}, n = r.iterator || \"@@iterator\", o = r.toStringTag || \"@@toStringTag\"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, \"_invoke\", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError(\"Generator is already running\"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = \"next\"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError(\"iterator result is not an object\"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i[\"return\"]) && t.call(i), c < 2 && (u = TypeError(\"The iterator does not provide a '\" + o + \"' method\"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, \"GeneratorFunction\")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, \"constructor\", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, \"constructor\", GeneratorFunction), GeneratorFunction.displayName = \"GeneratorFunction\", _regeneratorDefine2(GeneratorFunctionPrototype, o, \"GeneratorFunction\"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, \"Generator\"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, \"toString\", function () { return \"[object Generator]\"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }\nfunction _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, \"\", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o(\"next\", 0), o(\"throw\", 1), o(\"return\", 2)); }, _regeneratorDefine2(e, r, n, t); }\nfunction 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); }\nfunction _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); }); }; }\nfunction _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError(\"Cannot call a class as a function\"); }\nfunction _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); } }\nfunction _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, \"prototype\", { writable: !1 }), e; }\nfunction _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; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == _typeof(i) ? i : i + \"\"; }\nfunction _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); }\n\n\n\n\n\n\n\n\n\n\nvar notAllowedPaymentStatuses = [\"EXPIRED\", \"PAID\", \"PROCESSING\", \"EXPIRED\", \"DISABLED\"];\nvar MAX_WIDTH = 1400;\nvar PaymentElements = /*#__PURE__*/function () {\n function PaymentElements(props) {\n var _props$options, _props$options2, _props$options3;\n _classCallCheck(this, PaymentElements);\n _defineProperty(this, \"activePaymentMethod\", \"\");\n _defineProperty(this, \"browserFingerprint\", \"\");\n _defineProperty(this, \"sessionDetails\", {});\n _defineProperty(this, \"paymentInstances\", {});\n _defineProperty(this, \"formValidity\", {\n isValid: false,\n invalidFields: []\n });\n // private oneTimePayment: boolean = false;\n _defineProperty(this, \"paymentMethodsToShow\", {});\n _defineProperty(this, \"showPayButton\", true);\n Object.assign(this, props);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('mode', this.mode);\n this.maxWidth = MAX_WIDTH;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('MAX_WIDTH', MAX_WIDTH);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('oneTimePayment', ((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.oneTimePayment) || false);\n this.initiatePayment = function () {};\n this.showPayButton = (_props$options2 = props.options) === null || _props$options2 === void 0 || (_props$options2 = _props$options2.payButton) === null || _props$options2 === void 0 ? void 0 : _props$options2.show;\n this.onPaymentButtonValidity = (_props$options3 = props.options) === null || _props$options3 === void 0 || (_props$options3 = _props$options3.payButton) === null || _props$options3 === void 0 ? void 0 : _props$options3.onPaymentButtonValidity;\n if (this.showPayButton === false) {\n this.initiatePayment = this.handlePayButtonClick.bind(this);\n }\n void this.initialize();\n }\n return _createClass(PaymentElements, [{\n key: \"handleThemeColors\",\n value: function handleThemeColors() {\n var theme = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get('appearance');\n document.querySelectorAll(\".label\").forEach(function (label) {\n return label.style.color = (theme === null || theme === void 0 ? void 0 : theme.primaryTextColor) || \"#333\";\n });\n }\n }, {\n key: \"initialize\",\n value: function () {\n var _initialize = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {\n var _resp$paymentDetails,\n _resp$paymentDetails2,\n _resp$merchantDetails,\n _resp$configs,\n _resp$paymentDetails3,\n _resp$paymentDetails4,\n _this = this,\n _this$onLoad3;\n var rootDiv, container, resp, isSubscription, _this$onLoad, merchantTheme, _this$onLoad2, _resp$paymentDetails$, amount, currencySymbol, currencyCode, formattedAmount, tabsContainer, formContainer, payDiv, _i, _Object$keys, method, instance;\n return _regenerator().w(function (_context) {\n while (1) switch (_context.n) {\n case 0:\n rootDiv = document.getElementById(this.container);\n container = document.createElement(\"div\");\n rootDiv.style.maxWidth = this.maxWidth + \"px\";\n rootDiv.classList.add(\"payment-elements-root\");\n rootDiv.innerHTML = '';\n container.classList.add(\"payment-elements-container\");\n if (container) {\n _context.n = 1;\n break;\n }\n throw new Error(\"\".concat(this.container, \" not found\"));\n case 1:\n (0,_loader__WEBPACK_IMPORTED_MODULE_3__.getLoaderTemplate)(container, \"Loading payment options...\");\n rootDiv.append(container);\n _context.n = 2;\n return (0,_rajesh896_broprint_js__WEBPACK_IMPORTED_MODULE_1__.getCurrentBrowserFingerPrint)();\n case 2:\n this.browserFingerprint = _context.v;\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionToken\", this.sessionToken);\n _context.n = 3;\n return (0,_services_apiService_common_service__WEBPACK_IMPORTED_MODULE_0__.getSession)(this.sessionToken);\n case 3:\n resp = _context.v;\n // check for subscription\n isSubscription = !(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(resp === null || resp === void 0 || (_resp$paymentDetails = resp.paymentDetails) === null || _resp$paymentDetails === void 0 ? void 0 : _resp$paymentDetails.subscriptionDetails);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"isSubscription\", isSubscription);\n if (!notAllowedPaymentStatuses.includes(resp.status)) {\n _context.n = 4;\n break;\n }\n return _context.a(2, (_this$onLoad = this.onLoad) === null || _this$onLoad === void 0 ? void 0 : _this$onLoad.call(this, {\n message: \"This checkout token is \".concat(resp === null || resp === void 0 ? void 0 : resp.status)\n }));\n case 4:\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('currencySymbol', resp === null || resp === void 0 || (_resp$paymentDetails2 = resp.paymentDetails) === null || _resp$paymentDetails2 === void 0 || (_resp$paymentDetails2 = _resp$paymentDetails2.money) === null || _resp$paymentDetails2 === void 0 ? void 0 : _resp$paymentDetails2.currencySymbol);\n this.sessionDetails = resp;\n merchantTheme = resp === null || resp === void 0 || (_resp$merchantDetails = resp.merchantDetails) === null || _resp$merchantDetails === void 0 ? void 0 : _resp$merchantDetails.checkoutTheme;\n (0,_utils_themeController__WEBPACK_IMPORTED_MODULE_8__.handleAppearanceOptions)({\n appearance: this.appearance,\n theme: {\n themePrimaryColor: merchantTheme.primaryButtonColor,\n themeSecondaryColor: merchantTheme.secondaryButtonColor,\n themePrimaryTextColor: merchantTheme.primaryButtonColor,\n themeSecondaryTextColor: merchantTheme.secondaryButtonColor\n }\n });\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"sessionDetails\", resp);\n // this.paymentMethodsToShow = orderPaymentMethodsByUserPreference(\n // getPaymentOptionsToDisplay(resp?.configs?.paymentMethods, this.paymentMethods),\n // this.paymentMethods\n // );\n this.paymentMethodsToShow = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.orderPaymentMethodsByUserPreference)((0,_utils__WEBPACK_IMPORTED_MODULE_2__.getPaymentOptionsToDisplay)(resp === null || resp === void 0 || (_resp$configs = resp.configs) === null || _resp$configs === void 0 ? void 0 : _resp$configs.paymentMethods, this.paymentMethods.includes('card') ? ['card'] : []), this.paymentMethods);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"paymentMethodsToShow\", this.paymentMethodsToShow);\n if (!(0,_utils__WEBPACK_IMPORTED_MODULE_2__.isEmpty)(this.paymentMethodsToShow)) {\n _context.n = 5;\n break;\n }\n return _context.a(2, (_this$onLoad2 = this.onLoad) === null || _this$onLoad2 === void 0 ? void 0 : _this$onLoad2.call(this, {\n message: \"No valid payment methods found\"\n }));\n case 5:\n this.shopper = this.shopperDetails || (resp === null || resp === void 0 || (_resp$paymentDetails3 = resp.paymentDetails) === null || _resp$paymentDetails3 === void 0 ? void 0 : _resp$paymentDetails3.shopper);\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"shopper\", this.shopper);\n _resp$paymentDetails$ = resp === null || resp === void 0 || (_resp$paymentDetails4 = resp.paymentDetails) === null || _resp$paymentDetails4 === void 0 ? void 0 : _resp$paymentDetails4.money, amount = _resp$paymentDetails$.amount, currencySymbol = _resp$paymentDetails$.currencySymbol, currencyCode = _resp$paymentDetails$.currencyCode;\n formattedAmount = String((0,_utils__WEBPACK_IMPORTED_MODULE_2__.numberToCurrency)(amount, currencyCode));\n container.innerHTML = \"\";\n tabsContainer = undefined;\n this.activePaymentMethod = Object.keys(this.paymentMethodsToShow)[0];\n if (Object.keys(this.paymentMethodsToShow).length > 1) {\n tabsContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createTabsContainer)(this.paymentMethodsToShow, this.activePaymentMethod, this.switchPaymentMethod.bind(this));\n }\n formContainer = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createFormContainer)();\n if (this.showPayButton) {\n payDiv = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayButton)(function () {\n return (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createPayLabel)(currencySymbol, formattedAmount);\n }, function (e) {\n e.preventDefault();\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(_this.boxpayPayButton, true);\n void _this.handlePayButtonClick();\n });\n payDiv.style.maxWidth = this.maxWidth + \"px\";\n this.boxpayPayButton = payDiv.querySelector(\"button\");\n }\n if (tabsContainer) {\n container.append(tabsContainer, formContainer);\n } else {\n container.append(formContainer);\n }\n this.handleSubscriptionCheckBox(rootDiv);\n if (this.showPayButton) {\n rootDiv.append(payDiv);\n }\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n for (_i = 0, _Object$keys = Object.keys(this.paymentMethodsToShow); _i < _Object$keys.length; _i++) {\n method = _Object$keys[_i];\n instance = (0,_utils_paymentInstanceFactory__WEBPACK_IMPORTED_MODULE_6__.createPaymentInstance)(method, formContainer, payDiv, this.paymentMethodsToShow, this.options || {}, this.handleFormValidityChange.bind(this), this.updatePayButtonText.bind(this), this);\n this.paymentInstances[method] = instance;\n }\n this.mountActiveMethod();\n (_this$onLoad3 = this.onLoad) === null || _this$onLoad3 === void 0 || _this$onLoad3.call(this, {\n message: \"Payment Elements Loaded\"\n });\n case 6:\n return _context.a(2);\n }\n }, _callee, this);\n }));\n function initialize() {\n return _initialize.apply(this, arguments);\n }\n return initialize;\n }()\n }, {\n key: \"handleSubscriptionCheckBox\",\n value: function handleSubscriptionCheckBox(rootDiv) {\n var isSubscription = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"isSubscription\");\n var oneTimePayment = _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.get(\"oneTimePayment\");\n if (isSubscription && oneTimePayment) {\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set('isOneTimePaymentChecked', true);\n // globalState.set('sendSiFlag', true);\n } else if (isSubscription && !oneTimePayment) {\n var siElement = (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.createCheckBox)(\"Setup automatic payments\", function () {});\n rootDiv.appendChild(siElement);\n // globalState.set('sendSiFlag', true);\n } else {\n // globalState.set('sendSiFlag', false);\n }\n }\n }, {\n key: \"switchPaymentMethod\",\n value: function switchPaymentMethod(method) {\n if (this.activePaymentMethod === method) return;\n this.activePaymentMethod = method;\n this.mountActiveMethod();\n this.handleFormValidityChange({\n isValid: false,\n invalidFields: []\n });\n this.updatePayButtonText();\n\n // stop if any status polling is going on\n var controller = {\n cancelled: true\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n }\n }, {\n key: \"mountActiveMethod\",\n value: function mountActiveMethod() {\n var _activeInstance$rende;\n var formContainer = document.getElementById(\"payment-form-container\");\n if (!formContainer) return;\n formContainer.innerHTML = \"\";\n var activeInstance = this.paymentInstances[this.activePaymentMethod];\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"activePaymentMethod\", this.activePaymentMethod);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"CURRENT_PAYMENT_METHOD\", this.activePaymentMethod);\n activeInstance === null || activeInstance === void 0 || (_activeInstance$rende = activeInstance.render) === null || _activeInstance$rende === void 0 || _activeInstance$rende.call(activeInstance);\n (0,_utils_domUtils__WEBPACK_IMPORTED_MODULE_4__.updateActiveTab)(this.activePaymentMethod);\n this.handleThemeColors();\n }\n }, {\n key: \"handleFormValidityChange\",\n value: function handleFormValidityChange(_ref) {\n var isValid = _ref.isValid,\n invalidFields = _ref.invalidFields;\n this.formValidity = {\n isValid: isValid,\n invalidFields: invalidFields\n };\n if (this.boxpayPayButton) this.boxpayPayButton.disabled = !isValid;\n if (!this.showPayButton) {\n if (typeof this.onPaymentButtonValidity === 'function') {\n this.onPaymentButtonValidity(isValid);\n }\n }\n }\n }, {\n key: \"handlePayButtonClick\",\n value: function () {\n var _handlePayButtonClick = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {\n var controller, res;\n return _regenerator().w(function (_context2) {\n while (1) switch (_context2.n) {\n case 0:\n console.log(\"PAY btn clicked\");\n if (!this.boxpayPayButton) {\n _context2.n = 2;\n break;\n }\n if (!this.boxpayPayButton.disabled) {\n _context2.n = 1;\n break;\n }\n return _context2.a(2);\n case 1:\n this.boxpayPayButton.disabled = true;\n case 2:\n controller = {\n cancelled: false\n };\n _state_globalState__WEBPACK_IMPORTED_MODULE_7__.globalState.set(\"pollController\", controller);\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"PAY_BTN_CLICKED\", {});\n _context2.n = 3;\n return (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handlePayClick)(this);\n case 3:\n res = _context2.v;\n return _context2.a(2, res);\n }\n }, _callee2, this);\n }));\n function handlePayButtonClick() {\n return _handlePayButtonClick.apply(this, arguments);\n }\n return handlePayButtonClick;\n }()\n }, {\n key: \"sendResponse\",\n value: function sendResponse(response) {\n if (this.boxpayPayButton) {\n (0,_utils_paymentHandlers__WEBPACK_IMPORTED_MODULE_5__.handleButtonLoader)(this.boxpayPayButton, false);\n }\n if ((response === null || response === void 0 ? void 0 : response.status) !== \"ERROR\") {\n var _this$onPayment;\n _utils_EventBus__WEBPACK_IMPORTED_MODULE_9__.EventBus.emit(\"SENDING_RESPONSE\", response);\n (_this$onPayment = this.onPayment) === null || _this$onPayment === void 0 || _this$onPayment.call(this, response);\n }\n return response;\n }\n }, {\n key: \"updatePayButtonText\",\n value: function updatePayButtonText(text) {\n var _this$sessionDetails;\n if (!this.boxpayPayButton) return;\n var _ref2 = ((_this$sessionDetails = this.sessionDetails) === null || _this$sessionDetails === void 0 || (_this$sessionDetails = _this$sessionDetails.paymentDetails) === null || _this$sessionDetails === void 0 ? void 0 : _this$sessionDetails.money) || {},\n amount = _ref2.amount,\n currencySymbol = _ref2.currencySymbol;\n this.boxpayPayButton.textContent = text || \"Pay \".concat(currencySymbol, \" \").concat(amount);\n }\n }]);\n}();\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (PaymentElements);\n\n//# sourceURL=webpack://boxpay-checkout-web-sdk/./src/components/paymentElements/PaymentElement.controller.ts?\n}");
|
|
1504
1504
|
|
|
1505
1505
|
/***/ }),
|
|
1506
1506
|
|