@alipay/ams-checkout 0.0.1726046231-dev.10 → 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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/core/component/element/components/address.d.ts +4 -3
- package/esm/core/component/element/components/address.js +10 -3
- package/esm/core/component/element/components/payment.d.ts +2 -1
- package/esm/core/component/element/components/payment.js +7 -3
- package/esm/core/component/element/element-mock.d.ts +2 -0
- package/esm/core/component/element/element-mock.js +263 -0
- package/esm/core/component/element/index.d.ts +5 -3
- package/esm/core/component/element/index.js +233 -191
- package/esm/core/component/element/type.d.ts +16 -4
- package/esm/types/index.d.ts +2 -1
- package/esm/types/index.js +1 -0
- package/package.json +1 -1
@@ -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 {
|
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
|
-
|
106
|
-
|
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$
|
112
|
-
(_this$_options$onEven = (_this$
|
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
|
130
|
-
|
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$
|
136
|
-
(_this$_options$onEven2 = (_this$
|
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
|
-
//
|
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,
|
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 =
|
237
|
+
_context.next = 9;
|
239
238
|
break;
|
240
239
|
}
|
241
|
-
_context.next =
|
240
|
+
_context.next = 4;
|
242
241
|
return _this.onValidateFunc(ElementPaymentMethod.AUTH_ELEMENT);
|
243
|
-
case
|
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 =
|
247
|
+
_context.next = 9;
|
249
248
|
break;
|
250
249
|
}
|
251
|
-
return _context.abrupt("return", resolve(
|
252
|
-
case
|
250
|
+
return _context.abrupt("return", resolve(undefined));
|
251
|
+
case 9:
|
253
252
|
if (!_this.launchSource.includes(ElementPaymentMethod.ADDRESS_ELEMENT)) {
|
254
|
-
_context.next =
|
253
|
+
_context.next = 17;
|
255
254
|
break;
|
256
255
|
}
|
257
|
-
_context.next =
|
256
|
+
_context.next = 12;
|
258
257
|
return _this.onValidateFunc(ElementPaymentMethod.ADDRESS_ELEMENT);
|
259
|
-
case
|
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 =
|
263
|
+
_context.next = 17;
|
265
264
|
break;
|
266
265
|
}
|
267
|
-
return _context.abrupt("return", resolve(
|
268
|
-
case
|
266
|
+
return _context.abrupt("return", resolve(undefined));
|
267
|
+
case 17:
|
269
268
|
if (!_this.launchSource.includes(ElementPaymentMethod.PAYMENT_ELEMENT)) {
|
270
|
-
_context.next =
|
269
|
+
_context.next = 26;
|
271
270
|
break;
|
272
271
|
}
|
273
|
-
_context.next =
|
272
|
+
_context.next = 20;
|
274
273
|
return _this.onValidateFunc(ElementPaymentMethod.PAYMENT_ELEMENT);
|
275
|
-
case
|
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 =
|
280
|
+
_context.next = 26;
|
282
281
|
break;
|
283
282
|
}
|
284
|
-
return _context.abrupt("return", resolve(
|
285
|
-
case
|
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(
|
289
|
-
case
|
287
|
+
resolve(params);
|
288
|
+
case 27:
|
290
289
|
case "end":
|
291
290
|
return _context.stop();
|
292
291
|
}
|
@@ -320,27 +319,36 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
320
319
|
this.elementContainer = new AntomSDKCore();
|
321
320
|
this.elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', new ElementProcessor());
|
322
321
|
this.elementContainer.init({}, ProductSceneEnum.ELEMENT_PAYMENT);
|
322
|
+
this.isConnect = parseData.connectFactor.enableConnect;
|
323
323
|
this.elementContainer.startBizFlow({
|
324
324
|
paymentSession: this._options.sessionData
|
325
325
|
}).then(function (res) {
|
326
|
-
//
|
327
|
-
|
328
|
-
|
329
|
-
_this2.
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
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
|
+
}
|
339
348
|
});
|
340
349
|
this.iframeSrc = this.createIframeSrc(this._options.environment, this._options.version);
|
341
|
-
|
342
|
-
// 注册 auth 邮箱模块
|
343
350
|
try {
|
351
|
+
// 注册 auth 邮箱模块
|
344
352
|
this.authBase = new ElementAuthComponent();
|
345
353
|
this.authBase.create({
|
346
354
|
environment: this._options.environment,
|
@@ -355,7 +363,7 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
355
363
|
environment: this._options.environment,
|
356
364
|
locale: this._options.locale,
|
357
365
|
appVersion: this._options.version || ''
|
358
|
-
});
|
366
|
+
}, this.isConnect);
|
359
367
|
|
360
368
|
// 注册 address 地址模块
|
361
369
|
this.addressBase = new ElementAddressComponent();
|
@@ -363,10 +371,10 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
363
371
|
environment: this._options.environment,
|
364
372
|
locale: this._options.locale,
|
365
373
|
appVersion: this._options.version || ''
|
366
|
-
});
|
374
|
+
}, this.isConnect);
|
367
375
|
} catch (error) {
|
368
|
-
var _this$_options$onEven3, _this$
|
369
|
-
(_this$_options$onEven3 = (_this$
|
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, {
|
370
378
|
code: EventCallbackCode.Failed,
|
371
379
|
message: 'create sdk fail'
|
372
380
|
});
|
@@ -375,6 +383,8 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
375
383
|
// 注册监听消息
|
376
384
|
this.addListener();
|
377
385
|
}
|
386
|
+
|
387
|
+
// iframe src生成方法
|
378
388
|
}, {
|
379
389
|
key: "createIframeSrc",
|
380
390
|
value: function createIframeSrc() {
|
@@ -392,7 +402,7 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
392
402
|
key: "sdkActionQuery",
|
393
403
|
value: function sdkActionQuery() {
|
394
404
|
var _this3 = this;
|
395
|
-
return new Promise(function (resolve) {
|
405
|
+
return new Promise(function (resolve, reject) {
|
396
406
|
var paymentSessionConfig = _this3.parseData.paymentSessionConfig;
|
397
407
|
var hostSign = _this3.sessionData.split('&&')[1] || '';
|
398
408
|
_this3.requestService.request({
|
@@ -409,13 +419,20 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
409
419
|
'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query'
|
410
420
|
}).then(function (result) {
|
411
421
|
if (!result.success) {
|
412
|
-
var _this3$_options
|
413
|
-
(_this3$_options
|
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, {
|
414
424
|
code: EventCallbackCode.Failed,
|
415
425
|
message: 'sdkAction.query Request Error'
|
416
426
|
});
|
427
|
+
reject(result);
|
417
428
|
}
|
418
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
|
+
});
|
419
436
|
});
|
420
437
|
});
|
421
438
|
}
|
@@ -442,10 +459,17 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
442
459
|
'Operation-Type': 'com.ipay.iexpfront.one.account.query'
|
443
460
|
}).then(function (result) {
|
444
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
|
+
});
|
445
468
|
});
|
446
469
|
});
|
447
470
|
}
|
448
471
|
|
472
|
+
// 循环给所有iframe发同一个消息
|
449
473
|
// private postCommonMessage<T>(event: ElementPaymentEvent, params: T) {
|
450
474
|
// for (let index = 0; index < this.launchSource.length; index++) {
|
451
475
|
// this.eventService.emitAndListen(
|
@@ -467,20 +491,6 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
467
491
|
key: "addListener",
|
468
492
|
value: function addListener() {
|
469
493
|
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
494
|
this.eventService.listen(ElementPaymentEvent.LAUNCH, function (result) {
|
485
495
|
_this5.launchFunc(result);
|
486
496
|
});
|
@@ -492,79 +502,83 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
492
502
|
});
|
493
503
|
this.eventService.listen(ElementPaymentEvent.CALLBACK, function (result) {
|
494
504
|
var _this5$eventCallback;
|
505
|
+
console.log('antom sdk 组件事件回调');
|
495
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]) {
|
496
507
|
var _this5$eventCallback$, _this5$eventCallback$2;
|
497
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);
|
498
509
|
}
|
499
510
|
});
|
511
|
+
this.eventService.listen(ElementPaymentEvent.LOG, function (result) {
|
512
|
+
console.log('antom sdk 组件日志回调');
|
513
|
+
});
|
500
514
|
}
|
515
|
+
|
516
|
+
// launch消息处理
|
501
517
|
}, {
|
502
|
-
key: "
|
503
|
-
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
|
+
|
504
542
|
// 发送初始化数据
|
505
|
-
|
543
|
+
}, {
|
544
|
+
key: "sendRenderData",
|
545
|
+
value: function sendRenderData() {
|
546
|
+
var _this6 = this;
|
506
547
|
if (this.launchSource.length === this.componentsCount && this.sdkActionRes && this.oneAccountRes) {
|
507
|
-
var _this$_options$loadin
|
548
|
+
var _this$_options$loadin;
|
508
549
|
var baseData = {
|
509
550
|
originActionQueryResult: this.sdkActionRes,
|
510
551
|
originOneAccountQueryResult: this.oneAccountRes,
|
511
552
|
paymentSessionData: this._options.sessionData,
|
512
553
|
sessionResult: this.parseData || {}
|
513
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();
|
514
574
|
if ((_this$_options$loadin = this._options.loading) !== null && _this$_options$loadin !== void 0 && _this$_options$loadin.onEndLoading) {
|
515
575
|
var _this$_options$loadin2, _this$_options$loadin3;
|
516
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);
|
517
577
|
}
|
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
578
|
}
|
567
579
|
}
|
580
|
+
|
581
|
+
// 注销所有消息监听,这里需要和addListener里面监听的事件对应
|
568
582
|
}, {
|
569
583
|
key: "removeListener",
|
570
584
|
value: function removeListener() {
|
@@ -573,6 +587,8 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
573
587
|
this.eventService.unlisten(ElementPaymentEvent.LAUNCH);
|
574
588
|
this.eventService.unlisten(ElementPaymentEvent.SIZE_CHANGE);
|
575
589
|
}
|
590
|
+
|
591
|
+
// 注册组件事件监听
|
576
592
|
}, {
|
577
593
|
key: "registerEventListener",
|
578
594
|
value: function registerEventListener(source, event, callback) {
|
@@ -583,9 +599,15 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
583
599
|
}, {
|
584
600
|
key: "mountAuth",
|
585
601
|
value: function mountAuth(renderOptions, sdkSelector) {
|
586
|
-
var
|
587
|
-
|
588
|
-
|
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;
|
589
611
|
var _selector = sdkSelector.indexOf('#') === 0 ? sdkSelector.slice(1) : sdkSelector;
|
590
612
|
var link = renderOptions === null || renderOptions === void 0 || (_renderOptions$debugP = renderOptions.debugProps) === null || _renderOptions$debugP === void 0 ? void 0 : _renderOptions$debugP.localLink;
|
591
613
|
var params = window.location.href.split('?')[1];
|
@@ -595,22 +617,17 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
595
617
|
url: url
|
596
618
|
}).then(function (result) {
|
597
619
|
if (!result) {
|
598
|
-
var
|
599
|
-
(
|
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, {
|
600
622
|
code: EventCallbackCode.Failed,
|
601
623
|
message: 'Component loading failed'
|
602
624
|
});
|
603
625
|
return undefined;
|
604
626
|
}
|
605
|
-
|
606
|
-
|
627
|
+
_this7.eventService.addIFrame(result);
|
628
|
+
_this7.iframes[ElementPaymentMethod.AUTH_ELEMENT] = result;
|
607
629
|
});
|
608
|
-
return {
|
609
|
-
// unmount: () => {
|
610
|
-
// this.authBase.unmount();
|
611
|
-
// this.removeSdk(ElementPaymentMethod.AUTH_ELEMENT);
|
612
|
-
// },
|
613
|
-
};
|
630
|
+
return {};
|
614
631
|
}
|
615
632
|
}, {
|
616
633
|
key: "mount",
|
@@ -654,9 +671,11 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
654
671
|
return undefined;
|
655
672
|
}
|
656
673
|
}
|
674
|
+
|
675
|
+
// 注销单个iframe,暂时没有用到
|
657
676
|
}, {
|
658
|
-
key: "
|
659
|
-
value: function
|
677
|
+
key: "removeIframe",
|
678
|
+
value: function removeIframe(sdk) {
|
660
679
|
if (sdk && this.launchSource.some(function (source) {
|
661
680
|
return source === sdk;
|
662
681
|
})) {
|
@@ -667,6 +686,8 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
667
686
|
this.eventService.removeIFrame(this.iframes[sdk]);
|
668
687
|
}
|
669
688
|
}
|
689
|
+
|
690
|
+
// 暴露出去的注销组件方法
|
670
691
|
}, {
|
671
692
|
key: "unmount",
|
672
693
|
value: function unmount() {
|
@@ -681,22 +702,43 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
681
702
|
}
|
682
703
|
}, {
|
683
704
|
key: "submitPayment",
|
684
|
-
value:
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
var _this$_options$loadin8, _this$_options$loadin9;
|
689
|
-
(
|
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);
|
690
739
|
}
|
691
|
-
|
692
|
-
|
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
|
-
}
|
740
|
+
return submitPayment;
|
741
|
+
}()
|
700
742
|
}]);
|
701
743
|
return ElementComponent;
|
702
744
|
}();
|