@alipay/ams-checkout 2.0.19 → 2.0.20
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/ckp/index.d.ts +1 -1
- package/esm/core/component/ckp/index.js +5 -2
- 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 +94 -19
- package/esm/core/component/element/mock.js +1 -1
- package/esm/core/component/element/type.d.ts +58 -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/types/index.d.ts +4 -1
- package/package.json +1 -1
- package/types.d.ts +3 -0
- package/types.untrimmed.d.ts +3 -0
|
@@ -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;
|
|
@@ -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;
|
|
@@ -27,11 +27,13 @@ import { ELEMENT_PAGE_URL } from "../../../../constant/element";
|
|
|
27
27
|
import { EVENT } from "../../../../constant";
|
|
28
28
|
import { ServiceProvider } from "../../../../foundation/service";
|
|
29
29
|
import { ApplePaySdk, handleGooglePay, isSkipRenderPaymentMethod } from "../../../../plugin/component/channel";
|
|
30
|
+
import { DisplayTypeEnum } from "../../../../types";
|
|
30
31
|
import { queryParse } from "../../../../util";
|
|
31
32
|
import { LogConfig, Logger } from "../../../../util/logger";
|
|
32
33
|
import { parseSessionData } from "../../index";
|
|
33
34
|
import { oneAccount, sdkAction } from "../mock";
|
|
34
|
-
import {
|
|
35
|
+
import { convertPaymentMethods } from "../elementProcessor/convertPaymentMethods";
|
|
36
|
+
import { generateIframeSrc as _generateIframeSrc, isElementPad, isElementPC, safeParse, safeStringify } from "../util";
|
|
35
37
|
import BaseElementProcessor from "./baseElementProcessor";
|
|
36
38
|
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
|
|
37
39
|
var logger = new Logger(LogConfig, true);
|
|
@@ -85,11 +87,44 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
85
87
|
}, {
|
|
86
88
|
key: "onReady",
|
|
87
89
|
value: function onReady(extraParam) {
|
|
88
|
-
var _this$elementContaine, _this$elementContaine2, _this$elementContaine3, _this$elementContaine4, _this$elementContaine5;
|
|
90
|
+
var _this$options, _paymentContext$displ, _this$elementContaine, _this$elementContaine2, _this$elementContaine3, _this$elementContaine4, _this$elementContaine5;
|
|
89
91
|
var paymentContext = this.elementContainer.getPaymentContext();
|
|
90
92
|
this.getLogger().logInfo({
|
|
91
93
|
title: 'sdk_event_renderComponent'
|
|
92
94
|
});
|
|
95
|
+
|
|
96
|
+
// preview mobile 模式下,单普通支付方式(无表单、非快捷支付)不发送 renderComponent,阻止自动提交
|
|
97
|
+
var previewMode = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.preview;
|
|
98
|
+
if (previewMode === 'mobile') {
|
|
99
|
+
var _extraParam$originAct, _extraParam$originAct2, _paymentMethods$, _paymentMethods$2;
|
|
100
|
+
var paymentMethods = (extraParam === null || extraParam === void 0 || (_extraParam$originAct = extraParam.originActionQueryResult) === null || _extraParam$originAct === void 0 ? void 0 : _extraParam$originAct.paymentMethods) || [];
|
|
101
|
+
var savedPaymentMethods = (extraParam === null || extraParam === void 0 || (_extraParam$originAct2 = extraParam.originActionQueryResult) === null || _extraParam$originAct2 === void 0 ? void 0 : _extraParam$originAct2.savedPaymentMethods) || [];
|
|
102
|
+
if (paymentMethods.length === 1 && savedPaymentMethods.length === 0 && !((_paymentMethods$ = paymentMethods[0]) !== null && _paymentMethods$ !== void 0 && (_paymentMethods$ = _paymentMethods$.paymentElements) !== null && _paymentMethods$ !== void 0 && _paymentMethods$.length) && !['APPLEPAY', 'GOOGLEPAY'].includes((_paymentMethods$2 = paymentMethods[0]) === null || _paymentMethods$2 === void 0 ? void 0 : _paymentMethods$2.paymentMethodType)) {
|
|
103
|
+
// 跳过 renderComponent,避免触发自动提交
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ===== Element 自助化运营:appearance 二选一处理(不做 deepMerge)=====
|
|
109
|
+
// 根据 theme 值二选一:
|
|
110
|
+
// - 内置 6 大主题(非 APR_ 前缀):完全使用 SDK mount 传入的 appearance
|
|
111
|
+
// - 自定义主题模版(APR_ 前缀 AppearanceID):完全使用后端 sdkAction.query 返回的 appearance,
|
|
112
|
+
// SDK mount 中传的 layout/variables/card 全部忽略
|
|
113
|
+
var mountAppearance = paymentContext === null || paymentContext === void 0 || (_paymentContext$displ = paymentContext.displayInfo) === null || _paymentContext$displ === void 0 ? void 0 : _paymentContext$displ.appearance;
|
|
114
|
+
var isAppearanceId = typeof (mountAppearance === null || mountAppearance === void 0 ? void 0 : mountAppearance.theme) === 'string' && mountAppearance.theme.startsWith('APR_');
|
|
115
|
+
var finalAppearance;
|
|
116
|
+
if (isAppearanceId) {
|
|
117
|
+
var _extraParam$originAct3, _safeParse;
|
|
118
|
+
// 分支 A:自定义主题模版(APR_xxxx)
|
|
119
|
+
// 完全使用后端返回的配置,忽略 SDK mount 中的 layout/variables/card
|
|
120
|
+
// elementSettings 可能是 JSON string,需统一解析为对象
|
|
121
|
+
var elementSettings = extraParam === null || extraParam === void 0 || (_extraParam$originAct3 = extraParam.originActionQueryResult) === null || _extraParam$originAct3 === void 0 || (_extraParam$originAct3 = _extraParam$originAct3.pageStyle) === null || _extraParam$originAct3 === void 0 ? void 0 : _extraParam$originAct3.elementSettings;
|
|
122
|
+
finalAppearance = typeof elementSettings === 'string' ? (_safeParse = safeParse(elementSettings)) === null || _safeParse === void 0 ? void 0 : _safeParse.appearance : elementSettings === null || elementSettings === void 0 ? void 0 : elementSettings.appearance;
|
|
123
|
+
} else {
|
|
124
|
+
// 分支 B:内置 6 大主题或未指定主题
|
|
125
|
+
// 完全使用 SDK mount 传入的配置;
|
|
126
|
+
finalAppearance = mountAppearance;
|
|
127
|
+
}
|
|
93
128
|
this.eventCenter.dispatchToApp({
|
|
94
129
|
event: 'renderComponent',
|
|
95
130
|
data: {
|
|
@@ -108,7 +143,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
108
143
|
merchantId: (_this$elementContaine4 = this.elementContainer) === null || _this$elementContaine4 === void 0 || (_this$elementContaine4 = _this$elementContaine4.getPaymentContext()) === null || _this$elementContaine4 === void 0 || (_this$elementContaine4 = _this$elementContaine4.paymentSessionObj) === null || _this$elementContaine4 === void 0 ? void 0 : _this$elementContaine4.clientId,
|
|
109
144
|
paymentMethodType: (_this$elementContaine5 = this.elementContainer) === null || _this$elementContaine5 === void 0 || (_this$elementContaine5 = _this$elementContaine5.getPaymentContext()) === null || _this$elementContaine5 === void 0 || (_this$elementContaine5 = _this$elementContaine5.paymentSessionObj) === null || _this$elementContaine5 === void 0 || (_this$elementContaine5 = _this$elementContaine5.paymentMethodInfoView) === null || _this$elementContaine5 === void 0 ? void 0 : _this$elementContaine5.paymentMethodType
|
|
110
145
|
},
|
|
111
|
-
appearance:
|
|
146
|
+
appearance: finalAppearance,
|
|
112
147
|
sessionResult: paymentContext === null || paymentContext === void 0 ? void 0 : paymentContext.paymentSessionObj,
|
|
113
148
|
notRedirectAfterComplete: (extraParam === null || extraParam === void 0 ? void 0 : extraParam.notRedirectAfterComplete) === true,
|
|
114
149
|
merchantAppointParam: extraParam === null || extraParam === void 0 ? void 0 : extraParam.merchantAppointParam,
|
|
@@ -344,6 +379,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
344
379
|
}, {
|
|
345
380
|
key: "generateIframeSrc",
|
|
346
381
|
value: function generateIframeSrc(_ref3) {
|
|
382
|
+
var _this$options3;
|
|
347
383
|
var link = _ref3.link,
|
|
348
384
|
instanceId = _ref3.instanceId;
|
|
349
385
|
this.instanceId = instanceId;
|
|
@@ -351,12 +387,15 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
351
387
|
paymentSession = _ref4.paymentSession,
|
|
352
388
|
paymentSessionObj = _ref4.paymentSessionObj,
|
|
353
389
|
sdkMetaData = _ref4.sdkMetaData;
|
|
354
|
-
var _this$
|
|
355
|
-
environment = _this$
|
|
356
|
-
analytics = _this$
|
|
357
|
-
locale = _this$
|
|
390
|
+
var _this$options2 = this.options,
|
|
391
|
+
environment = _this$options2.env.environment,
|
|
392
|
+
analytics = _this$options2.analytics,
|
|
393
|
+
locale = _this$options2.locale;
|
|
358
394
|
var _ref5 = paymentSessionObj || {},
|
|
359
395
|
extendInfo = _ref5.extendInfo;
|
|
396
|
+
// 预览模式下,若为 'mobile' 需要让 iframe 以 popup(MobileElement)形态渲染
|
|
397
|
+
var previewMode = (_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.preview;
|
|
398
|
+
var renderDisplayType = previewMode === 'mobile' ? DisplayTypeEnum.popup : DisplayTypeEnum.inline;
|
|
360
399
|
var url = _generateIframeSrc({
|
|
361
400
|
paymentSession: paymentSession,
|
|
362
401
|
paymentSessionObj: paymentSessionObj,
|
|
@@ -366,7 +405,8 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
366
405
|
link: link,
|
|
367
406
|
appVersion: sdkMetaData === null || sdkMetaData === void 0 ? void 0 : sdkMetaData.webAppVersion,
|
|
368
407
|
pageUrl: isExpressCheckout(extendInfo) ? ELEMENT_PAGE_URL.EXPRESS_CHECKOUT : ELEMENT_PAGE_URL.ELEMENT_PAYMENT,
|
|
369
|
-
instanceId: instanceId
|
|
408
|
+
instanceId: instanceId,
|
|
409
|
+
renderDisplayType: renderDisplayType
|
|
370
410
|
});
|
|
371
411
|
this.setElementUrl(url);
|
|
372
412
|
return url;
|
|
@@ -376,8 +416,9 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
376
416
|
value: function () {
|
|
377
417
|
var _obtainData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
378
418
|
var _paymentSessionObj$co,
|
|
419
|
+
_this$options5,
|
|
379
420
|
_this3 = this;
|
|
380
|
-
var requestService, _this$elementContaine7, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$
|
|
421
|
+
var requestService, _this$elementContaine7, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$options4, environment, locale, _ref6, paymentSessionConfig, hostSign, isConnect, LOCAL_MOCK, previewMode, IS_PREVIEW, SHOULD_USE_MOCK, _queryParse, appType, terminalType, generateActionQueryPromise, generateOneAccountQueryPromise, _yield$Promise$all, _yield$Promise$all2, originActionQueryResult, originOneAccountQueryResult;
|
|
381
422
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
382
423
|
while (1) switch (_context3.prev = _context3.next) {
|
|
383
424
|
case 0:
|
|
@@ -385,11 +426,14 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
385
426
|
_this$elementContaine7 = this.elementContainer.getPaymentContext(), paymentSession = _this$elementContaine7.paymentSession, paymentSessionObj = _this$elementContaine7.paymentSessionObj, displayInfo = _this$elementContaine7.displayInfo;
|
|
386
427
|
_displayInfo = displayInfo;
|
|
387
428
|
debugProps = _displayInfo.debugProps;
|
|
388
|
-
_this$
|
|
429
|
+
_this$options4 = this.options, environment = _this$options4.env.environment, locale = _this$options4.locale;
|
|
389
430
|
_ref6 = paymentSessionObj || {}, paymentSessionConfig = _ref6.paymentSessionConfig;
|
|
390
431
|
hostSign = paymentSession.split('&&')[1] || '';
|
|
391
432
|
isConnect = paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$co = paymentSessionObj.connectFactor) === null || _paymentSessionObj$co === void 0 ? void 0 : _paymentSessionObj$co.enableConnect;
|
|
392
|
-
LOCAL_MOCK = (debugProps === null || debugProps === void 0 ? void 0 : debugProps.isDebug) && (debugProps === null || debugProps === void 0 ? void 0 : debugProps.local_mock);
|
|
433
|
+
LOCAL_MOCK = (debugProps === null || debugProps === void 0 ? void 0 : debugProps.isDebug) && (debugProps === null || debugProps === void 0 ? void 0 : debugProps.local_mock); // 兼容三种预览开关取值:true / 'web' / 'mobile'
|
|
434
|
+
previewMode = (_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.preview;
|
|
435
|
+
IS_PREVIEW = previewMode === true || previewMode === 'web' || previewMode === 'mobile';
|
|
436
|
+
SHOULD_USE_MOCK = LOCAL_MOCK || IS_PREVIEW;
|
|
393
437
|
_queryParse = queryParse(this.getElementUrl()), appType = _queryParse.appType;
|
|
394
438
|
terminalType = isElementPad() ? 'WEB' : appType ? 'APP' : isElementPC() ? 'WEB' : 'WAP';
|
|
395
439
|
/**
|
|
@@ -401,10 +445,14 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
401
445
|
generateActionQueryPromise = function generateActionQueryPromise() {
|
|
402
446
|
return new Promise(function (resolve, reject) {
|
|
403
447
|
var _displayInfo$merchant;
|
|
404
|
-
|
|
405
|
-
if (LOCAL_MOCK) {
|
|
448
|
+
if (SHOULD_USE_MOCK) {
|
|
406
449
|
setTimeout(function () {
|
|
407
|
-
|
|
450
|
+
if (IS_PREVIEW) {
|
|
451
|
+
var mockData = _this3.buildPreviewMockData(sdkAction);
|
|
452
|
+
resolve(mockData);
|
|
453
|
+
} else {
|
|
454
|
+
resolve(sdkAction);
|
|
455
|
+
}
|
|
408
456
|
}, 100);
|
|
409
457
|
return;
|
|
410
458
|
}
|
|
@@ -422,6 +470,12 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
422
470
|
}
|
|
423
471
|
};
|
|
424
472
|
|
|
473
|
+
// 自定义主题模版(APR_ 前缀 AppearanceID):额外传递 appearanceId
|
|
474
|
+
var mountAppearance = displayInfo === null || displayInfo === void 0 ? void 0 : displayInfo.appearance;
|
|
475
|
+
var isAppearanceId = typeof (mountAppearance === null || mountAppearance === void 0 ? void 0 : mountAppearance.theme) === 'string' && mountAppearance.theme.startsWith('APR_');
|
|
476
|
+
if (isAppearanceId) {
|
|
477
|
+
sdkRequestData.appearanceId = mountAppearance.theme;
|
|
478
|
+
}
|
|
425
479
|
// 可选参数:商户指定的储值卡信息
|
|
426
480
|
if (displayInfo !== null && displayInfo !== void 0 && (_displayInfo$merchant = displayInfo.merchantAppointParam) !== null && _displayInfo$merchant !== void 0 && _displayInfo$merchant.storedCard) {
|
|
427
481
|
sdkRequestData.merchantAppointParam = displayInfo.merchantAppointParam;
|
|
@@ -486,8 +540,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
486
540
|
*/
|
|
487
541
|
generateOneAccountQueryPromise = function generateOneAccountQueryPromise() {
|
|
488
542
|
return new Promise(function (resolve, reject) {
|
|
489
|
-
|
|
490
|
-
if (LOCAL_MOCK) {
|
|
543
|
+
if (SHOULD_USE_MOCK) {
|
|
491
544
|
setTimeout(function () {
|
|
492
545
|
resolve(oneAccount);
|
|
493
546
|
}, 100);
|
|
@@ -523,9 +576,9 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
523
576
|
});
|
|
524
577
|
});
|
|
525
578
|
};
|
|
526
|
-
_context3.next =
|
|
579
|
+
_context3.next = 18;
|
|
527
580
|
return Promise.all(isConnect ? [generateActionQueryPromise(), generateOneAccountQueryPromise()] : [generateActionQueryPromise()]);
|
|
528
|
-
case
|
|
581
|
+
case 18:
|
|
529
582
|
_yield$Promise$all = _context3.sent;
|
|
530
583
|
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
531
584
|
originActionQueryResult = _yield$Promise$all2[0];
|
|
@@ -538,7 +591,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
538
591
|
originActionQueryResult: originActionQueryResult,
|
|
539
592
|
originOneAccountQueryResult: originOneAccountQueryResult
|
|
540
593
|
});
|
|
541
|
-
case
|
|
594
|
+
case 24:
|
|
542
595
|
case "end":
|
|
543
596
|
return _context3.stop();
|
|
544
597
|
}
|
|
@@ -549,6 +602,28 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
549
602
|
}
|
|
550
603
|
return obtainData;
|
|
551
604
|
}()
|
|
605
|
+
/**
|
|
606
|
+
* 构建预览模式的 mock 数据
|
|
607
|
+
* 合并 mock.ts 的硬编码数据和 mount 传入的 paymentMethods 配置
|
|
608
|
+
*/
|
|
609
|
+
}, {
|
|
610
|
+
key: "buildPreviewMockData",
|
|
611
|
+
value: function buildPreviewMockData(baseMock) {
|
|
612
|
+
var _this$elementContaine8 = this.elementContainer.getPaymentContext(),
|
|
613
|
+
displayInfo = _this$elementContaine8.displayInfo;
|
|
614
|
+
var mountOptions = displayInfo;
|
|
615
|
+
var paymentMethodsConfig = mountOptions === null || mountOptions === void 0 ? void 0 : mountOptions.previewPaymentMethods;
|
|
616
|
+
|
|
617
|
+
// 深拷贝 mock 数据,避免修改原始对象
|
|
618
|
+
var result = JSON.parse(JSON.stringify(baseMock));
|
|
619
|
+
|
|
620
|
+
// 转换 paymentMethods 配置为内部格式
|
|
621
|
+
var convertedMethods = convertPaymentMethods(paymentMethodsConfig);
|
|
622
|
+
|
|
623
|
+
// 替换 paymentMethods
|
|
624
|
+
result.paymentMethods = convertedMethods;
|
|
625
|
+
return result;
|
|
626
|
+
}
|
|
552
627
|
}, {
|
|
553
628
|
key: "getValue",
|
|
554
629
|
value: function getValue() {
|
|
@@ -153,7 +153,7 @@ export var sdkAction1 = {
|
|
|
153
153
|
}, {
|
|
154
154
|
antomPage: 'paymentMetaPage',
|
|
155
155
|
category: 'AC_WALLET',
|
|
156
|
-
expressCheckout:
|
|
156
|
+
expressCheckout: false,
|
|
157
157
|
icon: 'https://cdn.marmot-cloud.com/storage/2024/05/15/5b829130-42d9-46e7-a23d-6774f7352900.svg',
|
|
158
158
|
iconName: 'Alipay',
|
|
159
159
|
interActionType: 'REDIRECT',
|
|
@@ -149,7 +149,7 @@ type CompatibleVariables<T extends Record<string, string>> = {
|
|
|
149
149
|
export interface PaymentMountOptions extends BaseMountOptions {
|
|
150
150
|
type: ElementType.payment;
|
|
151
151
|
appearance?: {
|
|
152
|
-
theme?: ThemeType
|
|
152
|
+
theme?: ThemeType | `APR_${string}`;
|
|
153
153
|
layout?: {
|
|
154
154
|
type: PaymentElementLayout;
|
|
155
155
|
};
|
|
@@ -192,6 +192,54 @@ export interface PaymentMountOptions extends BaseMountOptions {
|
|
|
192
192
|
};
|
|
193
193
|
notRedirectAfterComplete?: boolean;
|
|
194
194
|
merchantAppointParam?: IMerchantAppointParam;
|
|
195
|
+
/**
|
|
196
|
+
* 支付方式配置
|
|
197
|
+
*
|
|
198
|
+
* 使用说明:
|
|
199
|
+
* - preview: true 时生效,用于配置预览展示的支付方式和外观
|
|
200
|
+
* - preview: false/undefined 时,此配置被忽略,支付方式来自后端 sdkAction.query 接口
|
|
201
|
+
*/
|
|
202
|
+
previewPaymentMethods?: {
|
|
203
|
+
/**
|
|
204
|
+
* 极速支付配置
|
|
205
|
+
*/
|
|
206
|
+
expressCheckout?: {
|
|
207
|
+
enabled: boolean;
|
|
208
|
+
methods?: {
|
|
209
|
+
/**
|
|
210
|
+
* 支付方式显示名称,如 "Apple Pay"
|
|
211
|
+
*/
|
|
212
|
+
paymentMethodName: string;
|
|
213
|
+
/**
|
|
214
|
+
* 支付方式类型,如 "APPLEPAY"
|
|
215
|
+
*/
|
|
216
|
+
paymentMethodType: string;
|
|
217
|
+
}[];
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* 支持的支付方式列表
|
|
221
|
+
* 数组顺序即为前端展示顺序
|
|
222
|
+
*/
|
|
223
|
+
supportedMethods?: {
|
|
224
|
+
/**
|
|
225
|
+
* 支付方式显示名称,如 "CARD", "AlipayHK"
|
|
226
|
+
*/
|
|
227
|
+
paymentMethodName: string;
|
|
228
|
+
/**
|
|
229
|
+
* 支付方式类型,如 "VISA", "ALIPAY_HK"
|
|
230
|
+
*/
|
|
231
|
+
paymentMethodType: string;
|
|
232
|
+
/**
|
|
233
|
+
* 支付方式图标 URL
|
|
234
|
+
*/
|
|
235
|
+
logoUrl?: string;
|
|
236
|
+
}[];
|
|
237
|
+
/**
|
|
238
|
+
* 推荐支付方式
|
|
239
|
+
* 值为 paymentMethodType,匹配的支付方式会被标记为 recommend
|
|
240
|
+
*/
|
|
241
|
+
topping?: string;
|
|
242
|
+
};
|
|
195
243
|
}
|
|
196
244
|
export declare enum AddressEventCallbackName {
|
|
197
245
|
SHIPPING_CHANGE = "SHIPPING_CHANGE"
|
|
@@ -441,6 +489,15 @@ export interface IElementOptions {
|
|
|
441
489
|
onStartLoading: () => void;
|
|
442
490
|
onEndLoading: () => void;
|
|
443
491
|
};
|
|
492
|
+
/**
|
|
493
|
+
* 预览模式开关
|
|
494
|
+
* - true / 'web': 跳过真实 API 请求,使用 mock 数据,按 WebElement(inline)方式渲染(向后兼容,等同于 'web')
|
|
495
|
+
* - 'mobile': 跳过真实 API 请求,使用 mock 数据,按 MobileElement(popup)方式渲染,用于 mobileElement 降级预览
|
|
496
|
+
* - false / undefined: 发起真实请求(默认行为)
|
|
497
|
+
*
|
|
498
|
+
* 使用场景:B 端配置后台预览,C 端生产环境不应使用
|
|
499
|
+
*/
|
|
500
|
+
preview?: boolean | 'web' | 'mobile';
|
|
444
501
|
}
|
|
445
502
|
export interface IElementProcessors {
|
|
446
503
|
[ElementType.auth]: AuthProcessor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IElementStatus } from '../../../foundation';
|
|
2
|
-
import { CashierSdkActionQueryResult, Ianalytics, IPaymentSessionMetaData } from '../../../types';
|
|
2
|
+
import { CashierSdkActionQueryResult, DisplayTypeEnum, Ianalytics, IPaymentSessionMetaData } from '../../../types';
|
|
3
3
|
import { ContainerController } from './elementContainerService/containerService';
|
|
4
4
|
import { ELEMENT_ENVIRONMENT_TYPE, EventCallbackCode, IElementOptions, IToastOptions } from './type';
|
|
5
5
|
export declare const formatElementOption: (options: IElementOptions) => {
|
|
@@ -19,6 +19,7 @@ export declare const formatElementOption: (options: IElementOptions) => {
|
|
|
19
19
|
onStartLoading: () => void;
|
|
20
20
|
onEndLoading: () => void;
|
|
21
21
|
};
|
|
22
|
+
preview?: boolean | "mobile" | "web";
|
|
22
23
|
};
|
|
23
24
|
export declare const validateElementOption: (options: IElementOptions) => {
|
|
24
25
|
isValid: boolean;
|
|
@@ -48,7 +49,7 @@ export declare function checkCanUpdate({ status, paymentContainerService, newPay
|
|
|
48
49
|
newPaymentSessionData: string;
|
|
49
50
|
oldPaymentSessionData: string;
|
|
50
51
|
}): boolean;
|
|
51
|
-
export declare function generateIframeSrc({ paymentSessionObj, paymentSession, instanceId, environment, appVersion, analytics, locale, pageUrl, link, }: {
|
|
52
|
+
export declare function generateIframeSrc({ paymentSessionObj, paymentSession, instanceId, environment, appVersion, analytics, locale, pageUrl, link, renderDisplayType, }: {
|
|
52
53
|
paymentSessionObj: IPaymentSessionMetaData;
|
|
53
54
|
paymentSession: string;
|
|
54
55
|
environment: string;
|
|
@@ -58,6 +59,12 @@ export declare function generateIframeSrc({ paymentSessionObj, paymentSession, i
|
|
|
58
59
|
pageUrl: string;
|
|
59
60
|
appVersion: string;
|
|
60
61
|
link?: string;
|
|
62
|
+
/**
|
|
63
|
+
* iframe 中 checkout-v2 的渲染形态。
|
|
64
|
+
* - inline(默认): WebElement 渲染
|
|
65
|
+
* - popup: MobileElement 渲染(用于 mobileElement 降级预览)
|
|
66
|
+
*/
|
|
67
|
+
renderDisplayType?: DisplayTypeEnum;
|
|
61
68
|
}): string;
|
|
62
69
|
export declare function handleRedirect(data: any, fromFastSdk: boolean, eventCallback: ({ code, message }: {
|
|
63
70
|
code: any;
|
|
@@ -138,7 +138,8 @@ export function generateIframeSrc(_ref3) {
|
|
|
138
138
|
analytics = _ref3.analytics,
|
|
139
139
|
locale = _ref3.locale,
|
|
140
140
|
pageUrl = _ref3.pageUrl,
|
|
141
|
-
link = _ref3.link
|
|
141
|
+
link = _ref3.link,
|
|
142
|
+
renderDisplayType = _ref3.renderDisplayType;
|
|
142
143
|
var componentSign = getComponentSign(paymentSessionObj);
|
|
143
144
|
var productSceneVersion = (paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$pa = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa === void 0 ? void 0 : _paymentSessionObj$pa.productSceneVersion) || '';
|
|
144
145
|
var productScene = (paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$pa2 = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa2 === void 0 ? void 0 : _paymentSessionObj$pa2.productScene) || '';
|
|
@@ -151,7 +152,7 @@ export function generateIframeSrc(_ref3) {
|
|
|
151
152
|
link = "".concat(baseUrl[_env]).concat(pageUrl);
|
|
152
153
|
}
|
|
153
154
|
var _getIframeUrl = getIframeUrl({
|
|
154
|
-
renderDisplayType: DisplayTypeEnum.inline,
|
|
155
|
+
renderDisplayType: renderDisplayType !== null && renderDisplayType !== void 0 ? renderDisplayType : DisplayTypeEnum.inline,
|
|
155
156
|
componentSign: componentSign,
|
|
156
157
|
analytics: analytics,
|
|
157
158
|
productScene: productScene,
|
package/esm/modern/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { createLoader } from '@antglobal/create-sdk-loader';
|
|
|
15
15
|
|
|
16
16
|
import { stageName } from "./stageName";
|
|
17
17
|
var SDKURL = {
|
|
18
|
-
DEV: "https://sdk-dev.marmot-cloud.com/package/ams-checkout/".concat("2.0.
|
|
18
|
+
DEV: "https://sdk-dev.marmot-cloud.com/package/ams-checkout/".concat("2.0.20", "/ams-checkout.js"),
|
|
19
19
|
LOCAL: "http://localhost:3000/ams-checkout.min.js",
|
|
20
20
|
PROD: 'https://js.antom.com/v2/ams-checkout.js'
|
|
21
21
|
};
|