@alipay/ams-checkout 2.0.26 → 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.
- package/ams-checkout.js +3 -3
- package/dist/ams-checkout.min.js +1 -1
- package/esm/config/index.js +1 -1
- package/esm/core/component/ckp/index.js +21 -1
- package/esm/core/component/element/elementController/index.js +4 -3
- package/esm/core/component/element/modernElementController/adapter.js +3 -3
- package/esm/core/component/element/modernElementController/index.d.ts +3 -1
- package/esm/core/component/element/modernElementController/index.js +170 -151
- package/esm/core/component/element/type.d.ts +2 -2
- package/esm/foundation/service/log/keys.js +4 -0
- package/esm/index.d.ts +6 -7
- package/esm/index.js +9 -14
- package/esm/modern/index.js +1 -1
- package/esm/modern/sdk/elements/appearanceRules.d.ts +59 -0
- package/esm/modern/tools.js +1 -1
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/util/logger.js +1 -1
- package/package.json +12 -12
- package/types.d.ts +324 -65
- package/types.untrimmed.d.ts +330 -65
|
@@ -29,13 +29,20 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
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 {
|
|
32
|
+
import { ERRORMESSAGE, PROMISE_CALLBACK_CODE } from "../../../../constant";
|
|
33
|
+
import { BusManager, BusMessage } from "../../../bus";
|
|
34
|
+
import { ApplePayActionEnum } from "../../../bus/interface";
|
|
33
35
|
import { shouldQueryOneAccount } from "../../../utils/connectConfig";
|
|
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
|
+
import { getApplePayPaymentSession } from "../../../../service";
|
|
34
38
|
import { device } from "../../../../util";
|
|
39
|
+
import { BEFORE_CONFIRM_TIMEOUT_MS, executeWithTimeout, MERCHANT_CONFIRM_ABORT_CODE, MERCHANT_CONFIRM_TIMEOUT_CODE } from "../../../../util/beforeConfirm";
|
|
40
|
+
import CallApp from "../../../../util/intl-callapp/es/main";
|
|
41
|
+
import { LogConfig, Logger } from "../../../../util/logger";
|
|
42
|
+
import { v4 as uuid } from 'uuid';
|
|
35
43
|
import { EventCallbackCode } from "../type";
|
|
36
|
-
import { adaptSubmitResult, adaptAppearance } from "./adapter";
|
|
37
44
|
import { safeParse } from "../util";
|
|
38
|
-
import {
|
|
45
|
+
import { adaptAppearance, adaptSubmitResult } from "./adapter";
|
|
39
46
|
|
|
40
47
|
// ============================================================
|
|
41
48
|
// 埋点 helper(不改 opensdk 源码,复用 sdkTracker 单例,trackId 已自动注入)
|
|
@@ -164,13 +171,6 @@ var runApi = /*#__PURE__*/function () {
|
|
|
164
171
|
return _ref.apply(this, arguments);
|
|
165
172
|
};
|
|
166
173
|
}();
|
|
167
|
-
import CallApp from "../../../../util/intl-callapp/es/main";
|
|
168
|
-
import { getApplePayPaymentSession } from "../../../../service";
|
|
169
|
-
import { BusManager, BusMessage } from "../../../bus";
|
|
170
|
-
import { ApplePayActionEnum } from "../../../bus/interface";
|
|
171
|
-
import { ERRORMESSAGE, PROMISE_CALLBACK_CODE } from "../../../../constant";
|
|
172
|
-
import { LogConfig, Logger } from "../../../../util/logger";
|
|
173
|
-
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
|
|
174
174
|
var recoverSdkQueryBusinessResponse = function recoverSdkQueryBusinessResponse(error) {
|
|
175
175
|
var response = error === null || error === void 0 ? void 0 : error.response;
|
|
176
176
|
if ((response === null || response === void 0 ? void 0 : response.success) === false) {
|
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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.
|
|
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:
|
|
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:
|
|
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 =
|
|
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.
|
|
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
|
|
805
|
+
var _this4 = this;
|
|
797
806
|
this.bridge.on(MessageType.HEIGHT_UPDATE, function (height) {
|
|
798
|
-
if (
|
|
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
|
|
802
|
-
if (meta && meta.source !== ((
|
|
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
|
|
809
|
-
if (meta && meta.source !== ((
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
866
|
-
if (meta && meta.source !== ((
|
|
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
|
-
|
|
870
|
-
|
|
871
|
-
|
|
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
|
|
876
|
-
if (meta && meta.source !== ((
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
});
|
|
@@ -1020,13 +1029,13 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1020
1029
|
}(),
|
|
1021
1030
|
onAuthorized: function () {
|
|
1022
1031
|
var _onAuthorized = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref4) {
|
|
1023
|
-
var token, billingContact, shippingContact, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue;
|
|
1032
|
+
var token, billingContact, shippingContact, startTime, _yield$executeWithTim, rawResult, timedOut, isTimeout, shouldContinue;
|
|
1024
1033
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
1025
1034
|
while (1) switch (_context6.prev = _context6.next) {
|
|
1026
1035
|
case 0:
|
|
1027
1036
|
token = _ref4.token, billingContact = _ref4.billingContact, shippingContact = _ref4.shippingContact;
|
|
1028
1037
|
if (!onBeforeConfirm) {
|
|
1029
|
-
_context6.next =
|
|
1038
|
+
_context6.next = 19;
|
|
1030
1039
|
break;
|
|
1031
1040
|
}
|
|
1032
1041
|
_context6.prev = 2;
|
|
@@ -1040,48 +1049,49 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1040
1049
|
rawResult = _yield$executeWithTim.result;
|
|
1041
1050
|
timedOut = _yield$executeWithTim.timedOut;
|
|
1042
1051
|
// 双重校验:timedOut(Promise race)+ startTime(实际时间差),与老 ElementController 对齐
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1052
|
+
isTimeout = timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS;
|
|
1053
|
+
shouldContinue = !isTimeout && !!rawResult;
|
|
1054
|
+
if (isTimeout) {
|
|
1055
|
+
_this5.trackError('sdk_before_confirm_timeout', {
|
|
1046
1056
|
d1: 'applePay_chrome_modern'
|
|
1047
1057
|
});
|
|
1048
1058
|
}
|
|
1049
1059
|
if (shouldContinue) {
|
|
1050
|
-
_context6.next =
|
|
1060
|
+
_context6.next = 14;
|
|
1051
1061
|
break;
|
|
1052
1062
|
}
|
|
1053
1063
|
return _context6.abrupt("return", {
|
|
1054
1064
|
success: false,
|
|
1055
|
-
errorCode:
|
|
1065
|
+
errorCode: isTimeout ? MERCHANT_CONFIRM_TIMEOUT_CODE : MERCHANT_CONFIRM_ABORT_CODE
|
|
1056
1066
|
});
|
|
1057
|
-
case
|
|
1058
|
-
_context6.next =
|
|
1067
|
+
case 14:
|
|
1068
|
+
_context6.next = 19;
|
|
1059
1069
|
break;
|
|
1060
|
-
case
|
|
1061
|
-
_context6.prev =
|
|
1070
|
+
case 16:
|
|
1071
|
+
_context6.prev = 16;
|
|
1062
1072
|
_context6.t0 = _context6["catch"](2);
|
|
1063
1073
|
return _context6.abrupt("return", {
|
|
1064
1074
|
success: false,
|
|
1065
|
-
errorCode:
|
|
1075
|
+
errorCode: MERCHANT_CONFIRM_ABORT_CODE
|
|
1066
1076
|
});
|
|
1067
|
-
case
|
|
1077
|
+
case 19:
|
|
1068
1078
|
capturedResult = {
|
|
1069
1079
|
token: token,
|
|
1070
1080
|
billingContact: billingContact,
|
|
1071
1081
|
shippingContact: shippingContact
|
|
1072
1082
|
};
|
|
1073
|
-
|
|
1083
|
+
_this5.trackElement('applepay_authorized', {
|
|
1074
1084
|
d1: token ? 'has_token' : 'no_token'
|
|
1075
1085
|
});
|
|
1076
1086
|
return _context6.abrupt("return", {
|
|
1077
1087
|
success: true,
|
|
1078
1088
|
result: capturedResult
|
|
1079
1089
|
});
|
|
1080
|
-
case
|
|
1090
|
+
case 22:
|
|
1081
1091
|
case "end":
|
|
1082
1092
|
return _context6.stop();
|
|
1083
1093
|
}
|
|
1084
|
-
}, _callee6, null, [[2,
|
|
1094
|
+
}, _callee6, null, [[2, 16]]);
|
|
1085
1095
|
}));
|
|
1086
1096
|
function onAuthorized(_x14) {
|
|
1087
1097
|
return _onAuthorized.apply(this, arguments);
|
|
@@ -1157,7 +1167,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1157
1167
|
key: "handleGetGooglePayToken",
|
|
1158
1168
|
value: function handleGetGooglePayToken(payload) {
|
|
1159
1169
|
var _data$paymentMethodDe,
|
|
1160
|
-
|
|
1170
|
+
_this6 = this,
|
|
1161
1171
|
_google;
|
|
1162
1172
|
var data = payload === null || payload === void 0 ? void 0 : payload.data;
|
|
1163
1173
|
var googlePayProps = data === null || data === void 0 || (_data$paymentMethodDe = data.paymentMethodDetail) === null || _data$paymentMethodDe === void 0 ? void 0 : _data$paymentMethodDe.googlePayProps;
|
|
@@ -1201,10 +1211,10 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1201
1211
|
};
|
|
1202
1212
|
}).then(function (paymentData) {
|
|
1203
1213
|
if (paymentData) {
|
|
1204
|
-
|
|
1214
|
+
_this6.trackElement('googlepay_token_success', {
|
|
1205
1215
|
d1: 'has_token'
|
|
1206
1216
|
});
|
|
1207
|
-
|
|
1217
|
+
_this6.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
|
|
1208
1218
|
success: true,
|
|
1209
1219
|
result: paymentData
|
|
1210
1220
|
});
|
|
@@ -1212,16 +1222,16 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1212
1222
|
}).catch(function (err) {
|
|
1213
1223
|
var statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || 'GOOGLE_PAY_PAYMENT_FAILED';
|
|
1214
1224
|
if (statusCode === 'CANCELED') {
|
|
1215
|
-
|
|
1225
|
+
_this6.trackElement('googlepay_cancel', {
|
|
1216
1226
|
d1: 'user_cancel'
|
|
1217
1227
|
});
|
|
1218
1228
|
} else {
|
|
1219
|
-
|
|
1229
|
+
_this6.trackError('googlepay_token_failed', {
|
|
1220
1230
|
d1: statusCode,
|
|
1221
1231
|
d2: (err === null || err === void 0 ? void 0 : err.statusMessage) || ''
|
|
1222
1232
|
});
|
|
1223
1233
|
}
|
|
1224
|
-
|
|
1234
|
+
_this6.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
|
|
1225
1235
|
success: false,
|
|
1226
1236
|
err: _objectSpread({
|
|
1227
1237
|
statusCode: statusCode
|
|
@@ -1253,10 +1263,10 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1253
1263
|
loadAndPay();
|
|
1254
1264
|
};
|
|
1255
1265
|
script.onerror = function () {
|
|
1256
|
-
|
|
1266
|
+
_this6.trackError('googlepay_script_load_failed', {
|
|
1257
1267
|
d1: 'script_error'
|
|
1258
1268
|
});
|
|
1259
|
-
|
|
1269
|
+
_this6.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
|
|
1260
1270
|
success: false,
|
|
1261
1271
|
err: {
|
|
1262
1272
|
statusCode: 'GOOGLE_PAY_NOT_SUPPORTED'
|
|
@@ -1305,7 +1315,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1305
1315
|
}, {
|
|
1306
1316
|
key: "handleBeforeConfirmInternal",
|
|
1307
1317
|
value: function handleBeforeConfirmInternal(onBeforeConfirm) {
|
|
1308
|
-
var
|
|
1318
|
+
var _this7 = this;
|
|
1309
1319
|
if (!onBeforeConfirm) {
|
|
1310
1320
|
logger.logInfo({
|
|
1311
1321
|
title: 'sdk_before_confirm_skip'
|
|
@@ -1330,8 +1340,9 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1330
1340
|
var rawResult = _ref5.result,
|
|
1331
1341
|
timedOut = _ref5.timedOut;
|
|
1332
1342
|
// 双重校验:timedOut(Promise race)+ startTime(实际时间差),与老 ElementController 对齐
|
|
1333
|
-
var
|
|
1334
|
-
|
|
1343
|
+
var isTimeout = timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS;
|
|
1344
|
+
var shouldContinue = !isTimeout && !!rawResult;
|
|
1345
|
+
if (isTimeout) {
|
|
1335
1346
|
logger.logError({
|
|
1336
1347
|
title: 'sdk_before_confirm_timeout'
|
|
1337
1348
|
});
|
|
@@ -1341,10 +1352,12 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1341
1352
|
}, {
|
|
1342
1353
|
shouldContinue: shouldContinue
|
|
1343
1354
|
});
|
|
1344
|
-
|
|
1355
|
+
_this7.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, _objectSpread({
|
|
1345
1356
|
success: true,
|
|
1346
1357
|
result: !!shouldContinue
|
|
1347
|
-
}
|
|
1358
|
+
}, isTimeout ? {
|
|
1359
|
+
isTimeout: true
|
|
1360
|
+
} : {}));
|
|
1348
1361
|
}).catch(function (error) {
|
|
1349
1362
|
logger.logError({
|
|
1350
1363
|
title: 'sdk_before_confirm_error'
|
|
@@ -1352,7 +1365,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1352
1365
|
errorMessage: String((error === null || error === void 0 ? void 0 : error.message) || error).slice(0, 200),
|
|
1353
1366
|
path: 'modernController_bridge'
|
|
1354
1367
|
});
|
|
1355
|
-
|
|
1368
|
+
_this7.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
|
|
1356
1369
|
success: false,
|
|
1357
1370
|
result: false
|
|
1358
1371
|
});
|
|
@@ -1366,12 +1379,12 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1366
1379
|
}, {
|
|
1367
1380
|
key: "waitForReadyHandshake",
|
|
1368
1381
|
value: function waitForReadyHandshake() {
|
|
1369
|
-
var
|
|
1382
|
+
var _this8 = this;
|
|
1370
1383
|
return new Promise(function (resolve, reject) {
|
|
1371
1384
|
var cancelDestroyCallback = function cancelDestroyCallback() {};
|
|
1372
1385
|
var timer = setTimeout(function () {
|
|
1373
1386
|
cancelDestroyCallback();
|
|
1374
|
-
|
|
1387
|
+
_this8.trackError('ready_handshake_timeout', {
|
|
1375
1388
|
d1: String(MOUNT_TIMEOUT)
|
|
1376
1389
|
});
|
|
1377
1390
|
reject({
|
|
@@ -1379,16 +1392,16 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1379
1392
|
message: 'An error occurred; the transaction cannot be initiated.'
|
|
1380
1393
|
});
|
|
1381
1394
|
}, MOUNT_TIMEOUT);
|
|
1382
|
-
cancelDestroyCallback =
|
|
1395
|
+
cancelDestroyCallback = _this8.onDestroy(function () {
|
|
1383
1396
|
clearTimeout(timer);
|
|
1384
1397
|
reject(getDestroyedError());
|
|
1385
1398
|
});
|
|
1386
|
-
|
|
1387
|
-
var
|
|
1399
|
+
_this8.bridge.once(MessageType.READY_HANDSHAKE, function () {
|
|
1400
|
+
var _this8$iframe;
|
|
1388
1401
|
clearTimeout(timer);
|
|
1389
1402
|
cancelDestroyCallback();
|
|
1390
|
-
if (!((
|
|
1391
|
-
|
|
1403
|
+
if (!((_this8$iframe = _this8.iframe) !== null && _this8$iframe !== void 0 && _this8$iframe.contentWindow)) {
|
|
1404
|
+
_this8.trackError('iframe_contentwindow_unavailable', {
|
|
1392
1405
|
d1: 'after_ready_handshake'
|
|
1393
1406
|
});
|
|
1394
1407
|
reject({
|
|
@@ -1397,9 +1410,9 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1397
1410
|
});
|
|
1398
1411
|
return;
|
|
1399
1412
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
m1:
|
|
1413
|
+
_this8.bridge.setTarget(_this8.iframe.contentWindow);
|
|
1414
|
+
_this8.trackHandshake('ready_handshake_received', {
|
|
1415
|
+
m1: _this8._mountStartTime ? Date.now() - _this8._mountStartTime : 0
|
|
1403
1416
|
});
|
|
1404
1417
|
resolve();
|
|
1405
1418
|
});
|
|
@@ -1424,12 +1437,12 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1424
1437
|
}, {
|
|
1425
1438
|
key: "waitForHandshakeAck",
|
|
1426
1439
|
value: function waitForHandshakeAck() {
|
|
1427
|
-
var
|
|
1440
|
+
var _this9 = this;
|
|
1428
1441
|
return new Promise(function (resolve, reject) {
|
|
1429
1442
|
var cancelDestroyCallback = function cancelDestroyCallback() {};
|
|
1430
1443
|
var timer = setTimeout(function () {
|
|
1431
1444
|
cancelDestroyCallback();
|
|
1432
|
-
|
|
1445
|
+
_this9.trackError('handshake_ack_timeout', {
|
|
1433
1446
|
d1: String(MOUNT_TIMEOUT)
|
|
1434
1447
|
});
|
|
1435
1448
|
reject({
|
|
@@ -1437,15 +1450,15 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1437
1450
|
message: 'An error occurred; the transaction cannot be initiated.'
|
|
1438
1451
|
});
|
|
1439
1452
|
}, MOUNT_TIMEOUT);
|
|
1440
|
-
cancelDestroyCallback =
|
|
1453
|
+
cancelDestroyCallback = _this9.onDestroy(function () {
|
|
1441
1454
|
clearTimeout(timer);
|
|
1442
1455
|
reject(getDestroyedError());
|
|
1443
1456
|
});
|
|
1444
|
-
|
|
1457
|
+
_this9.bridge.once(MessageType.HANDSHAKE_ACK, function () {
|
|
1445
1458
|
clearTimeout(timer);
|
|
1446
1459
|
cancelDestroyCallback();
|
|
1447
|
-
|
|
1448
|
-
m1:
|
|
1460
|
+
_this9.trackHandshake('handshake_ack_received', {
|
|
1461
|
+
m1: _this9._mountStartTime ? Date.now() - _this9._mountStartTime : 0
|
|
1449
1462
|
});
|
|
1450
1463
|
resolve();
|
|
1451
1464
|
});
|
|
@@ -1455,15 +1468,15 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1455
1468
|
key: "submitPayment",
|
|
1456
1469
|
value: function () {
|
|
1457
1470
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
|
|
1458
|
-
var
|
|
1471
|
+
var _this10 = this;
|
|
1459
1472
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1460
1473
|
while (1) switch (_context8.prev = _context8.next) {
|
|
1461
1474
|
case 0:
|
|
1462
1475
|
return _context8.abrupt("return", runApi('submitPayment', function () {
|
|
1463
|
-
return
|
|
1476
|
+
return _this10.doSubmitPayment(params);
|
|
1464
1477
|
}, function () {
|
|
1465
|
-
return
|
|
1466
|
-
d4:
|
|
1478
|
+
return _this10.currentPaymentMethodType ? {
|
|
1479
|
+
d4: _this10.currentPaymentMethodType
|
|
1467
1480
|
} : {};
|
|
1468
1481
|
}, normalizeApiInput('submitPayment', params), this.merchantId));
|
|
1469
1482
|
case 1:
|
|
@@ -1481,8 +1494,8 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1481
1494
|
key: "doSubmitPayment",
|
|
1482
1495
|
value: function () {
|
|
1483
1496
|
var _doSubmitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
|
|
1484
|
-
var
|
|
1485
|
-
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;
|
|
1497
|
+
var _this11 = this;
|
|
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;
|
|
1486
1499
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1487
1500
|
while (1) switch (_context9.prev = _context9.next) {
|
|
1488
1501
|
case 0:
|
|
@@ -1519,7 +1532,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1519
1532
|
isApplePay = this.currentPaymentMethodType === 'APPLEPAY'; // 剥除 onBeforeConfirm 函数,避免 postMessage 序列化报错
|
|
1520
1533
|
_ref6 = params || {}, onBeforeConfirm = _ref6.onBeforeConfirm, serializableParams = _objectWithoutProperties(_ref6, _excluded2); // ── 非 Apple Pay:同步执行 onBeforeConfirm(submit 前拦截,对齐老 ElementController) ──
|
|
1521
1534
|
if (!(onBeforeConfirm && !isApplePay)) {
|
|
1522
|
-
_context9.next =
|
|
1535
|
+
_context9.next = 32;
|
|
1523
1536
|
break;
|
|
1524
1537
|
}
|
|
1525
1538
|
logger.logInfo({
|
|
@@ -1538,11 +1551,13 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1538
1551
|
_yield$executeWithTim2 = _context9.sent;
|
|
1539
1552
|
shouldContinue = _yield$executeWithTim2.result;
|
|
1540
1553
|
timedOut = _yield$executeWithTim2.timedOut;
|
|
1541
|
-
|
|
1542
|
-
|
|
1554
|
+
// 双重校验:timedOut(Promise race)+ startTime(实际时间差),防止竞态误判
|
|
1555
|
+
isTimeout = timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS;
|
|
1556
|
+
if (!(isTimeout || !shouldContinue)) {
|
|
1557
|
+
_context9.next = 23;
|
|
1543
1558
|
break;
|
|
1544
1559
|
}
|
|
1545
|
-
if (
|
|
1560
|
+
if (isTimeout) {
|
|
1546
1561
|
logger.logError({
|
|
1547
1562
|
title: 'sdk_before_confirm_timeout'
|
|
1548
1563
|
}, {
|
|
@@ -1560,21 +1575,22 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1560
1575
|
return _context9.abrupt("return", {
|
|
1561
1576
|
status: 'FAIL',
|
|
1562
1577
|
error: {
|
|
1563
|
-
code:
|
|
1564
|
-
message: 'Merchant canceled payment.'
|
|
1578
|
+
code: isTimeout ? MERCHANT_CONFIRM_TIMEOUT_CODE : MERCHANT_CONFIRM_ABORT_CODE,
|
|
1579
|
+
message: isTimeout ? 'Merchant confirmation timed out.' : 'Merchant canceled payment.',
|
|
1580
|
+
needChangeSessionForRetry: false
|
|
1565
1581
|
}
|
|
1566
1582
|
});
|
|
1567
|
-
case
|
|
1583
|
+
case 23:
|
|
1568
1584
|
logger.logInfo({
|
|
1569
1585
|
title: 'sdk_before_confirm_success'
|
|
1570
1586
|
}, {
|
|
1571
1587
|
paymentMethodType: this.currentPaymentMethodType || 'UNKNOWN',
|
|
1572
1588
|
path: 'nonApplePay_sync'
|
|
1573
1589
|
});
|
|
1574
|
-
_context9.next =
|
|
1590
|
+
_context9.next = 30;
|
|
1575
1591
|
break;
|
|
1576
|
-
case
|
|
1577
|
-
_context9.prev =
|
|
1592
|
+
case 26:
|
|
1593
|
+
_context9.prev = 26;
|
|
1578
1594
|
_context9.t0 = _context9["catch"](12);
|
|
1579
1595
|
logger.logError({
|
|
1580
1596
|
title: 'sdk_before_confirm_error'
|
|
@@ -1586,14 +1602,15 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1586
1602
|
return _context9.abrupt("return", {
|
|
1587
1603
|
status: 'FAIL',
|
|
1588
1604
|
error: {
|
|
1589
|
-
code:
|
|
1590
|
-
message: 'Merchant canceled payment.'
|
|
1605
|
+
code: MERCHANT_CONFIRM_ABORT_CODE,
|
|
1606
|
+
message: 'Merchant canceled payment.',
|
|
1607
|
+
needChangeSessionForRetry: false
|
|
1591
1608
|
}
|
|
1592
1609
|
});
|
|
1593
|
-
case
|
|
1594
|
-
_context9.next =
|
|
1610
|
+
case 30:
|
|
1611
|
+
_context9.next = 33;
|
|
1595
1612
|
break;
|
|
1596
|
-
case
|
|
1613
|
+
case 32:
|
|
1597
1614
|
if (!onBeforeConfirm) {
|
|
1598
1615
|
logger.logInfo({
|
|
1599
1616
|
title: 'sdk_before_confirm_skip'
|
|
@@ -1602,7 +1619,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1602
1619
|
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
1603
1620
|
});
|
|
1604
1621
|
}
|
|
1605
|
-
case
|
|
1622
|
+
case 33:
|
|
1606
1623
|
// Apple Pay: 标记是否有 beforeConfirm,供 SUBMIT 消息的 hasBeforeConfirm 字段使用
|
|
1607
1624
|
hasBeforeConfirmForApplePay = isApplePay && !!onBeforeConfirm; // ── amount/currency 校验 + 缓存(对齐老 ElementController 逻辑) ──
|
|
1608
1625
|
hasAmount = !!(serializableParams !== null && serializableParams !== void 0 && serializableParams.amount);
|
|
@@ -1626,24 +1643,24 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1626
1643
|
// 未命中的 once wrapper 绑着旧闭包(旧 onBeforeConfirm / 旧 resolve)会残留并串扰后续提交,
|
|
1627
1644
|
// 在 submit 终态统一释放(二次 off 幂等,已命中的 once 已自行 off)。
|
|
1628
1645
|
cleanups = [];
|
|
1629
|
-
_context9.prev =
|
|
1646
|
+
_context9.prev = 42;
|
|
1630
1647
|
resultPromise = new Promise(function (resolve) {
|
|
1631
1648
|
// 先注册事件监听,再发送 SUBMIT,避免 webapp 快速响应导致消息丢失
|
|
1632
1649
|
// PC 非 Safari:webapp 委托 SDK 拉起 Apple Pay 拿 token
|
|
1633
|
-
cleanups.push(
|
|
1634
|
-
|
|
1650
|
+
cleanups.push(_this11.bridge.once(AMSMessageType.GET_APPLE_PAY_TOKEN, function (payload) {
|
|
1651
|
+
_this11.handleGetApplePayToken(payload, onBeforeConfirm).then(function () {
|
|
1635
1652
|
// token 已回传 webapp,继续等 SUBMIT_REPLY
|
|
1636
1653
|
});
|
|
1637
1654
|
}));
|
|
1638
1655
|
// Web element GP:webapp 委托 SDK/父 frame 调 loadPaymentData 拿 token
|
|
1639
|
-
cleanups.push(
|
|
1640
|
-
|
|
1656
|
+
cleanups.push(_this11.bridge.once(AMSMessageType.GET_GOOGLE_PAY_TOKEN, function (payload) {
|
|
1657
|
+
_this11.handleGetGooglePayToken(payload);
|
|
1641
1658
|
}));
|
|
1642
1659
|
// Safari:webapp 请求执行商户 onBeforeConfirm 回调
|
|
1643
|
-
cleanups.push(
|
|
1644
|
-
|
|
1660
|
+
cleanups.push(_this11.bridge.once(AMSMessageType.BEFORE_CONFIRM, function () {
|
|
1661
|
+
_this11.handleBeforeConfirmInternal(onBeforeConfirm || null);
|
|
1645
1662
|
}));
|
|
1646
|
-
cleanups.push(
|
|
1663
|
+
cleanups.push(_this11.bridge.once(MessageType.SUBMIT_REPLY, resolve));
|
|
1647
1664
|
}); // 监听注册完成后再发送 SUBMIT,确保不会遗漏快速响应
|
|
1648
1665
|
this.send(MessageType.SUBMIT, _objectSpread(_objectSpread({}, serializableParams), {}, {
|
|
1649
1666
|
redirect: this.notRedirectAfterComplete ? 'if_required' : 'always',
|
|
@@ -1652,25 +1669,25 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1652
1669
|
amount: serializableParams.amount,
|
|
1653
1670
|
currency: serializableParams.currency
|
|
1654
1671
|
} : {}));
|
|
1655
|
-
_context9.next =
|
|
1672
|
+
_context9.next = 47;
|
|
1656
1673
|
return resultPromise;
|
|
1657
|
-
case
|
|
1674
|
+
case 47:
|
|
1658
1675
|
result = _context9.sent;
|
|
1659
1676
|
this.trackElement('submit_reply', {
|
|
1660
1677
|
d1: (result === null || result === void 0 ? void 0 : result.status) || '',
|
|
1661
1678
|
d2: (result === null || result === void 0 || (_result$error5 = result.error) === null || _result$error5 === void 0 ? void 0 : _result$error5.code) || ''
|
|
1662
1679
|
});
|
|
1663
1680
|
return _context9.abrupt("return", adaptSubmitResult(result));
|
|
1664
|
-
case
|
|
1665
|
-
_context9.prev =
|
|
1666
|
-
_context9.t1 = _context9["catch"](
|
|
1681
|
+
case 52:
|
|
1682
|
+
_context9.prev = 52;
|
|
1683
|
+
_context9.t1 = _context9["catch"](42);
|
|
1667
1684
|
this.trackError('submit_error', {
|
|
1668
1685
|
d1: (_context9.t1 === null || _context9.t1 === void 0 ? void 0 : _context9.t1.code) || 'UNKNOWN',
|
|
1669
1686
|
d2: (_context9.t1 === null || _context9.t1 === void 0 ? void 0 : _context9.t1.message) || ''
|
|
1670
1687
|
});
|
|
1671
1688
|
throw _context9.t1;
|
|
1672
|
-
case
|
|
1673
|
-
_context9.prev =
|
|
1689
|
+
case 56:
|
|
1690
|
+
_context9.prev = 56;
|
|
1674
1691
|
cleanups.forEach(function (fn) {
|
|
1675
1692
|
try {
|
|
1676
1693
|
fn();
|
|
@@ -1679,16 +1696,16 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1679
1696
|
}
|
|
1680
1697
|
});
|
|
1681
1698
|
(_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);
|
|
1682
|
-
return _context9.finish(
|
|
1683
|
-
case
|
|
1684
|
-
_context9.prev =
|
|
1699
|
+
return _context9.finish(56);
|
|
1700
|
+
case 60:
|
|
1701
|
+
_context9.prev = 60;
|
|
1685
1702
|
this.isSubmitting = false;
|
|
1686
|
-
return _context9.finish(
|
|
1687
|
-
case
|
|
1703
|
+
return _context9.finish(60);
|
|
1704
|
+
case 63:
|
|
1688
1705
|
case "end":
|
|
1689
1706
|
return _context9.stop();
|
|
1690
1707
|
}
|
|
1691
|
-
}, _callee9, this, [[7,,
|
|
1708
|
+
}, _callee9, this, [[7,, 60, 63], [12, 26], [42, 52, 56, 60]]);
|
|
1692
1709
|
}));
|
|
1693
1710
|
function doSubmitPayment(_x16) {
|
|
1694
1711
|
return _doSubmitPayment.apply(this, arguments);
|
|
@@ -1699,12 +1716,12 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1699
1716
|
key: "validateFields",
|
|
1700
1717
|
value: function () {
|
|
1701
1718
|
var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
1702
|
-
var
|
|
1719
|
+
var _this12 = this;
|
|
1703
1720
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1704
1721
|
while (1) switch (_context10.prev = _context10.next) {
|
|
1705
1722
|
case 0:
|
|
1706
1723
|
return _context10.abrupt("return", runApi('validateFields', function () {
|
|
1707
|
-
return
|
|
1724
|
+
return _this12.doValidateFields();
|
|
1708
1725
|
}, undefined, undefined, this.merchantId));
|
|
1709
1726
|
case 1:
|
|
1710
1727
|
case "end":
|
|
@@ -1721,7 +1738,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1721
1738
|
key: "doValidateFields",
|
|
1722
1739
|
value: function () {
|
|
1723
1740
|
var _doValidateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
1724
|
-
var
|
|
1741
|
+
var _this13 = this;
|
|
1725
1742
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1726
1743
|
while (1) switch (_context11.prev = _context11.next) {
|
|
1727
1744
|
case 0:
|
|
@@ -1739,17 +1756,17 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1739
1756
|
this.send(AMSMessageType.VALIDATE);
|
|
1740
1757
|
return _context11.abrupt("return", new Promise(function (resolve) {
|
|
1741
1758
|
var timer = setTimeout(function () {
|
|
1742
|
-
|
|
1759
|
+
_this13.trackError('validate_fields_timeout', {
|
|
1743
1760
|
d1: '15000'
|
|
1744
1761
|
});
|
|
1745
1762
|
resolve({
|
|
1746
1763
|
isValid: false
|
|
1747
1764
|
});
|
|
1748
1765
|
}, 15000);
|
|
1749
|
-
|
|
1766
|
+
_this13.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
|
|
1750
1767
|
clearTimeout(timer);
|
|
1751
1768
|
var isValid = !!(payload !== null && payload !== void 0 && payload.isValid);
|
|
1752
|
-
|
|
1769
|
+
_this13.trackElement('validate_result', {
|
|
1753
1770
|
d1: isValid ? 'valid' : 'invalid'
|
|
1754
1771
|
});
|
|
1755
1772
|
resolve(payload || {
|
|
@@ -1795,16 +1812,17 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1795
1812
|
}, {
|
|
1796
1813
|
key: "destroy",
|
|
1797
1814
|
value: function destroy() {
|
|
1798
|
-
var _this$
|
|
1815
|
+
var _this$iframe2;
|
|
1799
1816
|
this.trackElement('destroy', {
|
|
1800
1817
|
d1: this.status
|
|
1801
1818
|
});
|
|
1802
1819
|
if (this.status === 'initialized' || this.status === 'destroyed') {
|
|
1803
1820
|
return;
|
|
1804
1821
|
}
|
|
1822
|
+
this.stopModalMessageMonitor();
|
|
1805
1823
|
this.handleCloseModal();
|
|
1806
1824
|
this.bridge.destroy();
|
|
1807
|
-
if ((_this$
|
|
1825
|
+
if ((_this$iframe2 = this.iframe) !== null && _this$iframe2 !== void 0 && _this$iframe2.parentNode) this.iframe.parentNode.removeChild(this.iframe);
|
|
1808
1826
|
this.iframe = null;
|
|
1809
1827
|
this.setStatus('destroyed');
|
|
1810
1828
|
this.runDestroyCallbacks();
|
|
@@ -1813,8 +1831,8 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1813
1831
|
}, {
|
|
1814
1832
|
key: "cleanup",
|
|
1815
1833
|
value: function cleanup() {
|
|
1816
|
-
var _this$
|
|
1817
|
-
if ((_this$
|
|
1834
|
+
var _this$iframe3;
|
|
1835
|
+
if ((_this$iframe3 = this.iframe) !== null && _this$iframe3 !== void 0 && _this$iframe3.parentNode) this.iframe.parentNode.removeChild(this.iframe);
|
|
1818
1836
|
this.iframe = null;
|
|
1819
1837
|
this.setStatus('initialized');
|
|
1820
1838
|
this.cachedSend = [];
|
|
@@ -1832,7 +1850,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1832
1850
|
}, {
|
|
1833
1851
|
key: "onDestroy",
|
|
1834
1852
|
value: function onDestroy(callback) {
|
|
1835
|
-
var
|
|
1853
|
+
var _this14 = this;
|
|
1836
1854
|
if (this.status === 'destroyed') {
|
|
1837
1855
|
callback();
|
|
1838
1856
|
return function () {
|
|
@@ -1841,7 +1859,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1841
1859
|
}
|
|
1842
1860
|
this.destroyCallbacks.push(callback);
|
|
1843
1861
|
return function () {
|
|
1844
|
-
|
|
1862
|
+
_this14.destroyCallbacks = _this14.destroyCallbacks.filter(function (item) {
|
|
1845
1863
|
return item !== callback;
|
|
1846
1864
|
});
|
|
1847
1865
|
};
|
|
@@ -1881,12 +1899,12 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1881
1899
|
}, {
|
|
1882
1900
|
key: "flushCachedMessages",
|
|
1883
1901
|
value: function flushCachedMessages() {
|
|
1884
|
-
var
|
|
1902
|
+
var _this15 = this;
|
|
1885
1903
|
if (this.cachedSend.length > 0) {
|
|
1886
1904
|
this.cachedSend.forEach(function (_ref7) {
|
|
1887
1905
|
var type = _ref7.type,
|
|
1888
1906
|
payload = _ref7.payload;
|
|
1889
|
-
|
|
1907
|
+
_this15.bridge.send(type, payload);
|
|
1890
1908
|
});
|
|
1891
1909
|
this.cachedSend = [];
|
|
1892
1910
|
}
|
|
@@ -1909,7 +1927,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1909
1927
|
var _payload$appearance,
|
|
1910
1928
|
_themeColorMap$appear,
|
|
1911
1929
|
_payload$appearance2,
|
|
1912
|
-
|
|
1930
|
+
_this16 = this;
|
|
1913
1931
|
// 清理已存在的 modal
|
|
1914
1932
|
this.handleCloseModal();
|
|
1915
1933
|
var mode = device.isMobile ? 'mobile' : 'desktop';
|
|
@@ -1943,9 +1961,10 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1943
1961
|
// 从 appearance 提取主题信息,组装 loadingConfig(对齐 antom.ts openModal 的处理逻辑)
|
|
1944
1962
|
var appearanceTheme = (payload === null || payload === void 0 || (_payload$appearance = payload.appearance) === null || _payload$appearance === void 0 ? void 0 : _payload$appearance.theme) || 'default';
|
|
1945
1963
|
var themeConfig = (_themeColorMap$appear = themeColorMap[appearanceTheme]) !== null && _themeColorMap$appear !== void 0 ? _themeColorMap$appear : themeColorMap.default;
|
|
1964
|
+
var appearanceVariables = payload === null || payload === void 0 || (_payload$appearance2 = payload.appearance) === null || _payload$appearance2 === void 0 ? void 0 : _payload$appearance2.variables;
|
|
1946
1965
|
var loadingConfig = {
|
|
1947
1966
|
theme: themeConfig.theme,
|
|
1948
|
-
backgroundColor: (
|
|
1967
|
+
backgroundColor: (appearanceVariables === null || appearanceVariables === void 0 ? void 0 : appearanceVariables['color-background-primary']) || (appearanceVariables === null || appearanceVariables === void 0 ? void 0 : appearanceVariables['background-primary']) || themeConfig.backgroundColor
|
|
1949
1968
|
};
|
|
1950
1969
|
|
|
1951
1970
|
// 调用 openModal 工具函数创建 DOM(overlay + modal + iframe + 动画 + close icon + loading)
|
|
@@ -1964,7 +1983,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1964
1983
|
destroy = _openModal.destroy;
|
|
1965
1984
|
var offReady = modalBridge.once(MessageType.MODAL_TRANSFER_READY, function (_payload, _ports, meta) {
|
|
1966
1985
|
if (meta && meta.source !== iframe.contentWindow) return;
|
|
1967
|
-
|
|
1986
|
+
_this16.trackElement('modal_loaded', {
|
|
1968
1987
|
d1: payload.url
|
|
1969
1988
|
});
|
|
1970
1989
|
// 确保 target 已设置(如果 load 事件尚未触发,在此设置)
|
|
@@ -1993,13 +2012,13 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1993
2012
|
this.modalIframe = iframe;
|
|
1994
2013
|
this.modalDestroy = function () {
|
|
1995
2014
|
if (payload.closeConfirm) {
|
|
1996
|
-
|
|
2015
|
+
_this16.trackElement('modal_close_confirm', {
|
|
1997
2016
|
d1: 'confirm_resolved'
|
|
1998
2017
|
});
|
|
1999
2018
|
}
|
|
2000
2019
|
destroy();
|
|
2001
2020
|
offReady();
|
|
2002
|
-
|
|
2021
|
+
_this16.modalIframe = null;
|
|
2003
2022
|
};
|
|
2004
2023
|
}
|
|
2005
2024
|
|