@alipay/ams-checkout 1.10.0 → 1.11.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/core/bus/ability/callback.d.ts +9 -0
- package/esm/core/bus/ability/callback.js +55 -0
- package/esm/core/bus/ability/security.d.ts +10 -0
- package/esm/core/bus/ability/security.js +104 -0
- package/esm/core/bus/ability/tracker.d.ts +9 -0
- package/esm/core/bus/ability/tracker.js +77 -0
- package/esm/core/bus/index.d.ts +125 -0
- package/esm/core/bus/index.js +366 -0
- package/esm/core/bus/interface.d.ts +32 -0
- package/esm/core/bus/interface.js +35 -0
- package/esm/core/component/index.d.ts +20 -1
- package/esm/core/component/index.js +270 -23
- package/esm/core/instance/index.d.ts +5 -1
- package/esm/core/instance/index.js +41 -4
- package/esm/index.d.ts +9 -4
- package/esm/index.js +56 -21
- package/esm/{core/applepay/index.d.ts → plugin/applepay/component.d.ts} +27 -8
- package/esm/{core/applepay/index.js → plugin/applepay/component.js} +150 -180
- package/esm/plugin/applepay/index.d.ts +17 -0
- package/esm/plugin/applepay/index.js +117 -0
- package/esm/{common → plugin}/applepay/interface.d.ts +62 -3
- package/esm/plugin/applepay/interface.js +69 -0
- package/esm/{common/applepay/index.d.ts → plugin/applepay/service.d.ts} +13 -7
- package/esm/{common/applepay/index.js → plugin/applepay/service.js} +159 -41
- package/esm/plugin/component/cashierApp.d.ts +3 -0
- package/esm/plugin/component/cashierApp.js +23 -2
- package/esm/plugin/component/index.d.ts +6 -2
- package/esm/plugin/component/index.js +126 -44
- package/esm/plugin/const.d.ts +2 -0
- package/esm/plugin/const.js +19 -0
- package/esm/plugin/type.d.ts +33 -0
- package/esm/request/index.d.ts +1 -1
- package/esm/service/index.d.ts +1 -1
- package/esm/types/index.d.ts +63 -6
- package/esm/types/index.js +8 -1
- package/esm/util/createIframeNode.d.ts +1 -0
- package/esm/util/createIframeNode.js +6 -0
- package/package.json +1 -1
- /package/esm/{common/applepay/interface.js → plugin/type.js} +0 -0
@@ -1,4 +1,6 @@
|
|
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
2
4
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
3
5
|
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
6
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
@@ -28,11 +30,17 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
30
|
import { v4 as uuid } from 'uuid';
|
29
31
|
import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
|
30
32
|
import ComponentApp from "../../plugin/component";
|
31
|
-
import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
|
33
|
+
import { componentSignEnum, environmentEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
|
32
34
|
import { getOrSetStorageId, isPC, parseBase64ToString } from "../../util";
|
33
|
-
import { createIframeNode } from "../../util/createIframeNode";
|
35
|
+
import { createIframeNode, createPreloadIframeNode } from "../../util/createIframeNode";
|
34
36
|
import { getSecurityConfigStorageKey } from "../../util/security";
|
35
37
|
import CoreInstance from "../instance/index";
|
38
|
+
import { BusManager, BusMessage } from "../bus";
|
39
|
+
import { SDKCallbackBusSubscriber } from "../bus/ability/callback";
|
40
|
+
import { ApplePayBusSubscriber } from "../../plugin/applepay";
|
41
|
+
import { SecurityBusSubscriber } from "../bus/ability/security";
|
42
|
+
import { TrackerBusSubscriber } from "../bus/ability/tracker";
|
43
|
+
import { ExtendPlugin } from "../../plugin/const";
|
36
44
|
export var getComponentSign = function getComponentSign(params) {
|
37
45
|
var _params$paymentSessio = params.paymentSessionConfig,
|
38
46
|
_params$paymentSessio2 = _params$paymentSessio === void 0 ? {} : _params$paymentSessio,
|
@@ -106,11 +114,15 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
106
114
|
_this = _super.call(this, options);
|
107
115
|
// Instantiate the plug-in and set render
|
108
116
|
_defineProperty(_assertThisInitialized(_this), "_componentApp", void 0);
|
117
|
+
_defineProperty(_assertThisInitialized(_this), "channelType", void 0);
|
118
|
+
_defineProperty(_assertThisInitialized(_this), "productSceneVersion", void 0);
|
109
119
|
var ComponentPlugin = new ComponentApp();
|
110
120
|
ComponentPlugin.setRender(createIframeNode);
|
121
|
+
ComponentPlugin.setPreloadRender(createPreloadIframeNode);
|
111
122
|
// Register Cashier Application Plug in
|
112
123
|
_this._registerPlugin(COMPONENTPLUGINID, ComponentPlugin);
|
113
124
|
_this._componentApp = _this._getPlugin(COMPONENTPLUGINID);
|
125
|
+
_this.registerBusAbility();
|
114
126
|
return _this;
|
115
127
|
}
|
116
128
|
_createClass(AMSComponent, [{
|
@@ -146,6 +158,147 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
146
158
|
return Promise.reject(error);
|
147
159
|
}
|
148
160
|
}
|
161
|
+
}, {
|
162
|
+
key: "savePreviousChannel",
|
163
|
+
value: function savePreviousChannel(iframeNodesParams) {
|
164
|
+
var _ref2 = iframeNodesParams || {},
|
165
|
+
_ref2$paymentSessionM = _ref2.paymentSessionMetaData.paymentSessionConfig,
|
166
|
+
_ref2$paymentSessionM2 = _ref2$paymentSessionM.productScene,
|
167
|
+
productScene = _ref2$paymentSessionM2 === void 0 ? '' : _ref2$paymentSessionM2,
|
168
|
+
_ref2$paymentSessionM3 = _ref2$paymentSessionM.paymentMethodCategoryType,
|
169
|
+
paymentMethodCategoryType = _ref2$paymentSessionM3 === void 0 ? '' : _ref2$paymentSessionM3,
|
170
|
+
_ref2$paymentSessionM4 = _ref2$paymentSessionM.productSceneVersion,
|
171
|
+
productSceneVersion = _ref2$paymentSessionM4 === void 0 ? '' : _ref2$paymentSessionM4;
|
172
|
+
var channelType = "".concat(productScene, "_").concat(paymentMethodCategoryType);
|
173
|
+
if (productScene && paymentMethodCategoryType && productSceneVersion) {
|
174
|
+
if (Array.isArray(this.channelType) && this.channelType.includes(channelType) && this.productSceneVersion === productSceneVersion) {
|
175
|
+
this.logger.logInfo({
|
176
|
+
title: 'preload_match'
|
177
|
+
}, {
|
178
|
+
preloadChannel: this.channelType,
|
179
|
+
preloadVersion: this.productSceneVersion,
|
180
|
+
sessionDataChannel: channelType,
|
181
|
+
sessionDataVersion: productSceneVersion
|
182
|
+
});
|
183
|
+
} else {
|
184
|
+
this.logger.logInfo({
|
185
|
+
title: 'preload_no_match'
|
186
|
+
}, {
|
187
|
+
preloadChannel: this.channelType,
|
188
|
+
preloadVersion: this.productSceneVersion,
|
189
|
+
sessionDataChannel: channelType,
|
190
|
+
sessionDataVersion: productSceneVersion
|
191
|
+
});
|
192
|
+
}
|
193
|
+
var previousChannel = {
|
194
|
+
channelType: channelType === componentSignEnum.VAULTING_CARD ? componentSignEnum.CASHIER_PAYMENT_CARD : channelType,
|
195
|
+
productSceneVersion: productSceneVersion
|
196
|
+
};
|
197
|
+
localStorage.setItem('antom_checkout_previousChannel', JSON.stringify(previousChannel));
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* 初始化 Bus总线的能力
|
203
|
+
*/
|
204
|
+
}, {
|
205
|
+
key: "registerBusAbility",
|
206
|
+
value: function registerBusAbility() {
|
207
|
+
var _this$originOptions,
|
208
|
+
_this2 = this;
|
209
|
+
BusManager.debugTrace(((_this$originOptions = this.originOptions) === null || _this$originOptions === void 0 ? void 0 : _this$originOptions.environment) !== environmentEnum.prod, this.logger);
|
210
|
+
BusManager.clear();
|
211
|
+
BusManager.addInterceptor({
|
212
|
+
onPublishException: function onPublishException(message, e) {
|
213
|
+
_this2.logger.logError({
|
214
|
+
title: 'onBusPublishException'
|
215
|
+
}, _objectSpread(_objectSpread({}, message), {}, {
|
216
|
+
errorMessage: JSON.stringify(e)
|
217
|
+
}));
|
218
|
+
}
|
219
|
+
});
|
220
|
+
// subscribe basic ablility
|
221
|
+
BusManager.subscribe(new SDKCallbackBusSubscriber(function (state) {
|
222
|
+
var _this2$_componentApp;
|
223
|
+
(_this2$_componentApp = _this2._componentApp) === null || _this2$_componentApp === void 0 || (_this2$_componentApp = _this2$_componentApp.AMSSDK) === null || _this2$_componentApp === void 0 || _this2$_componentApp._eventCenter.emit(EVENT.eventCallback.name, state);
|
224
|
+
}));
|
225
|
+
BusManager.subscribe(new SecurityBusSubscriber(function (deviceIdParameter, isPolling) {
|
226
|
+
var _this2$_componentApp2;
|
227
|
+
return (_this2$_componentApp2 = _this2._componentApp) === null || _this2$_componentApp2 === void 0 ? void 0 : _this2$_componentApp2.getDeviceIdAndLog(deviceIdParameter, isPolling);
|
228
|
+
}));
|
229
|
+
BusManager.subscribe(new TrackerBusSubscriber(this.logger));
|
230
|
+
// subscribe plugin
|
231
|
+
BusManager.subscribe(new ApplePayBusSubscriber(this.logger));
|
232
|
+
|
233
|
+
// register bus plugin
|
234
|
+
ExtendPlugin.forEach(function (item) {
|
235
|
+
var _item$busActionNames;
|
236
|
+
if (item !== null && item !== void 0 && item.busSubscriber) {
|
237
|
+
BusManager.subscribe(item === null || item === void 0 ? void 0 : item.busSubscriber);
|
238
|
+
}
|
239
|
+
var paymentChannelMatcher = item.paymentChannelMatcher;
|
240
|
+
if (paymentChannelMatcher) {
|
241
|
+
_this2._registerPlugin(paymentChannelMatcher.paymentMethod, item.busActionNames);
|
242
|
+
}
|
243
|
+
var sessionMatcher = item.sessionMatcher;
|
244
|
+
if (sessionMatcher) {
|
245
|
+
var pluginKey = sessionMatcher.productScene + sessionMatcher.productSceneVersion + sessionMatcher.paymentMethodCategoryType;
|
246
|
+
if (sessionMatcher.paymentMethodTypes) {
|
247
|
+
sessionMatcher.paymentMethodTypes.forEach(function (paymentMethodType) {
|
248
|
+
var subPluginKey = pluginKey + paymentMethodType;
|
249
|
+
_this2._registerPlugin(subPluginKey, item.busActionNames);
|
250
|
+
});
|
251
|
+
} else {
|
252
|
+
_this2._registerPlugin(pluginKey, item.busActionNames);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
var optInit = item === null || item === void 0 || (_item$busActionNames = item.busActionNames) === null || _item$busActionNames === void 0 ? void 0 : _item$busActionNames.optional_init;
|
256
|
+
if (optInit) {
|
257
|
+
BusManager.publish(new BusMessage(optInit, JSON.stringify(_this2.originOptions)));
|
258
|
+
}
|
259
|
+
});
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* To determine whether the corresponding payment method is available,
|
264
|
+
* only the channel described in the document will be called, and it will be returned as available by default
|
265
|
+
* @param paymentMethod - described in the document
|
266
|
+
* @param subPaymentMethod - described in the document
|
267
|
+
* @returns
|
268
|
+
*/
|
269
|
+
}, {
|
270
|
+
key: "canMakePayments",
|
271
|
+
value: function canMakePayments(paymentMethod, subPaymentMethod) {
|
272
|
+
var _this3 = this;
|
273
|
+
// 判断支付方式是否可用
|
274
|
+
return new Promise(function (resolve) {
|
275
|
+
var _this3$_getPlugin;
|
276
|
+
if (!paymentMethod) {
|
277
|
+
return resolve(true);
|
278
|
+
}
|
279
|
+
var actionName = (_this3$_getPlugin = _this3._getPlugin(paymentMethod)) === null || _this3$_getPlugin === void 0 ? void 0 : _this3$_getPlugin.canMakePayments;
|
280
|
+
if (actionName && BusManager.isSubscribed(actionName)) {
|
281
|
+
BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
|
282
|
+
paymentMethod: paymentMethod,
|
283
|
+
subPaymentMethod: subPaymentMethod
|
284
|
+
})), {
|
285
|
+
fallback: false
|
286
|
+
}).then(function (message) {
|
287
|
+
resolve(message.getJSONObject());
|
288
|
+
}).catch(function (e) {
|
289
|
+
_this3.logger.logInfo({
|
290
|
+
title: 'canMakePayments_error'
|
291
|
+
}, {
|
292
|
+
params: JSON.stringify(e)
|
293
|
+
});
|
294
|
+
resolve(false);
|
295
|
+
});
|
296
|
+
} else {
|
297
|
+
resolve(true);
|
298
|
+
}
|
299
|
+
});
|
300
|
+
}
|
301
|
+
|
149
302
|
/**
|
150
303
|
* @description Create component application
|
151
304
|
* @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
|
@@ -153,24 +306,85 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
153
306
|
}, {
|
154
307
|
key: "createComponent",
|
155
308
|
value: function createComponent(params) {
|
156
|
-
var
|
309
|
+
var _this4 = this;
|
310
|
+
this.clearPreloadIframe();
|
157
311
|
return this.parameterInitAndCheck({
|
158
312
|
params: params,
|
159
313
|
renderDisplayType: renderDisplayTypeEnum.popup
|
160
314
|
}).then(function (_params) {
|
161
315
|
return handleParams(_params);
|
162
316
|
}).catch(function (error) {
|
163
|
-
|
317
|
+
_this4.logger.logError({
|
164
318
|
title: 'sdk_error_parameter'
|
165
319
|
}, {
|
166
320
|
params: JSON.stringify(params)
|
167
321
|
}).send();
|
168
|
-
|
322
|
+
_this4._eventCenter.emit(EVENT.error.name, error);
|
169
323
|
return Promise.reject(error);
|
170
324
|
}).then(function (appendParams) {
|
171
|
-
return
|
325
|
+
return _this4.createComponentProcess(appendParams);
|
172
326
|
});
|
173
327
|
}
|
328
|
+
}, {
|
329
|
+
key: "createComponentProcess",
|
330
|
+
value: function createComponentProcess(appendParams) {
|
331
|
+
var _this$getBusActionNam;
|
332
|
+
this._appendParams = appendParams;
|
333
|
+
var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.createComponent;
|
334
|
+
if (actionName && BusManager.isSubscribed(actionName)) {
|
335
|
+
// 执行出错了,在通用拦截器返回
|
336
|
+
BusManager.publish(new BusMessage(actionName, JSON.stringify({
|
337
|
+
appendParams: appendParams,
|
338
|
+
options: this.originOptions
|
339
|
+
})));
|
340
|
+
return Promise.resolve();
|
341
|
+
}
|
342
|
+
var iframeNodesParams = appendParams.iframeNodesParams;
|
343
|
+
this.savePreviousChannel(iframeNodesParams);
|
344
|
+
return this.pluginAppendIframe(appendParams);
|
345
|
+
}
|
346
|
+
}, {
|
347
|
+
key: "preloadComponent",
|
348
|
+
value: function preloadComponent(channelType, productSceneVersion) {
|
349
|
+
var _this5 = this;
|
350
|
+
this.channelType = channelType;
|
351
|
+
this.productSceneVersion = productSceneVersion;
|
352
|
+
var MAX_CLEAR_TIME = 10000;
|
353
|
+
if (Array.isArray(channelType)) {
|
354
|
+
for (var i = 0; i < channelType.length; i++) {
|
355
|
+
this._componentApp.appendPreloadIframeNodes(channelType[i], productSceneVersion);
|
356
|
+
}
|
357
|
+
} else {
|
358
|
+
this.logger.logError({
|
359
|
+
title: 'performance_optimization_channelType_error'
|
360
|
+
}, {
|
361
|
+
channelType: channelType
|
362
|
+
});
|
363
|
+
}
|
364
|
+
setTimeout(function () {
|
365
|
+
_this5.clearPreloadIframe(true);
|
366
|
+
}, MAX_CLEAR_TIME);
|
367
|
+
}
|
368
|
+
}, {
|
369
|
+
key: "clearPreloadIframe",
|
370
|
+
value: function clearPreloadIframe() {
|
371
|
+
var isTimeOut = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
372
|
+
if (Array.isArray(this.channelType)) {
|
373
|
+
for (var i = 0; i < this.channelType.length; i++) {
|
374
|
+
var iframe = document.getElementById("ams-checkout-component-".concat(this.channelType[i], "-").concat(this.productSceneVersion));
|
375
|
+
iframe && document.body.removeChild(iframe);
|
376
|
+
}
|
377
|
+
}
|
378
|
+
if (!isTimeOut) {
|
379
|
+
this.logger.logInfo({
|
380
|
+
title: 'performance_optimization_clearPreloadIframe'
|
381
|
+
});
|
382
|
+
} else {
|
383
|
+
this.logger.logInfo({
|
384
|
+
title: 'performance_optimization_clearPreloadIframe_timeout'
|
385
|
+
});
|
386
|
+
}
|
387
|
+
}
|
174
388
|
/**
|
175
389
|
* @description Create and render components in the specified element area
|
176
390
|
* @param params - The data source created by the component, necessary sessionData, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
|
@@ -179,7 +393,8 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
179
393
|
}, {
|
180
394
|
key: "mountComponent",
|
181
395
|
value: function mountComponent(params, selector) {
|
182
|
-
var
|
396
|
+
var _this6 = this;
|
397
|
+
this.clearPreloadIframe();
|
183
398
|
return this.parameterInitAndCheck({
|
184
399
|
params: params,
|
185
400
|
renderDisplayType: renderDisplayTypeEnum.inline,
|
@@ -187,17 +402,36 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
187
402
|
}).then(function (_params) {
|
188
403
|
return handleParams(_params);
|
189
404
|
}).catch(function (error) {
|
190
|
-
|
405
|
+
_this6.logger.logError({
|
191
406
|
title: 'sdk_error_parameter'
|
192
407
|
}, {
|
193
408
|
params: JSON.stringify(params)
|
194
409
|
}).send();
|
195
|
-
|
410
|
+
_this6._eventCenter.emit(EVENT.error.name, error);
|
196
411
|
return Promise.reject(error);
|
197
412
|
}).then(function (appendParams) {
|
198
|
-
return
|
413
|
+
return _this6.mountComponentProcess(appendParams);
|
199
414
|
});
|
200
415
|
}
|
416
|
+
}, {
|
417
|
+
key: "mountComponentProcess",
|
418
|
+
value: function mountComponentProcess(appendParams) {
|
419
|
+
var _this$getBusActionNam2;
|
420
|
+
this._appendParams = appendParams;
|
421
|
+
var actionName = (_this$getBusActionNam2 = this.getBusActionNames()) === null || _this$getBusActionNam2 === void 0 ? void 0 : _this$getBusActionNam2.mountComponent;
|
422
|
+
if (actionName && BusManager.isSubscribed(actionName)) {
|
423
|
+
// 执行出错了,在通用拦截器返回
|
424
|
+
BusManager.publish(new BusMessage(actionName, JSON.stringify({
|
425
|
+
appendParams: appendParams,
|
426
|
+
options: this.originOptions
|
427
|
+
})));
|
428
|
+
return Promise.resolve();
|
429
|
+
}
|
430
|
+
var iframeNodesParams = appendParams.iframeNodesParams;
|
431
|
+
this.savePreviousChannel(iframeNodesParams);
|
432
|
+
return this.pluginAppendIframe(appendParams);
|
433
|
+
}
|
434
|
+
|
201
435
|
/**
|
202
436
|
* @description Execute payment submission process
|
203
437
|
* @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
|
@@ -206,24 +440,37 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
206
440
|
}, {
|
207
441
|
key: "submit",
|
208
442
|
value: function submit(data) {
|
209
|
-
var
|
443
|
+
var _this7 = this;
|
210
444
|
return new Promise(function (resolve, reject) {
|
211
445
|
try {
|
446
|
+
var _this7$getBusActionNa;
|
212
447
|
var eventCallbackId = uuid();
|
213
|
-
|
214
|
-
_this4._eventCenter.once(eventCallbackId, function (_data) {
|
215
|
-
resolve(_data);
|
216
|
-
});
|
217
|
-
_this4._componentApp.dispatchToApp({
|
218
|
-
context: {
|
219
|
-
event: 'submitPay',
|
220
|
-
eventCallbackId: eventCallbackId,
|
221
|
-
data: data
|
222
|
-
}
|
223
|
-
});
|
224
|
-
_this4.logger.logInfo({
|
448
|
+
_this7.logger.logInfo({
|
225
449
|
title: 'sdk_event_apiSubmit'
|
226
450
|
});
|
451
|
+
var actionName = (_this7$getBusActionNa = _this7.getBusActionNames()) === null || _this7$getBusActionNa === void 0 ? void 0 : _this7$getBusActionNa.submit;
|
452
|
+
if (actionName && BusManager.isSubscribed(actionName)) {
|
453
|
+
// 执行出错了,在通用拦截器返回
|
454
|
+
BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
|
455
|
+
appendParams: _this7._appendParams,
|
456
|
+
options: _this7.originOptions,
|
457
|
+
data: data
|
458
|
+
}))).then(function (busMessage) {
|
459
|
+
resolve(busMessage === null || busMessage === void 0 ? void 0 : busMessage.getJSONObject());
|
460
|
+
});
|
461
|
+
} else {
|
462
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
463
|
+
_this7._eventCenter.once(eventCallbackId, function (_data) {
|
464
|
+
resolve(_data);
|
465
|
+
});
|
466
|
+
_this7._componentApp.dispatchToApp({
|
467
|
+
context: {
|
468
|
+
event: 'submitPay',
|
469
|
+
eventCallbackId: eventCallbackId,
|
470
|
+
data: data
|
471
|
+
}
|
472
|
+
});
|
473
|
+
}
|
227
474
|
} catch (error) {
|
228
475
|
reject(error);
|
229
476
|
}
|
@@ -1,13 +1,16 @@
|
|
1
|
-
import type { AMSCheckoutOptions, InitSecurityConfig, IoptionsParams } from '../../types/index';
|
1
|
+
import type { AMSCheckoutOptions, IAppendParams, InitSecurityConfig, IoptionsParams } from '../../types/index';
|
2
2
|
import { EventCenter } from '../../util/index';
|
3
3
|
import { Logger } from '../../util/logger';
|
4
4
|
import { Security } from '../../util/security';
|
5
|
+
import { ComponentActionNamesType } from 'src/plugin/type';
|
5
6
|
export default class AMSSDK {
|
6
7
|
options: AMSCheckoutOptions;
|
8
|
+
originOptions: IoptionsParams;
|
7
9
|
logger: Logger;
|
8
10
|
_eventCenter: EventCenter;
|
9
11
|
_instanceId: string;
|
10
12
|
_storageId: string;
|
13
|
+
_appendParams: IAppendParams;
|
11
14
|
protected securitySdkMap: Map<string, Security>;
|
12
15
|
protected plugins: Map<string, any>;
|
13
16
|
constructor(options: IoptionsParams);
|
@@ -72,4 +75,5 @@ export default class AMSSDK {
|
|
72
75
|
* @description Overlay Subscription
|
73
76
|
*/
|
74
77
|
protected _overrideSubscription(name: string, func: any, funcKey: string): void;
|
78
|
+
protected getBusActionNames(): ComponentActionNamesType;
|
75
79
|
}
|
@@ -26,17 +26,21 @@ import CallApp from "../../util/intl-callapp/es/main";
|
|
26
26
|
import { LogConfig, Logger } from "../../util/logger";
|
27
27
|
import { compareVersion } from "../../util/versionCompare";
|
28
28
|
import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security, SecurityRegionEnum } from "../../util/security";
|
29
|
+
import { BusManager, BusMessage } from "../bus";
|
29
30
|
var AMSSDK = /*#__PURE__*/function () {
|
30
31
|
function AMSSDK(options) {
|
31
32
|
_classCallCheck(this, AMSSDK);
|
32
33
|
_defineProperty(this, "options", void 0);
|
34
|
+
_defineProperty(this, "originOptions", void 0);
|
33
35
|
_defineProperty(this, "logger", void 0);
|
34
36
|
_defineProperty(this, "_eventCenter", void 0);
|
35
37
|
_defineProperty(this, "_instanceId", void 0);
|
36
38
|
_defineProperty(this, "_storageId", void 0);
|
39
|
+
_defineProperty(this, "_appendParams", void 0);
|
37
40
|
_defineProperty(this, "securitySdkMap", void 0);
|
38
41
|
_defineProperty(this, "plugins", void 0);
|
39
42
|
this._instanceId = uuid();
|
43
|
+
this.originOptions = options;
|
40
44
|
this.options = {};
|
41
45
|
this._eventCenter = new EventCenter();
|
42
46
|
this._initEvent(options);
|
@@ -101,17 +105,27 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
101
105
|
}, {
|
102
106
|
key: "unmount",
|
103
107
|
value: function unmount() {
|
108
|
+
var _this$getBusActionNam;
|
104
109
|
this.logger.logInfo({
|
105
110
|
title: 'sdk_event_apiOnDestroy'
|
106
111
|
}).send();
|
112
|
+
var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.destoryComponent;
|
113
|
+
if (actionName && BusManager.isSubscribed(actionName)) {
|
114
|
+
// 执行出错了,在通用拦截器返回
|
115
|
+
BusManager.publish(new BusMessage(actionName, JSON.stringify({
|
116
|
+
options: this.originOptions
|
117
|
+
})));
|
118
|
+
}
|
107
119
|
var _iterator = _createForOfIteratorHelper(this.plugins.values()),
|
108
120
|
_step;
|
109
121
|
try {
|
110
122
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
111
123
|
var plugin = _step.value;
|
112
124
|
try {
|
113
|
-
plugin.logoutPlugin
|
114
|
-
|
125
|
+
if (plugin.logoutPlugin) {
|
126
|
+
plugin.logoutPlugin();
|
127
|
+
// eslint-disable-next-line no-empty
|
128
|
+
}
|
115
129
|
} catch (error) {
|
116
130
|
console.error(error);
|
117
131
|
}
|
@@ -302,7 +316,9 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
302
316
|
value: function _registerPlugin(pluginId, plugin) {
|
303
317
|
this.plugins.set(pluginId, plugin);
|
304
318
|
try {
|
305
|
-
plugin.applyPlugin
|
319
|
+
if (plugin.applyPlugin) {
|
320
|
+
plugin.applyPlugin(this);
|
321
|
+
}
|
306
322
|
} catch (error) {
|
307
323
|
this.plugins.delete(pluginId);
|
308
324
|
if (getType(error) === 'error') throw error;
|
@@ -316,7 +332,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
316
332
|
key: "_getPlugin",
|
317
333
|
value: function _getPlugin(pluginId) {
|
318
334
|
if (!this.plugins.has(pluginId)) {
|
319
|
-
console.warn("".concat(pluginId, "Plugin unregistered"));
|
335
|
+
console.warn("".concat(pluginId, " Plugin unregistered"));
|
320
336
|
return null;
|
321
337
|
}
|
322
338
|
return this.plugins.get(pluginId);
|
@@ -381,6 +397,27 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
381
397
|
this._eventCenter.off(name, func, funcKey);
|
382
398
|
this._eventCenter.on(name, func, funcKey);
|
383
399
|
}
|
400
|
+
}, {
|
401
|
+
key: "getBusActionNames",
|
402
|
+
value: function getBusActionNames() {
|
403
|
+
var _appendParams$iframeN;
|
404
|
+
var appendParams = this._appendParams;
|
405
|
+
if (!appendParams) {
|
406
|
+
return null;
|
407
|
+
}
|
408
|
+
var actionNames = null;
|
409
|
+
var paymentSessionConfig = appendParams === null || appendParams === void 0 || (_appendParams$iframeN = appendParams.iframeNodesParams) === null || _appendParams$iframeN === void 0 || (_appendParams$iframeN = _appendParams$iframeN.paymentSessionMetaData) === null || _appendParams$iframeN === void 0 ? void 0 : _appendParams$iframeN.paymentSessionConfig;
|
410
|
+
if (paymentSessionConfig) {
|
411
|
+
var _appendParams$iframeN2;
|
412
|
+
var pluginKey = paymentSessionConfig.productScene + paymentSessionConfig.productSceneVersion + paymentSessionConfig.paymentMethodCategoryType;
|
413
|
+
var paymentMethodType = appendParams === null || appendParams === void 0 || (_appendParams$iframeN2 = appendParams.iframeNodesParams) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentSessionMetaData) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentSessionFactor) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentMethodInfo) === null || _appendParams$iframeN2 === void 0 ? void 0 : _appendParams$iframeN2.paymentMethodType;
|
414
|
+
if (paymentMethodType) {
|
415
|
+
pluginKey = pluginKey + paymentMethodType;
|
416
|
+
}
|
417
|
+
actionNames = this._getPlugin(pluginKey);
|
418
|
+
}
|
419
|
+
return actionNames;
|
420
|
+
}
|
384
421
|
}]);
|
385
422
|
return AMSSDK;
|
386
423
|
}();
|
package/esm/index.d.ts
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
6
|
+
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
7
|
+
*/
|
1
8
|
import { AMSComponent } from './core/component/index';
|
2
|
-
import { IoptionsParams } from './types';
|
3
|
-
import ApplePayComponent from './core/applepay';
|
9
|
+
import { IoptionsParams, componentSignEnum } from './types';
|
4
10
|
export * from './types';
|
5
11
|
export declare class AMSCheckout extends AMSComponent {
|
6
|
-
|
7
|
-
export declare class AMSApplePay extends ApplePayComponent {
|
12
|
+
constructor(_options: any, channelType?: componentSignEnum[], productSceneVersion?: string);
|
8
13
|
}
|
9
14
|
export declare class AMSAutoDebit extends AMSCheckout {
|
10
15
|
constructor(options: IoptionsParams);
|
package/esm/index.js
CHANGED
@@ -18,73 +18,108 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
18
18
|
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
19
19
|
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
20
20
|
*/
|
21
|
-
import { productSceneEnum } from "./types/index";
|
22
21
|
import { AMSComponent } from "./core/component/index";
|
23
|
-
import
|
22
|
+
import { componentSignEnum } from "./types";
|
23
|
+
import { productSceneEnum } from "./types/index";
|
24
|
+
import { Logger, LogConfig } from "./util/logger";
|
25
|
+
var logger = new Logger(LogConfig, true);
|
24
26
|
export * from "./types";
|
25
27
|
export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
|
26
28
|
_inherits(AMSCheckout, _AMSComponent);
|
27
29
|
var _super = _createSuper(AMSCheckout);
|
28
|
-
function AMSCheckout() {
|
30
|
+
function AMSCheckout(_options, channelType) {
|
31
|
+
var _this;
|
32
|
+
var productSceneVersion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '1.0';
|
29
33
|
_classCallCheck(this, AMSCheckout);
|
30
|
-
|
34
|
+
_this = _super.call(this, _options);
|
35
|
+
_this.preloadComponent(channelType, productSceneVersion);
|
36
|
+
return _this;
|
31
37
|
}
|
32
38
|
return _createClass(AMSCheckout);
|
33
39
|
}(AMSComponent);
|
34
|
-
export var AMSApplePay = /*#__PURE__*/function (_ApplePayComponent) {
|
35
|
-
_inherits(AMSApplePay, _ApplePayComponent);
|
36
|
-
var _super2 = _createSuper(AMSApplePay);
|
37
|
-
function AMSApplePay() {
|
38
|
-
_classCallCheck(this, AMSApplePay);
|
39
|
-
return _super2.apply(this, arguments);
|
40
|
-
}
|
41
|
-
return _createClass(AMSApplePay);
|
42
|
-
}(ApplePayComponent);
|
43
40
|
export var AMSAutoDebit = /*#__PURE__*/function (_AMSCheckout) {
|
44
41
|
_inherits(AMSAutoDebit, _AMSCheckout);
|
45
|
-
var
|
42
|
+
var _super2 = _createSuper(AMSAutoDebit);
|
46
43
|
function AMSAutoDebit(options) {
|
47
44
|
_classCallCheck(this, AMSAutoDebit);
|
48
45
|
var _options = Object.assign({}, options, {
|
49
46
|
product: productSceneEnum.AUTO_DEBIT
|
50
47
|
});
|
51
|
-
return
|
48
|
+
return _super2.call(this, _options, [componentSignEnum.AUTO_DEBIT_WALLET]);
|
52
49
|
}
|
53
50
|
return _createClass(AMSAutoDebit);
|
54
51
|
}(AMSCheckout);
|
55
52
|
export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
|
56
53
|
_inherits(AMSEasyPay, _AMSCheckout2);
|
57
|
-
var
|
54
|
+
var _super3 = _createSuper(AMSEasyPay);
|
58
55
|
function AMSEasyPay(options) {
|
59
56
|
_classCallCheck(this, AMSEasyPay);
|
60
57
|
var _options = Object.assign({}, options, {
|
61
58
|
product: productSceneEnum.EASY_PAY
|
62
59
|
});
|
63
|
-
|
60
|
+
var currentProductSceneVersion = '1.0';
|
61
|
+
try {
|
62
|
+
var previousChannelStr = localStorage.getItem('antom_checkout_previousChannel');
|
63
|
+
var previousChannel = JSON.parse(previousChannelStr) || {};
|
64
|
+
var _ref = previousChannel || {},
|
65
|
+
_ref$channelType = _ref.channelType,
|
66
|
+
channelType = _ref$channelType === void 0 ? '' : _ref$channelType,
|
67
|
+
_ref$productSceneVers = _ref.productSceneVersion,
|
68
|
+
productSceneVersion = _ref$productSceneVers === void 0 ? '1.0' : _ref$productSceneVers;
|
69
|
+
if (channelType === componentSignEnum.EASY_PAY_WALLET) {
|
70
|
+
currentProductSceneVersion = productSceneVersion;
|
71
|
+
}
|
72
|
+
} catch (error) {
|
73
|
+
logger.logError({
|
74
|
+
title: 'performance_optimization_get_previousChannel_error'
|
75
|
+
}, {
|
76
|
+
error: error
|
77
|
+
});
|
78
|
+
}
|
79
|
+
return _super3.call(this, _options, [componentSignEnum.EASY_PAY_WALLET], currentProductSceneVersion);
|
64
80
|
}
|
65
81
|
return _createClass(AMSEasyPay);
|
66
82
|
}(AMSCheckout);
|
67
83
|
export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
|
68
84
|
_inherits(AMSCashierPayment, _AMSCheckout3);
|
69
|
-
var
|
85
|
+
var _super4 = _createSuper(AMSCashierPayment);
|
70
86
|
function AMSCashierPayment(options) {
|
71
87
|
_classCallCheck(this, AMSCashierPayment);
|
72
88
|
var _options = Object.assign({}, options, {
|
73
89
|
product: productSceneEnum.CASHIER_PAYMENT
|
74
90
|
});
|
75
|
-
|
91
|
+
var currentChannelType;
|
92
|
+
try {
|
93
|
+
var previousChannelStr = localStorage.getItem('antom_checkout_previousChannel');
|
94
|
+
var previousChannel = JSON.parse(previousChannelStr) || {};
|
95
|
+
var _ref2 = previousChannel || {},
|
96
|
+
_ref2$channelType = _ref2.channelType,
|
97
|
+
channelType = _ref2$channelType === void 0 ? '' : _ref2$channelType;
|
98
|
+
if ([componentSignEnum.CASHIER_PAYMENT_CARD, componentSignEnum.CASHIER_PAYMENT_APM, componentSignEnum.CASHIER_PAYMENT_BANK].includes(channelType)) {
|
99
|
+
currentChannelType = [channelType];
|
100
|
+
} else {
|
101
|
+
currentChannelType = [componentSignEnum.CASHIER_PAYMENT_CARD, componentSignEnum.CASHIER_PAYMENT_APM];
|
102
|
+
}
|
103
|
+
} catch (error) {
|
104
|
+
logger.logError({
|
105
|
+
title: 'performance_optimization_get_previousChannel_error'
|
106
|
+
}, {
|
107
|
+
error: error
|
108
|
+
});
|
109
|
+
}
|
110
|
+
return _super4.call(this, _options, currentChannelType);
|
76
111
|
}
|
77
112
|
return _createClass(AMSCashierPayment);
|
78
113
|
}(AMSCheckout);
|
79
114
|
export var AMSVaulting = /*#__PURE__*/function (_AMSCheckout4) {
|
80
115
|
_inherits(AMSVaulting, _AMSCheckout4);
|
81
|
-
var
|
116
|
+
var _super5 = _createSuper(AMSVaulting);
|
82
117
|
function AMSVaulting(options) {
|
83
118
|
_classCallCheck(this, AMSVaulting);
|
84
119
|
var _options = Object.assign({}, options, {
|
85
120
|
product: productSceneEnum.VAULTING
|
86
121
|
});
|
87
|
-
return
|
122
|
+
return _super5.call(this, _options, [componentSignEnum.CASHIER_PAYMENT_CARD]);
|
88
123
|
}
|
89
124
|
return _createClass(AMSVaulting);
|
90
125
|
}(AMSCheckout);
|