@alipay/ams-checkout 0.0.1726734012-dev.1 → 0.0.1726734012-dev.3
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/channel.d.ts +19 -0
- package/esm/component/channel.js +87 -0
- package/esm/component/component.inline.style.d.ts +10 -0
- package/esm/component/component.inline.style.js +121 -0
- package/esm/component/component.popup.style.d.ts +25 -0
- package/esm/component/component.popup.style.js +203 -0
- package/esm/component/popupWindow.style.d.ts +11 -0
- package/esm/component/popupWindow.style.js +121 -0
- package/esm/config/index.d.ts +11 -0
- package/esm/config/index.js +20 -1
- package/esm/constant/index.d.ts +25 -0
- package/esm/constant/index.js +28 -0
- package/esm/core/bus/index.d.ts +3 -3
- package/esm/core/bus/index.js +14 -14
- package/esm/core/component/address.d.ts +8 -0
- package/esm/core/component/address.js +72 -0
- package/esm/core/component/appPreloadProcessing.js +2 -2
- package/esm/core/component/ckp/index.js +12 -8
- package/esm/core/component/element/components/address.d.ts +19 -0
- package/esm/core/component/element/components/address.js +68 -0
- package/esm/core/component/element/components/auth.d.ts +17 -0
- package/esm/core/component/element/components/auth.js +60 -0
- package/esm/core/component/element/components/payment.d.ts +19 -0
- package/esm/core/component/element/components/payment.js +74 -0
- package/esm/core/component/element/index.d.ts +47 -0
- package/esm/core/component/element/index.js +817 -0
- package/esm/core/component/element/mock.d.ts +4 -0
- package/esm/core/component/element/mock.js +491 -0
- package/esm/core/component/element/type.d.ts +191 -0
- package/esm/core/component/element/type.js +36 -0
- package/esm/core/component/element/utils.d.ts +13 -0
- package/esm/core/component/element/utils.js +6 -0
- package/esm/core/component/index.d.ts +12 -7
- package/esm/core/component/index.js +133 -78
- package/esm/core/drop-in/index.js +2 -2
- package/esm/core/instance/index.d.ts +1 -0
- package/esm/core/instance/index.js +24 -11
- package/esm/foundation/core/index.d.ts +28 -0
- package/esm/foundation/core/index.js +396 -0
- package/esm/foundation/index.d.ts +75 -0
- package/esm/foundation/index.js +42 -0
- package/esm/foundation/product-processor/easysafepay/deps.d.ts +18 -0
- package/esm/foundation/product-processor/easysafepay/deps.js +12 -0
- package/esm/foundation/product-processor/easysafepay/index.d.ts +26 -0
- package/esm/foundation/product-processor/easysafepay/index.js +464 -0
- package/esm/foundation/service/api-bus/ability/callback.d.ts +9 -0
- package/esm/foundation/service/api-bus/ability/callback.js +55 -0
- package/esm/foundation/service/api-bus/ability/globalData.d.ts +10 -0
- package/esm/foundation/service/api-bus/ability/globalData.js +89 -0
- package/esm/foundation/service/api-bus/ability/request.d.ts +10 -0
- package/esm/foundation/service/api-bus/ability/request.js +151 -0
- package/esm/foundation/service/api-bus/ability/security.d.ts +12 -0
- package/esm/foundation/service/api-bus/ability/security.js +161 -0
- package/esm/foundation/service/api-bus/ability/tracker.d.ts +9 -0
- package/esm/foundation/service/api-bus/ability/tracker.js +80 -0
- package/esm/foundation/service/api-bus/busManager.d.ts +127 -0
- package/esm/foundation/service/api-bus/busManager.js +398 -0
- package/esm/foundation/service/api-bus/index.d.ts +20 -0
- package/esm/foundation/service/api-bus/index.js +88 -0
- package/esm/foundation/service/api-bus/interface.d.ts +48 -0
- package/esm/foundation/service/api-bus/interface.js +54 -0
- package/esm/foundation/service/container/index.d.ts +32 -0
- package/esm/foundation/service/container/index.js +330 -0
- package/esm/foundation/service/container/popup.d.ts +17 -0
- package/esm/foundation/service/container/popup.js +103 -0
- package/esm/foundation/service/container/utils.d.ts +7 -0
- package/esm/foundation/service/container/utils.js +48 -0
- package/esm/foundation/service/event-center.d.ts +82 -0
- package/esm/foundation/service/event-center.js +274 -0
- package/esm/foundation/service/global-data/index.d.ts +11 -0
- package/esm/foundation/service/global-data/index.js +68 -0
- package/esm/foundation/service/index.d.ts +19 -0
- package/esm/foundation/service/index.js +82 -0
- package/esm/foundation/service/log/index.d.ts +43 -0
- package/esm/foundation/service/log/index.js +250 -0
- package/esm/foundation/service/log/keys.d.ts +13 -0
- package/esm/foundation/service/log/keys.js +103 -0
- package/esm/foundation/service/log/processor.d.ts +9 -0
- package/esm/foundation/service/log/processor.js +148 -0
- package/esm/foundation/service/log/types.d.ts +32 -0
- package/esm/foundation/service/log/types.js +1 -0
- package/esm/foundation/service/requester/deps.d.ts +17 -0
- package/esm/foundation/service/requester/deps.js +11 -0
- package/esm/foundation/service/requester/requester.d.ts +22 -0
- package/esm/foundation/service/requester/requester.js +217 -0
- package/esm/foundation/service/security/index.d.ts +28 -0
- package/esm/foundation/service/security/index.js +284 -0
- package/esm/foundation/service/security/security.d.ts +33 -0
- package/esm/foundation/service/security/security.js +182 -0
- package/esm/foundation/utils/gray_scale_utils.d.ts +7 -0
- package/esm/foundation/utils/gray_scale_utils.js +40 -0
- package/esm/foundation/utils/payment_context_utils.d.ts +13 -0
- package/esm/foundation/utils/payment_context_utils.js +57 -0
- package/esm/foundation/utils/payment_product_utils.d.ts +13 -0
- package/esm/foundation/utils/payment_product_utils.js +38 -0
- package/esm/foundation/utils/redirect_utils.d.ts +11 -0
- package/esm/foundation/utils/redirect_utils.js +262 -0
- package/esm/foundation/utils/system_events.d.ts +4 -0
- package/esm/foundation/utils/system_events.js +66 -0
- package/esm/foundation/utils/web_app_url_utils.d.ts +46 -0
- package/esm/foundation/utils/web_app_url_utils.js +112 -0
- package/esm/index.d.ts +19 -12
- package/esm/index.js +110 -56
- package/esm/plugin/applepay/component.js +13 -11
- package/esm/plugin/applepay/index.js +10 -6
- package/esm/plugin/applepay/service.d.ts +2 -2
- package/esm/plugin/applepay/service.js +26 -18
- package/esm/plugin/component/cashierApp.d.ts +10 -8
- package/esm/plugin/component/cashierApp.js +48 -11
- package/esm/plugin/component/channel.d.ts +4 -3
- package/esm/plugin/component/channel.js +39 -2
- package/esm/plugin/component/component.inline.style.d.ts +9 -10
- package/esm/plugin/component/component.inline.style.js +93 -10
- package/esm/plugin/component/component.popup.style.d.ts +15 -6
- package/esm/plugin/component/component.popup.style.js +30 -7
- package/esm/plugin/component/index.d.ts +14 -8
- package/esm/plugin/component/index.js +383 -187
- package/esm/plugin/component/popupWindow.style.d.ts +5 -2
- package/esm/plugin/component/popupWindow.style.js +70 -14
- package/esm/plugin/const.js +5 -5
- package/esm/plugin/drop-in/index.d.ts +5 -5
- package/esm/plugin/drop-in/index.js +7 -7
- package/esm/plugin/payment-element/utils.d.ts +2 -0
- package/esm/plugin/payment-element/utils.js +6 -0
- package/esm/plugin/paypal/index.js +2 -1
- package/esm/plugin/type.d.ts +4 -3
- package/esm/service/element.d.ts +4 -0
- package/esm/service/element.js +51 -0
- package/esm/service/index.d.ts +1 -0
- package/esm/service/index.js +6 -2
- package/esm/types/index.d.ts +337 -40
- package/esm/types/index.js +119 -55
- package/esm/util/createIframeNode.d.ts +2 -2
- package/esm/util/createIframeNode.js +3 -3
- package/esm/util/getBackScheme.d.ts +5 -0
- package/esm/util/getBackScheme.js +133 -0
- package/esm/util/index.js +4 -8
- package/esm/util/logger.d.ts +3 -3
- package/esm/util/logger.js +49 -13
- package/esm/util/security.d.ts +3 -2
- package/esm/util/security.js +2 -2
- package/esm/util/spm-map.d.ts +172 -0
- package/esm/util/spm-map.js +172 -0
- package/package.json +3 -1
@@ -24,7 +24,7 @@ import { v4 as uuid } from 'uuid';
|
|
24
24
|
import { sdkVersion } from "../../config/index";
|
25
25
|
import { ERRORMESSAGE, EVENT } from "../../constant";
|
26
26
|
import { antomConfig } from "../../service";
|
27
|
-
import {
|
27
|
+
import { EnvironmentEnum, modeEnum, networkModeEnum, osTypeEnum, ProductSceneEnum, terminalTypeEnum } from "../../types/index";
|
28
28
|
import { checkTimeElapsed, device, EventCenter, getOrSetStorageId, getType, queryParse, safeJson } from "../../util/index";
|
29
29
|
import CallApp from "../../util/intl-callapp/es/main";
|
30
30
|
import { LogConfig, Logger } from "../../util/logger";
|
@@ -61,7 +61,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
61
61
|
this._storageId = _storageId;
|
62
62
|
|
63
63
|
// TODO Consumption data analysis control parameters
|
64
|
-
this.logger = new Logger(LogConfig, ![
|
64
|
+
this.logger = new Logger(LogConfig, ![EnvironmentEnum.prod, EnvironmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment));
|
65
65
|
Logger.setInstance(this.logger);
|
66
66
|
this.logger.setMedta({
|
67
67
|
instanceId: this._instanceId
|
@@ -81,7 +81,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
81
81
|
var _this$options;
|
82
82
|
var antomSDKConfigKey = 'antomSDKConfigKey';
|
83
83
|
var config = safeJson(getOrSetStorageId(antomSDKConfigKey), {});
|
84
|
-
if (![
|
84
|
+
if (![EnvironmentEnum.prod, EnvironmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment)) return;
|
85
85
|
if (checkTimeElapsed()) {
|
86
86
|
antomConfig({
|
87
87
|
env: this.options.env.environment
|
@@ -89,7 +89,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
89
89
|
getOrSetStorageId(antomSDKConfigKey, JSON.stringify(res));
|
90
90
|
});
|
91
91
|
}
|
92
|
-
var product = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.product) ||
|
92
|
+
var product = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.product) || ProductSceneEnum.EASY_PAY;
|
93
93
|
var enable = true;
|
94
94
|
try {
|
95
95
|
var matchingConfig = config['pl_sec'].find(function (item) {
|
@@ -157,13 +157,14 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
157
157
|
value: function initSecurity(_ref) {
|
158
158
|
var _this = this;
|
159
159
|
var _ref$product = _ref.product,
|
160
|
-
product = _ref$product === void 0 ?
|
160
|
+
product = _ref$product === void 0 ? ProductSceneEnum.EASY_PAY : _ref$product,
|
161
161
|
_ref$scene = _ref.scene,
|
162
|
-
scene = _ref$scene === void 0 ?
|
162
|
+
scene = _ref$scene === void 0 ? ProductSceneEnum.EASY_PAY : _ref$scene;
|
163
|
+
console.log('执行了initSecurity');
|
163
164
|
this.logger.logInfo({
|
164
165
|
title: 'sdk_event_securitySdkPreInit'
|
165
166
|
}, {
|
166
|
-
|
167
|
+
productScene: product
|
167
168
|
}).send();
|
168
169
|
var sdk = this._getSecuritySDKByProductScene({
|
169
170
|
product: product || scene
|
@@ -176,14 +177,14 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
176
177
|
_this.logger.logInfo({
|
177
178
|
title: 'sdk_event_securitySdkPreInitSuccess'
|
178
179
|
}, {
|
179
|
-
|
180
|
+
productScene: product
|
180
181
|
}).send();
|
181
182
|
}, function (msg) {
|
182
183
|
_this.logger.logError({
|
183
184
|
title: 'sdk_error_securitySdkInitFailed',
|
184
185
|
msg: msg
|
185
186
|
}, {
|
186
|
-
|
187
|
+
productScene: product,
|
187
188
|
sign: 'Active initialization'
|
188
189
|
}).send();
|
189
190
|
});
|
@@ -258,7 +259,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
258
259
|
value: function _setEnv(options) {
|
259
260
|
var _queryParse = queryParse(),
|
260
261
|
_moreEnv = _queryParse._moreEnv;
|
261
|
-
if (options !== null && options !== void 0 && options.environment && !((options === null || options === void 0 ? void 0 : options.environment) in
|
262
|
+
if (options !== null && options !== void 0 && options.environment && !((options === null || options === void 0 ? void 0 : options.environment) in EnvironmentEnum) && _moreEnv !== 'true') {
|
262
263
|
console.warn(ERRORMESSAGE.INIT_PARAMETER_ERROR.ENVIRONMENT_ERROR.message);
|
263
264
|
options.environment = 'prod';
|
264
265
|
}
|
@@ -320,7 +321,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
320
321
|
this._overrideSubscription(EVENT.close.name, options.onClose, EVENT.close.uniqueKey);
|
321
322
|
}
|
322
323
|
if (options !== null && options !== void 0 && options.onBeforeSubmit) {
|
323
|
-
if (
|
324
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.onBeforeSubmit) !== 'function') throw new Error(ERRORMESSAGE.INIT_PARAMETER_ERROR.EVENT_ERROR.message);
|
324
325
|
this._overrideSubscription(EVENT.beforeSubmit.name, /*#__PURE__*/function () {
|
325
326
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload) {
|
326
327
|
var eventCallbackId, res;
|
@@ -369,6 +370,11 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
369
370
|
};
|
370
371
|
}(), EVENT.beforeSubmit.uniqueKey);
|
371
372
|
}
|
373
|
+
/** 地址监听 */
|
374
|
+
if (options !== null && options !== void 0 && options.onChange) {
|
375
|
+
if (getType(options.onChange) !== 'function') throw new Error(ERRORMESSAGE.INIT_PARAMETER_ERROR.EVENT_ERROR.message);
|
376
|
+
this._overrideSubscription(EVENT.onChange.name, options.onChange, EVENT.onChange.uniqueKey);
|
377
|
+
}
|
372
378
|
}
|
373
379
|
/**
|
374
380
|
* @description Register plug-in
|
@@ -412,6 +418,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
412
418
|
var normalUrl = (data === null || data === void 0 ? void 0 : data.normalUrl) || '';
|
413
419
|
var schemeUrl = (data === null || data === void 0 ? void 0 : data.schemeUrl) || '';
|
414
420
|
var applinkUrl = (data === null || data === void 0 ? void 0 : data.applinkUrl) || '';
|
421
|
+
var callAppJudgeTime = (data === null || data === void 0 ? void 0 : data.callAppJudgeTime) || '';
|
415
422
|
var jumpFunc = function jumpFunc() {
|
416
423
|
if (normalUrl) {
|
417
424
|
resolve();
|
@@ -434,6 +441,9 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
434
441
|
},
|
435
442
|
delay: 0
|
436
443
|
};
|
444
|
+
if (callAppJudgeTime) {
|
445
|
+
config['resultJudgmentTime'] = callAppJudgeTime;
|
446
|
+
}
|
437
447
|
try {
|
438
448
|
var callLib = new CallApp(config);
|
439
449
|
callLib.open({
|
@@ -479,6 +489,9 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
479
489
|
}
|
480
490
|
actionNames = this._getPlugin(pluginKey);
|
481
491
|
}
|
492
|
+
if (this.options.product === ProductSceneEnum.ELEMENT_ADDRESS) {
|
493
|
+
actionNames = this._getPlugin(ProductSceneEnum.ELEMENT_ADDRESS);
|
494
|
+
}
|
482
495
|
return actionNames;
|
483
496
|
}
|
484
497
|
}]);
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { IoptionsParams, ProductSceneEnum } from '../../types';
|
2
|
+
import { BizFlowStartBehavior, PaymentContext, ProductProcessor, StartBizFlowOptions } from '../index';
|
3
|
+
import { ServiceProvider } from '../service';
|
4
|
+
/**
|
5
|
+
* @author 谦彧 <zhangmian.zm@alipay.com>
|
6
|
+
* @date 2024/9/17
|
7
|
+
*/
|
8
|
+
export declare class AntomSDKCore {
|
9
|
+
private bizFlowStartBehavior;
|
10
|
+
private initOptions;
|
11
|
+
private paymentContext;
|
12
|
+
private instanceId;
|
13
|
+
private sdkMetaData;
|
14
|
+
private productProcessors;
|
15
|
+
private enablePopWindowEventCallback;
|
16
|
+
constructor();
|
17
|
+
registerProcessor(productScene: string, paymentMethod: string, processor: ProductProcessor): void;
|
18
|
+
init(options: IoptionsParams, productScene: ProductSceneEnum): void;
|
19
|
+
private prepare;
|
20
|
+
startBizFlow(options: StartBizFlowOptions): Promise<void>;
|
21
|
+
getServiceProvider(): ServiceProvider;
|
22
|
+
getBizFlowBehavior(): BizFlowStartBehavior;
|
23
|
+
getPaymentContext(): PaymentContext;
|
24
|
+
destroy(): void;
|
25
|
+
private handleBehaviorRender;
|
26
|
+
private handleClose;
|
27
|
+
private cleanRender;
|
28
|
+
}
|
@@ -0,0 +1,396 @@
|
|
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; }
|
4
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
5
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
6
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8
|
+
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); } }
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
13
|
+
import { DisplayTypeEnum, eventCodeEnum } from "../../types";
|
14
|
+
import { DisplayInfo } from "../index";
|
15
|
+
import { v4 as uuid } from 'uuid';
|
16
|
+
import { ServiceProvider } from "../service";
|
17
|
+
import { convertPaymentSession, getWebAppVersion, saveWebAppVersion } from "../utils/payment_context_utils";
|
18
|
+
import { getGrayscaleId } from "../utils/gray_scale_utils";
|
19
|
+
import { sdkVersion } from "../../config";
|
20
|
+
import { parseWebAppMatchConfig } from "../utils/web_app_url_utils";
|
21
|
+
import { redirect } from "../utils/redirect_utils";
|
22
|
+
import { insertStyleSheet } from "../../component/popupWindow.style";
|
23
|
+
import { hideMockup, createMockup, createRetentionPopup, hideRetentionPopup, showRetentionPopup, cleanMockup, removeRetentionPopup, handleDeclareInfo } from "../../component/component.popup.style";
|
24
|
+
import { COMPONENT_CLOSE_MASK_BLOCK_ID, EVENT, LOADING_ID } from "../../constant";
|
25
|
+
/**
|
26
|
+
* @author 谦彧 <zhangmian.zm@alipay.com>
|
27
|
+
* @date 2024/9/17
|
28
|
+
*/
|
29
|
+
export var AntomSDKCore = /*#__PURE__*/function () {
|
30
|
+
function AntomSDKCore() {
|
31
|
+
_classCallCheck(this, AntomSDKCore);
|
32
|
+
_defineProperty(this, "bizFlowStartBehavior", void 0);
|
33
|
+
_defineProperty(this, "initOptions", void 0);
|
34
|
+
_defineProperty(this, "paymentContext", void 0);
|
35
|
+
_defineProperty(this, "instanceId", void 0);
|
36
|
+
_defineProperty(this, "sdkMetaData", void 0);
|
37
|
+
_defineProperty(this, "productProcessors", {});
|
38
|
+
_defineProperty(this, "enablePopWindowEventCallback", false);
|
39
|
+
}
|
40
|
+
_createClass(AntomSDKCore, [{
|
41
|
+
key: "registerProcessor",
|
42
|
+
value: function registerProcessor(productScene) {
|
43
|
+
var paymentMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
44
|
+
var processor = arguments.length > 2 ? arguments[2] : undefined;
|
45
|
+
var processorId = paymentMethod ? "".concat(productScene, "|").concat(paymentMethod) : productScene;
|
46
|
+
this.productProcessors[processorId] = processor;
|
47
|
+
}
|
48
|
+
}, {
|
49
|
+
key: "init",
|
50
|
+
value: function init(options, productScene) {
|
51
|
+
this.instanceId = uuid();
|
52
|
+
this.sdkMetaData = {
|
53
|
+
webAppVersion: '',
|
54
|
+
greyscaleId: getGrayscaleId(),
|
55
|
+
productScene: productScene,
|
56
|
+
sdkVersion: sdkVersion
|
57
|
+
};
|
58
|
+
this.sdkMetaData.webAppVersion = getWebAppVersion(this.sdkMetaData);
|
59
|
+
ServiceProvider.getInstance(this.instanceId).init(options, this.sdkMetaData);
|
60
|
+
this.prepare(options, this.sdkMetaData);
|
61
|
+
}
|
62
|
+
}, {
|
63
|
+
key: "prepare",
|
64
|
+
value: function prepare(options, sdkMetaData) {
|
65
|
+
var _this = this;
|
66
|
+
var eventCenter = ServiceProvider.getInstance(this.instanceId).getService('EventCenter');
|
67
|
+
eventCenter.listen(EVENT.redirect.name, function (data) {
|
68
|
+
var _data$isDestroy, _data$isCallApp, _data$callAppDetectSu;
|
69
|
+
if (!data) {
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
var needCleanContainer = (_data$isDestroy = data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true;
|
73
|
+
var redirectBehavior = typeof data === 'string' ? {
|
74
|
+
url: data
|
75
|
+
} : {
|
76
|
+
applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
|
77
|
+
schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
|
78
|
+
url: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
|
79
|
+
browserLinkTarget: data === null || data === void 0 ? void 0 : data.target,
|
80
|
+
isCallApp: (_data$isCallApp = data === null || data === void 0 ? void 0 : data.isCallApp) !== null && _data$isCallApp !== void 0 ? _data$isCallApp : false,
|
81
|
+
callAppDetectSuccessDelay: (_data$callAppDetectSu = data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) !== null && _data$callAppDetectSu !== void 0 ? _data$callAppDetectSu : 5000
|
82
|
+
};
|
83
|
+
redirect(redirectBehavior, _this.instanceId);
|
84
|
+
if (needCleanContainer) {
|
85
|
+
_this.cleanRender();
|
86
|
+
}
|
87
|
+
});
|
88
|
+
eventCenter.listen(EVENT.initSecuritySDK.name, /*#__PURE__*/function () {
|
89
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data, payload) {
|
90
|
+
var _payload$context;
|
91
|
+
var securityService, success;
|
92
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
93
|
+
while (1) switch (_context.prev = _context.next) {
|
94
|
+
case 0:
|
95
|
+
securityService = ServiceProvider.getInstance(_this.instanceId).getService('Security');
|
96
|
+
_context.prev = 1;
|
97
|
+
_context.next = 4;
|
98
|
+
return securityService.initSecurity();
|
99
|
+
case 4:
|
100
|
+
success = true;
|
101
|
+
_context.next = 10;
|
102
|
+
break;
|
103
|
+
case 7:
|
104
|
+
_context.prev = 7;
|
105
|
+
_context.t0 = _context["catch"](1);
|
106
|
+
success = false;
|
107
|
+
case 10:
|
108
|
+
eventCenter.dispatchToApp({
|
109
|
+
event: 'appEventCallback',
|
110
|
+
eventCallbackId: (_payload$context = payload.context) === null || _payload$context === void 0 ? void 0 : _payload$context.eventCallbackId,
|
111
|
+
data: {
|
112
|
+
success: success
|
113
|
+
}
|
114
|
+
});
|
115
|
+
case 11:
|
116
|
+
case "end":
|
117
|
+
return _context.stop();
|
118
|
+
}
|
119
|
+
}, _callee, null, [[1, 7]]);
|
120
|
+
}));
|
121
|
+
return function (_x, _x2) {
|
122
|
+
return _ref.apply(this, arguments);
|
123
|
+
};
|
124
|
+
}());
|
125
|
+
eventCenter.listen(EVENT.getDeviceId.name, /*#__PURE__*/function () {
|
126
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data, payload) {
|
127
|
+
var _payload$context2;
|
128
|
+
var securityService, deviceId;
|
129
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
130
|
+
while (1) switch (_context2.prev = _context2.next) {
|
131
|
+
case 0:
|
132
|
+
securityService = ServiceProvider.getInstance(_this.instanceId).getService('Security');
|
133
|
+
_context2.next = 3;
|
134
|
+
return securityService.getDeviceId(data);
|
135
|
+
case 3:
|
136
|
+
deviceId = _context2.sent;
|
137
|
+
eventCenter.dispatchToApp({
|
138
|
+
event: 'appEventCallback',
|
139
|
+
eventCallbackId: (_payload$context2 = payload.context) === null || _payload$context2 === void 0 ? void 0 : _payload$context2.eventCallbackId,
|
140
|
+
data: {
|
141
|
+
deviceId: deviceId
|
142
|
+
}
|
143
|
+
});
|
144
|
+
case 5:
|
145
|
+
case "end":
|
146
|
+
return _context2.stop();
|
147
|
+
}
|
148
|
+
}, _callee2);
|
149
|
+
}));
|
150
|
+
return function (_x3, _x4) {
|
151
|
+
return _ref2.apply(this, arguments);
|
152
|
+
};
|
153
|
+
}());
|
154
|
+
eventCenter.listen(EVENT.closeCallback.name, function () {
|
155
|
+
var _options$onClose;
|
156
|
+
(_options$onClose = options.onClose) === null || _options$onClose === void 0 || _options$onClose.call(options);
|
157
|
+
});
|
158
|
+
eventCenter.listen(EVENT.eventCallback.name, function (data) {
|
159
|
+
var _options$onEventCallb;
|
160
|
+
(_options$onEventCallb = options.onEventCallback) === null || _options$onEventCallb === void 0 || _options$onEventCallb.call(options, data);
|
161
|
+
});
|
162
|
+
eventCenter.listen(EVENT.error.name, function (data) {
|
163
|
+
var _options$onError;
|
164
|
+
(_options$onError = options.onError) === null || _options$onError === void 0 || _options$onError.call(options, data);
|
165
|
+
});
|
166
|
+
eventCenter.listen(EVENT.declareEventCallbackInfo.name, function (data) {
|
167
|
+
if (data !== null && data !== void 0 && data.popWindowEventInfo) {
|
168
|
+
_this.enablePopWindowEventCallback = data.popWindowEventInfo.enableCallback;
|
169
|
+
}
|
170
|
+
});
|
171
|
+
|
172
|
+
// execute additional logic from specified product
|
173
|
+
if (this.productProcessors[sdkMetaData.productScene]) {
|
174
|
+
this.productProcessors[sdkMetaData.productScene].init(options, this.instanceId, sdkMetaData);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}, {
|
178
|
+
key: "startBizFlow",
|
179
|
+
value: function () {
|
180
|
+
var _startBizFlow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(options) {
|
181
|
+
var _this$paymentContext$, _this$paymentContext$2;
|
182
|
+
var paymentSession, displayInfo, _convertPaymentSessio, paymentSessionId, paymentSessionMetaData, mid, webAppMatchConfig, webAppVersion, productScene, paymentMethod, _this$bizFlowStartBeh, payload;
|
183
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
184
|
+
while (1) switch (_context3.prev = _context3.next) {
|
185
|
+
case 0:
|
186
|
+
if (!(!options || !options.paymentSession)) {
|
187
|
+
_context3.next = 2;
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
throw new Error('paymentSession is empty');
|
191
|
+
case 2:
|
192
|
+
paymentSession = options.paymentSession, displayInfo = options.displayInfo;
|
193
|
+
_convertPaymentSessio = convertPaymentSession(paymentSession), paymentSessionId = _convertPaymentSessio.id, paymentSessionMetaData = _convertPaymentSessio.data;
|
194
|
+
this.paymentContext = {
|
195
|
+
initOptions: this.initOptions,
|
196
|
+
startBizFlowOptions: options,
|
197
|
+
paymentSession: paymentSession,
|
198
|
+
paymentSessionId: paymentSessionId,
|
199
|
+
paymentSessionObj: paymentSessionMetaData,
|
200
|
+
displayInfo: _objectSpread(_objectSpread({}, new DisplayInfo()), displayInfo),
|
201
|
+
sdkMetaData: this.sdkMetaData
|
202
|
+
};
|
203
|
+
// upgrade WebApp version
|
204
|
+
mid = this.paymentContext.paymentSessionObj.clientId;
|
205
|
+
webAppMatchConfig = parseWebAppMatchConfig(this.paymentContext.paymentSessionObj.extendInfo);
|
206
|
+
webAppVersion = getWebAppVersion(this.sdkMetaData, mid, webAppMatchConfig);
|
207
|
+
this.sdkMetaData.webAppVersion = webAppVersion;
|
208
|
+
saveWebAppVersion(webAppVersion, this.sdkMetaData);
|
209
|
+
|
210
|
+
// Call service to update via payment context
|
211
|
+
ServiceProvider.getInstance(this.instanceId).update(this.paymentContext);
|
212
|
+
|
213
|
+
// Invoke processor
|
214
|
+
productScene = (_this$paymentContext$ = this.paymentContext.paymentSessionObj) === null || _this$paymentContext$ === void 0 || (_this$paymentContext$ = _this$paymentContext$.paymentSessionConfig) === null || _this$paymentContext$ === void 0 ? void 0 : _this$paymentContext$.productScene;
|
215
|
+
paymentMethod = (_this$paymentContext$2 = this.paymentContext.paymentSessionObj) === null || _this$paymentContext$2 === void 0 || (_this$paymentContext$2 = _this$paymentContext$2.paymentMethodInfoView) === null || _this$paymentContext$2 === void 0 ? void 0 : _this$paymentContext$2.paymentMethodType;
|
216
|
+
_context3.prev = 13;
|
217
|
+
if (!this.productProcessors["".concat(productScene, "|").concat(paymentMethod)]) {
|
218
|
+
_context3.next = 20;
|
219
|
+
break;
|
220
|
+
}
|
221
|
+
_context3.next = 17;
|
222
|
+
return this.productProcessors["".concat(productScene, "|").concat(paymentMethod)].startBizFlow(this.paymentContext);
|
223
|
+
case 17:
|
224
|
+
this.bizFlowStartBehavior = _context3.sent;
|
225
|
+
_context3.next = 24;
|
226
|
+
break;
|
227
|
+
case 20:
|
228
|
+
if (!this.productProcessors["".concat(productScene)]) {
|
229
|
+
_context3.next = 24;
|
230
|
+
break;
|
231
|
+
}
|
232
|
+
_context3.next = 23;
|
233
|
+
return this.productProcessors["".concat(productScene)].startBizFlow(this.paymentContext);
|
234
|
+
case 23:
|
235
|
+
this.bizFlowStartBehavior = _context3.sent;
|
236
|
+
case 24:
|
237
|
+
_context3.next = 29;
|
238
|
+
break;
|
239
|
+
case 26:
|
240
|
+
_context3.prev = 26;
|
241
|
+
_context3.t0 = _context3["catch"](13);
|
242
|
+
console.error('Invoke processor failed', _context3.t0);
|
243
|
+
case 29:
|
244
|
+
if (!(!this.bizFlowStartBehavior || this.bizFlowStartBehavior.behaviorType === 'NONE' || !this.bizFlowStartBehavior.payload)) {
|
245
|
+
_context3.next = 31;
|
246
|
+
break;
|
247
|
+
}
|
248
|
+
return _context3.abrupt("return");
|
249
|
+
case 31:
|
250
|
+
if (!(this.bizFlowStartBehavior.behaviorType === 'RENDER')) {
|
251
|
+
_context3.next = 34;
|
252
|
+
break;
|
253
|
+
}
|
254
|
+
this.handleBehaviorRender();
|
255
|
+
return _context3.abrupt("return");
|
256
|
+
case 34:
|
257
|
+
if (!(this.bizFlowStartBehavior.behaviorType === 'REDIRECT')) {
|
258
|
+
_context3.next = 38;
|
259
|
+
break;
|
260
|
+
}
|
261
|
+
payload = (_this$bizFlowStartBeh = this.bizFlowStartBehavior) === null || _this$bizFlowStartBeh === void 0 ? void 0 : _this$bizFlowStartBeh.payload;
|
262
|
+
redirect(payload, this.instanceId);
|
263
|
+
return _context3.abrupt("return");
|
264
|
+
case 38:
|
265
|
+
case "end":
|
266
|
+
return _context3.stop();
|
267
|
+
}
|
268
|
+
}, _callee3, this, [[13, 26]]);
|
269
|
+
}));
|
270
|
+
function startBizFlow(_x5) {
|
271
|
+
return _startBizFlow.apply(this, arguments);
|
272
|
+
}
|
273
|
+
return startBizFlow;
|
274
|
+
}()
|
275
|
+
}, {
|
276
|
+
key: "getServiceProvider",
|
277
|
+
value: function getServiceProvider() {
|
278
|
+
return ServiceProvider.getInstance(this.instanceId);
|
279
|
+
}
|
280
|
+
}, {
|
281
|
+
key: "getBizFlowBehavior",
|
282
|
+
value: function getBizFlowBehavior() {
|
283
|
+
return this.bizFlowStartBehavior;
|
284
|
+
}
|
285
|
+
}, {
|
286
|
+
key: "getPaymentContext",
|
287
|
+
value: function getPaymentContext() {
|
288
|
+
return this.paymentContext;
|
289
|
+
}
|
290
|
+
}, {
|
291
|
+
key: "destroy",
|
292
|
+
value: function destroy() {
|
293
|
+
this.cleanRender(true);
|
294
|
+
}
|
295
|
+
}, {
|
296
|
+
key: "handleBehaviorRender",
|
297
|
+
value: function handleBehaviorRender() {
|
298
|
+
var _this2 = this;
|
299
|
+
var eventCenter = ServiceProvider.getInstance(this.instanceId).getService('EventCenter');
|
300
|
+
var containerService = ServiceProvider.getInstance(this.instanceId).getService('Container');
|
301
|
+
var displayType = this.paymentContext.displayInfo.type;
|
302
|
+
var platform = this.paymentContext.displayInfo.platform;
|
303
|
+
var payload = this.bizFlowStartBehavior.payload;
|
304
|
+
var closeBtnCallbackForPopup = function closeBtnCallbackForPopup() {
|
305
|
+
var isOnCloseEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
306
|
+
if (displayType === DisplayTypeEnum.inline) {
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
if (_this2.paymentContext.displayInfo.isRetention) {
|
310
|
+
showRetentionPopup();
|
311
|
+
return;
|
312
|
+
} else {
|
313
|
+
_this2.handleClose(isOnCloseEvent);
|
314
|
+
}
|
315
|
+
};
|
316
|
+
|
317
|
+
// TODO 感觉有死循环
|
318
|
+
eventCenter.listen(EVENT.close.name, function () {
|
319
|
+
closeBtnCallbackForPopup(true);
|
320
|
+
});
|
321
|
+
eventCenter.listen(EVENT.setAllowRetention.name, function (data) {
|
322
|
+
if (data === undefined || typeof data !== 'boolean') {
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
_this2.paymentContext.displayInfo.isRetention = data;
|
326
|
+
});
|
327
|
+
eventCenter.listen(EVENT.declareCheckoutInfo.name, function (data) {
|
328
|
+
handleDeclareInfo(data === null || data === void 0 ? void 0 : data.closeDialogData);
|
329
|
+
});
|
330
|
+
var container = containerService.load(this.paymentContext.displayInfo, payload.url, closeBtnCallbackForPopup);
|
331
|
+
if (displayType === DisplayTypeEnum.inline) {
|
332
|
+
containerService.showLoading(container, this.paymentContext.displayInfo);
|
333
|
+
insertStyleSheet();
|
334
|
+
return;
|
335
|
+
}
|
336
|
+
if (displayType == DisplayTypeEnum.popup) {
|
337
|
+
createRetentionPopup(platform, function () {
|
338
|
+
hideRetentionPopup();
|
339
|
+
}, function () {
|
340
|
+
hideRetentionPopup();
|
341
|
+
_this2.handleClose();
|
342
|
+
});
|
343
|
+
createMockup({
|
344
|
+
platform: platform,
|
345
|
+
onClickOutside: payload.allowClickPopupOutsideClose ? closeBtnCallbackForPopup : undefined,
|
346
|
+
closeBtnFunc: closeBtnCallbackForPopup
|
347
|
+
});
|
348
|
+
containerService.showLoading(container, this.paymentContext.displayInfo);
|
349
|
+
return;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
}, {
|
353
|
+
key: "handleClose",
|
354
|
+
value: function handleClose() {
|
355
|
+
var isOnCloseEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
356
|
+
var eventCenter = ServiceProvider.getInstance(this.instanceId).getService('EventCenter');
|
357
|
+
eventCenter.emit(EVENT.closeCallback.name, {});
|
358
|
+
if (this.enablePopWindowEventCallback && !isOnCloseEvent) {
|
359
|
+
eventCenter.emit(EVENT.eventCallback.name, {
|
360
|
+
code: eventCodeEnum.SDK_PAYMENT_CANCEL,
|
361
|
+
result: {
|
362
|
+
result: {}
|
363
|
+
}
|
364
|
+
});
|
365
|
+
}
|
366
|
+
this.cleanRender();
|
367
|
+
}
|
368
|
+
}, {
|
369
|
+
key: "cleanRender",
|
370
|
+
value: function cleanRender() {
|
371
|
+
var _this3 = this,
|
372
|
+
_document$getElementB,
|
373
|
+
_document$getElementB2;
|
374
|
+
var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
375
|
+
var containerService = ServiceProvider.getInstance(this.instanceId).getService('Container');
|
376
|
+
var cleanElement = function cleanElement() {
|
377
|
+
containerService.cleanContainer(_this3.paymentContext.displayInfo);
|
378
|
+
cleanMockup();
|
379
|
+
removeRetentionPopup();
|
380
|
+
// TODO @/component this.removeEventListener();
|
381
|
+
};
|
382
|
+
(_document$getElementB = document.getElementById(COMPONENT_CLOSE_MASK_BLOCK_ID)) === null || _document$getElementB === void 0 || _document$getElementB.remove();
|
383
|
+
(_document$getElementB2 = document.getElementById(LOADING_ID)) === null || _document$getElementB2 === void 0 || _document$getElementB2.remove();
|
384
|
+
containerService.startHideAnim();
|
385
|
+
hideMockup();
|
386
|
+
if (immediately) {
|
387
|
+
cleanElement();
|
388
|
+
return;
|
389
|
+
}
|
390
|
+
setTimeout(function () {
|
391
|
+
cleanElement();
|
392
|
+
}, 300);
|
393
|
+
}
|
394
|
+
}]);
|
395
|
+
return AntomSDKCore;
|
396
|
+
}();
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { DisplayTypeEnum, IoptionsParams, IPaymentSessionMetaData, PlatformEnum, ProductSceneEnum, TargetEnum } from '../types';
|
2
|
+
/**
|
3
|
+
* @author 谦彧 <zhangmian.zm@alipay.com>
|
4
|
+
* @date 2024/9/17
|
5
|
+
*/
|
6
|
+
/**
|
7
|
+
* Represent one transaction, each transaction has its own instance.
|
8
|
+
*/
|
9
|
+
export interface PaymentContext {
|
10
|
+
initOptions: IoptionsParams;
|
11
|
+
startBizFlowOptions: StartBizFlowOptions;
|
12
|
+
displayInfo: DisplayInfo;
|
13
|
+
paymentSession: string;
|
14
|
+
paymentSessionId: string;
|
15
|
+
paymentSessionObj: IPaymentSessionMetaData;
|
16
|
+
sdkMetaData: SDKMetaData;
|
17
|
+
}
|
18
|
+
export interface StartBizFlowOptions {
|
19
|
+
paymentSession: string;
|
20
|
+
displayInfo?: Partial<DisplayInfo>;
|
21
|
+
submitPayRequestExtra?: any;
|
22
|
+
isAppWebview?: boolean;
|
23
|
+
}
|
24
|
+
export declare class DisplayInfo {
|
25
|
+
type: DisplayTypeEnum;
|
26
|
+
platform: PlatformEnum;
|
27
|
+
isRetention: boolean;
|
28
|
+
selector: string;
|
29
|
+
appearance?: Record<string, any>;
|
30
|
+
appendAliasContainerId?: boolean;
|
31
|
+
constructor();
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Provide unique logic for specified product, or specified product and its payment method.
|
35
|
+
* Such as: EasySafePay, PayPal in Cashier
|
36
|
+
*/
|
37
|
+
export interface ProductProcessor {
|
38
|
+
init(config: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): any;
|
39
|
+
startBizFlow(paymentContext: PaymentContext): Promise<BizFlowStartBehavior>;
|
40
|
+
}
|
41
|
+
export interface BizFlowStartBehavior {
|
42
|
+
behaviorType: 'RENDER' | 'REDIRECT' | 'NONE';
|
43
|
+
payload: RenderBehaviorPayload | RedirectBehaviorPayload;
|
44
|
+
data?: any;
|
45
|
+
}
|
46
|
+
export interface RenderBehaviorPayload {
|
47
|
+
url: string;
|
48
|
+
allowClickPopupOutsideClose?: boolean;
|
49
|
+
}
|
50
|
+
export interface RedirectBehaviorPayload {
|
51
|
+
url?: string;
|
52
|
+
schemeUrl?: string;
|
53
|
+
applinkUrl?: string;
|
54
|
+
browserLinkTarget?: TargetEnum;
|
55
|
+
isCallApp?: boolean;
|
56
|
+
callAppDetectSuccessDelay?: number;
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* Provide some capability, such as MonitorService, EventBusService, SecurityService
|
60
|
+
*/
|
61
|
+
export interface Service {
|
62
|
+
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): any;
|
63
|
+
update(paymentContext: PaymentContext): any;
|
64
|
+
destroy(): any;
|
65
|
+
}
|
66
|
+
export interface SDKMetaData {
|
67
|
+
productScene: ProductSceneEnum;
|
68
|
+
sdkVersion: string;
|
69
|
+
webAppVersion: string;
|
70
|
+
greyscaleId: number;
|
71
|
+
}
|
72
|
+
export interface InitContext {
|
73
|
+
initOptions: IoptionsParams;
|
74
|
+
sdkMetaData: SDKMetaData;
|
75
|
+
}
|