@alipay/ams-checkout 0.0.1744283958-dev.1 → 0.0.1744283958-dev.4
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/constant/index.d.ts +3 -0
- package/esm/constant/index.js +3 -0
- package/esm/core/component/element/elementContainerService/containerService.d.ts +2 -0
- package/esm/core/component/element/elementContainerService/containerService.js +7 -1
- package/esm/core/component/element/elementContainerService/index.d.ts +1 -0
- package/esm/core/component/element/elementContainerService/index.js +5 -0
- package/esm/core/component/element/elementController/index.d.ts +1 -0
- package/esm/core/component/element/elementController/index.js +137 -99
- package/esm/core/component/element/elementProcessor/addressProcessor.d.ts +4 -1
- package/esm/core/component/element/elementProcessor/addressProcessor.js +26 -5
- package/esm/core/component/element/elementProcessor/authProcessor.d.ts +4 -1
- package/esm/core/component/element/elementProcessor/authProcessor.js +26 -3
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +26 -20
- package/esm/core/component/element/mock.d.ts +2 -0
- package/esm/core/component/element/mock.js +360 -0
- package/package.json +1 -1
package/esm/constant/index.d.ts
CHANGED
@@ -213,6 +213,9 @@ export declare const EVENT: {
|
|
213
213
|
updated: {
|
214
214
|
name: string;
|
215
215
|
};
|
216
|
+
webAppReady: {
|
217
|
+
name: string;
|
218
|
+
};
|
216
219
|
};
|
217
220
|
export declare const COMPONENT_CONTAINER_ID = "ams-component-container";
|
218
221
|
export declare const COMPONENT_SECTION_ID = "ams-component-section";
|
package/esm/constant/index.js
CHANGED
@@ -13,6 +13,7 @@ export declare class ContainerController {
|
|
13
13
|
private instanceId;
|
14
14
|
private containerService;
|
15
15
|
private eventService;
|
16
|
+
private containerElement;
|
16
17
|
private _globalData?;
|
17
18
|
constructor({ type, instanceId, selector, processor, options, }: {
|
18
19
|
type: string;
|
@@ -22,6 +23,7 @@ export declare class ContainerController {
|
|
22
23
|
options: any;
|
23
24
|
});
|
24
25
|
private addEventListener;
|
26
|
+
getContainerElement(): HTMLDivElement;
|
25
27
|
createWebLaunchPromise(): Promise<unknown>;
|
26
28
|
switchContainerStatus(status: IContainerStatus): void;
|
27
29
|
getContainerStatus(): IContainerStatus;
|
@@ -29,6 +29,7 @@ export var ContainerController = /*#__PURE__*/function () {
|
|
29
29
|
_defineProperty(this, "instanceId", void 0);
|
30
30
|
_defineProperty(this, "containerService", void 0);
|
31
31
|
_defineProperty(this, "eventService", void 0);
|
32
|
+
_defineProperty(this, "containerElement", void 0);
|
32
33
|
_defineProperty(this, "_globalData", void 0);
|
33
34
|
this._globalData = new Map();
|
34
35
|
this.switchContainerStatus(IContainerStatus.INITING);
|
@@ -39,7 +40,7 @@ export var ContainerController = /*#__PURE__*/function () {
|
|
39
40
|
sdkVersion: '',
|
40
41
|
webAppVersion: ''
|
41
42
|
});
|
42
|
-
this.containerService.load({
|
43
|
+
this.containerElement = this.containerService.load({
|
43
44
|
type: DisplayTypeEnum.inline,
|
44
45
|
platform: PlatformEnum.desktop,
|
45
46
|
isRetention: false,
|
@@ -72,6 +73,11 @@ export var ContainerController = /*#__PURE__*/function () {
|
|
72
73
|
}
|
73
74
|
});
|
74
75
|
}
|
76
|
+
}, {
|
77
|
+
key: "getContainerElement",
|
78
|
+
value: function getContainerElement() {
|
79
|
+
return this.containerElement;
|
80
|
+
}
|
75
81
|
}, {
|
76
82
|
key: "createWebLaunchPromise",
|
77
83
|
value: function createWebLaunchPromise() {
|
@@ -9,6 +9,7 @@ export declare class ElementContainerService {
|
|
9
9
|
addContainerService(name: ElementType, service: ContainerController): void;
|
10
10
|
getContainerService(name: ElementType): ContainerController | undefined;
|
11
11
|
getContainerServices(): Map<ElementType, ContainerController>;
|
12
|
+
destroy(): void;
|
12
13
|
mount({ type, selector, processor, options }: {
|
13
14
|
type: any;
|
14
15
|
selector: any;
|
@@ -30,6 +30,11 @@ export var ElementContainerService = /*#__PURE__*/function () {
|
|
30
30
|
value: function getContainerServices() {
|
31
31
|
return this.containerServices;
|
32
32
|
}
|
33
|
+
}, {
|
34
|
+
key: "destroy",
|
35
|
+
value: function destroy() {
|
36
|
+
this.containerServices = new Map();
|
37
|
+
}
|
33
38
|
}, {
|
34
39
|
key: "mount",
|
35
40
|
value: function mount(_ref2) {
|
@@ -29,8 +29,10 @@ import { destroyModal } from "../../../../plugin/component/popupWindow.style";
|
|
29
29
|
import { ProductSceneEnum } from "../../../../types";
|
30
30
|
import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
|
31
31
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
32
|
-
import {
|
32
|
+
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
33
|
+
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode } from "../type";
|
33
34
|
import { checkCanMount, checkCanUpdate, handleRedirect } from "../util";
|
35
|
+
var TIMEOUT_DURATION = 10000;
|
34
36
|
var ElementController = /*#__PURE__*/function () {
|
35
37
|
// 新增变量
|
36
38
|
|
@@ -41,13 +43,16 @@ var ElementController = /*#__PURE__*/function () {
|
|
41
43
|
_defineProperty(this, "serviceMap", void 0);
|
42
44
|
_defineProperty(this, "loading", void 0);
|
43
45
|
_defineProperty(this, "elementProcessors", void 0);
|
46
|
+
_defineProperty(this, "initTimeout", void 0);
|
44
47
|
_defineProperty(this, "elementContainerService", void 0);
|
45
|
-
_defineProperty(this, "onValidateFunc", function (event, params) {
|
48
|
+
_defineProperty(this, "onValidateFunc", function (event, target, params) {
|
46
49
|
return new Promise(function (resolve) {
|
47
50
|
event.emitAndListen({
|
48
51
|
event: ElementPaymentEvent.VALIDATE,
|
49
52
|
data: {
|
50
|
-
params: _objectSpread({}, params)
|
53
|
+
params: _objectSpread({}, params),
|
54
|
+
target: target,
|
55
|
+
source: ElementPaymentMethod.CONTAINER_ELEMENT
|
51
56
|
}
|
52
57
|
}, function (result) {
|
53
58
|
resolve(result);
|
@@ -98,75 +103,96 @@ var ElementController = /*#__PURE__*/function () {
|
|
98
103
|
key: "mount",
|
99
104
|
value: function mount(renderOptions, sdkSelector, cashier) {
|
100
105
|
var _this = this;
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
return new Promise(function (resolve) {
|
107
|
+
var _checkCanMount = checkCanMount({
|
108
|
+
sdkSelector: sdkSelector,
|
109
|
+
status: _this.elementContainer.getStatus(),
|
110
|
+
containerService: _this.elementContainerService.getContainerService(renderOptions.type)
|
111
|
+
}),
|
112
|
+
success = _checkCanMount.success,
|
113
|
+
errorMsg = _checkCanMount.errorMsg;
|
114
|
+
if (!success) {
|
115
|
+
_this.onEventCallback({
|
116
|
+
code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
|
117
|
+
message: errorMsg
|
118
|
+
});
|
119
|
+
resolve({
|
120
|
+
success: false
|
121
|
+
});
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
clearTimeout(_this.initTimeout);
|
125
|
+
_this.initTimeout = null;
|
126
|
+
_this.initTimeout = setTimeout(function () {
|
127
|
+
clearTimeout(_this.initTimeout);
|
128
|
+
_this.initTimeout = null;
|
129
|
+
_this.changeLoading(false);
|
130
|
+
_this.elementContainer.setStatus(IContainerStatus.READY);
|
131
|
+
_this.elementContainerService.getContainerServices().forEach(function (value) {
|
132
|
+
value.getContainerElement().remove();
|
133
|
+
});
|
134
|
+
_this.elementContainerService.destroy();
|
135
|
+
}, TIMEOUT_DURATION);
|
136
|
+
_this.changeLoading(true);
|
137
|
+
var startBizFlowData = {
|
138
|
+
paymentSession: _this.options.sessionData,
|
139
|
+
displayInfo: _objectSpread(_objectSpread({}, renderOptions), {}, {
|
140
|
+
appendAliasContainerId: true
|
141
|
+
})
|
142
|
+
};
|
143
|
+
if (cashier && renderOptions.sessionData) {
|
144
|
+
startBizFlowData.paymentSession = renderOptions.sessionData;
|
145
|
+
}
|
146
|
+
_this.elementContainer.startBizFlow(startBizFlowData).catch(function (error) {
|
147
|
+
_this.onEventCallback({
|
148
|
+
code: EventCallbackCode.SDK_CREATEPAYMENT_PARAMETER_ERROR,
|
149
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || 'Initialization parameter exception.'
|
150
|
+
});
|
151
|
+
_this.changeLoading(false);
|
152
|
+
return;
|
112
153
|
});
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
appendAliasContainerId: true
|
120
|
-
})
|
121
|
-
};
|
122
|
-
if (cashier && renderOptions.sessionData) {
|
123
|
-
startBizFlowData.paymentSession = renderOptions.sessionData;
|
124
|
-
}
|
125
|
-
this.elementContainer.startBizFlow(startBizFlowData).catch(function (error) {
|
126
|
-
_this.onEventCallback({
|
127
|
-
code: EventCallbackCode.SDK_CREATEPAYMENT_PARAMETER_ERROR,
|
128
|
-
message: (error === null || error === void 0 ? void 0 : error.message) || 'Initialization parameter exception.'
|
154
|
+
_this.initElementProcessors(renderOptions.type);
|
155
|
+
_this.elementContainerService.mount({
|
156
|
+
type: renderOptions.type,
|
157
|
+
selector: sdkSelector,
|
158
|
+
processor: _this.elementProcessors[renderOptions.type],
|
159
|
+
options: renderOptions
|
129
160
|
});
|
130
|
-
_this.
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
this.sendRequestAndWaitWebLaunch(renderOptions);
|
143
|
-
this.addEventListener();
|
144
|
-
this.serviceMap.EventCenter.addIFrame(this.elementContainerService.getContainerService(renderOptions.type).getContainerService().getWebApp());
|
145
|
-
return {
|
146
|
-
getValue: this.elementProcessors[renderOptions.type].getValue.bind(this.elementProcessors[renderOptions.type]),
|
147
|
-
on: function on(event, callback) {
|
148
|
-
_this.elementProcessors[renderOptions.type].registerEventListener(event, callback);
|
161
|
+
_this.elementProcessors[renderOptions.type].registerEventCenter(_this.elementContainerService.getEventService(renderOptions.type));
|
162
|
+
_this.elementProcessors[renderOptions.type].beforeMount();
|
163
|
+
_this.sendRequestAndWaitWebLaunch(renderOptions);
|
164
|
+
function readyCallback(payload) {
|
165
|
+
var _this2 = this;
|
166
|
+
var resultData = _objectSpread({
|
167
|
+
getValue: this.elementProcessors[renderOptions.type].getValue.bind(this.elementProcessors[renderOptions.type]),
|
168
|
+
on: function on(event, callback) {
|
169
|
+
_this2.elementProcessors[renderOptions.type].registerEventListener(event, callback);
|
170
|
+
}
|
171
|
+
}, payload);
|
172
|
+
resolve(resultData);
|
149
173
|
}
|
150
|
-
|
174
|
+
_this.addEventListener(readyCallback);
|
175
|
+
_this.serviceMap.EventCenter.addIFrame(_this.elementContainerService.getContainerService(renderOptions.type).getContainerService().getWebApp());
|
176
|
+
});
|
151
177
|
}
|
152
178
|
}, {
|
153
179
|
key: "submitPayment",
|
154
180
|
value: function submitPayment() {
|
155
|
-
var
|
181
|
+
var _this3 = this;
|
156
182
|
this.changeLoading(true);
|
157
183
|
new Promise( /*#__PURE__*/function () {
|
158
184
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve) {
|
159
|
-
var params,
|
185
|
+
var params, _this3$elementProcess, _result$data, _result$data2, result, _this3$elementProcess2, _result$data3, _result$data4, _result, _this3$elementProcess3;
|
160
186
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
161
187
|
while (1) switch (_context.prev = _context.next) {
|
162
188
|
case 0:
|
163
189
|
params = {};
|
164
|
-
if (!
|
190
|
+
if (!_this3.elementProcessors[ElementType.auth]) {
|
165
191
|
_context.next = 8;
|
166
192
|
break;
|
167
193
|
}
|
168
194
|
_context.next = 4;
|
169
|
-
return
|
195
|
+
return _this3.onValidateFunc((_this3$elementProcess = _this3.elementProcessors[ElementType.auth]) === null || _this3$elementProcess === void 0 ? void 0 : _this3$elementProcess.eventCenter, ElementPaymentMethod.AUTH_ELEMENT);
|
170
196
|
case 4:
|
171
197
|
result = _context.sent;
|
172
198
|
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;
|
@@ -176,12 +202,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
176
202
|
}
|
177
203
|
return _context.abrupt("return", resolve(undefined));
|
178
204
|
case 8:
|
179
|
-
if (!
|
205
|
+
if (!_this3.elementProcessors[ElementType.address]) {
|
180
206
|
_context.next = 15;
|
181
207
|
break;
|
182
208
|
}
|
183
209
|
_context.next = 11;
|
184
|
-
return
|
210
|
+
return _this3.onValidateFunc((_this3$elementProcess2 = _this3.elementProcessors[ElementType.address]) === null || _this3$elementProcess2 === void 0 ? void 0 : _this3$elementProcess2.eventCenter, ElementPaymentMethod.ADDRESS_ELEMENT);
|
185
211
|
case 11:
|
186
212
|
_result = _context.sent;
|
187
213
|
params.shipping = (_result$data3 = _result.data) === null || _result$data3 === void 0 ? void 0 : _result$data3.data;
|
@@ -191,13 +217,13 @@ var ElementController = /*#__PURE__*/function () {
|
|
191
217
|
}
|
192
218
|
return _context.abrupt("return", resolve(undefined));
|
193
219
|
case 15:
|
194
|
-
if (!
|
220
|
+
if (!_this3.elementProcessors[ElementType.payment]) {
|
195
221
|
_context.next = 25;
|
196
222
|
break;
|
197
223
|
}
|
198
224
|
_context.prev = 16;
|
199
225
|
_context.next = 19;
|
200
|
-
return
|
226
|
+
return _this3.onValidateFunc((_this3$elementProcess3 = _this3.elementProcessors[ElementType.payment]) === null || _this3$elementProcess3 === void 0 ? void 0 : _this3$elementProcess3.eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, params);
|
201
227
|
case 19:
|
202
228
|
return _context.abrupt("return", resolve(undefined));
|
203
229
|
case 22:
|
@@ -216,9 +242,9 @@ var ElementController = /*#__PURE__*/function () {
|
|
216
242
|
return _ref2.apply(this, arguments);
|
217
243
|
};
|
218
244
|
}()).then(function () {
|
219
|
-
|
245
|
+
_this3.changeLoading(false);
|
220
246
|
}, function () {
|
221
|
-
|
247
|
+
_this3.changeLoading(false);
|
222
248
|
});
|
223
249
|
}
|
224
250
|
}, {
|
@@ -242,17 +268,24 @@ var ElementController = /*#__PURE__*/function () {
|
|
242
268
|
}
|
243
269
|
}, {
|
244
270
|
key: "addEventListener",
|
245
|
-
value: function addEventListener() {
|
246
|
-
var
|
271
|
+
value: function addEventListener(renderCallback) {
|
272
|
+
var _this4 = this;
|
247
273
|
this.serviceMap.EventCenter.listen(ElementPaymentEvent.CALLBACK, function (data) {
|
248
|
-
if (
|
249
|
-
var
|
250
|
-
(
|
274
|
+
if (_this4.elementProcessors[data.source] && _this4.elementProcessors[data.source].eventListener[data.event]) {
|
275
|
+
var _this4$elementProcess, _this4$elementProcess2;
|
276
|
+
(_this4$elementProcess = (_this4$elementProcess2 = _this4.elementProcessors[data.source].eventListener)[data.event]) === null || _this4$elementProcess === void 0 || _this4$elementProcess.call(_this4$elementProcess2, data.data);
|
251
277
|
}
|
252
278
|
});
|
253
279
|
this.serviceMap.EventCenter.listen(EVENT.sizeChanged.name, function (data) {
|
254
|
-
|
255
|
-
|
280
|
+
clearTimeout(_this4.initTimeout);
|
281
|
+
_this4.initTimeout = null;
|
282
|
+
if (_this4.elementContainerService.getContainerService(data.source)) {
|
283
|
+
renderCallback({
|
284
|
+
success: true
|
285
|
+
});
|
286
|
+
_this4.elementContainerService.getContainerService(data.source).switchContainerStatus(IContainerStatus.IN_BIZ_FLOW);
|
287
|
+
}
|
288
|
+
_this4.changeLoading(false);
|
256
289
|
// 遍历containerService中的所有container查看是否所有状态都是IN_BIZ_FLOW
|
257
290
|
// const allContainersInBizFlow = Object.values(this.elementContainerService.getContainerServices()).every(
|
258
291
|
// (containerService) => containerService.getContainerStatus() === IContainerStatus.IN_BIZ_FLOW,
|
@@ -264,27 +297,37 @@ var ElementController = /*#__PURE__*/function () {
|
|
264
297
|
this.serviceMap.EventCenter.listen(EVENT.redirect.name, function (data) {
|
265
298
|
handleRedirect(data);
|
266
299
|
});
|
300
|
+
this.serviceMap.EventCenter.listen(EVENT.webAppReady.name, function (data) {
|
301
|
+
if (_this4.elementContainerService.getContainerService(data.source)) {
|
302
|
+
renderCallback({
|
303
|
+
success: true
|
304
|
+
});
|
305
|
+
_this4.elementContainerService.getContainerService(data.source).switchContainerStatus(IContainerStatus.IN_BIZ_FLOW);
|
306
|
+
}
|
307
|
+
_this4.changeLoading(false);
|
308
|
+
});
|
267
309
|
}
|
268
310
|
}, {
|
269
311
|
key: "sendRequestAndWaitWebLaunch",
|
270
312
|
value: function sendRequestAndWaitWebLaunch(renderOptions) {
|
271
|
-
var
|
313
|
+
var _this5 = this;
|
272
314
|
var type = renderOptions.type,
|
273
315
|
options = _objectWithoutProperties(renderOptions, _excluded);
|
274
316
|
var webLaunchPromise = this.elementContainerService.getContainerService(type).createWebLaunchPromise();
|
275
317
|
Promise.all([webLaunchPromise, this.elementProcessors[type].obtainData()]).then(function (_ref3) {
|
318
|
+
var _this5$elementContain;
|
276
319
|
var _ref4 = _slicedToArray(_ref3, 2),
|
277
320
|
_webLaunchRes = _ref4[0],
|
278
321
|
_obtainDataRes = _ref4[1];
|
279
|
-
|
322
|
+
(_this5$elementContain = _this5.elementContainerService.getContainerService(type)) === null || _this5$elementContain === void 0 || _this5$elementContain.switchContainerStatus(IContainerStatus.READY);
|
280
323
|
var allReady = true;
|
281
|
-
|
324
|
+
_this5.elementContainerService.getContainerServices().forEach(function (item) {
|
282
325
|
if (!allReady) return;
|
283
326
|
allReady = item.getContainerStatus() === IContainerStatus.READY;
|
284
327
|
});
|
285
328
|
if (allReady) {
|
286
|
-
|
287
|
-
|
329
|
+
_this5.elementContainerService.getContainerServices().forEach(function (value, key) {
|
330
|
+
_this5.sendReady(key, options);
|
288
331
|
});
|
289
332
|
}
|
290
333
|
});
|
@@ -296,69 +339,64 @@ var ElementController = /*#__PURE__*/function () {
|
|
296
339
|
var paymentResult = (_this$elementProcesso = this.elementProcessors[ElementType.payment]) === null || _this$elementProcesso === void 0 ? void 0 : _this$elementProcesso.getObtainDataRes();
|
297
340
|
var paymentContext = this.elementContainer.getPaymentContext();
|
298
341
|
var params = _objectSpread(_objectSpread({}, options), {}, {
|
299
|
-
originActionQueryResult: paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.
|
300
|
-
originOneAccountQueryResult: paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.
|
342
|
+
originActionQueryResult: paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.originActionQueryResult,
|
343
|
+
originOneAccountQueryResult: paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.originOneAccountQueryResult,
|
301
344
|
paymentSessionData: paymentContext === null || paymentContext === void 0 ? void 0 : paymentContext.paymentSessionId,
|
302
345
|
sessionResult: (paymentContext === null || paymentContext === void 0 ? void 0 : paymentContext.paymentSessionObj) || {}
|
303
346
|
});
|
304
|
-
if (type === ElementType.address) {
|
305
|
-
var _paymentResult$origin;
|
306
|
-
params.prefillValue = (paymentResult === null || paymentResult === void 0 || (_paymentResult$origin = paymentResult.originOneAccountQuery) === null || _paymentResult$origin === void 0 ? void 0 : _paymentResult$origin.shippings) || [];
|
307
|
-
} else if (type === ElementType.payment) {
|
308
|
-
params.queryResult = paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.originActionQuery;
|
309
|
-
}
|
310
347
|
this.elementProcessors[type].onReady(params);
|
311
348
|
}
|
312
349
|
}, {
|
313
350
|
key: "updatePayment",
|
314
351
|
value: function () {
|
315
352
|
var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(paymentSessionData) {
|
316
|
-
var
|
353
|
+
var _this6 = this;
|
317
354
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
318
355
|
while (1) switch (_context3.prev = _context3.next) {
|
319
356
|
case 0:
|
320
357
|
return _context3.abrupt("return", new Promise( /*#__PURE__*/function () {
|
321
358
|
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve) {
|
322
|
-
var prePaymentSessionData, data;
|
359
|
+
var prePaymentSessionData, data, LOCAL_MOCK;
|
323
360
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
324
361
|
while (1) switch (_context2.prev = _context2.next) {
|
325
362
|
case 0:
|
326
363
|
if (checkCanUpdate({
|
327
|
-
status:
|
328
|
-
paymentContainerService:
|
364
|
+
status: _this6.elementContainer.getStatus(),
|
365
|
+
paymentContainerService: _this6.elementContainerService.getContainerService(ElementType.payment),
|
329
366
|
newPaymentSessionData: paymentSessionData,
|
330
|
-
oldPaymentSessionData:
|
367
|
+
oldPaymentSessionData: _this6.options.sessionData
|
331
368
|
})) {
|
332
369
|
_context2.next = 2;
|
333
370
|
break;
|
334
371
|
}
|
335
372
|
return _context2.abrupt("return", resolve(false));
|
336
373
|
case 2:
|
337
|
-
prePaymentSessionData =
|
338
|
-
|
374
|
+
prePaymentSessionData = _this6.elementContainer.getPaymentContext().paymentSession;
|
375
|
+
_this6.elementContainer.updatePaymentSessionData(paymentSessionData);
|
339
376
|
// 1、数据获取
|
340
377
|
_context2.next = 6;
|
341
|
-
return
|
378
|
+
return _this6.elementProcessors[ElementType.payment].obtainData();
|
342
379
|
case 6:
|
343
380
|
data = _context2.sent;
|
344
|
-
// 2、发送update消息
|
345
|
-
Object.values(
|
381
|
+
LOCAL_MOCK = window.location.href.indexOf('LOCAL_MOCK=1') !== -1; // 2、发送update消息
|
382
|
+
Object.values(_this6.elementProcessors).forEach(function (processor) {
|
346
383
|
processor.update({
|
347
384
|
data: {
|
348
|
-
|
385
|
+
originActionQueryResult: LOCAL_MOCK ? sdkActionUpdate : data.originActionQueryResult,
|
386
|
+
originOneAccountQueryResult: LOCAL_MOCK ? oneAccountUpdate : data.originOneAccountQueryResult
|
349
387
|
},
|
350
388
|
paymentSessionData: paymentSessionData
|
351
389
|
});
|
352
390
|
});
|
353
391
|
// 3、返回更新结果
|
354
|
-
|
392
|
+
_this6.serviceMap.EventCenter.listen(EVENT.updated.name, function (data) {
|
355
393
|
// 若更新不成功,还原core.paymentContext信息
|
356
394
|
if (!data.success) {
|
357
|
-
|
395
|
+
_this6.elementContainer.updatePaymentSessionData(prePaymentSessionData);
|
358
396
|
}
|
359
397
|
return resolve(data.success || false);
|
360
398
|
});
|
361
|
-
case
|
399
|
+
case 10:
|
362
400
|
case "end":
|
363
401
|
return _context2.stop();
|
364
402
|
}
|
@@ -382,15 +420,15 @@ var ElementController = /*#__PURE__*/function () {
|
|
382
420
|
}, {
|
383
421
|
key: "destroy",
|
384
422
|
value: function destroy() {
|
385
|
-
this.
|
386
|
-
|
387
|
-
});
|
423
|
+
this.elementContainer.destroy();
|
424
|
+
this.elementContainer.setStatus(IContainerStatus.DESTROYED);
|
388
425
|
// popup未注册会报错,但element不需要感知popup是否被注册
|
389
426
|
try {
|
390
427
|
destroyModal(); // 关闭popup弹窗
|
391
428
|
} catch (error) {}
|
392
|
-
this.
|
393
|
-
|
429
|
+
this.elementContainerService.getContainerServices().forEach(function (value) {
|
430
|
+
value.getContainerElement().remove();
|
431
|
+
});
|
394
432
|
}
|
395
433
|
}]);
|
396
434
|
return ElementController;
|
@@ -12,6 +12,9 @@ declare class AddressProcessor extends BaseElementProcessor {
|
|
12
12
|
}): string;
|
13
13
|
obtainData(): any;
|
14
14
|
getValue(hasValidate?: boolean): any;
|
15
|
-
update(data
|
15
|
+
update({ data, paymentSessionData }: {
|
16
|
+
data: any;
|
17
|
+
paymentSessionData: any;
|
18
|
+
}): void;
|
16
19
|
}
|
17
20
|
export default AddressProcessor;
|
@@ -1,4 +1,10 @@
|
|
1
1
|
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); }
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
3
|
+
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."); }
|
4
|
+
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); }
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
2
8
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
3
9
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
4
10
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
@@ -11,6 +17,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
|
|
11
17
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
12
18
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
13
19
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
20
|
+
import { parseSessionData } from "../..";
|
14
21
|
import PackageJson from "../../../../../package.json";
|
15
22
|
import { generateIframeSrc as _generateIframeSrc } from "../util";
|
16
23
|
import BaseElementProcessor from "./baseElementProcessor";
|
@@ -24,7 +31,7 @@ var AddressProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
24
31
|
_createClass(AddressProcessor, [{
|
25
32
|
key: "onReady",
|
26
33
|
value: function onReady(extraParam) {
|
27
|
-
var _this$elementContaine, _this$elementContaine2, _this$elementContaine3;
|
34
|
+
var _this$elementContaine, _this$elementContaine2, _this$elementContaine3, _extraParam$originOne;
|
28
35
|
this.eventCenter.dispatchToApp({
|
29
36
|
event: 'renderComponent',
|
30
37
|
data: {
|
@@ -37,7 +44,8 @@ var AddressProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
37
44
|
screenWidth: screen.width
|
38
45
|
},
|
39
46
|
appearance: (_this$elementContaine2 = this.elementContainer.getPaymentContext()) === null || _this$elementContaine2 === void 0 ? void 0 : _this$elementContaine2.displayInfo.appearance,
|
40
|
-
sessionResult: (_this$elementContaine3 = this.elementContainer.getPaymentContext()) === null || _this$elementContaine3 === void 0 ? void 0 : _this$elementContaine3.paymentSessionObj
|
47
|
+
sessionResult: (_this$elementContaine3 = this.elementContainer.getPaymentContext()) === null || _this$elementContaine3 === void 0 ? void 0 : _this$elementContaine3.paymentSessionObj,
|
48
|
+
prefillValue: (extraParam === null || extraParam === void 0 || (_extraParam$originOne = extraParam.originOneAccountQueryResult) === null || _extraParam$originOne === void 0 ? void 0 : _extraParam$originOne.shippings) || []
|
41
49
|
},
|
42
50
|
target: 'ADDRESS_ELEMENT'
|
43
51
|
}
|
@@ -113,10 +121,23 @@ var AddressProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
113
121
|
}
|
114
122
|
}, {
|
115
123
|
key: "update",
|
116
|
-
value: function update(
|
124
|
+
value: function update(_ref3) {
|
125
|
+
var data = _ref3.data,
|
126
|
+
paymentSessionData = _ref3.paymentSessionData;
|
127
|
+
var _parseSessionData = parseSessionData(paymentSessionData),
|
128
|
+
_parseSessionData2 = _slicedToArray(_parseSessionData, 2),
|
129
|
+
parseData = _parseSessionData2[0],
|
130
|
+
sessionData = _parseSessionData2[1];
|
117
131
|
// 实现 update 方法的具体逻辑
|
118
|
-
|
119
|
-
|
132
|
+
this.eventCenter.dispatchToApp({
|
133
|
+
event: 'updatePayment',
|
134
|
+
data: {
|
135
|
+
paymentSessionData: paymentSessionData,
|
136
|
+
data: data,
|
137
|
+
sessionResult: parseData,
|
138
|
+
sessionData: sessionData
|
139
|
+
}
|
140
|
+
});
|
120
141
|
}
|
121
142
|
}]);
|
122
143
|
return AddressProcessor;
|
@@ -12,6 +12,9 @@ declare class AuthProcessor extends BaseElementProcessor {
|
|
12
12
|
}): string;
|
13
13
|
obtainData(): any;
|
14
14
|
getValue(): any;
|
15
|
-
update(data
|
15
|
+
update({ data, paymentSessionData }: {
|
16
|
+
data: any;
|
17
|
+
paymentSessionData: any;
|
18
|
+
}): void;
|
16
19
|
}
|
17
20
|
export default AuthProcessor;
|