@alipay/ams-checkout 0.0.1756987734-dev.0 → 0.0.1756987734-dev.2

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.
@@ -6,10 +6,10 @@ export declare const sdkVersion: string;
6
6
  * @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
7
7
  * TODO 这里考虑直接换成packagejson.version
8
8
  */
9
- export declare const AMSCheckoutAppVersion = "1.42.1";
10
- export declare const AMSAutoDebitAppVersion = "1.42.1";
11
- export declare const AMSEasyPayAppVersion = "1.42.1";
12
- export declare const AMSCashierPaymentAppVersion = "1.42.1";
13
- export declare const AMSVaultingAppVersion = "1.42.1";
14
- export declare const AMSPaymentElementAppVersion = "1.42.1";
15
- export declare const ADDRESSElementAppVersion = "1.42.1";
9
+ export declare const AMSCheckoutAppVersion = "1.43.0";
10
+ export declare const AMSAutoDebitAppVersion = "1.43.0";
11
+ export declare const AMSEasyPayAppVersion = "1.43.0";
12
+ export declare const AMSCashierPaymentAppVersion = "1.43.0";
13
+ export declare const AMSVaultingAppVersion = "1.43.0";
14
+ export declare const AMSPaymentElementAppVersion = "1.43.0";
15
+ export declare const ADDRESSElementAppVersion = "1.43.0";
@@ -36,10 +36,10 @@ export var sdkVersion = json.version;
36
36
  * @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
37
37
  * TODO 这里考虑直接换成packagejson.version
38
38
  */
39
- export var AMSCheckoutAppVersion = '1.42.1'; // 兜底版本号
40
- export var AMSAutoDebitAppVersion = '1.42.1'; // 代扣
41
- export var AMSEasyPayAppVersion = '1.42.1'; // easypay
42
- export var AMSCashierPaymentAppVersion = '1.42.1'; // 收银台(卡、apm)
43
- export var AMSVaultingAppVersion = '1.42.1'; // 绑卡
44
- export var AMSPaymentElementAppVersion = '1.42.1'; // payment element
45
- export var ADDRESSElementAppVersion = '1.42.1'; // address element
39
+ export var AMSCheckoutAppVersion = '1.43.0'; // 兜底版本号
40
+ export var AMSAutoDebitAppVersion = '1.43.0'; // 代扣
41
+ export var AMSEasyPayAppVersion = '1.43.0'; // easypay
42
+ export var AMSCashierPaymentAppVersion = '1.43.0'; // 收银台(卡、apm)
43
+ export var AMSVaultingAppVersion = '1.43.0'; // 绑卡
44
+ export var AMSPaymentElementAppVersion = '1.43.0'; // payment element
45
+ export var ADDRESSElementAppVersion = '1.43.0'; // address element
@@ -249,6 +249,15 @@ export declare const EVENT: {
249
249
  messageForward: {
250
250
  name: string;
251
251
  };
252
+ validateFieldsResult: {
253
+ name: string;
254
+ uniqueKey: string;
255
+ };
256
+ };
257
+ export declare const SENDEVENT: {
258
+ validateFields: {
259
+ name: string;
260
+ };
252
261
  };
253
262
  export declare const COMPONENT_CONTAINER_ID = "ams-component-container";
254
263
  export declare const COMPONENT_SECTION_ID = "ams-component-section";
@@ -250,6 +250,17 @@ export var EVENT = {
250
250
  */
251
251
  messageForward: {
252
252
  name: 'onMessageForward'
253
+ },
254
+ validateFieldsResult: {
255
+ name: 'validateFieldsResult',
256
+ uniqueKey: 'uservalidateFieldsResult'
257
+ }
258
+ };
259
+
260
+ // 2025.09新增,非全量SDK发送事件码
261
+ export var SENDEVENT = {
262
+ validateFields: {
263
+ name: 'validateFields'
253
264
  }
254
265
  };
255
266
  export var COMPONENT_CONTAINER_ID = 'ams-component-container';
@@ -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];
@@ -52,4 +52,6 @@ export declare class AMSComponent extends CoreInstance {
52
52
  * @param data - Transfer information in the submission interface according to your requirements (optional)
53
53
  */
54
54
  submit(data?: Isubmit): Promise<unknown>;
55
+ protected _validateFields(): Promise<ValidationResult>;
56
+ protected _sendMessageToAPP(eventContext: EventPayloadContext): void;
55
57
  }
@@ -35,7 +35,7 @@ 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
39
  import { ApplePayBusSubscriber } from "../../plugin/applepay";
40
40
  import ComponentApp from "../../plugin/component";
41
41
  import { ExtendPlugin } from "../../plugin/const";
