@pisell/pisellos 0.0.229 → 0.0.230
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/modules/Payment/index.d.ts +59 -6
- package/dist/modules/Payment/index.js +823 -504
- package/dist/modules/Payment/types.d.ts +62 -32
- package/dist/modules/Payment/types.js +2 -2
- package/dist/modules/Payment/walletpass.d.ts +0 -0
- package/dist/modules/Payment/walletpass.js +0 -0
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/appointmentDemo.json +1 -0
- package/dist/solution/Checkout/index.d.ts +181 -0
- package/dist/solution/Checkout/index.js +1596 -0
- package/dist/solution/Checkout/types.d.ts +550 -0
- package/dist/solution/Checkout/types.js +132 -0
- package/dist/solution/Checkout/utils/index.d.ts +73 -0
- package/dist/solution/Checkout/utils/index.js +371 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/modules/Payment/index.d.ts +59 -6
- package/lib/modules/Payment/index.js +203 -64
- package/lib/modules/Payment/types.d.ts +62 -32
- package/lib/modules/Payment/walletpass.d.ts +0 -0
- package/lib/modules/Payment/walletpass.js +0 -0
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/appointmentDemo.json +1 -0
- package/lib/solution/Checkout/index.d.ts +181 -0
- package/lib/solution/Checkout/index.js +864 -0
- package/lib/solution/Checkout/types.d.ts +550 -0
- package/lib/solution/Checkout/types.js +75 -0
- package/lib/solution/Checkout/utils/index.d.ts +73 -0
- package/lib/solution/Checkout/utils/index.js +266 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/solution/Checkout/utils/index.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
calculateProgress: () => calculateProgress,
|
|
23
|
+
createCheckoutError: () => createCheckoutError,
|
|
24
|
+
debounce: () => debounce,
|
|
25
|
+
deepClone: () => deepClone,
|
|
26
|
+
formatAmount: () => formatAmount,
|
|
27
|
+
generateOrderId: () => generateOrderId,
|
|
28
|
+
getErrorMessage: () => getErrorMessage,
|
|
29
|
+
isEmpty: () => isEmpty,
|
|
30
|
+
isProduction: () => isProduction,
|
|
31
|
+
isValidPaymentMethodCode: () => isValidPaymentMethodCode,
|
|
32
|
+
logger: () => logger,
|
|
33
|
+
retry: () => retry,
|
|
34
|
+
safeJsonParse: () => safeJsonParse,
|
|
35
|
+
throttle: () => throttle,
|
|
36
|
+
validateAmount: () => validateAmount,
|
|
37
|
+
validateCheckoutData: () => validateCheckoutData
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(utils_exports);
|
|
40
|
+
var import_types = require("../types");
|
|
41
|
+
function validateCheckoutData(params) {
|
|
42
|
+
const errors = [];
|
|
43
|
+
if (!params.cartItems || params.cartItems.length === 0) {
|
|
44
|
+
errors.push("购物车不能为空");
|
|
45
|
+
}
|
|
46
|
+
if (params.cartItems) {
|
|
47
|
+
params.cartItems.forEach((item, index) => {
|
|
48
|
+
if (!item.id) {
|
|
49
|
+
errors.push(`购物车商品 ${index + 1} 缺少商品ID`);
|
|
50
|
+
}
|
|
51
|
+
if (!item.price || parseFloat(String(item.price)) < 0) {
|
|
52
|
+
errors.push(`购物车商品 ${index + 1} 价格无效`);
|
|
53
|
+
}
|
|
54
|
+
if (!item.num || item.num <= 0) {
|
|
55
|
+
errors.push(`购物车商品 ${index + 1} 数量无效`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (params.orderType && !["virtual", "appointment_booking"].includes(params.orderType)) {
|
|
60
|
+
errors.push("订单类型无效,必须是 virtual 或 appointment_booking");
|
|
61
|
+
}
|
|
62
|
+
if (params.platform && !["pc", "h5"].includes(params.platform)) {
|
|
63
|
+
errors.push("平台类型无效,必须是 pc 或 h5");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
valid: errors.length === 0,
|
|
67
|
+
errors
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function createCheckoutError(type, message, details) {
|
|
71
|
+
return {
|
|
72
|
+
type,
|
|
73
|
+
message,
|
|
74
|
+
details,
|
|
75
|
+
timestamp: Date.now()
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function calculateProgress(status, step) {
|
|
79
|
+
let baseProgress = 0;
|
|
80
|
+
switch (status) {
|
|
81
|
+
case import_types.CheckoutStatus.Initializing:
|
|
82
|
+
baseProgress = 5;
|
|
83
|
+
break;
|
|
84
|
+
case import_types.CheckoutStatus.Ready:
|
|
85
|
+
baseProgress = 10;
|
|
86
|
+
break;
|
|
87
|
+
case import_types.CheckoutStatus.CreatingOrder:
|
|
88
|
+
baseProgress = 25;
|
|
89
|
+
break;
|
|
90
|
+
case import_types.CheckoutStatus.OrderCreated:
|
|
91
|
+
baseProgress = 40;
|
|
92
|
+
break;
|
|
93
|
+
case import_types.CheckoutStatus.ProcessingPayment:
|
|
94
|
+
baseProgress = 65;
|
|
95
|
+
break;
|
|
96
|
+
case import_types.CheckoutStatus.PaymentCompleted:
|
|
97
|
+
baseProgress = 85;
|
|
98
|
+
break;
|
|
99
|
+
case import_types.CheckoutStatus.Completed:
|
|
100
|
+
baseProgress = 100;
|
|
101
|
+
break;
|
|
102
|
+
case import_types.CheckoutStatus.Cancelled:
|
|
103
|
+
case import_types.CheckoutStatus.Error:
|
|
104
|
+
baseProgress = 0;
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
baseProgress = 0;
|
|
108
|
+
}
|
|
109
|
+
let stepProgress = 0;
|
|
110
|
+
switch (step) {
|
|
111
|
+
case import_types.CheckoutStep.OrderConfirmation:
|
|
112
|
+
stepProgress = 0;
|
|
113
|
+
break;
|
|
114
|
+
case import_types.CheckoutStep.PaymentMethod:
|
|
115
|
+
stepProgress = 10;
|
|
116
|
+
break;
|
|
117
|
+
case import_types.CheckoutStep.PaymentProcessing:
|
|
118
|
+
stepProgress = 15;
|
|
119
|
+
break;
|
|
120
|
+
case import_types.CheckoutStep.Complete:
|
|
121
|
+
stepProgress = 0;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
return Math.min(100, baseProgress + stepProgress);
|
|
125
|
+
}
|
|
126
|
+
function formatAmount(amount) {
|
|
127
|
+
const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
128
|
+
if (isNaN(numAmount))
|
|
129
|
+
return "0.00";
|
|
130
|
+
return numAmount.toFixed(2);
|
|
131
|
+
}
|
|
132
|
+
function validateAmount(amount) {
|
|
133
|
+
const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
134
|
+
return !isNaN(numAmount) && numAmount >= 0;
|
|
135
|
+
}
|
|
136
|
+
function generateOrderId(prefix = "order") {
|
|
137
|
+
const timestamp = Date.now();
|
|
138
|
+
const random = Math.floor(Math.random() * 1e4).toString().padStart(4, "0");
|
|
139
|
+
return `${prefix}_${timestamp}_${random}`;
|
|
140
|
+
}
|
|
141
|
+
function isValidPaymentMethodCode(code) {
|
|
142
|
+
return typeof code === "string" && code.length > 0 && /^[a-zA-Z0-9_-]+$/.test(code);
|
|
143
|
+
}
|
|
144
|
+
function safeJsonParse(jsonString, defaultValue) {
|
|
145
|
+
try {
|
|
146
|
+
return JSON.parse(jsonString);
|
|
147
|
+
} catch {
|
|
148
|
+
return defaultValue;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function deepClone(obj) {
|
|
152
|
+
if (obj === null || typeof obj !== "object") {
|
|
153
|
+
return obj;
|
|
154
|
+
}
|
|
155
|
+
if (obj instanceof Date) {
|
|
156
|
+
return new Date(obj.getTime());
|
|
157
|
+
}
|
|
158
|
+
if (obj instanceof Array) {
|
|
159
|
+
return obj.map((item) => deepClone(item));
|
|
160
|
+
}
|
|
161
|
+
if (typeof obj === "object") {
|
|
162
|
+
const clonedObj = {};
|
|
163
|
+
for (const key in obj) {
|
|
164
|
+
if (obj.hasOwnProperty(key)) {
|
|
165
|
+
clonedObj[key] = deepClone(obj[key]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return clonedObj;
|
|
169
|
+
}
|
|
170
|
+
return obj;
|
|
171
|
+
}
|
|
172
|
+
function debounce(func, wait) {
|
|
173
|
+
let timeout = null;
|
|
174
|
+
return (...args) => {
|
|
175
|
+
if (timeout) {
|
|
176
|
+
clearTimeout(timeout);
|
|
177
|
+
}
|
|
178
|
+
timeout = setTimeout(() => {
|
|
179
|
+
func.apply(null, args);
|
|
180
|
+
}, wait);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function throttle(func, wait) {
|
|
184
|
+
let lastTime = 0;
|
|
185
|
+
return (...args) => {
|
|
186
|
+
const now = Date.now();
|
|
187
|
+
if (now - lastTime >= wait) {
|
|
188
|
+
lastTime = now;
|
|
189
|
+
func.apply(null, args);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async function retry(fn, maxAttempts = 3, delay = 1e3) {
|
|
194
|
+
let lastError;
|
|
195
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
196
|
+
try {
|
|
197
|
+
return await fn();
|
|
198
|
+
} catch (error) {
|
|
199
|
+
lastError = error;
|
|
200
|
+
if (attempt === maxAttempts) {
|
|
201
|
+
throw lastError;
|
|
202
|
+
}
|
|
203
|
+
await new Promise((resolve) => setTimeout(resolve, delay * attempt));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
throw lastError;
|
|
207
|
+
}
|
|
208
|
+
function isEmpty(obj) {
|
|
209
|
+
if (obj == null)
|
|
210
|
+
return true;
|
|
211
|
+
if (Array.isArray(obj) || typeof obj === "string")
|
|
212
|
+
return obj.length === 0;
|
|
213
|
+
if (typeof obj === "object")
|
|
214
|
+
return Object.keys(obj).length === 0;
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
function getErrorMessage(error) {
|
|
218
|
+
if (error instanceof Error) {
|
|
219
|
+
return error.message;
|
|
220
|
+
}
|
|
221
|
+
if (typeof error === "string") {
|
|
222
|
+
return error;
|
|
223
|
+
}
|
|
224
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
225
|
+
return String(error.message);
|
|
226
|
+
}
|
|
227
|
+
return "未知错误";
|
|
228
|
+
}
|
|
229
|
+
function isProduction() {
|
|
230
|
+
return process.env.NODE_ENV === "production";
|
|
231
|
+
}
|
|
232
|
+
var logger = {
|
|
233
|
+
info: (message, ...args) => {
|
|
234
|
+
console.log(`[Checkout] ${message}`, ...args);
|
|
235
|
+
},
|
|
236
|
+
warn: (message, ...args) => {
|
|
237
|
+
console.warn(`[Checkout] ${message}`, ...args);
|
|
238
|
+
},
|
|
239
|
+
error: (message, ...args) => {
|
|
240
|
+
console.error(`[Checkout] ${message}`, ...args);
|
|
241
|
+
},
|
|
242
|
+
debug: (message, ...args) => {
|
|
243
|
+
if (!isProduction()) {
|
|
244
|
+
console.debug(`[Checkout] ${message}`, ...args);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
249
|
+
0 && (module.exports = {
|
|
250
|
+
calculateProgress,
|
|
251
|
+
createCheckoutError,
|
|
252
|
+
debounce,
|
|
253
|
+
deepClone,
|
|
254
|
+
formatAmount,
|
|
255
|
+
generateOrderId,
|
|
256
|
+
getErrorMessage,
|
|
257
|
+
isEmpty,
|
|
258
|
+
isProduction,
|
|
259
|
+
isValidPaymentMethodCode,
|
|
260
|
+
logger,
|
|
261
|
+
retry,
|
|
262
|
+
safeJsonParse,
|
|
263
|
+
throttle,
|
|
264
|
+
validateAmount,
|
|
265
|
+
validateCheckoutData
|
|
266
|
+
});
|
package/lib/solution/index.d.ts
CHANGED
package/lib/solution/index.js
CHANGED
|
@@ -20,10 +20,12 @@ __reExport(solution_exports, require("./BuyTickets"), module.exports);
|
|
|
20
20
|
__reExport(solution_exports, require("./BookingByStep"), module.exports);
|
|
21
21
|
__reExport(solution_exports, require("./BookingTicket"), module.exports);
|
|
22
22
|
__reExport(solution_exports, require("./ShopDiscount"), module.exports);
|
|
23
|
+
__reExport(solution_exports, require("./Checkout"), module.exports);
|
|
23
24
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24
25
|
0 && (module.exports = {
|
|
25
26
|
...require("./BuyTickets"),
|
|
26
27
|
...require("./BookingByStep"),
|
|
27
28
|
...require("./BookingTicket"),
|
|
28
|
-
...require("./ShopDiscount")
|
|
29
|
+
...require("./ShopDiscount"),
|
|
30
|
+
...require("./Checkout")
|
|
29
31
|
});
|