@alipay/ams-checkout 0.0.1757298389-dev.1 → 0.0.1757298389-dev.11

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.
Files changed (33) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/component/component.popup.style.d.ts +1 -0
  3. package/esm/component/component.popup.style.js +1 -1
  4. package/esm/config/index.d.ts +7 -7
  5. package/esm/config/index.js +7 -7
  6. package/esm/constant/index.d.ts +47 -0
  7. package/esm/constant/index.js +50 -0
  8. package/esm/core/component/element/EventCenter/index.d.ts +29 -0
  9. package/esm/core/component/element/EventCenter/index.js +141 -0
  10. package/esm/core/component/element/elementContainerService/containerService.js +3 -2
  11. package/esm/core/component/element/elementController/index.d.ts +20 -2
  12. package/esm/core/component/element/elementController/index.js +463 -262
  13. package/esm/core/component/element/elementProcessor/addressProcessor.js +3 -3
  14. package/esm/core/component/element/elementProcessor/paymentProcessor.js +20 -14
  15. package/esm/core/component/element/index.d.ts +6 -1
  16. package/esm/core/component/element/index.js +5 -2
  17. package/esm/core/component/element/type.d.ts +35 -3
  18. package/esm/core/component/element/type.js +43 -1
  19. package/esm/core/component/element/util.d.ts +17 -4
  20. package/esm/core/component/element/util.js +45 -6
  21. package/esm/core/component/index.d.ts +4 -1
  22. package/esm/core/component/index.js +105 -2
  23. package/esm/foundation/service/log/keys.js +2 -0
  24. package/esm/foundation/service/requester/requester.js +2 -3
  25. package/esm/index.d.ts +10 -1
  26. package/esm/index.js +15 -1
  27. package/esm/plugin/component/index.d.ts +2 -0
  28. package/esm/plugin/component/index.js +23 -7
  29. package/esm/plugin/paypal/index.js +5 -2
  30. package/esm/types/index.d.ts +8 -1
  31. package/esm/util/spm-map.d.ts +2 -0
  32. package/esm/util/spm-map.js +2 -1
  33. package/package.json +2 -2
@@ -20,9 +20,9 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
20
20
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
21
21
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
22
22
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
23
- import { ProductSceneEnum } from "../../../../types";
24
23
  import { parseSessionData } from "../..";
25
24
  import PackageJson from "../../../../../package.json";
25
+ import { ProductSceneEnum } from "../../../../types";
26
26
  import { generateIframeSrc as _generateIframeSrc } from "../util";
27
27
  import BaseElementProcessor from "./baseElementProcessor";
28
28
  var AddressProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
