@alipay/ams-checkout 1.3.1-dev → 1.3.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.
Files changed (57) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/package.json +1 -54
  3. package/dist/esm/config/index.d.ts +0 -22
  4. package/dist/esm/config/index.js +0 -69
  5. package/dist/esm/constant/index.d.ts +0 -135
  6. package/dist/esm/constant/index.js +0 -135
  7. package/dist/esm/core/component/index.d.ts +0 -17
  8. package/dist/esm/core/component/index.js +0 -127
  9. package/dist/esm/core/drop-in/index.d.ts +0 -29
  10. package/dist/esm/core/drop-in/index.js +0 -104
  11. package/dist/esm/core/instance/index.d.ts +0 -67
  12. package/dist/esm/core/instance/index.js +0 -276
  13. package/dist/esm/image/cta.svg +0 -9
  14. package/dist/esm/index.d.ts +0 -22
  15. package/dist/esm/plugin/component/cashierApp.d.ts +0 -24
  16. package/dist/esm/plugin/component/cashierApp.js +0 -140
  17. package/dist/esm/plugin/component/component.style.d.ts +0 -8
  18. package/dist/esm/plugin/component/component.style.js +0 -15
  19. package/dist/esm/plugin/component/index.d.ts +0 -101
  20. package/dist/esm/plugin/component/index.js +0 -875
  21. package/dist/esm/plugin/drop-in/index.d.ts +0 -73
  22. package/dist/esm/plugin/drop-in/index.js +0 -323
  23. package/dist/esm/request/index.d.ts +0 -15
  24. package/dist/esm/request/index.js +0 -145
  25. package/dist/esm/request/utils.d.ts +0 -28
  26. package/dist/esm/request/utils.js +0 -59
  27. package/dist/esm/service/index.d.ts +0 -2
  28. package/dist/esm/service/index.js +0 -40
  29. package/dist/esm/types/index.d.ts +0 -194
  30. package/dist/esm/types/index.js +0 -94
  31. package/dist/esm/util/createIframeNode.d.ts +0 -5
  32. package/dist/esm/util/createIframeNode.js +0 -35
  33. package/dist/esm/util/get.d.ts +0 -25
  34. package/dist/esm/util/get.js +0 -145
  35. package/dist/esm/util/index.d.ts +0 -53
  36. package/dist/esm/util/index.js +0 -235
  37. package/dist/esm/util/intl-callapp/es/browser.d.ts +0 -21
  38. package/dist/esm/util/intl-callapp/es/browser.js +0 -42
  39. package/dist/esm/util/intl-callapp/es/evoke.d.ts +0 -13
  40. package/dist/esm/util/intl-callapp/es/evoke.js +0 -39
  41. package/dist/esm/util/intl-callapp/es/generate.d.ts +0 -29
  42. package/dist/esm/util/intl-callapp/es/generate.js +0 -44
  43. package/dist/esm/util/intl-callapp/es/index.d.ts +0 -43
  44. package/dist/esm/util/intl-callapp/es/index.js +0 -298
  45. package/dist/esm/util/intl-callapp/es/main.d.ts +0 -41
  46. package/dist/esm/util/intl-callapp/es/main.js +0 -305
  47. package/dist/esm/util/intl-callapp/es/openWallet.d.ts +0 -15
  48. package/dist/esm/util/intl-callapp/es/openWallet.js +0 -197
  49. package/dist/esm/util/intl-callapp/es/types.d.ts +0 -46
  50. package/dist/esm/util/intl-callapp/es/types.js +0 -1
  51. package/dist/esm/util/intl-callapp/es/utils/config.d.ts +0 -24
  52. package/dist/esm/util/intl-callapp/es/utils/config.js +0 -57
  53. package/dist/esm/util/intl-callapp/es/utils/index.d.ts +0 -15
  54. package/dist/esm/util/intl-callapp/es/utils/index.js +0 -98
  55. package/dist/esm/util/mock.d.ts +0 -1
  56. package/dist/esm/util/mock.js +0 -4
  57. /package/{dist/esm → esm}/index.js +0 -0
