@alipay/ams-checkout 0.0.1710212811-dev.27 → 0.0.1710212811-dev.29

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.
@@ -15,13 +15,20 @@ export declare class AMSComponent extends CoreInstance {
15
15
  * 初始化 Bus总线的能力
16
16
  */
17
17
  private registerBusAbility;
18
- canMakePayments(paymentMethod: PaymentMethodTypeEnum, subPaymentMethod: SubPaymentMethodTypeEnum): Promise<boolean>;
18
+ /**
19
+ * To determine whether the corresponding payment method is available,
20
+ * only the channel described in the document will be called, and it will be returned as available by default
21
+ * @param paymentMethod - described in the document
22
+ * @param subPaymentMethod - described in the document
23
+ * @returns
24
+ */
25
+ canMakePayments(paymentMethod: PaymentMethodTypeEnum, subPaymentMethod?: SubPaymentMethodTypeEnum): Promise<boolean>;
19
26
  /**
20
27
  * @description Create component application
21
28
  * @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
29
  */
23
30
  createComponent(params: IcreateComponent): Promise<void>;
24
- private isApplePay;
31
+ private createComponentProcess;
25
32
  preloadComponent(channelType: any, productSceneVersion: any): void;
26
33
  clearPreloadIframe(isTimeOut?: boolean): void;
27
34
  /**
@@ -30,6 +37,7 @@ export declare class AMSComponent extends CoreInstance {
30
37
  * @param selector - Necessary element selector ID
31
38
  */
32
39
  mountComponent(params: IcreateComponent, selector: Iselector): Promise<void>;
40
+ private mountComponentProcess;
33
41
  /**
34
42
  * @description Execute payment submission process
35
43
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
@@ -36,11 +36,11 @@ import { createIframeNode, createPreloadIframeNode } from "../../util/createIfra
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,
@@ -229,17 +229,57 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
229
229
  BusManager.subscribe(new TrackerBusSubscriber(this.logger));
230
230
  // subscribe plugin
231
231
  BusManager.subscribe(new ApplePayBusSubscriber(this.logger));
232
- // publish event
233
- BusManager.publish(new BusMessage(PaymentActionEnum.optional_init, JSON.stringify(this.originOptions)));
232
+
233
+ // register bus plugin
234
+ ExtendPlugin.forEach(function (item) {
235
+ var _item$busActionNames;
236
+ if (item !== null && item !== void 0 && item.busSubscriber) {
237
+ BusManager.subscribe(item === null || item === void 0 ? void 0 : item.busSubscriber);
238
+ }
239
+ var paymentChannelMatcher = item.paymentChannelMatcher;
240
+ if (paymentChannelMatcher) {
241
+ _this2._registerPlugin(paymentChannelMatcher.paymentMethod, item.busActionNames);
242
+ }
243
+ var sessionMatcher = item.sessionMatcher;
244
+ if (sessionMatcher) {
245
+ var pluginKey = sessionMatcher.productScene + sessionMatcher.productSceneVersion + sessionMatcher.paymentMethodCategoryType;
246
+ if (sessionMatcher.paymentMethodTypes) {
247
+ sessionMatcher.paymentMethodTypes.forEach(function (paymentMethodType) {
248
+ var subPluginKey = pluginKey + paymentMethodType;
249
+ _this2._registerPlugin(subPluginKey, item.busActionNames);
250
+ });
251
+ } else {
252
+ _this2._registerPlugin(pluginKey, item.busActionNames);
253
+ }
254
+ }
255
+ var optInit = item === null || item === void 0 || (_item$busActionNames = item.busActionNames) === null || _item$busActionNames === void 0 ? void 0 : _item$busActionNames.optional_init;
256
+ if (optInit) {
257
+ BusManager.publish(new BusMessage(optInit, JSON.stringify(_this2.originOptions)));
258
+ }
259
+ });
234
260
  }
261
+
262
+ /**
263
+ * To determine whether the corresponding payment method is available,
264
+ * only the channel described in the document will be called, and it will be returned as available by default
265
+ * @param paymentMethod - described in the document
266
+ * @param subPaymentMethod - described in the document
267
+ * @returns
268
+ */
235
269
  }, {
236
270
  key: "canMakePayments",
237
271
  value: function canMakePayments(paymentMethod, subPaymentMethod) {
238
272
  var _this3 = this;
239
273
  // 判断支付方式是否可用
240
274
  return new Promise(function (resolve) {
241
- if (paymentMethod === 'ApplePay') {
242
- BusManager.publishForResult(new BusMessage(ApplePayActionEnum.canMakePayments, JSON.stringify({
275
+ var _this3$_getPlugin;
276
+ if (!paymentMethod) {
277
+ return resolve(true);
278
+ }
279
+ var actionName = (_this3$_getPlugin = _this3._getPlugin(paymentMethod)) === null || _this3$_getPlugin === void 0 ? void 0 : _this3$_getPlugin.canMakePayments;
280
+ if (actionName && BusManager.isSubscribed(actionName)) {
281
+ BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
282
+ paymentMethod: paymentMethod,
243
283
  subPaymentMethod: subPaymentMethod
244
284
  })), {
245
285
  fallback: false
@@ -282,28 +322,26 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
282
322
  _this4._eventCenter.emit(EVENT.error.name, error);
283
323
  return Promise.reject(error);
284
324
  }).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);
325
+ return _this4.createComponentProcess(appendParams);
296
326
  });
297
327
  }
298
328
  }, {
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";
329
+ key: "createComponentProcess",
330
+ value: function createComponentProcess(appendParams) {
331
+ var _this$getBusActionNam;
332
+ this._appendParams = appendParams;
333
+ var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.createComponent;
334
+ if (actionName && BusManager.isSubscribed(actionName)) {
335
+ // 执行出错了,在通用拦截器返回
336
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
337
+ appendParams: appendParams,
338
+ options: this.originOptions
339
+ })));
340
+ return Promise.resolve();
341
+ }
342
+ var iframeNodesParams = appendParams.iframeNodesParams;
343
+ this.savePreviousChannel(iframeNodesParams);
344
+ return this.pluginAppendIframe(appendParams);
307
345
  }