@@ -526,6 +526,88 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
526
526
  }
527
527
  });
528
528
  }
529
+
530
+ // 预留给AMSVaulting复用
531
+ }, {
532
+ key: "_validateFields",
533
+ value: function _validateFields() {
534
+ var _this9 = this;
535
+ return new Promise(function (resolve) {
536
+ // 收银台应用渲染表单后,才允许发送校验消息,三端约定一致
537
+ if (!_this9._componentApp.shouldValidateFields()) {
538
+ resolve({
539
+ isValid: false
540
+ });
541
+ _this9.logger.logInfo({
542
+ title: 'sdk_event_validateFields'
543
+ }, {
544
+ processResult: 'notRenderComponent'
545
+ });
546
+ return;
547
+ }
548
+ var timeoutId;
549
+ var validationPromise = new Promise(function (validationResolve) {
550
+ // 发送validateFields消息
551
+ _this9._sendMessageToAPP({
552
+ event: SENDEVENT.validateFields.name,
553
+ data: {}
554
+ });
555
+ // 接收收银台应用的返回validateFieldsResult消息
556
+ _this9._overrideSubscription(EVENT.validateFieldsResult.name, /*#__PURE__*/function () {
557
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload) {
558
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
559
+ while (1) switch (_context2.prev = _context2.next) {
560
+ case 0:
561
+ _this9.logger.logInfo({
562
+ title: 'sdk_event_validateFields'
563
+ }, {
564
+ processResult: payload.isValid ? 'true' : 'false'
565
+ });
566
+ // 收银台应用保证数据格式,三端SDK负责透传
567
+ validationResolve(payload);
568
+ case 2:
569
+ case "end":
570
+ return _context2.stop();
571
+ }
572
+ }, _callee2);
573
+ }));
574
+ return function (_x2) {
575
+ return _ref5.apply(this, arguments);
576
+ };
577
+ }(), EVENT.validateFieldsResult.uniqueKey);
578
+ });
579
+
580
+ // 兜底场景,三端约定超时时间15秒,兼容cpf网络校验超时场景
581
+ var timeoutPromise = new Promise(function (timeoutResolve) {
582
+ timeoutId = setTimeout(function () {
583
+ _this9.logger.logInfo({
584
+ title: 'sdk_event_validateFields'
585
+ }, {
586
+ processResult: 'timeout'
587
+ });
588
+ timeoutResolve({
589
+ isValid: false
590
+ });
591
+ }, 15000);
592
+ });
593
+ Promise.race([validationPromise, timeoutPromise]).then(function (result) {
594
+ clearTimeout(timeoutId);
595
+ resolve(result);
596
+ }).catch(function () {
597
+ clearTimeout(timeoutId);
598
+ resolve({
599
+ isValid: false
600
+ });
601
+ });
602
+ });
603
+ }
604
+ }, {
605
+ key: "_sendMessageToAPP",
606
+ value: function _sendMessageToAPP(eventContext) {
607
+ this._componentApp.dispatchToApp({
608
+ context: eventContext
609
+ });
610
+ }
529
611
  }]);
530
612
  return AMSComponent;
531
613
  }(CoreInstance);
package/esm/index.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/index.js CHANGED
@@ -111,7 +111,21 @@ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout2) {
111
111
  }
112
112
  return _super3.call(this, _options, currentChannelType);
113
113
  }
