@alipay/ams-checkout 0.0.1730107332-dev.3 → 0.0.1730107332-dev.30
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/dist/umd/ams-checkout.min.js +1 -1
- package/esm/component/channel.d.ts +2 -3
- package/esm/component/channel.js +65 -30
- package/esm/component/component.inline.style.js +1 -1
- package/esm/component/component.popup.style.d.ts +1 -3
- package/esm/component/component.popup.style.js +1 -3
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +7 -7
- package/esm/constant/index.d.ts +3 -0
- package/esm/constant/index.js +3 -0
- package/esm/core/bus/ability/callback.d.ts +9 -0
- package/esm/core/bus/ability/callback.js +55 -0
- package/esm/core/bus/ability/security.d.ts +10 -0
- package/esm/core/bus/ability/security.js +104 -0
- package/esm/core/bus/ability/tracker.d.ts +9 -0
- package/esm/core/bus/ability/tracker.js +77 -0
- package/esm/core/bus/index.d.ts +125 -0
- package/esm/core/bus/index.js +366 -0
- package/esm/core/bus/interface.d.ts +36 -0
- package/esm/core/bus/interface.js +40 -0
- package/esm/core/component/address.d.ts +8 -0
- package/esm/core/component/address.js +72 -0
- package/esm/core/component/appPreloadProcessing.d.ts +1 -0
- package/esm/core/component/appPreloadProcessing.js +89 -0
- package/esm/core/component/ckp/index.d.ts +27 -0
- package/esm/core/component/ckp/index.js +166 -0
- package/esm/core/component/index.d.ts +51 -0
- package/esm/core/component/index.js +531 -0
- package/esm/core/drop-in/index.d.ts +22 -0
- package/esm/core/drop-in/index.js +104 -0
- package/esm/core/instance/index.d.ts +89 -0
- package/esm/core/instance/index.js +499 -0
- package/esm/foundation/core/index.d.ts +2 -2
- package/esm/foundation/core/index.js +8 -4
- package/esm/foundation/index.d.ts +8 -5
- package/esm/foundation/product-processor/easysafepay/deps.d.ts +5 -4
- package/esm/foundation/product-processor/easysafepay/deps.js +3 -2
- package/esm/foundation/product-processor/easysafepay/index.d.ts +2 -3
- package/esm/foundation/product-processor/easysafepay/index.js +115 -231
- package/esm/foundation/service/api-bus/index.d.ts +2 -2
- package/esm/foundation/service/container/index.d.ts +2 -2
- package/esm/foundation/service/container/index.js +0 -1
- package/esm/foundation/service/event-center.d.ts +4 -4
- package/esm/foundation/service/event-center.js +10 -10
- package/esm/foundation/service/global-data/index.d.ts +2 -2
- package/esm/foundation/service/index.d.ts +2 -2
- package/esm/foundation/service/log/index.d.ts +2 -2
- package/esm/foundation/service/requester/deps.d.ts +1 -1
- package/esm/foundation/service/requester/requester.d.ts +2 -2
- package/esm/foundation/service/security/index.d.ts +2 -2
- package/esm/foundation/service/security/index.js +1 -0
- package/esm/foundation/utils/redirect_utils.d.ts +5 -0
- package/esm/foundation/utils/redirect_utils.js +178 -24
- package/esm/foundation/utils/web_app_url_utils.js +1 -1
- package/esm/index.d.ts +27 -2
- package/esm/index.js +133 -7
- package/esm/plugin/applepay/component.d.ts +50 -0
- package/esm/plugin/applepay/component.js +339 -0
- package/esm/plugin/applepay/index.d.ts +17 -0
- package/esm/plugin/applepay/index.js +117 -0
- package/esm/plugin/applepay/interface.d.ts +161 -0
- package/esm/plugin/applepay/interface.js +69 -0
- package/esm/plugin/applepay/service.d.ts +54 -0
- package/esm/plugin/applepay/service.js +289 -0
- package/esm/plugin/component/cashierApp.d.ts +34 -0
- package/esm/plugin/component/cashierApp.js +237 -0
- package/esm/plugin/component/channel.d.ts +21 -0
- package/esm/plugin/component/channel.js +89 -0
- package/esm/plugin/component/component.inline.style.d.ts +10 -0
- package/esm/plugin/component/component.inline.style.js +119 -0
- package/esm/plugin/component/component.popup.style.d.ts +16 -0
- package/esm/plugin/component/component.popup.style.js +174 -0
- package/esm/plugin/component/index.d.ts +126 -0
- package/esm/plugin/component/index.js +1839 -0
- package/esm/plugin/component/popupWindow.style.d.ts +11 -0
- package/esm/plugin/component/popupWindow.style.js +121 -0
- package/esm/plugin/const.d.ts +2 -0
- package/esm/plugin/const.js +33 -0
- package/esm/plugin/drop-in/index.d.ts +71 -0
- package/esm/plugin/drop-in/index.js +324 -0
- package/esm/plugin/payment-element/utils.d.ts +2 -0
- package/esm/plugin/payment-element/utils.js +6 -0
- package/esm/plugin/paypal/index.d.ts +20 -0
- package/esm/plugin/paypal/index.js +390 -0
- package/esm/plugin/type.d.ts +34 -0
- package/esm/plugin/type.js +1 -0
- package/esm/plugin/utils.d.ts +6 -0
- package/esm/plugin/utils.js +21 -0
- package/esm/types/index.d.ts +10 -11
- package/esm/types/index.js +2 -1
- package/esm/util/createIframeNode.d.ts +6 -0
- package/esm/util/createIframeNode.js +48 -0
- package/esm/util/getBackScheme.d.ts +5 -0
- package/esm/util/getBackScheme.js +134 -0
- package/esm/util/index.d.ts +1 -1
- package/esm/util/index.js +4 -3
- package/esm/util/intl-callapp/es/index.js +0 -1
- package/esm/util/security.d.ts +33 -0
- package/esm/util/security.js +182 -0
- package/package.json +2 -2
- package/esm/foundation/types/index.d.ts +0 -4
- package/esm/foundation/types/index.js +0 -4
@@ -0,0 +1,1839 @@
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
4
|
+
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
5
|
+
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); } }
|
6
|
+
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); }); }; }
|
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
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 @typescript-eslint/no-explicit-any */
|
20
|
+
import { v4 as uuid } from 'uuid';
|
21
|
+
import { sdkVersion } from "../../config";
|
22
|
+
import { COMPONENTPLUGINID, COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CONTAINER_ID, COMPONENT_RETENTION_ID, COMPONENT_SECTION_ID, ERRORMESSAGE, EVENT, LISTENER_PREFIX, LOADING_ID, LOADTIME_LIMIT, MOCKUP_ID, POPUP_LOADTIME_LOG_LIMIT, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../constant";
|
23
|
+
import { queryPaymentInfo, submitPayInfo } from "../../service";
|
24
|
+
import { ComponentSignEnum, eventCodeEnum, MessageName, PlatformEnum, ProductSceneEnum, RedirectType, DisplayTypeEnum, TargetEnum } from "../../types";
|
25
|
+
import { getType, isJsonString, isPC } from "../../util";
|
26
|
+
import { isLocalMock } from "../../util/mock";
|
27
|
+
import { matchVersion } from "../../util/versionCompare";
|
28
|
+
import { getBackScheme } from "../../util/getBackScheme";
|
29
|
+
import { handlePaymentSessionConfig } from "../payment-element/utils";
|
30
|
+
import { createIframe, createPreloadIframe, getAppDomain, getIframeUrl } from "./cashierApp";
|
31
|
+
import { getChannelBehavior, handleGooglePay } from "./channel";
|
32
|
+
import { addInlineLoading, createInlineBaseElement } from "./component.inline.style";
|
33
|
+
import { addPopupLoading, createBaseElement, createMockup, createRetentionPopup, handleDeclareInfo as _handleDeclareInfo, hideRetentionPopup, removeRetentionPopup as _removeRetentionPopup, slideInAndOutKeyframes } from "./component.popup.style";
|
34
|
+
import { createModal, destroyModal, insertStyleSheet, removePopupLoading } from "./popupWindow.style";
|
35
|
+
window.changingPageHeight = window.innerHeight;
|
36
|
+
var ComponentApp = /*#__PURE__*/function () {
|
37
|
+
function ComponentApp(componentOption) {
|
38
|
+
_classCallCheck(this, ComponentApp);
|
39
|
+
_defineProperty(this, "app", void 0);
|
40
|
+
_defineProperty(this, "AMSSDK", void 0);
|
41
|
+
_defineProperty(this, "platform", void 0);
|
42
|
+
_defineProperty(this, "_performanceData", []);
|
43
|
+
_defineProperty(this, "_loadAppPromiseResolve", null);
|
44
|
+
_defineProperty(this, "_isInitComponent", void 0);
|
45
|
+
_defineProperty(this, "_globalData", void 0);
|
46
|
+
_defineProperty(this, "popupApp", void 0);
|
47
|
+
_defineProperty(this, "appDomain", void 0);
|
48
|
+
_defineProperty(this, "createIframeNode", void 0);
|
49
|
+
_defineProperty(this, "createPreloadIframeNode", void 0);
|
50
|
+
_defineProperty(this, "_selector", void 0);
|
51
|
+
_defineProperty(this, "_appVersion", void 0);
|
52
|
+
_defineProperty(this, "_isRetention", void 0);
|
53
|
+
_defineProperty(this, "_allowSubmitPayCallAhead", void 0);
|
54
|
+
_defineProperty(this, "_actionQueryPromise", null);
|
55
|
+
_defineProperty(this, "_actionSubmitPromise", null);
|
56
|
+
_defineProperty(this, "_renderParams", null);
|
57
|
+
_defineProperty(this, "_componentSign", ComponentSignEnum.NONE);
|
58
|
+
_defineProperty(this, "_appLocationSearch", void 0);
|
59
|
+
_defineProperty(this, "_renderDisplayType", DisplayTypeEnum.popup);
|
60
|
+
_defineProperty(this, "_multipleCallbackEvents", void 0);
|
61
|
+
_defineProperty(this, "_isAppWebview", void 0);
|
62
|
+
_defineProperty(this, "_merchantAppointParam", void 0);
|
63
|
+
_defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
|
64
|
+
this._appVersion = componentOption.appVersion;
|
65
|
+
this._isInitComponent = false;
|
66
|
+
this._selector = "#".concat(COMPONENT_SECTION_ID);
|
67
|
+
this.createIframeNode = function () {
|
68
|
+
return Promise.resolve();
|
69
|
+
};
|
70
|
+
this.createPreloadIframeNode = function () {
|
71
|
+
return Promise.resolve();
|
72
|
+
};
|
73
|
+
this.platform = isPC() ? PlatformEnum.desktop : PlatformEnum.mobile;
|
74
|
+
this._isRetention = true;
|
75
|
+
this._appLocationSearch = '';
|
76
|
+
this._performanceData.push({
|
77
|
+
key: 'sdk_init',
|
78
|
+
value: Date.now()
|
79
|
+
});
|
80
|
+
this._globalData = new Map();
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @description Cancel listening and destroy the dom
|
85
|
+
*/
|
86
|
+
_createClass(ComponentApp, [{
|
87
|
+
key: "logoutPlugin",
|
88
|
+
value: function logoutPlugin() {
|
89
|
+
this.cleanContainer(true);
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* @description When SDK registers plug-ins, it is a required function to receive SDK instances
|
94
|
+
*/
|
95
|
+
}, {
|
96
|
+
key: "applyPlugin",
|
97
|
+
value: function applyPlugin(AMSSDK) {
|
98
|
+
this.AMSSDK = AMSSDK;
|
99
|
+
this.subscribeFromSDK();
|
100
|
+
}
|
101
|
+
}, {
|
102
|
+
key: "initLoggerMeta",
|
103
|
+
value: function initLoggerMeta() {
|
104
|
+
var _this$_renderParams, _paymentSessionMetaDa, _this$_renderParams2, _this$_renderParams3;
|
105
|
+
var paymentSessionMetaData = (_this$_renderParams = this._renderParams) === null || _this$_renderParams === void 0 ? void 0 : _this$_renderParams.paymentSessionMetaData;
|
106
|
+
var paymentSessionConfig = paymentSessionMetaData.paymentSessionConfig;
|
107
|
+
this.AMSSDK.logger.setMedta({
|
108
|
+
platform: this.platform === PlatformEnum.desktop ? 'PC' : 'WAP',
|
109
|
+
// PC/WAP,
|
110
|
+
sdkVersion: sdkVersion,
|
111
|
+
webAppVersion: this._appVersion,
|
112
|
+
instanceId: this.AMSSDK._instanceId,
|
113
|
+
storageId: this.AMSSDK._storageId,
|
114
|
+
// the better way to use md5 paymentSesionID
|
115
|
+
renderDisplayType: paymentSessionMetaData === null || paymentSessionMetaData === void 0 ? void 0 : paymentSessionMetaData.renderDisplayType,
|
116
|
+
merchantId: paymentSessionMetaData === null || paymentSessionMetaData === void 0 ? void 0 : paymentSessionMetaData.clientId,
|
117
|
+
productScene: paymentSessionConfig === null || paymentSessionConfig === void 0 ? void 0 : paymentSessionConfig.productScene,
|
118
|
+
productSceneVersion: paymentSessionConfig === null || paymentSessionConfig === void 0 ? void 0 : paymentSessionConfig.productSceneVersion,
|
119
|
+
paymentMethodType: paymentSessionMetaData === null || paymentSessionMetaData === void 0 || (_paymentSessionMetaDa = paymentSessionMetaData.paymentMethodInfoView) === null || _paymentSessionMetaDa === void 0 ? void 0 : _paymentSessionMetaDa.paymentMethodType,
|
120
|
+
paymentMethodCategoryType: paymentSessionConfig === null || paymentSessionConfig === void 0 ? void 0 : paymentSessionConfig.paymentMethodCategoryType,
|
121
|
+
requestSeq: (_this$_renderParams2 = this._renderParams) === null || _this$_renderParams2 === void 0 ? void 0 : _this$_renderParams2.sessionData,
|
122
|
+
trackId: (_this$_renderParams3 = this._renderParams) === null || _this$_renderParams3 === void 0 ? void 0 : _this$_renderParams3.sessionData
|
123
|
+
});
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
|
128
|
+
*/
|
129
|
+
}, {
|
130
|
+
key: "setRender",
|
131
|
+
value: function setRender(renderFunc) {
|
132
|
+
this.createIframeNode = renderFunc;
|
133
|
+
}
|
134
|
+
}, {
|
135
|
+
key: "setPreloadRender",
|
136
|
+
value: function setPreloadRender(renderFunc) {
|
137
|
+
this.createPreloadIframeNode = renderFunc;
|
138
|
+
}
|
139
|
+
}, {
|
140
|
+
key: "initSecurity",
|
141
|
+
value: function initSecurity() {
|
142
|
+
var _this$_renderParams4,
|
143
|
+
_this = this;
|
144
|
+
var product = (_this$_renderParams4 = this._renderParams) === null || _this$_renderParams4 === void 0 || (_this$_renderParams4 = _this$_renderParams4.paymentSessionMetaData) === null || _this$_renderParams4 === void 0 || (_this$_renderParams4 = _this$_renderParams4.paymentSessionConfig) === null || _this$_renderParams4 === void 0 ? void 0 : _this$_renderParams4.productScene;
|
145
|
+
if (ComponentSignEnum.CASHIER_PAYMENT_APM === this._componentSign) return;
|
146
|
+
if (ComponentSignEnum.CASHIER_PAYMENT_BANK === this._componentSign) {
|
147
|
+
this.AMSSDK.logger.logInfo({
|
148
|
+
title: 'sdk_event_security_unneeded_scenarios'
|
149
|
+
}, {
|
150
|
+
product: product
|
151
|
+
});
|
152
|
+
}
|
153
|
+
var securitySDK = this.AMSSDK._getSecuritySDKByProductScene({
|
154
|
+
product: product
|
155
|
+
});
|
156
|
+
if (!securitySDK) {
|
157
|
+
this.AMSSDK.logger.logInfo({
|
158
|
+
title: 'sdk_event_securitySdkInit'
|
159
|
+
});
|
160
|
+
this.AMSSDK._newSecuritySDKByScene({
|
161
|
+
product: product
|
162
|
+
}, function () {
|
163
|
+
_this.AMSSDK.logger.logInfo({
|
164
|
+
title: 'sdk_event_securitySdkInitSuccess'
|
165
|
+
});
|
166
|
+
}, function () {
|
167
|
+
_this.AMSSDK.logger.logError({
|
168
|
+
title: 'sdk_error_securitySdkInitFailed'
|
169
|
+
}, {
|
170
|
+
sign: 'SDK internal initialization'
|
171
|
+
});
|
172
|
+
});
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}, {
|
176
|
+
key: "logDeviceId",
|
177
|
+
value: function logDeviceId(deviceId, getDeviceIdStartTime) {
|
178
|
+
var time = "".concat(Date.now() - getDeviceIdStartTime);
|
179
|
+
if (deviceId) {
|
180
|
+
this.AMSSDK.logger.logInfo({
|
181
|
+
title: 'sdk_event_securitySdkGetTokenSuccess'
|
182
|
+
}, {
|
183
|
+
deviceId: deviceId,
|
184
|
+
time: time
|
185
|
+
}).send();
|
186
|
+
} else {
|
187
|
+
this.AMSSDK.logger.logInfo({
|
188
|
+
title: 'sdk_error_securitySdkGetTokenFailed'
|
189
|
+
}, {
|
190
|
+
deviceId: deviceId,
|
191
|
+
time: time
|
192
|
+
}).send();
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}, {
|
196
|
+
key: "getDeviceIdAndLog",
|
197
|
+
value: function getDeviceIdAndLog() {
|
198
|
+
var _this2 = this;
|
199
|
+
var deviceIdParameter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
200
|
+
var isPolling = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
201
|
+
return new Promise(function (resolve) {
|
202
|
+
// To avoid rendering being blocked, move the logic to the next event loop for processing
|
203
|
+
setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
204
|
+
var _this2$_renderParams;
|
205
|
+
var productScene, getDeviceIdStartTime, securitySDK, deviceId;
|
206
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
207
|
+
while (1) switch (_context.prev = _context.next) {
|
208
|
+
case 0:
|
209
|
+
productScene = (_this2$_renderParams = _this2._renderParams) === null || _this2$_renderParams === void 0 || (_this2$_renderParams = _this2$_renderParams.paymentSessionMetaData) === null || _this2$_renderParams === void 0 || (_this2$_renderParams = _this2$_renderParams.paymentSessionConfig) === null || _this2$_renderParams === void 0 ? void 0 : _this2$_renderParams.productScene;
|
210
|
+
getDeviceIdStartTime = Date.now();
|
211
|
+
securitySDK = _this2.AMSSDK._getSecuritySDKByProductScene({
|
212
|
+
product: (deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.productScene) || productScene
|
213
|
+
});
|
214
|
+
deviceId = '';
|
215
|
+
if (!securitySDK) {
|
216
|
+
_context.next = 16;
|
217
|
+
break;
|
218
|
+
}
|
219
|
+
if (!(isPolling && parseInt(deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.tokenCollectTime) > 0)) {
|
220
|
+
_context.next = 11;
|
221
|
+
break;
|
222
|
+
}
|
223
|
+
_context.next = 8;
|
224
|
+
return securitySDK.pollingGetApdidToken(deviceIdParameter);
|
225
|
+
case 8:
|
226
|
+
_context.t0 = _context.sent;
|
227
|
+
_context.next = 14;
|
228
|
+
break;
|
229
|
+
case 11:
|
230
|
+
_context.next = 13;
|
231
|
+
return securitySDK.getApdidToken();
|
232
|
+
case 13:
|
233
|
+
_context.t0 = _context.sent;
|
234
|
+
case 14:
|
235
|
+
deviceId = _context.t0;
|
236
|
+
_this2.logDeviceId(deviceId, getDeviceIdStartTime);
|
237
|
+
case 16:
|
238
|
+
resolve(deviceId);
|
239
|
+
case 17:
|
240
|
+
case "end":
|
241
|
+
return _context.stop();
|
242
|
+
}
|
243
|
+
}, _callee);
|
244
|
+
})), 0);
|
245
|
+
});
|
246
|
+
}
|
247
|
+
|
248
|
+
/**
|
249
|
+
* @description render iframe content
|
250
|
+
*/
|
251
|
+
}, {
|
252
|
+
key: "appendIframeNodes",
|
253
|
+
value: function appendIframeNodes(componentSign, renderParams) {
|
254
|
+
var _renderParams,
|
255
|
+
_this$_renderParams5,
|
256
|
+
_this$_renderParams6,
|
257
|
+
_this$_renderParams7,
|
258
|
+
_this$_renderParams8,
|
259
|
+
_this3 = this;
|
260
|
+
if (this._isInitComponent) {
|
261
|
+
this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
|
262
|
+
return Promise.reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
|
263
|
+
}
|
264
|
+
renderParams = this.setParameterDefaultValues(componentSign, renderParams);
|
265
|
+
this._merchantAppointParam = renderParams.merchantAppointParam;
|
266
|
+
this._isInitComponent = true;
|
267
|
+
this._renderParams = renderParams;
|
268
|
+
this._componentSign = componentSign;
|
269
|
+
if ((_renderParams = renderParams) !== null && _renderParams !== void 0 && _renderParams.selector) this._selector = renderParams.selector;
|
270
|
+
this._renderDisplayType = renderParams.renderDisplayType;
|
271
|
+
this._isAppWebview = renderParams.isAppWebview;
|
272
|
+
var insertedNode = this._renderDisplayType === DisplayTypeEnum.inline ? "#".concat(COMPONENT_CONTAINER_ID) : this._selector;
|
273
|
+
this.initLoggerMeta();
|
274
|
+
this.initSecurity();
|
275
|
+
this._performanceData.push({
|
276
|
+
key: 'sdk_create_component',
|
277
|
+
value: Date.now()
|
278
|
+
});
|
279
|
+
var params = {
|
280
|
+
paymentSessionData: this._renderParams && ((_this$_renderParams5 = this._renderParams) === null || _this$_renderParams5 === void 0 ? void 0 : _this$_renderParams5.sessionData) || '',
|
281
|
+
paymentSessionConfig: (_this$_renderParams6 = this._renderParams) === null || _this$_renderParams6 === void 0 || (_this$_renderParams6 = _this$_renderParams6.paymentSessionMetaData) === null || _this$_renderParams6 === void 0 ? void 0 : _this$_renderParams6.paymentSessionConfig
|
282
|
+
};
|
283
|
+
var _ref2 = params.paymentSessionConfig || {},
|
284
|
+
_ref2$productSceneVer = _ref2.productSceneVersion,
|
285
|
+
productSceneVersion = _ref2$productSceneVer === void 0 ? '' : _ref2$productSceneVer,
|
286
|
+
_ref2$productScene = _ref2.productScene,
|
287
|
+
productScene = _ref2$productScene === void 0 ? '' : _ref2$productScene;
|
288
|
+
var _ref3 = ((_this$_renderParams7 = this._renderParams) === null || _this$_renderParams7 === void 0 ? void 0 : _this$_renderParams7.paymentSessionMetaData) || {},
|
289
|
+
_ref3$action = _ref3.action,
|
290
|
+
_ref3$action2 = _ref3$action === void 0 ? {} : _ref3$action,
|
291
|
+
_ref3$action2$autoDeb = _ref3$action2.autoDebitWithToken,
|
292
|
+
autoDebitWithToken = _ref3$action2$autoDeb === void 0 ? false : _ref3$action2$autoDeb,
|
293
|
+
_ref3$action2$require = _ref3$action2.requireFastSdk,
|
294
|
+
requireFastSdk = _ref3$action2$require === void 0 ? false : _ref3$action2$require;
|
295
|
+
var _ref4 = ((_this$_renderParams8 = this._renderParams) === null || _this$_renderParams8 === void 0 ? void 0 : _this$_renderParams8.paymentSessionMetaData) || {},
|
296
|
+
_ref4$authUrlInfo = _ref4.authUrlInfo,
|
297
|
+
authUrlInfo = _ref4$authUrlInfo === void 0 ? {} : _ref4$authUrlInfo;
|
298
|
+
this.AMSSDK.logger.logInfo({
|
299
|
+
title: 'sdk_event_createComponent'
|
300
|
+
}, {
|
301
|
+
version: productSceneVersion,
|
302
|
+
product: this.AMSSDK.options.product
|
303
|
+
}).send();
|
304
|
+
if (ComponentSignEnum.EASY_PAY_WALLET === this._componentSign) {
|
305
|
+
if (productScene === ProductSceneEnum.EASY_PAY && productSceneVersion === '1.0' && !autoDebitWithToken && requireFastSdk) {
|
306
|
+
// EASY_PAY 1.0首次支付,requireFastSdk为true,不需要接口请求
|
307
|
+
this.handleAuthUrlInfo(authUrlInfo);
|
308
|
+
return;
|
309
|
+
}
|
310
|
+
}
|
311
|
+
if (ComponentSignEnum.AUTO_DEBIT_WALLET === this._componentSign) {
|
312
|
+
var _this$_renderParams9, _action$web, _action$wap;
|
313
|
+
var action = ((_this$_renderParams9 = this._renderParams) === null || _this$_renderParams9 === void 0 || (_this$_renderParams9 = _this$_renderParams9.paymentSessionMetaData) === null || _this$_renderParams9 === void 0 ? void 0 : _this$_renderParams9.action) || {};
|
314
|
+
var signType = isPC() ? action === null || action === void 0 || (_action$web = action.web) === null || _action$web === void 0 ? void 0 : _action$web.signType : action === null || action === void 0 || (_action$wap = action.wap) === null || _action$wap === void 0 ? void 0 : _action$wap.signType;
|
315
|
+
var _requireFastSdk = (action === null || action === void 0 ? void 0 : action.requireFastSdk) || false;
|
316
|
+
if (signType === 'REDIRECT' && _requireFastSdk === true) {
|
317
|
+
// REDIRECT,requireFastSdk为true,不需要接口请求
|
318
|
+
this.handleAuthUrlInfo(authUrlInfo);
|
319
|
+
return;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
if (ComponentSignEnum.AUTO_DEBIT_PAY_WALLET === this._componentSign) {
|
323
|
+
if (requireFastSdk === true && productSceneVersion === '1.0') {
|
324
|
+
// REDIRECT,requireFastSdk为true,不需要接口请求
|
325
|
+
this.handleAuthUrlInfo(authUrlInfo);
|
326
|
+
return;
|
327
|
+
} else {
|
328
|
+
return Promise.reject({
|
329
|
+
code: ERRORMESSAGE.CREATEPAYMENT_PARAMETER_ERROR.code,
|
330
|
+
message: "Abnormal response data, interface failure, or unsupported payment method."
|
331
|
+
});
|
332
|
+
}
|
333
|
+
}
|
334
|
+
this.dispatchToSDK(EVENT.eventCallback.name, {
|
335
|
+
code: eventCodeEnum.SDK_START_OF_LOADING
|
336
|
+
});
|
337
|
+
if (this._renderDisplayType === DisplayTypeEnum.inline) {
|
338
|
+
var container = createInlineBaseElement(this._selector);
|
339
|
+
if (container) this.renderInlineLoading(renderParams, container);
|
340
|
+
insertStyleSheet();
|
341
|
+
}
|
342
|
+
if (this._renderDisplayType === DisplayTypeEnum.popup) {
|
343
|
+
var _this$_renderParams10;
|
344
|
+
createBaseElement(this.platform, this.closeBtnFunc.bind(this));
|
345
|
+
createRetentionPopup(this.platform, this.hideRetentionPopupFunc.bind(this), this.retentionPopupLeaveFunc.bind(this));
|
346
|
+
var channelBehavior = getChannelBehavior((_this$_renderParams10 = this._renderParams) === null || _this$_renderParams10 === void 0 ? void 0 : _this$_renderParams10.paymentSessionMetaData);
|
347
|
+
var onClickOutside = function onClickOutside() {};
|
348
|
+
if (channelBehavior !== null && channelBehavior !== void 0 && channelBehavior.allowClickOutsideClose) {
|
349
|
+
onClickOutside = this.closeBtnFunc.bind(this);
|
350
|
+
}
|
351
|
+
createMockup({
|
352
|
+
platform: this.platform,
|
353
|
+
onClickOutside: onClickOutside
|
354
|
+
});
|
355
|
+
this.renderPopupLoading(renderParams);
|
356
|
+
}
|
357
|
+
this.createApp(renderParams);
|
358
|
+
return Promise.all([this.createActionQueryPromise(), this.createSubmitPromise(), this.createIframeNode(this, insertedNode, this._renderDisplayType), this._createLoadAppPromise()]).then(function () {
|
359
|
+
return Promise.resolve();
|
360
|
+
}).catch(function (error) {
|
361
|
+
_this3.AMSSDK.logger.logError({
|
362
|
+
title: 'sdk_error_created_app_process_failed'
|
363
|
+
}).send();
|
364
|
+
_this3._isInitComponent = false;
|
365
|
+
_this3.cleanContainer();
|
366
|
+
return Promise.reject(error);
|
367
|
+
});
|
368
|
+
}
|
369
|
+
}, {
|
370
|
+
key: "appendPreloadIframeNodes",
|
371
|
+
value: function appendPreloadIframeNodes(componentSign, productSceneVersion) {
|
372
|
+
var virtualPreloadIframe = this.createPreloadApp(componentSign, productSceneVersion);
|
373
|
+
this.createPreloadIframeNode(virtualPreloadIframe);
|
374
|
+
this.AMSSDK.logger.logInfo({
|
375
|
+
title: 'performance_optimization_preload'
|
376
|
+
}, {
|
377
|
+
componentSign: componentSign,
|
378
|
+
productSceneVersion: productSceneVersion
|
379
|
+
});
|
380
|
+
}
|
381
|
+
}, {
|
382
|
+
key: "setParameterDefaultValues",
|
383
|
+
value: function setParameterDefaultValues(componentSign, renderParams) {
|
384
|
+
var newParams = Object.assign({}, renderParams);
|
385
|
+
if (componentSign === ComponentSignEnum.VAULTING_CARD) {
|
386
|
+
var _newParams$notRedirec;
|
387
|
+
newParams.notRedirectAfterComplete = (_newParams$notRedirec = newParams === null || newParams === void 0 ? void 0 : newParams.notRedirectAfterComplete) !== null && _newParams$notRedirec !== void 0 ? _newParams$notRedirec : true;
|
388
|
+
}
|
389
|
+
return newParams;
|
390
|
+
}
|
391
|
+
}, {
|
392
|
+
key: "renderInlineLoading",
|
393
|
+
value: function renderInlineLoading(renderParams, selector) {
|
394
|
+
var _renderParams$appeara, _this$_renderParams11;
|
395
|
+
var showLoading = renderParams === null || renderParams === void 0 || (_renderParams$appeara = renderParams.appearance) === null || _renderParams$appeara === void 0 ? void 0 : _renderParams$appeara.showLoading;
|
396
|
+
showLoading = typeof showLoading === 'boolean' ? showLoading : true;
|
397
|
+
var extendInfo = renderParams.paymentSessionMetaData.extendInfo;
|
398
|
+
var isExpressCheckout = false;
|
399
|
+
try {
|
400
|
+
// expressCheckout可能出现string(false) JSON.parse再转一次
|
401
|
+
isExpressCheckout = JSON.parse(JSON.parse(extendInfo).expressCheckout);
|
402
|
+
} catch (error) {
|
403
|
+
// 遇到JSON解析错误,默认false
|
404
|
+
}
|
405
|
+
if (showLoading) addInlineLoading(selector, this.platform, {
|
406
|
+
componentSign: this._componentSign,
|
407
|
+
type: (_this$_renderParams11 = this._renderParams) === null || _this$_renderParams11 === void 0 || (_this$_renderParams11 = _this$_renderParams11.appearance) === null || _this$_renderParams11 === void 0 || (_this$_renderParams11 = _this$_renderParams11.layout) === null || _this$_renderParams11 === void 0 ? void 0 : _this$_renderParams11.type,
|
408
|
+
isExpressCheckout: isExpressCheckout
|
409
|
+
});
|
410
|
+
}
|
411
|
+
}, {
|
412
|
+
key: "renderPopupLoading",
|
413
|
+
value: function renderPopupLoading(renderParams) {
|
414
|
+
var _renderParams$appeara2;
|
415
|
+
var showLoading = renderParams === null || renderParams === void 0 || (_renderParams$appeara2 = renderParams.appearance) === null || _renderParams$appeara2 === void 0 ? void 0 : _renderParams$appeara2.showLoading;
|
416
|
+
showLoading = typeof showLoading === 'boolean' ? showLoading : true;
|
417
|
+
if (!showLoading) return;
|
418
|
+
var mockup = document.getElementById(MOCKUP_ID);
|
419
|
+
if (mockup) mockup.style.display = 'block';
|
420
|
+
addPopupLoading();
|
421
|
+
}
|
422
|
+
}, {
|
423
|
+
key: "_createLoadAppPromise",
|
424
|
+
value: function _createLoadAppPromise(loadTimeLimit) {
|
425
|
+
var _this4 = this;
|
426
|
+
return new Promise(function (resolve, reject) {
|
427
|
+
_this4._loadAppPromiseResolve = resolve;
|
428
|
+
setTimeout(function () {
|
429
|
+
reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
|
430
|
+
}, loadTimeLimit !== null && loadTimeLimit !== void 0 ? loadTimeLimit : LOADTIME_LIMIT);
|
431
|
+
}).catch(function (error) {
|
432
|
+
_this4.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
|
433
|
+
_this4.AMSSDK.logger.logError({
|
434
|
+
title: 'sdk_error_web_app_timeout'
|
435
|
+
}).send();
|
436
|
+
return Promise.reject(error);
|
437
|
+
});
|
438
|
+
}
|
439
|
+
|
440
|
+
/**
|
441
|
+
* @description Interface request
|
442
|
+
*/
|
443
|
+
}, {
|
444
|
+
key: "createActionQueryPromise",
|
445
|
+
value: function createActionQueryPromise() {
|
446
|
+
var _this5 = this;
|
447
|
+
this._performanceData.push({
|
448
|
+
key: 'sdk_action_query_start',
|
449
|
+
value: Date.now()
|
450
|
+
});
|
451
|
+
// eslint-disable-next-line no-async-promise-executor
|
452
|
+
this._actionQueryPromise = new Promise( /*#__PURE__*/function () {
|
453
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
|
454
|
+
var _this5$_renderParams, _this5$_renderParams2, _this5$_renderParams3, _this5$_renderParams4, _this5$_renderParams5, _this5$_renderParams6;
|
455
|
+
var envInfo, params, _ref6, _ref6$extendInfo, extendInfo, actionData, enableVaultingApiOptimize, enableEasypayApiOptimize, _ref7, skipSdkQuery, skipSdkQueryForm, extendInfoData, ifSkip, channelBehavior, _this5$_renderParams7, _ref8, _ref8$productSceneVer, productSceneVersion, _ref8$productScene, productScene, _this5$_renderParams8, _action$web2, _action$wap2, action, signType;
|
456
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
457
|
+
while (1) switch (_context2.prev = _context2.next) {
|
458
|
+
case 0:
|
459
|
+
envInfo = {
|
460
|
+
locale: _this5.AMSSDK.options.locale
|
461
|
+
};
|
462
|
+
params = {
|
463
|
+
paymentSessionData: _this5._renderParams && ((_this5$_renderParams = _this5._renderParams) === null || _this5$_renderParams === void 0 ? void 0 : _this5$_renderParams.sessionData) || '',
|
464
|
+
paymentSessionConfig: (_this5$_renderParams2 = _this5._renderParams) === null || _this5$_renderParams2 === void 0 || (_this5$_renderParams2 = _this5$_renderParams2.paymentSessionMetaData) === null || _this5$_renderParams2 === void 0 ? void 0 : _this5$_renderParams2.paymentSessionConfig,
|
465
|
+
notRedirectAfterComplete: ((_this5$_renderParams3 = _this5._renderParams) === null || _this5$_renderParams3 === void 0 ? void 0 : _this5$_renderParams3.notRedirectAfterComplete) === true,
|
466
|
+
merchantAppointParam: _this5._merchantAppointParam
|
467
|
+
};
|
468
|
+
/**
|
469
|
+
* @description Simulated or unnecessary scenarios
|
470
|
+
*/
|
471
|
+
_ref6 = ((_this5$_renderParams4 = _this5._renderParams) === null || _this5$_renderParams4 === void 0 ? void 0 : _this5$_renderParams4.paymentSessionMetaData) || {}, _ref6$extendInfo = _ref6.extendInfo, extendInfo = _ref6$extendInfo === void 0 ? '' : _ref6$extendInfo, actionData = _ref6.action;
|
472
|
+
enableVaultingApiOptimize = false;
|
473
|
+
enableEasypayApiOptimize = false;
|
474
|
+
_ref7 = ((_this5$_renderParams5 = _this5._renderParams) === null || _this5$_renderParams5 === void 0 || (_this5$_renderParams5 = _this5$_renderParams5.paymentSessionMetaData) === null || _this5$_renderParams5 === void 0 ? void 0 : _this5$_renderParams5.action) || {}, skipSdkQuery = _ref7.skipSdkQuery, skipSdkQueryForm = _ref7.skipSdkQueryForm;
|
475
|
+
try {
|
476
|
+
extendInfoData = JSON.parse(extendInfo);
|
477
|
+
enableVaultingApiOptimize = extendInfoData.enableVaultingApiOptimize || false;
|
478
|
+
enableEasypayApiOptimize = extendInfoData.enableEasypayApiOptimize || false;
|
479
|
+
} catch (error) {
|
480
|
+
console.log(error);
|
481
|
+
}
|
482
|
+
if (!isLocalMock()) {
|
483
|
+
_context2.next = 9;
|
484
|
+
break;
|
485
|
+
}
|
486
|
+
return _context2.abrupt("return", resolve({
|
487
|
+
message: 'sdk no need to make query request',
|
488
|
+
success: true
|
489
|
+
}));
|
490
|
+
case 9:
|
491
|
+
if (ComponentSignEnum.ELEMENT_PAYMENT === _this5._componentSign) {
|
492
|
+
params.paymentSessionConfig = handlePaymentSessionConfig(params.paymentSessionConfig);
|
493
|
+
}
|
494
|
+
/** 地址组件跳过接口查询 */
|
495
|
+
if (!(ComponentSignEnum.ELEMENT_ADDRESS === _this5._componentSign)) {
|
496
|
+
_context2.next = 12;
|
497
|
+
break;
|
498
|
+
}
|
499
|
+
return _context2.abrupt("return", resolve({
|
500
|
+
message: 'sdk no need to make query request',
|
501
|
+
success: true
|
502
|
+
}));
|
503
|
+
case 12:
|
504
|
+
if (!(ComponentSignEnum.VAULTING_CARD === _this5._componentSign)) {
|
505
|
+
_context2.next = 24;
|
506
|
+
break;
|
507
|
+
}
|
508
|
+
if (!enableVaultingApiOptimize) {
|
509
|
+
_context2.next = 24;
|
510
|
+
break;
|
511
|
+
}
|
512
|
+
if (!skipSdkQueryForm) {
|
513
|
+
_context2.next = 21;
|
514
|
+
break;
|
515
|
+
}
|
516
|
+
// 优先判断 skipSdkQueryForm
|
517
|
+
ifSkip = matchVersion(skipSdkQueryForm, _this5._appVersion);
|
518
|
+
if (!ifSkip) {
|
519
|
+
_context2.next = 19;
|
520
|
+
break;
|
521
|
+
}
|
522
|
+
resolve({
|
523
|
+
message: 'sdk no need to make query request',
|
524
|
+
success: true
|
525
|
+
});
|
526
|
+
return _context2.abrupt("return");
|
527
|
+
case 19:
|
528
|
+
_context2.next = 24;
|
529
|
+
break;
|
530
|
+
case 21:
|
531
|
+
if (!skipSdkQuery) {
|
532
|
+
_context2.next = 24;
|
533
|
+
break;
|
534
|
+
}
|
535
|
+
resolve({
|
536
|
+
message: 'sdk no need to make query request',
|
537
|
+
success: true
|
538
|
+
});
|
539
|
+
return _context2.abrupt("return");
|
540
|
+
case 24:
|
541
|
+
channelBehavior = getChannelBehavior((_this5$_renderParams6 = _this5._renderParams) === null || _this5$_renderParams6 === void 0 ? void 0 : _this5$_renderParams6.paymentSessionMetaData); // Easypay TOSS 渠道无需actionQuery
|
542
|
+
if (!(channelBehavior !== null && channelBehavior !== void 0 && channelBehavior.usePaymentSessionAsQueryResult)) {
|
543
|
+
_context2.next = 27;
|
544
|
+
break;
|
545
|
+
}
|
546
|
+
return _context2.abrupt("return", resolve({
|
547
|
+
autoDebitWithToken: actionData === null || actionData === void 0 ? void 0 : actionData.autoDebitWithToken,
|
548
|
+
amountConfirmRequired: actionData === null || actionData === void 0 ? void 0 : actionData.amountConfirmRequired,
|
549
|
+
success: true
|
550
|
+
}));
|
551
|
+
case 27:
|
552
|
+
if (!(ComponentSignEnum.CASHIER_PAYMENT_CARD === _this5._componentSign || ComponentSignEnum.VAULTING_CARD === _this5._componentSign)) {
|
553
|
+
_context2.next = 33;
|
554
|
+
break;
|
555
|
+
}
|
556
|
+
params.paymentMethodType = 'CARD';
|
557
|
+
_context2.next = 31;
|
558
|
+
return _this5.getDeviceIdAndLog();
|
559
|
+
case 31:
|
560
|
+
envInfo.deviceId = _context2.sent;
|
561
|
+
if (window.navigator.userAgent.indexOf('miniProgram') > -1) {
|
562
|
+
envInfo.extendInfo = {
|
563
|
+
WAP_SUB_TYPE: 'WECHAT_MINI_PROGRAM'
|
564
|
+
};
|
565
|
+
}
|
566
|
+
case 33:
|
567
|
+
if (!(ComponentSignEnum.EASY_PAY_WALLET === _this5._componentSign)) {
|
568
|
+
_context2.next = 42;
|
569
|
+
break;
|
570
|
+
}
|
571
|
+
_ref8 = params.paymentSessionConfig || {}, _ref8$productSceneVer = _ref8.productSceneVersion, productSceneVersion = _ref8$productSceneVer === void 0 ? '' : _ref8$productSceneVer, _ref8$productScene = _ref8.productScene, productScene = _ref8$productScene === void 0 ? '' : _ref8$productScene;
|
572
|
+
if (!((_this5$_renderParams7 = _this5._renderParams) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.paymentSessionMetaData) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.action) !== null && _this5$_renderParams7 !== void 0 && _this5$_renderParams7.skipSdkQuery && enableEasypayApiOptimize)) {
|
573
|
+
_context2.next = 37;
|
574
|
+
break;
|
575
|
+
}
|
576
|
+
return _context2.abrupt("return", resolve({
|
577
|
+
message: 'sdk no need to make query request',
|
578
|
+
success: true
|
579
|
+
}));
|
580
|
+
case 37:
|
581
|
+
if (!(productScene === ProductSceneEnum.EASY_PAY && productSceneVersion === '2.0')) {
|
582
|
+
_context2.next = 39;
|
583
|
+
break;
|
584
|
+
}
|
585
|
+
return _context2.abrupt("return", resolve({
|
586
|
+
message: 'sdk no need to make query request',
|
587
|
+
success: true
|
588
|
+
}));
|
589
|
+
case 39:
|
590
|
+
_context2.next = 41;
|
591
|
+
return _this5.getDeviceIdAndLog();
|
592
|
+
case 41:
|
593
|
+
envInfo.deviceId = _context2.sent;
|
594
|
+
case 42:
|
595
|
+
if (!(ComponentSignEnum.AUTO_DEBIT_WALLET === _this5._componentSign)) {
|
596
|
+
_context2.next = 52;
|
597
|
+
break;
|
598
|
+
}
|
599
|
+
action = ((_this5$_renderParams8 = _this5._renderParams) === null || _this5$_renderParams8 === void 0 || (_this5$_renderParams8 = _this5$_renderParams8.paymentSessionMetaData) === null || _this5$_renderParams8 === void 0 ? void 0 : _this5$_renderParams8.action) || {};
|
600
|
+
signType = isPC() ? action === null || action === void 0 || (_action$web2 = action.web) === null || _action$web2 === void 0 ? void 0 : _action$web2.signType : action === null || action === void 0 || (_action$wap2 = action.wap) === null || _action$wap2 === void 0 ? void 0 : _action$wap2.signType;
|
601
|
+
if (!(signType === 'SMS')) {
|
602
|
+
_context2.next = 47;
|
603
|
+
break;
|
604
|
+
}
|
605
|
+
return _context2.abrupt("return", resolve({
|
606
|
+
message: 'sdk no need to make query request',
|
607
|
+
success: true
|
608
|
+
}));
|
609
|
+
case 47:
|
610
|
+
if (!(!signType || signType !== 'REDIRECT')) {
|
611
|
+
_context2.next = 49;
|
612
|
+
break;
|
613
|
+
}
|
614
|
+
return _context2.abrupt("return", resolve({
|
615
|
+
success: false
|
616
|
+
}));
|
617
|
+
case 49:
|
618
|
+
_context2.next = 51;
|
619
|
+
return _this5.getDeviceIdAndLog();
|
620
|
+
case 51:
|
621
|
+
envInfo.deviceId = _context2.sent;
|
622
|
+
case 52:
|
623
|
+
_this5.AMSSDK.logger.logInfo({
|
624
|
+
title: 'sdk_event_sdkQuery'
|
625
|
+
}, {
|
626
|
+
paymentSessionConfig: JSON.stringify(params.paymentSessionConfig),
|
627
|
+
requestBody: params
|
628
|
+
}).send();
|
629
|
+
queryPaymentInfo(params, {
|
630
|
+
env: _this5.AMSSDK.options.env.environment,
|
631
|
+
envInfo: envInfo
|
632
|
+
}, _this5.AMSSDK.logger).then(function (res) {
|
633
|
+
_this5._performanceData.push({
|
634
|
+
key: 'sdk_action_query_end',
|
635
|
+
value: Date.now()
|
636
|
+
});
|
637
|
+
resolve(res);
|
638
|
+
_this5.AMSSDK.logger.logInfo({
|
639
|
+
title: 'sdk_event_sdkQueryEnd'
|
640
|
+
}, {
|
641
|
+
paymentSessionConfig: JSON.stringify(params.paymentSessionConfig),
|
642
|
+
responseBody: res
|
643
|
+
}).send();
|
644
|
+
}).catch(function (err) {
|
645
|
+
if ([ComponentSignEnum.CASHIER_PAYMENT_CARD, ComponentSignEnum.VAULTING_CARD, ComponentSignEnum.CASHIER_PAYMENT_APM].includes(_this5._componentSign)) {
|
646
|
+
return resolve({
|
647
|
+
success: false
|
648
|
+
});
|
649
|
+
}
|
650
|
+
_this5.dispatchToSDK(EVENT.error.name, {
|
651
|
+
code: ERRORMESSAGE.CREATECOMPONENT_ERROR.code
|
652
|
+
});
|
653
|
+
_this5.AMSSDK.logger.logError({
|
654
|
+
title: 'sdk_event_sdkQuery_failed'
|
655
|
+
}, {
|
656
|
+
paymentSessionConfig: JSON.stringify(params.paymentSessionConfig),
|
657
|
+
errorReason: err
|
658
|
+
}).send();
|
659
|
+
reject(err);
|
660
|
+
});
|
661
|
+
case 54:
|
662
|
+
case "end":
|
663
|
+
return _context2.stop();
|
664
|
+
}
|
665
|
+
}, _callee2);
|
666
|
+
}));
|
667
|
+
return function (_x, _x2) {
|
668
|
+
return _ref5.apply(this, arguments);
|
669
|
+
};
|
670
|
+
}());
|
671
|
+
return this._actionQueryPromise;
|
672
|
+
}
|
673
|
+
|
674
|
+
// private create
|
675
|
+
}, {
|
676
|
+
key: "createSubmitPromise",
|
677
|
+
value: function createSubmitPromise() {
|
678
|
+
var _this$_renderParams12,
|
679
|
+
_this$_renderParams13,
|
680
|
+
_this$_renderParams14,
|
681
|
+
_this6 = this;
|
682
|
+
this._performanceData.push({
|
683
|
+
key: 'sdk_submit_start',
|
684
|
+
value: Date.now()
|
685
|
+
});
|
686
|
+
var params = {
|
687
|
+
paymentSessionData: this._renderParams && ((_this$_renderParams12 = this._renderParams) === null || _this$_renderParams12 === void 0 ? void 0 : _this$_renderParams12.sessionData) || '',
|
688
|
+
paymentSessionConfig: (_this$_renderParams13 = this._renderParams) === null || _this$_renderParams13 === void 0 || (_this$_renderParams13 = _this$_renderParams13.paymentSessionMetaData) === null || _this$_renderParams13 === void 0 ? void 0 : _this$_renderParams13.paymentSessionConfig
|
689
|
+
};
|
690
|
+
var channelBehavior = getChannelBehavior((_this$_renderParams14 = this._renderParams) === null || _this$_renderParams14 === void 0 ? void 0 : _this$_renderParams14.paymentSessionMetaData);
|
691
|
+
// eslint-disable-next-line no-async-promise-executor
|
692
|
+
this._actionSubmitPromise = new Promise( /*#__PURE__*/function () {
|
693
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
694
|
+
var _channelBehavior$buil, _this6$_renderParams$;
|
695
|
+
var shouldSkipSubmitPayInSDK, _this6$_renderParams, _this6$_renderParams2, _this6$_renderParams3, _ref10, _ref10$productSceneVe, productSceneVersion, _ref10$productScene, productScene, _ref11, _ref11$action, _ref11$action2, _ref11$action2$enable, enableSignAgreement, _ref11$action2$autoDe, autoDebitWithToken, _ref12, _ref12$paymentMethodI, _ref12$paymentMethodI2, _ref12$paymentMethodI3, paymentMethodType, isAppWebview, backScheme, extParams;
|
696
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
697
|
+
while (1) switch (_context3.prev = _context3.next) {
|
698
|
+
case 0:
|
699
|
+
if (!(_this6.AMSSDK.options.product === ProductSceneEnum.ELEMENT_ADDRESS)) {
|
700
|
+
_context3.next = 2;
|
701
|
+
break;
|
702
|
+
}
|
703
|
+
return _context3.abrupt("return", resolve({
|
704
|
+
message: 'sdk no need to make submitPay request',
|
705
|
+
success: true
|
706
|
+
}));
|
707
|
+
case 2:
|
708
|
+
shouldSkipSubmitPayInSDK = false;
|
709
|
+
if (channelBehavior) {
|
710
|
+
// 新逻辑走 channelBehavior判断
|
711
|
+
shouldSkipSubmitPayInSDK = !channelBehavior.submitPayInSdk;
|
712
|
+
} else {
|
713
|
+
shouldSkipSubmitPayInSDK = !((_this6$_renderParams = _this6._renderParams) !== null && _this6$_renderParams !== void 0 && (_this6$_renderParams = _this6$_renderParams.paymentSessionMetaData) !== null && _this6$_renderParams !== void 0 && (_this6$_renderParams = _this6$_renderParams.action) !== null && _this6$_renderParams !== void 0 && _this6$_renderParams.skipSdkQuery) || ComponentSignEnum.EASY_PAY_WALLET !== _this6._componentSign;
|
714
|
+
}
|
715
|
+
if (ComponentSignEnum.EASY_PAY_WALLET === _this6._componentSign) {
|
716
|
+
_ref10 = params.paymentSessionConfig || {}, _ref10$productSceneVe = _ref10.productSceneVersion, productSceneVersion = _ref10$productSceneVe === void 0 ? '' : _ref10$productSceneVe, _ref10$productScene = _ref10.productScene, productScene = _ref10$productScene === void 0 ? '' : _ref10$productScene;
|
717
|
+
_ref11 = ((_this6$_renderParams2 = _this6._renderParams) === null || _this6$_renderParams2 === void 0 ? void 0 : _this6$_renderParams2.paymentSessionMetaData) || {}, _ref11$action = _ref11.action, _ref11$action2 = _ref11$action === void 0 ? {} : _ref11$action, _ref11$action2$enable = _ref11$action2.enableSignAgreement, enableSignAgreement = _ref11$action2$enable === void 0 ? false : _ref11$action2$enable, _ref11$action2$autoDe = _ref11$action2.autoDebitWithToken, autoDebitWithToken = _ref11$action2$autoDe === void 0 ? false : _ref11$action2$autoDe;
|
718
|
+
_ref12 = ((_this6$_renderParams3 = _this6._renderParams) === null || _this6$_renderParams3 === void 0 ? void 0 : _this6$_renderParams3.paymentSessionMetaData) || {}, _ref12$paymentMethodI = _ref12.paymentMethodInfoView, _ref12$paymentMethodI2 = _ref12$paymentMethodI === void 0 ? {} : _ref12$paymentMethodI, _ref12$paymentMethodI3 = _ref12$paymentMethodI2.paymentMethodType, paymentMethodType = _ref12$paymentMethodI3 === void 0 ? '' : _ref12$paymentMethodI3;
|
719
|
+
if (productScene === ProductSceneEnum.EASY_PAY && productSceneVersion === '2.0' && !autoDebitWithToken) {
|
720
|
+
isAppWebview = _this6._isAppWebview || false; ///EasyPay 2.0 首次传signAgreement字段
|
721
|
+
params['signAgreement'] = enableSignAgreement;
|
722
|
+
if (paymentMethodType == 'ALIPAY_CN' && !isAppWebview) {
|
723
|
+
backScheme = getBackScheme(undefined, _this6.AMSSDK.logger);
|
724
|
+
if (backScheme && backScheme !== 'https') {
|
725
|
+
params['h5FromApp'] = encodeURIComponent(backScheme);
|
726
|
+
}
|
727
|
+
}
|
728
|
+
}
|
729
|
+
}
|
730
|
+
// 带上标记告知WebCheckOut SDK已发送submitpay请求
|
731
|
+
_this6._allowSubmitPayCallAhead = !shouldSkipSubmitPayInSDK;
|
732
|
+
if (!shouldSkipSubmitPayInSDK) {
|
733
|
+
_context3.next = 8;
|
734
|
+
break;
|
735
|
+
}
|
736
|
+
return _context3.abrupt("return", resolve({
|
737
|
+
message: 'sdk no need to make submitPay request',
|
738
|
+
success: true
|
739
|
+
}));
|
740
|
+
case 8:
|
741
|
+
_this6.AMSSDK.logger.logInfo({
|
742
|
+
title: 'sdk_event_submitPay'
|
743
|
+
}, {
|
744
|
+
paymentSessionConfig: JSON.stringify(params.paymentSessionConfig),
|
745
|
+
requestBody: params
|
746
|
+
}).send();
|
747
|
+
extParams = (channelBehavior === null || channelBehavior === void 0 || (_channelBehavior$buil = channelBehavior.buildSubmitPayExtParams) === null || _channelBehavior$buil === void 0 ? void 0 : _channelBehavior$buil.call(channelBehavior, {
|
748
|
+
instanceId: _this6.AMSSDK._instanceId,
|
749
|
+
locale: _this6.AMSSDK.options.locale,
|
750
|
+
paymentMethodType: (_this6$_renderParams$ = _this6._renderParams.paymentSessionMetaData) === null || _this6$_renderParams$ === void 0 || (_this6$_renderParams$ = _this6$_renderParams$.paymentMethodInfoView) === null || _this6$_renderParams$ === void 0 ? void 0 : _this6$_renderParams$.paymentMethodType,
|
751
|
+
paymentSessionData: _this6._renderParams.sessionData,
|
752
|
+
env: _this6.AMSSDK.options.env.environment,
|
753
|
+
sdkVersion: _this6._appVersion
|
754
|
+
})) || {};
|
755
|
+
params.extParams = extParams;
|
756
|
+
_context3.t0 = submitPayInfo;
|
757
|
+
_context3.t1 = params;
|
758
|
+
_context3.t2 = _this6.AMSSDK.options.env.environment;
|
759
|
+
_context3.next = 16;
|
760
|
+
return _this6.getDeviceIdAndLog();
|
761
|
+
case 16:
|
762
|
+
_context3.t3 = _context3.sent;
|
763
|
+
_context3.t4 = {
|
764
|
+
deviceId: _context3.t3
|
765
|
+
};
|
766
|
+
_context3.t5 = {
|
767
|
+
env: _context3.t2,
|
768
|
+
timeout: 15000,
|
769
|
+
envInfo: _context3.t4
|
770
|
+
};
|
771
|
+
_context3.t6 = _this6.AMSSDK.logger;
|
772
|
+
(0, _context3.t0)(_context3.t1, _context3.t5, _context3.t6).then(function (res) {
|
773
|
+
_this6._performanceData.push({
|
774
|
+
key: 'sdk_submit_end',
|
775
|
+
value: Date.now()
|
776
|
+
});
|
777
|
+
_this6.AMSSDK.logger.logInfo({
|
778
|
+
title: 'sdk_event_submitPayEnd'
|
779
|
+
}, {
|
780
|
+
paymentSessionConfig: JSON.stringify(params.paymentSessionConfig),
|
781
|
+
responseBody: res
|
782
|
+
}).send();
|
783
|
+
resolve(res);
|
784
|
+
}).catch(function (err) {
|
785
|
+
_this6.AMSSDK.logger.logError({
|
786
|
+
title: 'sdk_event_submitPay_failed'
|
787
|
+
}, {
|
788
|
+
paymentSessionConfig: JSON.stringify(params.paymentSessionConfig),
|
789
|
+
responseBody: err
|
790
|
+
}).send();
|
791
|
+
resolve({
|
792
|
+
success: false
|
793
|
+
});
|
794
|
+
});
|
795
|
+
case 21:
|
796
|
+
case "end":
|
797
|
+
return _context3.stop();
|
798
|
+
}
|
799
|
+
}, _callee3);
|
800
|
+
}));
|
801
|
+
return function (_x3) {
|
802
|
+
return _ref9.apply(this, arguments);
|
803
|
+
};
|
804
|
+
}());
|
805
|
+
}
|
806
|
+
}, {
|
807
|
+
key: "cleanElement",
|
808
|
+
value: function cleanElement() {
|
809
|
+
try {
|
810
|
+
var _document$getElementB;
|
811
|
+
// selector and container
|
812
|
+
if (getType(this._selector) === 'string') {
|
813
|
+
var selectorDom = document.querySelector(this._selector);
|
814
|
+
if (selectorDom) selectorDom.innerHTML = '';
|
815
|
+
}
|
816
|
+
var container = document.getElementById(COMPONENT_CONTAINER_ID);
|
817
|
+
if (container) container === null || container === void 0 || container.remove();
|
818
|
+
|
819
|
+
// animation
|
820
|
+
(_document$getElementB = document.getElementById("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style"))) === null || _document$getElementB === void 0 || _document$getElementB.remove();
|
821
|
+
|
822
|
+
// mockup
|
823
|
+
var body = document.getElementsByTagName('body')[0];
|
824
|
+
body.style.overflow = 'auto';
|
825
|
+
var mockup = document.getElementById(MOCKUP_ID);
|
826
|
+
mockup === null || mockup === void 0 || mockup.remove();
|
827
|
+
|
828
|
+
// retentionPopup
|
829
|
+
this.removeRetentionPopup(this.platform);
|
830
|
+
|
831
|
+
// listener
|
832
|
+
this.removeEventListener();
|
833
|
+
} catch (error) {
|
834
|
+
console.error(error);
|
835
|
+
}
|
836
|
+
}
|
837
|
+
// 预加载iframe创建
|
838
|
+
}, {
|
839
|
+
key: "createPreloadApp",
|
840
|
+
value: function createPreloadApp(componentSign) {
|
841
|
+
var productSceneVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1.0';
|
842
|
+
var preloadIframe = createPreloadIframe(componentSign, productSceneVersion);
|
843
|
+
var productScene = componentSign.split(/_(?=[^_]*$)/)[0];
|
844
|
+
var _getIframeUrl = getIframeUrl({
|
845
|
+
renderDisplayType: DisplayTypeEnum.popup,
|
846
|
+
componentSign: componentSign,
|
847
|
+
analytics: {
|
848
|
+
enabled: false
|
849
|
+
},
|
850
|
+
productScene: productScene,
|
851
|
+
productSceneVersion: productSceneVersion,
|
852
|
+
environment: this.AMSSDK.options.env.environment,
|
853
|
+
appVersion: this._appVersion,
|
854
|
+
instanceId: '',
|
855
|
+
isPreload: 'true',
|
856
|
+
mid: ''
|
857
|
+
}),
|
858
|
+
path = _getIframeUrl.path,
|
859
|
+
locationSearch = _getIframeUrl.locationSearch;
|
860
|
+
preloadIframe.src = "".concat(path, "?").concat(locationSearch);
|
861
|
+
if (!path) {
|
862
|
+
this.AMSSDK.logger.logError({
|
863
|
+
title: 'performance_optimization_preload_path_error'
|
864
|
+
}, {
|
865
|
+
path: path,
|
866
|
+
locationSearch: locationSearch
|
867
|
+
});
|
868
|
+
}
|
869
|
+
return preloadIframe;
|
870
|
+
}
|
871
|
+
/**
|
872
|
+
* @description Create app
|
873
|
+
*/
|
874
|
+
}, {
|
875
|
+
key: "createApp",
|
876
|
+
value: function createApp(renderParams) {
|
877
|
+
if (!!window.postMessage !== true) {
|
878
|
+
this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.BROWSER_NOT_SUPPORT_POSTMESSAGE);
|
879
|
+
return;
|
880
|
+
}
|
881
|
+
this._performanceData.push({
|
882
|
+
key: 'sdk_popup_start',
|
883
|
+
value: Date.now()
|
884
|
+
});
|
885
|
+
try {
|
886
|
+
var _renderParams$payment, _renderParams$payment2, _renderParams$payment3, _renderParams$payment4;
|
887
|
+
var productSceneVersion = (renderParams === null || renderParams === void 0 || (_renderParams$payment = renderParams.paymentSessionMetaData) === null || _renderParams$payment === void 0 || (_renderParams$payment = _renderParams$payment.paymentSessionConfig) === null || _renderParams$payment === void 0 ? void 0 : _renderParams$payment.productSceneVersion) || '';
|
888
|
+
var productScene = (renderParams === null || renderParams === void 0 || (_renderParams$payment2 = renderParams.paymentSessionMetaData) === null || _renderParams$payment2 === void 0 || (_renderParams$payment2 = _renderParams$payment2.paymentSessionConfig) === null || _renderParams$payment2 === void 0 ? void 0 : _renderParams$payment2.productScene) || '';
|
889
|
+
var extendInfo = (renderParams === null || renderParams === void 0 || (_renderParams$payment3 = renderParams.paymentSessionMetaData) === null || _renderParams$payment3 === void 0 ? void 0 : _renderParams$payment3.extendInfo) || '';
|
890
|
+
var mid = renderParams === null || renderParams === void 0 || (_renderParams$payment4 = renderParams.paymentSessionMetaData) === null || _renderParams$payment4 === void 0 ? void 0 : _renderParams$payment4.clientId;
|
891
|
+
var environment = this.AMSSDK.options.env.environment;
|
892
|
+
this.appDomain = getAppDomain({
|
893
|
+
environment: environment,
|
894
|
+
appVersion: this._appVersion,
|
895
|
+
componentSign: this._componentSign,
|
896
|
+
productScene: productScene,
|
897
|
+
productSceneVersion: productSceneVersion,
|
898
|
+
extendInfo: extendInfo,
|
899
|
+
mid: mid
|
900
|
+
});
|
901
|
+
this.app = createIframe(this.AMSSDK.options.mode, this.platform);
|
902
|
+
var hostSign = ((renderParams === null || renderParams === void 0 ? void 0 : renderParams.sessionData) || '').split('&&')[1] || '';
|
903
|
+
var _getIframeUrl2 = getIframeUrl({
|
904
|
+
renderDisplayType: renderParams.renderDisplayType,
|
905
|
+
componentSign: this._componentSign,
|
906
|
+
analytics: this.AMSSDK.options.analytics,
|
907
|
+
productScene: productScene,
|
908
|
+
productSceneVersion: productSceneVersion,
|
909
|
+
environment: environment,
|
910
|
+
appVersion: this._appVersion,
|
911
|
+
extendInfo: extendInfo,
|
912
|
+
locale: this.AMSSDK.options.locale,
|
913
|
+
instanceId: this.AMSSDK._instanceId,
|
914
|
+
hostSign: hostSign,
|
915
|
+
mid: mid
|
916
|
+
}),
|
917
|
+
path = _getIframeUrl2.path,
|
918
|
+
locationSearch = _getIframeUrl2.locationSearch;
|
919
|
+
this._appLocationSearch = locationSearch;
|
920
|
+
// locationSearch 是一个序列化好的字符串
|
921
|
+
// 先判断path 是否有QueryParams,如果有需要扩展,否则直接拼?xx=xx
|
922
|
+
if (path.indexOf('?') !== -1) {
|
923
|
+
this.app.src = "".concat(path, "&").concat(locationSearch);
|
924
|
+
} else {
|
925
|
+
this.app.src = "".concat(path, "?").concat(locationSearch);
|
926
|
+
}
|
927
|
+
// Subscribe to messages from iframe
|
928
|
+
this.addEventListener();
|
929
|
+
} catch (error) {
|
930
|
+
this.AMSSDK.logger.logError({
|
931
|
+
title: 'sdk_error_created_app_failed'
|
932
|
+
}).send();
|
933
|
+
this.dispatchToSDK(EVENT.error.name, Object.assign({}, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.FAILED_TO_CREATE_IFRAME, {
|
934
|
+
stack: error
|
935
|
+
}));
|
936
|
+
}
|
937
|
+
}
|
938
|
+
}, {
|
939
|
+
key: "listener",
|
940
|
+
value: function listener(e) {
|
941
|
+
var _e$data;
|
942
|
+
if (e.origin !== this.appDomain) return;
|
943
|
+
if (((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.source) === 'react-devtools-content-script') {
|
944
|
+
// 防止 react 开发工具发的消息,非常频繁影响查看日志
|
945
|
+
return;
|
946
|
+
}
|
947
|
+
var isJson = isJsonString(e.data);
|
948
|
+
if (isJson) {
|
949
|
+
var data = JSON.parse(e.data);
|
950
|
+
if (data.name !== MessageName.APP_TO_SDK && data.name !== MessageName.APP_TO_APP || data.instanceId !== this.AMSSDK._instanceId) return;
|
951
|
+
this._handleAppMessage(data);
|
952
|
+
} else {
|
953
|
+
console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
|
954
|
+
this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.NOT_JSON_FORMAT);
|
955
|
+
}
|
956
|
+
}
|
957
|
+
}, {
|
958
|
+
key: "resizeListener",
|
959
|
+
value: function resizeListener(e) {
|
960
|
+
var _e$target, _e$target2;
|
961
|
+
var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
|
962
|
+
cashier.style.transition = 'none';
|
963
|
+
this.dispatchToApp({
|
964
|
+
context: {
|
965
|
+
event: 'renderResize',
|
966
|
+
data: {
|
967
|
+
heightOfVisible: (e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.innerHeight) || window.innerHeight,
|
968
|
+
widthOfVisible: (e === null || e === void 0 || (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : _e$target2.innerWidth) || window.innerWidth
|
969
|
+
}
|
970
|
+
}
|
971
|
+
});
|
972
|
+
}
|
973
|
+
}, {
|
974
|
+
key: "createDialog",
|
975
|
+
value: function () {
|
976
|
+
var _createDialog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(data) {
|
977
|
+
var pageUrl, _data$device, isLoad, timeout, logTimeout;
|
978
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
979
|
+
while (1) switch (_context4.prev = _context4.next) {
|
980
|
+
case 0:
|
981
|
+
pageUrl = data.url.includes('?') ? "".concat(data.url, "&").concat(this._appLocationSearch) : "".concat(data.url, "?").concat(this._appLocationSearch);
|
982
|
+
_context4.prev = 1;
|
983
|
+
isLoad = false;
|
984
|
+
_context4.next = 5;
|
985
|
+
return createModal({
|
986
|
+
widthPadding: data === null || data === void 0 ? void 0 : data.widthPadding,
|
987
|
+
device: (_data$device = data === null || data === void 0 ? void 0 : data.device) !== null && _data$device !== void 0 ? _data$device : this.platform,
|
988
|
+
loadingConfig: data === null || data === void 0 ? void 0 : data.loadingConfig,
|
989
|
+
url: pageUrl
|
990
|
+
});
|
991
|
+
case 5:
|
992
|
+
this.popupApp = _context4.sent;
|
993
|
+
timeout = setTimeout(function () {
|
994
|
+
if (isLoad) return;
|
995
|
+
throw {
|
996
|
+
title: 'sdk_error_create_pop_up'
|
997
|
+
};
|
998
|
+
}, LOADTIME_LIMIT);
|
999
|
+
logTimeout = setTimeout(function () {
|
1000
|
+
if (isLoad) return;
|
1001
|
+
throw {
|
1002
|
+
title: 'sdk_error_pop_up_time_out'
|
1003
|
+
};
|
1004
|
+
}, POPUP_LOADTIME_LOG_LIMIT);
|
1005
|
+
this.popupApp.onload = function () {
|
1006
|
+
isLoad = true;
|
1007
|
+
removePopupLoading();
|
1008
|
+
clearTimeout(timeout);
|
1009
|
+
clearTimeout(logTimeout);
|
1010
|
+
};
|
1011
|
+
_context4.next = 15;
|
1012
|
+
break;
|
1013
|
+
case 11:
|
1014
|
+
_context4.prev = 11;
|
1015
|
+
_context4.t0 = _context4["catch"](1);
|
1016
|
+
this.AMSSDK.logger.logError({
|
1017
|
+
title: (_context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.title) || 'sdk_error_create_pop_up'
|
1018
|
+
}, {
|
1019
|
+
message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
|
1020
|
+
url: pageUrl
|
1021
|
+
});
|
1022
|
+
this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
|
1023
|
+
case 15:
|
1024
|
+
case "end":
|
1025
|
+
return _context4.stop();
|
1026
|
+
}
|
1027
|
+
}, _callee4, this, [[1, 11]]);
|
1028
|
+
}));
|
1029
|
+
function createDialog(_x4) {
|
1030
|
+
return _createDialog.apply(this, arguments);
|
1031
|
+
}
|
1032
|
+
return createDialog;
|
1033
|
+
}()
|
1034
|
+
}, {
|
1035
|
+
key: "getDeviceIdAndCallback",
|
1036
|
+
value: function () {
|
1037
|
+
var _getDeviceIdAndCallback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(eventContext) {
|
1038
|
+
var deviceId;
|
1039
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
1040
|
+
while (1) switch (_context5.prev = _context5.next) {
|
1041
|
+
case 0:
|
1042
|
+
if (!(eventContext !== null && eventContext !== void 0 && eventContext.eventCallbackId)) {
|
1043
|
+
_context5.next = 5;
|
1044
|
+
break;
|
1045
|
+
}
|
1046
|
+
_context5.next = 3;
|
1047
|
+
return this.getDeviceIdAndLog(eventContext === null || eventContext === void 0 ? void 0 : eventContext.data, true);
|
1048
|
+
case 3:
|
1049
|
+
deviceId = _context5.sent;
|
1050
|
+
this.dispatchToApp({
|
1051
|
+
context: {
|
1052
|
+
event: 'appEventCallback',
|
1053
|
+
eventCallbackId: eventContext === null || eventContext === void 0 ? void 0 : eventContext.eventCallbackId,
|
1054
|
+
data: {
|
1055
|
+
deviceId: deviceId
|
1056
|
+
}
|
1057
|
+
}
|
1058
|
+
});
|
1059
|
+
case 5:
|
1060
|
+
case "end":
|
1061
|
+
return _context5.stop();
|
1062
|
+
}
|
1063
|
+
}, _callee5, this);
|
1064
|
+
}));
|
1065
|
+
function getDeviceIdAndCallback(_x5) {
|
1066
|
+
return _getDeviceIdAndCallback.apply(this, arguments);
|
1067
|
+
}
|
1068
|
+
return getDeviceIdAndCallback;
|
1069
|
+
}()
|
1070
|
+
}, {
|
1071
|
+
key: "getUserAgentAndCallback",
|
1072
|
+
value: function () {
|
1073
|
+
var _getUserAgentAndCallback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(eventContext) {
|
1074
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
1075
|
+
while (1) switch (_context6.prev = _context6.next) {
|
1076
|
+
case 0:
|
1077
|
+
if (eventContext !== null && eventContext !== void 0 && eventContext.eventCallbackId) {
|
1078
|
+
try {
|
1079
|
+
this.dispatchToApp({
|
1080
|
+
context: {
|
1081
|
+
event: 'appEventCallback',
|
1082
|
+
eventCallbackId: eventContext === null || eventContext === void 0 ? void 0 : eventContext.eventCallbackId,
|
1083
|
+
data: {
|
1084
|
+
userAgent: window.navigator.userAgent
|
1085
|
+
}
|
1086
|
+
}
|
1087
|
+
});
|
1088
|
+
} catch (error) {
|
1089
|
+
/* empty */
|
1090
|
+
}
|
1091
|
+
}
|
1092
|
+
case 1:
|
1093
|
+
case "end":
|
1094
|
+
return _context6.stop();
|
1095
|
+
}
|
1096
|
+
}, _callee6, this);
|
1097
|
+
}));
|
1098
|
+
function getUserAgentAndCallback(_x6) {
|
1099
|
+
return _getUserAgentAndCallback.apply(this, arguments);
|
1100
|
+
}
|
1101
|
+
return getUserAgentAndCallback;
|
1102
|
+
}()
|
1103
|
+
}, {
|
1104
|
+
key: "returnDataAndCallback",
|
1105
|
+
value: function () {
|
1106
|
+
var _returnDataAndCallback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(eventContext) {
|
1107
|
+
var _eventContext$data, targetData;
|
1108
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
1109
|
+
while (1) switch (_context7.prev = _context7.next) {
|
1110
|
+
case 0:
|
1111
|
+
if (eventContext !== null && eventContext !== void 0 && eventContext.eventCallbackId) {
|
1112
|
+
targetData = this._globalData.get((_eventContext$data = eventContext.data) === null || _eventContext$data === void 0 ? void 0 : _eventContext$data.dataKey);
|
1113
|
+
this.dispatchToApp({
|
1114
|
+
context: {
|
1115
|
+
event: 'appEventCallback',
|
1116
|
+
eventCallbackId: eventContext === null || eventContext === void 0 ? void 0 : eventContext.eventCallbackId,
|
1117
|
+
data: targetData
|
1118
|
+
}
|
1119
|
+
});
|
1120
|
+
}
|
1121
|
+
case 1:
|
1122
|
+
case "end":
|
1123
|
+
return _context7.stop();
|
1124
|
+
}
|
1125
|
+
}, _callee7, this);
|
1126
|
+
}));
|
1127
|
+
function returnDataAndCallback(_x7) {
|
1128
|
+
return _returnDataAndCallback.apply(this, arguments);
|
1129
|
+
}
|
1130
|
+
return returnDataAndCallback;
|
1131
|
+
}()
|
1132
|
+
/**
|
1133
|
+
* @description Initialize subscription iframe message
|
1134
|
+
*/
|
1135
|
+
}, {
|
1136
|
+
key: "addEventListener",
|
1137
|
+
value: function addEventListener() {
|
1138
|
+
this.removeEventListener();
|
1139
|
+
window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)] = this.listener.bind(this);
|
1140
|
+
window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")] = this.resizeListener.bind(this);
|
1141
|
+
window.addEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
|
1142
|
+
window.addEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
|
1143
|
+
}
|
1144
|
+
}, {
|
1145
|
+
key: "removeEventListener",
|
1146
|
+
value: function removeEventListener() {
|
1147
|
+
window.removeEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
|
1148
|
+
window.removeEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
/**
|
1152
|
+
* @description Processing messages from iframe
|
1153
|
+
*/
|
1154
|
+
}, {
|
1155
|
+
key: "_handleAppMessage",
|
1156
|
+
value: function _handleAppMessage(data) {
|
1157
|
+
var _data$context2,
|
1158
|
+
_this7 = this;
|
1159
|
+
var eventKeyMap = Object.keys(EVENT).map(function (key) {
|
1160
|
+
return EVENT[key].name;
|
1161
|
+
});
|
1162
|
+
if (!eventKeyMap.includes(data.context.event)) {
|
1163
|
+
return;
|
1164
|
+
}
|
1165
|
+
if (data.context.event === EVENT.getDeviceId.name) {
|
1166
|
+
this.getDeviceIdAndCallback(data.context);
|
1167
|
+
return;
|
1168
|
+
}
|
1169
|
+
if (data.context.event === EVENT.getUserAgentFromSdk.name) {
|
1170
|
+
this.getUserAgentAndCallback(data.context);
|
1171
|
+
return;
|
1172
|
+
}
|
1173
|
+
if (data.context.event === EVENT.popWindow.name) {
|
1174
|
+
destroyModal();
|
1175
|
+
return;
|
1176
|
+
}
|
1177
|
+
if (data.context.event === EVENT.getGlobalData.name) {
|
1178
|
+
this.returnDataAndCallback(data.context);
|
1179
|
+
return;
|
1180
|
+
}
|
1181
|
+
if (data.context.event === EVENT.setGlobalData.name) {
|
1182
|
+
var _data$context$data, _data$context$data2;
|
1183
|
+
this._globalData.set((_data$context$data = data.context.data) === null || _data$context$data === void 0 ? void 0 : _data$context$data.dataKey, (_data$context$data2 = data.context.data) === null || _data$context$data2 === void 0 ? void 0 : _data$context$data2.data);
|
1184
|
+
return;
|
1185
|
+
}
|
1186
|
+
if (data.context.event === EVENT.popupWindow.name) {
|
1187
|
+
var _data$context;
|
1188
|
+
this.createDialog((_data$context = data.context) === null || _data$context === void 0 ? void 0 : _data$context.data);
|
1189
|
+
return;
|
1190
|
+
}
|
1191
|
+
if (data.context.event === EVENT.sendMuitiAppEventToSdk.name) {
|
1192
|
+
this.dispatchToApp({
|
1193
|
+
context: {
|
1194
|
+
event: 'receiveMuitiAppFromSdk',
|
1195
|
+
data: data.context.data
|
1196
|
+
}
|
1197
|
+
});
|
1198
|
+
return;
|
1199
|
+
}
|
1200
|
+
if (data.context.event === EVENT.dismissLoading.name) {
|
1201
|
+
var _data$context$data3;
|
1202
|
+
this.dismissLoadingFunc(false);
|
1203
|
+
this.dispatchToSDK(EVENT.eventCallback.name, {
|
1204
|
+
code: 'SDK_END_OF_LOADING',
|
1205
|
+
message: ((_data$context$data3 = data.context.data) === null || _data$context$data3 === void 0 ? void 0 : _data$context$data3.message) || ''
|
1206
|
+
});
|
1207
|
+
return;
|
1208
|
+
}
|
1209
|
+
if (data.context.event === EVENT.launch.name) {
|
1210
|
+
this._performanceData.push({
|
1211
|
+
key: 'sdk_onLaunch',
|
1212
|
+
value: Date.now()
|
1213
|
+
});
|
1214
|
+
this.AMSSDK.logger.logInfo({
|
1215
|
+
title: 'sdk_event_webAppOnLaunch'
|
1216
|
+
}).send();
|
1217
|
+
this._loadAppPromiseResolve && this._loadAppPromiseResolve(true);
|
1218
|
+
this.sendRenderEvent();
|
1219
|
+
return;
|
1220
|
+
}
|
1221
|
+
if (data.context.event === EVENT.sizeChanged.name) {
|
1222
|
+
this.handleSizeChanged(data);
|
1223
|
+
}
|
1224
|
+
if (data.context.event === EVENT.close.name) {
|
1225
|
+
return this.closeBtnFunc();
|
1226
|
+
}
|
1227
|
+
if (data.context.event === EVENT.redirect.name) {
|
1228
|
+
return this.handleRedirect(data.context.data);
|
1229
|
+
}
|
1230
|
+
if (data.context.event === EVENT.submitForm.name) {
|
1231
|
+
this.submitForm(data.context.data);
|
1232
|
+
return;
|
1233
|
+
}
|
1234
|
+
if (data.context.event === EVENT.hideCloseButton.name) {
|
1235
|
+
this.handleCloseBtnShow(false);
|
1236
|
+
return;
|
1237
|
+
}
|
1238
|
+
if (data.context.event === EVENT.showCloseButton.name) {
|
1239
|
+
this.handleCloseBtnShow(true);
|
1240
|
+
return;
|
1241
|
+
}
|
1242
|
+
if (data.context.event === EVENT.setAllowRetention.name) {
|
1243
|
+
if (data.context.data === true) this._isRetention = true;
|
1244
|
+
if (data.context.data === false) this._isRetention = false;
|
1245
|
+
return;
|
1246
|
+
}
|
1247
|
+
if (data.context.event === EVENT.declareCheckoutInfo.name) {
|
1248
|
+
this.handleDeclareInfo(data.context.data);
|
1249
|
+
return;
|
1250
|
+
}
|
1251
|
+
if (data.context.event === EVENT.declareEventCallbackInfo.name) {
|
1252
|
+
this._multipleCallbackEvents = data.context.data;
|
1253
|
+
return;
|
1254
|
+
}
|
1255
|
+
if (data.context.event === EVENT.appHeartBeat.name) {
|
1256
|
+
this.handleAppHeartBeat();
|
1257
|
+
return;
|
1258
|
+
}
|
1259
|
+
if (data.context.event === EVENT.beforeSubmit.name) {
|
1260
|
+
var _this$AMSSDK$_eventCe;
|
1261
|
+
if ((_this$AMSSDK$_eventCe = this.AMSSDK._eventCenter) !== null && _this$AMSSDK$_eventCe !== void 0 && _this$AMSSDK$_eventCe.isExist(EVENT.beforeSubmit.name)) {
|
1262
|
+
this.AMSSDK._eventCenter.emit(EVENT.beforeSubmit.name, data.context.data);
|
1263
|
+
return;
|
1264
|
+
}
|
1265
|
+
// 不存在事件,默认通过
|
1266
|
+
var eventCallbackId = uuid();
|
1267
|
+
this.dispatchToApp({
|
1268
|
+
context: {
|
1269
|
+
event: EVENT.beforeSubmitDone.name,
|
1270
|
+
eventCallbackId: eventCallbackId,
|
1271
|
+
data: {
|
1272
|
+
result: 'IGNORE'
|
1273
|
+
}
|
1274
|
+
}
|
1275
|
+
});
|
1276
|
+
return;
|
1277
|
+
}
|
1278
|
+
if (data.context.event === EVENT.eventCallback.name) {
|
1279
|
+
this.AMSSDK.logger.logInfo({
|
1280
|
+
title: 'sdk_event_event_callback'
|
1281
|
+
}).send();
|
1282
|
+
}
|
1283
|
+
if ((data === null || data === void 0 || (_data$context2 = data.context) === null || _data$context2 === void 0 ? void 0 : _data$context2.event) === EVENT.getGooglePayToken.name) {
|
1284
|
+
handleGooglePay(data).then(function (res) {
|
1285
|
+
_this7.dispatchToApp({
|
1286
|
+
context: {
|
1287
|
+
event: 'getGooglePayToken',
|
1288
|
+
data: _objectSpread({}, res)
|
1289
|
+
}
|
1290
|
+
});
|
1291
|
+
}).catch(function (err) {
|
1292
|
+
_this7.dispatchToApp({
|
1293
|
+
context: {
|
1294
|
+
event: 'getGooglePayToken',
|
1295
|
+
data: {
|
1296
|
+
err: err
|
1297
|
+
}
|
1298
|
+
}
|
1299
|
+
});
|
1300
|
+
});
|
1301
|
+
return;
|
1302
|
+
}
|
1303
|
+
|
1304
|
+
// The plug-in communicates with the sdk after processing
|
1305
|
+
this.dispatchToSDK(data.context.event, data.context.data, data.context.eventCallbackId);
|
1306
|
+
}
|
1307
|
+
}, {
|
1308
|
+
key: "dismissLoadingFunc",
|
1309
|
+
value: function dismissLoadingFunc() {
|
1310
|
+
var _document$getElementB2;
|
1311
|
+
var isShowMockup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
1312
|
+
var mockup = document.getElementById(MOCKUP_ID);
|
1313
|
+
if (mockup) {
|
1314
|
+
mockup.style.background = 'rgb(0, 0, 0, 0.6)';
|
1315
|
+
mockup.style.display = isShowMockup ? 'block' : 'none';
|
1316
|
+
}
|
1317
|
+
(_document$getElementB2 = document.getElementById(LOADING_ID)) === null || _document$getElementB2 === void 0 || _document$getElementB2.remove();
|
1318
|
+
}
|
1319
|
+
}, {
|
1320
|
+
key: "handleSizeChanged",
|
1321
|
+
value: function handleSizeChanged(data) {
|
1322
|
+
var _data$context$data4;
|
1323
|
+
var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
|
1324
|
+
if (((_data$context$data4 = data.context.data) === null || _data$context$data4 === void 0 ? void 0 : _data$context$data4.height) <= 1 || data.context.data.height === parseInt(cashier.style.height)) return;
|
1325
|
+
cashier.style.height = "".concat(data.context.data.height, "px");
|
1326
|
+
this.app.style.opacity = '1';
|
1327
|
+
if (this._renderDisplayType === DisplayTypeEnum.popup) {
|
1328
|
+
if (this.platform === 'desktop') {
|
1329
|
+
if (data.context.data.width) cashier.style.width = "".concat(data.context.data.width, "px");
|
1330
|
+
cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
|
1331
|
+
this.app.style.height = "".concat(data.context.data.height, "px");
|
1332
|
+
}
|
1333
|
+
if (this.platform === 'mobile') {
|
1334
|
+
cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
|
1335
|
+
var animationStyleId = "".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style");
|
1336
|
+
var animationStyle = document.getElementById(animationStyleId);
|
1337
|
+
if (animationStyle) animationStyle === null || animationStyle === void 0 || animationStyle.remove();
|
1338
|
+
|
1339
|
+
// 此style用于弹窗出现和高度变化时动画,动画不同,属性不同
|
1340
|
+
this.app.style.height = parseInt(this.app.style.height) > 0 ? '100%' : "".concat(data.context.data.height, "px");
|
1341
|
+
// 弹出和弹入动画
|
1342
|
+
var runkeyframes = slideInAndOutKeyframes(COMPONENT_CONTAINER_ID, data.context.data.height);
|
1343
|
+
// 创建style标签
|
1344
|
+
var style = document.createElement('style');
|
1345
|
+
style.id = animationStyleId;
|
1346
|
+
// 设置style属性
|
1347
|
+
style.type = 'text/css';
|
1348
|
+
// 将 keyframes样式写入style内
|
1349
|
+
style.innerHTML = runkeyframes;
|
1350
|
+
// 将style样式存放到head标签
|
1351
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
1352
|
+
// size变动时动画
|
1353
|
+
setTimeout(function () {
|
1354
|
+
cashier.style.transition = 'height 0.28s ease-in-out';
|
1355
|
+
}, 500);
|
1356
|
+
}
|
1357
|
+
// 关闭loading,保留蒙层
|
1358
|
+
this.dismissLoadingFunc();
|
1359
|
+
}
|
1360
|
+
if (this._renderDisplayType === DisplayTypeEnum.inline) {
|
1361
|
+
var _document$getElementB3;
|
1362
|
+
(_document$getElementB3 = document.getElementById(LOADING_ID)) === null || _document$getElementB3 === void 0 || _document$getElementB3.remove();
|
1363
|
+
this.app.style.height = "".concat(data.context.data.height, "px");
|
1364
|
+
}
|
1365
|
+
}
|
1366
|
+
}, {
|
1367
|
+
key: "handleAuthUrlInfo",
|
1368
|
+
value: function handleAuthUrlInfo(authUrlInfo) {
|
1369
|
+
var data = {};
|
1370
|
+
if (!(authUrlInfo !== null && authUrlInfo !== void 0 && authUrlInfo.normalUrl) && !(authUrlInfo !== null && authUrlInfo !== void 0 && authUrlInfo.schemeUrl) && !(authUrlInfo !== null && authUrlInfo !== void 0 && authUrlInfo.applinkUrl) && authUrlInfo !== null && authUrlInfo !== void 0 && authUrlInfo.authUrl) {
|
1371
|
+
data = {
|
1372
|
+
normalUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.authUrl,
|
1373
|
+
schemeUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.authUrl,
|
1374
|
+
applinkUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.authUrl
|
1375
|
+
};
|
1376
|
+
} else {
|
1377
|
+
data = {
|
1378
|
+
normalUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.normalUrl,
|
1379
|
+
schemeUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.schemeUrl,
|
1380
|
+
applinkUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.applinkUrl
|
1381
|
+
};
|
1382
|
+
}
|
1383
|
+
this.handleRedirect(data, true);
|
1384
|
+
}
|
1385
|
+
}, {
|
1386
|
+
key: "handleRedirect",
|
1387
|
+
value: function handleRedirect(data) {
|
1388
|
+
var _data$isDestroy,
|
1389
|
+
_data$isCallApp,
|
1390
|
+
_data$callAppDetectSu,
|
1391
|
+
_this8 = this;
|
1392
|
+
var fromFastSdk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
1393
|
+
var _data = typeof data === 'string' ? {
|
1394
|
+
normalUrl: data
|
1395
|
+
} : _objectSpread(_objectSpread({}, data), {}, {
|
1396
|
+
applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
|
1397
|
+
schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
|
1398
|
+
normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
|
1399
|
+
target: data === null || data === void 0 ? void 0 : data.target,
|
1400
|
+
isDestroy: (_data$isDestroy = data === null || data === void 0 ? void 0 : data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true,
|
1401
|
+
isCallApp: (_data$isCallApp = data === null || data === void 0 ? void 0 : data.isCallApp) !== null && _data$isCallApp !== void 0 ? _data$isCallApp : false,
|
1402
|
+
callAppDetectSuccessDelay: (_data$callAppDetectSu = data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) !== null && _data$callAppDetectSu !== void 0 ? _data$callAppDetectSu : 2000
|
1403
|
+
});
|
1404
|
+
this.AMSSDK.logger.logInfo({
|
1405
|
+
title: 'sdk_event_call_url_start'
|
1406
|
+
}, _objectSpread({}, data)).send();
|
1407
|
+
var successCallback = function successCallback(type, url, durationInSeconds) {
|
1408
|
+
_this8.dispatchToSDK(EVENT.eventCallback.name, {
|
1409
|
+
code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
|
1410
|
+
message: "Successfully opened the app,".concat(type, ": ").concat(url)
|
1411
|
+
});
|
1412
|
+
var extra = {
|
1413
|
+
redirectInfo: JSON.stringify(_data),
|
1414
|
+
openType: type,
|
1415
|
+
url: url,
|
1416
|
+
fromFastSdk: fromFastSdk
|
1417
|
+
};
|
1418
|
+
if (durationInSeconds) {
|
1419
|
+
extra['durationInSeconds'] = durationInSeconds;
|
1420
|
+
}
|
1421
|
+
_this8.AMSSDK.logger.logInfo({
|
1422
|
+
title: 'sdk_event_call_url_success'
|
1423
|
+
}, extra).send();
|
1424
|
+
};
|
1425
|
+
var failCallback = function failCallback(type, url, durationInSeconds) {
|
1426
|
+
_this8.dispatchToSDK(EVENT.eventCallback.name, {
|
1427
|
+
code: eventCodeEnum.SDK_CALL_URL_ERROR,
|
1428
|
+
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)
|
1429
|
+
});
|
1430
|
+
var extra = {
|
1431
|
+
redirectInfo: JSON.stringify(_data),
|
1432
|
+
openType: type,
|
1433
|
+
url: url,
|
1434
|
+
fromFastSdk: fromFastSdk
|
1435
|
+
};
|
1436
|
+
if (durationInSeconds) {
|
1437
|
+
extra['durationInSeconds'] = durationInSeconds;
|
1438
|
+
}
|
1439
|
+
_this8.AMSSDK.logger.logInfo({
|
1440
|
+
title: 'sdk_error_call_url_failed'
|
1441
|
+
}, extra).send();
|
1442
|
+
};
|
1443
|
+
|
1444
|
+
// 支持 target: _blank,新开tab页打开
|
1445
|
+
if (_data.target === TargetEnum.BLANK) {
|
1446
|
+
if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
|
1447
|
+
successCallback(RedirectType.NormalUrl, _data.normalUrl);
|
1448
|
+
window.open(_data.normalUrl);
|
1449
|
+
return;
|
1450
|
+
}
|
1451
|
+
if (_data.target === TargetEnum.REPLACE && !(_data !== null && _data !== void 0 && _data.applinkUrl) && !(_data !== null && _data !== void 0 && _data.schemeUrl)) {
|
1452
|
+
if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
|
1453
|
+
successCallback(RedirectType.NormalUrl, _data.normalUrl);
|
1454
|
+
window.location.replace(_data.normalUrl);
|
1455
|
+
return;
|
1456
|
+
}
|
1457
|
+
// 销毁iframe和全局loading
|
1458
|
+
if (_data !== null && _data !== void 0 && _data.isDestroy) this.cleanContainer();
|
1459
|
+
// 唤端
|
1460
|
+
if (_data !== null && _data !== void 0 && _data.isCallApp && _data !== null && _data !== void 0 && _data.schemeUrl) {
|
1461
|
+
var startCallAppTime = new Date();
|
1462
|
+
var detectSuccessDelay = typeof (data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) === 'number' ? data.callAppDetectSuccessDelay : 5000;
|
1463
|
+
this.AMSSDK._redirect({
|
1464
|
+
schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl,
|
1465
|
+
callAppJudgeTime: detectSuccessDelay
|
1466
|
+
}).then(function () {
|
1467
|
+
var endCallAppTime = new Date();
|
1468
|
+
var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
|
1469
|
+
var durationInSeconds = durationInMilliseconds / 1000;
|
1470
|
+
successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl, durationInSeconds);
|
1471
|
+
}).catch(function () {
|
1472
|
+
var endCallAppTime = new Date();
|
1473
|
+
var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
|
1474
|
+
var durationInSeconds = durationInMilliseconds / 1000;
|
1475
|
+
failCallback(RedirectType.SchemeUrl, _data.schemeUrl, durationInSeconds);
|
1476
|
+
});
|
1477
|
+
return;
|
1478
|
+
}
|
1479
|
+
this.AMSSDK._redirect({
|
1480
|
+
applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
|
1481
|
+
}).then(function () {
|
1482
|
+
successCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
|
1483
|
+
}).catch(function () {
|
1484
|
+
if (_data !== null && _data !== void 0 && _data.applinkUrl) failCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
|
1485
|
+
return _this8.AMSSDK._redirect({
|
1486
|
+
schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl
|
1487
|
+
});
|
1488
|
+
}).then(function () {
|
1489
|
+
successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
|
1490
|
+
}).catch(function () {
|
1491
|
+
if (_data !== null && _data !== void 0 && _data.schemeUrl) failCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
|
1492
|
+
return _this8.AMSSDK._redirect({
|
1493
|
+
normalUrl: _data === null || _data === void 0 ? void 0 : _data.normalUrl
|
1494
|
+
});
|
1495
|
+
}).then(function () {
|
1496
|
+
successCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
|
1497
|
+
}).catch(function () {
|
1498
|
+
failCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
|
1499
|
+
});
|
1500
|
+
}
|
1501
|
+
}, {
|
1502
|
+
key: "handleDeclareInfo",
|
1503
|
+
value: function handleDeclareInfo(_ref13) {
|
1504
|
+
var _ref13$closeDialogDat = _ref13.closeDialogData,
|
1505
|
+
closeDialogData = _ref13$closeDialogDat === void 0 ? {} : _ref13$closeDialogDat;
|
1506
|
+
_handleDeclareInfo({
|
1507
|
+
closeDialogData: closeDialogData
|
1508
|
+
});
|
1509
|
+
}
|
1510
|
+
}, {
|
1511
|
+
key: "handleDeclarePopWindowCallback",
|
1512
|
+
value: function handleDeclarePopWindowCallback() {
|
1513
|
+
var eventInfoName = 'popWindowEventInfo';
|
1514
|
+
if (this._multipleCallbackEvents && eventInfoName in this._multipleCallbackEvents) {
|
1515
|
+
var eventInfo = this._multipleCallbackEvents[eventInfoName];
|
1516
|
+
if (eventInfo.enableCallback) {
|
1517
|
+
this.dispatchToSDK(EVENT.eventCallback.name, {
|
1518
|
+
code: eventInfo.eventName,
|
1519
|
+
result: {
|
1520
|
+
result: eventInfo.eventResult || {}
|
1521
|
+
}
|
1522
|
+
});
|
1523
|
+
}
|
1524
|
+
} else {
|
1525
|
+
console.log("not valid ".concat(eventInfoName, " in "), this._multipleCallbackEvents);
|
1526
|
+
}
|
1527
|
+
}
|
1528
|
+
}, {
|
1529
|
+
key: "handleAppHeartBeat",
|
1530
|
+
value: function handleAppHeartBeat() {
|
1531
|
+
var _this9 = this;
|
1532
|
+
try {
|
1533
|
+
if (!this._webAppHeartBeatTimeoutFn) {
|
1534
|
+
this._webAppHeartBeatTimeoutFn = function () {
|
1535
|
+
if (_this9.isAppAttached()) {
|
1536
|
+
_this9.AMSSDK.logger.logError({
|
1537
|
+
title: 'sdk_error_appHeartBeatTimeout'
|
1538
|
+
});
|
1539
|
+
}
|
1540
|
+
};
|
1541
|
+
}
|
1542
|
+
if (window._webAppHeartBeatTimeoutId) {
|
1543
|
+
clearTimeout(window._webAppHeartBeatTimeoutId);
|
1544
|
+
window._webAppHeartBeatTimeoutId = null;
|
1545
|
+
}
|
1546
|
+
if (this._webAppHeartBeatTimeoutFn) {
|
1547
|
+
window._webAppHeartBeatTimeoutId = setTimeout(this._webAppHeartBeatTimeoutFn, TIMEOUT_WEB_APP_HEART_BEAT);
|
1548
|
+
}
|
1549
|
+
setTimeout(function () {
|
1550
|
+
if (_this9.isAppAttached()) {
|
1551
|
+
_this9.dispatchToApp({
|
1552
|
+
context: {
|
1553
|
+
event: 'sdkHeartBeat',
|
1554
|
+
data: {}
|
1555
|
+
}
|
1556
|
+
});
|
1557
|
+
}
|
1558
|
+
}, TIME_DELAY_SEND_HEART_BEAT);
|
1559
|
+
} catch (error) {
|
1560
|
+
this.AMSSDK.logger.logError({
|
1561
|
+
title: 'sdk_error_handleAppHeartBeat'
|
1562
|
+
}, {
|
1563
|
+
errorMessage: error.message
|
1564
|
+
});
|
1565
|
+
}
|
1566
|
+
}
|
1567
|
+
}, {
|
1568
|
+
key: "isAppAttached",
|
1569
|
+
value: function isAppAttached() {
|
1570
|
+
return this.app || this.popupApp;
|
1571
|
+
}
|
1572
|
+
}, {
|
1573
|
+
key: "isWindowVisible",
|
1574
|
+
value: function isWindowVisible() {
|
1575
|
+
var _document;
|
1576
|
+
return ((_document = document) === null || _document === void 0 ? void 0 : _document.visibilityState) === 'visible';
|
1577
|
+
}
|
1578
|
+
}, {
|
1579
|
+
key: "handleCloseBtnShow",
|
1580
|
+
value: function handleCloseBtnShow(showClose) {
|
1581
|
+
var closeBlock = document.getElementById(COMPONENT_CLOSE_BLOCK_ID);
|
1582
|
+
if (showClose) {
|
1583
|
+
closeBlock === null || closeBlock === void 0 || closeBlock.classList.remove("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
|
1584
|
+
} else if (showClose === false) {
|
1585
|
+
closeBlock === null || closeBlock === void 0 || closeBlock.classList.add("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
|
1586
|
+
}
|
1587
|
+
}
|
1588
|
+
|
1589
|
+
/**
|
1590
|
+
* @description Send message to SDK
|
1591
|
+
*/
|
1592
|
+
}, {
|
1593
|
+
key: "dispatchToSDK",
|
1594
|
+
value: function dispatchToSDK(event, data, eventCallbackId) {
|
1595
|
+
this.AMSSDK._eventCenter.emit(event, data);
|
1596
|
+
if (eventCallbackId) this.AMSSDK._eventCenter.emit(eventCallbackId, data);
|
1597
|
+
}
|
1598
|
+
|
1599
|
+
/**
|
1600
|
+
* @description Send message to iframe
|
1601
|
+
*/
|
1602
|
+
}, {
|
1603
|
+
key: "dispatchToApp",
|
1604
|
+
value: function dispatchToApp(payload) {
|
1605
|
+
var targetElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
1606
|
+
var data = Object.assign({}, payload, {
|
1607
|
+
name: MessageName.SDK_TO_APP,
|
1608
|
+
mode: this.AMSSDK.options.mode,
|
1609
|
+
appId: COMPONENTPLUGINID,
|
1610
|
+
instanceId: this.AMSSDK._instanceId
|
1611
|
+
});
|
1612
|
+
if (targetElement && targetElement.contentWindow) {
|
1613
|
+
return targetElement.contentWindow.postMessage(JSON.stringify(data), '*');
|
1614
|
+
}
|
1615
|
+
if (this.app || this.popupApp) {
|
1616
|
+
var _this$app, _this$app2, _this$popupApp, _this$popupApp2;
|
1617
|
+
(this === null || this === void 0 || (_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.contentWindow) && (this === null || this === void 0 || (_this$app2 = this.app) === null || _this$app2 === void 0 ? void 0 : _this$app2.contentWindow.postMessage(JSON.stringify(data), this.appDomain));
|
1618
|
+
(this === null || this === void 0 || (_this$popupApp = this.popupApp) === null || _this$popupApp === void 0 ? void 0 : _this$popupApp.contentWindow) && (this === null || this === void 0 || (_this$popupApp2 = this.popupApp) === null || _this$popupApp2 === void 0 ? void 0 : _this$popupApp2.contentWindow.postMessage(JSON.stringify(data), '*'));
|
1619
|
+
return;
|
1620
|
+
}
|
1621
|
+
throw new Error(ERRORMESSAGE.SDK_SUBMIT_ERROR.message);
|
1622
|
+
}
|
1623
|
+
|
1624
|
+
/**
|
1625
|
+
* @description Subscribe to messages from SDK
|
1626
|
+
*/
|
1627
|
+
}, {
|
1628
|
+
key: "subscribeFromSDK",
|
1629
|
+
value: function subscribeFromSDK() {
|
1630
|
+
var eventKeyMap = {};
|
1631
|
+
for (var key in eventKeyMap) {
|
1632
|
+
// eslint-disable-next-line no-prototype-builtins
|
1633
|
+
if (eventKeyMap.hasOwnProperty(key)) {
|
1634
|
+
this.AMSSDK._eventCenter.on("".concat(COMPONENTPLUGINID, "-").concat(key), eventKeyMap[key].bind(this));
|
1635
|
+
}
|
1636
|
+
}
|
1637
|
+
}
|
1638
|
+
|
1639
|
+
/**
|
1640
|
+
* @description Send rendering events to iframe
|
1641
|
+
*/
|
1642
|
+
}, {
|
1643
|
+
key: "sendRenderEvent",
|
1644
|
+
value: (function () {
|
1645
|
+
var _sendRenderEvent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
1646
|
+
var _this$_renderParams15, _this$_renderParams16, _this$_renderParams17, _this$_renderParams18, _this$_renderParams19, _this$_renderParams20, _this$_renderParams21, _this$_renderParams22, _this$_renderParams23, _this$AMSSDK$logger, _this$_renderParams24, _this$_renderParams25, _this$_renderParams26, _this$AMSSDK, _this$_renderParams27, isAddressElement, res, submitRes;
|
1647
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
1648
|
+
while (1) switch (_context8.prev = _context8.next) {
|
1649
|
+
case 0:
|
1650
|
+
_context8.prev = 0;
|
1651
|
+
isAddressElement = this.AMSSDK.options.product === ProductSceneEnum.ELEMENT_ADDRESS;
|
1652
|
+
if (!((!this._actionQueryPromise || !this._actionSubmitPromise) && !isAddressElement)) {
|
1653
|
+
_context8.next = 4;
|
1654
|
+
break;
|
1655
|
+
}
|
1656
|
+
return _context8.abrupt("return");
|
1657
|
+
case 4:
|
1658
|
+
_context8.next = 6;
|
1659
|
+
return this._actionQueryPromise;
|
1660
|
+
case 6:
|
1661
|
+
res = _context8.sent;
|
1662
|
+
_context8.next = 9;
|
1663
|
+
return this._actionSubmitPromise;
|
1664
|
+
case 9:
|
1665
|
+
submitRes = _context8.sent;
|
1666
|
+
this._performanceData.push({
|
1667
|
+
key: 'sdk_render_component',
|
1668
|
+
value: Date.now()
|
1669
|
+
});
|
1670
|
+
this.dispatchToApp({
|
1671
|
+
context: {
|
1672
|
+
event: 'renderComponent',
|
1673
|
+
data: {
|
1674
|
+
queryResult: res,
|
1675
|
+
submitResult: submitRes,
|
1676
|
+
sessionResult: (_this$_renderParams15 = this._renderParams) === null || _this$_renderParams15 === void 0 ? void 0 : _this$_renderParams15.paymentSessionMetaData,
|
1677
|
+
paymentSessionData: (_this$_renderParams16 = this._renderParams) === null || _this$_renderParams16 === void 0 ? void 0 : _this$_renderParams16.sessionData,
|
1678
|
+
heightOfVisible: Math.max(window.changingPageHeight, window.innerHeight),
|
1679
|
+
renderDisplayType: (_this$_renderParams17 = this._renderParams) === null || _this$_renderParams17 === void 0 ? void 0 : _this$_renderParams17.renderDisplayType,
|
1680
|
+
appearance: (_this$_renderParams18 = this._renderParams) === null || _this$_renderParams18 === void 0 ? void 0 : _this$_renderParams18.appearance,
|
1681
|
+
notRedirectAfterComplete: ((_this$_renderParams19 = this._renderParams) === null || _this$_renderParams19 === void 0 ? void 0 : _this$_renderParams19.notRedirectAfterComplete) === true,
|
1682
|
+
isAppWebview: this._isAppWebview,
|
1683
|
+
merchantAppointParam: this._merchantAppointParam,
|
1684
|
+
allowSubmitPayCallAhead: this._allowSubmitPayCallAhead,
|
1685
|
+
/** 地址组件集成的参数 */
|
1686
|
+
configParams: (_this$_renderParams20 = this._renderParams) === null || _this$_renderParams20 === void 0 ? void 0 : _this$_renderParams20.configParams,
|
1687
|
+
prefillValue: (_this$_renderParams21 = this._renderParams) === null || _this$_renderParams21 === void 0 ? void 0 : _this$_renderParams21.prefillValue,
|
1688
|
+
componentSession: (_this$_renderParams22 = this._renderParams) === null || _this$_renderParams22 === void 0 ? void 0 : _this$_renderParams22.componentSession,
|
1689
|
+
envInfo: {
|
1690
|
+
screenHeight: screen.height,
|
1691
|
+
screenWidth: screen.width
|
1692
|
+
},
|
1693
|
+
logMetaData: _objectSpread(_objectSpread({
|
1694
|
+
trackId: (_this$_renderParams23 = this._renderParams) === null || _this$_renderParams23 === void 0 ? void 0 : _this$_renderParams23.sessionData,
|
1695
|
+
platform: this.platform,
|
1696
|
+
firstLogTime: (_this$AMSSDK$logger = this.AMSSDK.logger) === null || _this$AMSSDK$logger === void 0 ? void 0 : _this$AMSSDK$logger.getComponentStartTime()
|
1697
|
+
}, ((_this$_renderParams24 = this._renderParams) === null || _this$_renderParams24 === void 0 || (_this$_renderParams24 = _this$_renderParams24.paymentSessionMetaData) === null || _this$_renderParams24 === void 0 ? void 0 : _this$_renderParams24.paymentSessionConfig) || {}), {}, {
|
1698
|
+
renderDisplayType: (_this$_renderParams25 = this._renderParams) === null || _this$_renderParams25 === void 0 ? void 0 : _this$_renderParams25.renderDisplayType,
|
1699
|
+
sdkVersion: this._appVersion,
|
1700
|
+
merchantId: (_this$_renderParams26 = this._renderParams) === null || _this$_renderParams26 === void 0 || (_this$_renderParams26 = _this$_renderParams26.paymentSessionMetaData) === null || _this$_renderParams26 === void 0 ? void 0 : _this$_renderParams26.clientId,
|
1701
|
+
instanceId: (_this$AMSSDK = this.AMSSDK) === null || _this$AMSSDK === void 0 ? void 0 : _this$AMSSDK._instanceId,
|
1702
|
+
performanceData: this._performanceData,
|
1703
|
+
paymentMethodType: (_this$_renderParams27 = this._renderParams) === null || _this$_renderParams27 === void 0 || (_this$_renderParams27 = _this$_renderParams27.paymentSessionMetaData) === null || _this$_renderParams27 === void 0 || (_this$_renderParams27 = _this$_renderParams27.paymentMethodInfoView) === null || _this$_renderParams27 === void 0 ? void 0 : _this$_renderParams27.paymentMethodType
|
1704
|
+
})
|
1705
|
+
}
|
1706
|
+
}
|
1707
|
+
}, null);
|
1708
|
+
this.AMSSDK.logger.logInfo({
|
1709
|
+
title: 'sdk_event_renderComponent'
|
1710
|
+
});
|
1711
|
+
this.dispatchToApp({
|
1712
|
+
context: {
|
1713
|
+
event: 'web-sdk-performance',
|
1714
|
+
data: {
|
1715
|
+
performanceData: this._performanceData
|
1716
|
+
}
|
1717
|
+
}
|
1718
|
+
});
|
1719
|
+
// eslint-disable-next-line no-empty
|
1720
|
+
_context8.next = 18;
|
1721
|
+
break;
|
1722
|
+
case 16:
|
1723
|
+
_context8.prev = 16;
|
1724
|
+
_context8.t0 = _context8["catch"](0);
|
1725
|
+
case 18:
|
1726
|
+
case "end":
|
1727
|
+
return _context8.stop();
|
1728
|
+
}
|
1729
|
+
}, _callee8, this, [[0, 16]]);
|
1730
|
+
}));
|
1731
|
+
function sendRenderEvent() {
|
1732
|
+
return _sendRenderEvent.apply(this, arguments);
|
1733
|
+
}
|
1734
|
+
return sendRenderEvent;
|
1735
|
+
}()
|
1736
|
+
/**
|
1737
|
+
* @description close cashier
|
1738
|
+
*/
|
1739
|
+
)
|
1740
|
+
}, {
|
1741
|
+
key: "cleanContainer",
|
1742
|
+
value: function cleanContainer() {
|
1743
|
+
var _document$getElementB4,
|
1744
|
+
_this10 = this;
|
1745
|
+
var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
1746
|
+
(_document$getElementB4 = document.getElementById(LOADING_ID)) === null || _document$getElementB4 === void 0 || _document$getElementB4.remove();
|
1747
|
+
this.hideComponentAnimation();
|
1748
|
+
var mockup = document.getElementById(MOCKUP_ID);
|
1749
|
+
mockup === null || mockup === void 0 || mockup.classList.add("".concat(MOCKUP_ID, "-hidden"));
|
1750
|
+
this._loadAppPromiseResolve && this._loadAppPromiseResolve(true);
|
1751
|
+
this._performanceData = [];
|
1752
|
+
this._isInitComponent = false;
|
1753
|
+
this.app = null;
|
1754
|
+
if (immediately) this.cleanElement();else {
|
1755
|
+
setTimeout(function () {
|
1756
|
+
_this10.cleanElement();
|
1757
|
+
}, 300);
|
1758
|
+
}
|
1759
|
+
}
|
1760
|
+
}, {
|
1761
|
+
key: "hideComponentAnimation",
|
1762
|
+
value: function hideComponentAnimation() {
|
1763
|
+
var _container$style;
|
1764
|
+
var container = document.getElementById(COMPONENT_CONTAINER_ID);
|
1765
|
+
if (this.app) this.app.style.height = container === null || container === void 0 || (_container$style = container.style) === null || _container$style === void 0 ? void 0 : _container$style.height;
|
1766
|
+
if (container) {
|
1767
|
+
// size变化动画取消
|
1768
|
+
container.style.transition = '';
|
1769
|
+
container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform));
|
1770
|
+
container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
|
1771
|
+
container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-hidden-").concat(this.platform));
|
1772
|
+
}
|
1773
|
+
}
|
1774
|
+
}, {
|
1775
|
+
key: "closeBtnFunc",
|
1776
|
+
value: function closeBtnFunc() {
|
1777
|
+
// element && element.removeEventListener()
|
1778
|
+
if (this._isRetention) this.showRetentionPopup();else {
|
1779
|
+
this.cleanContainer();
|
1780
|
+
this.dispatchToSDK(EVENT.close.name, {});
|
1781
|
+
this.handleDeclarePopWindowCallback();
|
1782
|
+
}
|
1783
|
+
}
|
1784
|
+
}, {
|
1785
|
+
key: "retentionPopupLeaveFunc",
|
1786
|
+
value: function retentionPopupLeaveFunc() {
|
1787
|
+
this.dispatchToSDK(EVENT.close.name, {});
|
1788
|
+
this.hideRetentionPopupFunc();
|
1789
|
+
this.cleanContainer();
|
1790
|
+
this.handleDeclarePopWindowCallback();
|
1791
|
+
}
|
1792
|
+
}, {
|
1793
|
+
key: "removeRetentionPopup",
|
1794
|
+
value: function removeRetentionPopup(platform) {
|
1795
|
+
_removeRetentionPopup(platform, this.hideRetentionPopupFunc.bind(this), this.retentionPopupLeaveFunc.bind(this));
|
1796
|
+
}
|
1797
|
+
}, {
|
1798
|
+
key: "showRetentionPopup",
|
1799
|
+
value: function showRetentionPopup() {
|
1800
|
+
var retentionPopup = document.getElementById(COMPONENT_RETENTION_ID);
|
1801
|
+
var container = document.getElementById(COMPONENT_CONTAINER_ID);
|
1802
|
+
if (retentionPopup) {
|
1803
|
+
container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-opacity"));
|
1804
|
+
retentionPopup.classList.remove("".concat(COMPONENT_RETENTION_ID, "-hidden"));
|
1805
|
+
retentionPopup.classList.add("".concat(COMPONENT_RETENTION_ID, "-show"));
|
1806
|
+
}
|
1807
|
+
}
|
1808
|
+
}, {
|
1809
|
+
key: "hideRetentionPopupFunc",
|
1810
|
+
value: function hideRetentionPopupFunc() {
|
1811
|
+
hideRetentionPopup();
|
1812
|
+
}
|
1813
|
+
}, {
|
1814
|
+
key: "submitForm",
|
1815
|
+
value: function submitForm(data) {
|
1816
|
+
var attributes = data.attributes;
|
1817
|
+
var _document2 = document,
|
1818
|
+
body = _document2.body;
|
1819
|
+
var form = document.createElement('form');
|
1820
|
+
form.setAttribute('height', '1');
|
1821
|
+
form.setAttribute('width', '1');
|
1822
|
+
Object.keys(attributes.data).forEach(function (key) {
|
1823
|
+
var input = document.createElement('input');
|
1824
|
+
input.setAttribute('type', 'hidden');
|
1825
|
+
input.setAttribute('name', key);
|
1826
|
+
input.setAttribute('value', attributes.data[key]);
|
1827
|
+
form.appendChild(input);
|
1828
|
+
});
|
1829
|
+
form.setAttribute('action', attributes.action);
|
1830
|
+
form.setAttribute('method', 'post');
|
1831
|
+
body.appendChild(form);
|
1832
|
+
setTimeout(function () {
|
1833
|
+
form.submit();
|
1834
|
+
}, 0);
|
1835
|
+
}
|
1836
|
+
}]);
|
1837
|
+
return ComponentApp;
|
1838
|
+
}();
|
1839
|
+
export { ComponentApp as default };
|