308
346
  }, {
309
347
  key: "preloadComponent",
@@ -372,11 +410,28 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
372
410
  _this6._eventCenter.emit(EVENT.error.name, error);
373
411
  return Promise.reject(error);
374
412
  }).then(function (appendParams) {
375
- var iframeNodesParams = appendParams.iframeNodesParams;
376
- _this6.savePreviousChannel(iframeNodesParams);
377
- return _this6.pluginAppendIframe(appendParams);
413
+ return _this6.mountComponentProcess(appendParams);
378
414
  });
379
415
  }
416
+ }, {
417
+ key: "mountComponentProcess",
418
+ value: function mountComponentProcess(appendParams) {
419
+ var _this$getBusActionNam2;
420
+ this._appendParams = appendParams;
421
+ var actionName = (_this$getBusActionNam2 = this.getBusActionNames()) === null || _this$getBusActionNam2 === void 0 ? void 0 : _this$getBusActionNam2.mountComponent;
422
+ if (actionName && BusManager.isSubscribed(actionName)) {
423
+ // 执行出错了,在通用拦截器返回
424
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
425
+ appendParams: appendParams,
426
+ options: this.originOptions
427
+ })));
428
+ return Promise.resolve();
429
+ }
430
+ var iframeNodesParams = appendParams.iframeNodesParams;
431
+ this.savePreviousChannel(iframeNodesParams);
432
+ return this.pluginAppendIframe(appendParams);
433
+ }
434
+
380
435
  /**
381
436
  * @description Execute payment submission process
382
437
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
@@ -388,21 +443,34 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
388
443
  var _this7 = this;
389
444
  return new Promise(function (resolve, reject) {
390
445
  try {
446
+ var _this7$getBusActionNa;
391
447
  var eventCallbackId = uuid();
392
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
393
- _this7._eventCenter.once(eventCallbackId, function (_data) {
394
- resolve(_data);
395
- });
396
- _this7._componentApp.dispatchToApp({
397
- context: {
398
- event: 'submitPay',
399
- eventCallbackId: eventCallbackId,
400
- data: data
401
- }
402
- });
403
448
  _this7.logger.logInfo({
404
449
  title: 'sdk_event_apiSubmit'
405
450
  });
451
+ var actionName = (_this7$getBusActionNa = _this7.getBusActionNames()) === null || _this7$getBusActionNa === void 0 ? void 0 : _this7$getBusActionNa.submit;
452
+ if (actionName && BusManager.isSubscribed(actionName)) {
453
+ // 执行出错了,在通用拦截器返回
454
+ BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
455
+ appendParams: _this7._appendParams,
456
+ options: _this7.originOptions,
457
+ data: data
458
+ }))).then(function (busMessage) {
459
+ resolve(busMessage === null || busMessage === void 0 ? void 0 : busMessage.getJSONObject());
460
+ });
461
+ } else {
462
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
463
+ _this7._eventCenter.once(eventCallbackId, function (_data) {
464
+ resolve(_data);
465
+ });
466
+ _this7._componentApp.dispatchToApp({
467
+ context: {
468
+ event: 'submitPay',
469
+ eventCallbackId: eventCallbackId,
470
+ data: data
471
+ }
472
+ });
473
+ }
406
474
  } catch (error) {
407
475
  reject(error);
408
476
  }
@@ -1,7 +1,8 @@
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;
7
8
  originOptions: IoptionsParams;
@@ -9,6 +10,7 @@ export default class AMSSDK {
9
10
  _eventCenter: EventCenter;
10
11
  _instanceId: string;
11
12
  _storageId: string;
13
+ _appendParams: IAppendParams;
12
14
  protected securitySdkMap: Map<string, Security>;
13
15
  protected plugins: Map<string, any>;
14
16
  constructor(options: IoptionsParams);
@@ -73,4 +75,5 @@ export default class AMSSDK {
73
75
  * @description Overlay Subscription
74
76
  */
