@alipay/ams-checkout 1.10.1 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/config/request.js +3 -3
  3. package/esm/core/bus/ability/callback.d.ts +9 -0
  4. package/esm/core/bus/ability/callback.js +55 -0
  5. package/esm/core/bus/ability/security.d.ts +10 -0
  6. package/esm/core/bus/ability/security.js +104 -0
  7. package/esm/core/bus/ability/tracker.d.ts +9 -0
  8. package/esm/core/bus/ability/tracker.js +77 -0
  9. package/esm/core/bus/index.d.ts +125 -0
  10. package/esm/core/bus/index.js +366 -0
  11. package/esm/core/bus/interface.d.ts +32 -0
  12. package/esm/core/bus/interface.js +35 -0
  13. package/esm/core/component/index.d.ts +16 -1
  14. package/esm/core/component/index.js +189 -30
  15. package/esm/core/instance/index.d.ts +5 -1
  16. package/esm/core/instance/index.js +45 -7
  17. package/esm/index.d.ts +0 -3
  18. package/esm/index.js +8 -18
  19. package/esm/{core/applepay/index.d.ts → plugin/applepay/component.d.ts} +27 -8
  20. package/esm/{core/applepay/index.js → plugin/applepay/component.js} +150 -180
  21. package/esm/plugin/applepay/index.d.ts +17 -0
  22. package/esm/plugin/applepay/index.js +117 -0
  23. package/esm/{common → plugin}/applepay/interface.d.ts +62 -3
  24. package/esm/plugin/applepay/interface.js +69 -0
  25. package/esm/{common/applepay/index.d.ts → plugin/applepay/service.d.ts} +13 -7
  26. package/esm/{common/applepay/index.js → plugin/applepay/service.js} +159 -41
  27. package/esm/plugin/component/component.popup.style.js +1 -1
  28. package/esm/plugin/component/index.d.ts +3 -4
  29. package/esm/plugin/component/index.js +81 -49
  30. package/esm/plugin/const.d.ts +2 -0
  31. package/esm/plugin/const.js +19 -0
  32. package/esm/plugin/type.d.ts +33 -0
  33. package/esm/request/index.d.ts +1 -1
  34. package/esm/request/index.js +8 -14
  35. package/esm/service/index.d.ts +1 -1
  36. package/esm/types/index.d.ts +65 -6
  37. package/esm/types/index.js +8 -1
  38. package/esm/util/versionCompare.d.ts +2 -0
  39. package/esm/util/versionCompare.js +75 -0
  40. package/package.json +1 -1
  41. /package/esm/{common/applepay/interface.js → plugin/type.js} +0 -0
@@ -1,4 +1,6 @@
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 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; }
3
+ 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; }
2
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
5
  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); } }
4
6
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -28,11 +30,17 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
28
30
  import { v4 as uuid } from 'uuid';
29
31
  import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
30
32
  import ComponentApp from "../../plugin/component";
