@alipay/ams-checkout 0.0.1747014711-dev.7 → 0.0.1747907034-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +7 -7
- package/esm/core/component/ckp/index.js +0 -17
- package/esm/core/component/element/elementController/index.js +1 -2
- package/esm/core/component/element/util.d.ts +7 -0
- package/esm/core/component/element/util.js +193 -1
- package/package.json +1 -1
- package/esm/util/redirect.d.ts +0 -7
- package/esm/util/redirect.js +0 -199
package/esm/config/index.d.ts
CHANGED
@@ -5,10 +5,10 @@ export declare const sdkVersion: string;
|
|
5
5
|
/**
|
6
6
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
7
7
|
*/
|
8
|
-
export declare const AMSCheckoutAppVersion = "1.
|
9
|
-
export declare const AMSAutoDebitAppVersion = "1.
|
10
|
-
export declare const AMSEasyPayAppVersion = "1.
|
11
|
-
export declare const AMSCashierPaymentAppVersion = "1.
|
12
|
-
export declare const AMSVaultingAppVersion = "1.
|
13
|
-
export declare const AMSPaymentElementAppVersion = "1.
|
14
|
-
export declare const ADDRESSElementAppVersion = "1.
|
8
|
+
export declare const AMSCheckoutAppVersion = "1.36.0";
|
9
|
+
export declare const AMSAutoDebitAppVersion = "1.36.0";
|
10
|
+
export declare const AMSEasyPayAppVersion = "1.36.0";
|
11
|
+
export declare const AMSCashierPaymentAppVersion = "1.36.0";
|
12
|
+
export declare const AMSVaultingAppVersion = "1.36.0";
|
13
|
+
export declare const AMSPaymentElementAppVersion = "1.36.0";
|
14
|
+
export declare const ADDRESSElementAppVersion = "1.36.0";
|
package/esm/config/index.js
CHANGED
@@ -35,10 +35,10 @@ export var sdkVersion = json.version;
|
|
35
35
|
/**
|
36
36
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
37
37
|
*/
|
38
|
-
export var AMSCheckoutAppVersion = '1.
|
39
|
-
export var AMSAutoDebitAppVersion = '1.
|
40
|
-
export var AMSEasyPayAppVersion = '1.
|
41
|
-
export var AMSCashierPaymentAppVersion = '1.
|
42
|
-
export var AMSVaultingAppVersion = '1.
|
43
|
-
export var AMSPaymentElementAppVersion = '1.
|
44
|
-
export var ADDRESSElementAppVersion = '1.
|
38
|
+
export var AMSCheckoutAppVersion = '1.36.0'; // 兜底版本号
|
39
|
+
export var AMSAutoDebitAppVersion = '1.36.0'; // 代扣
|
40
|
+
export var AMSEasyPayAppVersion = '1.36.0'; // easypay
|
41
|
+
export var AMSCashierPaymentAppVersion = '1.36.0'; // 收银台(卡、apm)
|
42
|
+
export var AMSVaultingAppVersion = '1.36.0'; // 绑卡
|
43
|
+
export var AMSPaymentElementAppVersion = '1.36.0'; // payment element
|
44
|
+
export var ADDRESSElementAppVersion = '1.36.0'; // address element
|
@@ -9,7 +9,6 @@ import { v4 as uuid } from 'uuid';
|
|
9
9
|
import { EnvironmentEnum } from "../../../types";
|
10
10
|
import { queryParse } from "../../../util";
|
11
11
|
import { LogConfig, Logger } from "../../../util/logger";
|
12
|
-
import { handleRedirect } from "../../../util/redirect";
|
13
12
|
var CKP_PAYMENT_PAGE_HOST = {
|
14
13
|
DEV: 'https://dev.page.alipay.net',
|
15
14
|
TEST: 'https://test.page.alipay.net',
|
@@ -69,15 +68,10 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
|
|
69
68
|
return url;
|
70
69
|
});
|
71
70
|
_defineProperty(this, "eventListenerWrapper", function (event) {
|
72
|
-
var dataObj = JSON.parse(event.data) || {};
|
73
71
|
var _ref = JSON.parse(event.data) || {},
|
74
72
|
code = _ref.code,
|
75
73
|
message = _ref.message,
|
76
74
|
result = _ref.result;
|
77
|
-
var _dataObj$context = dataObj === null || dataObj === void 0 ? void 0 : dataObj.context,
|
78
|
-
eventCode = _dataObj$context.event,
|
79
|
-
data = _dataObj$context.data;
|
80
|
-
console.log(eventCode, 'eventCode', eventCode && (eventCode === null || eventCode === void 0 ? void 0 : eventCode.startsWith('onRedirectCode')), "🚀 ~ onRedirectCodeAMSCheckoutPage ~ dataObj:", dataObj, dataObj === null || dataObj === void 0 ? void 0 : dataObj.context);
|
81
75
|
if (code && code.startsWith('SDK_PAYMENT')) {
|
82
76
|
var _this$eventListener;
|
83
77
|
console.log('[antom-web-sdk] <antom-checkout-page> eventListenerWrapper', event, message, result);
|
@@ -87,16 +81,6 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
|
|
87
81
|
result: result
|
88
82
|
});
|
89
83
|
}
|
90
|
-
if (eventCode && eventCode !== null && eventCode !== void 0 && eventCode.startsWith('onRedirect')) {
|
91
|
-
var _this$eventListener2;
|
92
|
-
console.log(eventCode, '[antom-web-sdk] <antom-checkout-page> onRedirectCode', data);
|
93
|
-
(_this$eventListener2 = _this.eventListener) === null || _this$eventListener2 === void 0 || _this$eventListener2.call(_this, {
|
94
|
-
code: code,
|
95
|
-
message: message,
|
96
|
-
result: result
|
97
|
-
});
|
98
|
-
handleRedirect(data);
|
99
|
-
}
|
100
84
|
});
|
101
85
|
_defineProperty(this, "addListener", function () {
|
102
86
|
window.addEventListener('message', _this.eventListenerWrapper);
|
@@ -145,7 +129,6 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
|
|
145
129
|
throw new Error('PARAMS_ERROR_ALREADY_MOUNTED');
|
146
130
|
}
|
147
131
|
this.addListener();
|
148
|
-
console.log("🚀 ~ AMSCheckoutPage======== ~ event:", event);
|
149
132
|
var ckpPageAddress = this.generateIframeSrc(params.sessionData);
|
150
133
|
var iframe = document.createElement('iframe');
|
151
134
|
iframe.id = this.APP_IFRAME_ID;
|
@@ -33,8 +33,7 @@ import { ElementContainerService } from "../elementContainerService"; // 引入
|
|
33
33
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
34
34
|
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
35
35
|
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode } from "../type";
|
36
|
-
import { checkCanMount, checkCanUpdate, showToast } from "../util";
|
37
|
-
import { handleRedirect } from "../../../../util/redirect";
|
36
|
+
import { checkCanMount, checkCanUpdate, handleRedirect, showToast } from "../util";
|
38
37
|
var TIMEOUT_DURATION = 10000;
|
39
38
|
var ElementController = /*#__PURE__*/function () {
|
40
39
|
// 新增变量
|
@@ -49,6 +49,13 @@ export declare function generateIframeSrc({ paymentSessionObj, paymentSession, i
|
|
49
49
|
appVersion: string;
|
50
50
|
link?: string;
|
51
51
|
}): string;
|
52
|
+
export declare function handleRedirect(data: any, fromFastSdk?: boolean): void;
|
53
|
+
export declare function redirect(data: {
|
54
|
+
normalUrl?: string;
|
55
|
+
schemeUrl?: string;
|
56
|
+
applinkUrl?: string;
|
57
|
+
callAppJudgeTime?: number;
|
58
|
+
}): Promise<void>;
|
52
59
|
export declare function showToast(options?: IToastOptions, callback?: Function): void;
|
53
60
|
export declare const isElementMobile: () => boolean;
|
54
61
|
/**
|
@@ -10,9 +10,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
10
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
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
12
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 { ERRORMESSAGE } from "../../../constant";
|
13
14
|
import { IElementStatus } from "../../../foundation";
|
14
15
|
import { getIframeUrl } from "../../../plugin/component/cashierApp";
|
15
|
-
import { DisplayTypeEnum } from "../../../types";
|
16
|
+
import { DisplayTypeEnum, RedirectType, TargetEnum, terminalTypeEnum } from "../../../types";
|
17
|
+
import { device } from "../../../util/index";
|
18
|
+
import CallApp from "../../../util/intl-callapp/es/main";
|
16
19
|
import { getComponentSign, parseSessionData } from "../index";
|
17
20
|
import { ELEMENT_ENVIRONMENT } from "./type";
|
18
21
|
var formatElementOption = function formatElementOption(options) {
|
@@ -132,6 +135,195 @@ export function generateIframeSrc(_ref3) {
|
|
132
135
|
console.log('[debug] generateIframeSrc', path, locationSearch);
|
133
136
|
return "".concat(path, "?").concat(locationSearch);
|
134
137
|
}
|
138
|
+
export function handleRedirect(data) {
|
139
|
+
var _data$isDestroy, _data$isCallApp, _data$callAppDetectSu;
|
140
|
+
var fromFastSdk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
141
|
+
console.log('local payment sdk new element redirect arg ----', this);
|
142
|
+
var _data = typeof data === 'string' ? {
|
143
|
+
normalUrl: data
|
144
|
+
} : _objectSpread(_objectSpread({}, data), {}, {
|
145
|
+
applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
|
146
|
+
schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
|
147
|
+
normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
|
148
|
+
target: data === null || data === void 0 ? void 0 : data.target,
|
149
|
+
isDestroy: (_data$isDestroy = data === null || data === void 0 ? void 0 : data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true,
|
150
|
+
isCallApp: (_data$isCallApp = data === null || data === void 0 ? void 0 : data.isCallApp) !== null && _data$isCallApp !== void 0 ? _data$isCallApp : false,
|
151
|
+
callAppDetectSuccessDelay: (_data$callAppDetectSu = data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) !== null && _data$callAppDetectSu !== void 0 ? _data$callAppDetectSu : 2000
|
152
|
+
});
|
153
|
+
// const logParams = {
|
154
|
+
// applinkUrl: data?.applinkUrl || '',
|
155
|
+
// schemeUrl: data?.schemeUrl || '',
|
156
|
+
// normalUrl: data?.normalUrl || '',
|
157
|
+
// target: data?.target,
|
158
|
+
// isDestroy: data?.isDestroy ?? true,
|
159
|
+
// isCallApp: data?.isCallApp ?? false,
|
160
|
+
// callAppDetectSuccessDelay: data?.callAppDetectSuccessDelay ?? 2000,
|
161
|
+
// };
|
162
|
+
// this.AMSSDK.logger
|
163
|
+
// .logInfo(
|
164
|
+
// {
|
165
|
+
// title: 'sdk_event_call_url_start',
|
166
|
+
// },
|
167
|
+
// {
|
168
|
+
// redirectInfo: JSON.stringify(logParams),
|
169
|
+
// },
|
170
|
+
// )
|
171
|
+
// .send();
|
172
|
+
var successCallback = function successCallback(type, url, durationInSeconds) {
|
173
|
+
// TODO
|
174
|
+
// event.dispatchToSDK(EVENT.eventCallback.name, {
|
175
|
+
// code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
|
176
|
+
// message: `Successfully opened the app,${type}: ${url}`,
|
177
|
+
// });
|
178
|
+
var extra = {
|
179
|
+
redirectInfo: JSON.stringify(_data),
|
180
|
+
openType: type,
|
181
|
+
url: url,
|
182
|
+
fromFastSdk: fromFastSdk
|
183
|
+
};
|
184
|
+
if (durationInSeconds) {
|
185
|
+
extra['durationInSeconds'] = durationInSeconds;
|
186
|
+
}
|
187
|
+
// this.AMSSDK.logger
|
188
|
+
// .logInfo(
|
189
|
+
// {
|
190
|
+
// title: 'sdk_event_call_url_success',
|
191
|
+
// },
|
192
|
+
// extra,
|
193
|
+
// )
|
194
|
+
// .send();
|
195
|
+
};
|
196
|
+
var failCallback = function failCallback(type, url, durationInSeconds) {
|
197
|
+
// event.dispatchToSDK(EVENT.eventCallback.name, {
|
198
|
+
// code: eventCodeEnum.SDK_CALL_URL_ERROR,
|
199
|
+
// message: `Failed to open app,applinkUrl: ${_data?.applinkUrl} schemeUrl: ${_data?.schemeUrl} normalUrl: ${_data?.normalUrl}`,
|
200
|
+
// });
|
201
|
+
var extra = {
|
202
|
+
redirectInfo: JSON.stringify(_data),
|
203
|
+
openType: type,
|
204
|
+
url: url,
|
205
|
+
fromFastSdk: fromFastSdk
|
206
|
+
};
|
207
|
+
if (durationInSeconds) {
|
208
|
+
extra['durationInSeconds'] = durationInSeconds;
|
209
|
+
}
|
210
|
+
// this.AMSSDK.logger
|
211
|
+
// .logInfo(
|
212
|
+
// {
|
213
|
+
// title: 'sdk_error_call_url_failed',
|
214
|
+
// },
|
215
|
+
// extra,
|
216
|
+
// )
|
217
|
+
// .send();
|
218
|
+
};
|
219
|
+
|
220
|
+
// 支持 target: _blank,新开tab页打开
|
221
|
+
if (_data.target === TargetEnum.BLANK) {
|
222
|
+
if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
|
223
|
+
successCallback(RedirectType.NormalUrl, _data.normalUrl);
|
224
|
+
window.open(_data.normalUrl);
|
225
|
+
return;
|
226
|
+
}
|
227
|
+
if (_data.target === TargetEnum.REPLACE && !(_data !== null && _data !== void 0 && _data.applinkUrl) && !(_data !== null && _data !== void 0 && _data.schemeUrl)) {
|
228
|
+
if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
|
229
|
+
successCallback(RedirectType.NormalUrl, _data.normalUrl);
|
230
|
+
window.location.replace(_data.normalUrl);
|
231
|
+
return;
|
232
|
+
}
|
233
|
+
// TODO 销毁iframe和全局loading
|
234
|
+
// if (_data?.isDestroy) this.cleanContainer();
|
235
|
+
// 唤端
|
236
|
+
if (_data !== null && _data !== void 0 && _data.isCallApp && _data !== null && _data !== void 0 && _data.schemeUrl) {
|
237
|
+
var startCallAppTime = new Date();
|
238
|
+
var detectSuccessDelay = typeof (data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) === 'number' ? data.callAppDetectSuccessDelay : 5000;
|
239
|
+
redirect({
|
240
|
+
schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl,
|
241
|
+
callAppJudgeTime: detectSuccessDelay
|
242
|
+
}).then(function () {
|
243
|
+
var endCallAppTime = new Date();
|
244
|
+
var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
|
245
|
+
var durationInSeconds = durationInMilliseconds / 1000;
|
246
|
+
successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl, durationInSeconds);
|
247
|
+
}).catch(function () {
|
248
|
+
var endCallAppTime = new Date();
|
249
|
+
var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
|
250
|
+
var durationInSeconds = durationInMilliseconds / 1000;
|
251
|
+
failCallback(RedirectType.SchemeUrl, _data.schemeUrl, durationInSeconds);
|
252
|
+
});
|
253
|
+
return;
|
254
|
+
}
|
255
|
+
redirect({
|
256
|
+
applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
|
257
|
+
}).then(function () {
|
258
|
+
successCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
|
259
|
+
}).catch(function () {
|
260
|
+
if (_data !== null && _data !== void 0 && _data.applinkUrl) failCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
|
261
|
+
return redirect({
|
262
|
+
schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl
|
263
|
+
});
|
264
|
+
}).then(function () {
|
265
|
+
successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
|
266
|
+
}).catch(function () {
|
267
|
+
if (_data !== null && _data !== void 0 && _data.schemeUrl) failCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
|
268
|
+
return redirect({
|
269
|
+
normalUrl: _data === null || _data === void 0 ? void 0 : _data.normalUrl
|
270
|
+
});
|
271
|
+
}).then(function () {
|
272
|
+
successCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
|
273
|
+
}).catch(function () {
|
274
|
+
failCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
|
275
|
+
});
|
276
|
+
}
|
277
|
+
export function redirect(data) {
|
278
|
+
return new Promise(function (resolve, reject) {
|
279
|
+
var terminalType = device.isMobile ? terminalTypeEnum.WAP : terminalTypeEnum.WEB;
|
280
|
+
var isWeb = terminalType === terminalTypeEnum.WEB;
|
281
|
+
var normalUrl = (data === null || data === void 0 ? void 0 : data.normalUrl) || '';
|
282
|
+
var schemeUrl = (data === null || data === void 0 ? void 0 : data.schemeUrl) || '';
|
283
|
+
var applinkUrl = (data === null || data === void 0 ? void 0 : data.applinkUrl) || '';
|
284
|
+
var callAppJudgeTime = (data === null || data === void 0 ? void 0 : data.callAppJudgeTime) || '';
|
285
|
+
var jumpFunc = function jumpFunc() {
|
286
|
+
if (normalUrl) {
|
287
|
+
resolve();
|
288
|
+
window.location.href = normalUrl;
|
289
|
+
return;
|
290
|
+
}
|
291
|
+
reject(ERRORMESSAGE.SDK_CALL_URL_ERROR.REDIRECT_ERROR);
|
292
|
+
};
|
293
|
+
var callAppFunc = function callAppFunc() {
|
294
|
+
if (!schemeUrl && !applinkUrl) {
|
295
|
+
jumpFunc();
|
296
|
+
return;
|
297
|
+
}
|
298
|
+
var config = {
|
299
|
+
fallback: function fallback() {
|
300
|
+
jumpFunc();
|
301
|
+
},
|
302
|
+
successCb: function successCb() {
|
303
|
+
resolve();
|
304
|
+
},
|
305
|
+
delay: 0
|
306
|
+
};
|
307
|
+
if (callAppJudgeTime) {
|
308
|
+
config['resultJudgmentTime'] = callAppJudgeTime;
|
309
|
+
}
|
310
|
+
try {
|
311
|
+
var callLib = new CallApp(config);
|
312
|
+
callLib.open({
|
313
|
+
scheme: schemeUrl,
|
314
|
+
link: applinkUrl
|
315
|
+
});
|
316
|
+
} catch (error) {
|
317
|
+
jumpFunc();
|
318
|
+
}
|
319
|
+
};
|
320
|
+
if (isWeb) {
|
321
|
+
jumpFunc();
|
322
|
+
} else {
|
323
|
+
callAppFunc();
|
324
|
+
}
|
325
|
+
});
|
326
|
+
}
|
135
327
|
export function showToast() {
|
136
328
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
137
329
|
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
package/package.json
CHANGED
package/esm/util/redirect.d.ts
DELETED
package/esm/util/redirect.js
DELETED
@@ -1,199 +0,0 @@
|
|
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 _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; }
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
6
|
-
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); }
|
7
|
-
import { ERRORMESSAGE } from "../constant";
|
8
|
-
import CallApp from "./intl-callapp/es/main";
|
9
|
-
import { RedirectType, TargetEnum, terminalTypeEnum } from "../types";
|
10
|
-
import { device } from ".";
|
11
|
-
export function handleRedirect(data) {
|
12
|
-
var _data$isDestroy, _data$isCallApp, _data$callAppDetectSu;
|
13
|
-
var fromFastSdk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
14
|
-
console.log('local payment sdk new element redirect arg ----', this);
|
15
|
-
var _data = typeof data === 'string' ? {
|
16
|
-
normalUrl: data
|
17
|
-
} : _objectSpread(_objectSpread({}, data), {}, {
|
18
|
-
applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
|
19
|
-
schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
|
20
|
-
normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
|
21
|
-
target: data === null || data === void 0 ? void 0 : data.target,
|
22
|
-
isDestroy: (_data$isDestroy = data === null || data === void 0 ? void 0 : data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true,
|
23
|
-
isCallApp: (_data$isCallApp = data === null || data === void 0 ? void 0 : data.isCallApp) !== null && _data$isCallApp !== void 0 ? _data$isCallApp : false,
|
24
|
-
callAppDetectSuccessDelay: (_data$callAppDetectSu = data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) !== null && _data$callAppDetectSu !== void 0 ? _data$callAppDetectSu : 2000
|
25
|
-
});
|
26
|
-
// const logParams = {
|
27
|
-
// applinkUrl: data?.applinkUrl || '',
|
28
|
-
// schemeUrl: data?.schemeUrl || '',
|
29
|
-
// normalUrl: data?.normalUrl || '',
|
30
|
-
// target: data?.target,
|
31
|
-
// isDestroy: data?.isDestroy ?? true,
|
32
|
-
// isCallApp: data?.isCallApp ?? false,
|
33
|
-
// callAppDetectSuccessDelay: data?.callAppDetectSuccessDelay ?? 2000,
|
34
|
-
// };
|
35
|
-
// this.AMSSDK.logger
|
36
|
-
// .logInfo(
|
37
|
-
// {
|
38
|
-
// title: 'sdk_event_call_url_start',
|
39
|
-
// },
|
40
|
-
// {
|
41
|
-
// redirectInfo: JSON.stringify(logParams),
|
42
|
-
// },
|
43
|
-
// )
|
44
|
-
// .send();
|
45
|
-
var successCallback = function successCallback(type, url, durationInSeconds) {
|
46
|
-
// TODO
|
47
|
-
// event.dispatchToSDK(EVENT.eventCallback.name, {
|
48
|
-
// code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
|
49
|
-
// message: `Successfully opened the app,${type}: ${url}`,
|
50
|
-
// });
|
51
|
-
var extra = {
|
52
|
-
redirectInfo: JSON.stringify(_data),
|
53
|
-
openType: type,
|
54
|
-
url: url,
|
55
|
-
fromFastSdk: fromFastSdk
|
56
|
-
};
|
57
|
-
if (durationInSeconds) {
|
58
|
-
extra['durationInSeconds'] = durationInSeconds;
|
59
|
-
}
|
60
|
-
// this.AMSSDK.logger
|
61
|
-
// .logInfo(
|
62
|
-
// {
|
63
|
-
// title: 'sdk_event_call_url_success',
|
64
|
-
// },
|
65
|
-
// extra,
|
66
|
-
// )
|
67
|
-
// .send();
|
68
|
-
};
|
69
|
-
var failCallback = function failCallback(type, url, durationInSeconds) {
|
70
|
-
// event.dispatchToSDK(EVENT.eventCallback.name, {
|
71
|
-
// code: eventCodeEnum.SDK_CALL_URL_ERROR,
|
72
|
-
// message: `Failed to open app,applinkUrl: ${_data?.applinkUrl} schemeUrl: ${_data?.schemeUrl} normalUrl: ${_data?.normalUrl}`,
|
73
|
-
// });
|
74
|
-
var extra = {
|
75
|
-
redirectInfo: JSON.stringify(_data),
|
76
|
-
openType: type,
|
77
|
-
url: url,
|
78
|
-
fromFastSdk: fromFastSdk
|
79
|
-
};
|
80
|
-
if (durationInSeconds) {
|
81
|
-
extra['durationInSeconds'] = durationInSeconds;
|
82
|
-
}
|
83
|
-
// this.AMSSDK.logger
|
84
|
-
// .logInfo(
|
85
|
-
// {
|
86
|
-
// title: 'sdk_error_call_url_failed',
|
87
|
-
// },
|
88
|
-
// extra,
|
89
|
-
// )
|
90
|
-
// .send();
|
91
|
-
};
|
92
|
-
|
93
|
-
// 支持 target: _blank,新开tab页打开
|
94
|
-
if (_data.target === TargetEnum.BLANK) {
|
95
|
-
if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
|
96
|
-
successCallback(RedirectType.NormalUrl, _data.normalUrl);
|
97
|
-
window.open(_data.normalUrl);
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
if (_data.target === TargetEnum.REPLACE && !(_data !== null && _data !== void 0 && _data.applinkUrl) && !(_data !== null && _data !== void 0 && _data.schemeUrl)) {
|
101
|
-
if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
|
102
|
-
successCallback(RedirectType.NormalUrl, _data.normalUrl);
|
103
|
-
window.location.replace(_data.normalUrl);
|
104
|
-
return;
|
105
|
-
}
|
106
|
-
// TODO 销毁iframe和全局loading
|
107
|
-
// if (_data?.isDestroy) this.cleanContainer();
|
108
|
-
// 唤端
|
109
|
-
if (_data !== null && _data !== void 0 && _data.isCallApp && _data !== null && _data !== void 0 && _data.schemeUrl) {
|
110
|
-
var startCallAppTime = new Date();
|
111
|
-
var detectSuccessDelay = typeof (data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) === 'number' ? data.callAppDetectSuccessDelay : 5000;
|
112
|
-
redirect({
|
113
|
-
schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl,
|
114
|
-
callAppJudgeTime: detectSuccessDelay
|
115
|
-
}).then(function () {
|
116
|
-
var endCallAppTime = new Date();
|
117
|
-
var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
|
118
|
-
var durationInSeconds = durationInMilliseconds / 1000;
|
119
|
-
successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl, durationInSeconds);
|
120
|
-
}).catch(function () {
|
121
|
-
var endCallAppTime = new Date();
|
122
|
-
var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
|
123
|
-
var durationInSeconds = durationInMilliseconds / 1000;
|
124
|
-
failCallback(RedirectType.SchemeUrl, _data.schemeUrl, durationInSeconds);
|
125
|
-
});
|
126
|
-
return;
|
127
|
-
}
|
128
|
-
redirect({
|
129
|
-
applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
|
130
|
-
}).then(function () {
|
131
|
-
successCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
|
132
|
-
}).catch(function () {
|
133
|
-
if (_data !== null && _data !== void 0 && _data.applinkUrl) failCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
|
134
|
-
return redirect({
|
135
|
-
schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl
|
136
|
-
});
|
137
|
-
}).then(function () {
|
138
|
-
successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
|
139
|
-
}).catch(function () {
|
140
|
-
if (_data !== null && _data !== void 0 && _data.schemeUrl) failCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
|
141
|
-
return redirect({
|
142
|
-
normalUrl: _data === null || _data === void 0 ? void 0 : _data.normalUrl
|
143
|
-
});
|
144
|
-
}).then(function () {
|
145
|
-
successCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
|
146
|
-
}).catch(function () {
|
147
|
-
failCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
|
148
|
-
});
|
149
|
-
}
|
150
|
-
export function redirect(data) {
|
151
|
-
return new Promise(function (resolve, reject) {
|
152
|
-
var terminalType = device.isMobile ? terminalTypeEnum.WAP : terminalTypeEnum.WEB;
|
153
|
-
var isWeb = terminalType === terminalTypeEnum.WEB;
|
154
|
-
var normalUrl = (data === null || data === void 0 ? void 0 : data.normalUrl) || '';
|
155
|
-
var schemeUrl = (data === null || data === void 0 ? void 0 : data.schemeUrl) || '';
|
156
|
-
var applinkUrl = (data === null || data === void 0 ? void 0 : data.applinkUrl) || '';
|
157
|
-
var callAppJudgeTime = (data === null || data === void 0 ? void 0 : data.callAppJudgeTime) || '';
|
158
|
-
var jumpFunc = function jumpFunc() {
|
159
|
-
if (normalUrl) {
|
160
|
-
resolve();
|
161
|
-
window.location.href = normalUrl;
|
162
|
-
return;
|
163
|
-
}
|
164
|
-
reject(ERRORMESSAGE.SDK_CALL_URL_ERROR.REDIRECT_ERROR);
|
165
|
-
};
|
166
|
-
var callAppFunc = function callAppFunc() {
|
167
|
-
if (!schemeUrl && !applinkUrl) {
|
168
|
-
jumpFunc();
|
169
|
-
return;
|
170
|
-
}
|
171
|
-
var config = {
|
172
|
-
fallback: function fallback() {
|
173
|
-
jumpFunc();
|
174
|
-
},
|
175
|
-
successCb: function successCb() {
|
176
|
-
resolve();
|
177
|
-
},
|
178
|
-
delay: 0
|
179
|
-
};
|
180
|
-
if (callAppJudgeTime) {
|
181
|
-
config['resultJudgmentTime'] = callAppJudgeTime;
|
182
|
-
}
|
183
|
-
try {
|
184
|
-
var callLib = new CallApp(config);
|
185
|
-
callLib.open({
|
186
|
-
scheme: schemeUrl,
|
187
|
-
link: applinkUrl
|
188
|
-
});
|
189
|
-
} catch (error) {
|
190
|
-
jumpFunc();
|
191
|
-
}
|
192
|
-
};
|
193
|
-
if (isWeb) {
|
194
|
-
jumpFunc();
|
195
|
-
} else {
|
196
|
-
callAppFunc();
|
197
|
-
}
|
198
|
-
});
|
199
|
-
}
|