75
77
  protected _overrideSubscription(name: string, func: any, funcKey: string): void;
78
+ protected getBusActionNames(): ComponentActionNamesType;
76
79
  }
@@ -26,6 +26,7 @@ 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);
@@ -35,6 +36,7 @@ var AMSSDK = /*#__PURE__*/function () {
35
36
  _defineProperty(this, "_eventCenter", void 0);
36
37
  _defineProperty(this, "_instanceId", void 0);
37
38
  _defineProperty(this, "_storageId", void 0);
39
+ _defineProperty(this, "_appendParams", void 0);
38
40
  _defineProperty(this, "securitySdkMap", void 0);
39
41
  _defineProperty(this, "plugins", void 0);
40
42
  this._instanceId = uuid();
@@ -103,17 +105,27 @@ var AMSSDK = /*#__PURE__*/function () {
103
105
  }, {
104
106
  key: "unmount",
105
107
  value: function unmount() {
108
+ var _this$getBusActionNam;
106
109
  this.logger.logInfo({
107
110
  title: 'sdk_event_apiOnDestroy'
108
111
  }).send();
112
+ var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.destoryComponent;
113
+ if (actionName && BusManager.isSubscribed(actionName)) {
114
+ // 执行出错了,在通用拦截器返回
115
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
116
+ options: this.originOptions
117
+ })));
118
+ }
109
119
  var _iterator = _createForOfIteratorHelper(this.plugins.values()),
110
120
  _step;
111
121
  try {
112
122
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
113
123
  var plugin = _step.value;
114
124
  try {
115
- plugin.logoutPlugin();
116
- // eslint-disable-next-line no-empty
125
+ if (plugin.logoutPlugin) {
126
+ plugin.logoutPlugin();
127
+ // eslint-disable-next-line no-empty
128
+ }
117
129
  } catch (error) {
118
130
  console.error(error);
119
131
  }
@@ -304,7 +316,9 @@ var AMSSDK = /*#__PURE__*/function () {
304
316
  value: function _registerPlugin(pluginId, plugin) {
305
317
  this.plugins.set(pluginId, plugin);
306
318
  try {
307
- plugin.applyPlugin(this);
319
+ if (plugin.applyPlugin) {
320
+ plugin.applyPlugin(this);
321
+ }
308
322
  } catch (error) {
309
323
  this.plugins.delete(pluginId);
310
324
  if (getType(error) === 'error') throw error;
@@ -318,7 +332,7 @@ var AMSSDK = /*#__PURE__*/function () {
318
332
  key: "_getPlugin",
319
333
  value: function _getPlugin(pluginId) {
320
334
  if (!this.plugins.has(pluginId)) {
321
- console.warn("".concat(pluginId, "Plugin unregistered"));
335
+ console.warn("".concat(pluginId, " Plugin unregistered"));
322
336
  return null;
323
337
  }
324
338
  return this.plugins.get(pluginId);
@@ -383,6 +397,27 @@ var AMSSDK = /*#__PURE__*/function () {
383
397
  this._eventCenter.off(name, func, funcKey);
384
398
  this._eventCenter.on(name, func, funcKey);
385
399
  }
400
+ }, {
401
+ key: "getBusActionNames",
402
+ value: function getBusActionNames() {
403
+ var _appendParams$iframeN;
404
+ var appendParams = this._appendParams;
405
+ if (!appendParams) {
406
+ return null;
407
+ }
408
+ var actionNames = null;
409
+ 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;
410
+ if (paymentSessionConfig) {
411
+ var _appendParams$iframeN2;
412
+ var pluginKey = paymentSessionConfig.productScene + paymentSessionConfig.productSceneVersion + paymentSessionConfig.paymentMethodCategoryType;
413
+ 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;
414
+ if (paymentMethodType) {
415
+ pluginKey = pluginKey + paymentMethodType;
416
+ }
417
+ actionNames = this._getPlugin(pluginKey);
418
+ }
419
+ return actionNames;
420
+ }
386
421
  }]);
387
422
  return AMSSDK;
388
423
  }();
@@ -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",
@@ -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
+ mountComponent?: string;
9
+ submit?: 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 {};
@@ -474,4 +474,12 @@ export interface MultipleCallbackEvents {
474
474
  export type PaymentMethodTypeEnum = 'ApplePay';
475
475
  export type ApplePaySubTypeEnum = 'ApplePayRecurringPayment';
476
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
+ };
477
485
  export {};
@@ -164,4 +164,9 @@ export var RedirectType = /*#__PURE__*/function (RedirectType) {
164
164
  RedirectType["NormalUrl"] = "NormalUrl";
165
165
  RedirectType["Unknown"] = "Unknown";
166
166
  return RedirectType;
167
+ }({});
168
+ export var ProductSceneVersion = /*#__PURE__*/function (ProductSceneVersion) {
169
+ ProductSceneVersion["V1"] = "1.0";
170
+ ProductSceneVersion["V2"] = "2.0";
171
+ return ProductSceneVersion;
167
172
  }({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1710212811-dev.27",
3
+ "version": "0.0.1710212811-dev.29",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",