31
- import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
33
+ import { componentSignEnum, environmentEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
32
34
  import { getOrSetStorageId, isPC, parseBase64ToString } from "../../util";
33
35
  import { createIframeNode, createPreloadIframeNode } from "../../util/createIframeNode";
34
36
  import { getSecurityConfigStorageKey } from "../../util/security";
35
37
  import CoreInstance from "../instance/index";
38
+ import { BusManager, BusMessage } from "../bus";
39
+ import { SDKCallbackBusSubscriber } from "../bus/ability/callback";
40
+ import { ApplePayBusSubscriber } from "../../plugin/applepay";
41
+ import { SecurityBusSubscriber } from "../bus/ability/security";
42
+ import { TrackerBusSubscriber } from "../bus/ability/tracker";
43
+ import { ExtendPlugin } from "../../plugin/const";
36
44
  export var getComponentSign = function getComponentSign(params) {
37
45
  var _params$paymentSessio = params.paymentSessionConfig,
38
46
  _params$paymentSessio2 = _params$paymentSessio === void 0 ? {} : _params$paymentSessio,
@@ -66,7 +74,7 @@ var handleSessionData = function handleSessionData(originSessionData) {
66
74
  parseData = _parseSessionData2[0],
67
75
  sessionData = _parseSessionData2[1];
68
76
  resetEasyPaySceneVersion(parseData);
69
- return [parseData, sessionData];
77
+ return [parseData !== null && parseData !== void 0 ? parseData : {}, sessionData];
70
78
  };
71
79
  var handleParams = function handleParams(params) {
72
80
  var _params = Object.assign({
@@ -108,12 +116,14 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
108
116
  _defineProperty(_assertThisInitialized(_this), "_componentApp", void 0);
109
117
  _defineProperty(_assertThisInitialized(_this), "channelType", void 0);
110
118
  _defineProperty(_assertThisInitialized(_this), "productSceneVersion", void 0);
119
+ _defineProperty(_assertThisInitialized(_this), "timer", void 0);
111
120
  var ComponentPlugin = new ComponentApp();
112
121
  ComponentPlugin.setRender(createIframeNode);
113
122
  ComponentPlugin.setPreloadRender(createPreloadIframeNode);
114
123
  // Register Cashier Application Plug in
115
124
  _this._registerPlugin(COMPONENTPLUGINID, ComponentPlugin);
116
125
  _this._componentApp = _this._getPlugin(COMPONENTPLUGINID);
126
+ _this.registerBusAbility();
117
127
  return _this;
118
128
  }
119
129
  _createClass(AMSComponent, [{
@@ -188,6 +198,108 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
188
198
  localStorage.setItem('antom_checkout_previousChannel', JSON.stringify(previousChannel));
189
199
  }
190
200
  }
201
+
202
+ /**
203
+ * 初始化 Bus总线的能力
204
+ */
205
+ }, {
206
+ key: "registerBusAbility",
207
+ value: function registerBusAbility() {
208
+ var _this$originOptions,
209
+ _this2 = this;
210
+ BusManager.debugTrace(((_this$originOptions = this.originOptions) === null || _this$originOptions === void 0 ? void 0 : _this$originOptions.environment) !== environmentEnum.prod, this.logger);
211
+ BusManager.clear();
212
+ BusManager.addInterceptor({
213
+ onPublishException: function onPublishException(message, e) {
214
+ _this2.logger.logError({
215
+ title: 'onBusPublishException'
216
+ }, _objectSpread(_objectSpread({}, message), {}, {
217
+ errorMessage: JSON.stringify(e)
218
+ }));
219
+ }
220
+ });
221
+ // subscribe basic ablility
222
+ BusManager.subscribe(new SDKCallbackBusSubscriber(function (state) {
223
+ var _this2$_componentApp;
224
+ (_this2$_componentApp = _this2._componentApp) === null || _this2$_componentApp === void 0 || (_this2$_componentApp = _this2$_componentApp.AMSSDK) === null || _this2$_componentApp === void 0 || _this2$_componentApp._eventCenter.emit(EVENT.eventCallback.name, state);
225
+ }));
226
+ BusManager.subscribe(new SecurityBusSubscriber(function (deviceIdParameter, isPolling) {
227
+ var _this2$_componentApp2;
228
+ return (_this2$_componentApp2 = _this2._componentApp) === null || _this2$_componentApp2 === void 0 ? void 0 : _this2$_componentApp2.getDeviceIdAndLog(deviceIdParameter, isPolling);
229
+ }));
230
+ BusManager.subscribe(new TrackerBusSubscriber(this.logger));
231
+ // subscribe plugin
232
+ BusManager.subscribe(new ApplePayBusSubscriber(this.logger));
233
+
234
+ // register bus plugin
235
+ ExtendPlugin.forEach(function (item) {
236
+ var _item$busActionNames;
237
+ if (item !== null && item !== void 0 && item.busSubscriber) {
238
+ BusManager.subscribe(item === null || item === void 0 ? void 0 : item.busSubscriber);
239
+ }
240
+ var paymentChannelMatcher = item.paymentChannelMatcher;
241
+ if (paymentChannelMatcher) {
242
+ _this2._registerPlugin(paymentChannelMatcher.paymentMethod, item.busActionNames);
243
+ }
244
+ var sessionMatcher = item.sessionMatcher;
245
+ if (sessionMatcher) {
246
+ var pluginKey = sessionMatcher.productScene + sessionMatcher.productSceneVersion + sessionMatcher.paymentMethodCategoryType;
247
+ if (sessionMatcher.paymentMethodTypes) {
248
+ sessionMatcher.paymentMethodTypes.forEach(function (paymentMethodType) {
249
+ var subPluginKey = pluginKey + paymentMethodType;
250
+ _this2._registerPlugin(subPluginKey, item.busActionNames);
251
+ });
252
+ } else {
253
+ _this2._registerPlugin(pluginKey, item.busActionNames);
254
+ }
255
+ }
256
+ var optInit = item === null || item === void 0 || (_item$busActionNames = item.busActionNames) === null || _item$busActionNames === void 0 ? void 0 : _item$busActionNames.optional_init;
257
+ if (optInit) {
258
+ BusManager.publish(new BusMessage(optInit, JSON.stringify(_this2.originOptions)));
259
+ }
260
+ });
261
+ }
262
+
263
+ /**
264
+ * To determine whether the corresponding payment method is available,
265
+ * only the channel described in the document will be called, and it will be returned as available by default
266
+ * @param paymentMethod - described in the document
267
+ * @param subPaymentMethod - described in the document
268
+ * @returns
269
+ */
270
+ }, {
271
+ key: "canMakePayments",
272
+ value: function canMakePayments(paymentMethod, subPaymentMethod) {
273
+ var _this3 = this;
274
+ // 判断支付方式是否可用
275
+ return new Promise(function (resolve) {
276
+ var _this3$_getPlugin;
277
+ if (!paymentMethod) {
278
+ return resolve(true);
279
+ }
280
+ var actionName = (_this3$_getPlugin = _this3._getPlugin(paymentMethod)) === null || _this3$_getPlugin === void 0 ? void 0 : _this3$_getPlugin.canMakePayments;
281
+ if (actionName && BusManager.isSubscribed(actionName)) {
282
+ BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
283
+ paymentMethod: paymentMethod,
284
+ subPaymentMethod: subPaymentMethod
285
+ })), {
286
+ fallback: false
287
+ }).then(function (message) {
288
+ resolve(message.getJSONObject());
289
+ }).catch(function (e) {
290
+ _this3.logger.logInfo({
291
+ title: 'canMakePayments_error'
292
+ }, {
293
+ params: JSON.stringify(e)
294
+ });
295
+ resolve(false);
296
+ });
297
+ } else {
298
+ resolve(true);
299
+ }
300
+ });
301
+ }
302
+
191
303
  /**
192
304
  * @description Create component application
193
305
  * @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
@@ -195,7 +307,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
195
307
  }, {
196
308
  key: "createComponent",
197
309
  value: function createComponent(params) {
198
- var _this2 = this;
310
+ var _this4 = this;
199
311
  this.clearPreloadIframe();
200
312
  return this.parameterInitAndCheck({
201
313
  params: params,
@@ -203,23 +315,39 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
203
315
  }).then(function (_params) {
204
316
  return handleParams(_params);
205
317
  }).catch(function (error) {
206
- _this2.logger.logError({
318
+ _this4.logger.logError({
207
319
  title: 'sdk_error_parameter'
208
320
  }, {
209
321
  params: JSON.stringify(params)
210
322
  }).send();
211
- _this2._eventCenter.emit(EVENT.error.name, error);
323
+ _this4._eventCenter.emit(EVENT.error.name, error);
212
324
  return Promise.reject(error);
213
325
  }).then(function (appendParams) {
214
- var iframeNodesParams = appendParams.iframeNodesParams;
215
- _this2.savePreviousChannel(iframeNodesParams);
216
- return _this2.pluginAppendIframe(appendParams);
326
+ return _this4.createComponentProcess(appendParams);
217
327
  });
218
328
  }
329
+ }, {
330
+ key: "createComponentProcess",
331
+ value: function createComponentProcess(appendParams) {
332
+ var _this$getBusActionNam;
333
+ this._appendParams = appendParams;
334
+ var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.createComponent;
335
+ if (actionName && BusManager.isSubscribed(actionName)) {
336
+ // 执行出错了,在通用拦截器返回
337
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
338
+ appendParams: appendParams,
339
+ options: this.originOptions
340
+ })));
341
+ return Promise.resolve();
342
+ }
343
+ var iframeNodesParams = appendParams.iframeNodesParams;
344
+ this.savePreviousChannel(iframeNodesParams);
345
+ return this.pluginAppendIframe(appendParams);
346
+ }
219
347
  }, {
220
348
  key: "preloadComponent",
221
349
  value: function preloadComponent(channelType, productSceneVersion) {
222
- var _this3 = this;
350
+ var _this5 = this;
223
351
  this.channelType = channelType;
224
352
  this.productSceneVersion = productSceneVersion;
225
353
  var MAX_CLEAR_TIME = 10000;
@@ -234,14 +362,15 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
234
362
  channelType: channelType
235
363
  });
236
364
  }
237
- setTimeout(function () {
238
- _this3.clearPreloadIframe(true);
365
+ this.timer = setTimeout(function () {
366
+ _this5.clearPreloadIframe(true);
239
367
  }, MAX_CLEAR_TIME);
240
368
  }
241
369
  }, {
242
370
  key: "clearPreloadIframe",
243
371
  value: function clearPreloadIframe() {
244
372
  var isTimeOut = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
373
+ !isTimeOut && clearTimeout(this.timer);
245
374
  if (Array.isArray(this.channelType)) {
246
375
  for (var i = 0; i < this.channelType.length; i++) {
247
376
  var iframe = document.getElementById("ams-checkout-component-".concat(this.channelType[i], "-").concat(this.productSceneVersion));
@@ -266,7 +395,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
266
395
  }, {
267
396
  key: "mountComponent",
268
397
  value: function mountComponent(params, selector) {
269
- var _this4 = this;
398
+ var _this6 = this;
270
399
  this.clearPreloadIframe();
271
400
  return this.parameterInitAndCheck({
272
401
  params: params,
@@ -275,19 +404,36 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
275
404
  }).then(function (_params) {
276
405
  return handleParams(_params);
277
406
  }).catch(function (error) {
278
- _this4.logger.logError({
407
+ _this6.logger.logError({
279
408
  title: 'sdk_error_parameter'
280
409
  }, {
281
410
  params: JSON.stringify(params)
282
411
  }).send();
283
- _this4._eventCenter.emit(EVENT.error.name, error);
412
+ _this6._eventCenter.emit(EVENT.error.name, error);
284
413
  return Promise.reject(error);
285
414
  }).then(function (appendParams) {
286
- var iframeNodesParams = appendParams.iframeNodesParams;
287
- _this4.savePreviousChannel(iframeNodesParams);
288
- return _this4.pluginAppendIframe(appendParams);
415
+ return _this6.mountComponentProcess(appendParams);
289
416
  });
290
417
  }
418
+ }, {
419
+ key: "mountComponentProcess",
420
+ value: function mountComponentProcess(appendParams) {
421
+ var _this$getBusActionNam2;
422
+ this._appendParams = appendParams;
423
+ var actionName = (_this$getBusActionNam2 = this.getBusActionNames()) === null || _this$getBusActionNam2 === void 0 ? void 0 : _this$getBusActionNam2.mountComponent;
424
+ if (actionName && BusManager.isSubscribed(actionName)) {
425
+ // 执行出错了,在通用拦截器返回
426
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
427
+ appendParams: appendParams,
428
+ options: this.originOptions
429
+ })));
430
+ return Promise.resolve();
431
+ }
432
+ var iframeNodesParams = appendParams.iframeNodesParams;
433
+ this.savePreviousChannel(iframeNodesParams);
434
+ return this.pluginAppendIframe(appendParams);
435
+ }
436
+
291
437
  /**
292
438
  * @description Execute payment submission process
293
439
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
@@ -296,24 +442,37 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
296
442
  }, {
297
443
  key: "submit",
298
444
  value: function submit(data) {
299
- var _this5 = this;
445
+ var _this7 = this;
300
446
  return new Promise(function (resolve, reject) {
301
447
  try {
448
+ var _this7$getBusActionNa;
302
449
  var eventCallbackId = uuid();
303
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
304
- _this5._eventCenter.once(eventCallbackId, function (_data) {
305
- resolve(_data);
306
- });
307
- _this5._componentApp.dispatchToApp({
308
- context: {
309
- event: 'submitPay',
310
- eventCallbackId: eventCallbackId,
311
- data: data
312
- }
313
- });
314
- _this5.logger.logInfo({
450
+ _this7.logger.logInfo({
315
451
  title: 'sdk_event_apiSubmit'
316
452
  });
453
+ var actionName = (_this7$getBusActionNa = _this7.getBusActionNames()) === null || _this7$getBusActionNa === void 0 ? void 0 : _this7$getBusActionNa.submit;
454
+ if (actionName && BusManager.isSubscribed(actionName)) {
455
+ // 执行出错了,在通用拦截器返回
456
+ BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
457
+ appendParams: _this7._appendParams,
458
+ options: _this7.originOptions,
459
+ data: data
460
+ }))).then(function (busMessage) {
461
+ resolve(busMessage === null || busMessage === void 0 ? void 0 : busMessage.getJSONObject());
462
+ });
463
+ } else {
464
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
465
+ _this7._eventCenter.once(eventCallbackId, function (_data) {
466
+ resolve(_data);
467
+ });
468
+ _this7._componentApp.dispatchToApp({
469
+ context: {
470
+ event: 'submitPay',
471
+ eventCallbackId: eventCallbackId,
472
+ data: data
473
+ }
474
+ });
475
+ }
317
476
  } catch (error) {
318
477
  reject(error);
319
478
  }
@@ -1,13 +1,16 @@
1
- import type { AMSCheckoutOptions, InitSecurityConfig, IoptionsParams } from '../../types/index';
1
+ import type { AMSCheckoutOptions, IAppendParams, InitSecurityConfig, IoptionsParams } from '../../types/index';
2
2
  import { EventCenter } from '../../util/index';
3
3
  import { Logger } from '../../util/logger';
4
4
  import { Security } from '../../util/security';
5
+ import { ComponentActionNamesType } from 'src/plugin/type';
5
6
  export default class AMSSDK {
6
7
  options: AMSCheckoutOptions;
8
+ originOptions: IoptionsParams;
7
9
  logger: Logger;
8
10
  _eventCenter: EventCenter;
9
11
  _instanceId: string;
10
12
  _storageId: string;
13
+ _appendParams: IAppendParams;
11
14
  protected securitySdkMap: Map<string, Security>;
12
15
  protected plugins: Map<string, any>;
13
16
  constructor(options: IoptionsParams);
@@ -72,4 +75,5 @@ export default class AMSSDK {
72
75
  * @description Overlay Subscription
73
76
  */
74
77
  protected _overrideSubscription(name: string, func: any, funcKey: string): void;
78
+ protected getBusActionNames(): ComponentActionNamesType;
75
79
  }
