@alipay/ams-checkout 1.30.0 → 1.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/config/index.d.ts +7 -7
  3. package/esm/config/index.js +7 -7
  4. package/esm/core/component/ckp/index.js +2 -0
  5. package/esm/core/component/element/components/address.d.ts +1 -1
  6. package/esm/core/component/element/components/address.js +2 -2
  7. package/esm/core/component/element/components/payment.d.ts +1 -1
  8. package/esm/core/component/element/components/payment.js +2 -2
  9. package/esm/core/component/element/index.d.ts +7 -6
  10. package/esm/core/component/element/index.js +287 -222
  11. package/esm/core/component/element/type.d.ts +171 -12
  12. package/esm/core/component/element/type.js +48 -3
  13. package/esm/core/component/index.js +5 -0
  14. package/esm/core/instance/index.js +12 -1
  15. package/esm/foundation/index.d.ts +1 -1
  16. package/esm/foundation/product-processor/easysafepay/index.d.ts +0 -2
  17. package/esm/foundation/product-processor/easysafepay/index.js +29 -73
  18. package/esm/foundation/service/container/index.d.ts +0 -2
  19. package/esm/foundation/service/container/index.js +20 -47
  20. package/esm/foundation/utils/payment_product_utils.d.ts +1 -1
  21. package/esm/foundation/utils/payment_product_utils.js +2 -2
  22. package/esm/foundation/utils/preload_helper.d.ts +21 -0
  23. package/esm/foundation/utils/preload_helper.js +143 -0
  24. package/esm/index.d.ts +7 -2
  25. package/esm/index.js +94 -7
  26. package/esm/plugin/component/index.d.ts +1 -0
  27. package/esm/plugin/component/index.js +24 -11
  28. package/esm/service/index.d.ts +0 -1
  29. package/esm/service/index.js +0 -2
  30. package/esm/types/index.d.ts +8 -117
  31. package/esm/types/index.js +2 -34
  32. package/esm/util/security.d.ts +1 -0
  33. package/esm/util/security.js +3 -1
  34. package/esm/util/spm-map.d.ts +3 -0
  35. package/esm/util/spm-map.js +3 -0
  36. package/package.json +1 -1
  37. package/esm/service/element.d.ts +0 -4
  38. package/esm/service/element.js +0 -51
@@ -18,8 +18,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
18
18
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
19
  import PackageJson from "../../../../package.json";
20
20
  import { AntomSDKCore } from "../../../foundation/core";
21
+ import { ServiceProvider } from "../../../foundation/service";
21
22
  import { EVENT as ConstantEvent } from "../../../constant";
22
- import { ConnectErrorCode, ElementPaymentEvent, ElementPaymentMethod, EventCallbackCode, ProductSceneEnum } from "../../../types";
23
+ import { ProductSceneEnum } from "../../../types";
23
24
  import { parseSessionData } from "../index";
24
25
  import { ElementAddressComponent } from "./components/address";
25
26
  import { ElementAuthComponent } from "./components/auth";
@@ -27,8 +28,9 @@ import { ElementPaymentComponent } from "./components/payment";
27
28
  // import { oneAccount, sdkAction, submitResult } from './mock';
28
29
  import { ApplePaySdk, isSkipRenderPaymentMethod } from "../../../plugin/component/channel";
29
30
  import { v4 as uuid } from 'uuid';
31
+ import { destroyModal } from "../../../plugin/component/popupWindow.style";
30
32
  import { LogConfig, Logger } from "../../../util/logger";
31
- import { addressTheme, ELEMENT_ENVIRONMENT, ThemeType } from "./type";
33
+ import { addressTheme, ElementPaymentEvent, ElementPaymentMethod, ElementType, ELEMENT_ENVIRONMENT, EventCallbackCode, MountElementType, ThemeType } from "./type";
32
34
  var logger = new Logger(LogConfig, true);