@@ -1,875 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
13
- /**
14
- * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
15
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
- * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
17
- * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
18
- */
19
- /* eslint-disable no-console */
20
- import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
21
- import { queryPaymentInfo } from "../../service";
22
- import { componentNameEnum, messageName, Target } from "../../types";
23
- import { getDesignFontSize, getType, isJsonString, isPC } from "../../util";
24
- import { isLocalMock } from "../../util/mock";
25
- import { createIframe, getAppDomain, getIframeUrl } from "./cashierApp";
26
- import { componentAddCSS } from "./component.style";
27
- var amsSetSize = function amsSetSize(event, dom) {
28
- try {
29
- var _dom = dom || document.getElementById('ams-component-container');
30
- _dom.style.fontSize = "".concat(getDesignFontSize(), "px");
31
- // eslint-disable-next-line no-empty
32
- } catch (error) {}
33
- };
34
- var addEvent = function addEvent() {
35
- window.removeEventListener('resize', amsSetSize);
36
- window.removeEventListener('pageShow', amsSetSize);
37
- window.removeEventListener('DOMContentLoaded', amsSetSize);
38
- window.addEventListener('resize', amsSetSize);
39
- window.addEventListener('pageShow', amsSetSize);
40
- window.addEventListener('DOMContentLoaded', amsSetSize);
41
- };
42
- var _window = window,
43
- innerHeight = _window.innerHeight;
44
- var mockupId = 'ams-component-mockup';
45
- var loadingId = 'ams-component-loading';
46
- var ComponentApp = /*#__PURE__*/function () {
47
- function ComponentApp() {
48
- _classCallCheck(this, ComponentApp);
49
- _defineProperty(this, "app", void 0);
50
- _defineProperty(this, "appDomain", void 0);
51
- _defineProperty(this, "AMSSDK", void 0);
52
- _defineProperty(this, "platform", void 0);
53
- _defineProperty(this, "createIframeNode", void 0);
54
- _defineProperty(this, "_selector", void 0);
55
- _defineProperty(this, "_appVersion", void 0);
56
- _defineProperty(this, "_isRetention", void 0);
57
- _defineProperty(this, "_actionQueryPromise", null);
58
- _defineProperty(this, "_renderParams", null);
59
- _defineProperty(this, "_componentName", '');
60
- _defineProperty(this, "_performanceData", []);
61
- _defineProperty(this, "_isInitComponent", void 0);
62
- _defineProperty(this, "_clickEventName", void 0);
63
- this._appVersion = '1.3.1';
64
- this._isInitComponent = false;
65
- this._selector = '#ams-component-section';
66
- this.createIframeNode = function () {
67
- return Promise.resolve();
68
- };
69
- this.platform = isPC() ? 'desktop' : 'mobile';
70
- this._clickEventName = this.platform === 'mobile' ? 'touchend' : 'click';
71
- this._isRetention = true;
72
- addEvent();
73
- this.createMountElement();
74
- this._performanceData.push({
75
- key: 'sdk_init',
76
- value: Date.now()
77
- });
78
- }
79
-
80
- /**
81
- * @description Cancel listening and destroy the dom
82
- */
83
- _createClass(ComponentApp, [{
84
- key: "logoutPlugin",
85
- value: function logoutPlugin() {
86
- this.closeCashier();
87
- }
88
-
89
- /**
90
- * @description When SDK registers plug-ins, it is a required function to receive SDK instances
91
- */
92
- }, {
93
- key: "applyPlugin",
94
- value: function applyPlugin(AMSSDK) {
95
- this.AMSSDK = AMSSDK;
96
- this.subscribeFromSDK();
97
- }
98
-
99
- /**
100
- * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
101
- */
102
- }, {
103
- key: "setRender",
104
- value: function setRender(createIframeNode) {
105
- this.createIframeNode = createIframeNode;
106
- }
107
-
108
- /**
109
- * @description render iframe content
110
- */
111
- }, {
112
- key: "appendIframeNodes",
113
- value: function appendIframeNodes(componentName, renderParams) {
114
- var _renderParams$appeara,
115
- _this = this;
116
- if (this._isInitComponent) return Promise.reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
117
- this._isInitComponent = true;
118
- this._renderParams = renderParams;
119
- this._componentName = componentName;
120
- this._performanceData.push({
121
- key: 'sdk_create_component',
122
- value: Date.now()
123
- });
124
- this.createRetentionPopup();
125
- this.createMockup();
126
- if ((renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$appeara = renderParams.appearance) === null || _renderParams$appeara === void 0 ? void 0 : _renderParams$appeara.showLoading) !== false) {
127
- var mockup = document.getElementById(mockupId);
128
- if (mockup) {
129
- mockup.style.display = 'block';
130
- }
131
- this.showLoading();
132
- }
133
- this.showCashier();
134
- this.createApp(renderParams);
135
- this.createActionQueryPromise();
136
- return Promise.all([this.createIframeNode(this, _objectSpread(_objectSpread({}, renderParams), {}, {
137
- selector: this._selector
138
- })), this._actionQueryPromise]).catch(function () {
139
- _this._isInitComponent = false;
140
- });
141
- }
142
- /**
143
- * @description Interface request
144
- */
145
- }, {
146
- key: "createActionQueryPromise",
147
- value: function createActionQueryPromise() {
148
- var _this2 = this;
149
- this._performanceData.push({
150
- key: 'sdk_action_query_start',
151
- value: Date.now()
152
- });
153
- this._actionQueryPromise = new Promise(function (resolve, reject) {
154
- var _this2$_renderParams, _this2$_renderParams2, _this2$_renderParams3;
155
- var params = {
156
- paymentSessionData: _this2._renderParams && ((_this2$_renderParams = _this2._renderParams) === null || _this2$_renderParams === void 0 ? void 0 : _this2$_renderParams.paymentSessionData) || '',
157
- paymentSessionConfig: (_this2$_renderParams2 = _this2._renderParams) === null || _this2$_renderParams2 === void 0 ? void 0 : (_this2$_renderParams3 = _this2$_renderParams2.paymentSessionMetaData) === null || _this2$_renderParams3 === void 0 ? void 0 : _this2$_renderParams3.paymentSessionConfig
158
- };
159
- if (componentNameEnum.card === _this2._componentName) {
160
- params.paymentMethodType = 'CARD';
161
- }
162
- if (componentNameEnum.easyPay === _this2._componentName) {
163
- var _this2$_renderParams4;
164
- // if EASY_PAY 2.0 , no need to query payment request
165
- var _ref = params.paymentSessionConfig || {},
166
- _ref$productSceneVers = _ref.productSceneVersion,
167
- productSceneVersion = _ref$productSceneVers === void 0 ? '' : _ref$productSceneVers,
168
- _ref$productScene = _ref.productScene,
169
- productScene = _ref$productScene === void 0 ? '' : _ref$productScene;
170
- var _ref2 = ((_this2$_renderParams4 = _this2._renderParams) === null || _this2$_renderParams4 === void 0 ? void 0 : _this2$_renderParams4.paymentSessionMetaData) || {},
171
- _ref2$action = _ref2.action,
172
- _ref2$action2 = _ref2$action === void 0 ? {} : _ref2$action,
173
- _ref2$action2$autoDeb = _ref2$action2.autoDebitWithToken,
174
- autoDebitWithToken = _ref2$action2$autoDeb === void 0 ? false : _ref2$action2$autoDeb;
175
- if (productScene === 'EASY_PAY' && productSceneVersion === '2.0' && !autoDebitWithToken) {
176
- // make queryResult no data we setAppStateData in antom-web-checkout app,
177
- // eslint-disable-next-line no-promise-executor-return
178
- return resolve({
179
- message: 'sdk no need to make query request'
180
- });
181
- }
182
- }
183
- /**
184
- * @author tianqiang
185
- * @description 代扣逻辑处理
186
- */
187
- if (componentNameEnum.autoDebit === _this2._componentName) {
188
- var _this2$_renderParams5, _this2$_renderParams6, _action$web, _action$wap;
189
- var action = ((_this2$_renderParams5 = _this2._renderParams) === null || _this2$_renderParams5 === void 0 ? void 0 : (_this2$_renderParams6 = _this2$_renderParams5.paymentSessionMetaData) === null || _this2$_renderParams6 === void 0 ? void 0 : _this2$_renderParams6.action) || {};
190
- var signType = (isPC() ? action === null || action === void 0 ? void 0 : (_action$web = action.web) === null || _action$web === void 0 ? void 0 : _action$web.signType : action === null || action === void 0 ? void 0 : (_action$wap = action.wap) === null || _action$wap === void 0 ? void 0 : _action$wap.signType) || '';
191
- if (signType === 'SMS') {
192
- return resolve({
193
- message: 'sdk no need to make query request'
194
- });
195
- } else if (!signType || signType !== 'REDIRECT') {
196
- return resolve({
197
- success: false
198
- });
199
- }
200
- }
201
-
202
- // mock
203
- if (isLocalMock()) {
204
- return resolve({
205
- message: 'sdk no need to make query request'
206
- });
207
- }
208
- queryPaymentInfo(params, {
209
- env: _this2.AMSSDK.options.env.environment,
210
- locale: _this2.AMSSDK.options.locale
211
- }).then(function (res) {
212
- _this2._performanceData.push({
213
- key: 'sdk_action_query_end',
214
- value: Date.now()
215
- });
216
- if (res && res.success) {
217
- resolve(res);
218
- } else {
219
- resolve(res);
220
- _this2.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR);
221
- }
222
- }).catch(function (err) {
223
- reject(err);
224
- _this2.closeCashier();
225
- });
226
- });
227
- }
228
- }, {
229
- key: "cleanApp",
230
- value: function cleanApp() {
231
- try {
232
- this.app = null;
233
- this._removeEventListener();
234
- if (getType(this._selector) === 'string') {
235
- var dorpinDom = document.querySelector(this._selector);
236
- if (dorpinDom) dorpinDom.innerHTML = '';
237
- }
238
- // eslint-disable-next-line no-empty
239
- } catch (error) {}
240
- }
241
-
242
- /**
243
- * @description Create app
244
- */
245
- }, {
246
- key: "createApp",
247
- value: function createApp(renderParams) {
248
- if (!!window.postMessage !== true) {
249
- this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.BROWSER_NOT_SUPPORT_POSTMESSAGE);
250
- return;
251
- }
252
- this._performanceData.push({
253
- key: 'sdk_popup_start',
254
- value: Date.now()
255
- });
256
- try {
257
- var _renderParams$payment, _renderParams$payment2, _renderParams$payment3;
258
- var productSceneVersion = (renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$payment = renderParams.paymentSessionMetaData) === null || _renderParams$payment === void 0 ? void 0 : (_renderParams$payment2 = _renderParams$payment.paymentSessionConfig) === null || _renderParams$payment2 === void 0 ? void 0 : _renderParams$payment2.productSceneVersion) || '';
259
- var extendInfo = (renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$payment3 = renderParams.paymentSessionMetaData) === null || _renderParams$payment3 === void 0 ? void 0 : _renderParams$payment3.extendInfo) || '';
260
- var environment = this.AMSSDK.options.env.environment;
261
- this.appDomain = getAppDomain({
262
- environment: environment,
263
- appVersion: this._appVersion,
264
- componentName: this._componentName,
265
- productSceneVersion: productSceneVersion,
266
- extendInfo: extendInfo
267
- });
268
- this.app = createIframe(this.AMSSDK.options.mode);
269
- this.app.src = getIframeUrl({
270
- componentName: this._componentName,
271
- appearance: (renderParams === null || renderParams === void 0 ? void 0 : renderParams.appearance) || {},
272
- analytics: this.AMSSDK.options.analytics,
273
- productSceneVersion: productSceneVersion,
274
- environment: environment,
275
- appVersion: this._appVersion,
276
- extendInfo: extendInfo,
277
- locale: this.AMSSDK.options.locale,
278
- instanceId: this.AMSSDK._instanceId
279
- });
280
-
281
- // Subscribe to messages from iframe
282
- this._addEventListener();
283
- } catch (error) {
284
- this.dispatchToSDK(EVENT.error.name, Object.assign({}, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.FAILED_TO_CREATE_IFRAME, {
285
- stack: error
286
- }));
287
- }
288
- }
289
- }, {
290
- key: "listener",
291
- value: function listener(e) {
292
- if (e.origin !== this.appDomain) {
293
- return;
294
- }
295
- var isJson = isJsonString(e.data);
296
- if (isJson) {
297
- var data = JSON.parse(e.data);
298
- if (data.name !== messageName.APP_TO_SDK && data.name !== messageName.APP_TO_APP || data.instanceId !== this.AMSSDK._instanceId) {
299
- return;
300
- }
301
- this._handleAppMessage(data);
302
- } else {
303
- console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
304
- this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.NOT_JSON_FORMAT);
305
- }
306
- }
307
-
308
- /**
309
- * @description Initialize subscription iframe message
310
- */
311
- }, {
312
- key: "_addEventListener",
313
- value: function _addEventListener() {
314
- window["_ams_sdk_component_listener_".concat(this.AMSSDK._instanceId)] = this.listener.bind(this);
315
- this._removeEventListener();
316
- window.addEventListener('message', window["_ams_sdk_component_listener_".concat(this.AMSSDK._instanceId)]);
317
- }
318
- }, {
319
- key: "_removeEventListener",
320
- value: function _removeEventListener() {
321
- window.removeEventListener('message', window["_ams_sdk_component_listener_".concat(this.AMSSDK._instanceId)]);
322
- }
323
-
324
- /**
325
- * @description Processing messages from iframe
326
- */
327
- }, {
328
- key: "_handleAppMessage",
329
- value: function _handleAppMessage(data) {
330
- var eventKeyMap = [EVENT.launch.name, EVENT.redirect.name, EVENT.sizeChanged.name, EVENT.log.name, EVENT.onClose.name, EVENT.eventCallback.name, EVENT.submitForm.name, EVENT.showCloseButton.name, EVENT.hideCloseButton.name, EVENT.setAllowRetention.name, EVENT.declareCheckoutInfo.name, EVENT.showPopup.name, EVENT.dismissLoading.name];
331
- if (data.context.event === EVENT.dismissLoading.name) {
332
- var _data$context$data;
333
- this.dispatchToSDK(EVENT.eventCallback.name, {
334
- code: 'SDK_END_OF_LOADING',
335
- message: ((_data$context$data = data.context.data) === null || _data$context$data === void 0 ? void 0 : _data$context$data.message) || ''
336
- });
337
- return;
338
- }
339
- if (!eventKeyMap.includes(data.context.event)) {
340
- return;
341
- }
342
- if (data.context.event === EVENT.launch.name) {
343
- this._performanceData.push({
344
- key: 'sdk_onLaunch',
345
- value: Date.now()
346
- });
347
- this.sendRenderEvent();
348
- return;
349
- }
350
- if (data.context.event === EVENT.sizeChanged.name) {
351
- this.handleSizeChanged(data);
352
- }
353
- if (data.context.event === EVENT.onClose.name) {
354
- return this.closeBtnFunc();
355
- }
356
- if (data.context.event === EVENT.redirect.name) {
357
- return this.handleRedirect(data.context.data);
358
- }
359
- if (data.context.event === EVENT.submitForm.name) {
360
- this.submitForm(data.context.data);
361
- return;
362
- }
363
- if (data.context.event === EVENT.hideCloseButton.name) {
364
- this.handleCloseBtnShow(false);
365
- return;
366
- }
367
- if (data.context.event === EVENT.showCloseButton.name) {
368
- this.handleCloseBtnShow(true);
369
- return;
370
- }
371
- if (data.context.event === EVENT.setAllowRetention.name) {
372
- if (data.context.data === true) this._isRetention = true;
373
- if (data.context.data === false) this._isRetention = false;
374
- return;
375
- }
376
- if (data.context.event === EVENT.declareCheckoutInfo.name) {
377
- this.handleDeclareInfo(data.context.data);
378
- return;
379
- }
380
-
381
- // The plug-in communicates with the sdk after processing
382
- this.dispatchToSDK(data.context.event, data.context.data);
383
- }
384
- }, {
385
- key: "handleSizeChanged",
386
- value: function handleSizeChanged(data) {
387
- var _data$context$data2;
388
- if (((_data$context$data2 = data.context.data) === null || _data$context$data2 === void 0 ? void 0 : _data$context$data2.height) > 1) {
389
- var _document$getElementB;
390
- var mockup = document.getElementById(mockupId);
391
- if (mockup) {
392
- mockup.style.background = '#000000';
393
- mockup.style.opacity = '0.6';
394
- mockup.style.display = 'block';
395
- }
396
- (_document$getElementB = document.getElementById(loadingId)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
397
- var cashier = document.getElementById('ams-component-container');
398
- cashier.style.height = "".concat(data.context.data.height, "px");
399
- if (this.platform === 'desktop') {
400
- cashier.classList.add('ams-component-container-desktop-animation');
401
- if (data.context.data.width) cashier.style.width = "".concat(data.context.data.width, "px");
402
- }
403
- if (this.platform === 'mobile') {
404
- cashier.classList.add('ams-component-container-mobile-animation');
405
- var animationStyleId = 'ams-component-container-mobile-animation-style';
406
- var animationStyle = document.getElementById(animationStyleId);
407
- if (animationStyle) animationStyle === null || animationStyle === void 0 ? void 0 : animationStyle.remove();
408
-
409
- // 弹出和弹入动画
410
- var runkeyframes = " @keyframes ams-component-container-slide-in {\n 0% {\n height: 1px;\n }\n 100% {\n height: ".concat(data.context.data.height, "px;\n }\n }\n @keyframes ams-component-container-slide-out {\n 0% {\n height: ").concat(data.context.data.height, "px;\n opacity: 1;\n }\n 50% {\n opacity: 1;\n }\n 100% {\n height: 1px;\n opacity: 0;\n }\n }");
411
- // 创建style标签
412
- var style = document.createElement('style');
413
- style.id = animationStyleId;
414
- // 设置style属性
415
- style.type = 'text/css';
416
- // 将 keyframes样式写入style内
417
- style.innerHTML = runkeyframes;
418
- // 将style样式存放到head标签
419
- document.getElementsByTagName('head')[0].appendChild(style);
420
-
421
- // size变动时动画
422
- setTimeout(function () {
423
- cashier.style.transition = 'height 0.28s ease-in-out';
424
- }, 400);
425
- }
426
- this.app.style.height = "".concat(data.context.data.height, "px");
427
- this.app.style.width = '100%';
428
- this.app.style.border = '0';
429
- this.app.style.overflow = 'hidden';
430
- }
431
- }
432
- }, {
433
- key: "handleRedirect",
434
- value: function handleRedirect(data) {
435
- var _this3 = this;
436
- this.closeCashier();
437
- var _data = typeof data === 'string' ? {
438
- normalUrl: data
439
- } : {
440
- applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
441
- schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
442
- normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
443
- target: data === null || data === void 0 ? void 0 : data.target
444
- };
445
- var successCallback = function successCallback(type, url) {
446
- _this3.dispatchToSDK(EVENT.eventCallback.name, {
447
- code: 'SDK_CALL_URL_SUCCESS',
448
- message: "Successfully opened the app,".concat(type, ": ").concat(url)
449
- });
450
- };
451
- var failCallback = function failCallback() {
452
- _this3.dispatchToSDK(EVENT.eventCallback.name, {
453
- code: 'SDK_CALL_URL_ERROR',
454
- message: "Failed to open app,applinkUrl: ".concat(_data === null || _data === void 0 ? void 0 : _data.applinkUrl, " schemeUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.schemeUrl, " normalUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.normalUrl)
455
- });
456
- };
457
-
458
- // pc端支持 target: _blank,新开tab页打开
459
- if (_data.target === Target.BLANK) {
460
- successCallback('normalUrl', _data.normalUrl);
461
- if (!_data.normalUrl) return;
462
- window.open(_data.normalUrl);
463
- return;
464
- }
465
- this.AMSSDK._redirect({
466
- applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
467
- }).then(function () {
468
- successCallback('applinkUrl', _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
469
- }).catch(function () {
470
- return _this3.AMSSDK._redirect({
471
- schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl
472
- });
473
- }).then(function () {
474
- successCallback('schemeUrl', _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
475
- }).catch(function () {
476
- return _this3.AMSSDK._redirect({
477
- normalUrl: _data === null || _data === void 0 ? void 0 : _data.normalUrl
478
- });
479
- }).then(function () {
480
- successCallback('normalUrl', _data === null || _data === void 0 ? void 0 : _data.normalUrl);
481
- }).catch(function () {
482
- failCallback();
483
- });
484
- }
485
- }, {
486
- key: "handleDeclareInfo",
487
- value: function handleDeclareInfo(_ref3) {
488
- var _ref3$closeDialogData = _ref3.closeDialogData,
489
- closeDialogData = _ref3$closeDialogData === void 0 ? {} : _ref3$closeDialogData;
490
- try {
491
- if (closeDialogData) {
492
- var retentionTitle = document.getElementById('ams-component-retention-title');
493
- if (retentionTitle) {
494
- var _closeDialogData$titl, _closeDialogData$titl2, _closeDialogData$titl3;
495
- retentionTitle.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl = closeDialogData.title) === null || _closeDialogData$titl === void 0 ? void 0 : _closeDialogData$titl.fontSize, "px");
496
- retentionTitle.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl2 = closeDialogData.title) === null || _closeDialogData$titl2 === void 0 ? void 0 : _closeDialogData$titl2.fontColor;
497
- retentionTitle.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl3 = closeDialogData.title) === null || _closeDialogData$titl3 === void 0 ? void 0 : _closeDialogData$titl3.text;
498
- }
499
- var retentionMessage = document.getElementById('ams-component-retention-sub-title');
500
- if (retentionMessage) {
501
- var _closeDialogData$mess, _closeDialogData$mess2, _closeDialogData$mess3;
502
- retentionMessage.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess = closeDialogData.message) === null || _closeDialogData$mess === void 0 ? void 0 : _closeDialogData$mess.fontSize, "px");
503
- retentionMessage.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess2 = closeDialogData.message) === null || _closeDialogData$mess2 === void 0 ? void 0 : _closeDialogData$mess2.fontColor;
504
- retentionMessage.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess3 = closeDialogData.message) === null || _closeDialogData$mess3 === void 0 ? void 0 : _closeDialogData$mess3.text;
505
- }
506
- var remainBtn = document.getElementById('ams-component-retention-remain');
507
- if (remainBtn) {
508
- var _closeDialogData$btnO, _closeDialogData$btnO2, _closeDialogData$btnO3, _closeDialogData$btnO4, _closeDialogData$btnO5, _closeDialogData$btnO7;
509
- remainBtn.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO = closeDialogData.btnOK) === null || _closeDialogData$btnO === void 0 ? void 0 : _closeDialogData$btnO.text;
510
- remainBtn.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO2 = closeDialogData.btnOK) === null || _closeDialogData$btnO2 === void 0 ? void 0 : _closeDialogData$btnO2.fontSize, "px");
511
- remainBtn.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO3 = closeDialogData.btnOK) === null || _closeDialogData$btnO3 === void 0 ? void 0 : _closeDialogData$btnO3.fontColor;
512
- remainBtn.style.borderRadius = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO4 = closeDialogData.btnOK) === null || _closeDialogData$btnO4 === void 0 ? void 0 : _closeDialogData$btnO4.corner, "px");
513
- if ((closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO5 = closeDialogData.btnOK) === null || _closeDialogData$btnO5 === void 0 ? void 0 : _closeDialogData$btnO5.type) === 'stroke') {
514
- var _closeDialogData$btnO6;
515
- remainBtn.style.border = "1px solid ".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO6 = closeDialogData.btnOK) === null || _closeDialogData$btnO6 === void 0 ? void 0 : _closeDialogData$btnO6.bg);
516
- } else remainBtn.style.backgroundColor = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO7 = closeDialogData.btnOK) === null || _closeDialogData$btnO7 === void 0 ? void 0 : _closeDialogData$btnO7.bg;
517
- }
518
- var leaveBrn = document.getElementById('ams-component-retention-leave');
519
- if (leaveBrn) {
520
- var _closeDialogData$btnC, _closeDialogData$btnC2, _closeDialogData$btnC3, _closeDialogData$btnC4, _closeDialogData$btnC5, _closeDialogData$btnC7;
521
- leaveBrn.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC = closeDialogData.btnCancel) === null || _closeDialogData$btnC === void 0 ? void 0 : _closeDialogData$btnC.text;
522
- leaveBrn.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC2 = closeDialogData.btnCancel) === null || _closeDialogData$btnC2 === void 0 ? void 0 : _closeDialogData$btnC2.fontSize, "px");
523
- leaveBrn.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC3 = closeDialogData.btnCancel) === null || _closeDialogData$btnC3 === void 0 ? void 0 : _closeDialogData$btnC3.fontColor;
524
- leaveBrn.style.borderRadius = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC4 = closeDialogData.btnCancel) === null || _closeDialogData$btnC4 === void 0 ? void 0 : _closeDialogData$btnC4.corner, "px");
525
- if ((closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC5 = closeDialogData.btnCancel) === null || _closeDialogData$btnC5 === void 0 ? void 0 : _closeDialogData$btnC5.type) === 'stroke') {
526
- var _closeDialogData$btnC6;
527
- leaveBrn.style.border = "1px solid ".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC6 = closeDialogData.btnCancel) === null || _closeDialogData$btnC6 === void 0 ? void 0 : _closeDialogData$btnC6.bg);
528
- } else leaveBrn.style.backgroundColor = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC7 = closeDialogData.btnCancel) === null || _closeDialogData$btnC7 === void 0 ? void 0 : _closeDialogData$btnC7.bg;
529
- }
530
- }
531
- } catch (error) {
532
- console.error(error);
533
- }
534
- }
535
- }, {
536
- key: "handleCloseBtnShow",
537
- value: function handleCloseBtnShow(showClose) {
538
- var closeBlock = document.getElementById('asm-component-section-close-block');
539
- if (showClose) {
540
- closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.remove('asm-component-close-block-hidden');
541
- } else if (showClose === false) {
542
- closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.add('asm-component-close-block-hidden');
543
- }
544
- }
545
-
546
- /**
547
- * @description Send message to SDK
548
- */
549
- }, {
550
- key: "dispatchToSDK",
551
- value: function dispatchToSDK(event, data) {
552
- this.AMSSDK.eventCenter.emit(event, data);
553
- }
554
-
555
- /**
556
- * @description Send message to iframe
557
- */
558
- }, {
559
- key: "dispatchToApp",
560
- value: function dispatchToApp(data) {
561
- if (this.app && this.app.contentWindow) {
562
- this.app.contentWindow.postMessage(JSON.stringify(data), this.appDomain);
563
- }
564
- }
565
-
566
- /**
567
- * @description Subscribe to messages from SDK
568
- */
569
- }, {
570
- key: "subscribeFromSDK",
571
- value: function subscribeFromSDK() {
572
- var eventKeyMap = {};
573
- for (var key in eventKeyMap) {
574
- // eslint-disable-next-line no-prototype-builtins
575
- if (eventKeyMap.hasOwnProperty(key)) {
576
- this.AMSSDK.eventCenter.on("".concat(COMPONENTPLUGINID, "-").concat(key), eventKeyMap[key].bind(this));
577
- }
578
- }
579
- }
580
-
581
- /**
582
- * @description Send rendering events to iframe
583
- */
584
- }, {
585
- key: "sendRenderEvent",
586
- value: function () {
587
- var _sendRenderEvent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
588
- var _this$_renderParams, _this$_renderParams2, res;
589
- return _regeneratorRuntime().wrap(function _callee$(_context) {
590
- while (1) switch (_context.prev = _context.next) {
591
- case 0:
592
- _context.prev = 0;
593
- if (this._actionQueryPromise) {
594
- _context.next = 3;
595
- break;
596
- }
597
- return _context.abrupt("return");
598
- case 3:
599
- _context.next = 5;
600
- return this._actionQueryPromise;
601
- case 5:
602
- res = _context.sent;
603
- this._performanceData.push({
604
- key: 'sdk_render_component',
605
- value: Date.now()
606
- });
607
- this.dispatchToApp({
608
- name: messageName.SDK_TO_APP,
609
- mode: this.AMSSDK.options.mode,
610
- appId: COMPONENTPLUGINID,
611
- instanceId: this.AMSSDK._instanceId,
612
- context: {
613
- event: 'renderComponent',
614
- data: {
615
- queryResult: res,
616
- sessionResult: (_this$_renderParams = this._renderParams) === null || _this$_renderParams === void 0 ? void 0 : _this$_renderParams.paymentSessionMetaData,
617
- paymentSessionData: (_this$_renderParams2 = this._renderParams) === null || _this$_renderParams2 === void 0 ? void 0 : _this$_renderParams2.paymentSessionData,
618
- heightOfVisible: Math.max(innerHeight, window.innerHeight),
619
- envInfo: {
620
- screenHeight: screen.height,
621
- screenWidth: screen.width
622
- }
623
- }
624
- }
625
- });
626
- this.dispatchToApp({
627
- name: messageName.SDK_TO_APP,
628
- mode: this.AMSSDK.options.mode,
629
- appId: COMPONENTPLUGINID,
630
- instanceId: this.AMSSDK._instanceId,
631
- context: {
632
- event: 'web-sdk-performance',
633
- data: {
634
- performanceData: this._performanceData
635
- }
636
- }
637
- });
638
- // eslint-disable-next-line no-empty
639
- _context.next = 13;
640
- break;
641
- case 11:
642
- _context.prev = 11;
643
- _context.t0 = _context["catch"](0);
644
- case 13:
645
- case "end":
646
- return _context.stop();
647
- }
648
- }, _callee, this, [[0, 11]]);
649
- }));
650
- function sendRenderEvent() {
651
- return _sendRenderEvent.apply(this, arguments);
652
- }
653
- return sendRenderEvent;
654
- }()
655
- }, {
656
- key: "showLoading",
657
- value: function showLoading() {
658
- var loading = document.createElement('div');
659
- loading === null || loading === void 0 ? void 0 : loading.classList.add(loadingId);
660
- loading.id = loadingId;
661
- loading.innerHTML = '<div class="line"><div></div><div></div><div></div><div></div></div>';
662
- loading.style.fontSize = "".concat(getDesignFontSize(), "px");
663
- var body = document.getElementsByTagName('body')[0];
664
- body === null || body === void 0 ? void 0 : body.appendChild(loading);
665
- }
666
-
667
- /**
668
- * @description show cashier
669
- */
670
- }, {
671
- key: "showCashier",
672
- value: function showCashier() {
673
- var cashier = document.getElementById('ams-component-container');
674
- cashier === null || cashier === void 0 ? void 0 : cashier.classList.remove("ams-component-container-hidden-".concat(this.platform));
675
- cashier === null || cashier === void 0 ? void 0 : cashier.classList.add("ams-component-container-".concat(this.platform));
676
- }
677
-
678
- /**
679
- * @description close cashier
680
- */
681
- }, {
682
- key: "closeCashier",
683
- value: function closeCashier() {
684
- var _document$getElementB2;
685
- var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
686
- this._performanceData = [];
687
- this._isInitComponent = false;
688
- (_document$getElementB2 = document.getElementById(loadingId)) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.remove();
689
- this.hideComponentAndCleanDom(immediately);
690
- }
691
- }, {
692
- key: "hideComponentAndCleanDom",
693
- value: function hideComponentAndCleanDom() {
694
- var _this4 = this;
695
- var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
696
- var container = document.getElementById('ams-component-container');
697
- // size变化动画取消
698
- container.style.transition = '';
699
- container === null || container === void 0 ? void 0 : container.classList.remove("ams-component-container-".concat(this.platform));
700
- container === null || container === void 0 ? void 0 : container.classList.remove("ams-component-container-".concat(this.platform, "-animation"));
701
- container === null || container === void 0 ? void 0 : container.classList.add("ams-component-container-hidden-".concat(this.platform));
702
- var removeMockupAndApp = function removeMockupAndApp() {
703
- var _document$getElementB3;
704
- var body = document.getElementsByTagName('body')[0];
705
- body.style.overflow = 'auto';
706
- var mockup = document.getElementById(mockupId);
707
- mockup === null || mockup === void 0 ? void 0 : mockup.remove();
708
- if (container) container.style.height = '';
709
- (_document$getElementB3 = document.getElementById('ams-component-container-mobile-animation-style')) === null || _document$getElementB3 === void 0 ? void 0 : _document$getElementB3.remove();
710
- _this4.removeRetentionPopup();
711
- _this4.cleanApp();
712
- };
713
- if (immediately) removeMockupAndApp();else {
714
- setTimeout(function () {
715
- removeMockupAndApp();
716
- }, 300);
717
- }
718
- }
719
- }, {
720
- key: "closeBtnFunc",
721
- value: function closeBtnFunc() {
722
- // element && element.removeEventListener()
723
- if (this._isRetention) this.showRetentionPopup();else {
724
- this.closeCashier();
725
- this.dispatchToSDK(EVENT.onClose.name, {});
726
- }
727
- }
728
-
729
- /**
730
- * @description create mount node
731
- */
732
- }, {
733
- key: "createMountElement",
734
- value: function createMountElement() {
735
- componentAddCSS();
736
- var amsComponentContainer = document.createElement('div');
737
- amsComponentContainer.className = "ams-component-container-hidden-".concat(this.platform);
738
- amsComponentContainer.id = 'ams-component-container';
739
- amsSetSize(null, amsComponentContainer);
740
- document.body.appendChild(amsComponentContainer);
741
- var amsComponentSection = document.createElement('div');
742
- amsComponentSection.className = "ams-component-section-".concat(this.platform);
743
- amsComponentSection.id = this._selector.slice(1);
744
- amsComponentContainer.appendChild(amsComponentSection);
745
- this.createCloseBtn();
746
- }
747
- }, {
748
- key: "createCloseBtn",
749
- value: function createCloseBtn() {
750
- var _this5 = this;
751
- var container = document.getElementById('ams-component-container');
752
- // close btn
753
- var closeBtnHTML = "<img class='asm-component-close-btn-".concat(this.platform, "' src=\"https://cdn.marmot-cloud.com/storage/2023/5/18/1692a487-99b5-4314-9d6f-e9814bc1ca41.svg\"/>");
754
- var closeBlock = document.createElement('div');
755
- closeBlock.classList.add("asm-component-close-block-".concat(this.platform), 'asm-component-close-block-hidden');
756
- closeBlock.id = 'asm-component-section-close-block';
757
- closeBlock.innerHTML = closeBtnHTML;
758
- closeBlock.addEventListener(this._clickEventName, function () {
759
- _this5.closeBtnFunc();
760
- });
761
- if (container) container.appendChild(closeBlock);
762
- }
763
- }, {
764
- key: "createRetentionPopup",
765
- value: function createRetentionPopup() {
766
- // retention popup
767
- var retentionPopup = document.createElement('div');
768
- retentionPopup.id = 'ams-component-retention';
769
- retentionPopup.classList.add("ams-component-retention-".concat(this.platform));
770
- retentionPopup.innerHTML = "\n <span id=\"ams-component-retention-title\" class=\"ams-component-retention-title-".concat(this.platform, "\">\n Are you sure you want to leave?\n </span>\n <span\n id=\"ams-component-retention-sub-title\"\n class=\"ams-component-retention-sub-title-").concat(this.platform, "\"\n >\n If you leave this page, you'll have to start over again.\n </span>\n <div class=\"ams-component-retention-btn-block-").concat(this.platform, "\">\n <div id=\"ams-component-retention-remain\" class=\"ams-component-retention-remain-").concat(this.platform, "\">\n Continue Payment\n </div>\n <div id=\"ams-component-retention-leave\" class=\"ams-component-retention-leave-").concat(this.platform, "\">\n Leave\n </div>\n </div>");
771
- document.body.appendChild(retentionPopup);
772
- var remainBtn = document.getElementById('ams-component-retention-remain');
773
- if (remainBtn) {
774
- remainBtn.addEventListener(this._clickEventName, this.hideRetentionPopup.bind(this));
775
- }
776
- var leaveBtn = document.getElementById('ams-component-retention-leave');
777
- if (leaveBtn) {
778
- leaveBtn.addEventListener(this._clickEventName, this.retentionPopupLeaveFunc.bind(this));
779
- }
780
- }
781
- }, {
782
- key: "retentionPopupLeaveFunc",
783
- value: function retentionPopupLeaveFunc() {
784
- this.dispatchToSDK(EVENT.onClose.name, {});
785
- this.hideRetentionPopup();
786
- this.closeCashier();
787
- }
788
- }, {
789
- key: "removeRetentionPopup",
790
- value: function removeRetentionPopup() {
791
- var _document$getElementB4;
792
- var remainBtn = document.getElementById('ams-component-retention-remain');
793
- if (remainBtn) {
794
- remainBtn.removeEventListener(this._clickEventName, this.hideRetentionPopup);
795
- }
796
- var leaveBtn = document.getElementById('ams-component-retention-leave');
797
- if (leaveBtn) {
798
- leaveBtn.removeEventListener(this._clickEventName, this.retentionPopupLeaveFunc);
799
- }
800
- (_document$getElementB4 = document.getElementById('ams-component-retention')) === null || _document$getElementB4 === void 0 ? void 0 : _document$getElementB4.remove();
801
- }
802
- }, {
803
- key: "showRetentionPopup",
804
- value: function showRetentionPopup() {
805
- var retentionPopup = document.getElementById('ams-component-retention');
806
- var container = document.getElementById('ams-component-container');
807
- if (retentionPopup) {
808
- container === null || container === void 0 ? void 0 : container.classList.add('ams-component-container-opacity');
809
- retentionPopup.classList.remove('ams-component-retention-hidden');
810
- retentionPopup.classList.add('ams-component-retention-show');
811
- }
812
- }
813
- }, {
814
- key: "hideRetentionPopup",
815
- value: function hideRetentionPopup() {
816
- var retentionPopup = document.getElementById('ams-component-retention');
817
- var container = document.getElementById('ams-component-container');
818
- if (retentionPopup) {
819
- retentionPopup.classList.remove('ams-component-retention-show');
820
- retentionPopup.classList.add('ams-component-retention-hidden');
821
- setTimeout(function () {
822
- retentionPopup.classList.remove('ams-component-retention-hidden');
823
- container === null || container === void 0 ? void 0 : container.classList.remove('ams-component-container-opacity');
824
- }, 250);
825
- }
826
- }
827
- /**
828
- * @description create mockup
829
- */
830
- }, {
831
- key: "createMockup",
832
- value: function createMockup() {
833
- var body = document.getElementsByTagName('body')[0];
834
- body.style.overflow = 'hidden';
835
- var mockup = document.createElement('div');
836
- mockup.style.width = '100vw';
837
- mockup.style.height = '100vh';
838
- mockup.style.position = 'fixed';
839
- mockup.style.top = '0';
840
- mockup.style.left = '0';
841
- mockup.style.zIndex = '1000';
842
- mockup.style.background = '#ffffff';
843
- mockup.style.opacity = '0.5';
844
- mockup.style.display = 'none';
845
- mockup.id = mockupId;
846
- body.appendChild(mockup);
847
- }
848
- }, {
849
- key: "submitForm",
850
- value: function submitForm(data) {
851
- var attributes = data.attributes;
852
- var _document = document,
853
- body = _document.body;
854
- var form = document.createElement('form');
855
- form.setAttribute('height', '1');
856
- form.setAttribute('width', '1');
857
- Object.keys(attributes.data).forEach(function (key) {
858
- var input = document.createElement('input');
859
- input.setAttribute('type', 'hidden');
860
- input.setAttribute('name', key);
861
- input.setAttribute('value', attributes.data[key]);
862
- form.appendChild(input);
863
- });
864
- form.setAttribute('action', attributes.action);
865
- form.setAttribute('method', 'post');
866
- body.appendChild(form);
867
- this.closeCashier(true);
868
- setTimeout(function () {
869
- form.submit();
870
- }, 0);
871
- }
872
- }]);
873
- return ComponentApp;
874
- }();
875
- export { ComponentApp as default };