@@ -26,17 +26,21 @@ import CallApp from "../../util/intl-callapp/es/main";
26
26
  import { LogConfig, Logger } from "../../util/logger";
27
27
  import { compareVersion } from "../../util/versionCompare";
28
28
  import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security, SecurityRegionEnum } from "../../util/security";
29
+ import { BusManager, BusMessage } from "../bus";
29
30
  var AMSSDK = /*#__PURE__*/function () {
30
31
  function AMSSDK(options) {
31
32
  _classCallCheck(this, AMSSDK);
32
33
  _defineProperty(this, "options", void 0);
34
+ _defineProperty(this, "originOptions", void 0);
33
35
  _defineProperty(this, "logger", void 0);
34
36
  _defineProperty(this, "_eventCenter", void 0);
35
37
  _defineProperty(this, "_instanceId", void 0);
36
38
  _defineProperty(this, "_storageId", void 0);
39
+ _defineProperty(this, "_appendParams", void 0);
37
40
  _defineProperty(this, "securitySdkMap", void 0);
38
41
  _defineProperty(this, "plugins", void 0);
39
42
  this._instanceId = uuid();
43
+ this.originOptions = options;
40
44
  this.options = {};
41
45
  this._eventCenter = new EventCenter();
42
46
  this._initEvent(options);
@@ -52,7 +56,7 @@ var AMSSDK = /*#__PURE__*/function () {
52
56
  this._storageId = _storageId;
53
57
 
54
58
  // TODO Consumption data analysis control parameters
55
- this.logger = new Logger(LogConfig, (options === null || options === void 0 ? void 0 : options.environment) !== environmentEnum.prod);
59
+ this.logger = new Logger(LogConfig, ![environmentEnum.prod, environmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment));
56
60
  this.logger.setMedta({
57
61
  instanceId: this._instanceId
58
62
  });
@@ -61,14 +65,15 @@ var AMSSDK = /*#__PURE__*/function () {
61
65
  title: 'NEW_AMSSDK_BY_MECHANT',
62
66
  msg: "".concat(options === null || options === void 0 ? void 0 : options.environment, "_").concat(options === null || options === void 0 ? void 0 : options.locale, "}")
63
67
  }).send();
64
- this.preInitSecurity();
68
+ this.preInitSecurity(options);
65
69
  }
66
70
  _createClass(AMSSDK, [{
67
71
  key: "preInitSecurity",
68
- value: function preInitSecurity() {
72
+ value: function preInitSecurity(options) {
69
73
  var _this$options;
70
74
  var antomSDKConfigKey = 'antomSDKConfigKey';
71
75
  var config = safeJson(getOrSetStorageId(antomSDKConfigKey), {});
76
+ if (![environmentEnum.prod, environmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment)) return;
72
77
  if (checkTimeElapsed()) {
73
78
  antomConfig({
74
79
  env: this.options.env.environment
@@ -101,17 +106,27 @@ var AMSSDK = /*#__PURE__*/function () {
101
106
  }, {
102
107
  key: "unmount",
103
108
  value: function unmount() {
109
+ var _this$getBusActionNam;
104
110
  this.logger.logInfo({
105
111
  title: 'sdk_event_apiOnDestroy'
106
112
  }).send();
113
+ var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.destoryComponent;
114
+ if (actionName && BusManager.isSubscribed(actionName)) {
115
+ // 执行出错了,在通用拦截器返回
116
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
117
+ options: this.originOptions
118
+ })));
119
+ }
107
120
  var _iterator = _createForOfIteratorHelper(this.plugins.values()),
108
121
  _step;
109
122
  try {
110
123
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
111
124
  var plugin = _step.value;
112
125
  try {
113
- plugin.logoutPlugin();
114
- // eslint-disable-next-line no-empty
126
+ if (plugin.logoutPlugin) {
127
+ plugin.logoutPlugin();
128
+ // eslint-disable-next-line no-empty
129
+ }
115
130
  } catch (error) {
116
131
  console.error(error);
117
132
  }
@@ -302,7 +317,9 @@ var AMSSDK = /*#__PURE__*/function () {
302
317
  value: function _registerPlugin(pluginId, plugin) {
303
318
  this.plugins.set(pluginId, plugin);
304
319
  try {
305
- plugin.applyPlugin(this);
320
+ if (plugin.applyPlugin) {
321
+ plugin.applyPlugin(this);
322
+ }
306
323
  } catch (error) {
307
324
  this.plugins.delete(pluginId);
308
325
  if (getType(error) === 'error') throw error;
@@ -316,7 +333,7 @@ var AMSSDK = /*#__PURE__*/function () {
316
333
  key: "_getPlugin",
317
334
  value: function _getPlugin(pluginId) {
318
335
  if (!this.plugins.has(pluginId)) {
319
- console.warn("".concat(pluginId, "Plugin unregistered"));
336
+ console.warn("".concat(pluginId, " Plugin unregistered"));
320
337
  return null;
321
338
  }
322
339
  return this.plugins.get(pluginId);
@@ -381,6 +398,27 @@ var AMSSDK = /*#__PURE__*/function () {
381
398
  this._eventCenter.off(name, func, funcKey);
382
399
  this._eventCenter.on(name, func, funcKey);
383
400
  }
401
+ }, {
402
+ key: "getBusActionNames",
403
+ value: function getBusActionNames() {
404
+ var _appendParams$iframeN;
405
+ var appendParams = this._appendParams;
406
+ if (!appendParams) {
407
+ return null;
408
+ }
409
+ var actionNames = null;
410
+ var paymentSessionConfig = appendParams === null || appendParams === void 0 || (_appendParams$iframeN = appendParams.iframeNodesParams) === null || _appendParams$iframeN === void 0 || (_appendParams$iframeN = _appendParams$iframeN.paymentSessionMetaData) === null || _appendParams$iframeN === void 0 ? void 0 : _appendParams$iframeN.paymentSessionConfig;
411
+ if (paymentSessionConfig) {
412
+ var _appendParams$iframeN2;
413
+ var pluginKey = paymentSessionConfig.productScene + paymentSessionConfig.productSceneVersion + paymentSessionConfig.paymentMethodCategoryType;
414
+ var paymentMethodType = appendParams === null || appendParams === void 0 || (_appendParams$iframeN2 = appendParams.iframeNodesParams) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentSessionMetaData) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentSessionFactor) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentMethodInfo) === null || _appendParams$iframeN2 === void 0 ? void 0 : _appendParams$iframeN2.paymentMethodType;
415
+ if (paymentMethodType) {
416
+ pluginKey = pluginKey + paymentMethodType;
417
+ }
418
+ actionNames = this._getPlugin(pluginKey);
419
+ }
420
+ return actionNames;
421
+ }
384
422
  }]);
385
423
  return AMSSDK;
386
424
  }();
package/esm/index.d.ts CHANGED
@@ -5,15 +5,12 @@
5
5
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
- import ApplePayComponent from './core/applepay';
9
8
  import { AMSComponent } from './core/component/index';
10
9
  import { IoptionsParams, componentSignEnum } from './types';
11
10
  export * from './types';
12
11
  export declare class AMSCheckout extends AMSComponent {
13
12
  constructor(_options: any, channelType?: componentSignEnum[], productSceneVersion?: string);
14
13
  }
15
- export declare class AMSApplePay extends ApplePayComponent {
16
- }
17
14
  export declare class AMSAutoDebit extends AMSCheckout {
18
15
  constructor(options: IoptionsParams);
19
16
  }
package/esm/index.js CHANGED
@@ -18,7 +18,6 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
18
18
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
19
19
  * 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.
20
20
  */
21
- import ApplePayComponent from "./core/applepay";
22
21
  import { AMSComponent } from "./core/component/index";
23
22
  import { componentSignEnum } from "./types";
24
23
  import { productSceneEnum } from "./types/index";
@@ -38,30 +37,21 @@ export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
38
37
  }
39
38
  return _createClass(AMSCheckout);
40
39
  }(AMSComponent);
41
- export var AMSApplePay = /*#__PURE__*/function (_ApplePayComponent) {
42
- _inherits(AMSApplePay, _ApplePayComponent);
43
- var _super2 = _createSuper(AMSApplePay);
44
- function AMSApplePay() {
45
- _classCallCheck(this, AMSApplePay);
46
- return _super2.apply(this, arguments);
47
- }
48
- return _createClass(AMSApplePay);
49
- }(ApplePayComponent);
50
40
  export var AMSAutoDebit = /*#__PURE__*/function (_AMSCheckout) {
51
41
  _inherits(AMSAutoDebit, _AMSCheckout);
52
- var _super3 = _createSuper(AMSAutoDebit);
42
+ var _super2 = _createSuper(AMSAutoDebit);
53
43
  function AMSAutoDebit(options) {
54
44
  _classCallCheck(this, AMSAutoDebit);
55
45
  var _options = Object.assign({}, options, {
56
46
  product: productSceneEnum.AUTO_DEBIT
57
47
  });
58
- return _super3.call(this, _options, [componentSignEnum.AUTO_DEBIT_WALLET]);
48
+ return _super2.call(this, _options, [componentSignEnum.AUTO_DEBIT_WALLET]);
59
49
  }
60
50
  return _createClass(AMSAutoDebit);
61
51
  }(AMSCheckout);
62
52
  export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
63
53
  _inherits(AMSEasyPay, _AMSCheckout2);
64
- var _super4 = _createSuper(AMSEasyPay);
54
+ var _super3 = _createSuper(AMSEasyPay);
65
55
  function AMSEasyPay(options) {
66
56
  _classCallCheck(this, AMSEasyPay);
67
57
  var _options = Object.assign({}, options, {
@@ -86,13 +76,13 @@ export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
86
76
  error: error
87
77
  });
88
78
  }
89
- return _super4.call(this, _options, [componentSignEnum.EASY_PAY_WALLET], currentProductSceneVersion);
79
+ return _super3.call(this, _options, [componentSignEnum.EASY_PAY_WALLET], currentProductSceneVersion);
90
80
  }
91
81
  return _createClass(AMSEasyPay);
92
82
  }(AMSCheckout);
93
83
  export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
94
84
  _inherits(AMSCashierPayment, _AMSCheckout3);
95
- var _super5 = _createSuper(AMSCashierPayment);
85
+ var _super4 = _createSuper(AMSCashierPayment);
96
86
  function AMSCashierPayment(options) {
97
87
  _classCallCheck(this, AMSCashierPayment);
98
88
  var _options = Object.assign({}, options, {
@@ -117,19 +107,19 @@ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
117
107
  error: error
118
108
  });
119
109
  }
120
- return _super5.call(this, _options, currentChannelType);
110
+ return _super4.call(this, _options, currentChannelType);
121
111
  }
122
112
  return _createClass(AMSCashierPayment);
123
113
  }(AMSCheckout);
