@alipay/ams-checkout 2.0.27 → 2.0.28

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.
@@ -33,7 +33,7 @@ import { ERRORMESSAGE, PROMISE_CALLBACK_CODE } from "../../../../constant";
33
33
  import { BusManager, BusMessage } from "../../../bus";
34
34
  import { ApplePayActionEnum } from "../../../bus/interface";
35
35
  import { shouldQueryOneAccount } from "../../../utils/connectConfig";
36
- import { ApplePayHostService, awaitWrap, buildPageUrl, buildRecurringPaymentRequest, checkSessionData, debug, debugError, getDevReqConfig, getLocaleFromRenderData, getMetaData, MessageType, ModalPort, oneAccountQuery, openModal, OpenSDKError, parseHostSign, parseTrackerId, request, SDKBridge, sdkQuery, sdkTracker, showToast, themeColorMap } from "../../../../modern/tools";
36
+ import { ApplePayHostService, awaitWrap, buildPageUrl, buildRecurringPaymentRequest, checkSessionData, debug, debugError, getDevReqConfig, getLocaleFromRenderData, getModalMessageTrackData, getMetaData, installModalMessageMonitor, MessageType, ModalPort, oneAccountQuery, openModal, OpenSDKError, parseHostSign, parseTrackerId, request, SDKBridge, sdkQuery, sdkTracker, showToast, themeColorMap } from "../../../../modern/tools";
37
37
  import { getApplePayPaymentSession } from "../../../../service";
38
38
  import { device } from "../../../../util";
39
39
  import { BEFORE_CONFIRM_TIMEOUT_MS, executeWithTimeout, MERCHANT_CONFIRM_ABORT_CODE, MERCHANT_CONFIRM_TIMEOUT_CODE } from "../../../../util/beforeConfirm";