33
35
  var ElementProcessor = /*#__PURE__*/function () {
34
36
  function ElementProcessor(options) {
@@ -40,12 +42,8 @@ var ElementProcessor = /*#__PURE__*/function () {
40
42
  }
41
43
  _createClass(ElementProcessor, [{
42
44
  key: "init",
43
- value: function init() {
44
- var elementContainer = new AntomSDKCore();
45
- elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', undefined);
46
- elementContainer.init({}, ProductSceneEnum.ELEMENT_PAYMENT);
47
- var serviceProvider = elementContainer.getServiceProvider();
48
- this.requestService = serviceProvider.getService('Requester');
45
+ value: function init(config, instanceId) {
46
+ this.requestService = ServiceProvider.getInstance(instanceId).getService('Requester');
49
47
  }
50
48
  }, {
51
49
  key: "sdkActionQuery",
@@ -156,7 +154,7 @@ export var ElementComponent = /*#__PURE__*/function () {
156
154
  _defineProperty(this, "parseData", void 0);
157
155
  // sessionData 解析出来的数据
158
156
  _defineProperty(this, "loading", void 0);
159
- // mount loading
157
+ // element loading
160
158
  _defineProperty(this, "sessionData", void 0);
161
159
  // sessionData 解析出来的数据
162
160
  _defineProperty(this, "elementContainer", void 0);
@@ -171,14 +169,15 @@ export var ElementComponent = /*#__PURE__*/function () {
171
169
  // element 入参
172
170
  _defineProperty(this, "eventService", void 0);
173
171
  // 消息服务
174
- _defineProperty(this, "requestService", void 0);
175
- // 接口服务
172
+ // private requestService: RequesterService; // 接口服务 一期connect功能,目前已都放入到应用层
176
173
  _defineProperty(this, "sdkActionRes", void 0);
177
174
  // sdk aciton接口返回
178
175
  _defineProperty(this, "oneAccountRes", void 0);
179
176
  // one account接口返回
180
177
  _defineProperty(this, "launchSource", void 0);
181
178
  // launch 来源记录
179
+ _defineProperty(this, "initCompleted", void 0);
180
+ // init完成
182
181
  _defineProperty(this, "isConnect", void 0);
183
182
  // 当前sessionData是否connect模式
184
183
  _defineProperty(this, "iframeSrc", void 0);
@@ -187,6 +186,8 @@ export var ElementComponent = /*#__PURE__*/function () {
187
186
  // 组件mount配置记录
188
187
  _defineProperty(this, "iframes", void 0);
189
188
  // iframs合集
189
+ _defineProperty(this, "loadingElement", []);
190
+ // 当前加载中的element
190
191
  _defineProperty(this, "componentsCount", void 0);
191
192
  // mount 渲染了多少个element
192
193
  _defineProperty(this, "eventCallback", void 0);
@@ -209,9 +210,10 @@ export var ElementComponent = /*#__PURE__*/function () {
209
210
  prefillValue: renderOptions.prefillValue
210
211
  };
211
212
  _this4.mountOptions[ElementPaymentMethod.ADDRESS_ELEMENT] = _mountParams;
212
- _this4.addressBase.mount(_this4._options.sessionData, _objectSpread({
213
+ _this4.addressBase.mount(_objectSpread({
213
214
  selector: sdkSelector,
214
- elementProps: renderOptions.elementProps
215
+ elementProps: renderOptions.elementProps,
216
+ sessionData: renderOptions.sessionData
215
217
  }, _mountParams)).then(function (result) {
216
218
  if (!result) {
217
219
  return _this4.mountErrorHandle();
@@ -235,8 +237,9 @@ export var ElementComponent = /*#__PURE__*/function () {
235
237
  };
236
238
  _this4.mountOptions[ElementPaymentMethod.PAYMENT_ELEMENT] = _mountParams;
237
239
  _this4.initApplePaySdk();
238
- _this4.paymentBase.mount(_this4._options.sessionData, _objectSpread({
240
+ _this4.paymentBase.mount(_objectSpread({
239
241
  selector: sdkSelector,
242
+ sessionData: renderOptions.sessionData,
240
243
  elementProps: renderOptions.elementProps
241
244
  }, _mountParams)).then(function (result) {
242
245
  if (!result) {
@@ -247,7 +250,7 @@ export var ElementComponent = /*#__PURE__*/function () {
247
250
  });
248
251
  return {};
249
252
  });
250
- // submit提交非RISK_REJECT错误
253
+ // submit提交非RISK_REJECT错误 一期connect功能,目前已都放入到应用层
251
254
  _defineProperty(this, "onAfterSubmitFunc", function (target, params) {
252
255
  _this4.eventService.emitAndListen({
253
256
  event: ElementPaymentEvent.AFTER_SUBMIT,
@@ -258,65 +261,76 @@ export var ElementComponent = /*#__PURE__*/function () {
258
261
  }
259
262
  }, function () {});
260
263
  });
261
- // submit提交 失败,清空组件数据
262
- _defineProperty(this, "onSubmitRiskFunc", function (target) {
263
- _this4.eventService.emitAndListen({
264
- event: ElementPaymentEvent.SUBMIT_RISK,
265
- data: {
266
- target: target,
267
- source: ElementPaymentMethod.CONTAINER_ELEMENT,
268
- params: {}
269
- }
270
- }, function () {});
271
- });
272
- // 发起支付
273
- _defineProperty(this, "onSubmit", function (params) {
274
- return new Promise(function (resolve) {
275
- var paymentSessionConfig = _this4.parseData.paymentSessionConfig;
276
- console.log('element submit params ------', _objectSpread({
277
- paymentSessionConfig: paymentSessionConfig,
278
- paymentSessionData: _this4.sessionData
279
- }, params));
280
- _this4.requestService.request(_objectSpread({
281
- paymentSessionConfig: paymentSessionConfig,
282
- paymentSessionData: _this4.sessionData
283
- }, params), {
284
- env: _this4._options.environment,
285
- envInfo: {
286
- locale: _this4._options.locale
287
- },
288
- timeout: 300000,
289
- // TODO dev环境submit提交接口超时
290
- 'Operation-Type': 'com.ipay.iexpcashier.cashier.submitPayByPaymentSession'
291
- }).then(function (result) {
292
- var _result$codeFormViews, _result$actionForm;
293
- if (result !== null && result !== void 0 && result.codeFormViews && result !== null && result !== void 0 && (_result$codeFormViews = result.codeFormViews) !== null && _result$codeFormViews !== void 0 && (_result$codeFormViews = _result$codeFormViews[0]) !== null && _result$codeFormViews !== void 0 && _result$codeFormViews.codeExpireTime && result !== null && result !== void 0 && result.actionForm && !(result !== null && result !== void 0 && (_result$actionForm = result.actionForm) !== null && _result$actionForm !== void 0 && _result$actionForm.paymentCodeExpireTime)) {
294
- var _result$codeFormViews2;
295
- result.actionForm.paymentCodeExpireTime = result === null || result === void 0 || (_result$codeFormViews2 = result.codeFormViews) === null || _result$codeFormViews2 === void 0 || (_result$codeFormViews2 = _result$codeFormViews2[0]) === null || _result$codeFormViews2 === void 0 ? void 0 : _result$codeFormViews2.codeExpireTime;
296
- }
297
- if (result.errorCode === ConnectErrorCode.RISK_REJECT) {
298
- _this4.onSubmitRiskFunc(ElementPaymentMethod.ADDRESS_ELEMENT);
299
- _this4.onSubmitRiskFunc(ElementPaymentMethod.AUTH_ELEMENT);
300
- _this4.onSubmitRiskFunc(ElementPaymentMethod.PAYMENT_ELEMENT);
301
- } else {
302
- _this4.onAfterSubmitFunc(ElementPaymentMethod.PAYMENT_ELEMENT, result);
303
- }
304
- resolve({
305
- success: result.success,
306
- msg: result.errorMessage
307
- });
308
- }, function () {
309
- resolve({
310
- success: false,
311
- msg: 'submitPayByPaymentSession api error'
312
- });
313
- // this?._options?.onEventCallback?.({
314
- // code: EventCallbackCode.Failed,
315
- // message: 'submitPayByPaymentSession api error',
316
- // });
317
- });
318
- });
319
- });
264
+ // submit提交 失败,清空组件数据 一期connect功能,目前已都放入到应用层
265
+ // private onSubmitRiskFunc = (target: ElementPaymentMethod) => {
266
+ // this.eventService.emitAndListen(
267
+ // {
268
+ // event: ElementPaymentEvent.SUBMIT_RISK,
269
+ // data: {
270
+ // target,
271
+ // source: ElementPaymentMethod.CONTAINER_ELEMENT,
272
+ // params: {},
273
+ // },
274
+ // },
275
+ // () => {},
276
+ // );
277
+ // };
278
+ // 发起支付 一期connect功能,目前已都放入到应用层
279
+ // private onSubmit = (params: SubmitServiceParams): Promise<SubmitFuncResult> => {
280
+ // return new Promise((resolve) => {
281
+ // const { paymentSessionConfig } = this.parseData;
282
+ // console.log('element submit params ------', {
283
+ // paymentSessionConfig,
284
+ // paymentSessionData: this.sessionData,
285
+ // ...params,
286
+ // });
287
+ // this.requestService
288
+ // .request<SubmitServiceResult>(
289
+ // {
290
+ // paymentSessionConfig,
291
+ // paymentSessionData: this.sessionData,
292
+ // ...params,
293
+ // },
294
+ // {
295
+ // env: this._options.environment,
296
+ // envInfo: {
297
+ // locale: this._options.locale,
298
+ // },
299
+ // timeout: 300000, // TODO dev环境submit提交接口超时
300
+ // 'Operation-Type': 'com.ipay.iexpcashier.cashier.submitPayByPaymentSession',
301
+ // },
302
+ // )
303
+ // .then(
304
+ // (result) => {
305
+ // if (
306
+ // result?.codeFormViews &&
307
+ // result?.codeFormViews?.[0]?.codeExpireTime &&
308
+ // result?.actionForm &&
309
+ // !result?.actionForm?.paymentCodeExpireTime
310
+ // ) {
311
+ // result.actionForm.paymentCodeExpireTime = result?.codeFormViews?.[0]?.codeExpireTime;
312
+ // }
313
+ // if (result.errorCode === ConnectErrorCode.RISK_REJECT) {
314
+ // this.onSubmitRiskFunc(ElementPaymentMethod.ADDRESS_ELEMENT);
315
+ // this.onSubmitRiskFunc(ElementPaymentMethod.AUTH_ELEMENT);
316
+ // this.onSubmitRiskFunc(ElementPaymentMethod.PAYMENT_ELEMENT);
317
+ // } else {
318
+ // this.onAfterSubmitFunc(ElementPaymentMethod.PAYMENT_ELEMENT, result);
319
+ // }
320
+ // resolve({
321
+ // success: result.success,
322
+ // msg: result.errorMessage,
323
+ // });
324
+ // },
325
+ // () => {
326
+ // resolve({
327
+ // success: false,
328
+ // msg: 'submitPayByPaymentSession api error',
329
+ // });
330
+ // },
331
+ // );
332
+ // });
333
+ // };
320
334
  // 发送validate消息
321
335
  _defineProperty(this, "onValidateFunc", function (target, params) {
322
336
  return new Promise(function (resolve) {
@@ -344,70 +358,65 @@ export var ElementComponent = /*#__PURE__*/function () {
344
358
  case 0:
345
359
  params = {};
346
360
  if (!_this4.launchSource.includes(ElementPaymentMethod.AUTH_ELEMENT)) {
347
- _context.next = 9;
361
+ _context.next = 8;
348
362
  break;
349
363
  }
350
364
  _context.next = 4;
351
365
  return _this4.onValidateFunc(ElementPaymentMethod.AUTH_ELEMENT);
352
366
  case 4:
353
367
  result = _context.sent;
354
- console.log('element submit validate auth---------', result);
355
368
  params.accountInfo = (_result$data = result.data) === null || _result$data === void 0 || (_result$data = _result$data.data) === null || _result$data === void 0 ? void 0 : _result$data.accountInfo;
356
369
  if (result !== null && result !== void 0 && (_result$data2 = result.data) !== null && _result$data2 !== void 0 && _result$data2.success) {
357
- _context.next = 9;
370
+ _context.next = 8;
358
371
  break;
359
372
  }
360
373
  return _context.abrupt("return", resolve(undefined));
361
- case 9:
374
+ case 8:
362
375
  if (!_this4.launchSource.includes(ElementPaymentMethod.ADDRESS_ELEMENT)) {
363
- _context.next = 17;
376
+ _context.next = 15;
364
377
  break;
365
378
  }
366
- _context.next = 12;
379
+ _context.next = 11;
367
380
  return _this4.onValidateFunc(ElementPaymentMethod.ADDRESS_ELEMENT);
368
- case 12:
381
+ case 11:
369
382
  _result = _context.sent;
370
- console.log('element submit validate address---------', _result);
371
383
  params.shipping = (_result$data3 = _result.data) === null || _result$data3 === void 0 ? void 0 : _result$data3.data;
372
384
  if (_result !== null && _result !== void 0 && (_result$data4 = _result.data) !== null && _result$data4 !== void 0 && _result$data4.success) {
373
- _context.next = 17;
385
+ _context.next = 15;
374
386
  break;
375
387
  }
376
388
  return _context.abrupt("return", resolve(undefined));
377
- case 17:
389
+ case 15:
378
390
  if (!(_this4.launchSource.includes(ElementPaymentMethod.PAYMENT_ELEMENT) || !_this4.isConnect)) {
379
- _context.next = 30;
391
+ _context.next = 27;
380
392
  break;
381
393
  }
382
- _context.prev = 18;
383
- _context.next = 21;
394
+ _context.prev = 16;
395
+ _context.next = 19;
384
396
  return _this4.onValidateFunc(ElementPaymentMethod.PAYMENT_ELEMENT, params);
385
- case 21:
397
+ case 19:
386
398
  _result2 = _context.sent;
387
- console.log('element submit validate payment---------', _result2, _this4.isConnect);
388
- // params.paymentFactors = result.data?.data?.paymentFactors;
389
- // params.paymentMethod = result.data?.data?.paymentMethod;
390
399
  if (_result2 !== null && _result2 !== void 0 && (_result2$data = _result2.data) !== null && _result2$data !== void 0 && _result2$data.success) {
391
- _context.next = 25;
400
+ _context.next = 22;
392
401
  break;
393
402
  }
394
403
  return _context.abrupt("return", resolve(undefined));
395
- case 25:
396
- _context.next = 30;
404
+ case 22:
405
+ _context.next = 27;
397
406
  break;
398
- case 27:
399
- _context.prev = 27;
400
- _context.t0 = _context["catch"](18);
407
+ case 24:
408
+ _context.prev = 24;
409
+ _context.t0 = _context["catch"](16);
401
410
  return _context.abrupt("return", resolve(undefined));
402
- case 30:
411
+ case 27:
403
412
  // params.paymentFactors = paymentResult.data?.data.paymentFactors;
404
413
  // params.paymentMethod = paymentResult.data?.data.paymentMethod;
405
414
  resolve(params);
406
- case 31:
415
+ case 28:
407
416
  case "end":
408
417
  return _context.stop();
409
418
  }
410
- }, _callee, null, [[18, 27]]);
419
+ }, _callee, null, [[16, 24]]);
411
420
  }));
412
421
  return function (_x) {
413
422
  return _ref.apply(this, arguments);
@@ -418,14 +427,6 @@ export var ElementComponent = /*#__PURE__*/function () {
418
427
  this._options = _objectSpread(_objectSpread({}, options), {}, {
419
428
  environment: env.toLocaleLowerCase()
420
429
  });
421
- this.eventCallback = _defineProperty(_defineProperty(_defineProperty({}, ElementPaymentMethod.ADDRESS_ELEMENT, {}), ElementPaymentMethod.AUTH_ELEMENT, {}), ElementPaymentMethod.PAYMENT_ELEMENT, {});
422
- this.launchSource = [];
423
- this.componentsCount = 0;
424
- this.iframes = {};
425
- this.mountOptions = {};
426
- logger.logInfo({
427
- title: 'a3753.b101271.c386688'
428
- });
429
430
  this.createElement();
430
431
  }
431
432
 
@@ -433,17 +434,32 @@ export var ElementComponent = /*#__PURE__*/function () {
433
434
  _createClass(ElementComponent, [{
434
435
  key: "createElement",
435
436
  value: function createElement() {
437
+ this.eventCallback = _defineProperty(_defineProperty(_defineProperty({}, ElementPaymentMethod.ADDRESS_ELEMENT, {}), ElementPaymentMethod.AUTH_ELEMENT, {}), ElementPaymentMethod.PAYMENT_ELEMENT, {});
438
+ this.launchSource = [];
439
+ this.componentsCount = 0;
440
+ this.iframes = {};
441
+ this.mountOptions = {};
442
+ logger.logInfo({
443
+ title: 'sdk_element_create'
444
+ });
445
+ this.elementContainer = new AntomSDKCore();
446
+ this.iframeSrc = this.createIframeSrc(this._options.environment, this._options.version);
447
+ }
448
+ }, {
449
+ key: "beforeMount",
450
+ value: function beforeMount(mountSessionData) {
436
451
  var _parseData$connectFac,
437
452
  _parseData$paymentSes,
438
453
  _this5 = this;
439
- var _parseSessionData = parseSessionData(this._options.sessionData),
454
+ if (this.initCompleted) return;
455
+ this.initCompleted = true;
456
+ var _parseSessionData = parseSessionData(mountSessionData),
440
457
  _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
441
458
  parseData = _parseSessionData2[0],
442
459
  sessionData = _parseSessionData2[1];
443
460
  this.parseData = parseData;
444
461
  this.sessionData = sessionData;
445
462
  this.isConnect = (parseData === null || parseData === void 0 || (_parseData$connectFac = parseData.connectFactor) === null || _parseData$connectFac === void 0 ? void 0 : _parseData$connectFac.enableConnect) && (parseData === null || parseData === void 0 || (_parseData$paymentSes = parseData.paymentSessionConfig) === null || _parseData$paymentSes === void 0 ? void 0 : _parseData$paymentSes.productScene) === ProductSceneEnum.ELEMENT_PAYMENT;
446
- this.elementContainer = new AntomSDKCore();
447
463
  this.elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', new ElementProcessor({
448
464
  paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
449
465
  sessionData: sessionData,
@@ -452,72 +468,83 @@ export var ElementComponent = /*#__PURE__*/function () {
452
468
  isConnect: this.isConnect
453
469
  }));
454
470
  this.elementContainer.init({}, ProductSceneEnum.ELEMENT_PAYMENT);
455
- this.elementContainer.startBizFlow({
456
- paymentSession: this._options.sessionData
457
- }).then(function () {
458
- var _bizFlowBehavior$data;
459
- if (!_this5.isConnect) return;
460
- var bizFlowBehavior = _this5.elementContainer.getBizFlowBehavior();
461
- if (!(bizFlowBehavior !== null && bizFlowBehavior !== void 0 && (_bizFlowBehavior$data = bizFlowBehavior.data) !== null && _bizFlowBehavior$data !== void 0 && _bizFlowBehavior$data.success)) {
462
- var _this5$_options, _this5$_options$onEve;
463
- console.log('demo event callback----', {
464
- code: EventCallbackCode.FAILED,
465
- message: 'INTERNAL_FAILED'
466
- });
467
- _this5 === null || _this5 === void 0 || (_this5$_options = _this5._options) === null || _this5$_options === void 0 || (_this5$_options$onEve = _this5$_options.onEventCallback) === null || _this5$_options$onEve === void 0 || _this5$_options$onEve.call(_this5$_options, {
468
- code: EventCallbackCode.FAILED,
469
- message: 'INTERNAL_FAILED'
470
- });
471
- } else {
472
- var _bizFlowBehavior$data2, _bizFlowBehavior$data3;
473
- _this5.oneAccountRes = bizFlowBehavior === null || bizFlowBehavior === void 0 || (_bizFlowBehavior$data2 = bizFlowBehavior.data) === null || _bizFlowBehavior$data2 === void 0 ? void 0 : _bizFlowBehavior$data2.oneAccountRes;
474
- _this5.sdkActionRes = bizFlowBehavior === null || bizFlowBehavior === void 0 || (_bizFlowBehavior$data3 = bizFlowBehavior.data) === null || _bizFlowBehavior$data3 === void 0 ? void 0 : _bizFlowBehavior$data3.sdkActionRes;
475
- _this5.afterInit();
476
- }
477
- });
478
- this.iframeSrc = this.createIframeSrc(this._options.environment, this._options.version);
479
471
  try {
480
- // 注册 auth 邮箱模块
481
- this.authBase = new ElementAuthComponent();
482
- this.authBase.create({
483
- environment: this._options.environment,
484
- locale: this._options.locale
472
+ this.elementContainer.startBizFlow({
473
+ paymentSession: mountSessionData
474
+ }).then(function () {
475
+ var _bizFlowBehavior$data;
476
+ if (!_this5.isConnect) return;
477
+ var bizFlowBehavior = _this5.elementContainer.getBizFlowBehavior();
478
+ if (!(bizFlowBehavior !== null && bizFlowBehavior !== void 0 && (_bizFlowBehavior$data = bizFlowBehavior.data) !== null && _bizFlowBehavior$data !== void 0 && _bizFlowBehavior$data.success)) {
479
+ var _this5$_options, _this5$_options$onEve;
480
+ _this5 === null || _this5 === void 0 || (_this5$_options = _this5._options) === null || _this5$_options === void 0 || (_this5$_options$onEve = _this5$_options.onEventCallback) === null || _this5$_options$onEve === void 0 || _this5$_options$onEve.call(_this5$_options, {
481
+ code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
482
+ message: 'Component initialization exception.'
483
+ });
484
+ _this5.closeLoading();
485
+ } else {
486
+ var _bizFlowBehavior$data2, _bizFlowBehavior$data3;
487
+ _this5.oneAccountRes = bizFlowBehavior === null || bizFlowBehavior === void 0 || (_bizFlowBehavior$data2 = bizFlowBehavior.data) === null || _bizFlowBehavior$data2 === void 0 ? void 0 : _bizFlowBehavior$data2.oneAccountRes;
488
+ _this5.sdkActionRes = bizFlowBehavior === null || bizFlowBehavior === void 0 || (_bizFlowBehavior$data3 = bizFlowBehavior.data) === null || _bizFlowBehavior$data3 === void 0 ? void 0 : _bizFlowBehavior$data3.sdkActionRes;
489
+ _this5.afterInit();
490
+ }
485
491
  });
486
- var serviceProvider = this.elementContainer.getServiceProvider();
487
- this.eventService = serviceProvider.getService('EventCenter');
488
- this.requestService = serviceProvider.getService('Requester');
489
- // 注册 payment 卡支付模块
490
- this.paymentBase = new ElementPaymentComponent();
491
- this.paymentBase.create({
492
- environment: this._options.environment,
493
- locale: this._options.locale,
494
- appVersion: this._options.version || ''
495
- }, this.isConnect);
496
-
497
- // 注册 address 地址模块
498
- this.addressBase = new ElementAddressComponent();
499
- this.addressBase.create({
500
- environment: this._options.environment,
501
- locale: this._options.locale,
502
- appVersion: this._options.version || ''
503
- }, this.isConnect);
504
492
  } catch (error) {
505
- var _this$_options$onEven, _this$_options;
506
- console.log('demo event callback----', {
507
- code: EventCallbackCode.FAILED,
508
- message: 'INTERNAL_FAILED'
509
- });
510
- (_this$_options$onEven = (_this$_options = this._options).onEventCallback) === null || _this$_options$onEven === void 0 || _this$_options$onEven.call(_this$_options, {
511
- code: EventCallbackCode.FAILED,
512
- message: 'INTERNAL_FAILED'
513
- // message: 'create sdk fail',
493
+ this._options.onEventCallback({
494
+ code: EventCallbackCode.SDK_CREATEPAYMENT_PARAMETER_ERROR,
495
+ message: 'Initialization parameter exception.'
514
496
  });
497
+ this.closeLoading();
515
498
  }
516
-
499
+ var serviceProvider = this.elementContainer.getServiceProvider();
500
+ // 注册事件服务
501
+ this.eventService = serviceProvider.getService('EventCenter');
502
+ // 注册请求服务服务 一期connect功能,目前已都放入到应用层
503
+ // this.requestService = serviceProvider.getService<RequesterService>('Requester');
517
504
  // 注册监听消息
518
505
  this.addListener();
519
506
  }
520
507
 
508
+ // 创建
509
+ }, {
510
+ key: "createComponentSdk",
511
+ value: function createComponentSdk(type) {
512
+ try {
513
+ // 注册 auth 邮箱模块
514
+ if (type === ElementType.auth) {
515
+ this.authBase = new ElementAuthComponent();
516
+ this.authBase.create({
517
+ environment: this._options.environment,
518
+ locale: this._options.locale
519
+ });
520
+ } else if (type === ElementType.address) {
521
+ this.addressBase = new ElementAddressComponent();
522
+ this.addressBase.create({
523
+ environment: this._options.environment,
524
+ locale: this._options.locale,
525
+ appVersion: this._options.version || ''
526
+ }, this.isConnect);
527
+ } else if (type === ElementType.payment) {
528
+ // 注册 payment 卡支付模块
529
+ this.paymentBase = new ElementPaymentComponent();
530
+ this.paymentBase.create({
531
+ environment: this._options.environment,
532
+ locale: this._options.locale,
533
+ appVersion: this._options.version || ''
534
+ }, this.isConnect);
535
+ } else {
536
+ throw Error("The provided 'type' value is invalid");
537
+ }
538
+ } catch (error) {
539
+ var _this$_options, _this$_options$onEven;
540
+ this === null || this === void 0 || (_this$_options = this._options) === null || _this$_options === void 0 || (_this$_options$onEven = _this$_options.onEventCallback) === null || _this$_options$onEven === void 0 || _this$_options$onEven.call(_this$_options, {
541
+ code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
542
+ message: 'Component initialization exception.'
543
+ });
544
+ this.closeLoading();
545
+ }
546
+ }
547
+
521
548
  // iframe src生成方法
522
549
  }, {
523
550
  key: "createIframeSrc",
@@ -539,6 +566,16 @@ export var ElementComponent = /*#__PURE__*/function () {
539
566
  payment: payment
540
567
  };
541
568
  }
569
+ }, {
570
+ key: "closeLoading",
571
+ value: function closeLoading() {
572
+ var _this$_options$loadin;
573
+ if (this.loading && (_this$_options$loadin = this._options.loading) !== null && _this$_options$loadin !== void 0 && _this$_options$loadin.onEndLoading) {
574
+ var _this$_options$loadin2, _this$_options$loadin3;
575
+ (_this$_options$loadin2 = this._options.loading) === null || _this$_options$loadin2 === void 0 || (_this$_options$loadin3 = _this$_options$loadin2.onEndLoading) === null || _this$_options$loadin3 === void 0 || _this$_options$loadin3.call(_this$_options$loadin2);
576
+ }
577
+ this.loading = false;
578
+ }
542
579
 
543
580
  // 循环给所有iframe发同一个消息
544
581
  // private postCommonMessage<T>(event: ElementPaymentEvent, params: T) {
@@ -573,12 +610,10 @@ export var ElementComponent = /*#__PURE__*/function () {
573
610
  });
574
611
  this.eventService.listen(ElementPaymentEvent.SEND_MUITI_APP_EVENT_TO_SDK, function (result) {
575
612
  var _this6$_options$onEve, _this6$_options;
576
- console.log('demo event callback----', result.data);
577
613
  (_this6$_options$onEve = (_this6$_options = _this6._options).onEventCallback) === null || _this6$_options$onEve === void 0 || _this6$_options$onEve.call(_this6$_options, result.data);
578
614
  });
579
615
  this.eventService.listen(ElementPaymentEvent.CALLBACK, function (result) {
580
616
  var _this6$eventCallback;
581
- console.log('antom sdk 组件事件回调');
582
617
  if ((_this6$eventCallback = _this6.eventCallback) !== null && _this6$eventCallback !== void 0 && (_this6$eventCallback = _this6$eventCallback[result.source]) !== null && _this6$eventCallback !== void 0 && _this6$eventCallback[result.event]) {
583
618
  var _this6$eventCallback$, _this6$eventCallback$2;
584
619
  (_this6$eventCallback$ = (_this6$eventCallback$2 = _this6.eventCallback[result.source])[result.event]) === null || _this6$eventCallback$ === void 0 || _this6$eventCallback$.call(_this6$eventCallback$2, result.data);
@@ -590,9 +625,14 @@ export var ElementComponent = /*#__PURE__*/function () {
590
625
  this.eventService.listen(ConstantEvent.redirect.name, function (data, res) {
591
626
  data.isDestroy && _this6.unmount();
592
627
  });
593
- this.eventService.listen(ElementPaymentEvent.LOG, function (result) {
594
- console.log('antom sdk 组件日志回调');
628
+ this.eventService.listen(ConstantEvent.appHeartBeat.name, function (result) {
629
+ _this6.closeLoading();
595
630
  });
631
+
632
+ // this.eventService.listen(ElementPaymentEvent.LOG, (result: EventCallbackData) => {
633
+ // console.log('antom sdk 组件日志回调');
634
+ // });
635
+
596
636
  this.eventService.listen(ElementPaymentEvent.HANDLE_PAYMENT, function (result) {
597
637
  if ((result === null || result === void 0 ? void 0 : result.paymentMethodType) === 'APPLEPAY') {
598
638
  _this6.ApplePayService.begin().then(function (res) {
@@ -632,15 +672,10 @@ export var ElementComponent = /*#__PURE__*/function () {
632
672
  }, {
633
673
  key: "showIframe",
634
674
  value: function showIframe() {
635
- var _this$paymentBase, _this$addressBase, _this$authBase, _this$_options$loadin;
636
- this.loading = false;
675
+ var _this$paymentBase, _this$addressBase, _this$authBase;
637
676
  (this === null || this === void 0 ? void 0 : this.paymentBase) && (this === null || this === void 0 || (_this$paymentBase = this.paymentBase) === null || _this$paymentBase === void 0 ? void 0 : _this$paymentBase.update());
638
677
  (this === null || this === void 0 ? void 0 : this.addressBase) && (this === null || this === void 0 || (_this$addressBase = this.addressBase) === null || _this$addressBase === void 0 ? void 0 : _this$addressBase.update());
639
678
  (this === null || this === void 0 ? void 0 : this.authBase) && (this === null || this === void 0 || (_this$authBase = this.authBase) === null || _this$authBase === void 0 ? void 0 : _this$authBase.update());
640
- if ((_this$_options$loadin = this._options.loading) !== null && _this$_options$loadin !== void 0 && _this$_options$loadin.onEndLoading) {
641
- var _this$_options$loadin2, _this$_options$loadin3;
642
- (_this$_options$loadin2 = this._options.loading) === null || _this$_options$loadin2 === void 0 || (_this$_options$loadin3 = _this$_options$loadin2.onEndLoading) === null || _this$_options$loadin3 === void 0 || _this$_options$loadin3.call(_this$_options$loadin2);
643
- }
644
679
  }
645
680
  }, {
646
681
  key: "afterInit",
@@ -659,7 +694,7 @@ export var ElementComponent = /*#__PURE__*/function () {
659
694
  var baseData = {
660
695
  originActionQueryResult: this.sdkActionRes,
661
696
  originOneAccountQueryResult: this.oneAccountRes,
662
- paymentSessionData: this._options.sessionData,
697
+ paymentSessionData: this.sessionData,
663
698
  sessionResult: this.parseData || {}
664
699
  };
665
700
  this.launchSource.forEach(function (target) {
@@ -689,6 +724,10 @@ export var ElementComponent = /*#__PURE__*/function () {
689
724
  this.eventService.unlisten(ElementPaymentEvent.CAPTURE_ASSET);
690
725
  this.eventService.unlisten(ElementPaymentEvent.LAUNCH);
691
726
  this.eventService.unlisten(ElementPaymentEvent.SIZE_CHANGE);
727
+ this.eventService.unlisten(ElementPaymentEvent.CALLBACK);
728
+ this.eventService.unlisten(ConstantEvent.close.name);
729
+ this.eventService.unlisten(ConstantEvent.redirect.name);
730
+ this.eventService.unlisten(ConstantEvent.appHeartBeat.name);
692
731
  this.eventService.unlisten(ElementPaymentEvent.HANDLE_PAYMENT);
693
732
  }
694
733
 
@@ -718,6 +757,7 @@ export var ElementComponent = /*#__PURE__*/function () {
718
757
  var url = link.indexOf('?') === -1 ? "".concat(link, "?").concat(params) : link;
719
758
  this.authBase.mount({
720
759
  selector: sdkSelector,
760
+ sessionData: renderOptions.sessionData,
721
761
  url: url
722
762
  }).then(function (result) {
723
763
  if (!result) {
@@ -776,48 +816,55 @@ export var ElementComponent = /*#__PURE__*/function () {
776
816
  }, {
777
817
  key: "mountErrorHandle",
778
818
  value: function mountErrorHandle() {
779
- var _this$_options$onEven2, _this$_options3;
780
- console.log('demo event callback----', {
781
- code: EventCallbackCode.FAILED,
782
- message: 'INTERNAL_FAILED'
783
- });
784
- (_this$_options$onEven2 = (_this$_options3 = this._options).onEventCallback) === null || _this$_options$onEven2 === void 0 || _this$_options$onEven2.call(_this$_options3, {
785
- code: EventCallbackCode.FAILED,
786
- message: 'INTERNAL_FAILED'
819
+ var _this$_options3, _this$_options3$onEve;
820
+ this === null || this === void 0 || (_this$_options3 = this._options) === null || _this$_options3 === void 0 || (_this$_options3$onEve = _this$_options3.onEventCallback) === null || _this$_options3$onEve === void 0 || _this$_options3$onEve.call(_this$_options3, {
821
+ code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
822
+ message: 'Component initialization exception.'
787
823
  });
824
+ this.closeLoading();
788
825
  logger.logError({
789
- title: 'a3753.b101271.c386691'
826
+ title: 'sdk_element_mount_fail'
790
827
  });
828
+ this.resetState();
791
829
  }
792
830
  }, {
793
831
  key: "mount",
794
832
  value: function mount(renderOptions, sdkSelector) {
795
- logger.logInfo({
796
- title: 'a3753.b101271.c386690'
797
- });
833
+ // 当前type element已加载 / 加载中
834
+ if (this.iframes[MountElementType[renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.type]] || this.loadingElement.includes(renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.type)) {
835
+ throw Error('The component has been mounted, please do not execute it again.');
836
+ }
798
837
  if (typeof sdkSelector === 'string') {
799
838
  var _this$_options$loadin4, _renderOptions$debugP, _renderOptions$debugP2;
800
839
  var element = document.querySelector(sdkSelector);
840
+ // 容器是否存在
801
841
  if (!element) {
802
- return this.mountErrorHandle();
842
+ throw Error('Loading failed, you need to check if the element exists.');
803
843
  }
804
- this.componentsCount = this.componentsCount + 1;
805
- if (!this.loading && (_this$_options$loadin4 = this._options.loading) !== null && _this$_options$loadin4 !== void 0 && _this$_options$loadin4.onStartLoading && this.isConnect) {
844
+ // 生成sdk,同时判断 type 是否合规,不合规会直接报错
845
+ this.createComponentSdk(renderOptions.type);
846
+ this.beforeMount(renderOptions.sessionData);
847
+ this.loadingElement.push(renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.type);
848
+ logger.logInfo({
849
+ title: 'sdk_element_mount_start'
850
+ });
851
+ if (!this.loading && (_this$_options$loadin4 = this._options.loading) !== null && _this$_options$loadin4 !== void 0 && _this$_options$loadin4.onStartLoading) {
806
852
  var _this$_options$loadin5, _this$_options$loadin6;
807
853
  (_this$_options$loadin5 = this._options.loading) === null || _this$_options$loadin5 === void 0 || (_this$_options$loadin6 = _this$_options$loadin5.onStartLoading) === null || _this$_options$loadin6 === void 0 || _this$_options$loadin6.call(_this$_options$loadin5);
808
854
  }
855
+ this.loading = true;
856
+ this.componentsCount = this.componentsCount + 1;
809
857
  var elementLink = renderOptions !== null && renderOptions !== void 0 && (_renderOptions$debugP = renderOptions.debugProps) !== null && _renderOptions$debugP !== void 0 && _renderOptions$debugP.localLink ? renderOptions === null || renderOptions === void 0 || (_renderOptions$debugP2 = renderOptions.debugProps) === null || _renderOptions$debugP2 === void 0 ? void 0 : _renderOptions$debugP2.localLink : this.iframeSrc[renderOptions.type];
810
858
  renderOptions.elementProps = {
811
859
  elementLink: elementLink
812
860
  };
813
- this.loading = true;
814
- if (renderOptions.type === 'auth') {
861
+ if (renderOptions.type === ElementType.auth) {
815
862
  return this.mountAuth(renderOptions, sdkSelector);
816
863
  }
817
- if (renderOptions.type === 'address') {
864
+ if (renderOptions.type === ElementType.address) {
818
865
  return this.mountAddress(renderOptions, sdkSelector);
819
866
  }
820
- if (renderOptions.type === 'payment') {
867
+ if (renderOptions.type === ElementType.payment) {
821
868
  return this.mountPayment(renderOptions, sdkSelector);
822
869
  }
823
870
  } else {
@@ -826,56 +873,74 @@ export var ElementComponent = /*#__PURE__*/function () {
826
873
  }
827
874
 
828
875
  // 注销单个iframe,暂时没有用到
829
- }, {
830
- key: "removeIframe",
831
- value: function removeIframe(sdk) {
832
- if (sdk && this.launchSource.some(function (source) {
833
- return source === sdk;
834
- })) {
835
- this.launchSource = this.launchSource.filter(function (source) {
836
- return source !== sdk;
837
- });
838
- this.componentsCount = this.componentsCount - 1;
839
- this.eventService.removeIFrame(this.iframes[sdk]);
840
- }
841
- }
876
+ // private removeIframe(sdk: ElementPaymentMethod) {
877
+ // if (sdk && this.launchSource.some((source) => source === sdk)) {
878
+ // this.launchSource = this.launchSource.filter((source) => source !== sdk);
879
+ // this.componentsCount = this.componentsCount - 1;
880
+ // this.eventService.removeIFrame(this.iframes[sdk]);
881
+ // }
882
+ // }
842
883
 
843
884
  // 暴露出去的注销组件方法
844
885
  }, {
845
- key: "unmount",
846
- value: function unmount() {
886
+ key: "resetState",
887
+ value: function resetState() {
847
888
  var _this$authBase2, _this$authBase2$unmou, _this$addressBase2, _this$addressBase2$un, _this$paymentBase2, _this$paymentBase2$un;
848
889
  (_this$authBase2 = this.authBase) === null || _this$authBase2 === void 0 || (_this$authBase2$unmou = _this$authBase2.unmount) === null || _this$authBase2$unmou === void 0 || _this$authBase2$unmou.call(_this$authBase2);
849
890
  (_this$addressBase2 = this.addressBase) === null || _this$addressBase2 === void 0 || (_this$addressBase2$un = _this$addressBase2.unmount) === null || _this$addressBase2$un === void 0 || _this$addressBase2$un.call(_this$addressBase2);
850
891
  (_this$paymentBase2 = this.paymentBase) === null || _this$paymentBase2 === void 0 || (_this$paymentBase2$un = _this$paymentBase2.unmount) === null || _this$paymentBase2$un === void 0 || _this$paymentBase2$un.call(_this$paymentBase2);
851
892
  this.launchSource = [];
893
+ this.iframes = {};
852
894
  this.componentsCount = 0;
853
895
  this.eventService.destroy();
854
896
  this.removeListener();
897
+ this.loadingElement = [];
898
+ this.initCompleted = false;
899
+ }
900
+ }, {
901
+ key: "unmount",
902
+ value: function unmount() {
903
+ if (!this.iframes.PAYMENT_ELEMENT) {
904
+ throw Error('Component is not mounted. You need to check if the mount method has been successfully called to mount the component.');
905
+ }
906
+ // popup未注册会报错,但element不需要感知popup是否被注册
907
+ try {
908
+ destroyModal(); // 关闭popup弹窗
909
+ } catch (error) {}
910
+ this.resetState();
855
911
  }
856
912
  }, {
857
913
  key: "submitPayment",
858
914
  value: // 暴露出去的submit方法
859
915
  function () {
860
916
  var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
861
- var _this$_options$loadin7, _this$_options$loadin10;
862
- var _this$_options$loadin8, _this$_options$loadin9, _this$_options$loadin11, _this$_options$loadin12;
917
+ var _this$_options$loadin7;
918
+ var _this$_options$loadin8, _this$_options$loadin9;
863
919
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
864
920
  while (1) switch (_context3.prev = _context3.next) {
865
921
  case 0:
866
- // this.onAfterSubmitFunc(ElementPaymentMethod.PAYMENT_ELEMENT, submitResult);
867
- // return
922
+ if (this.iframes.PAYMENT_ELEMENT) {
923
+ _context3.next = 2;
924
+ break;
925
+ }
926
+ throw Error('Component is not mounted. You need to check if the mount method has been successfully called to mount the component.');
927
+ case 2:
928
+ if (!this.loading) {
929
+ _context3.next = 4;
930
+ break;
931
+ }
932
+ throw Error('The form is submitted repeatedly. without the need to click submit repeatedly.');
933
+ case 4:
868
934
  if ((_this$_options$loadin7 = this._options.loading) !== null && _this$_options$loadin7 !== void 0 && _this$_options$loadin7.onStartLoading) {
869
935
  (_this$_options$loadin8 = this._options.loading) === null || _this$_options$loadin8 === void 0 || (_this$_options$loadin9 = _this$_options$loadin8.onStartLoading) === null || _this$_options$loadin9 === void 0 || _this$_options$loadin9.call(_this$_options$loadin8);
870
936
  }
871
- _context3.next = 3;
937
+ this.loading = true;
938
+ _context3.next = 8;
872
939
  return this.validatePromiseFuncs();
873
- case 3:
874
- if ((_this$_options$loadin10 = this._options.loading) !== null && _this$_options$loadin10 !== void 0 && _this$_options$loadin10.onEndLoading) {
875
- (_this$_options$loadin11 = this._options.loading) === null || _this$_options$loadin11 === void 0 || (_this$_options$loadin12 = _this$_options$loadin11.onEndLoading) === null || _this$_options$loadin12 === void 0 || _this$_options$loadin12.call(_this$_options$loadin11);
876
- }
940
+ case 8:
941
+ this.closeLoading();
877
942
  return _context3.abrupt("return");
878
- case 5:
943
+ case 10:
879
944
  case "end":
880
945
  return _context3.stop();
881
946
  }