124
114
  export var AMSVaulting = /*#__PURE__*/function (_AMSCheckout4) {
125
115
  _inherits(AMSVaulting, _AMSCheckout4);
126
- var _super6 = _createSuper(AMSVaulting);
116
+ var _super5 = _createSuper(AMSVaulting);
127
117
  function AMSVaulting(options) {
128
118
  _classCallCheck(this, AMSVaulting);
129
119
  var _options = Object.assign({}, options, {
130
120
  product: productSceneEnum.VAULTING
131
121
  });
132
- return _super6.call(this, _options, [componentSignEnum.CASHIER_PAYMENT_CARD]);
122
+ return _super5.call(this, _options, [componentSignEnum.CASHIER_PAYMENT_CARD]);
133
123
  }
134
124
  return _createClass(AMSVaulting);
135
125
  }(AMSCheckout);
@@ -5,27 +5,46 @@
5
5
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
- import { IApplePayOptionsParams } from '../../types';
9
- import CoreInstance from '../instance';
8
+ import { ApplePaySubTypeEnum, IAppendParams, IApplePayOptionsParams } from '../../types';
9
+ import type { Logger } from '../../util/logger';
10
+ export declare enum ApplePayComponentEvent {
11
+ sdk_event_appleAvailable = "sdk_event_appleAvailable",
12
+ sdk_event_appleCreateComponent = "sdk_event_appleCreateComponent",
13
+ sdk_event_appleShowPaymentSheet = "sdk_event_appleShowPaymentSheet",
14
+ sdk_event_appleOnvalidatemerchant = "sdk_event_appleOnvalidatemerchant",
15
+ sdk_event_appleSubmitToken = "sdk_event_appleSubmitToken",
16
+ sdk_event_applePaymentResult = "sdk_event_applePaymentResult",
17
+ sdk_event_appleDestoryComponent = "sdk_event_appleDestoryComponent"
18
+ }
10
19
  /**
11
20
  * Apple pay Component
12
21
  */
