@alipay/ams-checkout 2.0.21 → 2.0.23

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.
@@ -1,15 +1,12 @@
1
1
  var _excluded = ["onStatusChange"],
2
2
  _excluded2 = ["onBeforeConfirm"];
3
3
  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); }
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
4
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
5
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
6
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
7
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
8
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
9
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- 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); } }
12
- 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); }); }; }
13
10
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
14
11
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
12
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -24,15 +21,20 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
24
21
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
22
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
26
23
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
+ 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; }
25
+ 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); } }
26
+ 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); }); }; }
27
27
  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; }
28
28
  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; }
29
29
  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; }
30
30
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
31
31
  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); }
32
- import { openModal, sdkQuery, getLocaleFromRenderData, getDevReqConfig, getMetaData, buildPageUrl, debugError, debug, MessageType, request, parseHostSign, SDKBridge, parseTrackerId, oneAccountQuery, OpenSDKError, awaitWrap, themeColorMap, ApplePayHostService, checkSessionData, sdkTracker } from "../../../../modern/tools";
32
+ import { openModal, showToast, sdkQuery, getLocaleFromRenderData, getDevReqConfig, getMetaData, buildPageUrl, debugError, debug, MessageType, request, parseHostSign, SDKBridge, parseTrackerId, oneAccountQuery, OpenSDKError, awaitWrap, themeColorMap, ApplePayHostService, buildRecurringPaymentRequest, checkSessionData, sdkTracker, ModalPort } from "../../../../modern/tools";
33
+ import { shouldQueryOneAccount } from "../../../utils/connectConfig";
33
34
  import { device } from "../../../../util";
34
35
  import { EventCallbackCode } from "../type";
35
36
  import { adaptSubmitResult, adaptAppearance } from "./adapter";
37
+ import { safeParse } from "../util";
36
38
  import { v4 as uuid } from 'uuid';
37
39
 
38
40
  // ============================================================
@@ -43,18 +45,45 @@ import { v4 as uuid } from 'uuid';
43
45
  // ============================================================
44
46
 
45
47
  var TRACK_CODE_PREFIX = '7982';
48
+
49
+ // 缓存解析出的 merchantId,供埋点 helper 在任意阶段统一带上
50
+ var _merchantId = '';
46
51
  var track = function track(phase, msg) {
47
52
  var extra = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
48
53
  try {
49
54
  var code = "".concat(TRACK_CODE_PREFIX).concat(phase === 'error' ? '' : phase);
55
+ // LogItem 类型未暴露 merchant_id 字段,但运行时 tracker 会透传,
56
+ // 故用断言保留该字段名供下游埋点消费
50
57
  sdkTracker.log(_objectSpread({
51
58
  code: code,
52
- msg: msg
59
+ msg: msg,
60
+ merchant_id: _merchantId
53
61
  }, extra));
54
62
  } catch (_unused) {
55
63
  /* 埋点失败绝不影响主流程 */
56
64
  }
57
65
  };
66
+
67
+ /**
68
+ * 优先取 sessionData 解析出的 clientId;
69
+ * 缺失时从容错角度回落到 extendInfo 中的 merchantId(URL 编码需解码)。
70
+ * 全程容错:任一步骤缺失/解析失败都返回空串,绝不抛异常。
71
+ */
72
+ var resolveMerchantId = function resolveMerchantId(parseData) {
73
+ if (parseData !== null && parseData !== void 0 && parseData.clientId) {
74
+ return parseData.clientId;
75
+ }
76
+ try {
77
+ var info = safeParse(parseData === null || parseData === void 0 ? void 0 : parseData.extendInfo, {});
78
+ var merchantId = info === null || info === void 0 ? void 0 : info.merchantId;
79
+ if (!merchantId || typeof merchantId !== 'string') {
80
+ return '';
81
+ }
82
+ return decodeURIComponent(merchantId);
83
+ } catch (_unused2) {
84
+ return '';
85
+ }
86
+ };
58
87
  var trackMount = function trackMount(msg) {
59
88
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
60
89
  return track('mount', msg, extra);
@@ -71,6 +100,81 @@ var trackError = function trackError(msg) {
71
100
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
72
101
  return track('error', msg, extra);
73
102
  };
103
+ // ============================================================
104
+ // 统一 API 终态上报(7982api):在 mount/submitPayment/validateFields
105
+ // 每个出口(成功/失败/中断)捕获「返回给商户的完整结果」,一处包裹覆盖全部分支。
106
+ // 与分散的 trackXxx 互补、不替换;merchantId 为关键字段,必带。
107
+ // _merchantId 在 setup() 解析后填充,mount 首次调用在 resolve 时已就绪。
108
+ // ============================================================
109
+ var reportApiEnd = function reportApiEnd(api, durationMs) {
110
+ var extra = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
111
+ try {
112
+ sdkTracker.log(_objectSpread({
113
+ code: "".concat(TRACK_CODE_PREFIX, "api"),
114
+ msg: api,
115
+ m1: durationMs,
116
+ merchant_id: _merchantId
117
+ }, extra));
118
+ } catch (_unused3) {
119
+ /* 埋点失败绝不影响主流程 */
120
+ }
121
+ };
122
+
123
+ // 将返回给商户的结果对象归一为埋点维度:d1 状态/成败、d2 error.code、d3 traceId、d4 扩展
124
+ var normalizeApiResult = function normalizeApiResult(api, result) {
125
+ var acc = {};
126
+ if (api === 'submitPayment') {
127
+ var _result$error, _result$error2;
128
+ acc.d1 = (result === null || result === void 0 ? void 0 : result.status) || '';
129
+ acc.d2 = (result === null || result === void 0 || (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.code) || '';
130
+ if (result !== null && result !== void 0 && (_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.traceId) acc.d3 = result.error.traceId;
131
+ // d4 固定留给 paymentMethodType(与 submit_reply 链 d4 口径一致,便于跨链关联)
132
+ if (result !== null && result !== void 0 && result.userCanceled3D) acc.d5 = 'true';
133
+ } else if (api === 'mount') {
134
+ var _result$error3, _result$error4;
135
+ acc.d1 = result !== null && result !== void 0 && result.error ? 'fail' : 'success';
136
+ acc.d2 = (result === null || result === void 0 || (_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.code) || '';
137
+ if (result !== null && result !== void 0 && (_result$error4 = result.error) !== null && _result$error4 !== void 0 && _result$error4.traceId) acc.d3 = result.error.traceId;
138
+ } else if (api === 'validateFields') {
139
+ acc.d1 = result !== null && result !== void 0 && result.isValid ? 'valid' : 'invalid';
140
+ }
141
+ return acc;
142
+ };
143
+
144
+ // 统一包裹:捕获终态(resolve/reject)后上报,原值/原异常原样透传,不影响任何已有逻辑。
145
+ // extraBuilder 供调用方注入实例上下文字段(如 paymentMethodType),其值覆盖 normalizeApiResult 结果。
146
+ var runApi = /*#__PURE__*/function () {
147
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, fn, extraBuilder) {
148
+ var startedAt, result;
149
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
150
+ while (1) switch (_context.prev = _context.next) {
151
+ case 0:
152
+ startedAt = Date.now();
153
+ _context.prev = 1;
154
+ _context.next = 4;
155
+ return fn();
156
+ case 4:
157
+ result = _context.sent;
158
+ reportApiEnd(api, Date.now() - startedAt, _objectSpread(_objectSpread({}, normalizeApiResult(api, result)), extraBuilder === null || extraBuilder === void 0 ? void 0 : extraBuilder(false)));
159
+ return _context.abrupt("return", result);
160
+ case 9:
161
+ _context.prev = 9;
162
+ _context.t0 = _context["catch"](1);
163
+ reportApiEnd(api, Date.now() - startedAt, _objectSpread({
164
+ d1: 'error',
165
+ d2: (_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.code) || 'UNKNOWN'
166
+ }, extraBuilder === null || extraBuilder === void 0 ? void 0 : extraBuilder(true)));
167
+ throw _context.t0;
168
+ case 13:
169
+ case "end":
170
+ return _context.stop();
171
+ }
172
+ }, _callee, null, [[1, 9]]);
173
+ }));
174
+ return function runApi(_x, _x2, _x3) {
175
+ return _ref.apply(this, arguments);
176
+ };
177
+ }();
74
178
  import CallApp from "../../../../util/intl-callapp/es/main";
75
179
  import { getApplePayPaymentSession } from "../../../../service";
76
180
  import { BusManager, BusMessage } from "../../../bus";
