@alipay/ams-checkout 0.0.1781004142-dev.8 → 0.0.1781004142-dev.9
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 +59 -51
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +3 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +11 -1
- package/esm/plugin/component/channel.d.ts +5 -1
- package/esm/plugin/component/channel.js +11 -3
- 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, paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS,
|
|
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:
|
|
@@ -404,7 +404,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
404
404
|
isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
|
|
405
405
|
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
406
406
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
407
|
-
_context4.next =
|
|
407
|
+
_context4.next = 38;
|
|
408
408
|
break;
|
|
409
409
|
}
|
|
410
410
|
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
@@ -416,23 +416,22 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
416
416
|
});
|
|
417
417
|
_context4.prev = 12;
|
|
418
418
|
timeoutPromise = new Promise(function (_, reject) {
|
|
419
|
-
|
|
419
|
+
timerId = setTimeout(function () {
|
|
420
420
|
return reject(new Error('onBeforeConfirm timed out'));
|
|
421
421
|
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
422
422
|
});
|
|
423
|
-
|
|
423
|
+
_context4.prev = 14;
|
|
424
424
|
_context4.next = 17;
|
|
425
425
|
return Promise.race([submitParams.onBeforeConfirm(), timeoutPromise]);
|
|
426
426
|
case 17:
|
|
427
427
|
shouldContinue = _context4.sent;
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
428
|
+
case 18:
|
|
429
|
+
_context4.prev = 18;
|
|
430
|
+
clearTimeout(timerId);
|
|
431
|
+
return _context4.finish(18);
|
|
432
|
+
case 21:
|
|
434
433
|
if (!(shouldContinue === false)) {
|
|
435
|
-
_context4.next =
|
|
434
|
+
_context4.next = 26;
|
|
436
435
|
break;
|
|
437
436
|
}
|
|
438
437
|
this.serviceMap.Log.logInfo({
|
|
@@ -442,6 +441,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
442
441
|
path: 'nonApplePay_sync'
|
|
443
442
|
});
|
|
444
443
|
this.changeLoading(false);
|
|
444
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
445
|
+
eventCode: PaymentStatus.FAIL,
|
|
446
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
447
|
+
});
|
|
445
448
|
return _context4.abrupt("return", {
|
|
446
449
|
status: PaymentStatus.FAIL,
|
|
447
450
|
error: {
|
|
@@ -450,17 +453,17 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
450
453
|
needChangeSessionForRetry: false
|
|
451
454
|
}
|
|
452
455
|
});
|
|
453
|
-
case
|
|
456
|
+
case 26:
|
|
454
457
|
this.serviceMap.Log.logInfo({
|
|
455
458
|
title: 'sdk_before_confirm_success'
|
|
456
459
|
}, {
|
|
457
460
|
paymentMethodType: paymentMethodType,
|
|
458
461
|
path: 'nonApplePay_sync'
|
|
459
462
|
});
|
|
460
|
-
_context4.next =
|
|
463
|
+
_context4.next = 36;
|
|
461
464
|
break;
|
|
462
|
-
case
|
|
463
|
-
_context4.prev =
|
|
465
|
+
case 29:
|
|
466
|
+
_context4.prev = 29;
|
|
464
467
|
_context4.t0 = _context4["catch"](12);
|
|
465
468
|
isTimeout = _context4.t0 instanceof Error && _context4.t0.message === 'onBeforeConfirm timed out';
|
|
466
469
|
if (isTimeout) {
|
|
@@ -480,6 +483,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
480
483
|
});
|
|
481
484
|
}
|
|
482
485
|
this.changeLoading(false);
|
|
486
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
487
|
+
eventCode: PaymentStatus.FAIL,
|
|
488
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
489
|
+
});
|
|
483
490
|
return _context4.abrupt("return", {
|
|
484
491
|
status: PaymentStatus.FAIL,
|
|
485
492
|
error: {
|
|
@@ -488,10 +495,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
488
495
|
needChangeSessionForRetry: false
|
|
489
496
|
}
|
|
490
497
|
});
|
|
491
|
-
case
|
|
492
|
-
_context4.next =
|
|
498
|
+
case 36:
|
|
499
|
+
_context4.next = 39;
|
|
493
500
|
break;
|
|
494
|
-
case
|
|
501
|
+
case 38:
|
|
495
502
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
|
|
496
503
|
this.serviceMap.Log.logInfo({
|
|
497
504
|
title: 'sdk_before_confirm_skip'
|
|
@@ -500,13 +507,13 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
500
507
|
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
501
508
|
});
|
|
502
509
|
}
|
|
503
|
-
case
|
|
510
|
+
case 39:
|
|
504
511
|
recordResult = null;
|
|
505
|
-
_context4.prev =
|
|
506
|
-
_context4.next =
|
|
512
|
+
_context4.prev = 40;
|
|
513
|
+
_context4.next = 43;
|
|
507
514
|
return new Promise( /*#__PURE__*/function () {
|
|
508
515
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
509
|
-
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;
|
|
510
517
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
511
518
|
while (1) switch (_context3.prev = _context3.next) {
|
|
512
519
|
case 0:
|
|
@@ -582,7 +589,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
582
589
|
return _context3.abrupt("return");
|
|
583
590
|
case 14:
|
|
584
591
|
if (!_this3.elementProcessors[ElementType.payment]) {
|
|
585
|
-
_context3.next =
|
|
592
|
+
_context3.next = 28;
|
|
586
593
|
break;
|
|
587
594
|
}
|
|
588
595
|
// Apple Pay: set onBeforeConfirm on paymentProcessor for event bridge callback after iframe authorization
|
|
@@ -596,21 +603,22 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
596
603
|
})
|
|
597
604
|
});
|
|
598
605
|
_this3.elementProcessors[ElementType.payment].setOnBeforeConfirm(hasBeforeConfirmForApplePay ? submitParams.onBeforeConfirm : null);
|
|
599
|
-
|
|
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;
|
|
600
621
|
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
622
|
return _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
|
|
615
623
|
handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
|
|
616
624
|
shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
|
|
@@ -621,18 +629,18 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
621
629
|
hasBeforeConfirm: hasBeforeConfirmForApplePay
|
|
622
630
|
});
|
|
623
631
|
}());
|
|
624
|
-
case
|
|
632
|
+
case 24:
|
|
625
633
|
_yield$_this3$onValid2 = _context3.sent;
|
|
626
634
|
_data = _yield$_this3$onValid2.data;
|
|
627
635
|
// TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
|
|
628
636
|
// TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
|
|
629
637
|
recordResult = _data;
|
|
630
638
|
recordResultCallback(recordResult);
|
|
631
|
-
case
|
|
632
|
-
_context3.next =
|
|
639
|
+
case 28:
|
|
640
|
+
_context3.next = 37;
|
|
633
641
|
break;
|
|
634
|
-
case
|
|
635
|
-
_context3.prev =
|
|
642
|
+
case 30:
|
|
643
|
+
_context3.prev = 30;
|
|
636
644
|
_context3.t0 = _context3["catch"](2);
|
|
637
645
|
// 修复error为{}空对象的问题,上报stack&message
|
|
638
646
|
errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
|
|
@@ -649,20 +657,20 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
649
657
|
});
|
|
650
658
|
recordResult = errorResult;
|
|
651
659
|
recordResultCallback(errorResult);
|
|
652
|
-
case
|
|
660
|
+
case 37:
|
|
653
661
|
case "end":
|
|
654
662
|
return _context3.stop();
|
|
655
663
|
}
|
|
656
|
-
}, _callee3, null, [[2,
|
|
664
|
+
}, _callee3, null, [[2, 30]]);
|
|
657
665
|
}));
|
|
658
666
|
return function (_x2) {
|
|
659
667
|
return _ref3.apply(this, arguments);
|
|
660
668
|
};
|
|
661
669
|
}());
|
|
662
|
-
case
|
|
670
|
+
case 43:
|
|
663
671
|
return _context4.abrupt("return", _context4.sent);
|
|
664
|
-
case
|
|
665
|
-
_context4.prev =
|
|
672
|
+
case 44:
|
|
673
|
+
_context4.prev = 44;
|
|
666
674
|
_logParams = {
|
|
667
675
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
668
676
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -673,12 +681,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
673
681
|
};
|
|
674
682
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
675
683
|
this.changeLoading(false);
|
|
676
|
-
return _context4.finish(
|
|
677
|
-
case
|
|
684
|
+
return _context4.finish(44);
|
|
685
|
+
case 49:
|
|
678
686
|
case "end":
|
|
679
687
|
return _context4.stop();
|
|
680
688
|
}
|
|
681
|
-
}, _callee4, this, [[12,
|
|
689
|
+
}, _callee4, this, [[12, 29], [14,, 18, 21], [40,, 44, 49]]);
|
|
682
690
|
}));
|
|
683
691
|
function submitPayment(_x) {
|
|
684
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,6 +62,8 @@ 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, [{
|
|
@@ -69,6 +71,12 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
69
71
|
value: function setOnBeforeConfirm(callback) {
|
|
70
72
|
this._onBeforeConfirm = callback;
|
|
71
73
|
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "setMerchantAmountOverride",
|
|
76
|
+
value: function setMerchantAmountOverride(amount, currency) {
|
|
77
|
+
this._merchantAmount = amount;
|
|
78
|
+
this._merchantCurrency = currency;
|
|
79
|
+
}
|
|
72
80
|
}, {
|
|
73
81
|
key: "onReady",
|
|
74
82
|
value: function onReady(extraParam) {
|
|
@@ -154,7 +162,9 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
154
162
|
parseData: paymentSessionObj,
|
|
155
163
|
logger: logger,
|
|
156
164
|
env: _this2.options.env.environment,
|
|
157
|
-
shipping: shipping
|
|
165
|
+
shipping: shipping,
|
|
166
|
+
merchantAmount: _this2._merchantAmount,
|
|
167
|
+
merchantCurrency: _this2._merchantCurrency
|
|
158
168
|
});
|
|
159
169
|
applePayService.startPay().then(function (res) {
|
|
160
170
|
_this2.eventCenter.dispatchToApp({
|
|
@@ -34,12 +34,16 @@ export declare class ApplePaySdk {
|
|
|
34
34
|
private logger;
|
|
35
35
|
private env;
|
|
36
36
|
private shipping?;
|
|
37
|
-
|
|
37
|
+
private merchantAmount;
|
|
38
|
+
private merchantCurrency;
|
|
39
|
+
constructor({ paymentSessionData, parseData, logger, env, shipping, merchantAmount, merchantCurrency, }: {
|
|
38
40
|
paymentSessionData: string;
|
|
39
41
|
parseData: IPaymentSessionMetaData;
|
|
40
42
|
logger: Logger;
|
|
41
43
|
env?: string;
|
|
42
44
|
shipping?: CKPShipping;
|
|
45
|
+
merchantAmount?: string | null;
|
|
46
|
+
merchantCurrency?: string | null;
|
|
43
47
|
});
|
|
44
48
|
startPay(): Promise<unknown>;
|
|
45
49
|
begin(): Promise<unknown>;
|
|
@@ -137,7 +137,11 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
137
137
|
logger = _ref.logger,
|
|
138
138
|
_ref$env = _ref.env,
|
|
139
139
|
env = _ref$env === void 0 ? EnvironmentEnum.prod : _ref$env,
|
|
140
|
-
shipping = _ref.shipping
|
|
140
|
+
shipping = _ref.shipping,
|
|
141
|
+
_ref$merchantAmount = _ref.merchantAmount,
|
|
142
|
+
merchantAmount = _ref$merchantAmount === void 0 ? null : _ref$merchantAmount,
|
|
143
|
+
_ref$merchantCurrency = _ref.merchantCurrency,
|
|
144
|
+
merchantCurrency = _ref$merchantCurrency === void 0 ? null : _ref$merchantCurrency;
|
|
141
145
|
_classCallCheck(this, ApplePaySdk);
|
|
142
146
|
_defineProperty(this, "APPLESDKURL", 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js');
|
|
143
147
|
_defineProperty(this, "session", null);
|
|
@@ -150,11 +154,15 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
150
154
|
_defineProperty(this, "logger", void 0);
|
|
151
155
|
_defineProperty(this, "env", void 0);
|
|
152
156
|
_defineProperty(this, "shipping", void 0);
|
|
157
|
+
_defineProperty(this, "merchantAmount", void 0);
|
|
158
|
+
_defineProperty(this, "merchantCurrency", void 0);
|
|
153
159
|
this.paymentSessionData = paymentSessionData;
|
|
154
160
|
this.parseData = parseData;
|
|
155
161
|
this.env = env;
|
|
156
162
|
this.logger = logger;
|
|
157
163
|
this.shipping = shipping;
|
|
164
|
+
this.merchantAmount = merchantAmount;
|
|
165
|
+
this.merchantCurrency = merchantCurrency;
|
|
158
166
|
}
|
|
159
167
|
_createClass(ApplePaySdk, [{
|
|
160
168
|
key: "startPay",
|
|
@@ -496,13 +504,13 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
496
504
|
extendInfo = _ref5.extendInfo;
|
|
497
505
|
var request = {
|
|
498
506
|
countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
|
|
499
|
-
currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
|
|
507
|
+
currencyCode: this.merchantCurrency || (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency),
|
|
500
508
|
merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
|
|
501
509
|
supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
|
|
502
510
|
total: {
|
|
503
511
|
label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
|
|
504
512
|
type: 'final',
|
|
505
|
-
amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
|
|
513
|
+
amount: this.merchantAmount || (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value)
|
|
506
514
|
},
|
|
507
515
|
requiredBillingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredBillingContactFields,
|
|
508
516
|
requiredShippingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredShippingContactFields
|