13
- declare class ApplePayComponent extends CoreInstance {
22
+ declare class ApplePayComponent {
14
23
  private _applePayService;
15
24
  private _parseData;
16
25
  private _sessionData;
17
26
  private _isFinish;
18
- constructor(options: IApplePayOptionsParams);
19
- private getDeviceIdAndLog;
20
- private logDeviceId;
27
+ private _options;
28
+ private logger;
29
+ private isRecurring;
30
+ constructor(options: IApplePayOptionsParams, logger: Logger);
31
+ /**
32
+ * Is Apple Pay Enabled
33
+ * @param subTypeEnum
34
+ * @returns
35
+ */
36
+ canMakePayments(subTypeEnum?: ApplePaySubTypeEnum): boolean;
21
37
  /**
22
38
  * Is Apple Pay Enabled
39
+ * @param subTypeEnum
40
+ * @returns
23
41
  */
24
- isAppPayEnabled(): boolean;
42
+ isAppPayEnabled(subTypeEnum?: ApplePaySubTypeEnum): boolean;
43
+ private onEventCallback;
25
44
  /**
26
45
  * Submit Pay
27
46
  * @param paymentSessionData
28
47
  */
29
- submitPay(paymentSessionData: string): void;
48
+ submitPay(appendParams: IAppendParams): void;
30
49
  }
31
50
  export default ApplePayComponent;