@alipay/ams-checkout 0.0.1726046231-dev.1 → 0.0.1726046231-dev.12

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