114
- _createClass(AMSCashierPayment, null, [{
114
+ _createClass(AMSCashierPayment, [{
115
+ key: "validateFields",
116
+ value:
117
+ /**
118
+ * Form validation function
119
+ * If the form is currently displayed:
120
+ * - Successful validation: isValid is true
121
+ * - Failed validation: isValid is false, and error messages are displayed on the form page
122
+ * If not on the form display page, isValid returns false
123
+ * @returns {Promise<ValidationResult>} Returns a Promise containing the validation result
124
+ */
125
+ function validateFields() {
126
+ return this._validateFields();
127
+ }
128
+ }], [{
115
129
  key: "preload",
116
130
  value: function preload() {
117
131
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
@@ -28,6 +28,7 @@ export default class ComponentApp {
28
28
  private _isAppWebview;
29
29
  _merchantAppointParam: IMerchantAppointParam;
30
30
  private _webAppHeartBeatTimeoutFn;
31
+ private _hasRenderComponent;
31
32
  constructor(componentOption?: {
32
33
  appVersion?: string;
33
34
  });
@@ -126,5 +127,6 @@ export default class ComponentApp {
126
127
  private showRetentionPopup;
127
128
  private hideRetentionPopupFunc;
128
129
  private submitForm;
130
+ shouldValidateFields(): boolean;
129
131
  }
130
132
  export {};
@@ -23,7 +23,7 @@ import { COMPONENTPLUGINID, COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CLOSE_MASK_BLOCK
23
23
  import { ElementPaymentMethod } from "../../core/component/oldElement/type";
24
24
  import { queryPaymentInfo, submitPayInfo } from "../../service";
25
25
  import { ComponentSignEnum, DisplayTypeEnum, eventCodeEnum, MessageName, PlatformEnum, ProductSceneEnum, RedirectType, TargetEnum } from "../../types";
26
- import { getType, isJsonString, isPC } from "../../util";
26
+ import { getType, isJsonString, isPC, device } from "../../util";
27
27
  import { getBackScheme } from "../../util/getBackScheme";
28
28
  import { isLocalMock } from "../../util/mock";
29
29
  import { matchVersion } from "../../util/versionCompare";
@@ -62,6 +62,7 @@ var ComponentApp = /*#__PURE__*/function () {
62
62
  _defineProperty(this, "_isAppWebview", void 0);
63
63
  _defineProperty(this, "_merchantAppointParam", void 0);
64
64
  _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
65
+ _defineProperty(this, "_hasRenderComponent", false);
65
66
  this._appVersion = componentOption.appVersion;
66
67
  this._isInitComponent = false;
67
68
  this._selector = "#".concat(COMPONENT_SECTION_ID);
@@ -71,7 +72,7 @@ var ComponentApp = /*#__PURE__*/function () {
71
72
  this.createPreloadIframeNode = function () {
72
73
  return Promise.resolve();
73
74
  };
74
- this.platform = isPC() ? PlatformEnum.desktop : PlatformEnum.mobile;
75
+ this.platform = device.isMobile ? PlatformEnum.mobile : PlatformEnum.desktop;
75
76
  this._isRetention = true;
76
77
  this._appLocationSearch = '';
77
78
  this._performanceData.push({
@@ -1842,6 +1843,7 @@ var ComponentApp = /*#__PURE__*/function () {
1842
1843
  return this._actionSubmitPromise;
1843
1844
  case 9:
1844
1845
  submitRes = _context8.sent;
1846
+ this._hasRenderComponent = true;
1845
1847
  this._performanceData.push({
1846
1848
  key: 'sdk_render_component',
1847
1849
  value: Date.now()
@@ -1897,16 +1899,16 @@ var ComponentApp = /*#__PURE__*/function () {
1897
1899
  }
1898
1900
  });
1899
1901
  // eslint-disable-next-line no-empty
1900
- _context8.next = 18;
1902
+ _context8.next = 19;
1901
1903
  break;
1902
- case 16:
1903
- _context8.prev = 16;
1904
+ case 17:
1905
+ _context8.prev = 17;
1904
1906
  _context8.t0 = _context8["catch"](0);
1905
- case 18:
1907
+ case 19:
1906
1908
  case "end":
1907
1909
  return _context8.stop();
1908
1910
  }
1909
- }, _callee8, this, [[0, 16]]);
1911
+ }, _callee8, this, [[0, 17]]);
1910
1912
  }));
1911
1913
  function sendRenderEvent() {
1912
1914
  return _sendRenderEvent.apply(this, arguments);
@@ -1933,6 +1935,7 @@ var ComponentApp = /*#__PURE__*/function () {
1933
1935
  this._performanceData = [];
1934
1936
  this._isInitComponent = false;
1935
1937
  this.app = null;
1938
+ this._hasRenderComponent = false;
1936
1939
  if (immediately) this.cleanElement();else {
1937
1940
  setTimeout(function () {
1938
1941
  _this10.cleanElement();
@@ -2019,6 +2022,11 @@ var ComponentApp = /*#__PURE__*/function () {
2019
2022
  form.submit();
2020
2023
  }, 0);
2021
2024
  }
2025
+ }, {
2026
+ key: "shouldValidateFields",
2027
+ value: function shouldValidateFields() {
2028
+ return this._hasRenderComponent;
2029
+ }
2022
2030
  }]);
2023
2031
  return ComponentApp;
2024
2032
  }();
@@ -40,6 +40,9 @@ export interface IoptionsParams {
40
40
  mode?: string;
41
41
  securityRegion?: 'US' | 'SG' | 'DE';
42
42
  }
43
+ export interface ValidationResult {
44
+ isValid: boolean;
45
+ }
43
46
  export interface IPreloadOptions {
44
47
  environment?: string;
45
48
  securityRegion?: 'US' | 'SG' | 'DE';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1756987734-dev.0",
3
+ "version": "0.0.1756987734-dev.2",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",