@alipay/ams-checkout 0.0.1747014711-dev.5 → 0.0.1747014711-dev.7
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 +2 -2
- package/esm/core/component/element/elementContainerService/containerService.js +2 -2
- package/esm/core/component/element/elementController/index.js +17 -10
- package/esm/core/component/element/elementProcessor/baseElementProcessor.d.ts +3 -0
- package/esm/core/component/element/elementProcessor/baseElementProcessor.js +11 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +15 -8
- package/esm/core/component/element/index.js +6 -1
- package/esm/core/component/element/util.d.ts +6 -7
- package/esm/core/component/element/util.js +28 -193
- package/esm/core/instance/index.d.ts +1 -1
- package/esm/plugin/type.d.ts +1 -1
- package/esm/util/redirect.d.ts +7 -0
- package/esm/util/redirect.js +199 -0
- package/package.json +1 -1
@@ -0,0 +1,199 @@
|
|
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
|
+
}
|