@alipay/ams-checkout 0.0.1783323899-dev.0 → 0.0.1783323899-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ams-checkout.js +3 -3
- package/dist/ams-checkout.min.js +1 -1
- package/dist/ams-checkout.min.js.map +1 -1
- package/esm/config/index.js +1 -1
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +12 -5
- package/esm/core/component/element/modernElementController/index.d.ts +16 -0
- package/esm/core/component/element/modernElementController/index.js +167 -36
- package/esm/foundation/service/event-center.js +12 -9
- package/esm/modern/tools.js +1 -1
- package/esm/util/logger.js +1 -1
- package/package.json +1 -1
package/esm/config/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export var v2AppMarmotMap = {
|
|
|
30
30
|
light_sandbox: 'https://checkout.antom.com',
|
|
31
31
|
prod: 'https://checkout.antom.com'
|
|
32
32
|
};
|
|
33
|
-
export var sdkVersion = "0.0.1783323899-dev.
|
|
33
|
+
export var sdkVersion = "0.0.1783323899-dev.1";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
|
@@ -377,7 +377,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
377
377
|
var _obtainData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
378
378
|
var _paymentSessionObj$co,
|
|
379
379
|
_this3 = this;
|
|
380
|
-
var requestService, _this$elementContaine7, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$options2, environment, locale, _ref6, paymentSessionConfig, hostSign, isConnect, LOCAL_MOCK, _queryParse, appType, terminalType, generateActionQueryPromise, generateOneAccountQueryPromise, _yield$Promise$all, _yield$Promise$all2, originActionQueryResult, originOneAccountQueryResult;
|
|
380
|
+
var requestService, _this$elementContaine7, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$options2, environment, locale, _ref6, paymentSessionConfig, hostSign, isConnect, extendInfo, onlyIntegrateCardElementConnectMerchantFlag, _JSON$parse2, shouldQueryOneAccount, LOCAL_MOCK, _queryParse, appType, terminalType, generateActionQueryPromise, generateOneAccountQueryPromise, _yield$Promise$all, _yield$Promise$all2, originActionQueryResult, originOneAccountQueryResult;
|
|
381
381
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
382
382
|
while (1) switch (_context3.prev = _context3.next) {
|
|
383
383
|
case 0:
|
|
@@ -389,6 +389,13 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
389
389
|
_ref6 = paymentSessionObj || {}, paymentSessionConfig = _ref6.paymentSessionConfig;
|
|
390
390
|
hostSign = paymentSession.split('&&')[1] || '';
|
|
391
391
|
isConnect = paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$co = paymentSessionObj.connectFactor) === null || _paymentSessionObj$co === void 0 ? void 0 : _paymentSessionObj$co.enableConnect;
|
|
392
|
+
extendInfo = (paymentSessionObj === null || paymentSessionObj === void 0 ? void 0 : paymentSessionObj.extendInfo) || '';
|
|
393
|
+
try {
|
|
394
|
+
onlyIntegrateCardElementConnectMerchantFlag = (_JSON$parse2 = JSON.parse(extendInfo)) === null || _JSON$parse2 === void 0 ? void 0 : _JSON$parse2.onlyIntegrateCardElementConnectMerchantFlag;
|
|
395
|
+
} catch (_unused) {
|
|
396
|
+
onlyIntegrateCardElementConnectMerchantFlag = undefined;
|
|
397
|
+
}
|
|
398
|
+
shouldQueryOneAccount = isConnect && onlyIntegrateCardElementConnectMerchantFlag !== 'true';
|
|
392
399
|
LOCAL_MOCK = (debugProps === null || debugProps === void 0 ? void 0 : debugProps.isDebug) && (debugProps === null || debugProps === void 0 ? void 0 : debugProps.local_mock);
|
|
393
400
|
_queryParse = queryParse(this.getElementUrl()), appType = _queryParse.appType;
|
|
394
401
|
terminalType = isElementPad() ? 'WEB' : appType ? 'APP' : isElementPC() ? 'WEB' : 'WAP';
|
|
@@ -523,9 +530,9 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
523
530
|
});
|
|
524
531
|
});
|
|
525
532
|
};
|
|
526
|
-
_context3.next =
|
|
527
|
-
return Promise.all(
|
|
528
|
-
case
|
|
533
|
+
_context3.next = 18;
|
|
534
|
+
return Promise.all(shouldQueryOneAccount ? [generateActionQueryPromise(), generateOneAccountQueryPromise()] : [generateActionQueryPromise()]);
|
|
535
|
+
case 18:
|
|
529
536
|
_yield$Promise$all = _context3.sent;
|
|
530
537
|
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
531
538
|
originActionQueryResult = _yield$Promise$all2[0];
|
|
@@ -538,7 +545,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
538
545
|
originActionQueryResult: originActionQueryResult,
|
|
539
546
|
originOneAccountQueryResult: originOneAccountQueryResult
|
|
540
547
|
});
|
|
541
|
-
case
|
|
548
|
+
case 24:
|
|
542
549
|
case "end":
|
|
543
550
|
return _context3.stop();
|
|
544
551
|
}
|
|
@@ -70,6 +70,22 @@ export declare class ModernElementController implements IElementController {
|
|
|
70
70
|
* 改由 SDK 域 new ApplePaySdk().startPay() 拉起 Apple modal,结果通过 bridge 回传。
|
|
71
71
|
*/
|
|
72
72
|
private handleGetApplePayToken;
|
|
73
|
+
/**
|
|
74
|
+
* 处理 webapp 委托的 Google Pay token 请求。
|
|
75
|
+
*
|
|
76
|
+
* 背景:Web element 场景下,GP 按钮在跨域 iframe 中隐藏,商户通过 SDK submitPay 触发。
|
|
77
|
+
* 跨域 iframe 中 btn.click() 是编程式点击(isTrusted=false),第二次 PaymentRequest.show()
|
|
78
|
+
* 需要 transient user activation,iframe 内无法满足。因此委托 SDK/父 frame 调 loadPaymentData。
|
|
79
|
+
*
|
|
80
|
+
* 流程(对齐 v1 GooglePayLaunchSpecificPaymentMethodHandler.clickWebViewButton):
|
|
81
|
+
* 1. 从 payload 中提取 environment + paymentRequest
|
|
82
|
+
* 2. 动态加载 Google Pay SDK 脚本
|
|
83
|
+
* 3. 创建 PaymentsClient + isReadyToPay + loadPaymentData
|
|
84
|
+
* 4. 成功 → GET_GOOGLE_PAY_TOKEN_REPLY { success: true, result }
|
|
85
|
+
* 5. 取消 → GET_GOOGLE_PAY_TOKEN_REPLY { success: false, err: { statusCode: 'CANCELED' } }
|
|
86
|
+
* 6. 失败 → GET_GOOGLE_PAY_TOKEN_REPLY { success: false, err: { statusCode } }
|
|
87
|
+
*/
|
|
88
|
+
private handleGetGooglePayToken;
|
|
73
89
|
/**
|
|
74
90
|
* 处理 webapp 委托的 skipRenderPaymentMethod 拉起请求(fire-and-forget)。
|
|
75
91
|
* 走 plugin/applepay 标准链路:ApplePayBusSubscriber.onCreateComponent 自动注入
|
|
@@ -133,6 +133,9 @@ var AMSMessageType = {
|
|
|
133
133
|
VALIDATE_REPLY: 'OPENSDK@VALIDATE_REPLY',
|
|
134
134
|
GET_APPLE_PAY_TOKEN: 'OPENSDK@GET_APPLE_PAY_TOKEN',
|
|
135
135
|
GET_APPLE_PAY_TOKEN_REPLY: 'OPENSDK@GET_APPLE_PAY_TOKEN_REPLY',
|
|
136
|
+
// Web element GP:iframe 委托 SDK/父 frame 调 loadPaymentData(解决跨域 iframe 二次 show() 被拒问题)
|
|
137
|
+
GET_GOOGLE_PAY_TOKEN: 'OPENSDK@GET_GOOGLE_PAY_TOKEN',
|
|
138
|
+
GET_GOOGLE_PAY_TOKEN_REPLY: 'OPENSDK@GET_GOOGLE_PAY_TOKEN_REPLY',
|
|
136
139
|
// skipRenderPaymentMethod 场景:webapp 委托 SDK 全权拉起 ApplePay,fire-and-forget
|
|
137
140
|
// SDK 收到后走 BusManager.publish(ApplePayActionEnum.createComponent) → plugin/applepay 标准链路
|
|
138
141
|
// (含 onEventCallback 商户通知,不需要 reply 给 webapp)
|
|
@@ -353,7 +356,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
353
356
|
_this = this,
|
|
354
357
|
_parseData$paymentMet,
|
|
355
358
|
_sdkQueryResult$data;
|
|
356
|
-
var sessionData, parseData, isConnect, paymentSessionConfig, genSdkQueryPromise, genOneAccountQueryPromise, promises, _ref2, _ref3, sdkQueryResult, oneAccountQueryResult, _sdkQueryResult$error, _sdkQueryResult$error2, _oneAccountQueryResul, _oneAccountQueryResul2, preferredLocale, locale, renderDataError;
|
|
359
|
+
var sessionData, parseData, isConnect, extendInfo, onlyIntegrateCardElementConnectMerchantFlag, _JSON$parse, shouldQueryOneAccount, paymentSessionConfig, genSdkQueryPromise, genOneAccountQueryPromise, promises, _ref2, _ref3, sdkQueryResult, oneAccountQueryResult, _sdkQueryResult$error, _sdkQueryResult$error2, _oneAccountQueryResul, _oneAccountQueryResul2, preferredLocale, locale, renderDataError;
|
|
357
360
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
358
361
|
while (1) switch (_context2.prev = _context2.next) {
|
|
359
362
|
case 0:
|
|
@@ -369,10 +372,17 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
369
372
|
request.setGlobalOptions({
|
|
370
373
|
hostSign: parseHostSign(sessionData),
|
|
371
374
|
env: this.options.environment,
|
|
372
|
-
sdkVersion: "0.0.1783323899-dev.
|
|
375
|
+
sdkVersion: "0.0.1783323899-dev.1" || '',
|
|
373
376
|
tracker: sdkTracker
|
|
374
377
|
});
|
|
375
378
|
isConnect = !!(parseData !== null && parseData !== void 0 && (_parseData$connectFac = parseData.connectFactor) !== null && _parseData$connectFac !== void 0 && _parseData$connectFac.enableConnect);
|
|
379
|
+
extendInfo = (parseData === null || parseData === void 0 ? void 0 : parseData.extendInfo) || '';
|
|
380
|
+
try {
|
|
381
|
+
onlyIntegrateCardElementConnectMerchantFlag = (_JSON$parse = JSON.parse(extendInfo)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.onlyIntegrateCardElementConnectMerchantFlag;
|
|
382
|
+
} catch (_unused3) {
|
|
383
|
+
onlyIntegrateCardElementConnectMerchantFlag = undefined;
|
|
384
|
+
}
|
|
385
|
+
shouldQueryOneAccount = isConnect && onlyIntegrateCardElementConnectMerchantFlag !== 'true';
|
|
376
386
|
paymentSessionConfig = parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig;
|
|
377
387
|
genSdkQueryPromise = function genSdkQueryPromise() {
|
|
378
388
|
var _renderOptions$mercha;
|
|
@@ -401,10 +411,10 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
401
411
|
}
|
|
402
412
|
}));
|
|
403
413
|
};
|
|
404
|
-
promises =
|
|
405
|
-
_context2.next =
|
|
414
|
+
promises = shouldQueryOneAccount ? [genSdkQueryPromise(), genOneAccountQueryPromise()] : [genSdkQueryPromise(), undefined];
|
|
415
|
+
_context2.next = 16;
|
|
406
416
|
return Promise.all(promises);
|
|
407
|
-
case
|
|
417
|
+
case 16:
|
|
408
418
|
_ref2 = _context2.sent;
|
|
409
419
|
_ref3 = _slicedToArray(_ref2, 2);
|
|
410
420
|
sdkQueryResult = _ref3[0];
|
|
@@ -415,7 +425,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
415
425
|
d2: ((_sdkQueryResult$error2 = sdkQueryResult.error) === null || _sdkQueryResult$error2 === void 0 ? void 0 : _sdkQueryResult$error2.message) || ''
|
|
416
426
|
});
|
|
417
427
|
}
|
|
418
|
-
if (
|
|
428
|
+
if (shouldQueryOneAccount && oneAccountQueryResult !== null && oneAccountQueryResult !== void 0 && oneAccountQueryResult.error) {
|
|
419
429
|
trackHandshake('one_account_query_failed', {
|
|
420
430
|
d1: ((_oneAccountQueryResul = oneAccountQueryResult.error) === null || _oneAccountQueryResul === void 0 ? void 0 : _oneAccountQueryResul.code) || '',
|
|
421
431
|
d2: ((_oneAccountQueryResul2 = oneAccountQueryResult.error) === null || _oneAccountQueryResul2 === void 0 ? void 0 : _oneAccountQueryResul2.message) || ''
|
|
@@ -458,7 +468,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
458
468
|
// 新sdk字段
|
|
459
469
|
locale: locale,
|
|
460
470
|
// 新sdk字段
|
|
461
|
-
sdkVersion: "0.0.1783323899-dev.
|
|
471
|
+
sdkVersion: "0.0.1783323899-dev.1" || '',
|
|
462
472
|
// 新sdk字段
|
|
463
473
|
merchantId: (sdkQueryResult === null || sdkQueryResult === void 0 || (_sdkQueryResult$data = sdkQueryResult.data) === null || _sdkQueryResult$data === void 0 ? void 0 : _sdkQueryResult$data.merchantId) || '',
|
|
464
474
|
// 新sdk字段
|
|
@@ -468,7 +478,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
468
478
|
env: this.options.environment === 'sandbox' ? 'sandbox' : 'prod'
|
|
469
479
|
}, getDevReqConfig())
|
|
470
480
|
});
|
|
471
|
-
case
|
|
481
|
+
case 26:
|
|
472
482
|
case "end":
|
|
473
483
|
return _context2.stop();
|
|
474
484
|
}
|
|
@@ -653,8 +663,6 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
653
663
|
_this2.destroy();
|
|
654
664
|
});
|
|
655
665
|
|
|
656
|
-
// PC 非 Safari Apple Pay:在 submitPayment 内通过 bridge.once 监听,此处不再注册
|
|
657
|
-
|
|
658
666
|
// skipRenderPaymentMethod 场景:webapp 委托 SDK 全权拉起 ApplePay,fire-and-forget
|
|
659
667
|
// 走 plugin/applepay 标准链路(onEventCallback 自动通知商户)
|
|
660
668
|
this.bridge.on(AMSMessageType.HANDLE_PAYMENT, function () {
|
|
@@ -891,13 +899,132 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
891
899
|
}
|
|
892
900
|
return handleGetApplePayToken;
|
|
893
901
|
}()
|
|
902
|
+
/**
|
|
903
|
+
* 处理 webapp 委托的 Google Pay token 请求。
|
|
904
|
+
*
|
|
905
|
+
* 背景:Web element 场景下,GP 按钮在跨域 iframe 中隐藏,商户通过 SDK submitPay 触发。
|
|
906
|
+
* 跨域 iframe 中 btn.click() 是编程式点击(isTrusted=false),第二次 PaymentRequest.show()
|
|
907
|
+
* 需要 transient user activation,iframe 内无法满足。因此委托 SDK/父 frame 调 loadPaymentData。
|
|
908
|
+
*
|
|
909
|
+
* 流程(对齐 v1 GooglePayLaunchSpecificPaymentMethodHandler.clickWebViewButton):
|
|
910
|
+
* 1. 从 payload 中提取 environment + paymentRequest
|
|
911
|
+
* 2. 动态加载 Google Pay SDK 脚本
|
|
912
|
+
* 3. 创建 PaymentsClient + isReadyToPay + loadPaymentData
|
|
913
|
+
* 4. 成功 → GET_GOOGLE_PAY_TOKEN_REPLY { success: true, result }
|
|
914
|
+
* 5. 取消 → GET_GOOGLE_PAY_TOKEN_REPLY { success: false, err: { statusCode: 'CANCELED' } }
|
|
915
|
+
* 6. 失败 → GET_GOOGLE_PAY_TOKEN_REPLY { success: false, err: { statusCode } }
|
|
916
|
+
*/
|
|
917
|
+
)
|
|
918
|
+
}, {
|
|
919
|
+
key: "handleGetGooglePayToken",
|
|
920
|
+
value: function handleGetGooglePayToken(payload) {
|
|
921
|
+
var _data$paymentMethodDe,
|
|
922
|
+
_this4 = this,
|
|
923
|
+
_google;
|
|
924
|
+
var data = payload === null || payload === void 0 ? void 0 : payload.data;
|
|
925
|
+
var googlePayProps = data === null || data === void 0 || (_data$paymentMethodDe = data.paymentMethodDetail) === null || _data$paymentMethodDe === void 0 ? void 0 : _data$paymentMethodDe.googlePayProps;
|
|
926
|
+
// 优先从 data 顶层取(elements2 的 requestTokenViaSdk 直接传了 environment/paymentRequest),
|
|
927
|
+
// 否则从 paymentMethodDetail.googlePayProps 取(兼容 v1 的数据结构)
|
|
928
|
+
var environment = (data === null || data === void 0 ? void 0 : data.environment) || (googlePayProps === null || googlePayProps === void 0 ? void 0 : googlePayProps.environment) || 'TEST';
|
|
929
|
+
var paymentRequest = (data === null || data === void 0 ? void 0 : data.paymentRequest) || (googlePayProps === null || googlePayProps === void 0 ? void 0 : googlePayProps.paymentRequest) || {};
|
|
930
|
+
trackElement('googlepay_token_request', {
|
|
931
|
+
d1: environment,
|
|
932
|
+
d2: paymentRequest ? 'has_payment_request' : 'no_payment_request'
|
|
933
|
+
});
|
|
934
|
+
if (!paymentRequest || !Object.keys(paymentRequest).length) {
|
|
935
|
+
trackError('googlepay_token_missing_data', {
|
|
936
|
+
d1: 'MISSING_DATA'
|
|
937
|
+
});
|
|
938
|
+
this.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
|
|
939
|
+
success: false,
|
|
940
|
+
err: {
|
|
941
|
+
statusCode: 'GOOGLE_PAY_PAYMENT_FAILED'
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
var loadAndPay = function loadAndPay() {
|
|
947
|
+
var paymentsClient = new window.google.payments.api.PaymentsClient({
|
|
948
|
+
environment: environment,
|
|
949
|
+
paymentDataCallbacks: {
|
|
950
|
+
onPaymentAuthorized: function onPaymentAuthorized() {
|
|
951
|
+
return {
|
|
952
|
+
transactionState: 'SUCCESS'
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
paymentsClient.isReadyToPay(paymentRequest).then(function (response) {
|
|
958
|
+
if (response.result) {
|
|
959
|
+
return paymentsClient.loadPaymentData(paymentRequest);
|
|
960
|
+
}
|
|
961
|
+
throw {
|
|
962
|
+
statusCode: 'GOOGLE_PAY_NOT_SUPPORTED'
|
|
963
|
+
};
|
|
964
|
+
}).then(function (paymentData) {
|
|
965
|
+
if (paymentData) {
|
|
966
|
+
trackElement('googlepay_token_success', {
|
|
967
|
+
d1: 'has_token'
|
|
968
|
+
});
|
|
969
|
+
_this4.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
|
|
970
|
+
success: true,
|
|
971
|
+
result: paymentData
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
}).catch(function (err) {
|
|
975
|
+
var statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || 'GOOGLE_PAY_PAYMENT_FAILED';
|
|
976
|
+
if (statusCode === 'CANCELED') {
|
|
977
|
+
trackElement('googlepay_cancel', {
|
|
978
|
+
d1: 'user_cancel'
|
|
979
|
+
});
|
|
980
|
+
} else {
|
|
981
|
+
trackError('googlepay_token_failed', {
|
|
982
|
+
d1: statusCode,
|
|
983
|
+
d2: (err === null || err === void 0 ? void 0 : err.statusMessage) || ''
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
_this4.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
|
|
987
|
+
success: false,
|
|
988
|
+
err: _objectSpread({
|
|
989
|
+
statusCode: statusCode
|
|
990
|
+
}, err)
|
|
991
|
+
});
|
|
992
|
+
});
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
// 如果 GP SDK 已经加载过(iframe 或其他渠道已加载),直接用
|
|
996
|
+
if ((_google = window.google) !== null && _google !== void 0 && (_google = _google.payments) !== null && _google !== void 0 && (_google = _google.api) !== null && _google !== void 0 && _google.PaymentsClient) {
|
|
997
|
+
loadAndPay();
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// 否则动态加载 GP SDK 脚本
|
|
1002
|
+
var script = document.createElement('script');
|
|
1003
|
+
script.src = 'https://pay.google.com/gp/p/js/pay.js';
|
|
1004
|
+
script.async = true;
|
|
1005
|
+
document.body.appendChild(script);
|
|
1006
|
+
script.onload = function () {
|
|
1007
|
+
loadAndPay();
|
|
1008
|
+
};
|
|
1009
|
+
script.onerror = function () {
|
|
1010
|
+
trackError('googlepay_script_load_failed', {
|
|
1011
|
+
d1: 'script_error'
|
|
1012
|
+
});
|
|
1013
|
+
_this4.bridge.send(AMSMessageType.GET_GOOGLE_PAY_TOKEN_REPLY, {
|
|
1014
|
+
success: false,
|
|
1015
|
+
err: {
|
|
1016
|
+
statusCode: 'GOOGLE_PAY_NOT_SUPPORTED'
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
|
|
894
1022
|
/**
|
|
895
1023
|
* 处理 webapp 委托的 skipRenderPaymentMethod 拉起请求(fire-and-forget)。
|
|
896
1024
|
* 走 plugin/applepay 标准链路:ApplePayBusSubscriber.onCreateComponent 自动注入
|
|
897
1025
|
* onEventCallback,通过 BusManager.publish(SDKCallbackActionEnum.onEventCallback)
|
|
898
1026
|
* 通知商户。SDK 端不需要 reply 给 webapp。
|
|
899
1027
|
*/
|
|
900
|
-
)
|
|
901
1028
|
}, {
|
|
902
1029
|
key: "handleHandlePayment",
|
|
903
1030
|
value: function handleHandlePayment() {
|
|
@@ -932,7 +1059,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
932
1059
|
}, {
|
|
933
1060
|
key: "handleBeforeConfirmInternal",
|
|
934
1061
|
value: function handleBeforeConfirmInternal(onBeforeConfirm) {
|
|
935
|
-
var
|
|
1062
|
+
var _this5 = this;
|
|
936
1063
|
if (!onBeforeConfirm) {
|
|
937
1064
|
logger.logInfo({
|
|
938
1065
|
title: 'sdk_before_confirm_skip'
|
|
@@ -966,7 +1093,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
966
1093
|
}, {
|
|
967
1094
|
shouldContinue: shouldContinue
|
|
968
1095
|
});
|
|
969
|
-
|
|
1096
|
+
_this5.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
|
|
970
1097
|
success: true,
|
|
971
1098
|
result: !!shouldContinue
|
|
972
1099
|
});
|
|
@@ -977,7 +1104,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
977
1104
|
errorMessage: String((error === null || error === void 0 ? void 0 : error.message) || error).slice(0, 200),
|
|
978
1105
|
path: 'modernController_bridge'
|
|
979
1106
|
});
|
|
980
|
-
|
|
1107
|
+
_this5.bridge.send(AMSMessageType.BEFORE_CONFIRM_REPLY, {
|
|
981
1108
|
success: false,
|
|
982
1109
|
result: false
|
|
983
1110
|
});
|
|
@@ -991,7 +1118,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
991
1118
|
}, {
|
|
992
1119
|
key: "waitForReadyHandshake",
|
|
993
1120
|
value: function waitForReadyHandshake() {
|
|
994
|
-
var
|
|
1121
|
+
var _this6 = this;
|
|
995
1122
|
return new Promise(function (resolve, reject) {
|
|
996
1123
|
var timer = setTimeout(function () {
|
|
997
1124
|
trackError('ready_handshake_timeout', {
|
|
@@ -1002,10 +1129,10 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1002
1129
|
message: 'An error occurred; the transaction cannot be initiated.'
|
|
1003
1130
|
});
|
|
1004
1131
|
}, MOUNT_TIMEOUT);
|
|
1005
|
-
|
|
1006
|
-
var
|
|
1132
|
+
_this6.bridge.once(MessageType.READY_HANDSHAKE, function () {
|
|
1133
|
+
var _this6$iframe;
|
|
1007
1134
|
clearTimeout(timer);
|
|
1008
|
-
if (!((
|
|
1135
|
+
if (!((_this6$iframe = _this6.iframe) !== null && _this6$iframe !== void 0 && _this6$iframe.contentWindow)) {
|
|
1009
1136
|
trackError('iframe_contentwindow_unavailable', {
|
|
1010
1137
|
d1: 'after_ready_handshake'
|
|
1011
1138
|
});
|
|
@@ -1015,9 +1142,9 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1015
1142
|
});
|
|
1016
1143
|
return;
|
|
1017
1144
|
}
|
|
1018
|
-
|
|
1145
|
+
_this6.bridge.setTarget(_this6.iframe.contentWindow);
|
|
1019
1146
|
trackHandshake('ready_handshake_received', {
|
|
1020
|
-
m1:
|
|
1147
|
+
m1: _this6._mountStartTime ? Date.now() - _this6._mountStartTime : 0
|
|
1021
1148
|
});
|
|
1022
1149
|
resolve();
|
|
1023
1150
|
});
|
|
@@ -1042,7 +1169,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1042
1169
|
}, {
|
|
1043
1170
|
key: "waitForHandshakeAck",
|
|
1044
1171
|
value: function waitForHandshakeAck() {
|
|
1045
|
-
var
|
|
1172
|
+
var _this7 = this;
|
|
1046
1173
|
return new Promise(function (resolve, reject) {
|
|
1047
1174
|
var timer = setTimeout(function () {
|
|
1048
1175
|
trackError('handshake_ack_timeout', {
|
|
@@ -1053,10 +1180,10 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1053
1180
|
message: 'An error occurred; the transaction cannot be initiated.'
|
|
1054
1181
|
});
|
|
1055
1182
|
}, MOUNT_TIMEOUT);
|
|
1056
|
-
|
|
1183
|
+
_this7.bridge.once(MessageType.HANDSHAKE_ACK, function () {
|
|
1057
1184
|
clearTimeout(timer);
|
|
1058
1185
|
trackHandshake('handshake_ack_received', {
|
|
1059
|
-
m1:
|
|
1186
|
+
m1: _this7._mountStartTime ? Date.now() - _this7._mountStartTime : 0
|
|
1060
1187
|
});
|
|
1061
1188
|
resolve();
|
|
1062
1189
|
});
|
|
@@ -1068,7 +1195,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1068
1195
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
1069
1196
|
var _this$options$loading7,
|
|
1070
1197
|
_this$options$loading8,
|
|
1071
|
-
|
|
1198
|
+
_this8 = this;
|
|
1072
1199
|
var isApplePay, _ref7, onBeforeConfirm, serializableParams, startTime, _yield$executeWithTim2, shouldContinue, timedOut, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _result$error, resultPromise, result, _this$options$loading9, _this$options$loading10;
|
|
1073
1200
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
1074
1201
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -1198,16 +1325,20 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1198
1325
|
resultPromise = new Promise(function (resolve) {
|
|
1199
1326
|
// 先注册事件监听,再发送 SUBMIT,避免 webapp 快速响应导致消息丢失
|
|
1200
1327
|
// PC 非 Safari:webapp 委托 SDK 拉起 Apple Pay 拿 token
|
|
1201
|
-
|
|
1202
|
-
|
|
1328
|
+
_this8.bridge.once(AMSMessageType.GET_APPLE_PAY_TOKEN, function (payload) {
|
|
1329
|
+
_this8.handleGetApplePayToken(payload, onBeforeConfirm).then(function () {
|
|
1203
1330
|
// token 已回传 webapp,继续等 SUBMIT_REPLY
|
|
1204
1331
|
});
|
|
1205
1332
|
});
|
|
1333
|
+
// Web element GP:webapp 委托 SDK/父 frame 调 loadPaymentData 拿 token
|
|
1334
|
+
_this8.bridge.once(AMSMessageType.GET_GOOGLE_PAY_TOKEN, function (payload) {
|
|
1335
|
+
_this8.handleGetGooglePayToken(payload);
|
|
1336
|
+
});
|
|
1206
1337
|
// Safari:webapp 请求执行商户 onBeforeConfirm 回调
|
|
1207
|
-
|
|
1208
|
-
|
|
1338
|
+
_this8.bridge.once(AMSMessageType.BEFORE_CONFIRM, function () {
|
|
1339
|
+
_this8.handleBeforeConfirmInternal(onBeforeConfirm || null);
|
|
1209
1340
|
});
|
|
1210
|
-
|
|
1341
|
+
_this8.bridge.once(MessageType.SUBMIT_REPLY, resolve);
|
|
1211
1342
|
}); // 监听注册完成后再发送 SUBMIT,确保不会遗漏快速响应
|
|
1212
1343
|
this.send(MessageType.SUBMIT, _objectSpread(_objectSpread({}, serializableParams), {}, {
|
|
1213
1344
|
redirect: this.notRedirectAfterComplete ? 'if_required' : 'always',
|
|
@@ -1252,7 +1383,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1252
1383
|
key: "validateFields",
|
|
1253
1384
|
value: function () {
|
|
1254
1385
|
var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
1255
|
-
var
|
|
1386
|
+
var _this9 = this;
|
|
1256
1387
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1257
1388
|
while (1) switch (_context7.prev = _context7.next) {
|
|
1258
1389
|
case 0:
|
|
@@ -1277,7 +1408,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1277
1408
|
isValid: false
|
|
1278
1409
|
});
|
|
1279
1410
|
}, 15000);
|
|
1280
|
-
|
|
1411
|
+
_this9.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
|
|
1281
1412
|
clearTimeout(timer);
|
|
1282
1413
|
var isValid = !!(payload !== null && payload !== void 0 && payload.isValid);
|
|
1283
1414
|
trackElement('validate_result', {
|
|
@@ -1385,12 +1516,12 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1385
1516
|
}, {
|
|
1386
1517
|
key: "flushCachedMessages",
|
|
1387
1518
|
value: function flushCachedMessages() {
|
|
1388
|
-
var
|
|
1519
|
+
var _this10 = this;
|
|
1389
1520
|
if (this.cachedSend.length > 0) {
|
|
1390
1521
|
this.cachedSend.forEach(function (_ref8) {
|
|
1391
1522
|
var type = _ref8.type,
|
|
1392
1523
|
payload = _ref8.payload;
|
|
1393
|
-
|
|
1524
|
+
_this10.bridge.send(type, payload);
|
|
1394
1525
|
});
|
|
1395
1526
|
this.cachedSend = [];
|
|
1396
1527
|
}
|
|
@@ -1413,7 +1544,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1413
1544
|
var _payload$appearance,
|
|
1414
1545
|
_themeColorMap$appear,
|
|
1415
1546
|
_payload$appearance2,
|
|
1416
|
-
|
|
1547
|
+
_this11 = this;
|
|
1417
1548
|
// 清理已存在的 modal
|
|
1418
1549
|
this.handleCloseModal();
|
|
1419
1550
|
var mode = device.isMobile ? 'mobile' : 'desktop';
|
|
@@ -1459,7 +1590,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1459
1590
|
onClose: payload.closeConfirm ? function () {
|
|
1460
1591
|
return new Promise(function (resolve) {
|
|
1461
1592
|
// closeConfirm 时等待确认关闭(由 CLOSE_MODAL 消息触发 resolve)
|
|
1462
|
-
|
|
1593
|
+
_this11._closeConfirmResolve = resolve;
|
|
1463
1594
|
});
|
|
1464
1595
|
} : undefined
|
|
1465
1596
|
})),
|
|
@@ -1478,7 +1609,7 @@ export var ModernElementController = /*#__PURE__*/function () {
|
|
|
1478
1609
|
if (iframeOrigin && iframeOrigin !== 'null') {
|
|
1479
1610
|
modalBridge.setOrigin(iframeOrigin);
|
|
1480
1611
|
}
|
|
1481
|
-
} catch (
|
|
1612
|
+
} catch (_unused5) {
|
|
1482
1613
|
// URL 解析失败时保持默认 origin
|
|
1483
1614
|
}
|
|
1484
1615
|
// 如果 payload 有 appearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送给 modal
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
1
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
2
|
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; }
|
|
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
4
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
5
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
6
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -106,17 +106,20 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
|
106
106
|
if ((_e$data = e.data) !== null && _e$data !== void 0 && _e$data.source && ['react-devtools-content-script', 'react-devtools-backend-manager', 'react-devtools-bridge'].includes(e.data.source)) {
|
|
107
107
|
return; // Ignore messages from React DevTools
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
this._handleAppMessage(_eventPayload);
|
|
109
|
+
// postMessage 结构化克隆传递的是对象,不是 JSON 字符串;先判断是否为对象,再尝试 JSON 解析
|
|
110
|
+
var eventPayload;
|
|
111
|
+
if (_typeof(e.data) === 'object' && e.data !== null) {
|
|
112
|
+
eventPayload = e.data;
|
|
113
|
+
} else if (isJsonString(e.data)) {
|
|
114
|
+
eventPayload = JSON.parse(e.data);
|
|
117
115
|
} else {
|
|
118
116
|
console.error(ERRORMESSAGE.NOT_JSON_FORMAT);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!this.checkEventCompliant(eventPayload)) {
|
|
120
|
+
return;
|
|
119
121
|
}
|
|
122
|
+
this._handleAppMessage(eventPayload);
|
|
120
123
|
}
|
|
121
124
|
}, {
|
|
122
125
|
key: "checkEventCompliant",
|