@alipay/ams-checkout 0.0.1709715270-dev.2 → 0.0.1709715270-dev.3

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,44 +75,22 @@ 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
- message: 'Abnormal response data is null'
88
+ message: 'Abnormal paymentSessionData'
100
89
  });
101
90
  this.logger.logError({
102
91
  name: 'APPLE_PAY',
103
92
  title: 'sessionDataNull',
104
- msg: 'Abnormal response data is null'
105
- }, {
106
- type: 'error',
107
- biz: 'sdk'
108
- }).send();
109
- return;
110
- }
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'
93
+ msg: 'Abnormal paymentSessionData'
123
94
  }, {
124
95
  type: 'error',
125
96
  biz: 'sdk'
@@ -288,18 +259,20 @@ var ApplePayComponent = /*#__PURE__*/function () {
288
259
  var _data$actionForm;
289
260
  _this._isFinish = true;
290
261
  _this.onEventCallback({
291
- code: eventCodeEnum.SDK_PAYMENT_FINISH,
262
+ code: eventCodeEnum.SDK_PAYMENT_SUCCESSFUL,
263
+ message: 'Payment successful',
292
264
  result: {
293
265
  redirectUrl: (data === null || data === void 0 || (_data$actionForm = data.actionForm) === null || _data$actionForm === void 0 ? void 0 : _data$actionForm.redirectUrl) || ''
294
266
  }
295
267
  });
296
268
  };
297
- var logError = function logError(msg, error) {
269
+ var logError = function logError(code, msg, error) {
298
270
  // log error
299
271
  _this.logger.logError({
300
272
  name: 'APPLE_PAY',
301
273
  title: msg,
302
274
  label: msg,
275
+ code: code,
303
276
  msg: error
304
277
  }, {
305
278
  type: 'error',
@@ -309,16 +282,18 @@ var ApplePayComponent = /*#__PURE__*/function () {
309
282
  return;
310
283
  }
311
284
  _this._isFinish = true;
312
- if (msg === 'UserCancel') {
285
+ if (error !== null && error !== void 0 && error.errorCode) {
313
286
  _this.onEventCallback({
314
- code: eventCodeEnum.SDK_PAYMENT_CANCEL
287
+ code: code,
288
+ message: msg,
289
+ result: {
290
+ errorCode: error === null || error === void 0 ? void 0 : error.errorCode
291
+ }
315
292
  });
316
293
  } else {
317
294
  _this.onEventCallback({
318
- code: eventCodeEnum.SDK_PAYMENT_FAIL,
319
- result: {
320
- errorMsg: msg
321
- }
295
+ code: code,
296
+ message: msg
322
297
  });
323
298
  }
324
299
  };
@@ -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",
@@ -158,6 +158,6 @@ export type ICompletePaymentAuthorized = (params: {
158
158
  paymentToken?: string;
159
159
  }) => Promise<any>;
160
160
  export type ICompleteApplePay = (data: any) => void;
161
- export type ILogError = (msg: string, error?: any) => void;
161
+ export type ILogError = (code: string, msg: string, error?: any) => void;
162
162
  export type traceMsg = 'start' | 'sessionBegin' | 'onValidateMerchant' | 'completeMerchantValidation' | 'onpaymentauthorized' | 'completePaymentAuthorized' | 'completeApplePay';
163
163
  export type IApplePayTrace = (msg: traceMsg) => void;
@@ -14,6 +14,7 @@ declare class ApplePayService {
14
14
  private merchantIdentifier;
15
15
  private merchantName;
16
16
  private session;
17
+ private paymentState;
17
18
  private getMerchantSession;
18
19
  private completePaymentAuthorized;
19
20
  private completeApplePay;
@@ -17,6 +17,14 @@ 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 { eventCodeEnum } from "../../types";
21
+ var PaymentState = /*#__PURE__*/function (PaymentState) {
22
+ PaymentState[PaymentState["notStarted"] = 0] = "notStarted";
23
+ PaymentState[PaymentState["pending"] = 1] = "pending";
24
+ PaymentState[PaymentState["fail"] = 2] = "fail";
25
+ PaymentState[PaymentState["success"] = 3] = "success";
26
+ return PaymentState;
27
+ }(PaymentState || {});
20
28
  /**
21
29
  * Apple Pay Service
22
30
  */
@@ -27,6 +35,7 @@ var ApplePayService = /*#__PURE__*/function () {
27
35
  _defineProperty(this, "merchantIdentifier", void 0);
28
36
  _defineProperty(this, "merchantName", void 0);
29
37
  _defineProperty(this, "session", void 0);
38
+ _defineProperty(this, "paymentState", void 0);
30
39
  _defineProperty(this, "getMerchantSession", void 0);
31
40
  _defineProperty(this, "completePaymentAuthorized", void 0);
32
41
  _defineProperty(this, "completeApplePay", void 0);
@@ -44,7 +53,7 @@ var ApplePayService = /*#__PURE__*/function () {
44
53
  _this.session.completeMerchantValidation(merchantSessionObject);
45
54
  _this.applePayTrace('completeMerchantValidation');
46
55
  }).catch(function (error) {
47
- _this.logError('MerchantValidationError', error);
56
+ _this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'MerchantValidationError', error);
48
57
  _this.session.abort();
49
58
  });
50
59
  });
@@ -55,19 +64,22 @@ var ApplePayService = /*#__PURE__*/function () {
55
64
  ApplePaySession = _window.ApplePaySession;
56
65
  var exception = function exception(error) {
57
66
  _this.session.completePayment(ApplePaySession.STATUS_FAILURE);
58
- _this.logError('PaymentAuthorizedError', error);
67
+ _this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'PaymentAuthorizedError', error);
59
68
  _this.session.abort();
60
69
  };
61
70
  if (event !== null && event !== void 0 && (_event$payment = event.payment) !== null && _event$payment !== void 0 && _event$payment.token) {
62
71
  _this.applePayTrace('completePaymentAuthorized');
72
+ _this.paymentState = PaymentState.pending;
63
73
  _this.completePaymentAuthorized({
64
74
  paymentToken: JSON.stringify(event.payment.token)
65
75
  }).then(function (data) {
66
76
  _this.applePayTrace('completeApplePay');
67
77
  _this.session.completePayment(ApplePaySession.STATUS_SUCCESS);
68
78
  _this.completeApplePay(data);
79
+ _this.paymentState = PaymentState.success;
69
80
  }).catch(function (error) {
70
81
  exception(error);
82
+ _this.paymentState = PaymentState.fail;
71
83
  });
72
84
  } else {
73
85
  exception();
@@ -91,13 +103,13 @@ var ApplePayService = /*#__PURE__*/function () {
91
103
  recurringInfo = paymentSessionFactor.recurringInfo;
92
104
  _this.merchantIdentifier = merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.partnerId;
93
105
  if (!(extendInfo !== null && extendInfo !== void 0 && extendInfo.merchantCapabilities) || !(extendInfo !== null && extendInfo !== void 0 && extendInfo.supportedNetworks) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.registeredCountry) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.currency) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.value) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.merchantName)) {
94
- _this.logError("invalid session data");
106
+ _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal paymentSessionFactor");
95
107
  return;
96
108
  }
97
109
  if (recurringInfo) {
98
110
  var _recurringInfo$interv;
99
111
  if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
100
- _this.logError("invalid session data in recurring");
112
+ _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal recurringInfo");
101
113
  return;
102
114
  }
103
115
  var lineItem = {
@@ -145,7 +157,11 @@ var ApplePayService = /*#__PURE__*/function () {
145
157
  _this.session.onvalidatemerchant = _this.onvalidatemerchant;
146
158
  _this.session.onpaymentauthorized = _this.onpaymentauthorized;
147
159
  _this.session.oncancel = function () {
148
- _this.logError('UserCancel');
160
+ if (_this.paymentState === PaymentState.pending) {
161
+ _this.logError(eventCodeEnum.SDK_PAYMENT_PROCESSING, 'Payment processing but user dismissed the sheet');
162
+ } else {
163
+ _this.logError(eventCodeEnum.SDK_PAYMENT_CANCEL, 'User dismissed the sheet');
164
+ }
149
165
  try {
150
166
  _this.session.abort();
151
167
  } catch (error) {
@@ -173,6 +189,7 @@ var ApplePayService = /*#__PURE__*/function () {
173
189
  this.completeApplePay = completeApplePay;
174
190
  this.logError = logError;
175
191
  this.applePayTrace = applePayTrace;
192
+ this.paymentState = PaymentState.notStarted;
176
193
  }
177
194
 
178
195
  /**
@@ -0,0 +1,2 @@
1
+ import { IExtendPlugin } from './type';
2
+ export declare const ExtendPlugin: IExtendPlugin;