@alipay/ams-checkout 0.0.1766664288-dev.3 → 0.0.1766664288-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ams-checkout.js +3 -3
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/core/component/element/elementController/index.js +18 -15
- package/esm/core/component/element/type.d.ts +1 -9
- package/esm/core/component/element/util.js +12 -3
- package/esm/foundation/service/log/index.d.ts +1 -0
- package/esm/foundation/service/log/index.js +40 -3
- package/esm/main.d.ts +10 -1
- package/esm/main.js +17 -2
- package/esm/util/logger.d.ts +1 -0
- package/esm/util/logger.js +40 -3
- package/package.json +1 -1
|
@@ -23,8 +23,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
23
23
|
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; }
|
|
24
24
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
25
25
|
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); }
|
|
26
|
-
import {
|
|
27
|
-
import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
|
|
26
|
+
import { productEventScenarios, ProductScene } from "../config";
|
|
28
27
|
import { cleanMockup, removeRetentionPopup } from "../../../../component/component.popup.style";
|
|
29
28
|
import { destroyModal } from "../../../../component/popupWindow.style";
|
|
30
29
|
import { ERRORMESSAGE, EVENT, PROMISE_CALLBACK_CODE } from "../../../../constant";
|
|
@@ -34,15 +33,16 @@ import PaymentProcessor from "../../../../core/component/element/elementProcesso
|
|
|
34
33
|
import { IElementStatus } from "../../../../foundation";
|
|
35
34
|
import { AntomSDKCore } from "../../../../foundation/core";
|
|
36
35
|
import { ElementProcessor } from "../../../../foundation/product-processor/element";
|
|
36
|
+
import { ServiceProvider } from "../../../../foundation/service";
|
|
37
|
+
import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
|
|
37
38
|
import { ProductSceneEnum } from "../../../../types";
|
|
39
|
+
import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
|
|
38
40
|
import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
|
|
39
41
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
|
40
42
|
import { EventCenter as ElementEventCenter } from "../EventCenter/index";
|
|
41
43
|
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
|
42
44
|
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
|
|
43
45
|
import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeParse, safeStringify, showToast } from "../util";
|
|
44
|
-
import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
|
|
45
|
-
import { productEventScenarios, ProductScene } from "../config";
|
|
46
46
|
var TIMEOUT_DURATION = 10000;
|
|
47
47
|
var ElementController = /*#__PURE__*/function () {
|
|
48
48
|
function ElementController(options) {
|
|
@@ -370,7 +370,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
370
370
|
_context4.next = 11;
|
|
371
371
|
return new Promise( /*#__PURE__*/function () {
|
|
372
372
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
373
|
-
var that, recordResultCallback, params, processStep, _submitParams$handleA, _yield$_this3$onValid2, _data, errorResult;
|
|
373
|
+
var that, recordResultCallback, params, processStep, _submitParams$handleA, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
374
374
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
375
375
|
while (1) switch (_context3.prev = _context3.next) {
|
|
376
376
|
case 0:
|
|
@@ -446,28 +446,31 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
446
446
|
return _context3.abrupt("return");
|
|
447
447
|
case 14:
|
|
448
448
|
if (!_this3.elementProcessors[ElementType.payment]) {
|
|
449
|
-
_context3.next =
|
|
449
|
+
_context3.next = 21;
|
|
450
450
|
break;
|
|
451
451
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
452
|
+
_context3.next = 17;
|
|
453
|
+
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, _objectSpread(_objectSpread({}, params), {}, {
|
|
454
|
+
handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true
|
|
455
|
+
}));
|
|
456
|
+
case 17:
|
|
456
457
|
_yield$_this3$onValid2 = _context3.sent;
|
|
457
458
|
_data = _yield$_this3$onValid2.data;
|
|
458
459
|
// TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
|
|
459
460
|
// TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
|
|
460
461
|
recordResult = _data;
|
|
461
462
|
recordResultCallback(recordResult);
|
|
462
|
-
case
|
|
463
|
+
case 21:
|
|
463
464
|
_context3.next = 30;
|
|
464
465
|
break;
|
|
465
|
-
case
|
|
466
|
-
_context3.prev =
|
|
466
|
+
case 23:
|
|
467
|
+
_context3.prev = 23;
|
|
467
468
|
_context3.t0 = _context3["catch"](2);
|
|
469
|
+
// 修复error为{}空对象的问题,上报stack&message
|
|
470
|
+
errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
|
|
468
471
|
errorResult = {
|
|
469
472
|
error: _objectSpread(_objectSpread({}, ERRORMESSAGE.ERR_DATA_STRUCT_UNRECOGNIZED), {}, {
|
|
470
|
-
context:
|
|
473
|
+
context: errorString
|
|
471
474
|
}),
|
|
472
475
|
status: PaymentStatus.FAIL
|
|
473
476
|
};
|
|
@@ -482,7 +485,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
482
485
|
case "end":
|
|
483
486
|
return _context3.stop();
|
|
484
487
|
}
|
|
485
|
-
}, _callee3, null, [[2,
|
|
488
|
+
}, _callee3, null, [[2, 23]]);
|
|
486
489
|
}));
|
|
487
490
|
return function (_x2) {
|
|
488
491
|
return _ref3.apply(this, arguments);
|
|
@@ -261,20 +261,12 @@ export interface AddressSubmitData {
|
|
|
261
261
|
shippingId: string;
|
|
262
262
|
actionFlag?: 'I' | 'U' | 'D';
|
|
263
263
|
}
|
|
264
|
-
export interface HandleAction {
|
|
265
|
-
APM?: boolean;
|
|
266
|
-
CARD?: boolean;
|
|
267
|
-
VA?: boolean;
|
|
268
|
-
AC_WALLET?: boolean;
|
|
269
|
-
}
|
|
270
|
-
export type HandleActionType = boolean | HandleAction;
|
|
271
264
|
export interface SubmitFuncParams {
|
|
272
|
-
handleActions?:
|
|
265
|
+
handleActions?: boolean;
|
|
273
266
|
}
|
|
274
267
|
export interface SubmitServiceParams extends PaymentSubmitData {
|
|
275
268
|
accountInfo: AuthSubmitData['accountInfo'];
|
|
276
269
|
shipping?: AddressSubmitData;
|
|
277
|
-
handleActions?: HandleActionType;
|
|
278
270
|
}
|
|
279
271
|
interface SubmitResultActionForm extends ActionForm {
|
|
280
272
|
paymentCodeExpireTime: string;
|
|
@@ -63,14 +63,20 @@ export function checkCanMount(_ref) {
|
|
|
63
63
|
return {
|
|
64
64
|
success: false,
|
|
65
65
|
errorMsg: "Element with selector ".concat(sdkSelector, " not found."),
|
|
66
|
-
error:
|
|
66
|
+
error: {
|
|
67
|
+
code: ERRORMESSAGE.PARAM_INVALID.code,
|
|
68
|
+
message: "Element with selector ".concat(sdkSelector, " not found.")
|
|
69
|
+
}
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
72
|
if (status === IElementStatus.DESTROYED) {
|
|
70
73
|
return {
|
|
71
74
|
success: false,
|
|
72
75
|
errorMsg: "Creating components in the destroyed state is forbidden.",
|
|
73
|
-
error:
|
|
76
|
+
error: {
|
|
77
|
+
code: ERRORMESSAGE.UI_STATE_ERROR.code,
|
|
78
|
+
message: "Creating components in the destroyed state is forbidden."
|
|
79
|
+
}
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
if (status === IElementStatus.READY) {
|
|
@@ -82,7 +88,10 @@ export function checkCanMount(_ref) {
|
|
|
82
88
|
return {
|
|
83
89
|
success: false,
|
|
84
90
|
errorMsg: "SDK status error.",
|
|
85
|
-
error:
|
|
91
|
+
error: {
|
|
92
|
+
code: ERRORMESSAGE.UI_STATE_ERROR.code,
|
|
93
|
+
message: "SDK status error."
|
|
94
|
+
}
|
|
86
95
|
};
|
|
87
96
|
}
|
|
88
97
|
return {
|
|
@@ -35,6 +35,7 @@ export declare class LogService implements Service {
|
|
|
35
35
|
log(type: string, payload: LogPayload, extra?: LogExtra, enableExtractCompliance?: boolean): LogService;
|
|
36
36
|
private reportLogs;
|
|
37
37
|
private loadScript;
|
|
38
|
+
private fallbackLoadScript;
|
|
38
39
|
private initTracker;
|
|
39
40
|
send(): void;
|
|
40
41
|
setComponentStartTime(val: number): void;
|
|
@@ -183,6 +183,43 @@ export var LogService = /*#__PURE__*/function () {
|
|
|
183
183
|
}, {
|
|
184
184
|
key: "loadScript",
|
|
185
185
|
value: function loadScript(url, callback) {
|
|
186
|
+
var _this3 = this;
|
|
187
|
+
/*
|
|
188
|
+
* 如果宿主环境存在AMD加载器,通过直接创建script标签的方式加载会造成宿主环境报错:
|
|
189
|
+
* Message: Mismatched anonymous define() module
|
|
190
|
+
* 原因是直接通过script标签加载的模块如果没有定义模块名,会被AMD加载器认为是匿名模块,
|
|
191
|
+
* 而宿主环境中已经存在匿名模块,导致报错。
|
|
192
|
+
*
|
|
193
|
+
* TODO: 所有通过window.iTracker调用的方法都需要判断
|
|
194
|
+
* 是否是AMD环境,如果是,需要通过require加载获取iTracker实例
|
|
195
|
+
* */
|
|
196
|
+
if (typeof window.define === 'function' && window.define.amd && typeof window.require === 'function') {
|
|
197
|
+
var moduleId = 'antom_iTracker';
|
|
198
|
+
try {
|
|
199
|
+
var _specified, _ref;
|
|
200
|
+
// 避免重复 config
|
|
201
|
+
if (!((_specified = (_ref = window.require).specified) !== null && _specified !== void 0 && _specified.call(_ref, moduleId))) {
|
|
202
|
+
// @ts-expect-error amd
|
|
203
|
+
window.require.config({
|
|
204
|
+
paths: _defineProperty({}, moduleId, url.replace(/\.js$/, ''))
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// @ts-expect-error amd
|
|
209
|
+
window.require([moduleId], callback, function (err) {
|
|
210
|
+
console.error('AMD load failed, falling back to script tag', err);
|
|
211
|
+
_this3.fallbackLoadScript(url, callback);
|
|
212
|
+
});
|
|
213
|
+
return;
|
|
214
|
+
} catch (e) {
|
|
215
|
+
console.warn('require not available, using script tag', e);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
this.fallbackLoadScript(url, callback);
|
|
219
|
+
}
|
|
220
|
+
}, {
|
|
221
|
+
key: "fallbackLoadScript",
|
|
222
|
+
value: function fallbackLoadScript(url, callback) {
|
|
186
223
|
var script = document.createElement('script');
|
|
187
224
|
script.type = 'text/javascript';
|
|
188
225
|
script.src = url;
|
|
@@ -195,16 +232,16 @@ export var LogService = /*#__PURE__*/function () {
|
|
|
195
232
|
}, {
|
|
196
233
|
key: "initTracker",
|
|
197
234
|
value: function initTracker() {
|
|
198
|
-
var
|
|
235
|
+
var _this4 = this;
|
|
199
236
|
if (this.isLoaded) return;
|
|
200
237
|
this.isLoaded = true;
|
|
201
238
|
try {
|
|
202
239
|
if (typeof localStorage !== 'undefined') {
|
|
203
240
|
this.loadScript(this.config.scriptUrl, function () {
|
|
204
241
|
var _window4;
|
|
205
|
-
(_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(
|
|
242
|
+
(_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this4.config);
|
|
206
243
|
setTimeout(function () {
|
|
207
|
-
|
|
244
|
+
_this4.reportLogs();
|
|
208
245
|
}, 80);
|
|
209
246
|
});
|
|
210
247
|
}
|
package/esm/main.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddressComponent } from './core/component/address';
|
|
2
2
|
import { ElementComponent } from './core/component/element';
|
|
3
3
|
import { AMSComponent } from './core/component/index';
|
|
4
|
-
import { ComponentSignEnum, IcreateComponent, IElementOptions, IoptionsAddressParams, IoptionsParams, IPreloadOptions } from './types';
|
|
4
|
+
import { ComponentSignEnum, IcreateComponent, IElementOptions, IoptionsAddressParams, IoptionsParams, IPreloadOptions, ValidationResult } from './types';
|
|
5
5
|
export { AMSCheckoutPage } from './core/component/ckp';
|
|
6
6
|
export * from './types';
|
|
7
7
|
export declare class AMSCheckout extends AMSComponent {
|
|
@@ -14,6 +14,15 @@ export declare class AMSAutoDebitPay extends AMSCheckout {
|
|
|
14
14
|
export declare class AMSCashierPayment extends AMSCheckout {
|
|
15
15
|
constructor(options: IoptionsParams);
|
|
16
16
|
static preload(options?: IPreloadOptions): void;
|
|
17
|
+
/**
|
|
18
|
+
* Form validation function
|
|
19
|
+
* If the form is currently displayed:
|
|
20
|
+
* - Successful validation: isValid is true
|
|
21
|
+
* - Failed validation: isValid is false, and error messages are displayed on the form page
|
|
22
|
+
* If not on the form display page, isValid returns false
|
|
23
|
+
* @returns {Promise<ValidationResult>} Returns a Promise containing the validation result
|
|
24
|
+
*/
|
|
25
|
+
validateFields(): Promise<ValidationResult>;
|
|
17
26
|
}
|
|
18
27
|
export declare class AMSVaulting extends AMSCheckout {
|
|
19
28
|
constructor(options: IoptionsParams);
|
package/esm/main.js
CHANGED
|
@@ -112,7 +112,21 @@ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout2) {
|
|
|
112
112
|
}
|
|
113
113
|
return _super3.call(this, _options, currentChannelType);
|
|
114
114
|
}
|
|
115
|
-
_createClass(AMSCashierPayment,
|
|
115
|
+
_createClass(AMSCashierPayment, [{
|
|
116
|
+
key: "validateFields",
|
|
117
|
+
value:
|
|
118
|
+
/**
|
|
119
|
+
* Form validation function
|
|
120
|
+
* If the form is currently displayed:
|
|
121
|
+
* - Successful validation: isValid is true
|
|
122
|
+
* - Failed validation: isValid is false, and error messages are displayed on the form page
|
|
123
|
+
* If not on the form display page, isValid returns false
|
|
124
|
+
* @returns {Promise<ValidationResult>} Returns a Promise containing the validation result
|
|
125
|
+
*/
|
|
126
|
+
function validateFields() {
|
|
127
|
+
return this._validateFields();
|
|
128
|
+
}
|
|
129
|
+
}], [{
|
|
116
130
|
key: "preload",
|
|
117
131
|
value: function preload() {
|
|
118
132
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
@@ -238,7 +252,8 @@ export var AMSEasyPay = /*#__PURE__*/function () {
|
|
|
238
252
|
displayInfo: {
|
|
239
253
|
type: DisplayTypeEnum.popup
|
|
240
254
|
},
|
|
241
|
-
isAppWebview: params.isAppWebview
|
|
255
|
+
isAppWebview: params.isAppWebview,
|
|
256
|
+
isNativeAppWebview: params.isNativeAppWebview
|
|
242
257
|
});
|
|
243
258
|
}
|
|
244
259
|
}, {
|
package/esm/util/logger.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export declare class Logger {
|
|
|
56
56
|
reportRPC(rpcData: LogPayload, extra?: Extra): Logger;
|
|
57
57
|
reportLogs(): void;
|
|
58
58
|
loadScript(url: string, callback: () => void): void;
|
|
59
|
+
private fallbackLoadScript;
|
|
59
60
|
initTracker(): void;
|
|
60
61
|
send(): void;
|
|
61
62
|
setComponentStartTime(val: number): void;
|
package/esm/util/logger.js
CHANGED
|
@@ -176,6 +176,43 @@ export var Logger = /*#__PURE__*/function () {
|
|
|
176
176
|
}, {
|
|
177
177
|
key: "loadScript",
|
|
178
178
|
value: function loadScript(url, callback) {
|
|
179
|
+
var _this5 = this;
|
|
180
|
+
/*
|
|
181
|
+
* 如果宿主环境存在AMD加载器,通过直接创建script标签的方式加载会造成宿主环境报错:
|
|
182
|
+
* Message: Mismatched anonymous define() module
|
|
183
|
+
* 原因是直接通过script标签加载的模块如果没有定义模块名,会被AMD加载器认为是匿名模块,
|
|
184
|
+
* 而宿主环境中已经存在匿名模块,导致报错。
|
|
185
|
+
*
|
|
186
|
+
* TODO: 所有通过window.iTracker调用的方法都需要判断
|
|
187
|
+
* 是否是AMD环境,如果是,需要通过require加载获取iTracker实例
|
|
188
|
+
* */
|
|
189
|
+
if (typeof window.define === 'function' && window.define.amd && typeof window.require === 'function') {
|
|
190
|
+
var moduleId = 'antom_iTracker';
|
|
191
|
+
try {
|
|
192
|
+
var _specified, _ref;
|
|
193
|
+
// 避免重复 config
|
|
194
|
+
if (!((_specified = (_ref = window.require).specified) !== null && _specified !== void 0 && _specified.call(_ref, moduleId))) {
|
|
195
|
+
// @ts-expect-error amd
|
|
196
|
+
window.require.config({
|
|
197
|
+
paths: _defineProperty({}, moduleId, url.replace(/\.js$/, ''))
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// @ts-expect-error amd
|
|
202
|
+
window.require([moduleId], callback, function (err) {
|
|
203
|
+
console.error('AMD load failed, falling back to script tag', err);
|
|
204
|
+
_this5.fallbackLoadScript(url, callback);
|
|
205
|
+
});
|
|
206
|
+
return;
|
|
207
|
+
} catch (e) {
|
|
208
|
+
console.warn('require not available, using script tag', e);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
this.fallbackLoadScript(url, callback);
|
|
212
|
+
}
|
|
213
|
+
}, {
|
|
214
|
+
key: "fallbackLoadScript",
|
|
215
|
+
value: function fallbackLoadScript(url, callback) {
|
|
179
216
|
var script = document.createElement('script');
|
|
180
217
|
script.type = 'text/javascript';
|
|
181
218
|
script.src = url;
|
|
@@ -188,16 +225,16 @@ export var Logger = /*#__PURE__*/function () {
|
|
|
188
225
|
}, {
|
|
189
226
|
key: "initTracker",
|
|
190
227
|
value: function initTracker() {
|
|
191
|
-
var
|
|
228
|
+
var _this6 = this;
|
|
192
229
|
if (this.isLoaded) return;
|
|
193
230
|
this.isLoaded = true;
|
|
194
231
|
try {
|
|
195
232
|
if (typeof localStorage !== 'undefined') {
|
|
196
233
|
this.loadScript(this.config.scriptUrl, function () {
|
|
197
234
|
var _window4;
|
|
198
|
-
(_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(
|
|
235
|
+
(_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this6.config);
|
|
199
236
|
setTimeout(function () {
|
|
200
|
-
|
|
237
|
+
_this6.reportLogs();
|
|
201
238
|
}, 80);
|
|
202
239
|
});
|
|
203
240
|
}
|