@pisell/pisellos 0.0.229 → 0.0.231
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/Order/index.d.ts +13 -2
- package/dist/modules/Order/index.js +84 -1
- package/dist/modules/Order/types.d.ts +43 -0
- package/dist/modules/Order/types.js +8 -0
- package/dist/modules/Payment/cash.d.ts +8 -0
- package/dist/modules/Payment/cash.js +20 -1
- package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
- package/dist/modules/Payment/eftpos.js +1 -1
- package/dist/modules/Payment/index.d.ts +57 -94
- package/dist/modules/Payment/index.js +810 -1109
- package/dist/modules/Payment/mx51.d.ts +0 -0
- package/dist/modules/Payment/mx51.js +0 -0
- package/dist/modules/Payment/types.d.ts +358 -50
- package/dist/modules/Payment/types.js +103 -4
- package/dist/modules/Payment/utils.d.ts +17 -0
- package/dist/modules/Payment/utils.js +62 -0
- package/dist/modules/Payment/walletpass.d.ts +96 -0
- package/dist/modules/Payment/walletpass.js +492 -0
- package/dist/modules/Schedule/index.d.ts +9 -0
- package/dist/modules/Schedule/index.js +60 -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 +415 -0
- package/dist/solution/Checkout/index.js +3622 -0
- package/dist/solution/Checkout/types.d.ts +737 -0
- package/dist/solution/Checkout/types.js +137 -0
- package/dist/solution/Checkout/utils/index.d.ts +73 -0
- package/dist/{modules/Payment/wallet.js → solution/Checkout/utils/index.js} +363 -70
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/modules/Order/index.d.ts +13 -2
- package/lib/modules/Order/index.js +58 -1
- package/lib/modules/Order/types.d.ts +43 -0
- package/lib/modules/Payment/cash.d.ts +8 -0
- package/lib/modules/Payment/cash.js +14 -1
- package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.d.ts +57 -94
- package/lib/modules/Payment/index.js +363 -525
- package/lib/modules/Payment/mx51.d.ts +0 -0
- package/lib/modules/Payment/mx51.js +0 -0
- package/lib/modules/Payment/types.d.ts +358 -50
- package/lib/modules/Payment/types.js +37 -2
- package/lib/modules/Payment/utils.d.ts +17 -0
- package/lib/modules/Payment/utils.js +67 -0
- package/lib/modules/Payment/walletpass.d.ts +96 -0
- package/lib/modules/Payment/walletpass.js +304 -0
- package/lib/modules/Schedule/index.d.ts +9 -0
- package/lib/modules/Schedule/index.js +36 -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 +415 -0
- package/lib/solution/Checkout/index.js +2107 -0
- package/lib/solution/Checkout/types.d.ts +737 -0
- package/lib/solution/Checkout/types.js +80 -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
- package/dist/modules/Payment/wallet.d.ts +0 -11
- package/lib/modules/Payment/wallet.d.ts +0 -11
- package/lib/modules/Payment/wallet.js +0 -51
|
@@ -0,0 +1,80 @@
|
|
|
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/types.ts
|
|
20
|
+
var types_exports = {};
|
|
21
|
+
__export(types_exports, {
|
|
22
|
+
CheckoutErrorType: () => CheckoutErrorType,
|
|
23
|
+
CheckoutHooks: () => CheckoutHooks,
|
|
24
|
+
CheckoutStatus: () => CheckoutStatus,
|
|
25
|
+
CheckoutStep: () => CheckoutStep
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(types_exports);
|
|
28
|
+
var CheckoutStatus = /* @__PURE__ */ ((CheckoutStatus2) => {
|
|
29
|
+
CheckoutStatus2["Initializing"] = "initializing";
|
|
30
|
+
CheckoutStatus2["Ready"] = "ready";
|
|
31
|
+
CheckoutStatus2["CreatingOrder"] = "creating_order";
|
|
32
|
+
CheckoutStatus2["OrderCreated"] = "order_created";
|
|
33
|
+
CheckoutStatus2["ProcessingPayment"] = "processing_payment";
|
|
34
|
+
CheckoutStatus2["PaymentCompleted"] = "payment_completed";
|
|
35
|
+
CheckoutStatus2["Completed"] = "completed";
|
|
36
|
+
CheckoutStatus2["Cancelled"] = "cancelled";
|
|
37
|
+
CheckoutStatus2["Error"] = "error";
|
|
38
|
+
return CheckoutStatus2;
|
|
39
|
+
})(CheckoutStatus || {});
|
|
40
|
+
var CheckoutStep = /* @__PURE__ */ ((CheckoutStep2) => {
|
|
41
|
+
CheckoutStep2["OrderConfirmation"] = "order_confirmation";
|
|
42
|
+
CheckoutStep2["PaymentMethod"] = "payment_method";
|
|
43
|
+
CheckoutStep2["PaymentProcessing"] = "payment_processing";
|
|
44
|
+
CheckoutStep2["Complete"] = "complete";
|
|
45
|
+
return CheckoutStep2;
|
|
46
|
+
})(CheckoutStep || {});
|
|
47
|
+
var CheckoutErrorType = /* @__PURE__ */ ((CheckoutErrorType2) => {
|
|
48
|
+
CheckoutErrorType2["OrderCreationFailed"] = "order_creation_failed";
|
|
49
|
+
CheckoutErrorType2["PaymentFailed"] = "payment_failed";
|
|
50
|
+
CheckoutErrorType2["ValidationFailed"] = "validation_failed";
|
|
51
|
+
CheckoutErrorType2["NetworkError"] = "network_error";
|
|
52
|
+
CheckoutErrorType2["UnknownError"] = "unknown_error";
|
|
53
|
+
return CheckoutErrorType2;
|
|
54
|
+
})(CheckoutErrorType || {});
|
|
55
|
+
var CheckoutHooks = /* @__PURE__ */ ((CheckoutHooks2) => {
|
|
56
|
+
CheckoutHooks2["OnCheckoutInitialized"] = "checkout:onInitialized";
|
|
57
|
+
CheckoutHooks2["OnStatusChanged"] = "checkout:onStatusChanged";
|
|
58
|
+
CheckoutHooks2["OnStepChanged"] = "checkout:onStepChanged";
|
|
59
|
+
CheckoutHooks2["OnOrderCreated"] = "checkout:onOrderCreated";
|
|
60
|
+
CheckoutHooks2["OnOrderCreationFailed"] = "checkout:onOrderCreationFailed";
|
|
61
|
+
CheckoutHooks2["OnPaymentStarted"] = "checkout:onPaymentStarted";
|
|
62
|
+
CheckoutHooks2["OnPaymentSuccess"] = "checkout:onPaymentSuccess";
|
|
63
|
+
CheckoutHooks2["OnPaymentFailed"] = "checkout:onPaymentFailed";
|
|
64
|
+
CheckoutHooks2["OnCheckoutCompleted"] = "checkout:onCompleted";
|
|
65
|
+
CheckoutHooks2["OnCheckoutCancelled"] = "checkout:onCancelled";
|
|
66
|
+
CheckoutHooks2["OnError"] = "checkout:onError";
|
|
67
|
+
CheckoutHooks2["OnStateAmountChanged"] = "checkout:onStateAmountChanged";
|
|
68
|
+
CheckoutHooks2["OnOrderPaymentCompleted"] = "checkout:onOrderPaymentCompleted";
|
|
69
|
+
CheckoutHooks2["OnOrderSynced"] = "checkout:onOrderSynced";
|
|
70
|
+
CheckoutHooks2["OnOrderNoteChanged"] = "checkout:onOrderNoteChanged";
|
|
71
|
+
CheckoutHooks2["OnShopDiscountChanged"] = "checkout:onShopDiscountChanged";
|
|
72
|
+
return CheckoutHooks2;
|
|
73
|
+
})(CheckoutHooks || {});
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
CheckoutErrorType,
|
|
77
|
+
CheckoutHooks,
|
|
78
|
+
CheckoutStatus,
|
|
79
|
+
CheckoutStep
|
|
80
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CheckoutInitParams, CheckoutError, CheckoutErrorType, CheckoutStatus, CheckoutStep } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 验证结账数据
|
|
4
|
+
*/
|
|
5
|
+
export declare function validateCheckoutData(params: CheckoutInitParams): {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
errors: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 创建结账错误对象
|
|
11
|
+
*/
|
|
12
|
+
export declare function createCheckoutError(type: CheckoutErrorType, message: string, details?: any): CheckoutError;
|
|
13
|
+
/**
|
|
14
|
+
* 计算结账进度
|
|
15
|
+
*/
|
|
16
|
+
export declare function calculateProgress(status: CheckoutStatus, step: CheckoutStep): number;
|
|
17
|
+
/**
|
|
18
|
+
* 格式化金额
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatAmount(amount: string | number): string;
|
|
21
|
+
/**
|
|
22
|
+
* 验证金额
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateAmount(amount: string | number): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 生成唯一订单ID
|
|
27
|
+
*/
|
|
28
|
+
export declare function generateOrderId(prefix?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* 检查是否为有效的支付方式代码
|
|
31
|
+
*/
|
|
32
|
+
export declare function isValidPaymentMethodCode(code: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 安全地解析JSON
|
|
35
|
+
*/
|
|
36
|
+
export declare function safeJsonParse<T>(jsonString: string, defaultValue: T): T;
|
|
37
|
+
/**
|
|
38
|
+
* 深度克隆对象
|
|
39
|
+
*/
|
|
40
|
+
export declare function deepClone<T>(obj: T): T;
|
|
41
|
+
/**
|
|
42
|
+
* 防抖函数
|
|
43
|
+
*/
|
|
44
|
+
export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void;
|
|
45
|
+
/**
|
|
46
|
+
* 节流函数
|
|
47
|
+
*/
|
|
48
|
+
export declare function throttle<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void;
|
|
49
|
+
/**
|
|
50
|
+
* 重试函数
|
|
51
|
+
*/
|
|
52
|
+
export declare function retry<T>(fn: () => Promise<T>, maxAttempts?: number, delay?: number): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* 检查对象是否为空
|
|
55
|
+
*/
|
|
56
|
+
export declare function isEmpty(obj: any): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 获取错误消息
|
|
59
|
+
*/
|
|
60
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
61
|
+
/**
|
|
62
|
+
* 检查是否为生产环境
|
|
63
|
+
*/
|
|
64
|
+
export declare function isProduction(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* 日志记录器
|
|
67
|
+
*/
|
|
68
|
+
export declare const logger: {
|
|
69
|
+
info: (message: string, ...args: any[]) => void;
|
|
70
|
+
warn: (message: string, ...args: any[]) => void;
|
|
71
|
+
error: (message: string, ...args: any[]) => void;
|
|
72
|
+
debug: (message: string, ...args: any[]) => void;
|
|
73
|
+
};
|
|
@@ -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
|
});
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { WalletPayment } from './types';
|
|
2
|
-
import type { PaymentModule } from './index';
|
|
3
|
-
/**
|
|
4
|
-
* 钱包支付实现
|
|
5
|
-
*/
|
|
6
|
-
export declare class WalletPaymentImpl implements WalletPayment {
|
|
7
|
-
private paymentModule;
|
|
8
|
-
constructor(paymentModule: PaymentModule);
|
|
9
|
-
processWalletPayment(amount: number, orderUuid: string, voucherId?: string): Promise<void>;
|
|
10
|
-
getWalletBalance(voucherId: string): Promise<number>;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { WalletPayment } from './types';
|
|
2
|
-
import type { PaymentModule } from './index';
|
|
3
|
-
/**
|
|
4
|
-
* 钱包支付实现
|
|
5
|
-
*/
|
|
6
|
-
export declare class WalletPaymentImpl implements WalletPayment {
|
|
7
|
-
private paymentModule;
|
|
8
|
-
constructor(paymentModule: PaymentModule);
|
|
9
|
-
processWalletPayment(amount: number, orderUuid: string, voucherId?: string): Promise<void>;
|
|
10
|
-
getWalletBalance(voucherId: string): Promise<number>;
|
|
11
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
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/modules/Payment/wallet.ts
|
|
20
|
-
var wallet_exports = {};
|
|
21
|
-
__export(wallet_exports, {
|
|
22
|
-
WalletPaymentImpl: () => WalletPaymentImpl
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(wallet_exports);
|
|
25
|
-
var WalletPaymentImpl = class {
|
|
26
|
-
constructor(paymentModule) {
|
|
27
|
-
this.paymentModule = paymentModule;
|
|
28
|
-
}
|
|
29
|
-
async processWalletPayment(amount, orderUuid, voucherId) {
|
|
30
|
-
const walletMethod = await this.paymentModule.getWalletPaymentMethod();
|
|
31
|
-
if (!walletMethod) {
|
|
32
|
-
throw new Error("钱包支付方式未找到");
|
|
33
|
-
}
|
|
34
|
-
const paymentItem = {
|
|
35
|
-
amount: amount.toString(),
|
|
36
|
-
code: walletMethod.code,
|
|
37
|
-
id: walletMethod.id,
|
|
38
|
-
name: walletMethod.name,
|
|
39
|
-
type: walletMethod.type,
|
|
40
|
-
voucher_id: voucherId || ""
|
|
41
|
-
};
|
|
42
|
-
await this.paymentModule.pushPaymentAsync(orderUuid, paymentItem);
|
|
43
|
-
}
|
|
44
|
-
async getWalletBalance(voucherId) {
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
-
0 && (module.exports = {
|
|
50
|
-
WalletPaymentImpl
|
|
51
|
-
});
|