@alipay/ams-checkout 0.0.1781004142-dev.3 → 0.0.1781004142-dev.5
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/constant/index.d.ts +3 -0
- package/esm/constant/index.js +4 -0
- package/esm/core/component/element/elementController/index.d.ts +2 -0
- package/esm/core/component/element/elementController/index.js +162 -24
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +7 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +145 -35
- package/esm/core/component/element/type.d.ts +20 -0
- package/esm/plugin/component/channel.d.ts +1 -1
- package/esm/plugin/component/channel.js +1 -3
- package/esm/util/spm-map.d.ts +6 -0
- package/esm/util/spm-map.js +7 -1
- package/package.json +1 -1
package/esm/constant/index.d.ts
CHANGED
package/esm/constant/index.js
CHANGED
|
@@ -289,6 +289,10 @@ export var EVENT = {
|
|
|
289
289
|
submitPromiseCallback: {
|
|
290
290
|
name: 'onSubmitPayCallback'
|
|
291
291
|
},
|
|
292
|
+
// After Apple Pay authorization, before charge: notify SDK layer to execute merchant's onBeforeConfirm callback
|
|
293
|
+
beforeConfirm: {
|
|
294
|
+
name: 'onBeforeConfirm'
|
|
295
|
+
},
|
|
292
296
|
validateFieldsResult: {
|
|
293
297
|
name: 'validateFieldsResult',
|
|
294
298
|
forwardName: 'validateFieldsResultForward',
|
|
@@ -10,6 +10,8 @@ declare class ElementController {
|
|
|
10
10
|
private onStatusChangeCallback;
|
|
11
11
|
private submitPayPromise;
|
|
12
12
|
private elementEventCenter;
|
|
13
|
+
/** Current selected payment method type (e.g. 'APPLEPAY', 'CARD'), updated via paymentMethodChanged event */
|
|
14
|
+
private currentPaymentMethodType;
|
|
13
15
|
constructor(options: IElementOptions);
|
|
14
16
|
private initService;
|
|
15
17
|
private initElementProcessors;
|
|
@@ -41,7 +41,7 @@ import { ElementContainerService } from "../elementContainerService"; // 引入
|
|
|
41
41
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
|
42
42
|
import { EventCenter as ElementEventCenter } from "../EventCenter/index";
|
|
43
43
|
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
|
44
|
-
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
|
|
44
|
+
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EVENTNAME, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
|
|
45
45
|
import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeParse, safeStringify, showToast } from "../util";
|
|
46
46
|
var TIMEOUT_DURATION = 16000;
|
|
47
47
|
var ElementController = /*#__PURE__*/function () {
|
|
@@ -59,6 +59,8 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
59
59
|
// 新增变量
|
|
60
60
|
_defineProperty(this, "submitPayPromise", void 0);
|
|
61
61
|
_defineProperty(this, "elementEventCenter", void 0);
|
|
62
|
+
/** Current selected payment method type (e.g. 'APPLEPAY', 'CARD'), updated via paymentMethodChanged event */
|
|
63
|
+
_defineProperty(this, "currentPaymentMethodType", void 0);
|
|
62
64
|
_defineProperty(this, "onValidateFunc", function (event, target) {
|
|
63
65
|
return new Promise(function (resolve) {
|
|
64
66
|
event.emitAndListen({
|
|
@@ -372,7 +374,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
372
374
|
value: function () {
|
|
373
375
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
|
|
374
376
|
var _this3 = this;
|
|
375
|
-
var startEventId, res, logParams, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
377
|
+
var startEventId, res, logParams, isApplePay, paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, startTime, shouldContinue, isTimeout, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
376
378
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
377
379
|
while (1) switch (_context4.prev = _context4.next) {
|
|
378
380
|
case 0:
|
|
@@ -397,12 +399,114 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
397
399
|
return _context4.abrupt("return", Promise.resolve(res));
|
|
398
400
|
case 6:
|
|
399
401
|
this.changeLoading(true);
|
|
402
|
+
|
|
403
|
+
// Non-Apple Pay: execute onBeforeConfirm at SDK layer directly, abort on failure
|
|
404
|
+
isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
|
|
405
|
+
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
406
|
+
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
407
|
+
_context4.next = 34;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
411
|
+
this.serviceMap.Log.logInfo({
|
|
412
|
+
title: 'sdk_before_confirm_start'
|
|
413
|
+
}, {
|
|
414
|
+
paymentMethodType: paymentMethodType,
|
|
415
|
+
path: 'nonApplePay_sync'
|
|
416
|
+
});
|
|
417
|
+
_context4.prev = 12;
|
|
418
|
+
timeoutPromise = new Promise(function (_, reject) {
|
|
419
|
+
return setTimeout(function () {
|
|
420
|
+
return reject(new Error('onBeforeConfirm timed out'));
|
|
421
|
+
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
422
|
+
});
|
|
423
|
+
startTime = Date.now();
|
|
424
|
+
_context4.next = 17;
|
|
425
|
+
return Promise.race([submitParams.onBeforeConfirm(), timeoutPromise]);
|
|
426
|
+
case 17:
|
|
427
|
+
shouldContinue = _context4.sent;
|
|
428
|
+
if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
|
|
429
|
+
this.serviceMap.Log.logError({
|
|
430
|
+
title: 'sdk_before_confirm_timeout'
|
|
431
|
+
});
|
|
432
|
+
shouldContinue = false;
|
|
433
|
+
}
|
|
434
|
+
if (!(shouldContinue === false)) {
|
|
435
|
+
_context4.next = 23;
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
this.serviceMap.Log.logInfo({
|
|
439
|
+
title: 'sdk_before_confirm_abort'
|
|
440
|
+
}, {
|
|
441
|
+
paymentMethodType: paymentMethodType,
|
|
442
|
+
path: 'nonApplePay_sync'
|
|
443
|
+
});
|
|
444
|
+
this.changeLoading(false);
|
|
445
|
+
return _context4.abrupt("return", {
|
|
446
|
+
status: PaymentStatus.FAIL,
|
|
447
|
+
error: {
|
|
448
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
449
|
+
message: 'Payment was cancelled by merchant before confirmation.',
|
|
450
|
+
needChangeSessionForRetry: false
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
case 23:
|
|
454
|
+
this.serviceMap.Log.logInfo({
|
|
455
|
+
title: 'sdk_before_confirm_success'
|
|
456
|
+
}, {
|
|
457
|
+
paymentMethodType: paymentMethodType,
|
|
458
|
+
path: 'nonApplePay_sync'
|
|
459
|
+
});
|
|
460
|
+
_context4.next = 32;
|
|
461
|
+
break;
|
|
462
|
+
case 26:
|
|
463
|
+
_context4.prev = 26;
|
|
464
|
+
_context4.t0 = _context4["catch"](12);
|
|
465
|
+
isTimeout = _context4.t0 instanceof Error && _context4.t0.message === 'onBeforeConfirm timed out';
|
|
466
|
+
if (isTimeout) {
|
|
467
|
+
this.serviceMap.Log.logError({
|
|
468
|
+
title: 'sdk_before_confirm_timeout'
|
|
469
|
+
}, {
|
|
470
|
+
paymentMethodType: paymentMethodType,
|
|
471
|
+
path: 'nonApplePay_sync'
|
|
472
|
+
});
|
|
473
|
+
} else {
|
|
474
|
+
this.serviceMap.Log.logError({
|
|
475
|
+
title: 'sdk_before_confirm_error'
|
|
476
|
+
}, {
|
|
477
|
+
paymentMethodType: paymentMethodType,
|
|
478
|
+
errorMessage: String((_context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message) || _context4.t0).slice(0, 200),
|
|
479
|
+
path: 'nonApplePay_sync'
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
this.changeLoading(false);
|
|
483
|
+
return _context4.abrupt("return", {
|
|
484
|
+
status: PaymentStatus.FAIL,
|
|
485
|
+
error: {
|
|
486
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
487
|
+
message: isTimeout ? 'onBeforeConfirm timed out after 15 seconds.' : 'An error occurred during the before-confirm callback.',
|
|
488
|
+
needChangeSessionForRetry: false
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
case 32:
|
|
492
|
+
_context4.next = 35;
|
|
493
|
+
break;
|
|
494
|
+
case 34:
|
|
495
|
+
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
|
|
496
|
+
this.serviceMap.Log.logInfo({
|
|
497
|
+
title: 'sdk_before_confirm_skip'
|
|
498
|
+
}, {
|
|
499
|
+
paymentMethodType: paymentMethodType,
|
|
500
|
+
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
case 35:
|
|
400
504
|
recordResult = null;
|
|
401
|
-
_context4.prev =
|
|
402
|
-
_context4.next =
|
|
505
|
+
_context4.prev = 36;
|
|
506
|
+
_context4.next = 39;
|
|
403
507
|
return new Promise( /*#__PURE__*/function () {
|
|
404
508
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
405
|
-
var that, recordResultCallback, params, processStep,
|
|
509
|
+
var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
406
510
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
407
511
|
while (1) switch (_context3.prev = _context3.next) {
|
|
408
512
|
case 0:
|
|
@@ -478,26 +582,57 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
478
582
|
return _context3.abrupt("return");
|
|
479
583
|
case 14:
|
|
480
584
|
if (!_this3.elementProcessors[ElementType.payment]) {
|
|
481
|
-
_context3.next =
|
|
585
|
+
_context3.next = 24;
|
|
482
586
|
break;
|
|
483
587
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
|
|
588
|
+
// Apple Pay: set onBeforeConfirm on paymentProcessor for event bridge callback after iframe authorization
|
|
589
|
+
hasBeforeConfirmForApplePay = isApplePay && !!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm);
|
|
590
|
+
_this3.serviceMap.Log.logInfo({
|
|
591
|
+
title: 'sdk_element_submitPayment_setBeforeConfirm'
|
|
592
|
+
}, {
|
|
593
|
+
msg: safeStringify({
|
|
594
|
+
hasBeforeConfirmForApplePay: hasBeforeConfirmForApplePay,
|
|
595
|
+
isApplePay: isApplePay
|
|
596
|
+
})
|
|
597
|
+
});
|
|
598
|
+
_this3.elementProcessors[ElementType.payment].setOnBeforeConfirm(hasBeforeConfirmForApplePay ? submitParams.onBeforeConfirm : null);
|
|
599
|
+
_context3.next = 20;
|
|
600
|
+
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, function (_submitParams$handleA) {
|
|
601
|
+
var hasAmount = !!(submitParams !== null && submitParams !== void 0 && submitParams.amount);
|
|
602
|
+
var hasCurrency = !!(submitParams !== null && submitParams !== void 0 && submitParams.currency);
|
|
603
|
+
if ((hasAmount || hasCurrency) && !(hasAmount && hasCurrency)) {
|
|
604
|
+
_this3.serviceMap.Log.logError({
|
|
605
|
+
title: 'sdk_element_submitPayment_amountCurrencyMismatch'
|
|
606
|
+
}, {
|
|
607
|
+
msg: safeStringify({
|
|
608
|
+
amount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount,
|
|
609
|
+
currency: submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency,
|
|
610
|
+
reason: 'amount and currency must be provided together, both ignored'
|
|
611
|
+
})
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
return _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
|
|
615
|
+
handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
|
|
616
|
+
shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
|
|
617
|
+
}, hasAmount && hasCurrency ? {
|
|
618
|
+
amount: submitParams.amount,
|
|
619
|
+
currency: submitParams.currency
|
|
620
|
+
} : {}), {}, {
|
|
621
|
+
hasBeforeConfirm: hasBeforeConfirmForApplePay
|
|
622
|
+
});
|
|
623
|
+
}());
|
|
624
|
+
case 20:
|
|
490
625
|
_yield$_this3$onValid2 = _context3.sent;
|
|
491
626
|
_data = _yield$_this3$onValid2.data;
|
|
492
627
|
// TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
|
|
493
628
|
// TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
|
|
494
629
|
recordResult = _data;
|
|
495
630
|
recordResultCallback(recordResult);
|
|
496
|
-
case
|
|
497
|
-
_context3.next =
|
|
631
|
+
case 24:
|
|
632
|
+
_context3.next = 33;
|
|
498
633
|
break;
|
|
499
|
-
case
|
|
500
|
-
_context3.prev =
|
|
634
|
+
case 26:
|
|
635
|
+
_context3.prev = 26;
|
|
501
636
|
_context3.t0 = _context3["catch"](2);
|
|
502
637
|
// 修复error为{}空对象的问题,上报stack&message
|
|
503
638
|
errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
|
|
@@ -514,20 +649,20 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
514
649
|
});
|
|
515
650
|
recordResult = errorResult;
|
|
516
651
|
recordResultCallback(errorResult);
|
|
517
|
-
case
|
|
652
|
+
case 33:
|
|
518
653
|
case "end":
|
|
519
654
|
return _context3.stop();
|
|
520
655
|
}
|
|
521
|
-
}, _callee3, null, [[2,
|
|
656
|
+
}, _callee3, null, [[2, 26]]);
|
|
522
657
|
}));
|
|
523
658
|
return function (_x2) {
|
|
524
659
|
return _ref3.apply(this, arguments);
|
|
525
660
|
};
|
|
526
661
|
}());
|
|
527
|
-
case
|
|
662
|
+
case 39:
|
|
528
663
|
return _context4.abrupt("return", _context4.sent);
|
|
529
|
-
case
|
|
530
|
-
_context4.prev =
|
|
664
|
+
case 40:
|
|
665
|
+
_context4.prev = 40;
|
|
531
666
|
_logParams = {
|
|
532
667
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
533
668
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -538,12 +673,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
538
673
|
};
|
|
539
674
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
540
675
|
this.changeLoading(false);
|
|
541
|
-
return _context4.finish(
|
|
542
|
-
case
|
|
676
|
+
return _context4.finish(40);
|
|
677
|
+
case 45:
|
|
543
678
|
case "end":
|
|
544
679
|
return _context4.stop();
|
|
545
680
|
}
|
|
546
|
-
}, _callee4, this, [[
|
|
681
|
+
}, _callee4, this, [[12, 26], [36,, 40, 45]]);
|
|
547
682
|
}));
|
|
548
683
|
function submitPayment(_x) {
|
|
549
684
|
return _submitPayment.apply(this, arguments);
|
|
@@ -628,6 +763,9 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
628
763
|
var _this4$submitPayPromi;
|
|
629
764
|
(_this4$submitPayPromi = _this4.submitPayPromise) === null || _this4$submitPayPromi === void 0 || _this4$submitPayPromi.call(_this4, data);
|
|
630
765
|
});
|
|
766
|
+
this.serviceMap.EventCenter.listen(EVENTNAME.PAYMENTMETHODCHANGED, function (data) {
|
|
767
|
+
_this4.currentPaymentMethodType = (data === null || data === void 0 ? void 0 : data.type) || '';
|
|
768
|
+
});
|
|
631
769
|
}
|
|
632
770
|
}, {
|
|
633
771
|
key: "sendRequestAndWaitWebLaunch",
|
|
@@ -2,6 +2,13 @@ import { LogService } from '../../../../foundation/service/log';
|
|
|
2
2
|
import BaseElementProcessor from './baseElementProcessor';
|
|
3
3
|
declare class PaymentProcessor extends BaseElementProcessor {
|
|
4
4
|
private ApplePayService;
|
|
5
|
+
/**
|
|
6
|
+
* Merchant's onBeforeConfirm callback reference, used in Apple Pay scenario only.
|
|
7
|
+
* Set by elementController.submitPayment before payment,
|
|
8
|
+
* triggered via beforeConfirm event after Apple Pay authorization in iframe.
|
|
9
|
+
*/
|
|
10
|
+
private _onBeforeConfirm;
|
|
11
|
+
setOnBeforeConfirm(callback: (() => Promise<boolean>) | null): void;
|
|
5
12
|
onReady(extraParam: any): void;
|
|
6
13
|
getLogger(): LogService;
|
|
7
14
|
private addEventListener;
|
|
@@ -56,9 +56,20 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
56
56
|
// parameterInitAndCheck(): void {}
|
|
57
57
|
// apple pay
|
|
58
58
|
_defineProperty(_assertThisInitialized(_this), "ApplePayService", void 0);
|
|
59
|
+
/**
|
|
60
|
+
* Merchant's onBeforeConfirm callback reference, used in Apple Pay scenario only.
|
|
61
|
+
* Set by elementController.submitPayment before payment,
|
|
62
|
+
* triggered via beforeConfirm event after Apple Pay authorization in iframe.
|
|
63
|
+
*/
|
|
64
|
+
_defineProperty(_assertThisInitialized(_this), "_onBeforeConfirm", null);
|
|
59
65
|
return _this;
|
|
60
66
|
}
|
|
61
67
|
_createClass(PaymentProcessor, [{
|
|
68
|
+
key: "setOnBeforeConfirm",
|
|
69
|
+
value: function setOnBeforeConfirm(callback) {
|
|
70
|
+
this._onBeforeConfirm = callback;
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
62
73
|
key: "onReady",
|
|
63
74
|
value: function onReady(extraParam) {
|
|
64
75
|
var _this$elementContaine, _this$elementContaine2, _this$elementContaine3, _this$elementContaine4, _this$elementContaine5;
|
|
@@ -163,19 +174,118 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
163
174
|
});
|
|
164
175
|
});
|
|
165
176
|
});
|
|
177
|
+
// Apple Pay event bridge: after user authorization (FaceID/TouchID) in iframe, before actual charge,
|
|
178
|
+
// requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
|
|
179
|
+
// and returns the result (continue/abort) to iframe via dispatchToApp.
|
|
180
|
+
this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
181
|
+
var paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, startTime, shouldContinue, isTimeout;
|
|
182
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
183
|
+
while (1) switch (_context.prev = _context.next) {
|
|
184
|
+
case 0:
|
|
185
|
+
paymentMethodType = 'APPLEPAY';
|
|
186
|
+
if (_this2._onBeforeConfirm) {
|
|
187
|
+
_context.next = 5;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
logger.logInfo({
|
|
191
|
+
title: 'sdk_before_confirm_skip'
|
|
192
|
+
}, {
|
|
193
|
+
paymentMethodType: paymentMethodType,
|
|
194
|
+
path: 'applePay_eventBridge'
|
|
195
|
+
});
|
|
196
|
+
_this2.eventCenter.dispatchToApp({
|
|
197
|
+
event: EVENT.beforeConfirm.name,
|
|
198
|
+
data: {
|
|
199
|
+
success: true,
|
|
200
|
+
result: true
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return _context.abrupt("return");
|
|
204
|
+
case 5:
|
|
205
|
+
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
206
|
+
logger.logInfo({
|
|
207
|
+
title: 'sdk_before_confirm_start'
|
|
208
|
+
}, {
|
|
209
|
+
paymentMethodType: paymentMethodType,
|
|
210
|
+
path: 'applePay_eventBridge'
|
|
211
|
+
});
|
|
212
|
+
_context.prev = 7;
|
|
213
|
+
timeoutPromise = new Promise(function (_, reject) {
|
|
214
|
+
return setTimeout(function () {
|
|
215
|
+
return reject(new Error('onBeforeConfirm timed out'));
|
|
216
|
+
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
217
|
+
});
|
|
218
|
+
startTime = Date.now();
|
|
219
|
+
_context.next = 12;
|
|
220
|
+
return Promise.race([_this2._onBeforeConfirm(), timeoutPromise]);
|
|
221
|
+
case 12:
|
|
222
|
+
shouldContinue = _context.sent;
|
|
223
|
+
if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
|
|
224
|
+
logger.logError({
|
|
225
|
+
title: 'sdk_before_confirm_timeout'
|
|
226
|
+
});
|
|
227
|
+
shouldContinue = false;
|
|
228
|
+
}
|
|
229
|
+
logger.logInfo({
|
|
230
|
+
title: 'sdk_element_beforeConfirm_callback_result'
|
|
231
|
+
}, {
|
|
232
|
+
shouldContinue: shouldContinue
|
|
233
|
+
});
|
|
234
|
+
_this2.eventCenter.dispatchToApp({
|
|
235
|
+
event: EVENT.beforeConfirm.name,
|
|
236
|
+
data: {
|
|
237
|
+
success: true,
|
|
238
|
+
result: shouldContinue !== false
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
_context.next = 23;
|
|
242
|
+
break;
|
|
243
|
+
case 18:
|
|
244
|
+
_context.prev = 18;
|
|
245
|
+
_context.t0 = _context["catch"](7);
|
|
246
|
+
isTimeout = _context.t0 instanceof Error && _context.t0.message === 'onBeforeConfirm timed out';
|
|
247
|
+
if (isTimeout) {
|
|
248
|
+
logger.logError({
|
|
249
|
+
title: 'sdk_before_confirm_timeout'
|
|
250
|
+
}, {
|
|
251
|
+
paymentMethodType: paymentMethodType,
|
|
252
|
+
path: 'applePay_eventBridge'
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
logger.logError({
|
|
256
|
+
title: 'sdk_before_confirm_error'
|
|
257
|
+
}, {
|
|
258
|
+
paymentMethodType: paymentMethodType,
|
|
259
|
+
errorMessage: String((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0).slice(0, 200),
|
|
260
|
+
path: 'applePay_eventBridge'
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
_this2.eventCenter.dispatchToApp({
|
|
264
|
+
event: EVENT.beforeConfirm.name,
|
|
265
|
+
data: {
|
|
266
|
+
success: false,
|
|
267
|
+
result: false
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
case 23:
|
|
271
|
+
case "end":
|
|
272
|
+
return _context.stop();
|
|
273
|
+
}
|
|
274
|
+
}, _callee, null, [[7, 18]]);
|
|
275
|
+
})));
|
|
166
276
|
}
|
|
167
277
|
}, {
|
|
168
278
|
key: "initApplePaySdk",
|
|
169
279
|
value: function () {
|
|
170
|
-
var _initApplePaySdk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
280
|
+
var _initApplePaySdk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
171
281
|
var _this$elementContaine6;
|
|
172
|
-
var
|
|
173
|
-
return _regeneratorRuntime().wrap(function
|
|
174
|
-
while (1) switch (
|
|
282
|
+
var _ref2, paymentSessionObj, paymentSession;
|
|
283
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
284
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
175
285
|
case 0:
|
|
176
|
-
|
|
286
|
+
_ref2 = ((_this$elementContaine6 = this.elementContainer) === null || _this$elementContaine6 === void 0 ? void 0 : _this$elementContaine6.getPaymentContext()) || {}, paymentSessionObj = _ref2.paymentSessionObj, paymentSession = _ref2.paymentSession;
|
|
177
287
|
if (!isSkipRenderPaymentMethod(paymentSessionObj)) {
|
|
178
|
-
|
|
288
|
+
_context2.next = 13;
|
|
179
289
|
break;
|
|
180
290
|
}
|
|
181
291
|
this.ApplePayService = new ApplePaySdk({
|
|
@@ -184,29 +294,29 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
184
294
|
logger: logger,
|
|
185
295
|
env: this.options.env.environment
|
|
186
296
|
});
|
|
187
|
-
|
|
297
|
+
_context2.prev = 3;
|
|
188
298
|
logger.logInfo({
|
|
189
299
|
title: 'a3753.b107385.c398110'
|
|
190
300
|
});
|
|
191
|
-
|
|
301
|
+
_context2.next = 7;
|
|
192
302
|
return this.ApplePayService.initApplePaySession();
|
|
193
303
|
case 7:
|
|
194
304
|
logger.logInfo({
|
|
195
305
|
title: 'a3753.b107385.c398112'
|
|
196
306
|
});
|
|
197
|
-
|
|
307
|
+
_context2.next = 13;
|
|
198
308
|
break;
|
|
199
309
|
case 10:
|
|
200
|
-
|
|
201
|
-
|
|
310
|
+
_context2.prev = 10;
|
|
311
|
+
_context2.t0 = _context2["catch"](3);
|
|
202
312
|
logger.logError({
|
|
203
313
|
title: 'a3753.b107385.c398111'
|
|
204
314
|
});
|
|
205
315
|
case 13:
|
|
206
316
|
case "end":
|
|
207
|
-
return
|
|
317
|
+
return _context2.stop();
|
|
208
318
|
}
|
|
209
|
-
},
|
|
319
|
+
}, _callee2, this, [[3, 10]]);
|
|
210
320
|
}));
|
|
211
321
|
function initApplePaySdk() {
|
|
212
322
|
return _initApplePaySdk.apply(this, arguments);
|
|
@@ -227,20 +337,20 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
227
337
|
}
|
|
228
338
|
}, {
|
|
229
339
|
key: "generateIframeSrc",
|
|
230
|
-
value: function generateIframeSrc(
|
|
231
|
-
var link =
|
|
232
|
-
instanceId =
|
|
340
|
+
value: function generateIframeSrc(_ref3) {
|
|
341
|
+
var link = _ref3.link,
|
|
342
|
+
instanceId = _ref3.instanceId;
|
|
233
343
|
this.instanceId = instanceId;
|
|
234
|
-
var
|
|
235
|
-
paymentSession =
|
|
236
|
-
paymentSessionObj =
|
|
237
|
-
sdkMetaData =
|
|
344
|
+
var _ref4 = this.elementContainer.getPaymentContext() || {},
|
|
345
|
+
paymentSession = _ref4.paymentSession,
|
|
346
|
+
paymentSessionObj = _ref4.paymentSessionObj,
|
|
347
|
+
sdkMetaData = _ref4.sdkMetaData;
|
|
238
348
|
var _this$options = this.options,
|
|
239
349
|
environment = _this$options.env.environment,
|
|
240
350
|
analytics = _this$options.analytics,
|
|
241
351
|
locale = _this$options.locale;
|
|
242
|
-
var
|
|
243
|
-
extendInfo =
|
|
352
|
+
var _ref5 = paymentSessionObj || {},
|
|
353
|
+
extendInfo = _ref5.extendInfo;
|
|
244
354
|
var url = _generateIframeSrc({
|
|
245
355
|
paymentSession: paymentSession,
|
|
246
356
|
paymentSessionObj: paymentSessionObj,
|
|
@@ -258,19 +368,19 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
258
368
|
}, {
|
|
259
369
|
key: "obtainData",
|
|
260
370
|
value: function () {
|
|
261
|
-
var _obtainData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
371
|
+
var _obtainData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
262
372
|
var _paymentSessionObj$co,
|
|
263
373
|
_this3 = this;
|
|
264
|
-
var requestService, _this$elementContaine7, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$options2, environment, locale,
|
|
265
|
-
return _regeneratorRuntime().wrap(function
|
|
266
|
-
while (1) switch (
|
|
374
|
+
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;
|
|
375
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
376
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
267
377
|
case 0:
|
|
268
378
|
requestService = ServiceProvider.getInstance(this.instanceId).getService('Requester');
|
|
269
379
|
_this$elementContaine7 = this.elementContainer.getPaymentContext(), paymentSession = _this$elementContaine7.paymentSession, paymentSessionObj = _this$elementContaine7.paymentSessionObj, displayInfo = _this$elementContaine7.displayInfo;
|
|
270
380
|
_displayInfo = displayInfo;
|
|
271
381
|
debugProps = _displayInfo.debugProps;
|
|
272
382
|
_this$options2 = this.options, environment = _this$options2.env.environment, locale = _this$options2.locale;
|
|
273
|
-
|
|
383
|
+
_ref6 = paymentSessionObj || {}, paymentSessionConfig = _ref6.paymentSessionConfig;
|
|
274
384
|
hostSign = paymentSession.split('&&')[1] || '';
|
|
275
385
|
isConnect = paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$co = paymentSessionObj.connectFactor) === null || _paymentSessionObj$co === void 0 ? void 0 : _paymentSessionObj$co.enableConnect;
|
|
276
386
|
LOCAL_MOCK = (debugProps === null || debugProps === void 0 ? void 0 : debugProps.isDebug) && (debugProps === null || debugProps === void 0 ? void 0 : debugProps.local_mock);
|
|
@@ -407,10 +517,10 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
407
517
|
});
|
|
408
518
|
});
|
|
409
519
|
};
|
|
410
|
-
|
|
520
|
+
_context3.next = 15;
|
|
411
521
|
return Promise.all(isConnect ? [generateActionQueryPromise(), generateOneAccountQueryPromise()] : [generateActionQueryPromise()]);
|
|
412
522
|
case 15:
|
|
413
|
-
_yield$Promise$all =
|
|
523
|
+
_yield$Promise$all = _context3.sent;
|
|
414
524
|
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
415
525
|
originActionQueryResult = _yield$Promise$all2[0];
|
|
416
526
|
originOneAccountQueryResult = _yield$Promise$all2[1];
|
|
@@ -418,15 +528,15 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
418
528
|
originActionQueryResult: originActionQueryResult,
|
|
419
529
|
originOneAccountQueryResult: originOneAccountQueryResult
|
|
420
530
|
};
|
|
421
|
-
return
|
|
531
|
+
return _context3.abrupt("return", {
|
|
422
532
|
originActionQueryResult: originActionQueryResult,
|
|
423
533
|
originOneAccountQueryResult: originOneAccountQueryResult
|
|
424
534
|
});
|
|
425
535
|
case 21:
|
|
426
536
|
case "end":
|
|
427
|
-
return
|
|
537
|
+
return _context3.stop();
|
|
428
538
|
}
|
|
429
|
-
},
|
|
539
|
+
}, _callee3, this);
|
|
430
540
|
}));
|
|
431
541
|
function obtainData() {
|
|
432
542
|
return _obtainData.apply(this, arguments);
|
|
@@ -441,9 +551,9 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
441
551
|
}
|
|
442
552
|
}, {
|
|
443
553
|
key: "update",
|
|
444
|
-
value: function update(
|
|
445
|
-
var data =
|
|
446
|
-
paymentSessionData =
|
|
554
|
+
value: function update(_ref7) {
|
|
555
|
+
var data = _ref7.data,
|
|
556
|
+
paymentSessionData = _ref7.paymentSessionData;
|
|
447
557
|
var _parseSessionData = parseSessionData(paymentSessionData),
|
|
448
558
|
_parseSessionData2 = _slicedToArray(_parseSessionData, 2),
|
|
449
559
|
parseData = _parseSessionData2[0],
|
|
@@ -287,6 +287,26 @@ export interface AddressSubmitData {
|
|
|
287
287
|
export interface SubmitFuncParams {
|
|
288
288
|
handleActions?: boolean;
|
|
289
289
|
shippingInfo?: ShippingInfo;
|
|
290
|
+
/**
|
|
291
|
+
* Amount displayed on the Apple Pay payment sheet, e.g. '10.99'.
|
|
292
|
+
* Display only; actual charge amount is controlled by server.
|
|
293
|
+
* Must be provided together with `currency`. Only effective for Apple Pay.
|
|
294
|
+
*/
|
|
295
|
+
amount?: string;
|
|
296
|
+
/**
|
|
297
|
+
* Currency code displayed on the Apple Pay payment sheet, e.g. 'USD'.
|
|
298
|
+
* Follows ISO 4217 standard. Must be provided together with `amount`. Only effective for Apple Pay.
|
|
299
|
+
*/
|
|
300
|
+
currency?: string;
|
|
301
|
+
/**
|
|
302
|
+
* Pre-confirmation callback. Executed after user authorization but before actual charge,
|
|
303
|
+
* allowing merchant to create order at this point.
|
|
304
|
+
* - Only effective when payment method is Apple Pay
|
|
305
|
+
* - Invoked via event bridge after user FaceID/TouchID authorization on the payment sheet
|
|
306
|
+
* - Return true: proceed with charge
|
|
307
|
+
* - Return false / timeout / throw error: abort payment, returns MERCHANT_CONFIRM_ABORT error code
|
|
308
|
+
*/
|
|
309
|
+
onBeforeConfirm?: () => Promise<boolean>;
|
|
290
310
|
}
|
|
291
311
|
export interface SubmitServiceParams extends PaymentSubmitData {
|
|
292
312
|
accountInfo: AuthSubmitData['accountInfo'];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CKPShipping } from '../../core/component/element/type';
|
|
2
1
|
import { type EventPayload, type IPaymentSessionMetaData } from '../../types';
|
|
2
|
+
import type { CKPShipping } from '../../core/component/element/type';
|
|
3
3
|
import { Logger } from '../../util/logger';
|
|
4
4
|
export type IChannelBehavior = {
|
|
5
5
|
usePaymentSessionAsQueryResult: boolean;
|
|
@@ -89,9 +89,7 @@ export var handleGooglePay = function handleGooglePay(data) {
|
|
|
89
89
|
var script = document.createElement('script');
|
|
90
90
|
script.src = 'https://pay.google.com/gp/p/js/pay.js';
|
|
91
91
|
script.async = true;
|
|
92
|
-
|
|
93
|
-
// 导致不支持 CORS 的第三方脚本(如 pay.google.com)加载失败
|
|
94
|
-
Node.prototype.appendChild.call(document.body, script);
|
|
92
|
+
document.body.appendChild(script);
|
|
95
93
|
// 执行googlePay sdk
|
|
96
94
|
script.onload = function () {
|
|
97
95
|
var paymentsClient = new window.google.payments.api.PaymentsClient({
|
package/esm/util/spm-map.d.ts
CHANGED
|
@@ -208,4 +208,10 @@ export declare const SPM_MAP: {
|
|
|
208
208
|
'Abnormal params recurringInfo': string;
|
|
209
209
|
'Payment processing but user dismissed the sheet': string;
|
|
210
210
|
'User dismissed the sheet': string;
|
|
211
|
+
sdk_before_confirm_start: string;
|
|
212
|
+
sdk_before_confirm_success: string;
|
|
213
|
+
sdk_before_confirm_abort: string;
|
|
214
|
+
sdk_before_confirm_error: string;
|
|
215
|
+
sdk_before_confirm_timeout: string;
|
|
216
|
+
sdk_before_confirm_skip: string;
|
|
211
217
|
};
|