@@ -269,6 +269,7 @@ var AMSMessageType = {
269
269
  */
270
270
  export var ModernElementController = /*#__PURE__*/function () {
271
271
  function ModernElementController(_ref2) {
272
+ var _this = this;
272
273
  var onStatusChange = _ref2.onStatusChange,
273
274
  options = _objectWithoutProperties(_ref2, _excluded);
274
275
  _classCallCheck(this, ModernElementController);
@@ -293,6 +294,8 @@ export var ModernElementController = /*#__PURE__*/function () {
293
294
  _defineProperty(this, "_merchantCurrency", null);
294
295
  /** 当前选中的支付方式类型(如 'APPLEPAY', 'CARD'),通过 paymentMethodChanged 事件更新 */
295
296
  _defineProperty(this, "currentPaymentMethodType", '');
297
+ /** Removes the passive host-window modal monitor for this controller. */
298
+ _defineProperty(this, "stopModalMessageMonitor", void 0);
296
299
  /** 提交进行中标志:submitPayment 执行期间为 true,用于拒绝并发重入,避免旧闭包串扰/重复拉起钱包 */
297
300
  _defineProperty(this, "isSubmitting", false);
298
301
  /**
@@ -320,6 +323,12 @@ export var ModernElementController = /*#__PURE__*/function () {
320
323
  debug('INFO', direction === 'OUT' ? 'SDK_INTERNAL' : 'APP_RUNTIME', msg.type, msg.payload);
321
324
  }
322
325
  });
326
+ this.stopModalMessageMonitor = installModalMessageMonitor(function (data) {
327
+ return _this.trackElement('modal_lifecycle_monitor', getModalMessageTrackData(data));
328
+ }, function (event) {
329
+ var _this$iframe;
330
+ return event.source === ((_this$iframe = _this.iframe) === null || _this$iframe === void 0 ? void 0 : _this$iframe.contentWindow);
331
+ });
323
332
  }
324
333
  _createClass(ModernElementController, [{
325
334
  key: "track",
@@ -366,7 +375,7 @@ export var ModernElementController = /*#__PURE__*/function () {
366
375
  key: "mount",
367
376
  value: function () {
368
377
  var _mount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderOptions, sdkSelector) {
369
- var _this = this;
378
+ var _this2 = this;
370
379
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
371
380
  while (1) switch (_context2.prev = _context2.next) {
372
381
  case 0:
@@ -380,7 +389,7 @@ export var ModernElementController = /*#__PURE__*/function () {
380
389
  /* setup 校验异常会统一上报 */
381
390
  }
382
391
  return _context2.abrupt("return", runApi('mount', function () {
383
- return _this.doMount(renderOptions, sdkSelector);
392
+ return _this2.doMount(renderOptions, sdkSelector);
384
393
  }, undefined, normalizeApiInput('mount', {
385
394
  renderOptions: renderOptions,
386
395
  sdkSelector: sdkSelector
@@ -558,7 +567,7 @@ export var ModernElementController = /*#__PURE__*/function () {
558
567
  value: (function () {
559
568
  var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(renderOptions) {
560
569
  var _parseData$connectFac,
561
- _this2 = this,
570
+ _this3 = this,
562
571
  _parseData$paymentMet,
563
572
  _sdkQueryResult$data;
564
573
  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;
@@ -582,7 +591,7 @@ export var ModernElementController = /*#__PURE__*/function () {
582
591
  hostSign: parseHostSign(sessionData),
583
592
  env: lastEnv
584
593
  }, getDevReqConfig()), {}, {
585
- sdkVersion: "2.0.27" || '',
594
+ sdkVersion: "2.0.28" || '',
586
595
  tracker: sdkTracker
587
596
  }));
588
597
  isConnect = !!(parseData !== null && parseData !== void 0 && (_parseData$connectFac = parseData.connectFactor) !== null && _parseData$connectFac !== void 0 && _parseData$connectFac.enableConnect);
@@ -595,14 +604,14 @@ export var ModernElementController = /*#__PURE__*/function () {
595
604
  isUserPreferredLocale: true
596
605
  },
597
606
  merchantAppointParam: (_renderOptions$mercha = renderOptions.merchantAppointParam) !== null && _renderOptions$mercha !== void 0 && _renderOptions$mercha.storedCard ? renderOptions.merchantAppointParam : undefined,
598
- notRedirectAfterComplete: _this2.notRedirectAfterComplete,
607
+ notRedirectAfterComplete: _this3.notRedirectAfterComplete,
599
608
  // sdk需要传入该字段
600
609
  paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
601
610
  paymentSessionData: sessionData
602
611
  }, {
603
612
  // 传商户初始化的 locale,服务端据此返回对应语言(缺失则回落用户偏好/en_US)
604
613
  envInfo: {
605
- locale: _this2.options.locale
614
+ locale: _this3.options.locale
606
615
  }
607
616
  }).catch(recoverSdkQueryBusinessResponse));
608
617
  };
@@ -618,7 +627,7 @@ export var ModernElementController = /*#__PURE__*/function () {
618
627
  promises = shouldQueryOneAccountFlag ? [genSdkQueryPromise(), genOneAccountQueryPromise()] : [genSdkQueryPromise(), undefined];
619
628
  cancelDestroyCallback = function cancelDestroyCallback() {};
620
629
  destroyPromise = new Promise(function (_, reject) {
621
- cancelDestroyCallback = _this2.onDestroy(function () {
630
+ cancelDestroyCallback = _this3.onDestroy(function () {
622
631
  return reject(getDestroyedError());
623
632
  });
624
633
  });
@@ -680,7 +689,7 @@ export var ModernElementController = /*#__PURE__*/function () {
680
689
  // 新sdk字段
681
690
  locale: locale,
682
691
  // 新sdk字段
683
- sdkVersion: "2.0.27" || '',
692
+ sdkVersion: "2.0.28" || '',
684
693
  // 新sdk字段
685
694
  merchantId: (sdkQueryResult === null || sdkQueryResult === void 0 || (_sdkQueryResult$data = sdkQueryResult.data) === null || _sdkQueryResult$data === void 0 ? void 0 : _sdkQueryResult$data.merchantId) || '',
686
695
  // 新sdk字段
@@ -793,20 +802,20 @@ export var ModernElementController = /*#__PURE__*/function () {
793
802
  }, {
794
803
  key: "bindBridgeEvents",
795
804
  value: function bindBridgeEvents() {
796
- var _this3 = this;
805
+ var _this4 = this;
797
806
  this.bridge.on(MessageType.HEIGHT_UPDATE, function (height) {
798
- if (_this3.iframe) _this3.iframe.style.height = "".concat(height, "px");
807
+ if (_this4.iframe) _this4.iframe.style.height = "".concat(height, "px");
799
808
  });
800
809
  this.bridge.on(AMSMessageType.SHOWTOAST, function (payload, _ports, meta) {
801
- var _this3$iframe, _this3$modalIframe;
802
- 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)) {
810
+ var _this4$iframe, _this4$modalIframe;
811
+ if (meta && meta.source !== ((_this4$iframe = _this4.iframe) === null || _this4$iframe === void 0 ? void 0 : _this4$iframe.contentWindow) && meta.source !== ((_this4$modalIframe = _this4.modalIframe) === null || _this4$modalIframe === void 0 ? void 0 : _this4$modalIframe.contentWindow)) {
803
812
  return;
804
813
  }
805
814
  showToast(payload);
806
815
  });
807
816
  this.bridge.on(MessageType.REDIRECT, function (payload, _ports, meta) {
808
- var _this3$iframe2, _this3$modalIframe2;
809
- 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)) {
817
+ var _this4$iframe2, _this4$modalIframe2;
818
+ if (meta && meta.source !== ((_this4$iframe2 = _this4.iframe) === null || _this4$iframe2 === void 0 ? void 0 : _this4$iframe2.contentWindow) && meta.source !== ((_this4$modalIframe2 = _this4.modalIframe) === null || _this4$modalIframe2 === void 0 ? void 0 : _this4$modalIframe2.contentWindow)) {
810
819
  return;
811
820
  }
812
821
  var url = payload.url,
@@ -815,7 +824,7 @@ export var ModernElementController = /*#__PURE__*/function () {
815
824
  schemaUrl = payload.schemaUrl,
816
825
  destroy = payload.destroy;
817
826
  // d1=mode(redirect/replace) d2=跳转类型 d3=兜底url d4=appLinkUrl d5=schemaUrl d6=是否销毁
818
- _this3.trackElement('redirect', {
827
+ _this4.trackElement('redirect', {
819
828
  d1: mode || 'redirect',
820
829
  d2: appLinkUrl ? 'app_link' : schemaUrl ? 'schema' : 'url',
821
830
  d3: url || '',
@@ -824,7 +833,7 @@ export var ModernElementController = /*#__PURE__*/function () {
824
833
  d6: destroy ? '1' : '0'
825
834
  });
826
835
  if (destroy) {
827
- _this3.destroy();
836
+ _this4.destroy();
828
837
  }
829
838
  function fallbackJump() {
830
839
  if (mode === 'replace') {
@@ -838,7 +847,7 @@ export var ModernElementController = /*#__PURE__*/function () {
838
847
  var app = new CallApp({
839
848
  resultJudgmentTime: 2000,
840
849
  fallback: function fallback() {
841
- _this3.trackElement('redirect_fallback', {
850
+ _this4.trackElement('redirect_fallback', {
842
851
  d1: 'callapp_failed',
843
852
  d2: url || ''
844
853
  });
@@ -853,7 +862,7 @@ export var ModernElementController = /*#__PURE__*/function () {
853
862
  fallbackJump();
854
863
  }
855
864
  } catch (error) {
856
- _this3.trackError('redirect_error', {
865
+ _this4.trackError('redirect_error', {
857
866
  d1: 'callapp_exception',
858
867
  d2: (error === null || error === void 0 ? void 0 : error.message) || '',
859
868
  d3: url || ''
@@ -862,34 +871,34 @@ export var ModernElementController = /*#__PURE__*/function () {
862
871
  }
863
872
  });
864
873
  this.bridge.on(MessageType.OPEN_MODAL, function (payload, _ports, meta) {
865
- var _this3$iframe3;
866
- if (meta && meta.source !== ((_this3$iframe3 = _this3.iframe) === null || _this3$iframe3 === void 0 ? void 0 : _this3$iframe3.contentWindow)) {
874
+ var _this4$iframe3;
875
+ if (meta && meta.source !== ((_this4$iframe3 = _this4.iframe) === null || _this4$iframe3 === void 0 ? void 0 : _this4$iframe3.contentWindow)) {
867
876
  return;
868
877
  }
869
- _this3.handleOpenModal(payload);
870
- _this3.bridge.once(MessageType.CLOSE_MODAL, function () {
871
- _this3.handleCloseModal();
878
+ _this4.handleOpenModal(payload);
879
+ _this4.bridge.once(MessageType.CLOSE_MODAL, function () {
880
+ _this4.handleCloseModal();
872
881
  });
873
882
  });
874
883
  this.bridge.on(MessageType.DESTROY_ELEMENT, function (_payload, _ports, meta) {
875
- var _this3$iframe4;
876
- if (meta && meta.source !== ((_this3$iframe4 = _this3.iframe) === null || _this3$iframe4 === void 0 ? void 0 : _this3$iframe4.contentWindow)) {
884
+ var _this4$iframe4;
885
+ if (meta && meta.source !== ((_this4$iframe4 = _this4.iframe) === null || _this4$iframe4 === void 0 ? void 0 : _this4$iframe4.contentWindow)) {
877
886
  return;
878
887
  }
879
- _this3.destroy();
888
+ _this4.destroy();
880
889
  });
881
890
 
882
891
  // skipRenderPaymentMethod 场景:webapp 委托 SDK 全权拉起 ApplePay,fire-and-forget
883
892
  // 走 plugin/applepay 标准链路(onEventCallback 自动通知商户)
884
893
  this.bridge.on(AMSMessageType.HANDLE_PAYMENT, function () {
885
- _this3.handleHandlePayment();
894
+ _this4.handleHandlePayment();
886
895
  });
887
896
 
888
897
  // Apple Pay beforeConfirm:在 submitPayment 内通过 bridge.once 监听,此处不再注册
889
898
 
890
899
  // 支付方式变化:iframe 通知 SDK 当前选中的支付方式类型
891
900
  this.bridge.on(AMSMessageType.PAYMENT_METHOD_CHANGED, function (payload) {
892
- _this3.currentPaymentMethodType = (payload === null || payload === void 0 ? void 0 : payload.type) || '';
901
+ _this4.currentPaymentMethodType = (payload === null || payload === void 0 ? void 0 : payload.type) || '';
893
902
  });
894
903
  }
895
904
 
@@ -903,7 +912,7 @@ export var ModernElementController = /*#__PURE__*/function () {
903
912
  value: (function () {
904
913
  var _handleGetApplePayToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(payload, onBeforeConfirm) {
905
914
  var _paymentMethod,
906
- _this4 = this;
915
+ _this5 = this;
907
916
  var sessionData, applePayProps, paymentRequest, merchantCapabilities, merchantInfo, paymentAmount, supportedNetworks, version, requiredBillingContactFields, requiredShippingContactFields, finalAmount, finalCurrency, capturedResult, recurringRequest, service, _capturedResult, errCode;
908
917
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
909
918
  while (1) switch (_context7.prev = _context7.next) {
@@ -975,7 +984,7 @@ export var ModernElementController = /*#__PURE__*/function () {
975
984
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
976
985
  while (1) switch (_context5.prev = _context5.next) {
977
986
  case 0:
978
- _this4.trackElement('applepay_validate_start', {
987
+ _this5.trackElement('applepay_validate_start', {
979
988
  d1: 'merchant_validate'
980
989
  });
981
990
  _context5.next = 3;
@@ -984,7 +993,7 @@ export var ModernElementController = /*#__PURE__*/function () {
984
993
  paymentSessionData: sessionData,
985
994
  merchantDomain: window.location.hostname
986
995
  }, {
987
- env: _this4.options.environment,
996
+ env: _this5.options.environment,
988
997
  envInfo: {
989
998
  deviceId: ''
990
999
  }
@@ -995,12 +1004,12 @@ export var ModernElementController = /*#__PURE__*/function () {
995
1004
  _context5.next = 7;
996
1005
  break;
997
1006
  }
998
- _this4.trackElement('applepay_validate_success', {
1007
+ _this5.trackElement('applepay_validate_success', {
999
1008
  d1: 'got_session'
1000
1009
  });
1001
1010
  return _context5.abrupt("return", typeof res.merchantSessionObject === 'string' ? JSON.parse(res.merchantSessionObject) : res.merchantSessionObject);
1002
1011
  case 7:
1003
- _this4.trackError('applepay_merchant_validate_failed', {
1012
+ _this5.trackError('applepay_merchant_validate_failed', {
1004
1013
  d1: 'VALIDATION_FAILED',
1005
1014
  d2: (res === null || res === void 0 ? void 0 : res.errorMessage) || 'Merchant validation failed'
1006
1015
  });
@@ -1043,7 +1052,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1043
1052
  isTimeout = timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS;
1044
1053
  shouldContinue = !isTimeout && !!rawResult;
1045
1054
  if (isTimeout) {
1046
- _this4.trackError('sdk_before_confirm_timeout', {
1055
+ _this5.trackError('sdk_before_confirm_timeout', {
1047
1056
  d1: 'applePay_chrome_modern'
1048
1057
  });
1049
1058
  }
@@ -1071,7 +1080,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1071
1080
  billingContact: billingContact,
1072
1081
  shippingContact: shippingContact
1073
1082
  };
1074
- _this4.trackElement('applepay_authorized', {
1083
+ _this5.trackElement('applepay_authorized', {
1075
1084
  d1: token ? 'has_token' : 'no_token'
1076
1085
  });
1077
1086
  return _context6.abrupt("return", {
@@ -1158,7 +1167,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1158
1167
  key: "handleGetGooglePayToken",
1159
1168
  value: function handleGetGooglePayToken(payload) {
1160
1169
  var _data$paymentMethodDe,
1161
- _this5 = this,
1170
+ _this6 = this,
1162
1171
  _google;
1163
1172
  var data = payload === null || payload === void 0 ? void 0 : payload.data;
1164
1173
  var googlePayProps = data === null || data === void 0 || (_data$paymentMethodDe = data.paymentMethodDetail) === null || _data$paymentMethodDe === void 0 ? void 0 : _data$paymentMethodDe.googlePayProps;
@@ -1202,10 +1211,10 @@ export var ModernElementController = /*#__PURE__*/function () {
1202
1211
  };
1203
1212
  }).then(function (paymentData) {
1204
1213
  if (paymentData) {
1205
- _this5.trackElement('googlepay_token_success', {
1214
+ _this6.trackElement('googlepay_token_success', {
1206
1215
  d1: 'has_token'
1207
1216
  });
1208
- _this5.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1217
+ _this6.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1209
1218
  success: true,
1210
1219
  result: paymentData
1211
1220
  });
@@ -1213,16 +1222,16 @@ export var ModernElementController = /*#__PURE__*/function () {
1213
1222
  }).catch(function (err) {
1214
1223
  var statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || 'GOOGLE_PAY_PAYMENT_FAILED';
1215
1224
  if (statusCode === 'CANCELED') {
1216
- _this5.trackElement('googlepay_cancel', {
1225
+ _this6.trackElement('googlepay_cancel', {
1217
1226
  d1: 'user_cancel'
1218
1227
  });
1219
1228
  } else {
1220
- _this5.trackError('googlepay_token_failed', {
1229
+ _this6.trackError('googlepay_token_failed', {
1221
1230
  d1: statusCode,
1222
1231
  d2: (err === null || err === void 0 ? void 0 : err.statusMessage) || ''
1223
1232
  });
1224
1233
  }
1225
- _this5.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1234
+ _this6.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1226
1235
  success: false,
1227
1236
  err: _objectSpread({
1228
1237
  statusCode: statusCode
@@ -1254,10 +1263,10 @@ export var ModernElementController = /*#__PURE__*/function () {
1254
1263
  loadAndPay();
1255
1264
  };
1256
1265
  script.onerror = function () {
1257
- _this5.trackError('googlepay_script_load_failed', {
1266
+ _this6.trackError('googlepay_script_load_failed', {
1258
1267
  d1: 'script_error'
1259
1268
  });
1260
- _this5.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1269
+ _this6.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
1261
1270
  success: false,
1262
1271
  err: {
1263
1272
  statusCode: 'GOOGLE_PAY_NOT_SUPPORTED'
@@ -1306,7 +1315,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1306
1315
  }, {
1307
1316
  key: "handleBeforeConfirmInternal",
1308
1317
  value: function handleBeforeConfirmInternal(onBeforeConfirm) {
1309
- var _this6 = this;
1318
+ var _this7 = this;
1310
1319
  if (!onBeforeConfirm) {
1311
1320
  logger.logInfo({
1312
1321
  title: 'sdk_before_confirm_skip'
@@ -1343,7 +1352,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1343
1352
  }, {
1344
1353
  shouldContinue: shouldContinue
1345
1354
  });
1346
- _this6.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, _objectSpread({
1355
+ _this7.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, _objectSpread({
1347
1356
  success: true,
1348
1357
  result: !!shouldContinue
1349
1358
  }, isTimeout ? {
@@ -1356,7 +1365,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1356
1365
  errorMessage: String((error === null || error === void 0 ? void 0 : error.message) || error).slice(0, 200),
1357
1366
  path: 'modernController_bridge'
1358
1367
  });
1359
- _this6.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
1368
+ _this7.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
1360
1369
  success: false,
1361
1370
  result: false
1362
1371
  });
@@ -1370,12 +1379,12 @@ export var ModernElementController = /*#__PURE__*/function () {
1370
1379
  }, {
1371
1380
  key: "waitForReadyHandshake",
1372
1381
  value: function waitForReadyHandshake() {
1373
- var _this7 = this;
1382
+ var _this8 = this;
1374
1383
  return new Promise(function (resolve, reject) {
1375
1384
  var cancelDestroyCallback = function cancelDestroyCallback() {};
1376
1385
  var timer = setTimeout(function () {
1377
1386
  cancelDestroyCallback();
1378
- _this7.trackError('ready_handshake_timeout', {
1387
+ _this8.trackError('ready_handshake_timeout', {
1379
1388
  d1: String(MOUNT_TIMEOUT)
1380
1389
  });
1381
1390
  reject({
@@ -1383,16 +1392,16 @@ export var ModernElementController = /*#__PURE__*/function () {
1383
1392
  message: 'An error occurred; the transaction cannot be initiated.'
1384
1393
  });
1385
1394
  }, MOUNT_TIMEOUT);
1386
- cancelDestroyCallback = _this7.onDestroy(function () {
1395
+ cancelDestroyCallback = _this8.onDestroy(function () {
1387
1396
  clearTimeout(timer);
1388
1397
  reject(getDestroyedError());
1389
1398
  });
1390
- _this7.bridge.once(MessageType.READY_HANDSHAKE, function () {
1391
- var _this7$iframe;
1399
+ _this8.bridge.once(MessageType.READY_HANDSHAKE, function () {
1400
+ var _this8$iframe;
1392
1401
  clearTimeout(timer);
1393
1402
  cancelDestroyCallback();
1394
- if (!((_this7$iframe = _this7.iframe) !== null && _this7$iframe !== void 0 && _this7$iframe.contentWindow)) {
1395
- _this7.trackError('iframe_contentwindow_unavailable', {
1403
+ if (!((_this8$iframe = _this8.iframe) !== null && _this8$iframe !== void 0 && _this8$iframe.contentWindow)) {
1404
+ _this8.trackError('iframe_contentwindow_unavailable', {
1396
1405
  d1: 'after_ready_handshake'
1397
1406
  });
1398
1407
  reject({
@@ -1401,9 +1410,9 @@ export var ModernElementController = /*#__PURE__*/function () {
1401
1410
  });
1402
1411
  return;
1403
1412
  }
1404
- _this7.bridge.setTarget(_this7.iframe.contentWindow);
1405
- _this7.trackHandshake('ready_handshake_received', {
1406
- m1: _this7._mountStartTime ? Date.now() - _this7._mountStartTime : 0
1413
+ _this8.bridge.setTarget(_this8.iframe.contentWindow);
1414
+ _this8.trackHandshake('ready_handshake_received', {
1415
+ m1: _this8._mountStartTime ? Date.now() - _this8._mountStartTime : 0
1407
1416
  });
1408
1417
  resolve();
1409
1418
  });
@@ -1428,12 +1437,12 @@ export var ModernElementController = /*#__PURE__*/function () {
1428
1437
  }, {
1429
1438
  key: "waitForHandshakeAck",
1430
1439
  value: function waitForHandshakeAck() {
1431
- var _this8 = this;
1440
+ var _this9 = this;
1432
1441
  return new Promise(function (resolve, reject) {
1433
1442
  var cancelDestroyCallback = function cancelDestroyCallback() {};
1434
1443
  var timer = setTimeout(function () {
1435
1444
  cancelDestroyCallback();
1436
- _this8.trackError('handshake_ack_timeout', {
1445
+ _this9.trackError('handshake_ack_timeout', {
1437
1446
  d1: String(MOUNT_TIMEOUT)
1438
1447
  });
1439
1448
  reject({
@@ -1441,15 +1450,15 @@ export var ModernElementController = /*#__PURE__*/function () {
1441
1450
  message: 'An error occurred; the transaction cannot be initiated.'
1442
1451
  });
1443
1452
  }, MOUNT_TIMEOUT);
1444
- cancelDestroyCallback = _this8.onDestroy(function () {
1453
+ cancelDestroyCallback = _this9.onDestroy(function () {
1445
1454
  clearTimeout(timer);
1446
1455
  reject(getDestroyedError());
1447
1456
  });
1448
- _this8.bridge.once(MessageType.HANDSHAKE_ACK, function () {
1457
+ _this9.bridge.once(MessageType.HANDSHAKE_ACK, function () {
1449
1458
  clearTimeout(timer);
1450
1459
  cancelDestroyCallback();
1451
- _this8.trackHandshake('handshake_ack_received', {
1452
- m1: _this8._mountStartTime ? Date.now() - _this8._mountStartTime : 0
1460
+ _this9.trackHandshake('handshake_ack_received', {
1461
+ m1: _this9._mountStartTime ? Date.now() - _this9._mountStartTime : 0
1453
1462
  });
1454
1463
  resolve();
1455
1464
  });
@@ -1459,15 +1468,15 @@ export var ModernElementController = /*#__PURE__*/function () {
1459
1468
  key: "submitPayment",
1460
1469
  value: function () {
1461
1470
  var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1462
- var _this9 = this;
1471
+ var _this10 = this;
1463
1472
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1464
1473
  while (1) switch (_context8.prev = _context8.next) {
1465
1474
  case 0:
1466
1475
  return _context8.abrupt("return", runApi('submitPayment', function () {
1467
- return _this9.doSubmitPayment(params);
1476
+ return _this10.doSubmitPayment(params);
1468
1477
  }, function () {
1469
- return _this9.currentPaymentMethodType ? {
1470
- d4: _this9.currentPaymentMethodType
1478
+ return _this10.currentPaymentMethodType ? {
1479
+ d4: _this10.currentPaymentMethodType
1471
1480
  } : {};
1472
1481
  }, normalizeApiInput('submitPayment', params), this.merchantId));
1473
1482
  case 1:
@@ -1485,7 +1494,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1485
1494
  key: "doSubmitPayment",
1486
1495
  value: function () {
1487
1496
  var _doSubmitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
1488
- var _this10 = this;
1497
+ var _this11 = this;
1489
1498
  var _this$options$loading7, _this$options$loading8, isApplePay, _ref6, onBeforeConfirm, serializableParams, startTime, _yield$executeWithTim2, shouldContinue, timedOut, isTimeout, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, cleanups, _result$error5, resultPromise, result, _this$options$loading9, _this$options$loading10;
1490
1499
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1491
1500
  while (1) switch (_context9.prev = _context9.next) {
@@ -1638,20 +1647,20 @@ export var ModernElementController = /*#__PURE__*/function () {
1638
1647
  resultPromise = new Promise(function (resolve) {
1639
1648
  // 先注册事件监听,再发送 SUBMIT,避免 webapp 快速响应导致消息丢失
1640
1649
  // PC 非 Safari:webapp 委托 SDK 拉起 Apple Pay 拿 token
1641
- cleanups.push(_this10.bridge.once(AMSMessageType.GET_APPLE_PAY_TOKEN, function (payload) {
1642
- _this10.handleGetApplePayToken(payload, onBeforeConfirm).then(function () {
1650
+ cleanups.push(_this11.bridge.once(AMSMessageType.GET_APPLE_PAY_TOKEN, function (payload) {
1651
+ _this11.handleGetApplePayToken(payload, onBeforeConfirm).then(function () {
1643
1652
  // token 已回传 webapp,继续等 SUBMIT_REPLY
1644
1653
  });
1645
1654
  }));
1646
1655
  // Web element GP:webapp 委托 SDK/父 frame 调 loadPaymentData 拿 token
1647
- cleanups.push(_this10.bridge.once(AMSMessageType.GET_GOOGLE_PAY_TOKEN, function (payload) {
1648
- _this10.handleGetGooglePayToken(payload);
1656
+ cleanups.push(_this11.bridge.once(AMSMessageType.GET_GOOGLE_PAY_TOKEN, function (payload) {
1657
+ _this11.handleGetGooglePayToken(payload);
1649
1658
  }));
1650
1659
  // Safari:webapp 请求执行商户 onBeforeConfirm 回调
1651
- cleanups.push(_this10.bridge.once(AMSMessageType.BEFORE_CONFIRM, function () {
1652
- _this10.handleBeforeConfirmInternal(onBeforeConfirm || null);
1660
+ cleanups.push(_this11.bridge.once(AMSMessageType.BEFORE_CONFIRM, function () {
1661
+ _this11.handleBeforeConfirmInternal(onBeforeConfirm || null);
1653
1662
  }));
1654
- cleanups.push(_this10.bridge.once(MessageType.SUBMIT_REPLY, resolve));
1663
+ cleanups.push(_this11.bridge.once(MessageType.SUBMIT_REPLY, resolve));
1655
1664
  }); // 监听注册完成后再发送 SUBMIT,确保不会遗漏快速响应
1656
1665
  this.send(MessageType.SUBMIT, _objectSpread(_objectSpread({}, serializableParams), {}, {
1657
1666
  redirect: this.notRedirectAfterComplete ? 'if_required' : 'always',
@@ -1707,12 +1716,12 @@ export var ModernElementController = /*#__PURE__*/function () {
1707
1716
  key: "validateFields",
1708
1717
  value: function () {
1709
1718
  var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1710
- var _this11 = this;
1719
+ var _this12 = this;
1711
1720
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1712
1721
  while (1) switch (_context10.prev = _context10.next) {
1713
1722
  case 0:
1714
1723
  return _context10.abrupt("return", runApi('validateFields', function () {
1715
- return _this11.doValidateFields();
1724
+ return _this12.doValidateFields();
1716
1725
  }, undefined, undefined, this.merchantId));
1717
1726
  case 1:
1718
1727
  case "end":
@@ -1729,7 +1738,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1729
1738
  key: "doValidateFields",
1730
1739
  value: function () {
1731
1740
  var _doValidateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1732
- var _this12 = this;
1741
+ var _this13 = this;
1733
1742
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1734
1743
  while (1) switch (_context11.prev = _context11.next) {
1735
1744
  case 0:
@@ -1747,17 +1756,17 @@ export var ModernElementController = /*#__PURE__*/function () {
1747
1756
  this.send(AMSMessageType.VALIDATE);
1748
1757
  return _context11.abrupt("return", new Promise(function (resolve) {
1749
1758
  var timer = setTimeout(function () {
1750
- _this12.trackError('validate_fields_timeout', {
1759
+ _this13.trackError('validate_fields_timeout', {
1751
1760
  d1: '15000'
1752
1761
  });
1753
1762
  resolve({
1754
1763
  isValid: false
1755
1764
  });
1756
1765
  }, 15000);
1757
- _this12.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
1766
+ _this13.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
1758
1767
  clearTimeout(timer);
1759
1768
  var isValid = !!(payload !== null && payload !== void 0 && payload.isValid);
1760
- _this12.trackElement('validate_result', {
1769
+ _this13.trackElement('validate_result', {
1761
1770
  d1: isValid ? 'valid' : 'invalid'
1762
1771
  });
1763
1772
  resolve(payload || {
@@ -1803,16 +1812,17 @@ export var ModernElementController = /*#__PURE__*/function () {
1803
1812
  }, {
1804
1813
  key: "destroy",
1805
1814
  value: function destroy() {
1806
- var _this$iframe;
1815
+ var _this$iframe2;
1807
1816
  this.trackElement('destroy', {
1808
1817
  d1: this.status
1809
1818
  });
1810
1819
  if (this.status === 'initialized' || this.status === 'destroyed') {
1811
1820
  return;
1812
1821
  }
1822
+ this.stopModalMessageMonitor();
1813
1823
  this.handleCloseModal();
1814
1824
  this.bridge.destroy();
1815
- if ((_this$iframe = this.iframe) !== null && _this$iframe !== void 0 && _this$iframe.parentNode) this.iframe.parentNode.removeChild(this.iframe);
1825
+ if ((_this$iframe2 = this.iframe) !== null && _this$iframe2 !== void 0 && _this$iframe2.parentNode) this.iframe.parentNode.removeChild(this.iframe);
1816
1826
  this.iframe = null;
1817
1827
  this.setStatus('destroyed');
1818
1828
  this.runDestroyCallbacks();
@@ -1821,8 +1831,8 @@ export var ModernElementController = /*#__PURE__*/function () {
1821
1831
  }, {
1822
1832
  key: "cleanup",
1823
1833
  value: function cleanup() {
1824
- var _this$iframe2;
1825
- if ((_this$iframe2 = this.iframe) !== null && _this$iframe2 !== void 0 && _this$iframe2.parentNode) this.iframe.parentNode.removeChild(this.iframe);
1834
+ var _this$iframe3;
1835
+ if ((_this$iframe3 = this.iframe) !== null && _this$iframe3 !== void 0 && _this$iframe3.parentNode) this.iframe.parentNode.removeChild(this.iframe);
1826
1836
  this.iframe = null;
1827
1837
  this.setStatus('initialized');
1828
1838
  this.cachedSend = [];
@@ -1840,7 +1850,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1840
1850
  }, {
1841
1851
  key: "onDestroy",
1842
1852
  value: function onDestroy(callback) {
1843
- var _this13 = this;
1853
+ var _this14 = this;
1844
1854
  if (this.status === 'destroyed') {
1845
1855
  callback();
1846
1856
  return function () {
@@ -1849,7 +1859,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1849
1859
  }
1850
1860
  this.destroyCallbacks.push(callback);
1851
1861
  return function () {
1852
- _this13.destroyCallbacks = _this13.destroyCallbacks.filter(function (item) {
1862
+ _this14.destroyCallbacks = _this14.destroyCallbacks.filter(function (item) {
1853
1863
  return item !== callback;
1854
1864
  });
1855
1865
  };
@@ -1889,12 +1899,12 @@ export var ModernElementController = /*#__PURE__*/function () {
1889
1899
  }, {
1890
1900
  key: "flushCachedMessages",
1891
1901
  value: function flushCachedMessages() {
1892
- var _this14 = this;
1902
+ var _this15 = this;
1893
1903
  if (this.cachedSend.length > 0) {
1894
1904
  this.cachedSend.forEach(function (_ref7) {
1895
1905
  var type = _ref7.type,
1896
1906
  payload = _ref7.payload;
1897
- _this14.bridge.send(type, payload);
1907
+ _this15.bridge.send(type, payload);
1898
1908
  });
1899
1909
  this.cachedSend = [];
1900
1910
  }
@@ -1917,7 +1927,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1917
1927
  var _payload$appearance,
1918
1928
  _themeColorMap$appear,
1919
1929
  _payload$appearance2,
1920
- _this15 = this;
1930
+ _this16 = this;
1921
1931
  // 清理已存在的 modal
1922
1932
  this.handleCloseModal();
1923
1933
  var mode = device.isMobile ? 'mobile' : 'desktop';
@@ -1973,7 +1983,7 @@ export var ModernElementController = /*#__PURE__*/function () {
1973
1983
  destroy = _openModal.destroy;
1974
1984
  var offReady = modalBridge.once(MessageType.MODAL_TRANSFER_READY, function (_payload, _ports, meta) {
1975
1985
  if (meta && meta.source !== iframe.contentWindow) return;
1976
- _this15.trackElement('modal_loaded', {
1986
+ _this16.trackElement('modal_loaded', {
1977
1987
  d1: payload.url
1978
1988
  });
1979
1989
  // 确保 target 已设置(如果 load 事件尚未触发,在此设置)
@@ -2002,13 +2012,13 @@ export var ModernElementController = /*#__PURE__*/function () {
2002
2012
  this.modalIframe = iframe;
2003
2013
  this.modalDestroy = function () {
2004
2014
  if (payload.closeConfirm) {
2005
- _this15.trackElement('modal_close_confirm', {
2015
+ _this16.trackElement('modal_close_confirm', {
2006
2016
  d1: 'confirm_resolved'
2007
2017
  });
2008
2018
  }
2009
2019
  destroy();
2010
2020
  offReady();
2011
- _this15.modalIframe = null;
2021
+ _this16.modalIframe = null;
2012
2022
  };
2013
2023
  }
2014
2024