@@ -35,12 +35,12 @@ var AddressProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
35
35
  _createClass(AddressProcessor, [{
36
36
  key: "onReady",
37
37
  value: function onReady(extraParam) {
38
- var _paymentSessionObj$pa, _extraParam$originOne;
38
+ var _paymentSessionObj$co, _paymentSessionObj$pa, _extraParam$originOne;
39
39
  var paymentContext = this.elementContainer.getPaymentContext();
40
40
  var paymentSessionObj = paymentContext.paymentSessionObj,
41
41
  paymentSessionId = paymentContext.paymentSessionId,
42
42
  displayInfo = paymentContext.displayInfo;
43
- var isConnect = paymentSessionObj.connectFactor.enableConnect && ((_paymentSessionObj$pa = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa === void 0 ? void 0 : _paymentSessionObj$pa.productScene) === ProductSceneEnum.ELEMENT_PAYMENT;
43
+ var isConnect = ((_paymentSessionObj$co = paymentSessionObj.connectFactor) === null || _paymentSessionObj$co === void 0 ? void 0 : _paymentSessionObj$co.enableConnect) && ((_paymentSessionObj$pa = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa === void 0 ? void 0 : _paymentSessionObj$pa.productScene) === ProductSceneEnum.ELEMENT_PAYMENT;
44
44
  this.eventCenter.dispatchToApp({
45
45
  event: 'renderComponent',
46
46
  data: {
@@ -27,11 +27,11 @@ import PackageJson from "../../../../../package.json";
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 { LogConfig, Logger } from "../../../../util/logger";
31
30
  import { queryParse } from "../../../../util";
31
+ import { LogConfig, Logger } from "../../../../util/logger";
32
32
  import { parseSessionData } from "../../index";
33
33
  import { oneAccount, sdkAction } from "../mock";
34
- import { generateIframeSrc as _generateIframeSrc, isElementPC, isElementPad } from "../util";
34
+ import { generateIframeSrc as _generateIframeSrc, isElementPad, isElementPC } from "../util";
35
35
  import BaseElementProcessor from "./baseElementProcessor";
36
36
  var logger = new Logger(LogConfig, true);
37
37
  var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
@@ -58,7 +58,8 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
58
58
  event: 'renderComponent',
59
59
  data: {
60
60
  heightOfVisible: Math.max(window.changingPageHeight, window.innerHeight),
61
- paymentSessionData: paymentContext === null || paymentContext === void 0 ? void 0 : paymentContext.paymentSessionId,
61
+ // 极简架构需要全量sessionData, 服务端与谦评估没得影响
62
+ paymentSessionData: paymentContext === null || paymentContext === void 0 ? void 0 : paymentContext.paymentSession,
62
63
  queryResult: extraParam === null || extraParam === void 0 ? void 0 : extraParam.originActionQueryResult,
63
64
  envInfo: {
64
65
  screenHeight: screen.height,
@@ -242,18 +243,19 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
242
243
  value: function () {
243
244
  var _obtainData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
244
245
  var _paymentSessionObj$co;
245
- var requestService, _this$elementContaine8, paymentSession, paymentSessionObj, displayInfo, merchantAppointParam, _this$options2, environment, locale, _ref4, paymentSessionConfig, hostSign, isConnect, LOCAL_MOCK, _queryParse, appType, terminalType, generateActionQueryPromise, generateOneAccountQueryPromise, _yield$Promise$all, _yield$Promise$all2, originActionQueryResult, originOneAccountQueryResult;
246
+ var requestService, _this$elementContaine8, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$options2, environment, locale, _ref4, paymentSessionConfig, hostSign, isConnect, LOCAL_MOCK, _queryParse, appType, terminalType, generateActionQueryPromise, generateOneAccountQueryPromise, _yield$Promise$all, _yield$Promise$all2, originActionQueryResult, originOneAccountQueryResult;
246
247
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
247
248
  while (1) switch (_context2.prev = _context2.next) {
248
249
  case 0:
249
250
  requestService = ServiceProvider.getInstance(this.instanceId).getService('Requester');
250
251
  _this$elementContaine8 = this.elementContainer.getPaymentContext(), paymentSession = _this$elementContaine8.paymentSession, paymentSessionObj = _this$elementContaine8.paymentSessionObj, displayInfo = _this$elementContaine8.displayInfo;
251
- merchantAppointParam = displayInfo.merchantAppointParam;
252
+ _displayInfo = displayInfo;
253
+ debugProps = _displayInfo.debugProps;
252
254
  _this$options2 = this.options, environment = _this$options2.env.environment, locale = _this$options2.locale;
253
255
  _ref4 = paymentSessionObj || {}, paymentSessionConfig = _ref4.paymentSessionConfig;
254
256
  hostSign = paymentSession.split('&&')[1] || '';
255
257
  isConnect = paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$co = paymentSessionObj.connectFactor) === null || _paymentSessionObj$co === void 0 ? void 0 : _paymentSessionObj$co.enableConnect;
256
- LOCAL_MOCK = window.location.href.indexOf('LOCAL_MOCK=1') !== -1;
258
+ LOCAL_MOCK = (debugProps === null || debugProps === void 0 ? void 0 : debugProps.isDebug) && (debugProps === null || debugProps === void 0 ? void 0 : debugProps.local_mock);
257
259
  _queryParse = queryParse(this.getElementUrl()), appType = _queryParse.appType;
258
260
  terminalType = isElementPad() ? 'WEB' : appType ? 'APP' : isElementPC() ? 'WEB' : 'WAP';
259
261
  generateActionQueryPromise = function generateActionQueryPromise() {
@@ -267,7 +269,11 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
267
269
  }
268
270
  var sdkRequestData = {
269
271
  paymentSessionConfig: paymentSessionConfig,
270
- paymentSessionData: paymentSession
272
+ paymentSessionData: paymentSession,
273
+ extParams: {
274
+ // 必传,服务端用于根据前端传入locale判断是否使用用户偏好语言
275
+ isUserPreferredLocale: true
276
+ }
271
277
  };
272
278
  if (displayInfo !== null && displayInfo !== void 0 && (_displayInfo$merchant = displayInfo.merchantAppointParam) !== null && _displayInfo$merchant !== void 0 && _displayInfo$merchant.storedCard) {
273
279
  sdkRequestData.merchantAppointParam = displayInfo.merchantAppointParam;
@@ -287,8 +293,8 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
287
293
  'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query'
288
294
  }).then(function (result) {
289
295
  resolve(result);
290
- }, function () {
291
- reject('sdk.action.query Request Error');
296
+ }, function (e) {
297
+ reject(e);
292
298
  });
293
299
  });
294
300
  };
@@ -317,14 +323,14 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
317
323
  'Operation-Type': 'com.ipay.iexpfront.one.account.query'
318
324
  }).then(function (result) {
319
325
  resolve(result);
320
- }, function () {
321
- reject('one.account.query Request Error');
326
+ }, function (e) {
327
+ reject(e);
322
328
  });
323
329
  });
324
330
  };
325
- _context2.next = 14;
331
+ _context2.next = 15;
326
332
  return Promise.all(isConnect ? [generateActionQueryPromise(), generateOneAccountQueryPromise()] : [generateActionQueryPromise()]);
327
- case 14:
333
+ case 15:
328
334
  _yield$Promise$all = _context2.sent;
329
335
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
330
336
  originActionQueryResult = _yield$Promise$all2[0];
@@ -337,7 +343,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
337
343
  originActionQueryResult: originActionQueryResult,
338
344
  originOneAccountQueryResult: originOneAccountQueryResult
339
345
  });
340
- case 20:
346
+ case 21:
341
347
  case "end":
342
348
  return _context2.stop();
343
349
  }
