@alipay/ams-checkout 0.0.1781004142-dev.1 → 0.0.1781004142-dev.12
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 +109 -63
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +3 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +65 -23
- package/esm/plugin/component/channel.d.ts +8 -1
- package/esm/plugin/component/channel.js +131 -26
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/types/index.d.ts +2 -7
- package/esm/util/spm-map.d.ts +6 -0
- package/esm/util/spm-map.js +7 -1
- package/package.json +1 -1
|
@@ -60,7 +60,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
60
60
|
_defineProperty(this, "submitPayPromise", void 0);
|
|
61
61
|
_defineProperty(this, "elementEventCenter", void 0);
|
|
62
62
|
/** Current selected payment method type (e.g. 'APPLEPAY', 'CARD'), updated via paymentMethodChanged event */
|
|
63
|
-
_defineProperty(this, "currentPaymentMethodType",
|
|
63
|
+
_defineProperty(this, "currentPaymentMethodType", '');
|
|
64
64
|
_defineProperty(this, "onValidateFunc", function (event, target) {
|
|
65
65
|
return new Promise(function (resolve) {
|
|
66
66
|
event.emitAndListen({
|
|
@@ -374,7 +374,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
374
374
|
value: function () {
|
|
375
375
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
|
|
376
376
|
var _this3 = this;
|
|
377
|
-
var startEventId, res, logParams, isApplePay, BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, shouldContinue, isTimeout, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
377
|
+
var startEventId, res, logParams, isApplePay, paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timerId, timeoutPromise, shouldContinue, isTimeout, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
378
378
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
379
379
|
while (1) switch (_context4.prev = _context4.next) {
|
|
380
380
|
case 0:
|
|
@@ -402,73 +402,118 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
402
402
|
|
|
403
403
|
// Non-Apple Pay: execute onBeforeConfirm at SDK layer directly, abort on failure
|
|
404
404
|
isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
|
|
405
|
-
this.
|
|
406
|
-
title: 'sdk_element_submitPayment_beforeConfirm'
|
|
407
|
-
}, {
|
|
408
|
-
msg: safeStringify({
|
|
409
|
-
isApplePay: isApplePay,
|
|
410
|
-
hasOnBeforeConfirm: !!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm),
|
|
411
|
-
currentPaymentMethodType: this.currentPaymentMethodType
|
|
412
|
-
})
|
|
413
|
-
});
|
|
405
|
+
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
414
406
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
415
|
-
_context4.next =
|
|
407
|
+
_context4.next = 38;
|
|
416
408
|
break;
|
|
417
409
|
}
|
|
418
410
|
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
419
|
-
|
|
411
|
+
this.serviceMap.Log.logInfo({
|
|
412
|
+
title: 'sdk_before_confirm_start'
|
|
413
|
+
}, {
|
|
414
|
+
paymentMethodType: paymentMethodType,
|
|
415
|
+
path: 'nonApplePay_sync'
|
|
416
|
+
});
|
|
417
|
+
_context4.prev = 12;
|
|
420
418
|
timeoutPromise = new Promise(function (_, reject) {
|
|
421
|
-
|
|
419
|
+
timerId = setTimeout(function () {
|
|
422
420
|
return reject(new Error('onBeforeConfirm timed out'));
|
|
423
421
|
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
424
422
|
});
|
|
425
|
-
_context4.
|
|
423
|
+
_context4.prev = 14;
|
|
424
|
+
_context4.next = 17;
|
|
426
425
|
return Promise.race([submitParams.onBeforeConfirm(), timeoutPromise]);
|
|
427
|
-
case
|
|
426
|
+
case 17:
|
|
428
427
|
shouldContinue = _context4.sent;
|
|
428
|
+
case 18:
|
|
429
|
+
_context4.prev = 18;
|
|
430
|
+
clearTimeout(timerId);
|
|
431
|
+
return _context4.finish(18);
|
|
432
|
+
case 21:
|
|
429
433
|
if (!(shouldContinue === false)) {
|
|
430
|
-
_context4.next =
|
|
434
|
+
_context4.next = 26;
|
|
431
435
|
break;
|
|
432
436
|
}
|
|
437
|
+
this.serviceMap.Log.logInfo({
|
|
438
|
+
title: 'sdk_before_confirm_abort'
|
|
439
|
+
}, {
|
|
440
|
+
paymentMethodType: paymentMethodType,
|
|
441
|
+
path: 'nonApplePay_sync'
|
|
442
|
+
});
|
|
433
443
|
this.changeLoading(false);
|
|
444
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
445
|
+
eventCode: PaymentStatus.FAIL,
|
|
446
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
447
|
+
});
|
|
434
448
|
return _context4.abrupt("return", {
|
|
435
449
|
status: PaymentStatus.FAIL,
|
|
436
450
|
error: {
|
|
437
451
|
code: 'MERCHANT_CONFIRM_ABORT',
|
|
438
|
-
message: '
|
|
452
|
+
message: 'Merchant canceled payment.',
|
|
439
453
|
needChangeSessionForRetry: false
|
|
440
454
|
}
|
|
441
455
|
});
|
|
442
|
-
case
|
|
443
|
-
|
|
456
|
+
case 26:
|
|
457
|
+
this.serviceMap.Log.logInfo({
|
|
458
|
+
title: 'sdk_before_confirm_success'
|
|
459
|
+
}, {
|
|
460
|
+
paymentMethodType: paymentMethodType,
|
|
461
|
+
path: 'nonApplePay_sync'
|
|
462
|
+
});
|
|
463
|
+
_context4.next = 36;
|
|
444
464
|
break;
|
|
445
|
-
case
|
|
446
|
-
_context4.prev =
|
|
447
|
-
_context4.t0 = _context4["catch"](
|
|
448
|
-
this.changeLoading(false);
|
|
465
|
+
case 29:
|
|
466
|
+
_context4.prev = 29;
|
|
467
|
+
_context4.t0 = _context4["catch"](12);
|
|
449
468
|
isTimeout = _context4.t0 instanceof Error && _context4.t0.message === 'onBeforeConfirm timed out';
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
469
|
+
if (isTimeout) {
|
|
470
|
+
this.serviceMap.Log.logError({
|
|
471
|
+
title: 'sdk_before_confirm_timeout'
|
|
472
|
+
}, {
|
|
473
|
+
paymentMethodType: paymentMethodType,
|
|
474
|
+
path: 'nonApplePay_sync'
|
|
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
|
+
}
|
|
485
|
+
this.changeLoading(false);
|
|
486
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
487
|
+
eventCode: PaymentStatus.FAIL,
|
|
488
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
456
489
|
});
|
|
457
490
|
return _context4.abrupt("return", {
|
|
458
491
|
status: PaymentStatus.FAIL,
|
|
459
492
|
error: {
|
|
460
493
|
code: 'MERCHANT_CONFIRM_ABORT',
|
|
461
|
-
message:
|
|
494
|
+
message: 'Merchant canceled payment.',
|
|
462
495
|
needChangeSessionForRetry: false
|
|
463
496
|
}
|
|
464
497
|
});
|
|
465
|
-
case
|
|
498
|
+
case 36:
|
|
499
|
+
_context4.next = 39;
|
|
500
|
+
break;
|
|
501
|
+
case 38:
|
|
502
|
+
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
|
|
503
|
+
this.serviceMap.Log.logInfo({
|
|
504
|
+
title: 'sdk_before_confirm_skip'
|
|
505
|
+
}, {
|
|
506
|
+
paymentMethodType: paymentMethodType,
|
|
507
|
+
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
case 39:
|
|
466
511
|
recordResult = null;
|
|
467
|
-
_context4.prev =
|
|
468
|
-
_context4.next =
|
|
512
|
+
_context4.prev = 40;
|
|
513
|
+
_context4.next = 43;
|
|
469
514
|
return new Promise( /*#__PURE__*/function () {
|
|
470
515
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
471
|
-
var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
516
|
+
var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
472
517
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
473
518
|
while (1) switch (_context3.prev = _context3.next) {
|
|
474
519
|
case 0:
|
|
@@ -544,7 +589,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
544
589
|
return _context3.abrupt("return");
|
|
545
590
|
case 14:
|
|
546
591
|
if (!_this3.elementProcessors[ElementType.payment]) {
|
|
547
|
-
_context3.next =
|
|
592
|
+
_context3.next = 28;
|
|
548
593
|
break;
|
|
549
594
|
}
|
|
550
595
|
// Apple Pay: set onBeforeConfirm on paymentProcessor for event bridge callback after iframe authorization
|
|
@@ -558,21 +603,22 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
558
603
|
})
|
|
559
604
|
});
|
|
560
605
|
_this3.elementProcessors[ElementType.payment].setOnBeforeConfirm(hasBeforeConfirmForApplePay ? submitParams.onBeforeConfirm : null);
|
|
561
|
-
|
|
606
|
+
hasAmount = !!(submitParams !== null && submitParams !== void 0 && submitParams.amount);
|
|
607
|
+
hasCurrency = !!(submitParams !== null && submitParams !== void 0 && submitParams.currency);
|
|
608
|
+
if ((hasAmount || hasCurrency) && !(hasAmount && hasCurrency)) {
|
|
609
|
+
_this3.serviceMap.Log.logError({
|
|
610
|
+
title: 'sdk_element_submitPayment_amountCurrencyMismatch'
|
|
611
|
+
}, {
|
|
612
|
+
msg: safeStringify({
|
|
613
|
+
amount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount,
|
|
614
|
+
currency: submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency,
|
|
615
|
+
reason: 'amount and currency must be provided together, both ignored'
|
|
616
|
+
})
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
_this3.elementProcessors[ElementType.payment].setMerchantAmountOverride(hasAmount && hasCurrency ? submitParams.amount : null, hasAmount && hasCurrency ? submitParams.currency : null);
|
|
620
|
+
_context3.next = 24;
|
|
562
621
|
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, function (_submitParams$handleA) {
|
|
563
|
-
var hasAmount = !!(submitParams !== null && submitParams !== void 0 && submitParams.amount);
|
|
564
|
-
var hasCurrency = !!(submitParams !== null && submitParams !== void 0 && submitParams.currency);
|
|
565
|
-
if ((hasAmount || hasCurrency) && !(hasAmount && hasCurrency)) {
|
|
566
|
-
_this3.serviceMap.Log.logError({
|
|
567
|
-
title: 'sdk_element_submitPayment_amountCurrencyMismatch'
|
|
568
|
-
}, {
|
|
569
|
-
msg: safeStringify({
|
|
570
|
-
amount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount,
|
|
571
|
-
currency: submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency,
|
|
572
|
-
reason: 'amount and currency must be provided together, both ignored'
|
|
573
|
-
})
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
622
|
return _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
|
|
577
623
|
handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
|
|
578
624
|
shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
|
|
@@ -583,18 +629,18 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
583
629
|
hasBeforeConfirm: hasBeforeConfirmForApplePay
|
|
584
630
|
});
|
|
585
631
|
}());
|
|
586
|
-
case
|
|
632
|
+
case 24:
|
|
587
633
|
_yield$_this3$onValid2 = _context3.sent;
|
|
588
634
|
_data = _yield$_this3$onValid2.data;
|
|
589
635
|
// TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
|
|
590
636
|
// TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
|
|
591
637
|
recordResult = _data;
|
|
592
638
|
recordResultCallback(recordResult);
|
|
593
|
-
case
|
|
594
|
-
_context3.next =
|
|
639
|
+
case 28:
|
|
640
|
+
_context3.next = 37;
|
|
595
641
|
break;
|
|
596
|
-
case
|
|
597
|
-
_context3.prev =
|
|
642
|
+
case 30:
|
|
643
|
+
_context3.prev = 30;
|
|
598
644
|
_context3.t0 = _context3["catch"](2);
|
|
599
645
|
// 修复error为{}空对象的问题,上报stack&message
|
|
600
646
|
errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
|
|
@@ -611,20 +657,20 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
611
657
|
});
|
|
612
658
|
recordResult = errorResult;
|
|
613
659
|
recordResultCallback(errorResult);
|
|
614
|
-
case
|
|
660
|
+
case 37:
|
|
615
661
|
case "end":
|
|
616
662
|
return _context3.stop();
|
|
617
663
|
}
|
|
618
|
-
}, _callee3, null, [[2,
|
|
664
|
+
}, _callee3, null, [[2, 30]]);
|
|
619
665
|
}));
|
|
620
666
|
return function (_x2) {
|
|
621
667
|
return _ref3.apply(this, arguments);
|
|
622
668
|
};
|
|
623
669
|
}());
|
|
624
|
-
case
|
|
670
|
+
case 43:
|
|
625
671
|
return _context4.abrupt("return", _context4.sent);
|
|
626
|
-
case
|
|
627
|
-
_context4.prev =
|
|
672
|
+
case 44:
|
|
673
|
+
_context4.prev = 44;
|
|
628
674
|
_logParams = {
|
|
629
675
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
630
676
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -635,12 +681,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
635
681
|
};
|
|
636
682
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
637
683
|
this.changeLoading(false);
|
|
638
|
-
return _context4.finish(
|
|
639
|
-
case
|
|
684
|
+
return _context4.finish(44);
|
|
685
|
+
case 49:
|
|
640
686
|
case "end":
|
|
641
687
|
return _context4.stop();
|
|
642
688
|
}
|
|
643
|
-
}, _callee4, this, [[
|
|
689
|
+
}, _callee4, this, [[12, 29], [14,, 18, 21], [40,, 44, 49]]);
|
|
644
690
|
}));
|
|
645
691
|
function submitPayment(_x) {
|
|
646
692
|
return _submitPayment.apply(this, arguments);
|
|
@@ -8,7 +8,10 @@ declare class PaymentProcessor extends BaseElementProcessor {
|
|
|
8
8
|
* triggered via beforeConfirm event after Apple Pay authorization in iframe.
|
|
9
9
|
*/
|
|
10
10
|
private _onBeforeConfirm;
|
|
11
|
+
private _merchantAmount;
|
|
12
|
+
private _merchantCurrency;
|
|
11
13
|
setOnBeforeConfirm(callback: (() => Promise<boolean>) | null): void;
|
|
14
|
+
setMerchantAmountOverride(amount: string | null, currency: string | null): void;
|
|
12
15
|
onReady(extraParam: any): void;
|
|
13
16
|
getLogger(): LogService;
|
|
14
17
|
private addEventListener;
|
|
@@ -62,12 +62,24 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
62
62
|
* triggered via beforeConfirm event after Apple Pay authorization in iframe.
|
|
63
63
|
*/
|
|
64
64
|
_defineProperty(_assertThisInitialized(_this), "_onBeforeConfirm", null);
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "_merchantAmount", null);
|
|
66
|
+
_defineProperty(_assertThisInitialized(_this), "_merchantCurrency", null);
|
|
65
67
|
return _this;
|
|
66
68
|
}
|
|
67
69
|
_createClass(PaymentProcessor, [{
|
|
68
70
|
key: "setOnBeforeConfirm",
|
|
69
71
|
value: function setOnBeforeConfirm(callback) {
|
|
70
72
|
this._onBeforeConfirm = callback;
|
|
73
|
+
// 展码链路:同步设置 onBeforeConfirm 到 ApplePaySdk,确保 Chrome 展码支付时能调用商户回调
|
|
74
|
+
if (this.ApplePayService) {
|
|
75
|
+
this.ApplePayService.setOnBeforeConfirm(callback);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "setMerchantAmountOverride",
|
|
80
|
+
value: function setMerchantAmountOverride(amount, currency) {
|
|
81
|
+
this._merchantAmount = amount;
|
|
82
|
+
this._merchantCurrency = currency;
|
|
71
83
|
}
|
|
72
84
|
}, {
|
|
73
85
|
key: "onReady",
|
|
@@ -154,8 +166,12 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
154
166
|
parseData: paymentSessionObj,
|
|
155
167
|
logger: logger,
|
|
156
168
|
env: _this2.options.env.environment,
|
|
157
|
-
shipping: shipping
|
|
169
|
+
shipping: shipping,
|
|
170
|
+
merchantAmount: _this2._merchantAmount,
|
|
171
|
+
merchantCurrency: _this2._merchantCurrency
|
|
158
172
|
});
|
|
173
|
+
// Chrome 展码链路:同步 onBeforeConfirm 到当前 ApplePaySdk 实例
|
|
174
|
+
applePayService.setOnBeforeConfirm(_this2._onBeforeConfirm);
|
|
159
175
|
applePayService.startPay().then(function (res) {
|
|
160
176
|
_this2.eventCenter.dispatchToApp({
|
|
161
177
|
event: 'getApplePayToken',
|
|
@@ -178,19 +194,21 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
178
194
|
// requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
|
|
179
195
|
// and returns the result (continue/abort) to iframe via dispatchToApp.
|
|
180
196
|
this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
181
|
-
var BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, shouldContinue, isTimeout;
|
|
197
|
+
var paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, startTime, shouldContinue, isTimeout;
|
|
182
198
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
183
199
|
while (1) switch (_context.prev = _context.next) {
|
|
184
200
|
case 0:
|
|
185
|
-
|
|
186
|
-
title: 'sdk_element_beforeConfirm_event_received'
|
|
187
|
-
}, {
|
|
188
|
-
hasCallback: !!_this2._onBeforeConfirm
|
|
189
|
-
});
|
|
201
|
+
paymentMethodType = 'APPLEPAY';
|
|
190
202
|
if (_this2._onBeforeConfirm) {
|
|
191
|
-
_context.next =
|
|
203
|
+
_context.next = 5;
|
|
192
204
|
break;
|
|
193
205
|
}
|
|
206
|
+
logger.logInfo({
|
|
207
|
+
title: 'sdk_before_confirm_skip'
|
|
208
|
+
}, {
|
|
209
|
+
paymentMethodType: paymentMethodType,
|
|
210
|
+
path: 'applePay_eventBridge'
|
|
211
|
+
});
|
|
194
212
|
_this2.eventCenter.dispatchToApp({
|
|
195
213
|
event: EVENT.beforeConfirm.name,
|
|
196
214
|
data: {
|
|
@@ -199,18 +217,31 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
199
217
|
}
|
|
200
218
|
});
|
|
201
219
|
return _context.abrupt("return");
|
|
202
|
-
case
|
|
220
|
+
case 5:
|
|
203
221
|
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
204
|
-
|
|
222
|
+
logger.logInfo({
|
|
223
|
+
title: 'sdk_before_confirm_start'
|
|
224
|
+
}, {
|
|
225
|
+
paymentMethodType: paymentMethodType,
|
|
226
|
+
path: 'applePay_eventBridge'
|
|
227
|
+
});
|
|
228
|
+
_context.prev = 7;
|
|
205
229
|
timeoutPromise = new Promise(function (_, reject) {
|
|
206
230
|
return setTimeout(function () {
|
|
207
231
|
return reject(new Error('onBeforeConfirm timed out'));
|
|
208
232
|
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
209
233
|
});
|
|
210
|
-
|
|
234
|
+
startTime = Date.now();
|
|
235
|
+
_context.next = 12;
|
|
211
236
|
return Promise.race([_this2._onBeforeConfirm(), timeoutPromise]);
|
|
212
|
-
case
|
|
237
|
+
case 12:
|
|
213
238
|
shouldContinue = _context.sent;
|
|
239
|
+
if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
|
|
240
|
+
logger.logError({
|
|
241
|
+
title: 'sdk_before_confirm_timeout'
|
|
242
|
+
});
|
|
243
|
+
shouldContinue = false;
|
|
244
|
+
}
|
|
214
245
|
logger.logInfo({
|
|
215
246
|
title: 'sdk_element_beforeConfirm_callback_result'
|
|
216
247
|
}, {
|
|
@@ -223,17 +254,28 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
223
254
|
result: shouldContinue !== false
|
|
224
255
|
}
|
|
225
256
|
});
|
|
226
|
-
_context.next =
|
|
257
|
+
_context.next = 23;
|
|
227
258
|
break;
|
|
228
|
-
case
|
|
229
|
-
_context.prev =
|
|
230
|
-
_context.t0 = _context["catch"](
|
|
259
|
+
case 18:
|
|
260
|
+
_context.prev = 18;
|
|
261
|
+
_context.t0 = _context["catch"](7);
|
|
231
262
|
isTimeout = _context.t0 instanceof Error && _context.t0.message === 'onBeforeConfirm timed out';
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
263
|
+
if (isTimeout) {
|
|
264
|
+
logger.logError({
|
|
265
|
+
title: 'sdk_before_confirm_timeout'
|
|
266
|
+
}, {
|
|
267
|
+
paymentMethodType: paymentMethodType,
|
|
268
|
+
path: 'applePay_eventBridge'
|
|
269
|
+
});
|
|
270
|
+
} else {
|
|
271
|
+
logger.logError({
|
|
272
|
+
title: 'sdk_before_confirm_error'
|
|
273
|
+
}, {
|
|
274
|
+
paymentMethodType: paymentMethodType,
|
|
275
|
+
errorMessage: String((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0).slice(0, 200),
|
|
276
|
+
path: 'applePay_eventBridge'
|
|
277
|
+
});
|
|
278
|
+
}
|
|
237
279
|
_this2.eventCenter.dispatchToApp({
|
|
238
280
|
event: EVENT.beforeConfirm.name,
|
|
239
281
|
data: {
|
|
@@ -241,11 +283,11 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
241
283
|
result: false
|
|
242
284
|
}
|
|
243
285
|
});
|
|
244
|
-
case
|
|
286
|
+
case 23:
|
|
245
287
|
case "end":
|
|
246
288
|
return _context.stop();
|
|
247
289
|
}
|
|
248
|
-
}, _callee, null, [[
|
|
290
|
+
}, _callee, null, [[7, 18]]);
|
|
249
291
|
})));
|
|
250
292
|
}
|
|
251
293
|
}, {
|
|
@@ -34,13 +34,20 @@ export declare class ApplePaySdk {
|
|
|
34
34
|
private logger;
|
|
35
35
|
private env;
|
|
36
36
|
private shipping?;
|
|
37
|
-
|
|
37
|
+
private merchantAmount;
|
|
38
|
+
private merchantCurrency;
|
|
39
|
+
private onBeforeConfirm?;
|
|
40
|
+
constructor({ paymentSessionData, parseData, logger, env, shipping, merchantAmount, merchantCurrency, }: {
|
|
38
41
|
paymentSessionData: string;
|
|
39
42
|
parseData: IPaymentSessionMetaData;
|
|
40
43
|
logger: Logger;
|
|
41
44
|
env?: string;
|
|
42
45
|
shipping?: CKPShipping;
|
|
46
|
+
merchantAmount?: string | null;
|
|
47
|
+
merchantCurrency?: string | null;
|
|
43
48
|
});
|
|
49
|
+
/** 设置商户 onBeforeConfirm 回调(展码链路使用) */
|
|
50
|
+
setOnBeforeConfirm(callback: (() => Promise<boolean>) | null): void;
|
|
44
51
|
startPay(): Promise<unknown>;
|
|
45
52
|
begin(): Promise<unknown>;
|
|
46
53
|
private submitPay;
|