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

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,9 @@ 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, ThemeType, ELEMENT_ENVIRONMENT } from "./type";
25
+ // import { oneAccount, sdkAction } from './mock';
26
+
27
+ import { addressTheme, ELEMENT_ENVIRONMENT, ThemeType } from "./type";
26
28
  var ElementProcessor = /*#__PURE__*/function () {
27
29
  function ElementProcessor() {
28
30
  _classCallCheck(this, ElementProcessor);
@@ -76,6 +78,8 @@ export var ElementComponent = /*#__PURE__*/function () {
76
78
  // one account接口返回
77
79
  _defineProperty(this, "launchSource", void 0);
78
80
  // launch 来源记录
81
+ _defineProperty(this, "isConnect", void 0);
82
+ // 当前sessionData是否connect模式
79
83
  _defineProperty(this, "iframeSrc", void 0);
80
84
  // iframe src记录
81
85
  _defineProperty(this, "mountOptions", void 0);
@@ -85,31 +89,29 @@ export var ElementComponent = /*#__PURE__*/function () {
85
89
  _defineProperty(this, "componentsCount", void 0);
86
90
  // mount 渲染了多少个element
87
91
  _defineProperty(this, "eventCallback", void 0);
88
- // launch消息处理
89
- _defineProperty(this, "launchFunc", function () {
90
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
91
- var eventSource = Object.keys(ElementPaymentMethod);
92
- var source = data.source,
93
- target = data.target;
94
- if (eventSource.includes(source) && target === ElementPaymentMethod.CONTAINER_ELEMENT) {
95
- if (_this.launchSource.every(function (item) {
96
- return item !== source;
97
- })) {
98
- _this.launchSource.push(source);
99
- _this.sendRenderData();
100
- }
101
- }
102
- });
103
92
  // 渲染地址组件
104
93
  _defineProperty(this, "mountAddress", function (renderOptions, sdkSelector) {
105
- _this.mountOptions[ElementPaymentMethod.ADDRESS_ELEMENT] = renderOptions;
106
- _this.addressBase.mount(_this._options.sessionData, {
94
+ var _renderOptions$appear, _this$_options;
95
+ var _mountParams = {
96
+ appearance: {
97
+ themeType: addressTheme[(renderOptions === null || renderOptions === void 0 || (_renderOptions$appear = renderOptions.appearance) === null || _renderOptions$appear === void 0 ? void 0 : _renderOptions$appear.theme) || ((_this$_options = _this._options) === null || _this$_options === void 0 || (_this$_options = _this$_options.appearance) === null || _this$_options === void 0 ? void 0 : _this$_options.theme) || ThemeType.Default]
98
+ },
99
+ configParams: _objectSpread({
100
+ needEditBackBtn: _this.isConnect,
101
+ autoSaveAsDefaultAddress: _this.isConnect,
102
+ editingNeedShippingQuery: _this.isConnect,
103
+ showTitle: _this.isConnect
104
+ }, renderOptions.configParams),
105
+ prefillValue: renderOptions.prefillValue
106
+ };
107
+ _this.mountOptions[ElementPaymentMethod.ADDRESS_ELEMENT] = _mountParams;
108
+ _this.addressBase.mount(_this._options.sessionData, _objectSpread({
107
109
  selector: sdkSelector,
108
110
  debugProps: renderOptions.debugProps
109
- }).then(function (result) {
111
+ }, _mountParams)).then(function (result) {
110
112
  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
+ var _this$_options$onEven, _this$_options2;
114
+ (_this$_options$onEven = (_this$_options2 = _this._options).onEventCallback) === null || _this$_options$onEven === void 0 || _this$_options$onEven.call(_this$_options2, {
113
115
  code: EventCallbackCode.Failed,
114
116
  message: 'Component loading failed'
115
117
  });
@@ -126,14 +128,20 @@ export var ElementComponent = /*#__PURE__*/function () {
126
128
  });
127
129
  // 渲染卡支付组件
128
130
  _defineProperty(this, "mountPayment", function (renderOptions, sdkSelector) {
129
- _this.mountOptions[ElementPaymentMethod.PAYMENT_ELEMENT] = renderOptions;
130
- _this.paymentBase.mount(_this._options.sessionData, {
131
+ var _this$_options3;
132
+ var _mountParams = {
133
+ appearance: renderOptions.appearance || ((_this$_options3 = _this._options) === null || _this$_options3 === void 0 ? void 0 : _this$_options3.appearance) || {
134
+ theme: ThemeType.Default
135
+ }
136
+ };
137
+ _this.mountOptions[ElementPaymentMethod.PAYMENT_ELEMENT] = _mountParams;
138
+ _this.paymentBase.mount(_this._options.sessionData, _objectSpread({
131
139
  selector: sdkSelector,
132
140
  debugProps: renderOptions.debugProps
133
- }).then(function (result) {
141
+ }, _mountParams)).then(function (result) {
134
142
  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, {
143
+ var _this$_options$onEven2, _this$_options4;
144
+ (_this$_options$onEven2 = (_this$_options4 = _this._options).onEventCallback) === null || _this$_options$onEven2 === void 0 || _this$_options$onEven2.call(_this$_options4, {
137
145
  code: EventCallbackCode.Failed,
138
146
  message: 'Component loading failed'
139
147
  });
@@ -142,29 +150,9 @@ export var ElementComponent = /*#__PURE__*/function () {
142
150
  _this.eventService.addIFrame(result);
143
151
  _this.iframes[ElementPaymentMethod.PAYMENT_ELEMENT] = result;
144
152
  });
145
- return {
146
- // unmount: () => {
147
- // this.paymentBase.unmount();
148
- // this.removeSdk(ElementPaymentMethod.PAYMENT_ELEMENT);
149
- // },
150
- };
153
+ return {};
151
154
  });
152
- // 发送validate消息
153
- _defineProperty(this, "onValidateFunc", function (target) {
154
- return new Promise(function (resolve) {
155
- _this.eventService.emitAndListen({
156
- event: ElementPaymentEvent.VALIDATE,
157
- data: {
158
- target: target,
159
- source: ElementPaymentMethod.CONTAINER_ELEMENT,
160
- params: {}
161
- }
162
- }, function (result) {
163
- resolve(result);
164
- });
165
- });
166
- });
167
- // submit提交并成功
155
+ // submit提交非RISK_REJECT错误
168
156
  _defineProperty(this, "onAfterSubmitFunc", function (target, params) {
169
157
  _this.eventService.emitAndListen({
170
158
  event: ElementPaymentEvent.AFTER_SUBMIT,
@@ -221,72 +209,83 @@ export var ElementComponent = /*#__PURE__*/function () {
221
209
  });
222
210
  });
223
211
  });
212
+ // 发送validate消息
213
+ _defineProperty(this, "onValidateFunc", function (target) {
214
+ return new Promise(function (resolve) {
215
+ _this.eventService.emitAndListen({
216
+ event: ElementPaymentEvent.VALIDATE,
217
+ data: {
218
+ target: target,
219
+ source: ElementPaymentMethod.CONTAINER_ELEMENT,
220
+ params: {}
221
+ }
222
+ }, function (result) {
223
+ resolve(result);
224
+ });
225
+ });
226
+ });
224
227
  // 处理validate事件
225
228
  _defineProperty(this, "validatePromiseFuncs", function () {
226
229
  return new Promise( /*#__PURE__*/function () {
227
230
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve) {
228
- var params, validateFailInfo, _result$data, _result$data2, result, _result$data3, _result$data4, _result, _result2$data, _result2$data2, _result2$data3, _result2;
231
+ var params, _result$data, _result$data2, result, _result$data3, _result$data4, _result, _result2$data, _result2$data2, _result2$data3, _result2;
229
232
  return _regeneratorRuntime().wrap(function _callee$(_context) {
230
233
  while (1) switch (_context.prev = _context.next) {
231
234
  case 0:
232
235
  params = {};
233
- validateFailInfo = {
234
- success: false,
235
- msg: ''
236
- };
237
236
  if (!_this.launchSource.includes(ElementPaymentMethod.AUTH_ELEMENT)) {
238
- _context.next = 10;
237
+ _context.next = 9;
239
238
  break;
240
239
  }
241
- _context.next = 5;
240
+ _context.next = 4;
242
241
  return _this.onValidateFunc(ElementPaymentMethod.AUTH_ELEMENT);
243
- case 5:
242
+ case 4:
244
243
  result = _context.sent;
245
244
  console.log('element submit validate auth---------', result);
246
245
  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;
247
246
  if (result !== null && result !== void 0 && (_result$data2 = result.data) !== null && _result$data2 !== void 0 && _result$data2.success) {
248
- _context.next = 10;
247
+ _context.next = 9;
249
248
  break;
250
249
  }
251
- return _context.abrupt("return", resolve(validateFailInfo));
252
- case 10:
250
+ return _context.abrupt("return", resolve(undefined));
251
+ case 9:
253
252
  if (!_this.launchSource.includes(ElementPaymentMethod.ADDRESS_ELEMENT)) {
254
- _context.next = 18;
253
+ _context.next = 17;
255
254
  break;
256
255
  }
257
- _context.next = 13;
256
+ _context.next = 12;
258
257
  return _this.onValidateFunc(ElementPaymentMethod.ADDRESS_ELEMENT);
259
- case 13:
258
+ case 12:
260
259
  _result = _context.sent;
261
260
  console.log('element submit validate address---------', _result);
262
261
  params.shipping = (_result$data3 = _result.data) === null || _result$data3 === void 0 ? void 0 : _result$data3.data;
263
262
  if (_result !== null && _result !== void 0 && (_result$data4 = _result.data) !== null && _result$data4 !== void 0 && _result$data4.success) {
264
- _context.next = 18;
263
+ _context.next = 17;
265
264
  break;
266
265
  }
267
- return _context.abrupt("return", resolve(validateFailInfo));
268
- case 18:
266
+ return _context.abrupt("return", resolve(undefined));
267
+ case 17:
269
268
  if (!_this.launchSource.includes(ElementPaymentMethod.PAYMENT_ELEMENT)) {
270
- _context.next = 27;
269
+ _context.next = 26;
271
270
  break;
272
271
  }
273
- _context.next = 21;
272
+ _context.next = 20;
274
273
  return _this.onValidateFunc(ElementPaymentMethod.PAYMENT_ELEMENT);
275
- case 21:
274
+ case 20:
276
275
  _result2 = _context.sent;
277
276
  console.log('element submit validate payment---------', _result2);
278
277
  params.paymentFactors = (_result2$data = _result2.data) === null || _result2$data === void 0 ? void 0 : _result2$data.data.paymentFactors;
279
278
  params.paymentMethod = (_result2$data2 = _result2.data) === null || _result2$data2 === void 0 ? void 0 : _result2$data2.data.paymentMethod;
280
279
  if (_result2 !== null && _result2 !== void 0 && (_result2$data3 = _result2.data) !== null && _result2$data3 !== void 0 && _result2$data3.success) {
281
- _context.next = 27;
280
+ _context.next = 26;
282
281
  break;
283
282
  }
284
- return _context.abrupt("return", resolve(validateFailInfo));
285
- case 27:
283
+ return _context.abrupt("return", resolve(undefined));
284
+ case 26:
286
285
  // params.paymentFactors = paymentResult.data?.data.paymentFactors;
287
286
  // params.paymentMethod = paymentResult.data?.data.paymentMethod;
288
- resolve(_this.onSubmit(params));
289
- case 28:
287
+ resolve(params);
288
+ case 27:
290
289
  case "end":
291
290
  return _context.stop();
292
291
  }
@@ -310,7 +309,8 @@ export var ElementComponent = /*#__PURE__*/function () {
310
309
  _createClass(ElementComponent, [{
311
310
  key: "createElement",
312
311
  value: function createElement() {
313
- var _this2 = this;
312
+ var _parseData$paymentSes,
313
+ _this2 = this;
314
314
  var _parseSessionData = parseSessionData(this._options.sessionData),
315
315
  _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
316
316
  parseData = _parseSessionData2[0],
@@ -320,27 +320,36 @@ export var ElementComponent = /*#__PURE__*/function () {
320
320
  this.elementContainer = new AntomSDKCore();
321
321
  this.elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', new ElementProcessor());
322
322
  this.elementContainer.init({}, ProductSceneEnum.ELEMENT_PAYMENT);
323
+ this.isConnect = parseData.connectFactor.enableConnect && (parseData === null || parseData === void 0 || (_parseData$paymentSes = parseData.paymentSessionConfig) === null || _parseData$paymentSes === void 0 ? void 0 : _parseData$paymentSes.productScene) === window.ProductSceneEnum.ELEMENT_PAYMENT;
323
324
  this.elementContainer.startBizFlow({
324
325
  paymentSession: this._options.sessionData
325
326
  }).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);
327
+ // console.log('antom sdk start-----', res, this.elementContainer.getBizFlowResult());
328
+ if (_this2.isConnect) {
329
+ // 请求消息
330
+ Promise.all([_this2.oneAccountQuery(), _this2.sdkActionQuery()]).then(function (result) {
331
+ _this2.oneAccountRes = result[0];
332
+ _this2.sdkActionRes = result[1];
333
+ _this2.sendRenderData();
334
+ });
335
+ // 本地mock测试数据
336
+ // setTimeout(() => {
337
+ // this.oneAccountRes = oneAccount;
338
+ // this.sdkActionRes = sdkAction;
339
+ // this.sendRenderData();
340
+ // }, 500);
341
+ // 本地mock测试报错页
342
+ // setTimeout(() => {
343
+ // this._options?.onEventCallback?.({
344
+ // code: EventCallbackCode.Failed,
345
+ // message: 'sdkAction.query Request Error',
346
+ // });
347
+ // }, 2000)
348
+ }
339
349
  });
340
350
  this.iframeSrc = this.createIframeSrc(this._options.environment, this._options.version);
341
-
342
- // 注册 auth 邮箱模块
343
351
  try {
352
+ // 注册 auth 邮箱模块
344
353
  this.authBase = new ElementAuthComponent();
345
354
  this.authBase.create({
346
355
  environment: this._options.environment,
@@ -355,7 +364,7 @@ export var ElementComponent = /*#__PURE__*/function () {
355
364
  environment: this._options.environment,
356
365
  locale: this._options.locale,
357
366
  appVersion: this._options.version || ''
358
- });
367
+ }, this.isConnect);
359
368
 
360
369
  // 注册 address 地址模块
361
370
  this.addressBase = new ElementAddressComponent();
@@ -363,10 +372,10 @@ export var ElementComponent = /*#__PURE__*/function () {
363
372
  environment: this._options.environment,
364
373
  locale: this._options.locale,
365
374
  appVersion: this._options.version || ''
366
- });
375
+ }, this.isConnect);
367
376
  } 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, {
377
+ var _this$_options$onEven3, _this$_options5;
378
+ (_this$_options$onEven3 = (_this$_options5 = this._options).onEventCallback) === null || _this$_options$onEven3 === void 0 || _this$_options$onEven3.call(_this$_options5, {
370
379
  code: EventCallbackCode.Failed,
371
380
  message: 'create sdk fail'
372
381
  });
@@ -375,6 +384,8 @@ export var ElementComponent = /*#__PURE__*/function () {
375
384
  // 注册监听消息
376
385
  this.addListener();
377
386
  }
387
+
388
+ // iframe src生成方法
378
389
  }, {
379
390
  key: "createIframeSrc",
380
391
  value: function createIframeSrc() {
@@ -392,7 +403,7 @@ export var ElementComponent = /*#__PURE__*/function () {
392
403
  key: "sdkActionQuery",
393
404
  value: function sdkActionQuery() {
394
405
  var _this3 = this;
395
- return new Promise(function (resolve) {
406
+ return new Promise(function (resolve, reject) {
396
407
  var paymentSessionConfig = _this3.parseData.paymentSessionConfig;
397
408
  var hostSign = _this3.sessionData.split('&&')[1] || '';
398
409
  _this3.requestService.request({
@@ -409,13 +420,20 @@ export var ElementComponent = /*#__PURE__*/function () {
409
420
  'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query'
410
421
  }).then(function (result) {
411
422
  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, {
423
+ var _this3$_options, _this3$_options$onEve;
424
+ (_this3$_options = _this3._options) === null || _this3$_options === void 0 || (_this3$_options$onEve = _this3$_options.onEventCallback) === null || _this3$_options$onEve === void 0 || _this3$_options$onEve.call(_this3$_options, {
414
425
  code: EventCallbackCode.Failed,
415
426
  message: 'sdkAction.query Request Error'
416
427
  });
428
+ reject(result);
417
429
  }
418
430
  resolve(result);
431
+ }, function () {
432
+ var _this3$_options2, _this3$_options2$onEv;
433
+ _this3 === null || _this3 === void 0 || (_this3$_options2 = _this3._options) === null || _this3$_options2 === void 0 || (_this3$_options2$onEv = _this3$_options2.onEventCallback) === null || _this3$_options2$onEv === void 0 || _this3$_options2$onEv.call(_this3$_options2, {
434
+ code: EventCallbackCode.Failed,
435
+ message: 'sdk.action.query Request Error'
436
+ });
419
437
  });
420
438
  });
421
439
  }
@@ -442,10 +460,17 @@ export var ElementComponent = /*#__PURE__*/function () {
442
460
  'Operation-Type': 'com.ipay.iexpfront.one.account.query'
443
461
  }).then(function (result) {
444
462
  resolve(result);
463
+ }, function () {
464
+ var _this4$_options, _this4$_options$onEve;
465
+ _this4 === null || _this4 === void 0 || (_this4$_options = _this4._options) === null || _this4$_options === void 0 || (_this4$_options$onEve = _this4$_options.onEventCallback) === null || _this4$_options$onEve === void 0 || _this4$_options$onEve.call(_this4$_options, {
466
+ code: EventCallbackCode.Failed,
467
+ message: 'one.account.query Request Error'
468
+ });
445
469
  });
446
470
  });
447
471
  }
448
472
 
473
+ // 循环给所有iframe发同一个消息
449
474
  // private postCommonMessage<T>(event: ElementPaymentEvent, params: T) {
450
475
  // for (let index = 0; index < this.launchSource.length; index++) {
451
476
  // this.eventService.emitAndListen(
@@ -467,20 +492,6 @@ export var ElementComponent = /*#__PURE__*/function () {
467
492
  key: "addListener",
468
493
  value: function addListener() {
469
494
  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
495
  this.eventService.listen(ElementPaymentEvent.LAUNCH, function (result) {
485
496
  _this5.launchFunc(result);
486
497
  });
@@ -492,79 +503,83 @@ export var ElementComponent = /*#__PURE__*/function () {
492
503
  });
493
504
  this.eventService.listen(ElementPaymentEvent.CALLBACK, function (result) {
494
505
  var _this5$eventCallback;
506
+ console.log('antom sdk 组件事件回调');
495
507
  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
508
  var _this5$eventCallback$, _this5$eventCallback$2;
497
509
  (_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
510
  }
499
511
  });
512
+ this.eventService.listen(ElementPaymentEvent.LOG, function (result) {
513
+ console.log('antom sdk 组件日志回调');
514
+ });
500
515
  }
516
+
517
+ // launch消息处理
501
518
  }, {
502
- key: "sendRenderData",
503
- value:
519
+ key: "launchFunc",
520
+ value: function launchFunc() {
521
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
522
+ var eventSource = Object.keys(ElementPaymentMethod);
523
+ var source = data.source,
524
+ target = data.target;
525
+ if (eventSource.includes(source) && target === ElementPaymentMethod.CONTAINER_ELEMENT) {
526
+ if (this.launchSource.every(function (item) {
527
+ return item !== source;
528
+ })) {
529
+ this.launchSource.push(source);
530
+ this.sendRenderData();
531
+ }
532
+ }
533
+ }
534
+ }, {
535
+ key: "showIframe",
536
+ value: function showIframe() {
537
+ var _this$paymentBase, _this$addressBase, _this$authBase;
538
+ (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());
539
+ (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());
540
+ (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());
541
+ }
542
+
504
543
  // 发送初始化数据
505
- function sendRenderData() {
544
+ }, {
545
+ key: "sendRenderData",
546
+ value: function sendRenderData() {
547
+ var _this6 = this;
506
548
  if (this.launchSource.length === this.componentsCount && this.sdkActionRes && this.oneAccountRes) {
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;
549
+ var _this$_options$loadin;
508
550
  var baseData = {
509
551
  originActionQueryResult: this.sdkActionRes,
510
552
  originOneAccountQueryResult: this.oneAccountRes,
511
553
  paymentSessionData: this._options.sessionData,
512
554
  sessionResult: this.parseData || {}
513
555
  };
556
+ this.loading = false;
557
+ this.launchSource.forEach(function (target) {
558
+ var _this6$mountOptions;
559
+ var params = _objectSpread(_objectSpread({}, (_this6$mountOptions = _this6.mountOptions) === null || _this6$mountOptions === void 0 ? void 0 : _this6$mountOptions[target]), baseData);
560
+ if (target === ElementPaymentMethod.ADDRESS_ELEMENT) {
561
+ params.prefillValue = _this6.oneAccountRes.shippings || [];
562
+ } else if (target === ElementPaymentMethod.PAYMENT_ELEMENT) {
563
+ params.queryResult = _this6.sdkActionRes;
564
+ }
565
+ _this6.eventService.emitAndListen({
566
+ event: ElementPaymentEvent.INITIAL_DATA_READY,
567
+ data: {
568
+ target: target,
569
+ source: ElementPaymentMethod.CONTAINER_ELEMENT,
570
+ params: params
571
+ }
572
+ }, function () {});
573
+ });
574
+ this.showIframe();
514
575
  if ((_this$_options$loadin = this._options.loading) !== null && _this$_options$loadin !== void 0 && _this$_options$loadin.onEndLoading) {
515
576
  var _this$_options$loadin2, _this$_options$loadin3;
516
577
  (_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);
517
578
  }
518
- this.loading = false;
519
- this.eventService.emitAndListen({
520
- event: ElementPaymentEvent.INITIAL_DATA_READY,
521
- data: {
522
- target: ElementPaymentMethod.PAYMENT_ELEMENT,
523
- source: ElementPaymentMethod.CONTAINER_ELEMENT,
524
- params: _objectSpread({
525
- queryResult: this.sdkActionRes,
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
- }
529
- }, baseData)
530
- }
531
- }, function () {});
532
- this.eventService.emitAndListen({
533
- event: ElementPaymentEvent.INITIAL_DATA_READY,
534
- data: {
535
- target: ElementPaymentMethod.ADDRESS_ELEMENT,
536
- source: ElementPaymentMethod.CONTAINER_ELEMENT,
537
- params: _objectSpread({
538
- prefillValue: this.oneAccountRes.shippings || [],
539
- appearance: {
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]
541
- },
542
- configParams: _objectSpread({
543
- needEditBackBtn: true,
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])
548
- }, baseData)
549
- }
550
- }, function () {});
551
- this.eventService.emitAndListen({
552
- event: ElementPaymentEvent.INITIAL_DATA_READY,
553
- data: {
554
- target: ElementPaymentMethod.AUTH_ELEMENT,
555
- source: ElementPaymentMethod.CONTAINER_ELEMENT,
556
- params: _objectSpread(_objectSpread({}, baseData), {}, {
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
- }
560
- })
561
- }
562
- }, function () {});
563
- (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());
564
- (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());
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());
566
579
  }
567
580
  }
581
+
582
+ // 注销所有消息监听,这里需要和addListener里面监听的事件对应
568
583
  }, {
569
584
  key: "removeListener",
570
585
  value: function removeListener() {
@@ -573,6 +588,8 @@ export var ElementComponent = /*#__PURE__*/function () {
573
588
  this.eventService.unlisten(ElementPaymentEvent.LAUNCH);
574
589
  this.eventService.unlisten(ElementPaymentEvent.SIZE_CHANGE);
575
590
  }
591
+
592
+ // 注册组件事件监听
576
593
  }, {
577
594
  key: "registerEventListener",
578
595
  value: function registerEventListener(source, event, callback) {
@@ -583,9 +600,15 @@ export var ElementComponent = /*#__PURE__*/function () {
583
600
  }, {
584
601
  key: "mountAuth",
585
602
  value: function mountAuth(renderOptions, sdkSelector) {
586
- var _renderOptions$debugP,
587
- _this6 = this;
588
- this.mountOptions[ElementPaymentMethod.AUTH_ELEMENT] = renderOptions;
603
+ var _this$_options6,
604
+ _renderOptions$debugP,
605
+ _this7 = this;
606
+ var _mountParams = {
607
+ appearance: renderOptions.appearance || ((_this$_options6 = this._options) === null || _this$_options6 === void 0 ? void 0 : _this$_options6.appearance) || {
608
+ theme: ThemeType.Default
609
+ }
610
+ };
611
+ this.mountOptions[ElementPaymentMethod.AUTH_ELEMENT] = _mountParams;
589
612
  var _selector = sdkSelector.indexOf('#') === 0 ? sdkSelector.slice(1) : sdkSelector;
590
613
  var link = renderOptions === null || renderOptions === void 0 || (_renderOptions$debugP = renderOptions.debugProps) === null || _renderOptions$debugP === void 0 ? void 0 : _renderOptions$debugP.localLink;
591
614
  var params = window.location.href.split('?')[1];
@@ -595,22 +618,17 @@ export var ElementComponent = /*#__PURE__*/function () {
595
618
  url: url
596
619
  }).then(function (result) {
597
620
  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, {
621
+ var _this7$_options$onEve, _this7$_options;
622
+ (_this7$_options$onEve = (_this7$_options = _this7._options).onEventCallback) === null || _this7$_options$onEve === void 0 || _this7$_options$onEve.call(_this7$_options, {
600
623
  code: EventCallbackCode.Failed,
601
624
  message: 'Component loading failed'
602
625
  });
603
626
  return undefined;
604
627
  }
605
- _this6.eventService.addIFrame(result);
606
- _this6.iframes[ElementPaymentMethod.AUTH_ELEMENT] = result;
628
+ _this7.eventService.addIFrame(result);
629
+ _this7.iframes[ElementPaymentMethod.AUTH_ELEMENT] = result;
607
630
  });
608
- return {
609
- // unmount: () => {
610
- // this.authBase.unmount();
611
- // this.removeSdk(ElementPaymentMethod.AUTH_ELEMENT);
612
- // },
613
- };
631
+ return {};
614
632
  }
615
633
  }, {
616
634
  key: "mount",
@@ -654,9 +672,11 @@ export var ElementComponent = /*#__PURE__*/function () {
654
672
  return undefined;
655
673
  }
656
674
  }
675
+
676
+ // 注销单个iframe,暂时没有用到
657
677
  }, {
658
- key: "removeSdk",
659
- value: function removeSdk(sdk) {
678
+ key: "removeIframe",
679
+ value: function removeIframe(sdk) {
660
680
  if (sdk && this.launchSource.some(function (source) {
661
681
  return source === sdk;
662
682
  })) {
@@ -667,6 +687,8 @@ export var ElementComponent = /*#__PURE__*/function () {
667
687
  this.eventService.removeIFrame(this.iframes[sdk]);
668
688
  }
669
689
  }
690
+
691
+ // 暴露出去的注销组件方法
670
692
  }, {
671
693
  key: "unmount",
672
694
  value: function unmount() {
@@ -681,22 +703,43 @@ export var ElementComponent = /*#__PURE__*/function () {
681
703
  }
682
704
  }, {
683
705
  key: "submitPayment",
684
- value: function submitPayment() {
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);
706
+ value: // 暴露出去的submit方法
707
+ function () {
708
+ var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
709
+ var _this$_options$loadin7, _this$_options$loadin10;
710
+ var _this$_options$loadin8, _this$_options$loadin9, validateRes, _this$_options$loadin11, _this$_options$loadin12;
711
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
712
+ while (1) switch (_context2.prev = _context2.next) {
713
+ case 0:
714
+ if ((_this$_options$loadin7 = this._options.loading) !== null && _this$_options$loadin7 !== void 0 && _this$_options$loadin7.onStartLoading) {
715
+ (_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);
716
+ }
717
+ _context2.next = 3;
718
+ return this.validatePromiseFuncs();
719
+ case 3:
720
+ validateRes = _context2.sent;
721
+ if (!validateRes) {
722
+ _context2.next = 7;
723
+ break;
724
+ }
725
+ _context2.next = 7;
726
+ return this.onSubmit(validateRes);
727
+ case 7:
728
+ if ((_this$_options$loadin10 = this._options.loading) !== null && _this$_options$loadin10 !== void 0 && _this$_options$loadin10.onEndLoading) {
729
+ (_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);
730
+ }
731
+ return _context2.abrupt("return");
732
+ case 9:
733
+ case "end":
734
+ return _context2.stop();
735
+ }
736
+ }, _callee2, this);
737
+ }));
738
+ function submitPayment() {
739
+ return _submitPayment.apply(this, arguments);
690
740
  }
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;
699
- }
741
+ return submitPayment;
742
+ }()
700
743
  }]);
701
744
  return ElementComponent;
702
745
  }();