@alipay/ams-checkout 0.0.1758607092-dev.0 → 0.0.1758783821-dev.0
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/component/popupWindow.style.d.ts +18 -9
- package/esm/component/popupWindow.style.js +21 -11
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +7 -7
- package/esm/constant/index.d.ts +37 -0
- package/esm/constant/index.js +38 -0
- package/esm/core/component/element/EventCenter/index.d.ts +29 -0
- package/esm/core/component/element/EventCenter/index.js +141 -0
- package/esm/core/component/element/elementContainerService/containerService.js +3 -2
- package/esm/core/component/element/elementController/index.d.ts +28 -2
- package/esm/core/component/element/elementController/index.js +453 -190
- package/esm/core/component/element/elementProcessor/addressProcessor.js +3 -3
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +20 -14
- package/esm/core/component/element/index.d.ts +9 -1
- package/esm/core/component/element/index.js +10 -2
- package/esm/core/component/element/type.d.ts +37 -4
- package/esm/core/component/element/type.js +45 -2
- package/esm/core/component/element/util.d.ts +17 -4
- package/esm/core/component/element/util.js +45 -6
- package/esm/foundation/service/container/index.js +10 -35
- package/esm/foundation/service/container/popup.d.ts +11 -0
- package/esm/foundation/service/container/popup.js +23 -2
- package/esm/foundation/service/log/keys.js +2 -0
- package/esm/foundation/service/requester/requester.js +2 -3
- package/esm/types/index.d.ts +5 -1
- package/esm/util/spm-map.d.ts +2 -0
- package/esm/util/spm-map.js +2 -1
- package/package.json +1 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
var _excluded = ["type"];
|
|
2
2
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
3
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
8
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
9
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -31,13 +35,12 @@ import { ElementProcessor } from "../../../../foundation/product-processor/eleme
|
|
|
31
35
|
import { ProductSceneEnum } from "../../../../types";
|
|
32
36
|
import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
|
|
33
37
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
|
38
|
+
import { EventCenter as ElementEventCenter } from "../EventCenter/index";
|
|
34
39
|
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
|
35
|
-
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, MountElementType } from "../type";
|
|
36
|
-
import { checkCanMount, checkCanUpdate, handleRedirect, showToast } from "../util";
|
|
40
|
+
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType } from "../type";
|
|
41
|
+
import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, showToast } from "../util";
|
|
37
42
|
var TIMEOUT_DURATION = 10000;
|
|
38
43
|
var ElementController = /*#__PURE__*/function () {
|
|
39
|
-
// 新增变量
|
|
40
|
-
|
|
41
44
|
function ElementController(options) {
|
|
42
45
|
_classCallCheck(this, ElementController);
|
|
43
46
|
_defineProperty(this, "options", void 0);
|
|
@@ -49,10 +52,27 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
49
52
|
_defineProperty(this, "elementContainerService", void 0);
|
|
50
53
|
// 新增变量
|
|
51
54
|
_defineProperty(this, "onStatusChangeCallback", void 0);
|
|
52
|
-
|
|
55
|
+
// 新增变量
|
|
56
|
+
_defineProperty(this, "submitPayPromise", void 0);
|
|
57
|
+
_defineProperty(this, "elementEventCenter", void 0);
|
|
58
|
+
_defineProperty(this, "onValidateFunc", function (event, target) {
|
|
53
59
|
return new Promise(function (resolve) {
|
|
54
60
|
event.emitAndListen({
|
|
55
61
|
event: ElementPaymentEvent.VALIDATE,
|
|
62
|
+
data: {
|
|
63
|
+
params: {},
|
|
64
|
+
target: target,
|
|
65
|
+
source: ElementPaymentMethod.CONTAINER_ELEMENT
|
|
66
|
+
}
|
|
67
|
+
}, function (result) {
|
|
68
|
+
resolve(result);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
_defineProperty(this, "onValidateAndSubmitPay", function (event, target, params) {
|
|
73
|
+
return new Promise(function (resolve) {
|
|
74
|
+
event.emitAndListen({
|
|
75
|
+
event: ElementPaymentEvent.SUBMIT_PAY,
|
|
56
76
|
data: {
|
|
57
77
|
params: _objectSpread({}, params),
|
|
58
78
|
target: target,
|
|
@@ -74,6 +94,9 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
74
94
|
instanceId: this.elementContainer.getInstanceId()
|
|
75
95
|
});
|
|
76
96
|
this.setControllerStatusOrView(IElementStatus.READY);
|
|
97
|
+
this.elementEventCenter = new ElementEventCenter({
|
|
98
|
+
logger: this.elementContainer.getServiceProvider().getService('Log')
|
|
99
|
+
});
|
|
77
100
|
}
|
|
78
101
|
_createClass(ElementController, [{
|
|
79
102
|
key: "initService",
|
|
@@ -110,155 +133,324 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
110
133
|
result: result
|
|
111
134
|
});
|
|
112
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* 处理初始化错误的方法
|
|
138
|
+
*/
|
|
113
139
|
}, {
|
|
114
|
-
key: "
|
|
115
|
-
value: function
|
|
140
|
+
key: "handleInitializationError",
|
|
141
|
+
value: function handleInitializationError() {
|
|
142
|
+
this.changeLoading(false);
|
|
143
|
+
this.setControllerStatusOrView(IElementStatus.READY);
|
|
144
|
+
this.onEventCallback(ERRORMESSAGE.SDK_LAUNCH_PAYMENT_APP_ERROR.CALL_APP_URL_ERROR);
|
|
145
|
+
this.elementContainerService.getContainerServices().forEach(function (value) {
|
|
146
|
+
value.getContainerElement().remove();
|
|
147
|
+
});
|
|
148
|
+
this.elementContainerService.destroy();
|
|
149
|
+
} // 处理挂载检查失败
|
|
150
|
+
}, {
|
|
151
|
+
key: "handleMountError",
|
|
152
|
+
value: function handleMountError(_ref2) {
|
|
153
|
+
var result = _ref2.result,
|
|
154
|
+
resolve = _ref2.resolve;
|
|
155
|
+
var errorMsg = result.errorMsg,
|
|
156
|
+
error = result.error;
|
|
157
|
+
this.onEventCallback({
|
|
158
|
+
code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
|
|
159
|
+
message: errorMsg
|
|
160
|
+
});
|
|
161
|
+
resolve({
|
|
162
|
+
error: error
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 清除并设置初始化定时器
|
|
167
|
+
}, {
|
|
168
|
+
key: "clearAndSetInitTimeout",
|
|
169
|
+
value: function clearAndSetInitTimeout(resolve) {
|
|
170
|
+
clearTimeout(this.initTimeout);
|
|
171
|
+
this.initTimeout = null;
|
|
172
|
+
this.initTimeout = this.setInitTimeout(resolve);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 设置初始化超时定时器
|
|
176
|
+
}, {
|
|
177
|
+
key: "setInitTimeout",
|
|
178
|
+
value: function setInitTimeout(resolve) {
|
|
116
179
|
var _this = this;
|
|
117
|
-
return
|
|
118
|
-
var _checkCanMount = checkCanMount({
|
|
119
|
-
sdkSelector: sdkSelector,
|
|
120
|
-
status: _this.elementContainer.getStatus(),
|
|
121
|
-
containerService: _this.elementContainerService.getContainerService(renderOptions.type)
|
|
122
|
-
}),
|
|
123
|
-
success = _checkCanMount.success,
|
|
124
|
-
errorMsg = _checkCanMount.errorMsg;
|
|
125
|
-
if (!success) {
|
|
126
|
-
_this.onEventCallback({
|
|
127
|
-
code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
|
|
128
|
-
message: errorMsg
|
|
129
|
-
});
|
|
130
|
-
resolve({
|
|
131
|
-
success: false
|
|
132
|
-
});
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
180
|
+
return setTimeout(function () {
|
|
135
181
|
clearTimeout(_this.initTimeout);
|
|
136
182
|
_this.initTimeout = null;
|
|
137
|
-
_this.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
183
|
+
_this.handleInitializationError();
|
|
184
|
+
resolve({
|
|
185
|
+
error: ERRORMESSAGE.INITALIZE_TIMEOUT.WEB
|
|
186
|
+
});
|
|
187
|
+
}, TIMEOUT_DURATION);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 初始化并挂载元素处理器
|
|
191
|
+
}, {
|
|
192
|
+
key: "initializeAndMountProcessor",
|
|
193
|
+
value: function initializeAndMountProcessor(type, selector, options) {
|
|
194
|
+
this.initElementProcessors(type);
|
|
195
|
+
this.elementContainerService.mount({
|
|
196
|
+
type: type,
|
|
197
|
+
selector: selector,
|
|
198
|
+
processor: this.elementProcessors[type],
|
|
199
|
+
options: options
|
|
200
|
+
});
|
|
201
|
+
this.elementProcessors[type].registerEventCenter(this.elementContainerService.getEventService(type));
|
|
202
|
+
this.elementProcessors[type].beforeMount();
|
|
203
|
+
}
|
|
204
|
+
// 处理业务流程启动失败
|
|
205
|
+
}, {
|
|
206
|
+
key: "handleStartBizFlowError",
|
|
207
|
+
value: function handleStartBizFlowError(error, readyCallback) {
|
|
208
|
+
readyCallback({
|
|
209
|
+
error: _objectSpread(_objectSpread({}, ERRORMESSAGE.PARAM_INVALID), {}, {
|
|
210
|
+
context: JSON.stringify(error)
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
this.onEventCallback({
|
|
214
|
+
code: EventCallbackCode.SDK_CREATEPAYMENT_PARAMETER_ERROR,
|
|
215
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || 'Initialization parameter exception.'
|
|
216
|
+
});
|
|
217
|
+
clearTimeout(this.initTimeout);
|
|
218
|
+
this.initTimeout = null;
|
|
219
|
+
this.changeLoading(false);
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "mount",
|
|
223
|
+
value: function mount(renderOptions, sdkSelector) {
|
|
224
|
+
var _this2 = this;
|
|
225
|
+
var startEventId = this.elementEventCenter.registerEvent(EXPOSURE_API_EVENT.MOUNT);
|
|
226
|
+
return new Promise(function (resolve) {
|
|
227
|
+
var checkMountResult = checkCanMount({
|
|
228
|
+
sdkSelector: sdkSelector,
|
|
229
|
+
status: _this2.elementContainer.getStatus(),
|
|
230
|
+
containerService: _this2.elementContainerService.getContainerService(renderOptions.type)
|
|
231
|
+
});
|
|
232
|
+
var readyCallback = function readyCallback(payload) {
|
|
233
|
+
_this2.elementEventCenter.endEvent(startEventId, payload);
|
|
234
|
+
resolve(payload);
|
|
154
235
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
message: (error === null || error === void 0 ? void 0 : error.message) || 'Initialization parameter exception.'
|
|
236
|
+
if (!checkMountResult.success) {
|
|
237
|
+
_this2.handleMountError({
|
|
238
|
+
result: checkMountResult,
|
|
239
|
+
resolve: readyCallback
|
|
160
240
|
});
|
|
161
|
-
clearTimeout(_this.initTimeout);
|
|
162
|
-
_this.initTimeout = null;
|
|
163
|
-
_this.changeLoading(false);
|
|
164
241
|
return;
|
|
165
|
-
});
|
|
166
|
-
_this.initElementProcessors(renderOptions.type);
|
|
167
|
-
_this.elementContainerService.mount({
|
|
168
|
-
type: renderOptions.type,
|
|
169
|
-
selector: sdkSelector,
|
|
170
|
-
processor: _this.elementProcessors[renderOptions.type],
|
|
171
|
-
options: renderOptions
|
|
172
|
-
});
|
|
173
|
-
_this.elementProcessors[renderOptions.type].registerEventCenter(_this.elementContainerService.getEventService(renderOptions.type));
|
|
174
|
-
_this.elementProcessors[renderOptions.type].beforeMount();
|
|
175
|
-
_this.sendRequestAndWaitWebLaunch(renderOptions);
|
|
176
|
-
function readyCallback(payload) {
|
|
177
|
-
var _this2 = this;
|
|
178
|
-
var resultData = _objectSpread({
|
|
179
|
-
getValue: this === null || this === void 0 ? void 0 : this.elementProcessors[renderOptions.type].getValue.bind(this === null || this === void 0 ? void 0 : this.elementProcessors[renderOptions.type]),
|
|
180
|
-
on: function on(event, callback) {
|
|
181
|
-
_this2 === null || _this2 === void 0 || _this2.elementProcessors[renderOptions.type].registerEventListener(event, callback);
|
|
182
|
-
}
|
|
183
|
-
}, payload);
|
|
184
|
-
resolve(resultData);
|
|
185
242
|
}
|
|
186
|
-
|
|
187
|
-
|
|
243
|
+
_this2.clearAndSetInitTimeout(readyCallback);
|
|
244
|
+
_this2.changeLoading(true);
|
|
245
|
+
try {
|
|
246
|
+
var startBizFlowData = {
|
|
247
|
+
paymentSession: _this2.options.sessionData,
|
|
248
|
+
displayInfo: _objectSpread(_objectSpread({}, renderOptions), {}, {
|
|
249
|
+
appendAliasContainerId: true
|
|
250
|
+
})
|
|
251
|
+
};
|
|
252
|
+
_this2.setControllerStatusOrView(IElementStatus.IN_BIZ_FLOW);
|
|
253
|
+
_this2.elementContainer.startBizFlow(startBizFlowData);
|
|
254
|
+
_this2.initializeAndMountProcessor(renderOptions.type, sdkSelector, renderOptions);
|
|
255
|
+
_this2.sendRequestAndWaitWebLaunch(renderOptions, readyCallback);
|
|
256
|
+
_this2.addEventListener(readyCallback);
|
|
257
|
+
_this2.serviceMap.EventCenter.addIFrame(_this2.elementContainerService.getContainerService(renderOptions.type).getContainerService().getWebApp());
|
|
258
|
+
} catch (error) {
|
|
259
|
+
_this2.handleStartBizFlowError(error, readyCallback);
|
|
260
|
+
}
|
|
188
261
|
});
|
|
189
262
|
}
|
|
263
|
+
}, {
|
|
264
|
+
key: "validateFields",
|
|
265
|
+
value: (
|
|
266
|
+
/**
|
|
267
|
+
* 25/09/08 新增商户主动校验api
|
|
268
|
+
* @returns {Promise<{isValid: boolean}>}
|
|
269
|
+
*/
|
|
270
|
+
function () {
|
|
271
|
+
var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
272
|
+
var startEventId, result, _this$elementProcesso, _validateResult$data, validateResult;
|
|
273
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
274
|
+
while (1) switch (_context.prev = _context.next) {
|
|
275
|
+
case 0:
|
|
276
|
+
startEventId = this.elementEventCenter.registerEvent(EXPOSURE_API_EVENT.VALIDATAFIELDS);
|
|
277
|
+
result = {
|
|
278
|
+
isValid: false
|
|
279
|
+
};
|
|
280
|
+
_context.prev = 2;
|
|
281
|
+
if (!(this.initTimeout || !((_this$elementProcesso = this.elementProcessors) !== null && _this$elementProcesso !== void 0 && _this$elementProcesso[ElementType.payment]))) {
|
|
282
|
+
_context.next = 5;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
return _context.abrupt("return", result);
|
|
286
|
+
case 5:
|
|
287
|
+
_context.next = 7;
|
|
288
|
+
return this.onValidateFunc(this.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT);
|
|
289
|
+
case 7:
|
|
290
|
+
validateResult = _context.sent;
|
|
291
|
+
result = (_validateResult$data = validateResult.data) !== null && _validateResult$data !== void 0 ? _validateResult$data : {
|
|
292
|
+
isValid: false
|
|
293
|
+
};
|
|
294
|
+
return _context.abrupt("return", result);
|
|
295
|
+
case 12:
|
|
296
|
+
_context.prev = 12;
|
|
297
|
+
_context.t0 = _context["catch"](2);
|
|
298
|
+
return _context.abrupt("return", result);
|
|
299
|
+
case 15:
|
|
300
|
+
_context.prev = 15;
|
|
301
|
+
this.elementEventCenter.endEvent(startEventId, result);
|
|
302
|
+
return _context.finish(15);
|
|
303
|
+
case 18:
|
|
304
|
+
case "end":
|
|
305
|
+
return _context.stop();
|
|
306
|
+
}
|
|
307
|
+
}, _callee, this, [[2, 12, 15, 18]]);
|
|
308
|
+
}));
|
|
309
|
+
function validateFields() {
|
|
310
|
+
return _validateFields.apply(this, arguments);
|
|
311
|
+
}
|
|
312
|
+
return validateFields;
|
|
313
|
+
}())
|
|
190
314
|
}, {
|
|
191
315
|
key: "submitPayment",
|
|
192
|
-
value: function
|
|
193
|
-
var
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
316
|
+
value: function () {
|
|
317
|
+
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
318
|
+
var _this3 = this;
|
|
319
|
+
var startEventId, res, recordResult;
|
|
320
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
321
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
322
|
+
case 0:
|
|
323
|
+
startEventId = this.elementEventCenter.registerEvent(EXPOSURE_API_EVENT.SUBMITPAYMENT);
|
|
324
|
+
if (!(this.elementContainer.getStatus() !== IElementStatus.IN_BIZ_FLOW)) {
|
|
325
|
+
_context4.next = 5;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
res = {
|
|
329
|
+
error: ERRORMESSAGE.CONTAINER_NOT_LOADED
|
|
330
|
+
};
|
|
331
|
+
this.elementEventCenter.endEvent(startEventId, res);
|
|
332
|
+
return _context4.abrupt("return", Promise.resolve(res));
|
|
333
|
+
case 5:
|
|
334
|
+
this.changeLoading(true);
|
|
335
|
+
recordResult = null;
|
|
336
|
+
_context4.prev = 7;
|
|
337
|
+
_context4.next = 10;
|
|
338
|
+
return new Promise( /*#__PURE__*/function () {
|
|
339
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
340
|
+
var params, processStep, _yield$_this3$onValid2, data, errorResult;
|
|
341
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
342
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
343
|
+
case 0:
|
|
344
|
+
_context3.prev = 0;
|
|
345
|
+
_this3.submitPayPromise = resolve;
|
|
346
|
+
params = {}; // 统一处理逻辑
|
|
347
|
+
processStep = /*#__PURE__*/function () {
|
|
348
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(elementType, method) {
|
|
349
|
+
var _yield$_this3$onValid, data;
|
|
350
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
351
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
352
|
+
case 0:
|
|
353
|
+
if (_this3.elementProcessors[elementType]) {
|
|
354
|
+
_context2.next = 2;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
return _context2.abrupt("return", true);
|
|
358
|
+
case 2:
|
|
359
|
+
_context2.next = 4;
|
|
360
|
+
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[elementType].eventCenter, method);
|
|
361
|
+
case 4:
|
|
362
|
+
_yield$_this3$onValid = _context2.sent;
|
|
363
|
+
data = _yield$_this3$onValid.data;
|
|
364
|
+
params.shipping = data === null || data === void 0 ? void 0 : data.data;
|
|
365
|
+
if (data !== null && data !== void 0 && data.success) {
|
|
366
|
+
_context2.next = 11;
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
recordResult = data;
|
|
370
|
+
resolve(data);
|
|
371
|
+
return _context2.abrupt("return", false);
|
|
372
|
+
case 11:
|
|
373
|
+
return _context2.abrupt("return", true);
|
|
374
|
+
case 12:
|
|
375
|
+
case "end":
|
|
376
|
+
return _context2.stop();
|
|
377
|
+
}
|
|
378
|
+
}, _callee2);
|
|
379
|
+
}));
|
|
380
|
+
return function processStep(_x2, _x3) {
|
|
381
|
+
return _ref4.apply(this, arguments);
|
|
382
|
+
};
|
|
383
|
+
}(); // 按顺序处理步骤
|
|
384
|
+
_context3.next = 6;
|
|
385
|
+
return processStep(ElementType.auth, ElementPaymentMethod.AUTH_ELEMENT);
|
|
386
|
+
case 6:
|
|
387
|
+
if (_context3.sent) {
|
|
388
|
+
_context3.next = 8;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
return _context3.abrupt("return");
|
|
392
|
+
case 8:
|
|
393
|
+
_context3.next = 10;
|
|
394
|
+
return processStep(ElementType.address, ElementPaymentMethod.ADDRESS_ELEMENT);
|
|
395
|
+
case 10:
|
|
396
|
+
if (_context3.sent) {
|
|
397
|
+
_context3.next = 12;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
return _context3.abrupt("return");
|
|
401
|
+
case 12:
|
|
402
|
+
if (!_this3.elementProcessors[ElementType.payment]) {
|
|
403
|
+
_context3.next = 19;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
_context3.next = 15;
|
|
407
|
+
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, params);
|
|
408
|
+
case 15:
|
|
409
|
+
_yield$_this3$onValid2 = _context3.sent;
|
|
410
|
+
data = _yield$_this3$onValid2.data;
|
|
411
|
+
recordResult = data;
|
|
412
|
+
resolve(data);
|
|
413
|
+
case 19:
|
|
414
|
+
_context3.next = 26;
|
|
415
|
+
break;
|
|
416
|
+
case 21:
|
|
417
|
+
_context3.prev = 21;
|
|
418
|
+
_context3.t0 = _context3["catch"](0);
|
|
419
|
+
errorResult = {
|
|
420
|
+
error: _objectSpread(_objectSpread({}, ERRORMESSAGE.ERR_DATA_STRUCT_UNRECOGNIZED), {}, {
|
|
421
|
+
context: JSON.stringify(_context3.t0)
|
|
422
|
+
})
|
|
423
|
+
};
|
|
424
|
+
recordResult = errorResult;
|
|
425
|
+
resolve(errorResult);
|
|
426
|
+
case 26:
|
|
427
|
+
case "end":
|
|
428
|
+
return _context3.stop();
|
|
429
|
+
}
|
|
430
|
+
}, _callee3, null, [[0, 21]]);
|
|
431
|
+
}));
|
|
432
|
+
return function (_x) {
|
|
433
|
+
return _ref3.apply(this, arguments);
|
|
434
|
+
};
|
|
435
|
+
}());
|
|
436
|
+
case 10:
|
|
437
|
+
return _context4.abrupt("return", _context4.sent);
|
|
438
|
+
case 11:
|
|
439
|
+
_context4.prev = 11;
|
|
440
|
+
this.elementEventCenter.endEvent(startEventId, recordResult);
|
|
441
|
+
this.changeLoading(false);
|
|
442
|
+
return _context4.finish(11);
|
|
443
|
+
case 15:
|
|
444
|
+
case "end":
|
|
445
|
+
return _context4.stop();
|
|
446
|
+
}
|
|
447
|
+
}, _callee4, this, [[7,, 11, 15]]);
|
|
448
|
+
}));
|
|
449
|
+
function submitPayment() {
|
|
450
|
+
return _submitPayment.apply(this, arguments);
|
|
451
|
+
}
|
|
452
|
+
return submitPayment;
|
|
453
|
+
}()
|
|
262
454
|
}, {
|
|
263
455
|
key: "changeLoading",
|
|
264
456
|
value: function changeLoading(loading) {
|
|
@@ -290,9 +482,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
290
482
|
clearTimeout(_this4.initTimeout);
|
|
291
483
|
_this4.initTimeout = null;
|
|
292
484
|
if (_this4.elementContainerService.getContainerService(data.source)) {
|
|
293
|
-
renderCallback(
|
|
294
|
-
success: true
|
|
295
|
-
});
|
|
485
|
+
renderCallback();
|
|
296
486
|
_this4.elementContainerService.getContainerService(data.source).switchContainerStatus(IContainerStatus.IN_BIZ_FLOW);
|
|
297
487
|
}
|
|
298
488
|
_this4.changeLoading(false);
|
|
@@ -314,10 +504,9 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
314
504
|
});
|
|
315
505
|
this.serviceMap.EventCenter.listen(EVENT.webAppReady.name, function (data) {
|
|
316
506
|
clearTimeout(_this4.initTimeout);
|
|
507
|
+
_this4.initTimeout = null;
|
|
317
508
|
if (_this4.elementContainerService.getContainerService(data.source)) {
|
|
318
|
-
renderCallback(
|
|
319
|
-
success: true
|
|
320
|
-
});
|
|
509
|
+
renderCallback();
|
|
321
510
|
_this4.elementContainerService.getContainerService(data.source).switchContainerStatus(IContainerStatus.IN_BIZ_FLOW);
|
|
322
511
|
}
|
|
323
512
|
_this4.changeLoading(false);
|
|
@@ -335,40 +524,109 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
335
524
|
});
|
|
336
525
|
}
|
|
337
526
|
});
|
|
527
|
+
this.serviceMap.EventCenter.listen(EVENT.submitPromiseCallback.name, function (data) {
|
|
528
|
+
var _this4$submitPayPromi;
|
|
529
|
+
(_this4$submitPayPromi = _this4.submitPayPromise) === null || _this4$submitPayPromi === void 0 || _this4$submitPayPromi.call(_this4, data);
|
|
530
|
+
});
|
|
338
531
|
}
|
|
339
532
|
}, {
|
|
340
533
|
key: "sendRequestAndWaitWebLaunch",
|
|
341
|
-
value: function
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
options
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
534
|
+
value: function () {
|
|
535
|
+
var _sendRequestAndWaitWebLaunch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(renderOptions, readyCallback) {
|
|
536
|
+
var _this5 = this;
|
|
537
|
+
var type, options, containerService, _yield$Promise$all, _yield$Promise$all2, _, obtainDataResult, error;
|
|
538
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
539
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
540
|
+
case 0:
|
|
541
|
+
type = renderOptions.type, options = _objectWithoutProperties(renderOptions, _excluded);
|
|
542
|
+
_context5.prev = 1;
|
|
543
|
+
containerService = this.elementContainerService.getContainerService(type);
|
|
544
|
+
if (containerService) {
|
|
545
|
+
_context5.next = 7;
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
this.handleInitializationError();
|
|
549
|
+
// 容器服务不存在,直接返回
|
|
550
|
+
readyCallback({
|
|
551
|
+
error: ERRORMESSAGE.UI_STATE_ERROR
|
|
552
|
+
});
|
|
553
|
+
return _context5.abrupt("return");
|
|
554
|
+
case 7:
|
|
555
|
+
_context5.next = 9;
|
|
556
|
+
return Promise.all([containerService.createWebLaunchPromise(), this.elementProcessors[type].obtainData()]);
|
|
557
|
+
case 9:
|
|
558
|
+
_yield$Promise$all = _context5.sent;
|
|
559
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
560
|
+
_ = _yield$Promise$all2[0];
|
|
561
|
+
obtainDataResult = _yield$Promise$all2[1];
|
|
562
|
+
containerService === null || containerService === void 0 || containerService.switchContainerStatus(IContainerStatus.READY);
|
|
563
|
+
error = this.getErrorFromResponse(obtainDataResult);
|
|
564
|
+
if (error) {
|
|
565
|
+
// 仅结束resove,传出回调码
|
|
566
|
+
readyCallback({
|
|
567
|
+
error: error
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
if (this.areAllContainersReady()) {
|
|
571
|
+
this.elementContainerService.getContainerServices().forEach(function (_, key) {
|
|
572
|
+
_this5.sendReady(key, options);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
_context5.next = 23;
|
|
576
|
+
break;
|
|
577
|
+
case 19:
|
|
578
|
+
_context5.prev = 19;
|
|
579
|
+
_context5.t0 = _context5["catch"](1);
|
|
580
|
+
this.handleInitializationError();
|
|
581
|
+
readyCallback({
|
|
582
|
+
error: _objectSpread(_objectSpread({}, ERRORMESSAGE.INITALIZE_TIMEOUT.API), {}, {
|
|
583
|
+
traceId: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.traceId
|
|
584
|
+
})
|
|
585
|
+
});
|
|
586
|
+
case 23:
|
|
587
|
+
case "end":
|
|
588
|
+
return _context5.stop();
|
|
589
|
+
}
|
|
590
|
+
}, _callee5, this, [[1, 19]]);
|
|
591
|
+
}));
|
|
592
|
+
function sendRequestAndWaitWebLaunch(_x4, _x5) {
|
|
593
|
+
return _sendRequestAndWaitWebLaunch.apply(this, arguments);
|
|
594
|
+
}
|
|
595
|
+
return sendRequestAndWaitWebLaunch;
|
|
596
|
+
}()
|
|
597
|
+
}, {
|
|
598
|
+
key: "getErrorFromResponse",
|
|
599
|
+
value: function getErrorFromResponse(response) {
|
|
600
|
+
if (isLoadErrorPage(response === null || response === void 0 ? void 0 : response.originActionQueryResult)) {
|
|
601
|
+
var _response$originActio = response.originActionQueryResult,
|
|
602
|
+
traceId = _response$originActio.traceId,
|
|
603
|
+
errorCode = _response$originActio.errorCode;
|
|
604
|
+
var baseError = ERRORMESSAGE.ERR_DATA_STRUCT_UNRECOGNIZED;
|
|
605
|
+
if ([ERRORMESSAGE.INQUIRY_PAYMENT_SESSION_FAILED.code, ERRORMESSAGE.UNKNOWN_EXCEPTION.code].includes(errorCode)) {
|
|
606
|
+
baseError = ERRORMESSAGE[errorCode];
|
|
361
607
|
}
|
|
608
|
+
return _objectSpread(_objectSpread({}, baseError), {}, {
|
|
609
|
+
traceId: traceId !== null && traceId !== void 0 ? traceId : ''
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
}, {
|
|
615
|
+
key: "areAllContainersReady",
|
|
616
|
+
value: function areAllContainersReady() {
|
|
617
|
+
var container = this.elementContainerService.getContainerServices();
|
|
618
|
+
return _toConsumableArray(container.values()).every(function (service) {
|
|
619
|
+
return service.getContainerStatus() === IContainerStatus.READY;
|
|
362
620
|
});
|
|
363
621
|
}
|
|
364
622
|
}, {
|
|
365
623
|
key: "sendReady",
|
|
366
624
|
value: function sendReady(type, options) {
|
|
367
|
-
var _this$
|
|
368
|
-
var paymentResult = (_this$
|
|
625
|
+
var _this$elementProcesso2, _paymentSessionObj$co, _paymentSessionObj$pa, _paymentResult$origin;
|
|
626
|
+
var paymentResult = (_this$elementProcesso2 = this.elementProcessors[ElementType.payment]) === null || _this$elementProcesso2 === void 0 ? void 0 : _this$elementProcesso2.getObtainDataRes();
|
|
369
627
|
var paymentContext = this.elementContainer.getPaymentContext();
|
|
370
628
|
var paymentSessionObj = paymentContext.paymentSessionObj;
|
|
371
|
-
var isConnect = paymentSessionObj.connectFactor.enableConnect && ((_paymentSessionObj$pa = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa === void 0 ? void 0 : _paymentSessionObj$pa.productScene) === ProductSceneEnum.ELEMENT_PAYMENT;
|
|
629
|
+
var isConnect = ((_paymentSessionObj$co = paymentSessionObj.connectFactor) === null || _paymentSessionObj$co === void 0 ? void 0 : _paymentSessionObj$co.enableConnect) && ((_paymentSessionObj$pa = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa === void 0 ? void 0 : _paymentSessionObj$pa.productScene) === ProductSceneEnum.ELEMENT_PAYMENT;
|
|
372
630
|
if (!(paymentResult !== null && paymentResult !== void 0 && (_paymentResult$origin = paymentResult.originActionQueryResult) !== null && _paymentResult$origin !== void 0 && _paymentResult$origin.success) && isConnect) {
|
|
373
631
|
var _this$onEventCallback;
|
|
374
632
|
clearTimeout(this.initTimeout);
|
|
@@ -392,16 +650,16 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
392
650
|
}, {
|
|
393
651
|
key: "updatePayment",
|
|
394
652
|
value: function () {
|
|
395
|
-
var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
653
|
+
var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(paymentSessionData) {
|
|
396
654
|
var _this6 = this;
|
|
397
|
-
return _regeneratorRuntime().wrap(function
|
|
398
|
-
while (1) switch (
|
|
655
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
656
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
399
657
|
case 0:
|
|
400
|
-
return
|
|
401
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
658
|
+
return _context7.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
659
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(resolve) {
|
|
402
660
|
var prePaymentSessionData, data, LOCAL_MOCK;
|
|
403
|
-
return _regeneratorRuntime().wrap(function
|
|
404
|
-
while (1) switch (
|
|
661
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
662
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
405
663
|
case 0:
|
|
406
664
|
if (checkCanUpdate({
|
|
407
665
|
status: _this6.elementContainer.getStatus(),
|
|
@@ -409,18 +667,18 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
409
667
|
newPaymentSessionData: paymentSessionData,
|
|
410
668
|
oldPaymentSessionData: _this6.options.sessionData
|
|
411
669
|
})) {
|
|
412
|
-
|
|
670
|
+
_context6.next = 2;
|
|
413
671
|
break;
|
|
414
672
|
}
|
|
415
|
-
return
|
|
673
|
+
return _context6.abrupt("return", resolve(false));
|
|
416
674
|
case 2:
|
|
417
675
|
prePaymentSessionData = _this6.elementContainer.getPaymentContext().paymentSession;
|
|
418
676
|
_this6.elementContainer.updatePaymentSessionData(paymentSessionData);
|
|
419
677
|
// 1、数据获取
|
|
420
|
-
|
|
678
|
+
_context6.next = 6;
|
|
421
679
|
return _this6.elementProcessors[ElementType.payment].obtainData();
|
|
422
680
|
case 6:
|
|
423
|
-
data =
|
|
681
|
+
data = _context6.sent;
|
|
424
682
|
LOCAL_MOCK = window.location.href.indexOf('LOCAL_MOCK=1') !== -1; // 2、发送update消息
|
|
425
683
|
Object.values(_this6.elementProcessors).forEach(function (processor) {
|
|
426
684
|
processor.update({
|
|
@@ -441,21 +699,21 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
441
699
|
});
|
|
442
700
|
case 10:
|
|
443
701
|
case "end":
|
|
444
|
-
return
|
|
702
|
+
return _context6.stop();
|
|
445
703
|
}
|
|
446
|
-
},
|
|
704
|
+
}, _callee6);
|
|
447
705
|
}));
|
|
448
|
-
return function (
|
|
706
|
+
return function (_x7) {
|
|
449
707
|
return _ref5.apply(this, arguments);
|
|
450
708
|
};
|
|
451
709
|
}()));
|
|
452
710
|
case 1:
|
|
453
711
|
case "end":
|
|
454
|
-
return
|
|
712
|
+
return _context7.stop();
|
|
455
713
|
}
|
|
456
|
-
},
|
|
714
|
+
}, _callee7);
|
|
457
715
|
}));
|
|
458
|
-
function updatePayment(
|
|
716
|
+
function updatePayment(_x6) {
|
|
459
717
|
return _updatePayment.apply(this, arguments);
|
|
460
718
|
}
|
|
461
719
|
return updatePayment;
|
|
@@ -475,8 +733,13 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
475
733
|
}, {
|
|
476
734
|
key: "destroy",
|
|
477
735
|
value: function destroy() {
|
|
478
|
-
this.
|
|
479
|
-
|
|
736
|
+
var startEventId = this.elementEventCenter.registerEvent(EXPOSURE_API_EVENT.DESTORY);
|
|
737
|
+
try {
|
|
738
|
+
this.destroyHandle();
|
|
739
|
+
this.setControllerStatusOrView(IElementStatus.DESTROYED);
|
|
740
|
+
} finally {
|
|
741
|
+
this.elementEventCenter.endEvent(startEventId);
|
|
742
|
+
}
|
|
480
743
|
}
|
|
481
744
|
}, {
|
|
482
745
|
key: "setControllerStatusOrView",
|