@alipay/ams-checkout 0.0.1781167787-dev.0 → 0.0.1782095417-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/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 +164 -25
- package/esm/core/component/element/elementProcessor/baseElementProcessor.d.ts +1 -0
- package/esm/core/component/element/elementProcessor/baseElementProcessor.js +1 -0
- package/esm/core/component/element/elementProcessor/convertPaymentMethods.d.ts +22 -0
- package/esm/core/component/element/elementProcessor/convertPaymentMethods.js +159 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +15 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +244 -53
- package/esm/core/component/element/mock.js +1 -1
- package/esm/core/component/element/type.d.ts +78 -1
- package/esm/core/component/element/util.d.ts +9 -2
- package/esm/core/component/element/util.js +3 -2
- package/esm/modern/index.js +1 -1
- package/esm/plugin/component/channel.d.ts +13 -2
- package/esm/plugin/component/channel.js +133 -30
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/types/index.d.ts +4 -7
- package/esm/util/beforeConfirm.d.ts +12 -0
- package/esm/util/beforeConfirm.js +68 -0
- 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;
|
|
@@ -37,11 +37,12 @@ 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";
|
|
43
44
|
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
|
44
|
-
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
|
|
45
|
+
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EVENTNAME, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
|
|
45
46
|
import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeParse, safeStringify, showToast } from "../util";
|
|
46
47
|
var TIMEOUT_DURATION = 16000;
|
|
47
48
|
var ElementController = /*#__PURE__*/function () {
|
|
@@ -59,6 +60,8 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
59
60
|
// 新增变量
|
|
60
61
|
_defineProperty(this, "submitPayPromise", void 0);
|
|
61
62
|
_defineProperty(this, "elementEventCenter", void 0);
|
|
63
|
+
/** Current selected payment method type (e.g. 'APPLEPAY', 'CARD'), updated via paymentMethodChanged event */
|
|
64
|
+
_defineProperty(this, "currentPaymentMethodType", '');
|
|
62
65
|
_defineProperty(this, "onValidateFunc", function (event, target) {
|
|
63
66
|
return new Promise(function (resolve) {
|
|
64
67
|
event.emitAndListen({
|
|
@@ -372,7 +375,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
372
375
|
value: function () {
|
|
373
376
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
|
|
374
377
|
var _this3 = this;
|
|
375
|
-
var startEventId, res, logParams, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
378
|
+
var startEventId, res, logParams, isApplePay, paymentMethodType, startTime, _yield$executeWithTim, shouldContinue, timedOut, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
376
379
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
377
380
|
while (1) switch (_context4.prev = _context4.next) {
|
|
378
381
|
case 0:
|
|
@@ -397,12 +400,113 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
397
400
|
return _context4.abrupt("return", Promise.resolve(res));
|
|
398
401
|
case 6:
|
|
399
402
|
this.changeLoading(true);
|
|
403
|
+
|
|
404
|
+
// Non-Apple Pay: execute onBeforeConfirm at SDK layer directly, abort on failure
|
|
405
|
+
isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
|
|
406
|
+
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
407
|
+
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
408
|
+
_context4.next = 34;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
this.serviceMap.Log.logInfo({
|
|
412
|
+
title: 'sdk_before_confirm_start'
|
|
413
|
+
}, {
|
|
414
|
+
paymentMethodType: paymentMethodType,
|
|
415
|
+
path: 'nonApplePay_sync'
|
|
416
|
+
});
|
|
417
|
+
_context4.prev = 11;
|
|
418
|
+
startTime = Date.now();
|
|
419
|
+
_context4.next = 15;
|
|
420
|
+
return executeWithTimeout(function () {
|
|
421
|
+
return submitParams.onBeforeConfirm();
|
|
422
|
+
});
|
|
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;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
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
|
+
}
|
|
446
|
+
this.changeLoading(false);
|
|
447
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
448
|
+
eventCode: PaymentStatus.FAIL,
|
|
449
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
450
|
+
});
|
|
451
|
+
return _context4.abrupt("return", {
|
|
452
|
+
status: PaymentStatus.FAIL,
|
|
453
|
+
error: {
|
|
454
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
455
|
+
message: 'Merchant canceled payment.',
|
|
456
|
+
needChangeSessionForRetry: false
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
case 23:
|
|
460
|
+
this.serviceMap.Log.logInfo({
|
|
461
|
+
title: 'sdk_before_confirm_success'
|
|
462
|
+
}, {
|
|
463
|
+
paymentMethodType: paymentMethodType,
|
|
464
|
+
path: 'nonApplePay_sync'
|
|
465
|
+
});
|
|
466
|
+
_context4.next = 32;
|
|
467
|
+
break;
|
|
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
|
+
});
|
|
478
|
+
this.changeLoading(false);
|
|
479
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
480
|
+
eventCode: PaymentStatus.FAIL,
|
|
481
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
482
|
+
});
|
|
483
|
+
return _context4.abrupt("return", {
|
|
484
|
+
status: PaymentStatus.FAIL,
|
|
485
|
+
error: {
|
|
486
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
487
|
+
message: 'Merchant canceled payment.',
|
|
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, hasAmount, hasCurrency, _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,58 @@ 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 = 28;
|
|
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
|
+
hasAmount = !!(submitParams !== null && submitParams !== void 0 && submitParams.amount);
|
|
600
|
+
hasCurrency = !!(submitParams !== null && submitParams !== void 0 && submitParams.currency);
|
|
601
|
+
if ((hasAmount || hasCurrency) && !(hasAmount && hasCurrency)) {
|
|
602
|
+
_this3.serviceMap.Log.logError({
|
|
603
|
+
title: 'sdk_element_submitPayment_amountCurrencyMismatch'
|
|
604
|
+
}, {
|
|
605
|
+
msg: safeStringify({
|
|
606
|
+
amount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount,
|
|
607
|
+
currency: submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency,
|
|
608
|
+
reason: 'amount and currency must be provided together, both ignored'
|
|
609
|
+
})
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
_this3.elementProcessors[ElementType.payment].setMerchantAmountOverride(hasAmount && hasCurrency ? submitParams.amount : null, hasAmount && hasCurrency ? submitParams.currency : null);
|
|
613
|
+
_context3.next = 24;
|
|
614
|
+
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, function (_submitParams$handleA) {
|
|
615
|
+
return _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
|
|
616
|
+
handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
|
|
617
|
+
shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
|
|
618
|
+
}, hasAmount && hasCurrency ? {
|
|
619
|
+
amount: submitParams.amount,
|
|
620
|
+
currency: submitParams.currency
|
|
621
|
+
} : {}), {}, {
|
|
622
|
+
hasBeforeConfirm: hasBeforeConfirmForApplePay
|
|
623
|
+
});
|
|
624
|
+
}());
|
|
625
|
+
case 24:
|
|
490
626
|
_yield$_this3$onValid2 = _context3.sent;
|
|
491
627
|
_data = _yield$_this3$onValid2.data;
|
|
492
628
|
// TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
|
|
493
629
|
// TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
|
|
494
630
|
recordResult = _data;
|
|
495
631
|
recordResultCallback(recordResult);
|
|
496
|
-
case
|
|
497
|
-
_context3.next =
|
|
632
|
+
case 28:
|
|
633
|
+
_context3.next = 37;
|
|
498
634
|
break;
|
|
499
|
-
case
|
|
500
|
-
_context3.prev =
|
|
635
|
+
case 30:
|
|
636
|
+
_context3.prev = 30;
|
|
501
637
|
_context3.t0 = _context3["catch"](2);
|
|
502
638
|
// 修复error为{}空对象的问题,上报stack&message
|
|
503
639
|
errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
|
|
@@ -514,20 +650,20 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
514
650
|
});
|
|
515
651
|
recordResult = errorResult;
|
|
516
652
|
recordResultCallback(errorResult);
|
|
517
|
-
case
|
|
653
|
+
case 37:
|
|
518
654
|
case "end":
|
|
519
655
|
return _context3.stop();
|
|
520
656
|
}
|
|
521
|
-
}, _callee3, null, [[2,
|
|
657
|
+
}, _callee3, null, [[2, 30]]);
|
|
522
658
|
}));
|
|
523
659
|
return function (_x2) {
|
|
524
660
|
return _ref3.apply(this, arguments);
|
|
525
661
|
};
|
|
526
662
|
}());
|
|
527
|
-
case
|
|
663
|
+
case 39:
|
|
528
664
|
return _context4.abrupt("return", _context4.sent);
|
|
529
|
-
case
|
|
530
|
-
_context4.prev =
|
|
665
|
+
case 40:
|
|
666
|
+
_context4.prev = 40;
|
|
531
667
|
_logParams = {
|
|
532
668
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
533
669
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -538,12 +674,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
538
674
|
};
|
|
539
675
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
540
676
|
this.changeLoading(false);
|
|
541
|
-
return _context4.finish(
|
|
542
|
-
case
|
|
677
|
+
return _context4.finish(40);
|
|
678
|
+
case 45:
|
|
543
679
|
case "end":
|
|
544
680
|
return _context4.stop();
|
|
545
681
|
}
|
|
546
|
-
}, _callee4, this, [[
|
|
682
|
+
}, _callee4, this, [[11, 26], [36,, 40, 45]]);
|
|
547
683
|
}));
|
|
548
684
|
function submitPayment(_x) {
|
|
549
685
|
return _submitPayment.apply(this, arguments);
|
|
@@ -628,6 +764,9 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
628
764
|
var _this4$submitPayPromi;
|
|
629
765
|
(_this4$submitPayPromi = _this4.submitPayPromise) === null || _this4$submitPayPromi === void 0 || _this4$submitPayPromi.call(_this4, data);
|
|
630
766
|
});
|
|
767
|
+
this.serviceMap.EventCenter.listen(EVENTNAME.PAYMENTMETHODCHANGED, function (data) {
|
|
768
|
+
_this4.currentPaymentMethodType = (data === null || data === void 0 ? void 0 : data.type) || '';
|
|
769
|
+
}, true);
|
|
631
770
|
}
|
|
632
771
|
}, {
|
|
633
772
|
key: "sendRequestAndWaitWebLaunch",
|
|
@@ -892,7 +1031,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
892
1031
|
}
|
|
893
1032
|
this.serviceMap.EventCenter.listen(event, function (data) {
|
|
894
1033
|
callback === null || callback === void 0 || callback(data);
|
|
895
|
-
});
|
|
1034
|
+
}, true);
|
|
896
1035
|
}
|
|
897
1036
|
}, {
|
|
898
1037
|
key: "isEventAllowed",
|
|
@@ -57,6 +57,7 @@ var BaseElementProcessor = /*#__PURE__*/function () {
|
|
|
57
57
|
_setEnv();
|
|
58
58
|
this.options.locale = (options === null || options === void 0 ? void 0 : options.locale) || '';
|
|
59
59
|
this.options.product = options === null || options === void 0 ? void 0 : options.product;
|
|
60
|
+
this.options.preview = options === null || options === void 0 ? void 0 : options.preview;
|
|
60
61
|
}
|
|
61
62
|
}, {
|
|
62
63
|
key: "registerElementContainer",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IPaymentMethod } from "../../../../types";
|
|
2
|
+
interface PaymentMethodsConfig {
|
|
3
|
+
expressCheckout?: {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
methods?: {
|
|
6
|
+
paymentMethodName: string;
|
|
7
|
+
paymentMethodType: string;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
supportedMethods?: {
|
|
11
|
+
paymentMethodName: string;
|
|
12
|
+
paymentMethodType: string;
|
|
13
|
+
logoUrl?: string;
|
|
14
|
+
}[];
|
|
15
|
+
topping?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 将 paymentMethods 配置转换为内部格式
|
|
19
|
+
* 与 CKP 的 convertPaymentMethods 逻辑保持一致
|
|
20
|
+
*/
|
|
21
|
+
export declare function convertPaymentMethods(paymentMethodsConf?: PaymentMethodsConfig): IPaymentMethod[];
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
/**
|
|
14
|
+
* 为 GOOGLEPAY 支付方式补充 mock 的 paymentMethodDetail 数据
|
|
15
|
+
* 预览模式下 GooglePay 需要完整的 googlePayProps 才能正常渲染
|
|
16
|
+
*/
|
|
17
|
+
function handleGooglePayMethodDetail(method) {
|
|
18
|
+
if (method.paymentMethodType === 'GOOGLEPAY') {
|
|
19
|
+
method.paymentMethodDetail = _objectSpread(_objectSpread({}, method.paymentMethodDetail), {}, {
|
|
20
|
+
googlePayProps: {
|
|
21
|
+
environment: 'TEST',
|
|
22
|
+
existingPaymentMethodRequired: true,
|
|
23
|
+
paymentRequest: {
|
|
24
|
+
allowedPaymentMethods: [{
|
|
25
|
+
parameters: {
|
|
26
|
+
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
|
|
27
|
+
allowedCardNetworks: ['VISA', 'JCB']
|
|
28
|
+
},
|
|
29
|
+
tokenizationSpecification: {
|
|
30
|
+
parameters: {
|
|
31
|
+
protocolVersion: 'ECv2',
|
|
32
|
+
publicKey: 'BDM6GVTLZmxSmTQzm04QKI2av54kFpkqjhbkejtdDUx+VMvUtJ6vc+ZlDp8TygNTf+QeihxpD869sCVWaa0KMJc='
|
|
33
|
+
},
|
|
34
|
+
type: 'DIRECT'
|
|
35
|
+
},
|
|
36
|
+
type: 'CARD'
|
|
37
|
+
}],
|
|
38
|
+
apiVersion: 2,
|
|
39
|
+
apiVersionMinor: 0,
|
|
40
|
+
callbackIntents: ['PAYMENT_AUTHORIZATION'],
|
|
41
|
+
merchantInfo: {
|
|
42
|
+
merchantId: '123',
|
|
43
|
+
merchantName: 'merchantName'
|
|
44
|
+
},
|
|
45
|
+
shippingAddressRequired: true,
|
|
46
|
+
transactionInfo: {
|
|
47
|
+
countryCode: 'US',
|
|
48
|
+
currencyCode: 'EUR',
|
|
49
|
+
totalPrice: '10',
|
|
50
|
+
totalPriceStatus: 'FINAL'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 为 ONLINEBANKING_YAPILY 支付方式处理 mock 数据
|
|
60
|
+
* Yapily 在预览模式下需要清空 paymentElements
|
|
61
|
+
*/
|
|
62
|
+
function handleYapilyMethodDetail(method) {
|
|
63
|
+
if (method.paymentMethodType === 'ONLINEBANKING_YAPILY') {
|
|
64
|
+
method.paymentElements = [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 合并所有的 Card 类支付方式
|
|
70
|
+
* 与 CKP handleAllCardsData 逻辑一致
|
|
71
|
+
*/
|
|
72
|
+
function handleAllCardsData() {
|
|
73
|
+
var supportedMethods = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
74
|
+
var firstCardIndex = -1;
|
|
75
|
+
var logoList = [];
|
|
76
|
+
supportedMethods.forEach(function (item, index) {
|
|
77
|
+
if (item.paymentMethodName === 'CARD') {
|
|
78
|
+
logoList.push({
|
|
79
|
+
cardBrand: item.paymentMethodType,
|
|
80
|
+
logoUrl: item.logoUrl || ''
|
|
81
|
+
});
|
|
82
|
+
if (firstCardIndex === -1) {
|
|
83
|
+
firstCardIndex = index;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (logoList.length) {
|
|
88
|
+
return {
|
|
89
|
+
firstCardIndex: firstCardIndex,
|
|
90
|
+
cardPaymentMethod: {
|
|
91
|
+
antomPage: 'paymentMetaPage',
|
|
92
|
+
category: 'CARD',
|
|
93
|
+
expressCheckout: false,
|
|
94
|
+
logoList: logoList,
|
|
95
|
+
paymentMethod: 'CARD',
|
|
96
|
+
paymentMethodName: 'Card',
|
|
97
|
+
paymentMethodType: 'CARD',
|
|
98
|
+
recommend: false,
|
|
99
|
+
webRedirectType: 'PAGE_REFRESH'
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 将 paymentMethods 配置转换为内部格式
|
|
108
|
+
* 与 CKP 的 convertPaymentMethods 逻辑保持一致
|
|
109
|
+
*/
|
|
110
|
+
export function convertPaymentMethods(paymentMethodsConf) {
|
|
111
|
+
if (!paymentMethodsConf) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
var expressCheckout = paymentMethodsConf.expressCheckout,
|
|
115
|
+
supportedMethods = paymentMethodsConf.supportedMethods,
|
|
116
|
+
topping = paymentMethodsConf.topping;
|
|
117
|
+
|
|
118
|
+
// 1. 处理极速支付(排在最前面)
|
|
119
|
+
var supportedExpressCheckoutMethods = ((expressCheckout === null || expressCheckout === void 0 ? void 0 : expressCheckout.methods) || []).map(function (item) {
|
|
120
|
+
var method = {
|
|
121
|
+
paymentMethodName: item.paymentMethodName,
|
|
122
|
+
paymentMethodType: item.paymentMethodType,
|
|
123
|
+
category: item.paymentMethodType,
|
|
124
|
+
expressCheckout: true
|
|
125
|
+
};
|
|
126
|
+
handleGooglePayMethodDetail(method);
|
|
127
|
+
return method;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// 2. 处理普通支付方式(跳过 CARD,CARD 统一合并处理)
|
|
131
|
+
var supportedPaymentMethods = [];
|
|
132
|
+
(supportedMethods || []).forEach(function (item) {
|
|
133
|
+
if (item.paymentMethodName === 'CARD') {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
var method = {
|
|
137
|
+
paymentMethodName: item.paymentMethodName,
|
|
138
|
+
paymentMethodType: item.paymentMethodType,
|
|
139
|
+
category: item.paymentMethodType,
|
|
140
|
+
icon: item.logoUrl,
|
|
141
|
+
recommend: false
|
|
142
|
+
};
|
|
143
|
+
if (method.paymentMethodType === topping) {
|
|
144
|
+
method.recommend = true;
|
|
145
|
+
}
|
|
146
|
+
handleGooglePayMethodDetail(method);
|
|
147
|
+
handleYapilyMethodDetail(method);
|
|
148
|
+
supportedPaymentMethods.push(method);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// 3. 合并所有的 Card 类支付方式
|
|
152
|
+
var cardPaymentMethods = handleAllCardsData(supportedMethods);
|
|
153
|
+
|
|
154
|
+
// 4. 插入 Card 类支付方式 (card 第一次出现的位置)
|
|
155
|
+
if (cardPaymentMethods) {
|
|
156
|
+
supportedPaymentMethods.splice(cardPaymentMethods.firstCardIndex, 0, cardPaymentMethods.cardPaymentMethod);
|
|
157
|
+
}
|
|
158
|
+
return [].concat(_toConsumableArray(supportedExpressCheckoutMethods), supportedPaymentMethods);
|
|
159
|
+
}
|
|
@@ -2,6 +2,16 @@ 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
|
+
private _merchantAmount;
|
|
12
|
+
private _merchantCurrency;
|
|
13
|
+
setOnBeforeConfirm(callback: (() => Promise<boolean>) | null): void;
|
|
14
|
+
setMerchantAmountOverride(amount: string | null, currency: string | null): void;
|
|
5
15
|
onReady(extraParam: any): void;
|
|
6
16
|
getLogger(): LogService;
|
|
7
17
|
private addEventListener;
|
|
@@ -13,6 +23,11 @@ declare class PaymentProcessor extends BaseElementProcessor {
|
|
|
13
23
|
instanceId: any;
|
|
14
24
|
}): string;
|
|
15
25
|
obtainData(): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* 构建预览模式的 mock 数据
|
|
28
|
+
* 合并 mock.ts 的硬编码数据和 mount 传入的 paymentMethods 配置
|
|
29
|
+
*/
|
|
30
|
+
private buildPreviewMockData;
|
|
16
31
|
getValue(): any;
|
|
17
32
|
update({ data, paymentSessionData }: {
|
|
18
33
|
data: any;
|