@@ -10,6 +10,11 @@ export declare class ElementComponent {
10
10
  validateFields(): Promise<{
11
11
  isValid: boolean;
12
12
  }>;
13
- submitPayment(): void;
13
+ submitPayment(): Promise<import("./type").IMerchantResponse | {
14
+ error: {
15
+ code: string;
16
+ message: string;
17
+ };
18
+ }>;
14
19
  destroy(): void;
15
20
  }
@@ -11,6 +11,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
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
13
  import ElementController from "./elementController";
14
+ import { InvalidElementConfigError } from "./type";
14
15
  import { formatElementOption, validateElementOption } from "./util";
15
16
  export var ElementComponent = /*#__PURE__*/function () {
16
17
  function ElementComponent(options) {
@@ -18,7 +19,9 @@ export var ElementComponent = /*#__PURE__*/function () {
18
19
  _defineProperty(this, "options", void 0);
19
20
  _defineProperty(this, "controller", void 0);
20
21
  var validate = validateElementOption(options);
21
- if (!validate) return;
22
+ if (!validate.isValid) {
23
+ throw new InvalidElementConfigError(validate.errors);
24
+ }
22
25
  this.options = formatElementOption(options);
23
26
  this.controller = new ElementController(options);
24
27
  }
@@ -57,7 +60,7 @@ export var ElementComponent = /*#__PURE__*/function () {
57
60
  }, {
58
61
  key: "submitPayment",
59
62
  value: function submitPayment() {
60
- this.controller.submitPayment();
63
+ return this.controller.submitPayment();
61
64
  }
62
65
  }, {
63
66
  key: "destroy",
@@ -127,6 +127,10 @@ export interface LinkAuthMountOptions extends BaseMountOptions {
127
127
  theme?: ThemeType;
128
128
  };
129
129
  }
130
+ type ToCamelCase<S extends string> = S extends `${infer First}-${infer Rest}` ? `${First}${Capitalize<ToCamelCase<Rest>>}` : S;
131
+ type CompatibleVariables<T extends Record<string, string>> = {
132
+ [K in keyof T as K | ToCamelCase<K & string>]: string;
133
+ };
130
134
  export interface PaymentMountOptions extends BaseMountOptions {
131
135
  type: ElementType.payment;
132
136
  appearance?: {
@@ -134,7 +138,7 @@ export interface PaymentMountOptions extends BaseMountOptions {
134
138
  layout?: {
135
139
  type: PaymentElementLayout;
136
140
  };
137
- variables?: {
141
+ variables?: Partial<CompatibleVariables<{
138
142
  'content-primary': string;
139
143
  'content-secondary': string;
140
144
  'content-tertiary': string;
@@ -159,7 +163,8 @@ export interface PaymentMountOptions extends BaseMountOptions {
159
163
  'radius-module': string;
160
164
  'radius-component': string;
161
165
  'radius-button': string;
162
- };
166
+ 'warpper-padding': string;
167
+ }>>;
163
168
  };
164
169
  notRedirectAfterComplete?: boolean;
165
170
  merchantAppointParam?: IMerchantAppointParam;
@@ -360,7 +365,7 @@ export interface IElementOptions {
360
365
  appearance?: {
361
366
  theme: ThemeType.Default | ThemeType.Night;
362
367
  };
363
- onEventCallback?: ({ code, message, result }: {
368
+ onEventCallback?: ({ code, message, result, }: {
364
369
  code: EventCallbackCode;
365
370
  message: string;
366
371
  result?: any;
@@ -388,4 +393,31 @@ export interface IToastOptions {
388
393
  icon?: 'SUCCESS' | 'FAIL';
389
394
  spin?: boolean;
390
395
  }
396
+ export interface IMerchantResponse {
397
+ success?: boolean;
398
+ error?: {
399
+ code: string;
400
+ message?: string;
401
+ traceId?: string;
402
+ context?: any;
403
+ };
404
+ status?: string;
405
+ }
406
+ export declare class InvalidElementConfigError extends Error {
407
+ errors: Array<{
408
+ field: keyof IElementOptions;
409
+ message: string;
410
+ }>;
411
+ constructor(errors: Array<{
412
+ field: keyof IElementOptions;
413
+ message: string;
414
+ }>);
415
+ }
416
+ export declare enum EXPOSURE_API_EVENT {
417
+ DESTORY = "destroy",
418
+ MOUNT = "mount",
419
+ SUBMITPAYMENT = "submitPayment",
420
+ VALIDATAFIELDS = "validateFields",
421
+ UPDATEPAYMENT = "updatePayment"
422
+ }
391
423
  export {};
@@ -1,4 +1,17 @@
1
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 _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
6
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
8
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
9
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
10
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
11
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
+ function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
2
15
  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; }
3
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
17
  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); }
@@ -71,6 +84,11 @@ export var ELEMENT_ENVIRONMENT = /*#__PURE__*/function (ELEMENT_ENVIRONMENT) {
71
84
  ELEMENT_ENVIRONMENT["SANDBOX"] = "SANDBOX";
72
85
  return ELEMENT_ENVIRONMENT;
73
86
  }({});
87
+
88
+ // 将短横线命名转为小驼峰
89
+
90
+ // 同时兼容短横线和小驼峰两种键名
91
+
74
92
  // export type IMountOptions = AddressMountOptions | LinkAuthMountOptions | PaymentMountOptions;
75
93
 
76
94
  export var AddressEventCallbackName = /*#__PURE__*/function (AddressEventCallbackName) {
@@ -87,4 +105,28 @@ var AccountStatusEnum = /*#__PURE__*/function (AccountStatusEnum) {
87
105
  AccountStatusEnum["EFFECTIVE"] = "EFFECTIVE";
88
106
  AccountStatusEnum["UNREGISTERED"] = "UNREGISTERED";
89
107
  return AccountStatusEnum;
90
- }(AccountStatusEnum || {}); // element 接口start
108
+ }(AccountStatusEnum || {}); // element 接口start
109
+ export var InvalidElementConfigError = /*#__PURE__*/function (_Error) {
110
+ _inherits(InvalidElementConfigError, _Error);
111
+ var _super = _createSuper(InvalidElementConfigError);
112
+ function InvalidElementConfigError(errors) {
113
+ var _this;
114
+ _classCallCheck(this, InvalidElementConfigError);
115
+ var errorMessages = errors.map(function (e) {
116
+ return "".concat(e.field, ": ").concat(e.message);
117
+ });
118
+ _this = _super.call(this, "Invalid config:\n".concat(errorMessages.join('\n')));
119
+ _this.errors = errors;
120
+ _this.name = 'InvalidElementConfigError';
121
+ return _this;
122
+ }
123
+ return _createClass(InvalidElementConfigError);
124
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
125
+ export var EXPOSURE_API_EVENT = /*#__PURE__*/function (EXPOSURE_API_EVENT) {
126
+ EXPOSURE_API_EVENT["DESTORY"] = "destroy";
127
+ EXPOSURE_API_EVENT["MOUNT"] = "mount";
128
+ EXPOSURE_API_EVENT["SUBMITPAYMENT"] = "submitPayment";
129
+ EXPOSURE_API_EVENT["VALIDATAFIELDS"] = "validateFields";
130
+ EXPOSURE_API_EVENT["UPDATEPAYMENT"] = "updatePayment";
131
+ return EXPOSURE_API_EVENT;
132
+ }({});
@@ -1,7 +1,7 @@
1
1
  import { IElementStatus } from '../../../foundation';
2
- import { Ianalytics, IPaymentSessionMetaData } from '../../../types';
2
+ import { CashierSdkActionQueryResult, Ianalytics, IPaymentSessionMetaData } from '../../../types';
3
3
  import { ContainerController } from './elementContainerService/containerService';
4
- import { ELEMENT_ENVIRONMENT_TYPE, IElementOptions, IToastOptions, EventCallbackCode } from './type';
4
+ import { ELEMENT_ENVIRONMENT_TYPE, EventCallbackCode, IElementOptions, IToastOptions } from './type';
5
5
  export declare const formatElementOption: (options: IElementOptions) => {
6
6
  environment: ELEMENT_ENVIRONMENT_TYPE;
7
7
  sessionData: string;
@@ -10,7 +10,7 @@ export declare const formatElementOption: (options: IElementOptions) => {
10
10
  appearance?: {
11
11
  theme: import("./type").ThemeType.Default | import("./type").ThemeType.Night;
12
12
  };
13
- onEventCallback?: ({ code, message, result }: {
13
+ onEventCallback?: ({ code, message, result, }: {
14
14
  code: EventCallbackCode;
15
15
  message: string;
16
16
  result?: any;
@@ -20,7 +20,10 @@ export declare const formatElementOption: (options: IElementOptions) => {
20
20
  onEndLoading: () => void;
21
21
  };
22
22
  };
23
- export declare const validateElementOption: (options: IElementOptions) => boolean;
23
+ export declare const validateElementOption: (options: IElementOptions) => {
24
+ isValid: boolean;
25
+ errors: any[];
26
+ };
24
27
  /**
25
28
  * 校验渲染条件
26
29
  * 校验当前sdkSelector结点是否存在
@@ -32,6 +35,10 @@ export declare function checkCanMount({ sdkSelector, containerService, status, }
32
35
  }): {
33
36
  success: boolean;
34
37
  errorMsg?: string;
38
+ error?: {
39
+ code: string;
40
+ message?: string;
41
+ };
35
42
  };
36
43
  export declare function checkCanUpdate({ status, paymentContainerService, newPaymentSessionData, oldPaymentSessionData, }: {
37
44
  status: IElementStatus;
@@ -67,3 +74,9 @@ export declare const isElementMobile: () => boolean;
67
74
  */
68
75
  export declare const isElementPad: () => boolean;
69
76
  export declare const isElementPC: () => boolean;
77
+ /**
78
+ * 判断是否需要加载错误页
79
+ * @param {CashierSdkActionQueryResult} params
80
+ * @returns {boolean} - 是否需要加载错误页
81
+ */
82
+ export declare const isLoadErrorPage: (params: CashierSdkActionQueryResult) => boolean;
@@ -25,15 +25,24 @@ export var formatElementOption = function formatElementOption(options) {
25
25
  });
26
26
  };
27
27
  export var validateElementOption = function validateElementOption(options) {
28
+ var errors = [];
28
29
  if (!options.sessionData) {
30
+ errors.push({
31
+ field: 'sessionData',
32
+ message: 'sessionData is empty'
33
+ });
34
+ }
35
+ if (errors.length > 0) {
29
36
  var _options$onEventCallb;
30
37
  options === null || options === void 0 || (_options$onEventCallb = options.onEventCallback) === null || _options$onEventCallb === void 0 || _options$onEventCallb.call(options, {
31
38
  code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
32
39
  message: 'sessionData is empty'
33
40
  });
34
- return false;
35
41
  }
36
- return true;
42
+ return {
43
+ isValid: errors.length === 0,
44
+ errors: errors
45
+ };
37
46
  };
38
47
 
39
48
  /**
@@ -50,13 +59,15 @@ export function checkCanMount(_ref) {
50
59
  console.error("Element with selector ".concat(sdkSelector, " not found."));
51
60
  return {
52
61
  success: false,
53
- errorMsg: "Element with selector ".concat(sdkSelector, " not found.")
62
+ errorMsg: "Element with selector ".concat(sdkSelector, " not found."),
63
+ error: ERRORMESSAGE.PARAM_INVALID
54
64
  };
55
65
  }
56
66
  if (status === IElementStatus.DESTROYED) {
57
67
  return {
58
68
  success: false,
59
- errorMsg: "Creating components in the destroyed state is forbidden."
69
+ errorMsg: "Creating components in the destroyed state is forbidden.",
70
+ error: ERRORMESSAGE.UI_STATE_ERROR
60
71
  };
61
72
  }
62
73
  if (status === IElementStatus.READY) {
@@ -67,7 +78,8 @@ export function checkCanMount(_ref) {
67
78
  if (containerService) {
68
79
  return {
69
80
  success: false,
70
- errorMsg: "SDK status error."
81
+ errorMsg: "SDK status error.",
82
+ error: ERRORMESSAGE.UI_STATE_ERROR
71
83
  };
72
84
  }
73
85
  return {
@@ -429,7 +441,7 @@ export function showToast() {
429
441
  textAlign: 'center',
430
442
  marginTop: '12px',
431
443
  lineHeight: '20px',
432
- fontFamily: "Noto Sans",
444
+ fontFamily: 'Noto Sans',
433
445
  fontWeight: 400,
434
446
  fontSize: '14px'
435
447
  }
@@ -474,4 +486,31 @@ export var isElementPad = function isElementPad() {
474
486
  };
475
487
  export var isElementPC = function isElementPC() {
476
488
  return !isElementMobile();
489
+ };
490
+
491
+ /**
492
+ * 判断是否需要加载错误页
493
+ * @param {CashierSdkActionQueryResult} params
494
+ * @returns {boolean} - 是否需要加载错误页
495
+ */
496
+ export var isLoadErrorPage = function isLoadErrorPage(params) {
497
+ var success = params.success,
498
+ paymentMethods = params.paymentMethods,
499
+ savedPaymentMethods = params.savedPaymentMethods,
500
+ orderAmountView = params.orderAmountView,
501
+ paymentAmountView = params.paymentAmountView;
502
+
503
+ // 校验是否存在支付方式
504
+ var hasValidPaymentMethods = paymentMethods && Array.isArray(paymentMethods) && paymentMethods.length > 0 || savedPaymentMethods && Array.isArray(savedPaymentMethods) && savedPaymentMethods.length > 0;
505
+
506
+ // 金额存在性校验
507
+ var hasAmountViews = !!orderAmountView && !!paymentAmountView;
508
+
509
+ // 错误条件判断(满足任意条件即需要展示错误页)
510
+ return !success ||
511
+ // 接口请求失败
512
+ !hasValidPaymentMethods ||
513
+ // 无有效支付方式
514
+ !hasAmountViews // 缺少金额展示
515
+ ;
477
516
  };
@@ -1,5 +1,5 @@
1
1
  import ComponentApp from '../../plugin/component';
2
- import { ComponentSignEnum, IappendIframeNodesParams, IcreateComponent, IoptionsParams, IPaymentSessionMetaData, Iselector, Isubmit, PaymentMethodTypeEnum, SubPaymentMethodTypeEnum } from '../../types';
2
+ import { ComponentSignEnum, EventPayloadContext, IappendIframeNodesParams, IcreateComponent, IoptionsParams, IPaymentSessionMetaData, Iselector, Isubmit, PaymentMethodTypeEnum, SubPaymentMethodTypeEnum, ValidationResult } from '../../types';
3
3
  import CoreInstance from '../instance/index';
4
4
  export declare const getComponentSign: (params: IPaymentSessionMetaData) => ComponentSignEnum;
5
5
  export declare const parseSessionData: (sessionData: string) => [IPaymentSessionMetaData, string];
@@ -15,6 +15,7 @@ export declare class AMSComponent extends CoreInstance {
15
15
  channelType: ComponentSignEnum[];
16
16
  productSceneVersion: string;
17
17
  timer: any;
18
+ private _validateResolveMap;
18
19
  constructor(options: IAMSComponentOptions);
19
20
  private parameterInitAndCheck;
20
21
  private pluginAppendIframe;
@@ -52,4 +53,6 @@ export declare class AMSComponent extends CoreInstance {
52
53
  * @param data - Transfer information in the submission interface according to your requirements (optional)
53
54
  */
54
55
  submit(data?: Isubmit): Promise<unknown>;
56
+ protected _validateFields(): Promise<ValidationResult>;
57
+ protected _sendMessageToAPP(eventContext: EventPayloadContext): void;
55
58
  }
@@ -35,7 +35,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
35
35
  * 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.
36
36
  */
37
37
  import { v4 as uuid } from 'uuid';
38
- import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
38
+ import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT, SENDEVENT } from "../../constant";
39
+ import PreloadHelper from "../../foundation/utils/preload_helper";
39
40
  import { ApplePayBusSubscriber } from "../../plugin/applepay";
40
41
  import ComponentApp from "../../plugin/component";
41
42
  import { ExtendPlugin } from "../../plugin/const";
@@ -50,7 +51,6 @@ import { SecurityBusSubscriber } from "../bus/ability/security";
50
51
  import { TrackerBusSubscriber } from "../bus/ability/tracker";
51
52
  import CoreInstance from "../instance/index";
52
53
  import { loadChannelPneumaticControl } from "./appPreloadProcessing";
53
- import PreloadHelper from "../../foundation/utils/preload_helper";
54
54
  export var getComponentSign = function getComponentSign(params) {
55
55
  var _params$paymentSessio = params.paymentSessionConfig,
56
56
  _params$paymentSessio2 = _params$paymentSessio === void 0 ? {} : _params$paymentSessio,
@@ -140,6 +140,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
140
140
  _defineProperty(_assertThisInitialized(_this2), "channelType", void 0);
141
141
  _defineProperty(_assertThisInitialized(_this2), "productSceneVersion", void 0);
142
142
  _defineProperty(_assertThisInitialized(_this2), "timer", void 0);
143
+ _defineProperty(_assertThisInitialized(_this2), "_validateResolveMap", new Map());
143
144
  var ComponentPlugin = new ComponentApp({
144
145
  appVersion: options.appVersion
145
146
  });
@@ -526,6 +527,108 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
526
527
  }
527
528
  });
528
529
  }
530
+
531
+ // 预留给AMSVaulting复用
532
+ }, {
533
+ key: "_validateFields",
534
+ value: function _validateFields() {
535
+ var _this9 = this;
536
+ return new Promise(function (resolve) {
537
+ // 收银台应用渲染表单后,才允许发送校验消息,三端约定一致
538
+ if (!_this9._componentApp.shouldValidateFields()) {
539
+ resolve({
540
+ isValid: false
541
+ });
542
+ _this9.logger.logInfo({
543
+ title: 'sdk_event_validateFields'
544
+ }, {
545
+ processResult: 'notRenderComponent'
546
+ });
547
+ return;
548
+ }
549
+ var timeoutId;
550
+ var validationPromise = new Promise(function (validationResolve) {
551
+ var eventCallbackId = uuid();
552
+ _this9._validateResolveMap.set(eventCallbackId, validationResolve);
553
+ // 发送validateFields消息
554
+ _this9._sendMessageToAPP({
555
+ event: SENDEVENT.validateFields.name,
556
+ data: {},
557
+ eventCallbackId: eventCallbackId
558
+ });
559
+ var isValidationResult = function isValidationResult(data) {
560
+ return _typeof(data) === 'object' && data !== null && typeof data.isValid === 'boolean';
561
+ };
562
+ var callback = /*#__PURE__*/function () {
563
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload) {
564
+ var currentEventCallbackId, currentResolve, result;
565
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
566
+ while (1) switch (_context2.prev = _context2.next) {
567
+ case 0:
568
+ currentEventCallbackId = (payload === null || payload === void 0 ? void 0 : payload.eventCallbackId) || ''; // 事件一一对应,处理异步商户调用多次可能导致乱序的问题
569
+ currentResolve = _this9._validateResolveMap.get(currentEventCallbackId);
570
+ result = {
571
+ isValid: false
572
+ };
573
+ if (isValidationResult(payload === null || payload === void 0 ? void 0 : payload.data)) {
574
+ result = payload === null || payload === void 0 ? void 0 : payload.data;
575
+ }
576
+ _this9.logger.logInfo({
577
+ title: 'sdk_event_validateFields'
578
+ }, {
579
+ processResult: result.isValid ? 'true' : 'false'
580
+ });
581
+ // 收银台应用保证数据格式,三端SDK负责透传
582
+ if (!!currentResolve) {
583
+ currentResolve(result);
584
+ _this9._validateResolveMap.delete(currentEventCallbackId);
585
+ }
586
+ case 6:
587
+ case "end":
588
+ return _context2.stop();
589
+ }
590
+ }, _callee2);
591
+ }));
592
+ return function callback(_x2) {
593
+ return _ref5.apply(this, arguments);
594
+ };
595
+ }();
596
+ // 接收收银台应用的返回validateFieldsResult消息
597
+ // validateFieldsResultForward处理订阅eventCallbackId为空的问题
598
+ _this9._overrideSubscription(EVENT.validateFieldsResult.forwardName, callback, EVENT.validateFieldsResult.uniqueKey);
599
+ });
600
+
601
+ // 兜底场景,三端约定超时时间15秒,兼容cpf网络校验超时场景
602
+ var timeoutPromise = new Promise(function (timeoutResolve) {
603
+ timeoutId = setTimeout(function () {
604
+ _this9.logger.logInfo({
605
+ title: 'sdk_event_validateFields'
606
+ }, {
607
+ processResult: 'timeout'
608
+ });
609
+ timeoutResolve({
610
+ isValid: false
611
+ });
612
+ }, 15000);
613
+ });
614
+ Promise.race([validationPromise, timeoutPromise]).then(function (result) {
615
+ clearTimeout(timeoutId);
616
+ resolve(result);
617
+ }).catch(function () {
618
+ clearTimeout(timeoutId);
619
+ resolve({
620
+ isValid: false
621
+ });
622
+ });
623
+ });
624
+ }
625
+ }, {
626
+ key: "_sendMessageToAPP",
627
+ value: function _sendMessageToAPP(eventContext) {
628
+ this._componentApp.dispatchToApp({
629
+ context: eventContext
630
+ });
631
+ }
529
632
  }]);
