@alipay/ams-checkout 0.0.1726046231-dev.0 → 0.0.1726046231-dev.10

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.
@@ -22,7 +22,7 @@ import { parseSessionData } from "../index";
22
22
  import { ElementAddressComponent } from "./components/address";
23
23
  import { ElementAuthComponent } from "./components/auth";
24
24
  import { ElementPaymentComponent } from "./components/payment";
25
- import { addressTheme } from "./type";
25
+ import { addressTheme, ThemeType, ELEMENT_ENVIRONMENT } from "./type";
26
26
  var ElementProcessor = /*#__PURE__*/function () {
27
27
  function ElementProcessor() {
28
28
  _classCallCheck(this, ElementProcessor);
@@ -76,6 +76,8 @@ export var ElementComponent = /*#__PURE__*/function () {
76
76
  // one account接口返回
77
77
  _defineProperty(this, "launchSource", void 0);
78
78
  // launch 来源记录
79
+ _defineProperty(this, "iframeSrc", void 0);
80
+ // iframe src记录
79
81
  _defineProperty(this, "mountOptions", void 0);
80
82
  // 组件mount配置记录
81
83
  _defineProperty(this, "iframes", void 0);
@@ -105,6 +107,14 @@ export var ElementComponent = /*#__PURE__*/function () {
105
107
  selector: sdkSelector,
106
108
  debugProps: renderOptions.debugProps
107
109
  }).then(function (result) {
110
+ if (!result) {
111
+ var _this$_options$onEven, _this$_options;
112
+ (_this$_options$onEven = (_this$_options = _this._options).onEventCallback) === null || _this$_options$onEven === void 0 || _this$_options$onEven.call(_this$_options, {
113
+ code: EventCallbackCode.Failed,
114
+ message: 'Component loading failed'
115
+ });
116
+ return undefined;
117
+ }
108
118
  _this.eventService.addIFrame(result);
109
119
  _this.iframes[ElementPaymentMethod.ADDRESS_ELEMENT] = result;
110
120
  });
@@ -121,6 +131,14 @@ export var ElementComponent = /*#__PURE__*/function () {
121
131
  selector: sdkSelector,
122
132
  debugProps: renderOptions.debugProps
123
133
  }).then(function (result) {
134
+ if (!result) {
135
+ var _this$_options$onEven2, _this$_options2;
136
+ (_this$_options$onEven2 = (_this$_options2 = _this._options).onEventCallback) === null || _this$_options$onEven2 === void 0 || _this$_options$onEven2.call(_this$_options2, {
137
+ code: EventCallbackCode.Failed,
138
+ message: 'Component loading failed'
139
+ });
140
+ return undefined;
141
+ }
124
142
  _this.eventService.addIFrame(result);
125
143
  _this.iframes[ElementPaymentMethod.PAYMENT_ELEMENT] = result;
126
144
  });
@@ -184,6 +202,8 @@ export var ElementComponent = /*#__PURE__*/function () {
184
202
  envInfo: {
185
203
  locale: _this._options.locale
186
204
  },
205
+ timeout: 300000,
206
+ // TODO dev环境submit提交接口超时
187
207
  'Operation-Type': 'com.ipay.iexpcashier.cashier.submitPayByPaymentSession'
188
208
  }).then(function (result) {
189
209
  console.log('element submit result ------', result);
@@ -285,24 +305,116 @@ export var ElementComponent = /*#__PURE__*/function () {
285
305
  this.mountOptions = {};
286
306
  this.createElement();
287
307
  }
308
+
309
+ // 初始化注册
288
310
  _createClass(ElementComponent, [{
311
+ key: "createElement",
312
+ value: function createElement() {
313
+ var _this2 = this;
314
+ var _parseSessionData = parseSessionData(this._options.sessionData),
315
+ _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
316
+ parseData = _parseSessionData2[0],
317
+ sessionData = _parseSessionData2[1];
318
+ this.parseData = parseData;
319
+ this.sessionData = sessionData;
320
+ this.elementContainer = new AntomSDKCore();
321
+ this.elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', new ElementProcessor());
322
+ this.elementContainer.init({}, ProductSceneEnum.ELEMENT_PAYMENT);
323
+ this.elementContainer.startBizFlow({
324
+ paymentSession: this._options.sessionData
325
+ }).then(function (res) {
326
+ // 请求消息
327
+ Promise.all([_this2.oneAccountQuery(), _this2.sdkActionQuery()]).then(function (result) {
328
+ _this2.oneAccountRes = result[0];
329
+ _this2.sdkActionRes = result[1];
330
+ _this2.sendRenderData();
331
+ });
332
+
333
+ // 本地mock测试数据
334
+ // setTimeout(() => {
335
+ // this.oneAccountRes = oneAccount;
336
+ // this.sdkActionRes = sdkAction;
337
+ // this.sendRenderData();
338
+ // }, 500);
339
+ });
340
+ this.iframeSrc = this.createIframeSrc(this._options.environment, this._options.version);
341
+
342
+ // 注册 auth 邮箱模块
343
+ try {
344
+ this.authBase = new ElementAuthComponent();
345
+ this.authBase.create({
346
+ environment: this._options.environment,
347
+ locale: this._options.locale
348
+ });
349
+ var serviceProvider = this.elementContainer.getServiceProvider();
350
+ this.eventService = serviceProvider.getService('EventCenter');
351
+ this.requestService = serviceProvider.getService('Requester');
352
+ // 注册 payment 卡支付模块
353
+ this.paymentBase = new ElementPaymentComponent();
354
+ this.paymentBase.create({
355
+ environment: this._options.environment,
356
+ locale: this._options.locale,
357
+ appVersion: this._options.version || ''
358
+ });
359
+
360
+ // 注册 address 地址模块
361
+ this.addressBase = new ElementAddressComponent();
362
+ this.addressBase.create({
363
+ environment: this._options.environment,
364
+ locale: this._options.locale,
365
+ appVersion: this._options.version || ''
366
+ });
367
+ } catch (error) {
368
+ var _this$_options$onEven3, _this$_options3;
369
+ (_this$_options$onEven3 = (_this$_options3 = this._options).onEventCallback) === null || _this$_options$onEven3 === void 0 || _this$_options$onEven3.call(_this$_options3, {
370
+ code: EventCallbackCode.Failed,
371
+ message: 'create sdk fail'
372
+ });
373
+ }
374
+
375
+ // 注册监听消息
376
+ this.addListener();
377
+ }
378
+ }, {
379
+ key: "createIframeSrc",
380
+ value: function createIframeSrc() {
381
+ var env = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ELEMENT_ENVIRONMENT.DEV;
382
+ var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1.23.0';
383
+ var baseUrl = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ELEMENT_ENVIRONMENT.DEV, 'http://dev.page.alipay.net/page/antom-web-checkout-v2'), ELEMENT_ENVIRONMENT.TEST, 'http://page.test.alipay.net/page/antom-web-checkout-v2'), ELEMENT_ENVIRONMENT.PRE, 'https://cdn-pre.marmot-cloud.com/page/antom-web-checkout-v2'), ELEMENT_ENVIRONMENT.PROD, 'https://checkout.antom.com');
384
+ var _env = (env === null || env === void 0 ? void 0 : env.toLocaleUpperCase()) || ELEMENT_ENVIRONMENT.DEV;
385
+ return {
386
+ auth: "".concat(baseUrl[_env], "/auth-element/").concat(version, "/pages/element_auth/index.html"),
387
+ address: "".concat(baseUrl[_env], "/element-address/").concat(version, "/pages/address/index.html"),
388
+ payment: "".concat(baseUrl[_env], "/elements/").concat(version, "/pages/element_payment/index.html")
389
+ };
390
+ }
391
+ }, {
289
392
  key: "sdkActionQuery",
290
393
  value: function sdkActionQuery() {
291
- var _this2 = this;
394
+ var _this3 = this;
292
395
  return new Promise(function (resolve) {
293
- var paymentSessionConfig = _this2.parseData.paymentSessionConfig;
294
- var hostSign = _this2.sessionData.split('&&')[1] || '';
295
- _this2.requestService.request({
396
+ var paymentSessionConfig = _this3.parseData.paymentSessionConfig;
397
+ var hostSign = _this3.sessionData.split('&&')[1] || '';
398
+ _this3.requestService.request({
296
399
  paymentSessionConfig: paymentSessionConfig,
297
- paymentSessionData: _this2.sessionData
400
+ paymentSessionData: _this3.sessionData
298
401
  }, {
299
- env: _this2._options.environment,
402
+ env: _this3._options.environment,
300
403
  envInfo: {
301
- locale: _this2._options.locale
404
+ locale: _this3._options.locale
302
405
  },
303
406
  hostSign: hostSign,
407
+ timeout: 300000,
408
+ // TODO dev环境接口超时
304
409
  'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query'
305
410
  }).then(function (result) {
411
+ if (!result.success) {
412
+ var _this3$_options$onEve, _this3$_options;
413
+ (_this3$_options$onEve = (_this3$_options = _this3._options).onEventCallback) === null || _this3$_options$onEve === void 0 || _this3$_options$onEve.call(_this3$_options, {
414
+ code: EventCallbackCode.Failed,
415
+ message: 'sdkAction.query Request Error'
416
+ });
417
+ }
306
418
  resolve(result);
307
419
  });
308
420
  });
@@ -310,21 +422,23 @@ export var ElementComponent = /*#__PURE__*/function () {
310
422
  }, {
311
423
  key: "oneAccountQuery",
312
424
  value: function oneAccountQuery() {
313
- var _this3 = this;
425
+ var _this4 = this;
314
426
  return new Promise(function (resolve) {
315
- var paymentSessionConfig = _this3.parseData.paymentSessionConfig;
316
- _this3.requestService.request({
427
+ var paymentSessionConfig = _this4.parseData.paymentSessionConfig;
428
+ _this4.requestService.request({
317
429
  paymentSessionConfig: paymentSessionConfig,
318
- paymentSessionData: _this3.sessionData,
430
+ paymentSessionData: _this4.sessionData,
319
431
  accountInfo: {
320
432
  email: ''
321
433
  }
322
434
  // oneAccountId: '',
323
435
  }, {
324
- env: _this3._options.environment,
436
+ env: _this4._options.environment,
325
437
  envInfo: {
326
- locale: _this3._options.locale
438
+ locale: _this4._options.locale
327
439
  },
440
+ timeout: 300000,
441
+ // TODO dev环境接口超时
328
442
  'Operation-Type': 'com.ipay.iexpfront.one.account.query'
329
443
  }).then(function (result) {
330
444
  resolve(result);
@@ -332,12 +446,65 @@ export var ElementComponent = /*#__PURE__*/function () {
332
446
  });
333
447
  }
334
448
 
335
- // 发送初始化数据
449
+ // private postCommonMessage<T>(event: ElementPaymentEvent, params: T) {
450
+ // for (let index = 0; index < this.launchSource.length; index++) {
451
+ // this.eventService.emitAndListen(
452
+ // {
453
+ // event: event,
454
+ // data: {
455
+ // source: ElementPaymentMethod.CONTAINER_ELEMENT,
456
+ // target: this.launchSource[0],
457
+ // params: params,
458
+ // },
459
+ // },
460
+ // () => {},
461
+ // )
462
+ // }
463
+ // }
464
+
465
+ // 监听sdk消息
466
+ }, {
467
+ key: "addListener",
468
+ value: function addListener() {
469
+ var _this5 = this;
470
+ this.eventService.listen(ElementPaymentEvent.SIGN_OUT, function (result) {
471
+ // const { source, target } = result;
472
+ // if (source === ElementPaymentMethod.AUTH_ELEMENT && target === ElementPaymentMethod.CONTAINER_ELEMENT) {
473
+ // // 给mount出来的每个sdk都发送消息
474
+ // this.postCommonMessage(ElementPaymentEvent.SIGN_OUT, {});
475
+ // }
476
+ });
477
+ this.eventService.listen(ElementPaymentEvent.CAPTURE_ASSET, function (result) {
478
+ // const { source, target } = result;
479
+ // if (source === ElementPaymentMethod.AUTH_ELEMENT && target === ElementPaymentMethod.CONTAINER_ELEMENT) {
480
+ // console.log('antom sdk event chang email 给address和payment下发新的数据---------', result);
481
+ // this.postCommonMessage(ElementPaymentEvent.CAPTURE_ASSET, result.data);
482
+ // }
483
+ });
484
+ this.eventService.listen(ElementPaymentEvent.LAUNCH, function (result) {
485
+ _this5.launchFunc(result);
486
+ });
487
+ this.eventService.listen(ElementPaymentEvent.SIZE_CHANGE, function (result) {
488
+ if (result.target === ElementPaymentMethod.CONTAINER_ELEMENT && result.source === ElementPaymentMethod.AUTH_ELEMENT) {
489
+ var _this5$authBase;
490
+ (_this5 === null || _this5 === void 0 ? void 0 : _this5.authBase) && (_this5 === null || _this5 === void 0 || (_this5$authBase = _this5.authBase) === null || _this5$authBase === void 0 ? void 0 : _this5$authBase.update(result.data.height));
491
+ }
492
+ });
493
+ this.eventService.listen(ElementPaymentEvent.CALLBACK, function (result) {
494
+ var _this5$eventCallback;
495
+ if ((_this5$eventCallback = _this5.eventCallback) !== null && _this5$eventCallback !== void 0 && (_this5$eventCallback = _this5$eventCallback[result.source]) !== null && _this5$eventCallback !== void 0 && _this5$eventCallback[result.event]) {
496
+ var _this5$eventCallback$, _this5$eventCallback$2;
497
+ (_this5$eventCallback$ = (_this5$eventCallback$2 = _this5.eventCallback[result.source])[result.event]) === null || _this5$eventCallback$ === void 0 || _this5$eventCallback$.call(_this5$eventCallback$2, result.data);
498
+ }
499
+ });
500
+ }
336
501
  }, {
337
502
  key: "sendRenderData",
338
- value: function sendRenderData() {
503
+ value:
504
+ // 发送初始化数据
505
+ function sendRenderData() {
339
506
  if (this.launchSource.length === this.componentsCount && this.sdkActionRes && this.oneAccountRes) {
340
- var _this$_options$loadin, _this$mountOptions, _this$mountOptions2, _this$mountOptions3, _this$paymentBase, _this$addressBase, _this$authBase;
507
+ var _this$_options$loadin, _this$mountOptions, _this$_options4, _this$mountOptions2, _this$_options5, _this$mountOptions3, _this$mountOptions4, _this$_options6, _this$paymentBase, _this$addressBase, _this$authBase;
341
508
  var baseData = {
342
509
  originActionQueryResult: this.sdkActionRes,
343
510
  originOneAccountQueryResult: this.oneAccountRes,
@@ -356,7 +523,9 @@ export var ElementComponent = /*#__PURE__*/function () {
356
523
  source: ElementPaymentMethod.CONTAINER_ELEMENT,
357
524
  params: _objectSpread({
358
525
  queryResult: this.sdkActionRes,
359
- appearance: (_this$mountOptions = this.mountOptions) === null || _this$mountOptions === void 0 || (_this$mountOptions = _this$mountOptions[ElementPaymentMethod.PAYMENT_ELEMENT]) === null || _this$mountOptions === void 0 ? void 0 : _this$mountOptions.appearance
526
+ appearance: ((_this$mountOptions = this.mountOptions) === null || _this$mountOptions === void 0 || (_this$mountOptions = _this$mountOptions[ElementPaymentMethod.PAYMENT_ELEMENT]) === null || _this$mountOptions === void 0 ? void 0 : _this$mountOptions.appearance) || ((_this$_options4 = this._options) === null || _this$_options4 === void 0 ? void 0 : _this$_options4.appearance) || {
527
+ theme: ThemeType.Default
528
+ }
360
529
  }, baseData)
361
530
  }
362
531
  }, function () {});
@@ -366,18 +535,16 @@ export var ElementComponent = /*#__PURE__*/function () {
366
535
  target: ElementPaymentMethod.ADDRESS_ELEMENT,
367
536
  source: ElementPaymentMethod.CONTAINER_ELEMENT,
368
537
  params: _objectSpread({
369
- prefillValue: this.oneAccountRes.shippings || [{
370
- shippingAddress: {
371
- region: ''
372
- }
373
- }],
538
+ prefillValue: this.oneAccountRes.shippings || [],
374
539
  appearance: {
375
- themeType: addressTheme[((_this$mountOptions2 = this.mountOptions) === null || _this$mountOptions2 === void 0 || (_this$mountOptions2 = _this$mountOptions2[ElementPaymentMethod.ADDRESS_ELEMENT]) === null || _this$mountOptions2 === void 0 || (_this$mountOptions2 = _this$mountOptions2.appearance) === null || _this$mountOptions2 === void 0 ? void 0 : _this$mountOptions2.theme) || 'light']
540
+ themeType: addressTheme[((_this$mountOptions2 = this.mountOptions) === null || _this$mountOptions2 === void 0 || (_this$mountOptions2 = _this$mountOptions2[ElementPaymentMethod.ADDRESS_ELEMENT]) === null || _this$mountOptions2 === void 0 || (_this$mountOptions2 = _this$mountOptions2.appearance) === null || _this$mountOptions2 === void 0 ? void 0 : _this$mountOptions2.theme) || ((_this$_options5 = this._options) === null || _this$_options5 === void 0 || (_this$_options5 = _this$_options5.appearance) === null || _this$_options5 === void 0 ? void 0 : _this$_options5.theme) || ThemeType.Default]
376
541
  },
377
- configParams: {
542
+ configParams: _objectSpread({
378
543
  needEditBackBtn: true,
379
- autoSaveAsDefaultAddress: true
380
- }
544
+ autoSaveAsDefaultAddress: true,
545
+ editingNeedShippingQuery: true,
546
+ showTitle: true
547
+ }, (_this$mountOptions3 = this.mountOptions) === null || _this$mountOptions3 === void 0 ? void 0 : _this$mountOptions3[ElementPaymentMethod.ADDRESS_ELEMENT])
381
548
  }, baseData)
382
549
  }
383
550
  }, function () {});
@@ -387,7 +554,9 @@ export var ElementComponent = /*#__PURE__*/function () {
387
554
  target: ElementPaymentMethod.AUTH_ELEMENT,
388
555
  source: ElementPaymentMethod.CONTAINER_ELEMENT,
389
556
  params: _objectSpread(_objectSpread({}, baseData), {}, {
390
- appearance: (_this$mountOptions3 = this.mountOptions) === null || _this$mountOptions3 === void 0 || (_this$mountOptions3 = _this$mountOptions3[ElementPaymentMethod.AUTH_ELEMENT]) === null || _this$mountOptions3 === void 0 ? void 0 : _this$mountOptions3.appearance
557
+ appearance: ((_this$mountOptions4 = this.mountOptions) === null || _this$mountOptions4 === void 0 || (_this$mountOptions4 = _this$mountOptions4[ElementPaymentMethod.AUTH_ELEMENT]) === null || _this$mountOptions4 === void 0 ? void 0 : _this$mountOptions4.appearance) || ((_this$_options6 = this._options) === null || _this$_options6 === void 0 ? void 0 : _this$_options6.appearance) || {
558
+ theme: ThemeType.Default
559
+ }
391
560
  })
392
561
  }
393
562
  }, function () {});
@@ -396,59 +565,6 @@ export var ElementComponent = /*#__PURE__*/function () {
396
565
  (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());
397
566
  }
398
567
  }
399
-
400
- // private postCommonMessage<T>(event: ElementPaymentEvent, params: T) {
401
- // for (let index = 0; index < this.launchSource.length; index++) {
402
- // this.eventService.emitAndListen(
403
- // {
404
- // event: event,
405
- // data: {
406
- // source: ElementPaymentMethod.CONTAINER_ELEMENT,
407
- // target: this.launchSource[0],
408
- // params: params,
409
- // },
410
- // },
411
- // () => {},
412
- // )
413
- // }
414
- // }
415
-
416
- // 监听sdk消息
417
- }, {
418
- key: "addListener",
419
- value: function addListener() {
420
- var _this4 = this;
421
- this.eventService.listen(ElementPaymentEvent.SIGN_OUT, function (result) {
422
- // const { source, target } = result;
423
- // if (source === ElementPaymentMethod.AUTH_ELEMENT && target === ElementPaymentMethod.CONTAINER_ELEMENT) {
424
- // // 给mount出来的每个sdk都发送消息
425
- // this.postCommonMessage(ElementPaymentEvent.SIGN_OUT, {});
426
- // }
427
- });
428
- this.eventService.listen(ElementPaymentEvent.CAPTURE_ASSET, function (result) {
429
- // const { source, target } = result;
430
- // if (source === ElementPaymentMethod.AUTH_ELEMENT && target === ElementPaymentMethod.CONTAINER_ELEMENT) {
431
- // console.log('antom sdk event chang email 给address和payment下发新的数据---------', result);
432
- // this.postCommonMessage(ElementPaymentEvent.CAPTURE_ASSET, result.data);
433
- // }
434
- });
435
- this.eventService.listen(ElementPaymentEvent.LAUNCH, function (result) {
436
- _this4.launchFunc(result);
437
- });
438
- this.eventService.listen(ElementPaymentEvent.SIZE_CHANGE, function (result) {
439
- if (result.target === ElementPaymentMethod.CONTAINER_ELEMENT && result.source === ElementPaymentMethod.AUTH_ELEMENT) {
440
- var _this4$authBase;
441
- (_this4 === null || _this4 === void 0 ? void 0 : _this4.authBase) && (_this4 === null || _this4 === void 0 || (_this4$authBase = _this4.authBase) === null || _this4$authBase === void 0 ? void 0 : _this4$authBase.update(result.data.height));
442
- }
443
- });
444
- this.eventService.listen(ElementPaymentEvent.CALLBACK, function (result) {
445
- var _this4$eventCallback;
446
- if ((_this4$eventCallback = _this4.eventCallback) !== null && _this4$eventCallback !== void 0 && (_this4$eventCallback = _this4$eventCallback[result.source]) !== null && _this4$eventCallback !== void 0 && _this4$eventCallback[result.event]) {
447
- var _this4$eventCallback$, _this4$eventCallback$2;
448
- (_this4$eventCallback$ = (_this4$eventCallback$2 = _this4.eventCallback[result.source])[result.event]) === null || _this4$eventCallback$ === void 0 || _this4$eventCallback$.call(_this4$eventCallback$2, result.data);
449
- }
450
- });
451
- }
452
568
  }, {
453
569
  key: "removeListener",
454
570
  value: function removeListener() {
@@ -457,65 +573,6 @@ export var ElementComponent = /*#__PURE__*/function () {
457
573
  this.eventService.unlisten(ElementPaymentEvent.LAUNCH);
458
574
  this.eventService.unlisten(ElementPaymentEvent.SIZE_CHANGE);
459
575
  }
460
-
461
- // 初始化注册
462
- }, {
463
- key: "createElement",
464
- value: function createElement() {
465
- var _this5 = this;
466
- var _parseSessionData = parseSessionData(this._options.sessionData),
467
- _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
468
- parseData = _parseSessionData2[0],
469
- sessionData = _parseSessionData2[1];
470
- this.parseData = parseData;
471
- this.sessionData = sessionData;
472
- this.elementContainer = new AntomSDKCore();
473
- this.elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', new ElementProcessor());
474
- this.elementContainer.init({}, ProductSceneEnum.ELEMENT_PAYMENT);
475
- this.elementContainer.startBizFlow({
476
- paymentSession: this._options.sessionData
477
- }).then(function (res) {
478
- // 请求消息
479
- Promise.all([_this5.oneAccountQuery(), _this5.sdkActionQuery()]).then(function (result) {
480
- _this5.oneAccountRes = result[0];
481
- _this5.sdkActionRes = result[1];
482
- _this5.sendRenderData();
483
- });
484
-
485
- // 本地mock测试数据
486
- // setTimeout(() => {
487
- // this.oneAccountRes = oneAccount;
488
- // this.sdkActionRes = sdkAction;
489
- // this.sendRenderData();
490
- // }, 500);
491
- });
492
-
493
- // 注册 auth 邮箱模块
494
- this.authBase = new ElementAuthComponent();
495
- this.authBase.create({
496
- environment: this._options.environment,
497
- locale: this._options.locale
498
- });
499
- var serviceProvider = this.elementContainer.getServiceProvider();
500
- this.eventService = serviceProvider.getService('EventCenter');
501
- this.requestService = serviceProvider.getService('Requester');
502
- // 注册 payment 卡支付模块
503
- this.paymentBase = new ElementPaymentComponent();
504
- this.paymentBase.create({
505
- environment: this._options.environment,
506
- locale: this._options.locale
507
- });
508
-
509
- // 注册 address 地址模块
510
- this.addressBase = new ElementAddressComponent();
511
- this.addressBase.create({
512
- environment: this._options.environment,
513
- locale: this._options.locale
514
- });
515
-
516
- // 注册监听消息
517
- this.addListener();
518
- }
519
576
  }, {
520
577
  key: "registerEventListener",
521
578
  value: function registerEventListener(source, event, callback) {
@@ -530,10 +587,21 @@ export var ElementComponent = /*#__PURE__*/function () {
530
587
  _this6 = this;
531
588
  this.mountOptions[ElementPaymentMethod.AUTH_ELEMENT] = renderOptions;
532
589
  var _selector = sdkSelector.indexOf('#') === 0 ? sdkSelector.slice(1) : sdkSelector;
590
+ var link = renderOptions === null || renderOptions === void 0 || (_renderOptions$debugP = renderOptions.debugProps) === null || _renderOptions$debugP === void 0 ? void 0 : _renderOptions$debugP.localLink;
591
+ var params = window.location.href.split('?')[1];
592
+ var url = link.indexOf('?') === -1 ? "".concat(link, "?").concat(params) : link;
533
593
  this.authBase.mount({
534
594
  selector: _selector,
535
- url: renderOptions === null || renderOptions === void 0 || (_renderOptions$debugP = renderOptions.debugProps) === null || _renderOptions$debugP === void 0 ? void 0 : _renderOptions$debugP.localLink
595
+ url: url
536
596
  }).then(function (result) {
597
+ if (!result) {
598
+ var _this6$_options$onEve, _this6$_options;
599
+ (_this6$_options$onEve = (_this6$_options = _this6._options).onEventCallback) === null || _this6$_options$onEve === void 0 || _this6$_options$onEve.call(_this6$_options, {
600
+ code: EventCallbackCode.Failed,
601
+ message: 'Component loading failed'
602
+ });
603
+ return undefined;
604
+ }
537
605
  _this6.eventService.addIFrame(result);
538
606
  _this6.iframes[ElementPaymentMethod.AUTH_ELEMENT] = result;
539
607
  });
@@ -548,11 +616,11 @@ export var ElementComponent = /*#__PURE__*/function () {
548
616
  key: "mount",
549
617
  value: function mount(renderOptions, sdkSelector) {
550
618
  if (typeof sdkSelector === 'string') {
551
- var _this$_options$loadin4;
619
+ var _this$_options$loadin4, _renderOptions$debugP2;
552
620
  var element = document.querySelector(sdkSelector);
553
621
  if (!element) {
554
- var _this$_options$onEven, _this$_options;
555
- (_this$_options$onEven = (_this$_options = this._options).onEventCallback) === null || _this$_options$onEven === void 0 || _this$_options$onEven.call(_this$_options, {
622
+ var _this$_options$onEven4, _this$_options7;
623
+ (_this$_options$onEven4 = (_this$_options7 = this._options).onEventCallback) === null || _this$_options$onEven4 === void 0 || _this$_options$onEven4.call(_this$_options7, {
556
624
  code: EventCallbackCode.Failed,
557
625
  message: 'Unable to obtain selector'
558
626
  });
@@ -563,8 +631,13 @@ export var ElementComponent = /*#__PURE__*/function () {
563
631
  var _this$_options$loadin5, _this$_options$loadin6;
564
632
  (_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);
565
633
  }
634
+ if (!(renderOptions !== null && renderOptions !== void 0 && (_renderOptions$debugP2 = renderOptions.debugProps) !== null && _renderOptions$debugP2 !== void 0 && _renderOptions$debugP2.localLink)) {
635
+ renderOptions.debugProps = {
636
+ localLink: this.iframeSrc[renderOptions.type]
637
+ };
638
+ }
566
639
  this.loading = true;
567
- if (renderOptions.type === 'linkAuthentication') {
640
+ if (renderOptions.type === 'auth') {
568
641
  return this.mountAuth(renderOptions, sdkSelector);
569
642
  }
570
643
  if (renderOptions.type === 'address') {
@@ -597,9 +670,10 @@ export var ElementComponent = /*#__PURE__*/function () {
597
670
  }, {
598
671
  key: "unmount",
599
672
  value: function unmount() {
600
- this.authBase.unmount();
601
- this.addressBase.unmount();
602
- this.paymentBase.unmount();
673
+ var _this$authBase2, _this$authBase2$unmou, _this$addressBase2, _this$addressBase2$un, _this$paymentBase2, _this$paymentBase2$un;
674
+ (_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);
675
+ (_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);
676
+ (_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);
603
677
  this.launchSource = [];
604
678
  this.componentsCount = 0;
605
679
  this.eventService.destroy();
@@ -608,7 +682,20 @@ export var ElementComponent = /*#__PURE__*/function () {
608
682
  }, {
609
683
  key: "submitPayment",
610
684
  value: function submitPayment() {
611
- return this.validatePromiseFuncs();
685
+ var _this$_options$loadin7,
686
+ _this7 = this;
687
+ if ((_this$_options$loadin7 = this._options.loading) !== null && _this$_options$loadin7 !== void 0 && _this$_options$loadin7.onStartLoading) {
688
+ var _this$_options$loadin8, _this$_options$loadin9;
689
+ (_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);
690
+ }
691
+ this.validatePromiseFuncs().then(function () {
692
+ var _this7$_options$loadi;
693
+ if ((_this7$_options$loadi = _this7._options.loading) !== null && _this7$_options$loadi !== void 0 && _this7$_options$loadi.onEndLoading) {
694
+ var _this7$_options$loadi2, _this7$_options$loadi3;
695
+ (_this7$_options$loadi2 = _this7._options.loading) === null || _this7$_options$loadi2 === void 0 || (_this7$_options$loadi3 = _this7$_options$loadi2.onEndLoading) === null || _this7$_options$loadi3 === void 0 || _this7$_options$loadi3.call(_this7$_options$loadi2);
696
+ }
697
+ });
698
+ return;
612
699
  }
613
700
  }]);
614
701
  return ElementComponent;
@@ -1,36 +1,79 @@
1
- import { ElementPaymentMethod, ConnectErrorCode } from '../../../types';
2
- interface BaseMountOptions {
1
+ import { ConnectErrorCode, ElementPaymentMethod } from '../../../types';
2
+ export declare enum ThemeType {
3
+ NostalgicGray = "nostalgicGray",
4
+ Default = "default",
5
+ Night = "night",
6
+ CherryBlossomPink = "cherryBlossomPink",
7
+ GamingPurple = "gamingPurple",
8
+ AgateGreen = "agateGreen"
3
9
  }
4
- type Theme = "night" | "light" | "agateGreen" | "nostalgicGray" | "gamingPurple" | "cherryBlossomPink";
5
10
  export declare const addressTheme: {
11
+ default: string;
6
12
  night: string;
7
- light: string;
8
13
  };
9
- export interface AddressMountOptions extends BaseMountOptions {
10
- type: 'address';
14
+ export declare enum EventCallbackCode {
15
+ Failed = "Failed",
16
+ Completed = "Completed"
17
+ }
18
+ export declare enum ELEMENT_ENVIRONMENT {
19
+ DEV = "DEV",
20
+ TEST = "TEST",
21
+ PRE = "PRE",
22
+ PROD = "PROD"
23
+ }
24
+ export type ELEMENT_ENVIRONMENT_TYPE = keyof typeof ELEMENT_ENVIRONMENT | (typeof ELEMENT_ENVIRONMENT)[keyof typeof ELEMENT_ENVIRONMENT];
25
+ export interface IElementOptions {
26
+ sessionData: string;
27
+ environment?: ELEMENT_ENVIRONMENT_TYPE;
28
+ locale?: string;
29
+ mode?: string;
30
+ version?: string;
11
31
  appearance?: {
12
- theme: "night" | "light";
32
+ theme: ThemeType.Default | ThemeType.Night;
33
+ };
34
+ onEventCallback?: ({ code, message }: {
35
+ code: EventCallbackCode;
36
+ message: string;
37
+ }) => void;
38
+ loading?: {
39
+ onStartLoading: () => void;
40
+ onEndLoading: () => void;
13
41
  };
42
+ }
43
+ interface BaseMountOptions<T = void> {
44
+ config?: {};
14
45
  debugProps?: {
15
46
  localLink: string;
16
47
  };
17
48
  }
18
- export interface LinkAuthMountOptions extends BaseMountOptions {
19
- type: 'linkAuthentication';
49
+ type HideField = 'shippingCountry' | 'shippingName' | 'shippingPhoneNo' | 'shippingRegion' | 'shippingAddress1' | 'shippingZipCode' | 'shippingAddress2';
50
+ export interface AddressMountOptions extends BaseMountOptions<{
51
+ /**
52
+ * 是否开启地址联想功能
53
+ * 0 开启
54
+ * 1 关闭
55
+ */
56
+ autoSaveAsDefaultAddress?: boolean;
57
+ /**
58
+ * 隐藏部分地址要素
59
+ */
60
+ hideFields?: Array<HideField>;
61
+ }> {
62
+ type: 'address';
20
63
  appearance?: {
21
- theme: Theme;
64
+ theme: ThemeType.Default | ThemeType.Night;
22
65
  };
23
- debugProps?: {
24
- localLink?: string;
66
+ }
67
+ export interface LinkAuthMountOptions extends BaseMountOptions {
68
+ type: 'auth';
69
+ appearance?: {
70
+ theme: ThemeType;
25
71
  };
26
72
  }
27
73
  export interface PaymentMountOptions extends BaseMountOptions {
28
74
  type: 'payment';
29
75
  appearance?: {
30
- theme: Theme;
31
- };
32
- debugProps?: {
33
- localLink: string;
76
+ theme: ThemeType;
34
77
  };
35
78
  }
36
79
  export declare enum AddressEventCallbackName {
@@ -101,6 +144,7 @@ export interface AddressSubmitData {
101
144
  notes: string;
102
145
  prefer: '1' | '0';
103
146
  shippingId: string;
147
+ actionFlag: 'I' | 'U' | 'D';
104
148
  }
105
149
  export interface SubmitServiceParams extends PaymentSubmitData {
106
150
  accountInfo: AuthSubmitData['accountInfo'];