@alipay/ams-checkout 0.0.1783323899-dev.1 → 0.0.1783403875-dev.1
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 -4
- package/dist/ams-checkout.min.js +1 -2
- package/esm/config/index.d.ts +0 -7
- package/esm/config/index.js +2 -2
- package/esm/constant/element.d.ts +1 -2
- package/esm/constant/element.js +0 -1
- package/esm/core/component/ckp/index.d.ts +1 -1
- package/esm/core/component/ckp/index.js +5 -2
- package/esm/core/component/element/elementController/index.d.ts +3 -3
- package/esm/core/component/element/elementController/index.js +57 -41
- 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 +5 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +105 -34
- package/esm/core/component/element/index.d.ts +1 -4
- package/esm/core/component/element/index.js +4 -19
- package/esm/core/component/element/mock.js +1 -1
- package/esm/core/component/element/type.d.ts +77 -16
- package/esm/core/component/element/util.d.ts +9 -2
- package/esm/core/component/element/util.js +3 -2
- package/esm/foundation/service/event-center.js +10 -13
- package/esm/modern/index.d.ts +1 -5
- package/esm/modern/index.js +51 -1
- package/esm/modern/stageName.d.ts +3 -0
- package/esm/modern/stageName.js +1 -0
- package/esm/plugin/component/channel.d.ts +2 -2
- package/esm/plugin/component/channel.js +18 -18
- package/esm/types/index.d.ts +4 -2
- package/esm/util/beforeConfirm.d.ts +4 -2
- package/esm/util/beforeConfirm.js +15 -14
- package/esm/util/logger.js +2 -1
- package/package.json +9 -15
- package/types.d.ts +94 -784
- package/types.untrimmed.d.ts +108 -931
- package/dist/ams-checkout.min.js.map +0 -1
- package/esm/core/component/element/modernElementController/adapter.d.ts +0 -19
- package/esm/core/component/element/modernElementController/adapter.js +0 -73
- package/esm/core/component/element/modernElementController/index.d.ts +0 -149
- package/esm/core/component/element/modernElementController/index.js +0 -1673
- package/esm/modern/global.d.ts +0 -3
- package/esm/modern/tools.js +0 -1
package/esm/config/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
-
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
|
6
|
-
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
|
7
|
-
*/
|
|
8
1
|
export declare const marmotMap: Record<string, string>;
|
|
9
2
|
export declare const marmotConfigMap: Record<string, string>;
|
|
10
3
|
export declare const v2AppMarmotMap: Record<string, string>;
|
package/esm/config/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
|
6
6
|
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
import json from "../../package.json";
|
|
9
9
|
export var marmotMap = {
|
|
10
10
|
dev: 'http://page.alipay.net/page/antom-web-checkout/src/component-app',
|
|
11
11
|
sit: 'http://page.test.alipay.net/page/antom-web-checkout/src/component-app',
|
|
@@ -30,7 +30,7 @@ export var v2AppMarmotMap = {
|
|
|
30
30
|
light_sandbox: 'https://checkout.antom.com',
|
|
31
31
|
prod: 'https://checkout.antom.com'
|
|
32
32
|
};
|
|
33
|
-
export var sdkVersion =
|
|
33
|
+
export var sdkVersion = json.version;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
|
@@ -22,6 +22,5 @@ export declare enum ELEMENT_PAGE_URL {
|
|
|
22
22
|
INSTRUCTION_GUIDE = "/elements/pages/instruction-guide/index.html",
|
|
23
23
|
THREED_PAGE = "/elements/pages/threed-page/index.html",
|
|
24
24
|
ELEMENT_AUTH = "/auth-element/pages/element_auth/index.html",
|
|
25
|
-
ADDRESS = "/element-address/pages/address/index.html"
|
|
26
|
-
NEW_ELEMENT_PAYMENT = "/elements2/pages/element_payment/index.html"
|
|
25
|
+
ADDRESS = "/element-address/pages/address/index.html"
|
|
27
26
|
}
|
package/esm/constant/element.js
CHANGED
|
@@ -26,6 +26,5 @@ export var ELEMENT_PAGE_URL = /*#__PURE__*/function (ELEMENT_PAGE_URL) {
|
|
|
26
26
|
ELEMENT_PAGE_URL["THREED_PAGE"] = "/elements/pages/threed-page/index.html";
|
|
27
27
|
ELEMENT_PAGE_URL["ELEMENT_AUTH"] = "/auth-element/pages/element_auth/index.html";
|
|
28
28
|
ELEMENT_PAGE_URL["ADDRESS"] = "/element-address/pages/address/index.html";
|
|
29
|
-
ELEMENT_PAGE_URL["NEW_ELEMENT_PAYMENT"] = "/elements2/pages/element_payment/index.html";
|
|
30
29
|
return ELEMENT_PAGE_URL;
|
|
31
30
|
}({});
|
|
@@ -20,7 +20,7 @@ export declare class AMSCheckoutPage {
|
|
|
20
20
|
/**
|
|
21
21
|
* 挂载组件
|
|
22
22
|
*/
|
|
23
|
-
mountComponent(params: Pick<IcreateComponent, 'sessionData'>, selector: string): Promise<void>;
|
|
23
|
+
mountComponent(params: Pick<IcreateComponent, 'sessionData' | 'isDemoMode'>, selector: string): Promise<void>;
|
|
24
24
|
/**
|
|
25
25
|
* 卸载组件
|
|
26
26
|
*/
|
|
@@ -50,7 +50,7 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
|
|
|
50
50
|
_defineProperty(this, "originOptions", void 0);
|
|
51
51
|
_defineProperty(this, "APP_IFRAME_ID", 'antom-checkout-page-sub-page-iframe');
|
|
52
52
|
_defineProperty(this, "eventListener", void 0);
|
|
53
|
-
_defineProperty(this, "generateIframeSrc", function (sessionData) {
|
|
53
|
+
_defineProperty(this, "generateIframeSrc", function (sessionData, isDemoMode) {
|
|
54
54
|
var env = _this.originOptions.environment || 'prod';
|
|
55
55
|
var session = sessionData || '';
|
|
56
56
|
var lang = _this.originOptions.locale || 'en_US';
|
|
@@ -66,6 +66,9 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
|
|
|
66
66
|
if (env === 'sandbox') {
|
|
67
67
|
queryObj.shadow = 'true';
|
|
68
68
|
}
|
|
69
|
+
if (isDemoMode) {
|
|
70
|
+
queryObj.demoMode = 'true';
|
|
71
|
+
}
|
|
69
72
|
Object.keys(queryObj).forEach(function (key) {
|
|
70
73
|
url += "".concat(url.includes('?') ? '&' : '?').concat(key, "=").concat(encodeURIComponent(queryObj[key]));
|
|
71
74
|
});
|
|
@@ -177,7 +180,7 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
|
|
|
177
180
|
throw new Error('PARAMS_ERROR_ALREADY_MOUNTED');
|
|
178
181
|
}
|
|
179
182
|
this.addListener();
|
|
180
|
-
var ckpPageAddress = this.generateIframeSrc(params.sessionData);
|
|
183
|
+
var ckpPageAddress = this.generateIframeSrc(params.sessionData, params.isDemoMode);
|
|
181
184
|
var iframe = document.createElement('iframe');
|
|
182
185
|
iframe.id = this.APP_IFRAME_ID;
|
|
183
186
|
iframe.src = ckpPageAddress;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse,
|
|
2
|
-
declare class ElementController
|
|
1
|
+
import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions, SubmitFuncParams } from '../type';
|
|
2
|
+
declare class ElementController {
|
|
3
3
|
private options;
|
|
4
4
|
private elementContainer;
|
|
5
5
|
private serviceMap;
|
|
@@ -44,7 +44,7 @@ declare class ElementController implements IElementController {
|
|
|
44
44
|
private getErrorFromResponse;
|
|
45
45
|
private areAllContainersReady;
|
|
46
46
|
private sendReady;
|
|
47
|
-
updatePayment(paymentSessionData:
|
|
47
|
+
updatePayment(paymentSessionData: any): Promise<unknown>;
|
|
48
48
|
private destroyHandle;
|
|
49
49
|
destroy(): void;
|
|
50
50
|
private setControllerStatusOrView;
|
|
@@ -37,7 +37,7 @@ import { ServiceProvider } from "../../../../foundation/service";
|
|
|
37
37
|
import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
|
|
38
38
|
import { ProductSceneEnum } from "../../../../types";
|
|
39
39
|
import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
|
|
40
|
-
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
|
|
40
|
+
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS, MERCHANT_CONFIRM_ABORT_CODE, MERCHANT_CONFIRM_TIMEOUT_CODE } from "../../../../util/beforeConfirm";
|
|
41
41
|
import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
|
|
42
42
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
|
43
43
|
import { EventCenter as ElementEventCenter } from "../EventCenter/index";
|
|
@@ -375,7 +375,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
375
375
|
value: function () {
|
|
376
376
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
|
|
377
377
|
var _this3 = this;
|
|
378
|
-
var startEventId, res, logParams, isApplePay, paymentMethodType, startTime, _yield$executeWithTim, shouldContinue, timedOut, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
378
|
+
var startEventId, res, logParams, isApplePay, paymentMethodType, startTime, _yield$executeWithTim, shouldContinue, timedOut, isTimeout, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
379
379
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
380
380
|
while (1) switch (_context4.prev = _context4.next) {
|
|
381
381
|
case 0:
|
|
@@ -405,7 +405,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
405
405
|
isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
|
|
406
406
|
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
407
407
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
408
|
-
_context4.next =
|
|
408
|
+
_context4.next = 40;
|
|
409
409
|
break;
|
|
410
410
|
}
|
|
411
411
|
this.serviceMap.Log.logInfo({
|
|
@@ -424,49 +424,65 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
424
424
|
_yield$executeWithTim = _context4.sent;
|
|
425
425
|
shouldContinue = _yield$executeWithTim.result;
|
|
426
426
|
timedOut = _yield$executeWithTim.timedOut;
|
|
427
|
-
|
|
428
|
-
|
|
427
|
+
isTimeout = timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS;
|
|
428
|
+
if (!isTimeout) {
|
|
429
|
+
_context4.next = 24;
|
|
429
430
|
break;
|
|
430
431
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
432
|
+
this.serviceMap.Log.logError({
|
|
433
|
+
title: 'sdk_before_confirm_timeout'
|
|
434
|
+
}, {
|
|
435
|
+
paymentMethodType: paymentMethodType,
|
|
436
|
+
path: 'nonApplePay_sync'
|
|
437
|
+
});
|
|
438
|
+
this.changeLoading(false);
|
|
439
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
440
|
+
eventCode: PaymentStatus.FAIL,
|
|
441
|
+
errorName: MERCHANT_CONFIRM_TIMEOUT_CODE
|
|
442
|
+
});
|
|
443
|
+
return _context4.abrupt("return", {
|
|
444
|
+
status: PaymentStatus.FAIL,
|
|
445
|
+
error: {
|
|
446
|
+
code: MERCHANT_CONFIRM_TIMEOUT_CODE,
|
|
447
|
+
message: 'Merchant confirmation timed out.',
|
|
448
|
+
needChangeSessionForRetry: false
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
case 24:
|
|
452
|
+
if (shouldContinue) {
|
|
453
|
+
_context4.next = 29;
|
|
454
|
+
break;
|
|
445
455
|
}
|
|
456
|
+
this.serviceMap.Log.logInfo({
|
|
457
|
+
title: 'sdk_before_confirm_abort'
|
|
458
|
+
}, {
|
|
459
|
+
paymentMethodType: paymentMethodType,
|
|
460
|
+
path: 'nonApplePay_sync'
|
|
461
|
+
});
|
|
446
462
|
this.changeLoading(false);
|
|
447
463
|
this.elementEventCenter.endEvent(startEventId, {
|
|
448
464
|
eventCode: PaymentStatus.FAIL,
|
|
449
|
-
errorName:
|
|
465
|
+
errorName: MERCHANT_CONFIRM_ABORT_CODE
|
|
450
466
|
});
|
|
451
467
|
return _context4.abrupt("return", {
|
|
452
468
|
status: PaymentStatus.FAIL,
|
|
453
469
|
error: {
|
|
454
|
-
code:
|
|
455
|
-
message: '
|
|
470
|
+
code: MERCHANT_CONFIRM_ABORT_CODE,
|
|
471
|
+
message: 'Payment was cancelled by merchant before confirmation.',
|
|
456
472
|
needChangeSessionForRetry: false
|
|
457
473
|
}
|
|
458
474
|
});
|
|
459
|
-
case
|
|
475
|
+
case 29:
|
|
460
476
|
this.serviceMap.Log.logInfo({
|
|
461
477
|
title: 'sdk_before_confirm_success'
|
|
462
478
|
}, {
|
|
463
479
|
paymentMethodType: paymentMethodType,
|
|
464
480
|
path: 'nonApplePay_sync'
|
|
465
481
|
});
|
|
466
|
-
_context4.next =
|
|
482
|
+
_context4.next = 38;
|
|
467
483
|
break;
|
|
468
|
-
case
|
|
469
|
-
_context4.prev =
|
|
484
|
+
case 32:
|
|
485
|
+
_context4.prev = 32;
|
|
470
486
|
_context4.t0 = _context4["catch"](11);
|
|
471
487
|
this.serviceMap.Log.logError({
|
|
472
488
|
title: 'sdk_before_confirm_error'
|
|
@@ -478,20 +494,20 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
478
494
|
this.changeLoading(false);
|
|
479
495
|
this.elementEventCenter.endEvent(startEventId, {
|
|
480
496
|
eventCode: PaymentStatus.FAIL,
|
|
481
|
-
errorName:
|
|
497
|
+
errorName: MERCHANT_CONFIRM_ABORT_CODE
|
|
482
498
|
});
|
|
483
499
|
return _context4.abrupt("return", {
|
|
484
500
|
status: PaymentStatus.FAIL,
|
|
485
501
|
error: {
|
|
486
|
-
code:
|
|
487
|
-
message: '
|
|
502
|
+
code: MERCHANT_CONFIRM_ABORT_CODE,
|
|
503
|
+
message: 'Payment was cancelled by merchant before confirmation.',
|
|
488
504
|
needChangeSessionForRetry: false
|
|
489
505
|
}
|
|
490
506
|
});
|
|
491
|
-
case
|
|
492
|
-
_context4.next =
|
|
507
|
+
case 38:
|
|
508
|
+
_context4.next = 41;
|
|
493
509
|
break;
|
|
494
|
-
case
|
|
510
|
+
case 40:
|
|
495
511
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
|
|
496
512
|
this.serviceMap.Log.logInfo({
|
|
497
513
|
title: 'sdk_before_confirm_skip'
|
|
@@ -500,10 +516,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
500
516
|
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
501
517
|
});
|
|
502
518
|
}
|
|
503
|
-
case
|
|
519
|
+
case 41:
|
|
504
520
|
recordResult = null;
|
|
505
|
-
_context4.prev =
|
|
506
|
-
_context4.next =
|
|
521
|
+
_context4.prev = 42;
|
|
522
|
+
_context4.next = 45;
|
|
507
523
|
return new Promise( /*#__PURE__*/function () {
|
|
508
524
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
509
525
|
var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
@@ -660,10 +676,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
660
676
|
return _ref3.apply(this, arguments);
|
|
661
677
|
};
|
|
662
678
|
}());
|
|
663
|
-
case
|
|
679
|
+
case 45:
|
|
664
680
|
return _context4.abrupt("return", _context4.sent);
|
|
665
|
-
case
|
|
666
|
-
_context4.prev =
|
|
681
|
+
case 46:
|
|
682
|
+
_context4.prev = 46;
|
|
667
683
|
_logParams = {
|
|
668
684
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
669
685
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -674,12 +690,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
674
690
|
};
|
|
675
691
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
676
692
|
this.changeLoading(false);
|
|
677
|
-
return _context4.finish(
|
|
678
|
-
case
|
|
693
|
+
return _context4.finish(46);
|
|
694
|
+
case 51:
|
|
679
695
|
case "end":
|
|
680
696
|
return _context4.stop();
|
|
681
697
|
}
|
|
682
|
-
}, _callee4, this, [[11,
|
|
698
|
+
}, _callee4, this, [[11, 32], [42,, 46, 51]]);
|
|
683
699
|
}));
|
|
684
700
|
function submitPayment(_x) {
|
|
685
701
|
return _submitPayment.apply(this, arguments);
|
|
@@ -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
|
+
}
|
|
@@ -23,6 +23,11 @@ declare class PaymentProcessor extends BaseElementProcessor {
|
|
|
23
23
|
instanceId: any;
|
|
24
24
|
}): string;
|
|
25
25
|
obtainData(): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* 构建预览模式的 mock 数据
|
|
28
|
+
* 合并 mock.ts 的硬编码数据和 mount 传入的 paymentMethods 配置
|
|
29
|
+
*/
|
|
30
|
+
private buildPreviewMockData;
|
|
26
31
|
getValue(): any;
|
|
27
32
|
update({ data, paymentSessionData }: {
|
|
28
33
|
data: any;
|