530
633
  return AMSComponent;
531
634
  }(CoreInstance);
@@ -86,6 +86,8 @@ _defineProperty(LogComplianceExtendKeys, "complianceExtParams", {
86
86
  // 用来标记事件别名
87
87
  success: 'D',
88
88
  // 用来标记行为是否成功
89
+ startTime: 'D',
90
+ endTime: 'D',
89
91
  // M 数字类型
90
92
  timeCost: 'M',
91
93
  pageLoadProgress: 'M',
@@ -12,8 +12,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
12
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
13
  import axios from 'axios';
14
14
  import { ServiceProvider } from '..';
15
- import { errorEnum } from "./deps";
16
- import { appId, device, fomatGetwayError, get, hostSignMap, lightSandboxMap, queryParse, requestHost, safeJson, sdkVersion, sofaId, tntInstId } from "./deps";
15
+ import { appId, device, errorEnum, fomatGetwayError, get, hostSignMap, lightSandboxMap, queryParse, requestHost, safeJson, sdkVersion, sofaId, tntInstId } from "./deps";
17
16
 
18
17
  /**
19
18
  * @author congle.zzq <congle.zzq@alipay.com>
@@ -116,7 +115,7 @@ export var RequesterService = /*#__PURE__*/function () {
116
115
  errorMessage: _context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message
117
116
  });
118
117
  timeoutCode = _context.t0 !== null && _context.t0 !== void 0 && (_error$message = _context.t0.message) !== null && _error$message !== void 0 && _error$message.includes('timeout') ? errorEnum.TIMEOUT : '';
119
- _errorCode = (_error === null || _error === void 0 ? void 0 : _error.errorCode) || timeoutCode;
118
+ _errorCode = timeoutCode || (_error === null || _error === void 0 ? void 0 : _error.errorCode);
120
119
  this.reportRequestTimeCost({
121
120
  title: 'a3753.b101271.c388193.d521387',
122
121
  name: options === null || options === void 0 ? void 0 : options['Operation-Type'],