@alipay/ams-checkout 0.0.1781004142-dev.9 → 0.0.1781669097-dev.0
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/core/component/element/elementController/index.js +55 -62
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +31 -35
- package/esm/modern/index.js +1 -1
- package/esm/plugin/component/channel.d.ts +7 -0
- package/esm/plugin/component/channel.js +121 -24
- package/esm/types/index.d.ts +2 -7
- package/esm/util/beforeConfirm.d.ts +12 -0
- package/esm/util/beforeConfirm.js +68 -0
- package/package.json +1 -1
|
@@ -37,6 +37,7 @@ import { ServiceProvider } from "../../../../foundation/service";
|
|
|
37
37
|
import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
|
|
38
38
|
import { ProductSceneEnum } from "../../../../types";
|
|
39
39
|
import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
|
|
40
|
+
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
|
|
40
41
|
import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
|
|
41
42
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
|
42
43
|
import { EventCenter as ElementEventCenter } from "../EventCenter/index";
|
|
@@ -374,7 +375,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
374
375
|
value: function () {
|
|
375
376
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
|
|
376
377
|
var _this3 = this;
|
|
377
|
-
var startEventId, res, logParams, isApplePay, paymentMethodType,
|
|
378
|
+
var startEventId, res, logParams, isApplePay, paymentMethodType, startTime, _yield$executeWithTim, shouldContinue, timedOut, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
378
379
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
379
380
|
while (1) switch (_context4.prev = _context4.next) {
|
|
380
381
|
case 0:
|
|
@@ -404,42 +405,44 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
404
405
|
isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
|
|
405
406
|
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
406
407
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
407
|
-
_context4.next =
|
|
408
|
+
_context4.next = 34;
|
|
408
409
|
break;
|
|
409
410
|
}
|
|
410
|
-
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
411
411
|
this.serviceMap.Log.logInfo({
|
|
412
412
|
title: 'sdk_before_confirm_start'
|
|
413
413
|
}, {
|
|
414
414
|
paymentMethodType: paymentMethodType,
|
|
415
415
|
path: 'nonApplePay_sync'
|
|
416
416
|
});
|
|
417
|
-
_context4.prev =
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
417
|
+
_context4.prev = 11;
|
|
418
|
+
startTime = Date.now();
|
|
419
|
+
_context4.next = 15;
|
|
420
|
+
return executeWithTimeout(function () {
|
|
421
|
+
return submitParams.onBeforeConfirm();
|
|
422
422
|
});
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
shouldContinue
|
|
428
|
-
|
|
429
|
-
_context4.prev = 18;
|
|
430
|
-
clearTimeout(timerId);
|
|
431
|
-
return _context4.finish(18);
|
|
432
|
-
case 21:
|
|
433
|
-
if (!(shouldContinue === false)) {
|
|
434
|
-
_context4.next = 26;
|
|
423
|
+
case 15:
|
|
424
|
+
_yield$executeWithTim = _context4.sent;
|
|
425
|
+
shouldContinue = _yield$executeWithTim.result;
|
|
426
|
+
timedOut = _yield$executeWithTim.timedOut;
|
|
427
|
+
if (!(timedOut || !shouldContinue || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS)) {
|
|
428
|
+
_context4.next = 23;
|
|
435
429
|
break;
|
|
436
430
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
431
|
+
if (timedOut) {
|
|
432
|
+
this.serviceMap.Log.logError({
|
|
433
|
+
title: 'sdk_before_confirm_timeout'
|
|
434
|
+
}, {
|
|
435
|
+
paymentMethodType: paymentMethodType,
|
|
436
|
+
path: 'nonApplePay_sync'
|
|
437
|
+
});
|
|
438
|
+
} else {
|
|
439
|
+
this.serviceMap.Log.logInfo({
|
|
440
|
+
title: 'sdk_before_confirm_abort'
|
|
441
|
+
}, {
|
|
442
|
+
paymentMethodType: paymentMethodType,
|
|
443
|
+
path: 'nonApplePay_sync'
|
|
444
|
+
});
|
|
445
|
+
}
|
|
443
446
|
this.changeLoading(false);
|
|
444
447
|
this.elementEventCenter.endEvent(startEventId, {
|
|
445
448
|
eventCode: PaymentStatus.FAIL,
|
|
@@ -453,35 +456,25 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
453
456
|
needChangeSessionForRetry: false
|
|
454
457
|
}
|
|
455
458
|
});
|
|
456
|
-
case
|
|
459
|
+
case 23:
|
|
457
460
|
this.serviceMap.Log.logInfo({
|
|
458
461
|
title: 'sdk_before_confirm_success'
|
|
459
462
|
}, {
|
|
460
463
|
paymentMethodType: paymentMethodType,
|
|
461
464
|
path: 'nonApplePay_sync'
|
|
462
465
|
});
|
|
463
|
-
_context4.next =
|
|
466
|
+
_context4.next = 32;
|
|
464
467
|
break;
|
|
465
|
-
case
|
|
466
|
-
_context4.prev =
|
|
467
|
-
_context4.t0 = _context4["catch"](
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
});
|
|
476
|
-
} else {
|
|
477
|
-
this.serviceMap.Log.logError({
|
|
478
|
-
title: 'sdk_before_confirm_error'
|
|
479
|
-
}, {
|
|
480
|
-
paymentMethodType: paymentMethodType,
|
|
481
|
-
errorMessage: String((_context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message) || _context4.t0).slice(0, 200),
|
|
482
|
-
path: 'nonApplePay_sync'
|
|
483
|
-
});
|
|
484
|
-
}
|
|
468
|
+
case 26:
|
|
469
|
+
_context4.prev = 26;
|
|
470
|
+
_context4.t0 = _context4["catch"](11);
|
|
471
|
+
this.serviceMap.Log.logError({
|
|
472
|
+
title: 'sdk_before_confirm_error'
|
|
473
|
+
}, {
|
|
474
|
+
paymentMethodType: paymentMethodType,
|
|
475
|
+
errorMessage: String((_context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message) || _context4.t0).slice(0, 200),
|
|
476
|
+
path: 'nonApplePay_sync'
|
|
477
|
+
});
|
|
485
478
|
this.changeLoading(false);
|
|
486
479
|
this.elementEventCenter.endEvent(startEventId, {
|
|
487
480
|
eventCode: PaymentStatus.FAIL,
|
|
@@ -495,10 +488,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
495
488
|
needChangeSessionForRetry: false
|
|
496
489
|
}
|
|
497
490
|
});
|
|
498
|
-
case
|
|
499
|
-
_context4.next =
|
|
491
|
+
case 32:
|
|
492
|
+
_context4.next = 35;
|
|
500
493
|
break;
|
|
501
|
-
case
|
|
494
|
+
case 34:
|
|
502
495
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
|
|
503
496
|
this.serviceMap.Log.logInfo({
|
|
504
497
|
title: 'sdk_before_confirm_skip'
|
|
@@ -507,10 +500,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
507
500
|
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
508
501
|
});
|
|
509
502
|
}
|
|
510
|
-
case
|
|
503
|
+
case 35:
|
|
511
504
|
recordResult = null;
|
|
512
|
-
_context4.prev =
|
|
513
|
-
_context4.next =
|
|
505
|
+
_context4.prev = 36;
|
|
506
|
+
_context4.next = 39;
|
|
514
507
|
return new Promise( /*#__PURE__*/function () {
|
|
515
508
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
516
509
|
var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
@@ -667,10 +660,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
667
660
|
return _ref3.apply(this, arguments);
|
|
668
661
|
};
|
|
669
662
|
}());
|
|
670
|
-
case
|
|
663
|
+
case 39:
|
|
671
664
|
return _context4.abrupt("return", _context4.sent);
|
|
672
|
-
case
|
|
673
|
-
_context4.prev =
|
|
665
|
+
case 40:
|
|
666
|
+
_context4.prev = 40;
|
|
674
667
|
_logParams = {
|
|
675
668
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
676
669
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -681,12 +674,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
681
674
|
};
|
|
682
675
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
683
676
|
this.changeLoading(false);
|
|
684
|
-
return _context4.finish(
|
|
685
|
-
case
|
|
677
|
+
return _context4.finish(40);
|
|
678
|
+
case 45:
|
|
686
679
|
case "end":
|
|
687
680
|
return _context4.stop();
|
|
688
681
|
}
|
|
689
|
-
}, _callee4, this, [[
|
|
682
|
+
}, _callee4, this, [[11, 26], [36,, 40, 45]]);
|
|
690
683
|
}));
|
|
691
684
|
function submitPayment(_x) {
|
|
692
685
|
return _submitPayment.apply(this, arguments);
|
|
@@ -773,7 +766,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
773
766
|
});
|
|
774
767
|
this.serviceMap.EventCenter.listen(EVENTNAME.PAYMENTMETHODCHANGED, function (data) {
|
|
775
768
|
_this4.currentPaymentMethodType = (data === null || data === void 0 ? void 0 : data.type) || '';
|
|
776
|
-
});
|
|
769
|
+
}, true);
|
|
777
770
|
}
|
|
778
771
|
}, {
|
|
779
772
|
key: "sendRequestAndWaitWebLaunch",
|
|
@@ -1038,7 +1031,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
1038
1031
|
}
|
|
1039
1032
|
this.serviceMap.EventCenter.listen(event, function (data) {
|
|
1040
1033
|
callback === null || callback === void 0 || callback(data);
|
|
1041
|
-
});
|
|
1034
|
+
}, true);
|
|
1042
1035
|
}
|
|
1043
1036
|
}, {
|
|
1044
1037
|
key: "isEventAllowed",
|
|
@@ -33,6 +33,7 @@ import { parseSessionData } from "../../index";
|
|
|
33
33
|
import { oneAccount, sdkAction } from "../mock";
|
|
34
34
|
import { generateIframeSrc as _generateIframeSrc, isElementPad, isElementPC, safeStringify } from "../util";
|
|
35
35
|
import BaseElementProcessor from "./baseElementProcessor";
|
|
36
|
+
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
|
|
36
37
|
var logger = new Logger(LogConfig, true);
|
|
37
38
|
var isExpressCheckout = function isExpressCheckout(extendInfo) {
|
|
38
39
|
try {
|
|
@@ -70,6 +71,10 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
70
71
|
key: "setOnBeforeConfirm",
|
|
71
72
|
value: function setOnBeforeConfirm(callback) {
|
|
72
73
|
this._onBeforeConfirm = callback;
|
|
74
|
+
// 展码链路:同步设置 onBeforeConfirm 到 ApplePaySdk,确保 Chrome 展码支付时能调用商户回调
|
|
75
|
+
if (this.ApplePayService) {
|
|
76
|
+
this.ApplePayService.setOnBeforeConfirm(callback);
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
}, {
|
|
75
80
|
key: "setMerchantAmountOverride",
|
|
@@ -166,6 +171,8 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
166
171
|
merchantAmount: _this2._merchantAmount,
|
|
167
172
|
merchantCurrency: _this2._merchantCurrency
|
|
168
173
|
});
|
|
174
|
+
// Chrome 展码链路:同步 onBeforeConfirm 到当前 ApplePaySdk 实例
|
|
175
|
+
applePayService.setOnBeforeConfirm(_this2._onBeforeConfirm);
|
|
169
176
|
applePayService.startPay().then(function (res) {
|
|
170
177
|
_this2.eventCenter.dispatchToApp({
|
|
171
178
|
event: 'getApplePayToken',
|
|
@@ -188,7 +195,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
188
195
|
// requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
|
|
189
196
|
// and returns the result (continue/abort) to iframe via dispatchToApp.
|
|
190
197
|
this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
191
|
-
var paymentMethodType,
|
|
198
|
+
var paymentMethodType, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue;
|
|
192
199
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
193
200
|
while (1) switch (_context.prev = _context.next) {
|
|
194
201
|
case 0:
|
|
@@ -212,25 +219,24 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
212
219
|
});
|
|
213
220
|
return _context.abrupt("return");
|
|
214
221
|
case 5:
|
|
215
|
-
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
216
222
|
logger.logInfo({
|
|
217
223
|
title: 'sdk_before_confirm_start'
|
|
218
224
|
}, {
|
|
219
225
|
paymentMethodType: paymentMethodType,
|
|
220
226
|
path: 'applePay_eventBridge'
|
|
221
227
|
});
|
|
222
|
-
_context.prev =
|
|
223
|
-
timeoutPromise = new Promise(function (_, reject) {
|
|
224
|
-
return setTimeout(function () {
|
|
225
|
-
return reject(new Error('onBeforeConfirm timed out'));
|
|
226
|
-
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
227
|
-
});
|
|
228
|
+
_context.prev = 6;
|
|
228
229
|
startTime = Date.now();
|
|
229
|
-
_context.next =
|
|
230
|
-
return
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
_context.next = 10;
|
|
231
|
+
return executeWithTimeout(function () {
|
|
232
|
+
return _this2._onBeforeConfirm();
|
|
233
|
+
});
|
|
234
|
+
case 10:
|
|
235
|
+
_yield$executeWithTim = _context.sent;
|
|
236
|
+
rawResult = _yield$executeWithTim.result;
|
|
237
|
+
timedOut = _yield$executeWithTim.timedOut;
|
|
238
|
+
shouldContinue = rawResult; // 双重校验:timedOut(Promise race) + startTime(实际时间差),防止竞态误判
|
|
239
|
+
if (timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
|
|
234
240
|
logger.logError({
|
|
235
241
|
title: 'sdk_before_confirm_timeout'
|
|
236
242
|
});
|
|
@@ -245,31 +251,21 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
245
251
|
event: EVENT.beforeConfirm.name,
|
|
246
252
|
data: {
|
|
247
253
|
success: true,
|
|
248
|
-
result: shouldContinue
|
|
254
|
+
result: !!shouldContinue
|
|
249
255
|
}
|
|
250
256
|
});
|
|
251
257
|
_context.next = 23;
|
|
252
258
|
break;
|
|
253
|
-
case
|
|
254
|
-
_context.prev =
|
|
255
|
-
_context.t0 = _context["catch"](
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
});
|
|
264
|
-
} else {
|
|
265
|
-
logger.logError({
|
|
266
|
-
title: 'sdk_before_confirm_error'
|
|
267
|
-
}, {
|
|
268
|
-
paymentMethodType: paymentMethodType,
|
|
269
|
-
errorMessage: String((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0).slice(0, 200),
|
|
270
|
-
path: 'applePay_eventBridge'
|
|
271
|
-
});
|
|
272
|
-
}
|
|
259
|
+
case 19:
|
|
260
|
+
_context.prev = 19;
|
|
261
|
+
_context.t0 = _context["catch"](6);
|
|
262
|
+
logger.logError({
|
|
263
|
+
title: 'sdk_before_confirm_error'
|
|
264
|
+
}, {
|
|
265
|
+
paymentMethodType: paymentMethodType,
|
|
266
|
+
errorMessage: String((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0).slice(0, 200),
|
|
267
|
+
path: 'applePay_eventBridge'
|
|
268
|
+
});
|
|
273
269
|
_this2.eventCenter.dispatchToApp({
|
|
274
270
|
event: EVENT.beforeConfirm.name,
|
|
275
271
|
data: {
|
|
@@ -281,7 +277,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
281
277
|
case "end":
|
|
282
278
|
return _context.stop();
|
|
283
279
|
}
|
|
284
|
-
}, _callee, null, [[
|
|
280
|
+
}, _callee, null, [[6, 19]]);
|
|
285
281
|
})));
|
|
286
282
|
}
|
|
287
283
|
}, {
|
package/esm/modern/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { createLoader } from '@antglobal/create-sdk-loader';
|
|
|
15
15
|
|
|
16
16
|
import { stageName } from "./stageName";
|
|
17
17
|
var SDKURL = {
|
|
18
|
-
DEV: "https://sdk-dev.marmot-cloud.com/package/ams-checkout/".concat("dev-
|
|
18
|
+
DEV: "https://sdk-dev.marmot-cloud.com/package/ams-checkout/".concat("dev-1781669097", "/ams-checkout.js"),
|
|
19
19
|
LOCAL: "http://localhost:3000/ams-checkout.min.js",
|
|
20
20
|
PROD: 'https://js.antom.com/v2/ams-checkout.js'
|
|
21
21
|
};
|
|
@@ -31,11 +31,16 @@ export declare class ApplePaySdk {
|
|
|
31
31
|
* @description 支付状态,pending:支付中,normal:正常
|
|
32
32
|
*/
|
|
33
33
|
private paymentStatus;
|
|
34
|
+
/**
|
|
35
|
+
* @description oncancel 原因标记,用于区分用户主动取消 vs 商户通过 onBeforeConfirm 中止
|
|
36
|
+
*/
|
|
37
|
+
private cancelReason;
|
|
34
38
|
private logger;
|
|
35
39
|
private env;
|
|
36
40
|
private shipping?;
|
|
37
41
|
private merchantAmount;
|
|
38
42
|
private merchantCurrency;
|
|
43
|
+
private onBeforeConfirm?;
|
|
39
44
|
constructor({ paymentSessionData, parseData, logger, env, shipping, merchantAmount, merchantCurrency, }: {
|
|
40
45
|
paymentSessionData: string;
|
|
41
46
|
parseData: IPaymentSessionMetaData;
|
|
@@ -45,6 +50,8 @@ export declare class ApplePaySdk {
|
|
|
45
50
|
merchantAmount?: string | null;
|
|
46
51
|
merchantCurrency?: string | null;
|
|
47
52
|
});
|
|
53
|
+
/** 设置商户 onBeforeConfirm 回调(展码链路使用) */
|
|
54
|
+
setOnBeforeConfirm(callback: (() => Promise<boolean>) | null): void;
|
|
48
55
|
startPay(): Promise<unknown>;
|
|
49
56
|
begin(): Promise<unknown>;
|
|
50
57
|
private submitPay;
|