@alipay/ams-checkout 0.0.1710212811-dev.25 → 0.0.1710212811-dev.28

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.
@@ -26,9 +26,6 @@ export declare enum ComponentActiontEnum {
26
26
  export declare enum RequestActiontEnum {
27
27
  onDestory = "httpRequest"
28
28
  }
29
- export declare enum MonitorActiontEnum {
30
- reportAnalytics = "reportAnalytics"
31
- }
32
29
  export declare enum LoadingActiontEnum {
33
30
  showLoading = "showLoading",
34
31
  dismissLoading = "dismissLoading"
@@ -28,10 +28,6 @@ export var RequestActiontEnum = /*#__PURE__*/function (RequestActiontEnum) {
28
28
  RequestActiontEnum["onDestory"] = "httpRequest";
29
29
  return RequestActiontEnum;
30
30
  }({});
31
- export var MonitorActiontEnum = /*#__PURE__*/function (MonitorActiontEnum) {
32
- MonitorActiontEnum["reportAnalytics"] = "reportAnalytics";
33
- return MonitorActiontEnum;
34
- }({});
35
31
  export var LoadingActiontEnum = /*#__PURE__*/function (LoadingActiontEnum) {
36
32
  LoadingActiontEnum["showLoading"] = "showLoading";
37
33
  LoadingActiontEnum["dismissLoading"] = "dismissLoading";
@@ -1,5 +1,5 @@
1
1
  import ComponentApp from '../../plugin/component';
2
- import { componentSignEnum, IcreateComponent, IoptionsParams, IpaymentSessionMetaData, Iselector, Isubmit, PaymentMethodTypeEnum, SubPaymentMethodTypeEnum } from '../../types';
2
+ import { componentSignEnum, IAppendParams, IcreateComponent, IoptionsParams, IpaymentSessionMetaData, Iselector, Isubmit, PaymentMethodTypeEnum, SubPaymentMethodTypeEnum } 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];
@@ -7,6 +7,7 @@ export declare class AMSComponent extends CoreInstance {
7
7
  _componentApp: ComponentApp;
8
8
  channelType: componentSignEnum[];
9
9
  productSceneVersion: string;
10
+ _appendParams: IAppendParams;
10
11
  constructor(options: IoptionsParams);
11
12
  private parameterInitAndCheck;
12
13
  private pluginAppendIframe;
@@ -15,13 +16,21 @@ export declare class AMSComponent extends CoreInstance {
15
16
  * 初始化 Bus总线的能力
16
17
  */
17
18
  private registerBusAbility;
18
- canMakePayments(paymentMethod: PaymentMethodTypeEnum, subPaymentMethod: SubPaymentMethodTypeEnum): Promise<boolean>;
19
+ /**
20
+ * To determine whether the corresponding payment method is available,
21
+ * only the channel described in the document will be called, and it will be returned as available by default
22
+ * @param paymentMethod - described in the document
23
+ * @param subPaymentMethod - described in the document
24
+ * @returns
25
+ */
26
+ canMakePayments(paymentMethod: PaymentMethodTypeEnum, subPaymentMethod?: SubPaymentMethodTypeEnum): Promise<boolean>;
19
27
  /**
20
28
  * @description Create component application
21
29
  * @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.
22
30
  */
23
31
  createComponent(params: IcreateComponent): Promise<void>;
24
- private isApplePay;
32
+ private getBusActionNames;
33
+ private createComponentProcess;
25
34
  preloadComponent(channelType: any, productSceneVersion: any): void;
26
35
  clearPreloadIframe(isTimeOut?: boolean): void;
27
36
  /**
@@ -30,6 +39,7 @@ export declare class AMSComponent extends CoreInstance {
30
39
  * @param selector - Necessary element selector ID
31
40
  */
32
41
  mountComponent(params: IcreateComponent, selector: Iselector): Promise<void>;
42
+ private mountComponentProcess;
33
43
  /**
34
44
  * @description Execute payment submission process
35
45
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
@@ -30,17 +30,17 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
30
30
  import { v4 as uuid } from 'uuid';
31
31
  import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
32
32
  import ComponentApp from "../../plugin/component";
33
- import { componentSignEnum, environmentEnum, modeEnum, networkModeEnum, PaymentMethodTypeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
33
+ import { componentSignEnum, environmentEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
34
34
  import { getOrSetStorageId, isPC, parseBase64ToString } from "../../util";
35
35
  import { createIframeNode, createPreloadIframeNode } from "../../util/createIframeNode";
36
36
  import { getSecurityConfigStorageKey } from "../../util/security";
37
37
  import CoreInstance from "../instance/index";
38
38
  import { BusManager, BusMessage } from "../bus";
39
- import { ApplePayActionEnum, PaymentActionEnum } from "../bus/interface";
40
39
  import { SDKCallbackBusSubscriber } from "../bus/ability/callback";
41
40
  import { ApplePayBusSubscriber } from "../../plugin/applepay";
42
41
  import { SecurityBusSubscriber } from "../bus/ability/security";
43
42
  import { TrackerBusSubscriber } from "../bus/ability/tracker";
43
+ import { ExtendPlugin } from "../../plugin/const";
44
44
  export var getComponentSign = function getComponentSign(params) {
45
45
  var _params$paymentSessio = params.paymentSessionConfig,
46
46
  _params$paymentSessio2 = _params$paymentSessio === void 0 ? {} : _params$paymentSessio,
@@ -116,6 +116,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
116
116
  _defineProperty(_assertThisInitialized(_this), "_componentApp", void 0);
117
117
  _defineProperty(_assertThisInitialized(_this), "channelType", void 0);
118
118
  _defineProperty(_assertThisInitialized(_this), "productSceneVersion", void 0);
119
+ _defineProperty(_assertThisInitialized(_this), "_appendParams", void 0);
119
120
  var ComponentPlugin = new ComponentApp();
120
121
  ComponentPlugin.setRender(createIframeNode);
121
122
  ComponentPlugin.setPreloadRender(createPreloadIframeNode);
@@ -210,8 +211,8 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
210
211
  BusManager.clear();
211
212
  BusManager.addInterceptor({
212
213
  onPublishException: function onPublishException(message, e) {
213
- _this2.logger.logInfo({
214
- title: 'onPublishException'
214
+ _this2.logger.logError({
215
+ title: 'onBusPublishException'
215
216
  }, _objectSpread(_objectSpread({}, message), {}, {
216
217
  errorMessage: JSON.stringify(e)
217
218
  }));
@@ -219,27 +220,67 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
219
220
  });
220
221
  // subscribe basic ablility
221
222
  BusManager.subscribe(new SDKCallbackBusSubscriber(function (state) {
222
- var _this2$originOptions;
223
- (_this2$originOptions = _this2.originOptions) === null || _this2$originOptions === void 0 || _this2$originOptions.onEventCallback(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);
224
225
  }));
225
226
  BusManager.subscribe(new SecurityBusSubscriber(function (deviceIdParameter, isPolling) {
226
- var _this2$_componentApp;
227
- return (_this2$_componentApp = _this2._componentApp) === null || _this2$_componentApp === void 0 ? void 0 : _this2$_componentApp.getDeviceIdAndLog(deviceIdParameter, isPolling);
227
+ var _this2$_componentApp2;
228
+ return (_this2$_componentApp2 = _this2._componentApp) === null || _this2$_componentApp2 === void 0 ? void 0 : _this2$_componentApp2.getDeviceIdAndLog(deviceIdParameter, isPolling);
228
229
  }));
229
230
  BusManager.subscribe(new TrackerBusSubscriber(this.logger));
230
231
  // subscribe plugin
231
232
  BusManager.subscribe(new ApplePayBusSubscriber(this.logger));
232
- // publish devent
233
- BusManager.publish(new BusMessage(PaymentActionEnum.optional_init, JSON.stringify(this.originOptions)));
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
+ });
234
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
+ */
235
270
  }, {
236
271
  key: "canMakePayments",
237
272
  value: function canMakePayments(paymentMethod, subPaymentMethod) {
238
273
  var _this3 = this;
239
274
  // 判断支付方式是否可用
240
275
  return new Promise(function (resolve) {
241
- if (paymentMethod === PaymentMethodTypeEnum.ApplePay) {
242
- BusManager.publishForResult(new BusMessage(ApplePayActionEnum.canMakePayments, JSON.stringify({
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,
243
284
  subPaymentMethod: subPaymentMethod
244
285
  })), {
245
286
  fallback: false
@@ -282,28 +323,46 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
282
323
  _this4._eventCenter.emit(EVENT.error.name, error);
283
324
  return Promise.reject(error);
284
325
  }).then(function (appendParams) {
285
- if (_this4.isApplePay(params === null || params === void 0 ? void 0 : params.paymentSessionData) && BusManager.isSubscribed(ApplePayActionEnum.createComponent)) {
286
- // 执行出错了,在通用拦截器返回
287
- BusManager.publish(new BusMessage(ApplePayActionEnum.createComponent, JSON.stringify({
288
- paymentSessionData: params === null || params === void 0 ? void 0 : params.paymentSessionData,
289
- options: _this4.originOptions
290
- })));
291
- return;
292
- }
293
- var iframeNodesParams = appendParams.iframeNodesParams;
294
- _this4.savePreviousChannel(iframeNodesParams);
295
- return _this4.pluginAppendIframe(appendParams);
326
+ return _this4.createComponentProcess(appendParams);
296
327
  });
297
328
  }
298
329
  }, {
299
- key: "isApplePay",
300
- value: function isApplePay(paymentSessionData) {
301
- var _parseData$paymentSes2, _parseData$paymentSes3;
302
- var _parseSessionData3 = parseSessionData(paymentSessionData),
303
- _parseSessionData4 = _slicedToArray(_parseSessionData3, 2),
304
- parseData = _parseSessionData4[0],
305
- sessionData = _parseSessionData4[1];
306
- return sessionData && (parseData === null || parseData === void 0 || (_parseData$paymentSes2 = parseData.paymentSessionConfig) === null || _parseData$paymentSes2 === void 0 ? void 0 : _parseData$paymentSes2.productScene) === productSceneEnum.CASHIER_PAYMENT && (parseData === null || parseData === void 0 || (_parseData$paymentSes3 = parseData.paymentSessionFactor) === null || _parseData$paymentSes3 === void 0 || (_parseData$paymentSes3 = _parseData$paymentSes3.paymentMethodInfo) === null || _parseData$paymentSes3 === void 0 ? void 0 : _parseData$paymentSes3.paymentMethodType) === "CARD_APPLE_PAY";
330
+ key: "getBusActionNames",
331
+ value: function getBusActionNames(appendParams) {
332
+ var _appendParams$iframeN;
333
+ if (!appendParams) {
334
+ return null;
335
+ }
336
+ var actionNames = null;
337
+ 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;
338
+ if (paymentSessionConfig) {
339
+ var _appendParams$iframeN2;
340
+ var pluginKey = paymentSessionConfig.productScene + paymentSessionConfig.productSceneVersion + paymentSessionConfig.paymentMethodCategoryType;
341
+ 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;
342
+ if (paymentMethodType) {
343
+ pluginKey = pluginKey + paymentMethodType;
344
+ }
345
+ actionNames = this._getPlugin(pluginKey);
346
+ }
347
+ return actionNames;
348
+ }
349
+ }, {
350
+ key: "createComponentProcess",
351
+ value: function createComponentProcess(appendParams) {
352
+ var _this$getBusActionNam;
353
+ this._appendParams = appendParams;
354
+ var actionName = (_this$getBusActionNam = this.getBusActionNames(appendParams)) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.createComponent;
355
+ if (actionName && BusManager.isSubscribed(actionName)) {
356
+ // 执行出错了,在通用拦截器返回
357
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
358
+ appendParams: appendParams,
359
+ options: this.originOptions
360
+ })));
361
+ return Promise.resolve();
362
+ }
363
+ var iframeNodesParams = appendParams.iframeNodesParams;
364
+ this.savePreviousChannel(iframeNodesParams);
365
+ return this.pluginAppendIframe(appendParams);
307
366
  }
308
367
  }, {
309
368
  key: "preloadComponent",
@@ -372,11 +431,28 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
372
431
  _this6._eventCenter.emit(EVENT.error.name, error);
373
432
  return Promise.reject(error);
374
433
  }).then(function (appendParams) {
375
- var iframeNodesParams = appendParams.iframeNodesParams;
376
- _this6.savePreviousChannel(iframeNodesParams);
377
- return _this6.pluginAppendIframe(appendParams);
434
+ return _this6.mountComponentProcess(appendParams);
378
435
  });
379
436
  }
437
+ }, {
438
+ key: "mountComponentProcess",
439
+ value: function mountComponentProcess(appendParams) {
440
+ var _this$getBusActionNam2;
441
+ this._appendParams = appendParams;
442
+ var actionName = (_this$getBusActionNam2 = this.getBusActionNames(appendParams)) === null || _this$getBusActionNam2 === void 0 ? void 0 : _this$getBusActionNam2.mountComponent;
443
+ if (actionName && BusManager.isSubscribed(actionName)) {
444
+ // 执行出错了,在通用拦截器返回
445
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
446
+ appendParams: appendParams,
447
+ options: this.originOptions
448
+ })));
449
+ return Promise.resolve();
450
+ }
451
+ var iframeNodesParams = appendParams.iframeNodesParams;
452
+ this.savePreviousChannel(iframeNodesParams);
453
+ return this.pluginAppendIframe(appendParams);
454
+ }
455
+
380
456
  /**
381
457
  * @description Execute payment submission process
382
458
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
@@ -388,21 +464,32 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
388
464
  var _this7 = this;
389
465
  return new Promise(function (resolve, reject) {
390
466
  try {
467
+ var _this7$getBusActionNa;
391
468
  var eventCallbackId = uuid();
392
469
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
393
470
  _this7._eventCenter.once(eventCallbackId, function (_data) {
394
471
  resolve(_data);
395
472
  });
396
- _this7._componentApp.dispatchToApp({
397
- context: {
398
- event: 'submitPay',
399
- eventCallbackId: eventCallbackId,
400
- data: data
401
- }
402
- });
403
473
  _this7.logger.logInfo({
404
474
  title: 'sdk_event_apiSubmit'
405
475
  });
476
+ var actionName = (_this7$getBusActionNa = _this7.getBusActionNames(_this7._appendParams)) === null || _this7$getBusActionNa === void 0 ? void 0 : _this7$getBusActionNa.submit;
477
+ if (actionName && BusManager.isSubscribed(actionName)) {
478
+ // 执行出错了,在通用拦截器返回
479
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
480
+ appendParams: _this7._appendParams,
481
+ options: _this7.originOptions,
482
+ data: data
483
+ })));
484
+ } else {
485
+ _this7._componentApp.dispatchToApp({
486
+ context: {
487
+ event: 'submitPay',
488
+ eventCallbackId: eventCallbackId,
489
+ data: data
490
+ }
491
+ });
492
+ }
406
493
  } catch (error) {
407
494
  reject(error);
408
495
  }
@@ -112,8 +112,10 @@ var AMSSDK = /*#__PURE__*/function () {
112
112
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
113
113
  var plugin = _step.value;
114
114
  try {
115
- plugin.logoutPlugin();
116
- // eslint-disable-next-line no-empty
115
+ if (plugin.logoutPlugin) {
116
+ plugin.logoutPlugin();
117
+ // eslint-disable-next-line no-empty
118
+ }
117
119
  } catch (error) {
118
120
  console.error(error);
119
121
  }
@@ -304,7 +306,9 @@ var AMSSDK = /*#__PURE__*/function () {
304
306
  value: function _registerPlugin(pluginId, plugin) {
305
307
  this.plugins.set(pluginId, plugin);
306
308
  try {
307
- plugin.applyPlugin(this);
309
+ if (plugin.applyPlugin) {
310
+ plugin.applyPlugin(this);
311
+ }
308
312
  } catch (error) {
309
313
  this.plugins.delete(pluginId);
310
314
  if (getType(error) === 'error') throw error;
@@ -318,7 +322,7 @@ var AMSSDK = /*#__PURE__*/function () {
318
322
  key: "_getPlugin",
319
323
  value: function _getPlugin(pluginId) {
320
324
  if (!this.plugins.has(pluginId)) {
321
- console.warn("".concat(pluginId, "Plugin unregistered"));
325
+ console.warn("".concat(pluginId, " Plugin unregistered"));
322
326
  return null;
323
327
  }
324
328
  return this.plugins.get(pluginId);
@@ -5,7 +5,7 @@
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 { ApplePaySubTypeEnum, IApplePayOptionsParams } from '../../types';
8
+ import { ApplePaySubTypeEnum, IAppendParams, IApplePayOptionsParams } from '../../types';
9
9
  import { Logger } from '../../util/logger';
10
10
  /**
11
11
  * Apple pay Component
@@ -35,6 +35,6 @@ declare class ApplePayComponent {
35
35
  * Submit Pay
36
36
  * @param paymentSessionData
37
37
  */
38
- submitPay(paymentSessionData: string): void;
38
+ submitPay(appendParams: IAppendParams): void;
39
39
  }
40
40
  export default ApplePayComponent;
@@ -2,12 +2,6 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
5
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
6
  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); } }
13
7
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -21,9 +15,8 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
21
15
  * 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
22
16
  * 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.
23
17
  */
24
- import { componentSignEnum, environmentEnum, eventCodeEnum, productSceneEnum } from "../../types";
18
+ import { environmentEnum, eventCodeEnum, productSceneEnum } from "../../types";
25
19
  import ApplePayService from "./service";
26
- import { getComponentSign, parseSessionData } from "../../core/component";
27
20
  import { getApplePayPaymentSession, submitPayInfo } from "../../service";
28
21
  import { BusManager, BusMessage } from "../../core/bus";
29
22
  import { SecuritySDKActionEnum } from "../../core/bus/interface";
@@ -82,18 +75,14 @@ var ApplePayComponent = /*#__PURE__*/function () {
82
75
  */
83
76
  }, {
84
77
  key: "submitPay",
85
- value: function submitPay(paymentSessionData) {
86
- var _this = this;
78
+ value: function submitPay(appendParams) {
79
+ var _appendParams$iframeN,
80
+ _appendParams$iframeN2,
81
+ _this = this;
87
82
  this._isFinish = false;
88
- // parse session Data
89
- var _parseSessionData = parseSessionData(paymentSessionData),
90
- _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
91
- parseData = _parseSessionData2[0],
92
- sessionData = _parseSessionData2[1];
93
- this._parseData = parseData;
94
- this._sessionData = sessionData;
95
- // parse data is null
96
- if (Object.keys(parseData).length === 0) {
83
+ this._parseData = appendParams === null || appendParams === void 0 || (_appendParams$iframeN = appendParams.iframeNodesParams) === null || _appendParams$iframeN === void 0 ? void 0 : _appendParams$iframeN.paymentSessionMetaData;
84
+ this._sessionData = appendParams === null || appendParams === void 0 || (_appendParams$iframeN2 = appendParams.iframeNodesParams) === null || _appendParams$iframeN2 === void 0 ? void 0 : _appendParams$iframeN2.sessionData;
85
+ if (!this._parseData || !this._sessionData) {
97
86
  this.onEventCallback({
98
87
  code: eventCodeEnum.SDK_PAYMENT_FAIL,
99
88
  message: 'Abnormal response data is null'
@@ -108,24 +97,6 @@ var ApplePayComponent = /*#__PURE__*/function () {
108
97
  }).send();
109
98
  return;
110
99
  }
111
- // validate parse data
112
- var componentSign = getComponentSign(parseData);
113
- if (componentSign === componentSignEnum.NONE) {
114
- // eslint-disable-next-line prefer-promise-reject-errors
115
- this.onEventCallback({
116
- code: eventCodeEnum.SDK_PAYMENT_FAIL,
117
- message: "Abnormal response data, interface failure, or unsupported payment method"
118
- });
119
- this.logger.logError({
120
- name: 'APPLE_PAY',
121
- title: 'paymentMethodUnknown',
122
- msg: 'Abnormal response data, interface failure, or unsupported payment method'
123
- }, {
124
- type: 'error',
125
- biz: 'sdk'
126
- }).send();
127
- return;
128
- }
129
100
  var getDeviceId = /*#__PURE__*/function () {
130
101
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
131
102
  var _yield$BusManager$pub, _this$_parseData;
@@ -66,8 +66,8 @@ export var ApplePayBusSubscriber = /*#__PURE__*/function (_BusSubscriber) {
66
66
  }
67
67
  }
68
68
  }), this.logger);
69
- var paymentSessionData = data === null || data === void 0 ? void 0 : data.paymentSessionData;
70
- this.applePay.submitPay(paymentSessionData);
69
+ var appendParams = data === null || data === void 0 ? void 0 : data.appendParams;
70
+ this.applePay.submitPay(appendParams);
71
71
  }
72
72
  }, {
73
73
  key: "onDestoryComponent",
@@ -17,8 +17,6 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
17
17
  */
18
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
19
  import { APPLE_PAY_VERSION, APPLE_PAY_RECURRING_VERSION } from "./interface";
20
- import { ApplePaySubTypeEnum } from "../../types";
21
-
22
20
  /**
23
21
  * Apple Pay Service
24
22
  */
@@ -217,7 +215,7 @@ var ApplePayService = /*#__PURE__*/function () {
217
215
  }], [{
218
216
  key: "canMakePayments",
219
217
  value: function canMakePayments(subTypeEnum) {
220
- if (ApplePaySubTypeEnum.ApplePayRecurringPayment === subTypeEnum) {
218
+ if ('ApplePayRecurringPayment' === subTypeEnum) {
221
219
  return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_RECURRING_VERSION) : false;
222
220
  }
223
221
  return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_VERSION) : false;
@@ -0,0 +1,2 @@
1
+ import { IExtendPlugin } from './type';
2
+ export declare const ExtendPlugin: IExtendPlugin;
@@ -0,0 +1,19 @@
1
+ import { ApplePayActionEnum, PaymentActionEnum } from "../core/bus/interface";
2
+ import { paymentMethodCategoryTypeEnum, productSceneEnum, ProductSceneVersion } from "../types/index";
3
+ export var ExtendPlugin = [{
4
+ sessionMatcher: {
5
+ productScene: productSceneEnum.CASHIER_PAYMENT,
6
+ productSceneVersion: ProductSceneVersion.V1,
7
+ paymentMethodCategoryType: paymentMethodCategoryTypeEnum.CARD,
8
+ paymentMethodTypes: ["CARD_APPLE_PAY"]
9
+ },
10
+ paymentChannelMatcher: {
11
+ paymentMethod: 'ApplePay'
12
+ },
13
+ busActionNames: {
14
+ canMakePayments: ApplePayActionEnum.canMakePayments,
15
+ optional_init: PaymentActionEnum.optional_init,
16
+ createComponent: ApplePayActionEnum.createComponent,
17
+ destoryComponent: ApplePayActionEnum.destoryComponent
18
+ }
19
+ }];
@@ -0,0 +1,33 @@
1
+ import { BusSubscriber } from '../core/bus';
2
+ import { paymentMethodCategoryTypeEnum, productSceneEnum, ProductSceneVersion } from '../types';
3
+ export type IExtendPlugin = IExtendPluginItem[];
4
+ export interface ComponentActionNamesType {
5
+ canMakePayments?: string;
6
+ optional_init?: string;
7
+ createComponent?: string;
8
+ submit?: string;
9
+ mountComponent?: string;
10
+ destoryComponent?: string;
11
+ }
12
+ export type IExtendPluginItem = {
13
+ /**
14
+ * 以下为sessionData匹配的场景
15
+ */
16
+ sessionMatcher?: {
17
+ productScene: productSceneEnum;
18
+ productSceneVersion: ProductSceneVersion;
19
+ paymentMethodCategoryType: paymentMethodCategoryTypeEnum;
20
+ paymentMethodTypes: string[];
21
+ };
22
+ /**
23
+ * 用于无sessionData场景,比如:canMakePayments
24
+ */
25
+ paymentChannelMatcher?: {
26
+ paymentMethod: string;
27
+ };
28
+ /**
29
+ * 以下plugin 实现的定义
30
+ */
31
+ busActionNames: ComponentActionNamesType;
32
+ busSubscriber?: BusSubscriber;
33
+ };
@@ -0,0 +1,2 @@
1
+ ;
2
+ export {};
@@ -471,11 +471,15 @@ export interface CallbackEventInfo {
471
471
  export interface MultipleCallbackEvents {
472
472
  [key: string]: CallbackEventInfo;
473
473
  }
474
- export declare enum PaymentMethodTypeEnum {
475
- ApplePay = "ApplePay"
476
- }
477
- export declare enum ApplePaySubTypeEnum {
478
- ApplePayRecurringPayment = "ApplePayRecurringPayment"
479
- }
474
+ export type PaymentMethodTypeEnum = 'ApplePay';
475
+ export type ApplePaySubTypeEnum = 'ApplePayRecurringPayment';
480
476
  export type SubPaymentMethodTypeEnum = ApplePaySubTypeEnum;
477
+ export declare enum ProductSceneVersion {
478
+ V1 = "1.0",
479
+ V2 = "2.0"
480
+ }
481
+ export type IAppendParams = {
482
+ componentSign: componentSignEnum;
483
+ iframeNodesParams: IappendIframeNodesParams;
484
+ };
481
485
  export {};
@@ -165,11 +165,8 @@ export var RedirectType = /*#__PURE__*/function (RedirectType) {
165
165
  RedirectType["Unknown"] = "Unknown";
166
166
  return RedirectType;
167
167
  }({});
168
- export var PaymentMethodTypeEnum = /*#__PURE__*/function (PaymentMethodTypeEnum) {
169
- PaymentMethodTypeEnum["ApplePay"] = "ApplePay";
170
- return PaymentMethodTypeEnum;
171
- }({});
172
- export var ApplePaySubTypeEnum = /*#__PURE__*/function (ApplePaySubTypeEnum) {
173
- ApplePaySubTypeEnum["ApplePayRecurringPayment"] = "ApplePayRecurringPayment";
174
- return ApplePaySubTypeEnum;
168
+ export var ProductSceneVersion = /*#__PURE__*/function (ProductSceneVersion) {
169
+ ProductSceneVersion["V1"] = "1.0";
170
+ ProductSceneVersion["V2"] = "2.0";
171
+ return ProductSceneVersion;
175
172
  }({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1710212811-dev.25",
3
+ "version": "0.0.1710212811-dev.28",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",