@@ -88,6 +192,9 @@ var recoverSdkQueryBusinessResponse = function recoverSdkQueryBusinessResponse(e
88
192
  var MOUNT_TIMEOUT = 16000;
89
193
  var logger = new Logger(LogConfig, true);
90
194
  var ELEMENT_DESTROYED_MESSAGE = 'Element already destroyed';
195
+ // 订阅/分期场景 ApplePaySession 版本:recurringPaymentRequest 需 v12+。
196
+ // 对齐老链路 plugin/applepay/interface.ts 的 APPLE_PAY_RECURRING_VERSION = 14。
197
+ var APPLE_PAY_RECURRING_VERSION = 14;
91
198
  var getDestroyedError = function getDestroyedError() {
92
199
  return {
93
200
  code: ERRORMESSAGE.UI_STATE_ERROR.code,
@@ -142,6 +249,7 @@ var HostSDKBridge = /*#__PURE__*/function (_SDKBridge) {
142
249
  var AMSMessageType = {
143
250
  VALIDATE: 'OPENSDK@VALIDATE',
144
251
  VALIDATE_REPLY: 'OPENSDK@VALIDATE_REPLY',
252
+ SHOWTOAST: 'OPENSDK@SHOWTOAST',
145
253
  GET_APPLE_PAY_TOKEN: 'OPENSDK@GET_APPLE_PAY_TOKEN',
146
254
  GET_APPLE_PAY_TOKEN_REPLY: 'OPENSDK@GET_APPLE_PAY_TOKEN_REPLY',
147
255
  // Web element GP:iframe 委托 SDK/父 frame 调 loadPaymentData(解决跨域 iframe 二次 show() 被拒问题)
@@ -171,9 +279,9 @@ var AMSMessageType = {
171
279
  * 7. ready 后发送缓存的消息
172
280
  */
173
281
  export var ModernElementController = /*#__PURE__*/function () {
174
- function ModernElementController(_ref) {
175
- var onStatusChange = _ref.onStatusChange,
176
- options = _objectWithoutProperties(_ref, _excluded);
282
+ function ModernElementController(_ref2) {
283
+ var onStatusChange = _ref2.onStatusChange,
284
+ options = _objectWithoutProperties(_ref2, _excluded);
177
285
  _classCallCheck(this, ModernElementController);
178
286
  _defineProperty(this, "options", void 0);
179
287
  _defineProperty(this, "onStatusChange", void 0);
@@ -186,7 +294,6 @@ export var ModernElementController = /*#__PURE__*/function () {
186
294
  _defineProperty(this, "modalBridge", null);
187
295
  _defineProperty(this, "modalDestroy", null);
188
296
  _defineProperty(this, "modalIframe", null);
189
- _defineProperty(this, "_closeConfirmResolve", null);
190
297
  _defineProperty(this, "notRedirectAfterComplete", false);
191
298
  _defineProperty(this, "_sdkInitTime", Date.now());
192
299
  _defineProperty(this, "_mountStartTime", 0);
@@ -223,11 +330,33 @@ export var ModernElementController = /*#__PURE__*/function () {
223
330
  _createClass(ModernElementController, [{
224
331
  key: "mount",
225
332
  value: function () {
226
- var _mount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(renderOptions, sdkSelector) {
333
+ var _mount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderOptions, sdkSelector) {
334
+ var _this = this;
335
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
336
+ while (1) switch (_context2.prev = _context2.next) {
337
+ case 0:
338
+ return _context2.abrupt("return", runApi('mount', function () {
339
+ return _this.doMount(renderOptions, sdkSelector);
340
+ }));
341
+ case 1:
342
+ case "end":
343
+ return _context2.stop();
344
+ }
345
+ }, _callee2);
346
+ }));
347
+ function mount(_x4, _x5) {
348
+ return _mount.apply(this, arguments);
349
+ }
350
+ return mount;
351
+ }()
352
+ }, {
353
+ key: "doMount",
354
+ value: function () {
355
+ var _doMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(renderOptions, sdkSelector) {
227
356
  var _this$options$loading, _this$options$loading2;
228
357
  var container, _this$options, _this$options$onEvent, _this$options$loading3, _this$options$loading4, iframeUrl, iframeOrigin, readyHandshakePromise, _yield$Promise$all, _yield$Promise$all2, setupConfig, dataStructError, _this$options$loading5, _this$options$loading6, _this$options2, _this$options2$onEven, errorResult;
229
- return _regeneratorRuntime().wrap(function _callee$(_context) {
230
- while (1) switch (_context.prev = _context.next) {
358
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
359
+ while (1) switch (_context3.prev = _context3.next) {
231
360
  case 0:
232
361
  trackMount('mount_start', {
233
362
  d1: sdkSelector,
@@ -235,7 +364,7 @@ export var ModernElementController = /*#__PURE__*/function () {
235
364
  });
236
365
  container = document.querySelector(sdkSelector);
237
366
  if (container) {
238
- _context.next = 6;
367
+ _context3.next = 6;
239
368
  break;
240
369
  }
241
370
  trackError('selector_not_found', {
@@ -245,7 +374,7 @@ export var ModernElementController = /*#__PURE__*/function () {
245
374
  code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
246
375
  message: "Element with selector ".concat(sdkSelector, " not found.")
247
376
  });
248
- return _context.abrupt("return", {
377
+ return _context3.abrupt("return", {
249
378
  error: {
250
379
  code: 'PARAM_INVALID',
251
380
  message: "selector not found"
@@ -254,7 +383,7 @@ export var ModernElementController = /*#__PURE__*/function () {
254
383
  case 6:
255
384
  (_this$options$loading = this.options.loading) === null || _this$options$loading === void 0 || (_this$options$loading2 = _this$options$loading.onStartLoading) === null || _this$options$loading2 === void 0 || _this$options$loading2.call(_this$options$loading);
256
385
  this.setStatus('mounting');
257
- _context.prev = 8;
386
+ _context3.prev = 8;
258
387
  // 1. 创建 iframe(先不设置 src,避免提前触发加载)
259
388
  iframeUrl = this.buildIframeUrl();
260
389
  this.iframe = document.createElement('iframe');
@@ -269,7 +398,7 @@ export var ModernElementController = /*#__PURE__*/function () {
269
398
  if (iframeOrigin && iframeOrigin !== 'null') {
270
399
  this.bridge.setOrigin(iframeOrigin);
271
400
  }
272
- } catch (_unused2) {
401
+ } catch (_unused4) {
273
402
  // URL 解析失败时保持默认 origin
274
403
  }
275
404
  } else {
@@ -287,14 +416,14 @@ export var ModernElementController = /*#__PURE__*/function () {
287
416
  });
288
417
 
289
418
  // 3. setup()(网络请求)与 waitForReadyHandshake()(等待 iframe 加载)并行执行
290
- _context.next = 24;
419
+ _context3.next = 24;
291
420
  return Promise.all([this.setup(renderOptions), readyHandshakePromise]);
292
421
  case 24:
293
- _yield$Promise$all = _context.sent;
422
+ _yield$Promise$all = _context3.sent;
294
423
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 1);
295
424
  setupConfig = _yield$Promise$all2[0];
296
425
  if (!(this.status === 'destroyed')) {
297
- _context.next = 29;
426
+ _context3.next = 29;
298
427
  break;
299
428
  }
300
429
  throw getDestroyedError();
@@ -313,59 +442,59 @@ export var ModernElementController = /*#__PURE__*/function () {
313
442
  this.sendHandshake(setupConfig);
314
443
 
315
444
  // 5. 等待 HANDSHAKE_ACK
316
- _context.next = 35;
445
+ _context3.next = 35;
317
446
  return this.waitForHandshakeAck();
318
447
  case 35:
319
448
  this.setStatus('ready');
320
449
  this.flushCachedMessages();
321
450
  (_this$options$loading3 = this.options.loading) === null || _this$options$loading3 === void 0 || (_this$options$loading4 = _this$options$loading3.onEndLoading) === null || _this$options$loading4 === void 0 || _this$options$loading4.call(_this$options$loading3);
322
451
  if (!dataStructError) {
323
- _context.next = 40;
452
+ _context3.next = 40;
324
453
  break;
325
454
  }
326
- return _context.abrupt("return", {
455
+ return _context3.abrupt("return", {
327
456
  error: dataStructError
328
457
  });
329
458
  case 40:
330
459
  trackMount('mount_success', {
331
460
  m1: this._mountStartTime ? Date.now() - this._mountStartTime : 0
332
461
  });
333
- return _context.abrupt("return", {});
462
+ return _context3.abrupt("return", {});
334
463
  case 44:
335
- _context.prev = 44;
336
- _context.t0 = _context["catch"](8);
464
+ _context3.prev = 44;
465
+ _context3.t0 = _context3["catch"](8);
337
466
  (_this$options$loading5 = this.options.loading) === null || _this$options$loading5 === void 0 || (_this$options$loading6 = _this$options$loading5.onEndLoading) === null || _this$options$loading6 === void 0 || _this$options$loading6.call(_this$options$loading5);
338
- if (!isDestroyedError(_context.t0)) {
339
- _context.next = 49;
467
+ if (!isDestroyedError(_context3.t0)) {
468
+ _context3.next = 49;
340
469
  break;
341
470
  }
342
- return _context.abrupt("return", {
343
- error: _context.t0
471
+ return _context3.abrupt("return", {
472
+ error: _context3.t0
344
473
  });
345
474
  case 49:
346
475
  trackError('mount_error', {
347
- d1: (_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.code) || 'UNKNOWN',
348
- d2: (_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || ''
476
+ d1: (_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.code) || 'UNKNOWN',
477
+ d2: (_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message) || ''
349
478
  });
350
479
  this.cleanup();
351
480
  errorResult = {
352
- code: _context.t0.code || 'UNKNOWN',
353
- message: _context.t0.message || ''
481
+ code: _context3.t0.code || 'UNKNOWN',
482
+ message: _context3.t0.message || ''
354
483
  };
355
484
  (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2$onEven = _this$options2.onEventCallback) === null || _this$options2$onEven === void 0 || _this$options2$onEven.call(_this$options2, errorResult);
356
- return _context.abrupt("return", {
485
+ return _context3.abrupt("return", {
357
486
  error: errorResult
358
487
  });
359
488
  case 54:
360
489
  case "end":
361
- return _context.stop();
490
+ return _context3.stop();
362
491
  }
363
- }, _callee, this, [[8, 44]]);
492
+ }, _callee3, this, [[8, 44]]);
364
493
  }));
365
- function mount(_x, _x2) {
366
- return _mount.apply(this, arguments);
494
+ function doMount(_x6, _x7) {
495
+ return _doMount.apply(this, arguments);
367
496
  }
368
- return mount;
497
+ return doMount;
369
498
  }()
370
499
  /**
371
500
  * setup() — 解析 sessionData 获取 metaData,发起 sdkQuery 获取渲染数据,准备 HANDSHAKE 配置
@@ -380,14 +509,14 @@ export var ModernElementController = /*#__PURE__*/function () {
380
509
  }, {
381
510
  key: "setup",
382
511
  value: (function () {
383
- var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderOptions) {
512
+ var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(renderOptions) {
384
513
  var _parseData$connectFac,
385
- _this = this,
514
+ _this2 = this,
386
515
  _parseData$paymentMet,
387
516
  _sdkQueryResult$data;
388
- var sessionData, parseData, isConnect, paymentSessionConfig, genSdkQueryPromise, genOneAccountQueryPromise, promises, cancelDestroyCallback, destroyPromise, queryPromise, _yield$Promise$race$f, _yield$Promise$race$f2, sdkQueryResult, oneAccountQueryResult, _sdkQueryResult$error, _sdkQueryResult$error2, _oneAccountQueryResul, _oneAccountQueryResul2, preferredLocale, locale, renderDataError;
389
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
390
- while (1) switch (_context2.prev = _context2.next) {
517
+ var sessionData, parseData, lastEnv, isConnect, shouldQueryOneAccountFlag, paymentSessionConfig, genSdkQueryPromise, genOneAccountQueryPromise, promises, cancelDestroyCallback, destroyPromise, queryPromise, _yield$Promise$race$f, _yield$Promise$race$f2, sdkQueryResult, oneAccountQueryResult, _sdkQueryResult$error, _sdkQueryResult$error2, _oneAccountQueryResul, _oneAccountQueryResul2, preferredLocale, locale, renderDataError;
518
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
519
+ while (1) switch (_context4.prev = _context4.next) {
391
520
  case 0:
392
521
  this._mountStartTime = Date.now();
393
522
  trackMount('setup_start');
@@ -395,16 +524,25 @@ export var ModernElementController = /*#__PURE__*/function () {
395
524
  this.notRedirectAfterComplete = renderOptions.notRedirectAfterComplete || false;
396
525
  sessionData = this.options.sessionData; // checkSessionData 失败会 throw AntomSDKError(SESSION_DATA_INVALID),
397
526
  // 冒泡到 mount 的 catch 由 mount_error 统一上报,此处无需额外处理
398
- parseData = checkSessionData(sessionData, 'ELEMENT_PAYMENT'); // 初始化 request 全局配置,使 sdkQuery 能正确发起请求
527
+ parseData = checkSessionData(sessionData, 'ELEMENT_PAYMENT');
528
+ lastEnv = this.options.environment === 'sandbox' ? 'sandbox' : 'prod';
529
+ this.options.environment;
530
+ // 解析 merchantId(优先 clientId,缺失时容错回落到 extendInfo.merchantId),
531
+ // 缓存到模块级变量,使后续所有 trackXxx 埋点统一带上
532
+ _merchantId = resolveMerchantId(parseData);
533
+
534
+ // 初始化 request 全局配置,使 sdkQuery 能正确发起请求
399
535
  // tracker: sdkTracker —— 接入 HTTP 层自动埋点(B 套),上报每个请求的成败/RTT/错误码
400
536
  // 与 antom.ts 入口对齐;不传则 sdkQuery/submitPay/inquiry 等网络细节不可观测
401
- request.setGlobalOptions({
537
+ request.setGlobalOptions(_objectSpread(_objectSpread({
402
538
  hostSign: parseHostSign(sessionData),
403
- env: this.options.environment,
404
- sdkVersion: "2.0.21" || '',
539
+ env: lastEnv
540
+ }, getDevReqConfig()), {}, {
541
+ sdkVersion: "2.0.23" || '',
405
542
  tracker: sdkTracker
406
- });
543
+ }));
407
544
  isConnect = !!(parseData !== null && parseData !== void 0 && (_parseData$connectFac = parseData.connectFactor) !== null && _parseData$connectFac !== void 0 && _parseData$connectFac.enableConnect);
545
+ shouldQueryOneAccountFlag = shouldQueryOneAccount(isConnect, parseData === null || parseData === void 0 ? void 0 : parseData.extendInfo);
408
546
  paymentSessionConfig = parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig;
409
547
  genSdkQueryPromise = function genSdkQueryPromise() {
410
548
  var _renderOptions$mercha;
@@ -413,14 +551,14 @@ export var ModernElementController = /*#__PURE__*/function () {
413
551
  isUserPreferredLocale: true
414
552
  },
415
553
  merchantAppointParam: (_renderOptions$mercha = renderOptions.merchantAppointParam) !== null && _renderOptions$mercha !== void 0 && _renderOptions$mercha.storedCard ? renderOptions.merchantAppointParam : undefined,
416
- notRedirectAfterComplete: _this.notRedirectAfterComplete,
554
+ notRedirectAfterComplete: _this2.notRedirectAfterComplete,
417
555
  // sdk需要传入该字段
418
556
  paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
419
557
  paymentSessionData: sessionData
420
558
  }, {
421
559
  // 传商户初始化的 locale,服务端据此返回对应语言(缺失则回落用户偏好/en_US)
422
560
  envInfo: {
423
- locale: _this.options.locale
561
+ locale: _this2.options.locale
424
562
  }
425
563
  }).catch(recoverSdkQueryBusinessResponse));
426
564
  };
@@ -433,18 +571,18 @@ export var ModernElementController = /*#__PURE__*/function () {
433
571
  }
434
572
  }));
435
573
  };
436
- promises = isConnect ? [genSdkQueryPromise(), genOneAccountQueryPromise()] : [genSdkQueryPromise(), undefined];
574
+ promises = shouldQueryOneAccountFlag ? [genSdkQueryPromise(), genOneAccountQueryPromise()] : [genSdkQueryPromise(), undefined];
437
575
  cancelDestroyCallback = function cancelDestroyCallback() {};
438
576
  destroyPromise = new Promise(function (_, reject) {
439
- cancelDestroyCallback = _this.onDestroy(function () {
577
+ cancelDestroyCallback = _this2.onDestroy(function () {
440
578
  return reject(getDestroyedError());
441
579
  });
442
580
  });
443
581
  queryPromise = Promise.all(promises);
444
- _context2.next = 16;
582
+ _context4.next = 20;
445
583
  return Promise.race([queryPromise, destroyPromise]).finally(cancelDestroyCallback);
446
- case 16:
447
- _yield$Promise$race$f = _context2.sent;
584
+ case 20:
585
+ _yield$Promise$race$f = _context4.sent;
448
586
  _yield$Promise$race$f2 = _slicedToArray(_yield$Promise$race$f, 2);
449
587
  sdkQueryResult = _yield$Promise$race$f2[0];
450
588
  oneAccountQueryResult = _yield$Promise$race$f2[1];
@@ -454,7 +592,7 @@ export var ModernElementController = /*#__PURE__*/function () {
454
592
  d2: ((_sdkQueryResult$error2 = sdkQueryResult.error) === null || _sdkQueryResult$error2 === void 0 ? void 0 : _sdkQueryResult$error2.message) || ''
455
593
  });
456
594
  }
457
- if (isConnect && oneAccountQueryResult !== null && oneAccountQueryResult !== void 0 && oneAccountQueryResult.error) {
595
+ if (shouldQueryOneAccountFlag && oneAccountQueryResult !== null && oneAccountQueryResult !== void 0 && oneAccountQueryResult.error) {
458
596
  trackHandshake('one_account_query_failed', {
459
597
  d1: ((_oneAccountQueryResul = oneAccountQueryResult.error) === null || _oneAccountQueryResul === void 0 ? void 0 : _oneAccountQueryResul.code) || '',
460
598
  d2: ((_oneAccountQueryResul2 = oneAccountQueryResult.error) === null || _oneAccountQueryResul2 === void 0 ? void 0 : _oneAccountQueryResul2.message) || ''
@@ -465,7 +603,7 @@ export var ModernElementController = /*#__PURE__*/function () {
465
603
  preferredLocale = getLocaleFromRenderData(sdkQueryResult.data);
466
604
  locale = preferredLocale || this.options.locale; // 优先使用请求错误,其次使用数据结构校验错误
467
605
  renderDataError = sdkQueryResult.error || (oneAccountQueryResult === null || oneAccountQueryResult === void 0 ? void 0 : oneAccountQueryResult.error);
468
- return _context2.abrupt("return", {
606
+ return _context4.abrupt("return", {
469
607
  sdkTiming: {
470
608
  sdkInitTime: this._sdkInitTime,
471
609
  mountStartTime: this._mountStartTime
@@ -482,6 +620,7 @@ export var ModernElementController = /*#__PURE__*/function () {
482
620
  sessionMetaData: parseData,
483
621
  // 更新字段,对应老的doMain
484
622
  merchantDomain: window.location.hostname,
623
+ doMain: window.location.hostname,
485
624
  // 更新字段,对应老的appearance,结构按新的来
486
625
  appearance: adaptAppearance((renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.appearance) || this.options.appearance, renderOptions.merchantAppointParam),
487
626
  // 原老字段
@@ -489,7 +628,7 @@ export var ModernElementController = /*#__PURE__*/function () {
489
628
  paymentMethodCategoryType: paymentSessionConfig === null || paymentSessionConfig === void 0 ? void 0 : paymentSessionConfig.paymentMethodCategoryType,
490
629
  productSceneVersion: paymentSessionConfig === null || paymentSessionConfig === void 0 ? void 0 : paymentSessionConfig.productSceneVersion,
491
630
  trackId: parseTrackerId(sessionData),
492
- merchantId: parseData === null || parseData === void 0 ? void 0 : parseData.clientId,
631
+ merchantId: _merchantId,
493
632
  paymentMethodType: parseData === null || parseData === void 0 || (_parseData$paymentMet = parseData.paymentMethodInfoView) === null || _parseData$paymentMet === void 0 ? void 0 : _parseData$paymentMet.paymentMethodType
494
633
  },
495
634
  // 原老字段
@@ -497,23 +636,23 @@ export var ModernElementController = /*#__PURE__*/function () {
497
636
  // 新sdk字段
498
637
  locale: locale,
499
638
  // 新sdk字段
500
- sdkVersion: "2.0.21" || '',
639
+ sdkVersion: "2.0.23" || '',
501
640
  // 新sdk字段
502
641
  merchantId: (sdkQueryResult === null || sdkQueryResult === void 0 || (_sdkQueryResult$data = sdkQueryResult.data) === null || _sdkQueryResult$data === void 0 ? void 0 : _sdkQueryResult$data.merchantId) || '',
503
642
  // 新sdk字段
504
- env: this.options.environment === 'sandbox' ? 'sandbox' : 'prod',
643
+ env: lastEnv,
505
644
  // 新sdk字段,开发环境调试使用
506
645
  _requestConfig: _objectSpread({
507
- env: this.options.environment === 'sandbox' ? 'sandbox' : 'prod'
646
+ env: lastEnv
508
647
  }, getDevReqConfig())
509
648
  });
510
- case 26:
649
+ case 30:
511
650
  case "end":
512
- return _context2.stop();
651
+ return _context4.stop();
513
652
  }
514
- }, _callee2, this);
653
+ }, _callee4, this);
515
654
  }));
516
- function setup(_x3) {
655
+ function setup(_x8) {
517
656
  return _setup.apply(this, arguments);
518
657
  }
519
658
  return setup;
@@ -579,10 +718,10 @@ export var ModernElementController = /*#__PURE__*/function () {
579
718
  // 金额存在性校验
580
719
  var hasAmountViews = !!orderAmountView && !!paymentAmountView;
581
720
  if (!success) {
582
- var _ref2 = renderData,
583
- traceId = _ref2.traceId,
584
- errorCode = _ref2.errorCode,
585
- errorMessage = _ref2.errorMessage;
721
+ var _ref3 = renderData,
722
+ traceId = _ref3.traceId,
723
+ errorCode = _ref3.errorCode,
724
+ errorMessage = _ref3.errorMessage;
586
725
  return this.getLegacySdkQueryError({
587
726
  errorCode: errorCode,
588
727
  errorMessage: errorMessage,
@@ -610,13 +749,20 @@ export var ModernElementController = /*#__PURE__*/function () {
610
749
  }, {
611
750
  key: "bindBridgeEvents",
612
751
  value: function bindBridgeEvents() {
613
- var _this2 = this;
752
+ var _this3 = this;
614
753
  this.bridge.on(MessageType.HEIGHT_UPDATE, function (height) {
615
- if (_this2.iframe) _this2.iframe.style.height = "".concat(height, "px");
754
+ if (_this3.iframe) _this3.iframe.style.height = "".concat(height, "px");
755
+ });
756
+ this.bridge.on(AMSMessageType.SHOWTOAST, function (payload, _ports, meta) {
757
+ var _this3$iframe, _this3$modalIframe;
758
+ if (meta && meta.source !== ((_this3$iframe = _this3.iframe) === null || _this3$iframe === void 0 ? void 0 : _this3$iframe.contentWindow) && meta.source !== ((_this3$modalIframe = _this3.modalIframe) === null || _this3$modalIframe === void 0 ? void 0 : _this3$modalIframe.contentWindow)) {
759
+ return;
760
+ }
761
+ showToast(payload);
616
762
  });
617
763
  this.bridge.on(MessageType.REDIRECT, function (payload, _ports, meta) {
618
- var _this2$iframe, _this2$modalIframe;
619
- if (meta && meta.source !== ((_this2$iframe = _this2.iframe) === null || _this2$iframe === void 0 ? void 0 : _this2$iframe.contentWindow) && meta.source !== ((_this2$modalIframe = _this2.modalIframe) === null || _this2$modalIframe === void 0 ? void 0 : _this2$modalIframe.contentWindow)) {
764
+ var _this3$iframe2, _this3$modalIframe2;
765
+ if (meta && meta.source !== ((_this3$iframe2 = _this3.iframe) === null || _this3$iframe2 === void 0 ? void 0 : _this3$iframe2.contentWindow) && meta.source !== ((_this3$modalIframe2 = _this3.modalIframe) === null || _this3$modalIframe2 === void 0 ? void 0 : _this3$modalIframe2.contentWindow)) {
620
766
  return;
621
767
  }
622
768
  var url = payload.url,
@@ -634,7 +780,7 @@ export var ModernElementController = /*#__PURE__*/function () {
634
780
  d6: destroy ? '1' : '0'
635
781
  });
636
782
  if (destroy) {
637
- _this2.destroy();
783
+ _this3.destroy();
638
784
  }
639
785
  function fallbackJump() {
640
786
  if (mode === 'replace') {
@@ -672,34 +818,34 @@ export var ModernElementController = /*#__PURE__*/function () {
672
818
  }
673
819
  });
674
820
  this.bridge.on(MessageType.OPEN_MODAL, function (payload, _ports, meta) {
675
- var _this2$iframe2;
676
- if (meta && meta.source !== ((_this2$iframe2 = _this2.iframe) === null || _this2$iframe2 === void 0 ? void 0 : _this2$iframe2.contentWindow)) {
821
+ var _this3$iframe3;
822
+ if (meta && meta.source !== ((_this3$iframe3 = _this3.iframe) === null || _this3$iframe3 === void 0 ? void 0 : _this3$iframe3.contentWindow)) {
677
823
  return;
678
824
  }
679
- _this2.handleOpenModal(payload);
680
- _this2.bridge.once(MessageType.CLOSE_MODAL, function () {
681
- _this2.handleCloseModal();
825
+ _this3.handleOpenModal(payload);
826
+ _this3.bridge.once(MessageType.CLOSE_MODAL, function () {
827
+ _this3.handleCloseModal();
682
828
  });
683
829
  });
684
830
  this.bridge.on(MessageType.DESTROY_ELEMENT, function (_payload, _ports, meta) {
685
- var _this2$iframe3;
686
- if (meta && meta.source !== ((_this2$iframe3 = _this2.iframe) === null || _this2$iframe3 === void 0 ? void 0 : _this2$iframe3.contentWindow)) {
831
+ var _this3$iframe4;
832
+ if (meta && meta.source !== ((_this3$iframe4 = _this3.iframe) === null || _this3$iframe4 === void 0 ? void 0 : _this3$iframe4.contentWindow)) {
687
833
  return;
688
834
  }
689
- _this2.destroy();
835
+ _this3.destroy();
690
836
  });
691
837
 
692
838
  // skipRenderPaymentMethod 场景:webapp 委托 SDK 全权拉起 ApplePay,fire-and-forget
693
839
  // 走 plugin/applepay 标准链路(onEventCallback 自动通知商户)
694
840
  this.bridge.on(AMSMessageType.HANDLE_PAYMENT, function () {
695
- _this2.handleHandlePayment();
841
+ _this3.handleHandlePayment();
696
842
  });
697
843
 
698
844
  // Apple Pay beforeConfirm:在 submitPayment 内通过 bridge.once 监听,此处不再注册
699
845
 
700
846
  // 支付方式变化:iframe 通知 SDK 当前选中的支付方式类型
701
847
  this.bridge.on(AMSMessageType.PAYMENT_METHOD_CHANGED, function (payload) {
702
- _this2.currentPaymentMethodType = (payload === null || payload === void 0 ? void 0 : payload.type) || '';
848
+ _this3.currentPaymentMethodType = (payload === null || payload === void 0 ? void 0 : payload.type) || '';
703
849
  });
704
850
  }
705
851
 
@@ -711,12 +857,12 @@ export var ModernElementController = /*#__PURE__*/function () {
711
857
  }, {
712
858
  key: "handleGetApplePayToken",
713
859
  value: (function () {
714
- var _handleGetApplePayToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(payload, onBeforeConfirm) {
860
+ var _handleGetApplePayToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(payload, onBeforeConfirm) {
715
861
  var _paymentMethod,
716
- _this3 = this;
717
- var sessionData, applePayProps, paymentRequest, merchantCapabilities, merchantInfo, paymentAmount, supportedNetworks, version, requiredBillingContactFields, requiredShippingContactFields, finalAmount, finalCurrency, capturedResult, service, _capturedResult, errCode;
718
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
719
- while (1) switch (_context5.prev = _context5.next) {
862
+ _this4 = this;
863
+ var sessionData, applePayProps, paymentRequest, merchantCapabilities, merchantInfo, paymentAmount, supportedNetworks, version, requiredBillingContactFields, requiredShippingContactFields, finalAmount, finalCurrency, capturedResult, recurringRequest, service, _capturedResult, errCode;
864
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
865
+ while (1) switch (_context7.prev = _context7.next) {
720
866
  case 0:
721
867
  sessionData = this.options.sessionData;
722
868
  applePayProps = payload === null || payload === void 0 || (_paymentMethod = payload.paymentMethod) === null || _paymentMethod === void 0 || (_paymentMethod = _paymentMethod.paymentMethodDetail) === null || _paymentMethod === void 0 ? void 0 : _paymentMethod.applePayProps;
@@ -725,7 +871,7 @@ export var ModernElementController = /*#__PURE__*/function () {
725
871
  d1: paymentRequest ? 'has_payment_request' : 'no_payment_request'
726
872
  });
727
873
  if (paymentRequest) {
728
- _context5.next = 8;
874
+ _context7.next = 8;
729
875
  break;
730
876
  }
731
877
  trackError('applepay_token_missing_data', {
@@ -737,7 +883,7 @@ export var ModernElementController = /*#__PURE__*/function () {
737
883
  errorCode: 'APPLE_PAY_MISSING_DATA'
738
884
  }
739
885
  });
740
- return _context5.abrupt("return");
886
+ return _context7.abrupt("return");
741
887
  case 8:
742
888
  merchantCapabilities = paymentRequest.merchantCapabilities, merchantInfo = paymentRequest.merchantInfo, paymentAmount = paymentRequest.paymentAmount, supportedNetworks = paymentRequest.supportedNetworks, version = paymentRequest.version, requiredBillingContactFields = paymentRequest.requiredBillingContactFields, requiredShippingContactFields = paymentRequest.requiredShippingContactFields;
743
889
  finalAmount = (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.formattedValue) || (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value);
@@ -748,53 +894,67 @@ export var ModernElementController = /*#__PURE__*/function () {
748
894
  if (this._merchantCurrency) {
749
895
  finalCurrency = this._merchantCurrency;
750
896
  }
897
+ // 订阅场景:从 sessionData 提取 recurringInfo 构造 recurringPaymentRequest。
898
+ // 对齐老 ApplePaySdk 链路(parseData.paymentSessionFactor.recurringInfo)与
899
+ // Express 链路(applePayHostToken.ts),否则 Chrome 非 Safari 会降级为普通支付弹窗。
900
+ recurringRequest = buildRecurringPaymentRequest(sessionData, merchantInfo, {
901
+ value: finalAmount,
902
+ currency: finalCurrency
903
+ });
751
904
  service = new ApplePayHostService({
752
- paymentRequest: {
905
+ paymentRequest: _objectSpread({
753
906
  countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.countryCode,
754
907
  currencyCode: finalCurrency,
755
908
  merchantCapabilities: merchantCapabilities,
756
909
  supportedNetworks: supportedNetworks,
757
910
  requiredBillingContactFields: requiredBillingContactFields,
758
911
  requiredShippingContactFields: requiredShippingContactFields,
759
- total: {
912
+ total: recurringRequest ? {
913
+ type: 'final',
914
+ label: recurringRequest.regularBilling.label,
915
+ amount: finalAmount
916
+ } : {
760
917
  type: 'final',
761
918
  label: (merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName) || 'Payment',
762
919
  amount: finalAmount
763
920
  },
764
- version: version
765
- },
921
+ version: recurringRequest ? APPLE_PAY_RECURRING_VERSION : version
922
+ }, recurringRequest ? {
923
+ lineItems: [recurringRequest.regularBilling],
924
+ recurringPaymentRequest: recurringRequest
925
+ } : {}),
766
926
  enableModalCloseListener: true,
767
927
  callbacks: {
768
928
  validateMerchant: function () {
769
- var _validateMerchant = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(validationURL) {
929
+ var _validateMerchant = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(validationURL) {
770
930
  var res;
771
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
772
- while (1) switch (_context3.prev = _context3.next) {
931
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
932
+ while (1) switch (_context5.prev = _context5.next) {
773
933
  case 0:
774
934
  trackElement('applepay_validate_start', {
775
935
  d1: 'merchant_validate'
776
936
  });
777
- _context3.next = 3;
937
+ _context5.next = 3;
778
938
  return getApplePayPaymentSession(sessionData, {
779
939
  validateUrl: validationURL,
780
940
  paymentSessionData: sessionData,
781
941
  merchantDomain: window.location.hostname
782
942
  }, {
783
- env: _this3.options.environment,
943
+ env: _this4.options.environment,
784
944
  envInfo: {
785
945
  deviceId: ''
786
946
  }
787
947
  }, logger);
788
948
  case 3:
789
- res = _context3.sent;
949
+ res = _context5.sent;
790
950
  if (!(res !== null && res !== void 0 && res.success && res.merchantSessionObject)) {
791
- _context3.next = 7;
951
+ _context5.next = 7;
792
952
  break;
793
953
  }
794
954
  trackElement('applepay_validate_success', {
795
955
  d1: 'got_session'
796
956
  });
797
- return _context3.abrupt("return", typeof res.merchantSessionObject === 'string' ? JSON.parse(res.merchantSessionObject) : res.merchantSessionObject);
957
+ return _context5.abrupt("return", typeof res.merchantSessionObject === 'string' ? JSON.parse(res.merchantSessionObject) : res.merchantSessionObject);
798
958
  case 7:
799
959
  trackError('applepay_merchant_validate_failed', {
800
960
  d1: 'VALIDATION_FAILED',
@@ -805,34 +965,34 @@ export var ModernElementController = /*#__PURE__*/function () {
805
965
  };
806
966
  case 9:
807
967
  case "end":
808
- return _context3.stop();
968
+ return _context5.stop();
809
969
  }
810
- }, _callee3);
970
+ }, _callee5);
811
971
  }));
812
- function validateMerchant(_x6) {
972
+ function validateMerchant(_x11) {
813
973
  return _validateMerchant.apply(this, arguments);
814
974
  }
815
975
  return validateMerchant;
816
976
  }(),
817
977
  onAuthorized: function () {
818
- var _onAuthorized = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref3) {
978
+ var _onAuthorized = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref4) {
819
979
  var token, billingContact, shippingContact, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue;
820
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
821
- while (1) switch (_context4.prev = _context4.next) {
980
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
981
+ while (1) switch (_context6.prev = _context6.next) {
822
982
  case 0:
823
- token = _ref3.token, billingContact = _ref3.billingContact, shippingContact = _ref3.shippingContact;
983
+ token = _ref4.token, billingContact = _ref4.billingContact, shippingContact = _ref4.shippingContact;
824
984
  if (!onBeforeConfirm) {
825
- _context4.next = 18;
985
+ _context6.next = 18;
826
986
  break;
827
987
  }
828
- _context4.prev = 2;
988
+ _context6.prev = 2;
829
989
  startTime = Date.now();
830
- _context4.next = 6;
990
+ _context6.next = 6;
831
991
  return executeWithTimeout(function () {
832
992
  return onBeforeConfirm();
833
993
  });
834
994
  case 6:
835
- _yield$executeWithTim = _context4.sent;
995
+ _yield$executeWithTim = _context6.sent;
836
996
  rawResult = _yield$executeWithTim.result;
837
997
  timedOut = _yield$executeWithTim.timedOut;
838
998
  // 双重校验:timedOut(Promise race)+ startTime(实际时间差),与老 ElementController 对齐
@@ -843,20 +1003,20 @@ export var ModernElementController = /*#__PURE__*/function () {
843
1003
  });
844
1004
  }
845
1005
  if (shouldContinue) {
846
- _context4.next = 13;
1006
+ _context6.next = 13;
847
1007
  break;
848
1008
  }
849
- return _context4.abrupt("return", {
1009
+ return _context6.abrupt("return", {
850
1010
  success: false,
851
1011
  errorCode: 'MERCHANT_CONFIRM_ABORT'
852
1012
  });
853
1013
  case 13:
854
- _context4.next = 18;
1014
+ _context6.next = 18;
855
1015
  break;
856
1016
  case 15:
857
- _context4.prev = 15;
858
- _context4.t0 = _context4["catch"](2);
859
- return _context4.abrupt("return", {
1017
+ _context6.prev = 15;
1018
+ _context6.t0 = _context6["catch"](2);
1019
+ return _context6.abrupt("return", {
860
1020
  success: false,
861
1021
  errorCode: 'MERCHANT_CONFIRM_ABORT'
862
1022
  });
@@ -869,27 +1029,27 @@ export var ModernElementController = /*#__PURE__*/function () {
869
1029
  trackElement('applepay_authorized', {
870
1030
  d1: token ? 'has_token' : 'no_token'
871
1031
  });
872
- return _context4.abrupt("return", {
1032
+ return _context6.abrupt("return", {
873
1033
  success: true,
874
1034
  result: capturedResult
875
1035
  });
876
1036
  case 21:
877
1037
  case "end":
878
- return _context4.stop();
1038
+ return _context6.stop();
879
1039
  }
880
- }, _callee4, null, [[2, 15]]);
1040
+ }, _callee6, null, [[2, 15]]);
881
1041
  }));
882
- function onAuthorized(_x7) {
1042
+ function onAuthorized(_x12) {
883
1043
  return _onAuthorized.apply(this, arguments);
884
1044
  }
885
1045
  return onAuthorized;
886
1046
  }()
887
1047
  }
888
1048
  });
889
- _context5.prev = 14;
890
- _context5.next = 17;
1049
+ _context7.prev = 15;
1050
+ _context7.next = 18;
891
1051
  return service.startPay();
892
- case 17:
1052
+ case 18:
893
1053
  trackElement('applepay_token_success', {
894
1054
  d1: (_capturedResult = capturedResult) !== null && _capturedResult !== void 0 && _capturedResult.token ? 'has_token' : 'no_token'
895
1055
  });
@@ -897,14 +1057,14 @@ export var ModernElementController = /*#__PURE__*/function () {
897
1057
  success: true,
898
1058
  result: capturedResult
899
1059
  });
900
- _context5.next = 25;
1060
+ _context7.next = 26;
901
1061
  break;
902
- case 21:
903
- _context5.prev = 21;
904
- _context5.t0 = _context5["catch"](14);
1062
+ case 22:
1063
+ _context7.prev = 22;
1064
+ _context7.t0 = _context7["catch"](15);
905
1065
  // 商户验证失败已在 validateMerchant 内单独埋点(applepay_merchant_validate_failed),此处跳过避免重复
906
- if ((_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.errorCode) !== 'APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED') {
907
- errCode = (_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.errorCode) || 'APPLE_PAY_NOT_SUPPORTED'; // 用户主动取消单独标记,便于区分取消与真实失败
1066
+ if ((_context7.t0 === null || _context7.t0 === void 0 ? void 0 : _context7.t0.errorCode) !== 'APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED') {
1067
+ errCode = (_context7.t0 === null || _context7.t0 === void 0 ? void 0 : _context7.t0.errorCode) || 'APPLE_PAY_NOT_SUPPORTED'; // 用户主动取消单独标记,便于区分取消与真实失败
908
1068
  if (errCode === 'APPLE_PAY_CANCEL') {
909
1069
  trackElement('applepay_cancel', {
910
1070
  d1: 'user_cancel'
@@ -912,23 +1072,23 @@ export var ModernElementController = /*#__PURE__*/function () {
912
1072
  } else {
913
1073
  trackError('applepay_token_failed', {
914
1074
  d1: errCode,
915
- d2: (_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.errorMessage) || ''
1075
+ d2: (_context7.t0 === null || _context7.t0 === void 0 ? void 0 : _context7.t0.errorMessage) || ''
916
1076
  });
917
1077
  }
918
1078
  }
919
1079
  this.bridge.send(AMSMessageType.GET_APPLE_PAY_TOKEN_REPLY, {
920
1080
  success: false,
921
1081
  result: {
922
- errorCode: (_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.errorCode) || 'APPLE_PAY_NOT_SUPPORTED'
1082
+ errorCode: (_context7.t0 === null || _context7.t0 === void 0 ? void 0 : _context7.t0.errorCode) || 'APPLE_PAY_NOT_SUPPORTED'
923
1083
  }
924
1084
  });
925
- case 25:
1085
+ case 26:
926
1086
  case "end":
927
- return _context5.stop();
1087
+ return _context7.stop();
928
1088
  }
929
- }, _callee5, this, [[14, 21]]);
1089
+ }, _callee7, this, [[15, 22]]);
930
1090
  }));
931
- function handleGetApplePayToken(_x4, _x5) {
1091
+ function handleGetApplePayToken(_x9, _x10) {
932
1092
  return _handleGetApplePayToken.apply(this, arguments);
933
1093
  }
934
1094
  return handleGetApplePayToken;
@@ -953,7 +1113,7 @@ export var ModernElementController = /*#__PURE__*/function () {
953
1113
  key: "handleGetGooglePayToken",
954
1114
  value: function handleGetGooglePayToken(payload) {
955
1115
  var _data$paymentMethodDe,
956
- _this4 = this,
1116
+ _this5 = this,
957
1117
  _google;
958
1118
  var data = payload === null || payload === void 0 ? void 0 : payload.data;
959
1119
  var googlePayProps = data === null || data === void 0 || (_data$paymentMethodDe = data.paymentMethodDetail) === null || _data$paymentMethodDe === void 0 ? void 0 : _data$paymentMethodDe.googlePayProps;
@@ -1000,7 +1160,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1000
1160
  trackElement('googlepay_token_success', {
1001
1161
  d1: 'has_token'
1002
1162
  });
1003
- _this4.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1163
+ _this5.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1004
1164
  success: true,
1005
1165
  result: paymentData
1006
1166
  });
@@ -1017,7 +1177,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1017
1177
  d2: (err === null || err === void 0 ? void 0 : err.statusMessage) || ''
1018
1178
  });
1019
1179
  }
1020
- _this4.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1180
+ _this5.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1021
1181
  success: false,
1022
1182
  err: _objectSpread({
1023
1183
  statusCode: statusCode
@@ -1036,7 +1196,15 @@ export var ModernElementController = /*#__PURE__*/function () {
1036
1196
  var script = document.createElement('script');
1037
1197
  script.src = 'https://pay.google.com/gp/p/js/pay.js';
1038
1198
  script.async = true;
1039
- document.body.appendChild(script);
1199
+
1200
+ // 当判断条件成立时,代表 document.body.appendChild 方法已被劫持
1201
+ if (document.body.appendChild !== Node.prototype.appendChild) {
1202
+ // 使用原生 appendChild 避免微前端沙箱(如 qiankun)将动态 <script> 劫持为 fetch 加载,
1203
+ // 导致不支持 CORS 的第三方脚本(如 pay.google.com)加载失败
1204
+ Node.prototype.appendChild.call(document.body, script);
1205
+ } else {
1206
+ document.body.appendChild(script);
1207
+ }
1040
1208
  script.onload = function () {
1041
1209
  loadAndPay();
1042
1210
  };
@@ -1044,7 +1212,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1044
1212
  trackError('googlepay_script_load_failed', {
1045
1213
  d1: 'script_error'
1046
1214
  });
1047
- _this4.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1215
+ _this5.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1048
1216
  success: false,
1049
1217
  err: {
1050
1218
  statusCode: 'GOOGLE_PAY_NOT_SUPPORTED'
@@ -1093,7 +1261,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1093
1261
  }, {
1094
1262
  key: "handleBeforeConfirmInternal",
1095
1263
  value: function handleBeforeConfirmInternal(onBeforeConfirm) {
1096
- var _this5 = this;
1264
+ var _this6 = this;
1097
1265
  if (!onBeforeConfirm) {
1098
1266
  logger.logInfo({
1099
1267
  title: 'sdk_before_confirm_skip'
@@ -1114,9 +1282,9 @@ export var ModernElementController = /*#__PURE__*/function () {
1114
1282
  var startTime = Date.now();
1115
1283
  executeWithTimeout(function () {
1116
1284
  return onBeforeConfirm();
1117
- }).then(function (_ref4) {
1118
- var rawResult = _ref4.result,
1119
- timedOut = _ref4.timedOut;
1285
+ }).then(function (_ref5) {
1286
+ var rawResult = _ref5.result,
1287
+ timedOut = _ref5.timedOut;
1120
1288
  // 双重校验:timedOut(Promise race)+ startTime(实际时间差),与老 ElementController 对齐
1121
1289
  var shouldContinue = !timedOut && !!rawResult && Date.now() - startTime < BEFORE_CONFIRM_TIMEOUT_MS;
1122
1290
  if (timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
@@ -1129,7 +1297,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1129
1297
  }, {
1130
1298
  shouldContinue: shouldContinue
1131
1299
  });
1132
- _this5.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
1300
+ _this6.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
1133
1301
  success: true,
1134
1302
  result: !!shouldContinue
1135
1303
  });
@@ -1140,7 +1308,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1140
1308
  errorMessage: String((error === null || error === void 0 ? void 0 : error.message) || error).slice(0, 200),
1141
1309
  path: 'modernController_bridge'
1142
1310
  });
1143
- _this5.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
1311
+ _this6.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
1144
1312
  success: false,
1145
1313
  result: false
1146
1314
  });
@@ -1154,7 +1322,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1154
1322
  }, {
1155
1323
  key: "waitForReadyHandshake",
1156
1324
  value: function waitForReadyHandshake() {
1157
- var _this6 = this;
1325
+ var _this7 = this;
1158
1326
  return new Promise(function (resolve, reject) {
1159
1327
  var cancelDestroyCallback = function cancelDestroyCallback() {};
1160
1328
  var timer = setTimeout(function () {
@@ -1167,15 +1335,15 @@ export var ModernElementController = /*#__PURE__*/function () {
1167
1335
  message: 'An error occurred; the transaction cannot be initiated.'
1168
1336
  });
1169
1337
  }, MOUNT_TIMEOUT);
1170
- cancelDestroyCallback = _this6.onDestroy(function () {
1338
+ cancelDestroyCallback = _this7.onDestroy(function () {
1171
1339
  clearTimeout(timer);
1172
1340
  reject(getDestroyedError());
1173
1341
  });
1174
- _this6.bridge.once(MessageType.READY_HANDSHAKE, function () {
1175
- var _this6$iframe;
1342
+ _this7.bridge.once(MessageType.READY_HANDSHAKE, function () {
1343
+ var _this7$iframe;
1176
1344
  clearTimeout(timer);
1177
1345
  cancelDestroyCallback();
1178
- if (!((_this6$iframe = _this6.iframe) !== null && _this6$iframe !== void 0 && _this6$iframe.contentWindow)) {
1346
+ if (!((_this7$iframe = _this7.iframe) !== null && _this7$iframe !== void 0 && _this7$iframe.contentWindow)) {
1179
1347
  trackError('iframe_contentwindow_unavailable', {
1180
1348
  d1: 'after_ready_handshake'
1181
1349
  });
@@ -1185,9 +1353,9 @@ export var ModernElementController = /*#__PURE__*/function () {
1185
1353
  });
1186
1354
  return;
1187
1355
  }
1188
- _this6.bridge.setTarget(_this6.iframe.contentWindow);
1356
+ _this7.bridge.setTarget(_this7.iframe.contentWindow);
1189
1357
  trackHandshake('ready_handshake_received', {
1190
- m1: _this6._mountStartTime ? Date.now() - _this6._mountStartTime : 0
1358
+ m1: _this7._mountStartTime ? Date.now() - _this7._mountStartTime : 0
1191
1359
  });
1192
1360
  resolve();
1193
1361
  });
@@ -1212,7 +1380,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1212
1380
  }, {
1213
1381
  key: "waitForHandshakeAck",
1214
1382
  value: function waitForHandshakeAck() {
1215
- var _this7 = this;
1383
+ var _this8 = this;
1216
1384
  return new Promise(function (resolve, reject) {
1217
1385
  var cancelDestroyCallback = function cancelDestroyCallback() {};
1218
1386
  var timer = setTimeout(function () {
@@ -1225,15 +1393,15 @@ export var ModernElementController = /*#__PURE__*/function () {
1225
1393
  message: 'An error occurred; the transaction cannot be initiated.'
1226
1394
  });
1227
1395
  }, MOUNT_TIMEOUT);
1228
- cancelDestroyCallback = _this7.onDestroy(function () {
1396
+ cancelDestroyCallback = _this8.onDestroy(function () {
1229
1397
  clearTimeout(timer);
1230
1398
  reject(getDestroyedError());
1231
1399
  });
1232
- _this7.bridge.once(MessageType.HANDSHAKE_ACK, function () {
1400
+ _this8.bridge.once(MessageType.HANDSHAKE_ACK, function () {
1233
1401
  clearTimeout(timer);
1234
1402
  cancelDestroyCallback();
1235
1403
  trackHandshake('handshake_ack_received', {
1236
- m1: _this7._mountStartTime ? Date.now() - _this7._mountStartTime : 0
1404
+ m1: _this8._mountStartTime ? Date.now() - _this8._mountStartTime : 0
1237
1405
  });
1238
1406
  resolve();
1239
1407
  });
@@ -1242,20 +1410,46 @@ export var ModernElementController = /*#__PURE__*/function () {
1242
1410
  }, {
1243
1411
  key: "submitPayment",
1244
1412
  value: function () {
1245
- var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
1246
- var _this8 = this;
1247
- var _this$options$loading7, _this$options$loading8, isApplePay, _ref5, onBeforeConfirm, serializableParams, startTime, _yield$executeWithTim2, shouldContinue, timedOut, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, cleanups, _result$error, resultPromise, result, _this$options$loading9, _this$options$loading10;
1248
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1249
- while (1) switch (_context6.prev = _context6.next) {
1413
+ var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1414
+ var _this9 = this;
1415
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1416
+ while (1) switch (_context8.prev = _context8.next) {
1417
+ case 0:
1418
+ return _context8.abrupt("return", runApi('submitPayment', function () {
1419
+ return _this9.doSubmitPayment(params);
1420
+ }, function () {
1421
+ return _this9.currentPaymentMethodType ? {
1422
+ d4: _this9.currentPaymentMethodType
1423
+ } : {};
1424
+ }));
1425
+ case 1:
1426
+ case "end":
1427
+ return _context8.stop();
1428
+ }
1429
+ }, _callee8);
1430
+ }));
1431
+ function submitPayment(_x13) {
1432
+ return _submitPayment.apply(this, arguments);
1433
+ }
1434
+ return submitPayment;
1435
+ }()
1436
+ }, {
1437
+ key: "doSubmitPayment",
1438
+ value: function () {
1439
+ var _doSubmitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
1440
+ var _this10 = this;
1441
+ var _this$options$loading7, _this$options$loading8, isApplePay, _ref6, onBeforeConfirm, serializableParams, startTime, _yield$executeWithTim2, shouldContinue, timedOut, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, cleanups, _result$error5, resultPromise, result, _this$options$loading9, _this$options$loading10;
1442
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1443
+ while (1) switch (_context9.prev = _context9.next) {
1250
1444
  case 0:
1251
1445
  if (!(this.status !== 'ready')) {
1252
- _context6.next = 3;
1446
+ _context9.next = 3;
1253
1447
  break;
1254
1448
  }
1255
1449
  trackError('submit_not_ready', {
1256
1450
  d1: this.status
1257
1451
  });
1258
- return _context6.abrupt("return", {
1452
+ return _context9.abrupt("return", {
1259
1453
  status: 'FAIL',
1260
1454
  error: {
1261
1455
  code: 'UI_STATE_ERROR',
@@ -1264,11 +1458,11 @@ export var ModernElementController = /*#__PURE__*/function () {
1264
1458
  });
1265
1459
  case 3:
1266
1460
  if (!this.isSubmitting) {
1267
- _context6.next = 6;
1461
+ _context9.next = 6;
1268
1462
  break;
1269
1463
  }
1270
1464
  trackError('submit_in_progress', {});
1271
- return _context6.abrupt("return", {
1465
+ return _context9.abrupt("return", {
1272
1466
  status: 'FAIL',
1273
1467
  error: {
1274
1468
  code: 'UI_STATE_ERROR',
@@ -1277,11 +1471,11 @@ export var ModernElementController = /*#__PURE__*/function () {
1277
1471
  });
1278
1472
  case 6:
1279
1473
  this.isSubmitting = true;
1280
- _context6.prev = 7;
1474
+ _context9.prev = 7;
1281
1475
  isApplePay = this.currentPaymentMethodType === 'APPLEPAY'; // 剥除 onBeforeConfirm 函数,避免 postMessage 序列化报错
1282
- _ref5 = params || {}, onBeforeConfirm = _ref5.onBeforeConfirm, serializableParams = _objectWithoutProperties(_ref5, _excluded2); // ── 非 Apple Pay:同步执行 onBeforeConfirm(submit 前拦截,对齐老 ElementController) ──
1476
+ _ref6 = params || {}, onBeforeConfirm = _ref6.onBeforeConfirm, serializableParams = _objectWithoutProperties(_ref6, _excluded2); // ── 非 Apple Pay:同步执行 onBeforeConfirm(submit 前拦截,对齐老 ElementController) ──
1283
1477
  if (!(onBeforeConfirm && !isApplePay)) {
1284
- _context6.next = 31;
1478
+ _context9.next = 31;
1285
1479
  break;
1286
1480
  }
1287
1481
  logger.logInfo({
@@ -1290,18 +1484,18 @@ export var ModernElementController = /*#__PURE__*/function () {
1290
1484
  paymentMethodType: this.currentPaymentMethodType || 'UNKNOWN',
1291
1485
  path: 'nonApplePay_sync'
1292
1486
  });
1293
- _context6.prev = 12;
1487
+ _context9.prev = 12;
1294
1488
  startTime = Date.now();
1295
- _context6.next = 16;
1489
+ _context9.next = 16;
1296
1490
  return executeWithTimeout(function () {
1297
1491
  return onBeforeConfirm();
1298
1492
  });
1299
1493
  case 16:
1300
- _yield$executeWithTim2 = _context6.sent;
1494
+ _yield$executeWithTim2 = _context9.sent;
1301
1495
  shouldContinue = _yield$executeWithTim2.result;
1302
1496
  timedOut = _yield$executeWithTim2.timedOut;
1303
1497
  if (!(timedOut || !shouldContinue || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS)) {
1304
- _context6.next = 22;
1498
+ _context9.next = 22;
1305
1499
  break;
1306
1500
  }
1307
1501
  if (timedOut) {
@@ -1319,7 +1513,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1319
1513
  path: 'nonApplePay_sync'
1320
1514
  });
1321
1515
  }
1322
- return _context6.abrupt("return", {
1516
+ return _context9.abrupt("return", {
1323
1517
  status: 'FAIL',
1324
1518
  error: {
1325
1519
  code: 'MERCHANT_CONFIRM_ABORT',
@@ -1333,19 +1527,19 @@ export var ModernElementController = /*#__PURE__*/function () {
1333
1527
  paymentMethodType: this.currentPaymentMethodType || 'UNKNOWN',
1334
1528
  path: 'nonApplePay_sync'
1335
1529
  });
1336
- _context6.next = 29;
1530
+ _context9.next = 29;
1337
1531
  break;
1338
1532
  case 25:
1339
- _context6.prev = 25;
1340
- _context6.t0 = _context6["catch"](12);
1533
+ _context9.prev = 25;
1534
+ _context9.t0 = _context9["catch"](12);
1341
1535
  logger.logError({
1342
1536
  title: 'sdk_before_confirm_error'
1343
1537
  }, {
1344
1538
  paymentMethodType: this.currentPaymentMethodType || 'UNKNOWN',
1345
- errorMessage: String((_context6.t0 === null || _context6.t0 === void 0 ? void 0 : _context6.t0.message) || _context6.t0).slice(0, 200),
1539
+ errorMessage: String((_context9.t0 === null || _context9.t0 === void 0 ? void 0 : _context9.t0.message) || _context9.t0).slice(0, 200),
1346
1540
  path: 'nonApplePay_sync'
1347
1541
  });
1348
- return _context6.abrupt("return", {
1542
+ return _context9.abrupt("return", {
1349
1543
  status: 'FAIL',
1350
1544
  error: {
1351
1545
  code: 'MERCHANT_CONFIRM_ABORT',
@@ -1353,7 +1547,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1353
1547
  }
1354
1548
  });
1355
1549
  case 29:
1356
- _context6.next = 32;
1550
+ _context9.next = 32;
1357
1551
  break;
1358
1552
  case 31:
1359
1553
  if (!onBeforeConfirm) {
@@ -1388,24 +1582,24 @@ export var ModernElementController = /*#__PURE__*/function () {
1388
1582
  // 未命中的 once wrapper 绑着旧闭包(旧 onBeforeConfirm / 旧 resolve)会残留并串扰后续提交,
1389
1583
  // 在 submit 终态统一释放(二次 off 幂等,已命中的 once 已自行 off)。
1390
1584
  cleanups = [];
1391
- _context6.prev = 41;
1585
+ _context9.prev = 41;
1392
1586
  resultPromise = new Promise(function (resolve) {
1393
1587
  // 先注册事件监听,再发送 SUBMIT,避免 webapp 快速响应导致消息丢失
1394
1588
  // PC 非 Safari:webapp 委托 SDK 拉起 Apple Pay 拿 token
1395
- cleanups.push(_this8.bridge.once(AMSMessageType.GET_APPLE_PAY_TOKEN, function (payload) {
1396
- _this8.handleGetApplePayToken(payload, onBeforeConfirm).then(function () {
1589
+ cleanups.push(_this10.bridge.once(AMSMessageType.GET_APPLE_PAY_TOKEN, function (payload) {
1590
+ _this10.handleGetApplePayToken(payload, onBeforeConfirm).then(function () {
1397
1591
  // token 已回传 webapp,继续等 SUBMIT_REPLY
1398
1592
  });
1399
1593
  }));
1400
1594
  // Web element GP:webapp 委托 SDK/父 frame 调 loadPaymentData 拿 token
1401
- cleanups.push(_this8.bridge.once(AMSMessageType.GET_GOOGLE_PAY_TOKEN, function (payload) {
1402
- _this8.handleGetGooglePayToken(payload);
1595
+ cleanups.push(_this10.bridge.once(AMSMessageType.GET_GOOGLE_PAY_TOKEN, function (payload) {
1596
+ _this10.handleGetGooglePayToken(payload);
1403
1597
  }));
1404
1598
  // Safari:webapp 请求执行商户 onBeforeConfirm 回调
1405
- cleanups.push(_this8.bridge.once(AMSMessageType.BEFORE_CONFIRM, function () {
1406
- _this8.handleBeforeConfirmInternal(onBeforeConfirm || null);
1599
+ cleanups.push(_this10.bridge.once(AMSMessageType.BEFORE_CONFIRM, function () {
1600
+ _this10.handleBeforeConfirmInternal(onBeforeConfirm || null);
1407
1601
  }));
1408
- cleanups.push(_this8.bridge.once(MessageType.SUBMIT_REPLY, resolve));
1602
+ cleanups.push(_this10.bridge.once(MessageType.SUBMIT_REPLY, resolve));
1409
1603
  }); // 监听注册完成后再发送 SUBMIT,确保不会遗漏快速响应
1410
1604
  this.send(MessageType.SUBMIT, _objectSpread(_objectSpread({}, serializableParams), {}, {
1411
1605
  redirect: this.notRedirectAfterComplete ? 'if_required' : 'always',
@@ -1414,70 +1608,92 @@ export var ModernElementController = /*#__PURE__*/function () {
1414
1608
  amount: serializableParams.amount,
1415
1609
  currency: serializableParams.currency
1416
1610
  } : {}));
1417
- _context6.next = 46;
1611
+ _context9.next = 46;
1418
1612
  return resultPromise;
1419
1613
  case 46:
1420
- result = _context6.sent;
1614
+ result = _context9.sent;
1421
1615
  trackElement('submit_reply', {
1422
1616
  d1: (result === null || result === void 0 ? void 0 : result.status) || '',
1423
- d2: (result === null || result === void 0 || (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.code) || ''
1617
+ d2: (result === null || result === void 0 || (_result$error5 = result.error) === null || _result$error5 === void 0 ? void 0 : _result$error5.code) || ''
1424
1618
  });
1425
- return _context6.abrupt("return", adaptSubmitResult(result));
1619
+ return _context9.abrupt("return", adaptSubmitResult(result));
1426
1620
  case 51:
1427
- _context6.prev = 51;
1428
- _context6.t1 = _context6["catch"](41);
1621
+ _context9.prev = 51;
1622
+ _context9.t1 = _context9["catch"](41);
1429
1623
  trackError('submit_error', {
1430
- d1: (_context6.t1 === null || _context6.t1 === void 0 ? void 0 : _context6.t1.code) || 'UNKNOWN',
1431
- d2: (_context6.t1 === null || _context6.t1 === void 0 ? void 0 : _context6.t1.message) || ''
1624
+ d1: (_context9.t1 === null || _context9.t1 === void 0 ? void 0 : _context9.t1.code) || 'UNKNOWN',
1625
+ d2: (_context9.t1 === null || _context9.t1 === void 0 ? void 0 : _context9.t1.message) || ''
1432
1626
  });
1433
- throw _context6.t1;
1627
+ throw _context9.t1;
1434
1628
  case 55:
1435
- _context6.prev = 55;
1629
+ _context9.prev = 55;
1436
1630
  cleanups.forEach(function (fn) {
1437
1631
  try {
1438
1632
  fn();
1439
- } catch (_unused4) {
1633
+ } catch (_unused6) {
1440
1634
  /* ignore cleanup error */
1441
1635
  }
1442
1636
  });
1443
1637
  (_this$options$loading9 = this.options.loading) === null || _this$options$loading9 === void 0 || (_this$options$loading10 = _this$options$loading9.onEndLoading) === null || _this$options$loading10 === void 0 || _this$options$loading10.call(_this$options$loading9);
1444
- return _context6.finish(55);
1638
+ return _context9.finish(55);
1445
1639
  case 59:
1446
- _context6.prev = 59;
1640
+ _context9.prev = 59;
1447
1641
  this.isSubmitting = false;
1448
- return _context6.finish(59);
1642
+ return _context9.finish(59);
1449
1643
  case 62:
1450
1644
  case "end":
1451
- return _context6.stop();
1645
+ return _context9.stop();
1452
1646
  }
1453
- }, _callee6, this, [[7,, 59, 62], [12, 25], [41, 51, 55, 59]]);
1647
+ }, _callee9, this, [[7,, 59, 62], [12, 25], [41, 51, 55, 59]]);
1454
1648
  }));
1455
- function submitPayment(_x8) {
1456
- return _submitPayment.apply(this, arguments);
1649
+ function doSubmitPayment(_x14) {
1650
+ return _doSubmitPayment.apply(this, arguments);
1457
1651
  }
1458
- return submitPayment;
1652
+ return doSubmitPayment;
1459
1653
  }()
1460
1654
  }, {
1461
1655
  key: "validateFields",
1462
1656
  value: function () {
1463
- var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1464
- var _this9 = this;
1465
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1466
- while (1) switch (_context7.prev = _context7.next) {
1657
+ var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1658
+ var _this11 = this;
1659
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1660
+ while (1) switch (_context10.prev = _context10.next) {
1661
+ case 0:
1662
+ return _context10.abrupt("return", runApi('validateFields', function () {
1663
+ return _this11.doValidateFields();
1664
+ }));
1665
+ case 1:
1666
+ case "end":
1667
+ return _context10.stop();
1668
+ }
1669
+ }, _callee10);
1670
+ }));
1671
+ function validateFields() {
1672
+ return _validateFields.apply(this, arguments);
1673
+ }
1674
+ return validateFields;
1675
+ }()
1676
+ }, {
1677
+ key: "doValidateFields",
1678
+ value: function () {
1679
+ var _doValidateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1680
+ var _this12 = this;
1681
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1682
+ while (1) switch (_context11.prev = _context11.next) {
1467
1683
  case 0:
1468
1684
  if (!(this.status !== 'ready')) {
1469
- _context7.next = 3;
1685
+ _context11.next = 3;
1470
1686
  break;
1471
1687
  }
1472
1688
  trackError('validate_not_ready', {
1473
1689
  d1: this.status
1474
1690
  });
1475
- return _context7.abrupt("return", {
1691
+ return _context11.abrupt("return", {
1476
1692
  isValid: false
1477
1693
  });
1478
1694
  case 3:
1479
1695
  this.send(AMSMessageType.VALIDATE);
1480
- return _context7.abrupt("return", new Promise(function (resolve) {
1696
+ return _context11.abrupt("return", new Promise(function (resolve) {
1481
1697
  var timer = setTimeout(function () {
1482
1698
  trackError('validate_fields_timeout', {
1483
1699
  d1: '15000'
@@ -1486,7 +1702,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1486
1702
  isValid: false
1487
1703
  });
1488
1704
  }, 15000);
1489
- _this9.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
1705
+ _this12.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
1490
1706
  clearTimeout(timer);
1491
1707
  var isValid = !!(payload !== null && payload !== void 0 && payload.isValid);
1492
1708
  trackElement('validate_result', {
@@ -1499,30 +1715,30 @@ export var ModernElementController = /*#__PURE__*/function () {
1499
1715
  }));
1500
1716
  case 5:
1501
1717
  case "end":
1502
- return _context7.stop();
1718
+ return _context11.stop();
1503
1719
  }
1504
- }, _callee7, this);
1720
+ }, _callee11, this);
1505
1721
  }));
1506
- function validateFields() {
1507
- return _validateFields.apply(this, arguments);
1722
+ function doValidateFields() {
1723
+ return _doValidateFields.apply(this, arguments);
1508
1724
  }
1509
- return validateFields;
1725
+ return doValidateFields;
1510
1726
  }() // eslint-disable-next-line @typescript-eslint/no-unused-vars
1511
1727
  }, {
1512
1728
  key: "updatePayment",
1513
1729
  value: function () {
1514
- var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(paymentSessionData) {
1515
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1516
- while (1) switch (_context8.prev = _context8.next) {
1730
+ var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(paymentSessionData) {
1731
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1732
+ while (1) switch (_context12.prev = _context12.next) {
1517
1733
  case 0:
1518
- return _context8.abrupt("return", false);
1734
+ return _context12.abrupt("return", false);
1519
1735
  case 1:
1520
1736
  case "end":
1521
- return _context8.stop();
1737
+ return _context12.stop();
1522
1738
  }
1523
- }, _callee8);
1739
+ }, _callee12);
1524
1740
  }));
1525
- function updatePayment(_x9) {
1741
+ function updatePayment(_x15) {
1526
1742
  return _updatePayment.apply(this, arguments);
1527
1743
  }
1528
1744
  return updatePayment;
@@ -1572,7 +1788,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1572
1788
  }, {
1573
1789
  key: "onDestroy",
1574
1790
  value: function onDestroy(callback) {
1575
- var _this10 = this;
1791
+ var _this13 = this;
1576
1792
  if (this.status === 'destroyed') {
1577
1793
  callback();
1578
1794
  return function () {
@@ -1581,7 +1797,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1581
1797
  }
1582
1798
  this.destroyCallbacks.push(callback);
1583
1799
  return function () {
1584
- _this10.destroyCallbacks = _this10.destroyCallbacks.filter(function (item) {
1800
+ _this13.destroyCallbacks = _this13.destroyCallbacks.filter(function (item) {
1585
1801
  return item !== callback;
1586
1802
  });
1587
1803
  };
@@ -1621,12 +1837,12 @@ export var ModernElementController = /*#__PURE__*/function () {
1621
1837
  }, {
1622
1838
  key: "flushCachedMessages",
1623
1839
  value: function flushCachedMessages() {
1624
- var _this11 = this;
1840
+ var _this14 = this;
1625
1841
  if (this.cachedSend.length > 0) {
1626
- this.cachedSend.forEach(function (_ref6) {
1627
- var type = _ref6.type,
1628
- payload = _ref6.payload;
1629
- _this11.bridge.send(type, payload);
1842
+ this.cachedSend.forEach(function (_ref7) {
1843
+ var type = _ref7.type,
1844
+ payload = _ref7.payload;
1845
+ _this14.bridge.send(type, payload);
1630
1846
  });
1631
1847
  this.cachedSend = [];
1632
1848
  }
@@ -1649,7 +1865,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1649
1865
  var _payload$appearance,
1650
1866
  _themeColorMap$appear,
1651
1867
  _payload$appearance2,
1652
- _this12 = this;
1868
+ _this15 = this;
1653
1869
  // 清理已存在的 modal
1654
1870
  this.handleCloseModal();
1655
1871
  var mode = device.isMobile ? 'mobile' : 'desktop';
@@ -1692,17 +1908,18 @@ export var ModernElementController = /*#__PURE__*/function () {
1692
1908
  var _openModal = openModal(_objectSpread(_objectSpread({}, payload), {}, {
1693
1909
  mode: mode,
1694
1910
  loadingConfig: loadingConfig,
1695
- onClose: payload.closeConfirm ? function () {
1696
- return new Promise(function (resolve) {
1697
- // closeConfirm 时等待确认关闭(由 CLOSE_MODAL 消息触发 resolve)
1698
- _this12._closeConfirmResolve = resolve;
1699
- });
1700
- } : undefined
1911
+ onClose: function onClose() {
1912
+ if (payload.closeConfirm) {
1913
+ // 这里提前关闭了
1914
+ var modalPort = new ModalPort(payload.modalId, messageChannel.port2);
1915
+ return modalPort.close(true);
1916
+ }
1917
+ }
1701
1918
  })),
1702
1919
  iframe = _openModal.iframe,
1703
1920
  destroy = _openModal.destroy;
1704
- var handler = function handler() {
1705
- iframe.removeEventListener('load', handler);
1921
+ var offReady = modalBridge.once(MessageType.MODAL_TRANSFER_READY, function (_payload, _ports, meta) {
1922
+ if (meta && meta.source !== iframe.contentWindow) return;
1706
1923
  trackElement('modal_loaded', {
1707
1924
  d1: payload.url
1708
1925
  });
@@ -1714,7 +1931,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1714
1931
  if (iframeOrigin && iframeOrigin !== 'null') {
1715
1932
  modalBridge.setOrigin(iframeOrigin);
1716
1933
  }
1717
- } catch (_unused5) {
1934
+ } catch (_unused7) {
1718
1935
  // URL 解析失败时保持默认 origin
1719
1936
  }
1720
1937
  // 如果 payload 有 appearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送给 modal
@@ -1728,16 +1945,18 @@ export var ModernElementController = /*#__PURE__*/function () {
1728
1945
  // 发送 port2 给 modal
1729
1946
  modalBridge.send(MessageType.TRANSFER_MODAL_PORT, payload.modalId, [messageChannel.port2]);
1730
1947
  }
1731
- };
1948
+ });
1732
1949
  this.modalIframe = iframe;
1733
1950
  this.modalDestroy = function () {
1951
+ if (payload.closeConfirm) {
1952
+ trackElement('modal_close_confirm', {
1953
+ d1: 'confirm_resolved'
1954
+ });
1955
+ }
1734
1956
  destroy();
1735
- iframe.removeEventListener('load', handler);
1736
- _this12.modalIframe = null;
1957
+ offReady();
1958
+ _this15.modalIframe = null;
1737
1959
  };
1738
-
1739
- // 监听 modal 的 iframe load 事件
1740
- iframe.addEventListener('load', handler);
1741
1960
  }
1742
1961
 
1743
1962
  /**
@@ -1747,13 +1966,6 @@ export var ModernElementController = /*#__PURE__*/function () {
1747
1966
  key: "handleCloseModal",
1748
1967
  value: function handleCloseModal() {
1749
1968
  // 如果有等待中的 closeConfirm,resolve 它
1750
- if (this._closeConfirmResolve) {
1751
- trackElement('modal_close_confirm', {
1752
- d1: 'confirm_resolved'
1753
- });
1754
- this._closeConfirmResolve();
1755
- this._closeConfirmResolve = null;
1756
- }
1757
1969
  trackElement('modal_closed', {
1758
1970
  d1: this.modalBridge ? 'with_bridge' : 'no_bridge'
1759
1971
  });