@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.
Files changed (65) hide show
  1. package/dist/modules/Order/index.d.ts +13 -2
  2. package/dist/modules/Order/index.js +84 -1
  3. package/dist/modules/Order/types.d.ts +43 -0
  4. package/dist/modules/Order/types.js +8 -0
  5. package/dist/modules/Payment/cash.d.ts +8 -0
  6. package/dist/modules/Payment/cash.js +20 -1
  7. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  8. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  9. package/dist/modules/Payment/eftpos.js +1 -1
  10. package/dist/modules/Payment/index.d.ts +57 -94
  11. package/dist/modules/Payment/index.js +810 -1109
  12. package/dist/modules/Payment/mx51.d.ts +0 -0
  13. package/dist/modules/Payment/mx51.js +0 -0
  14. package/dist/modules/Payment/types.d.ts +358 -50
  15. package/dist/modules/Payment/types.js +103 -4
  16. package/dist/modules/Payment/utils.d.ts +17 -0
  17. package/dist/modules/Payment/utils.js +62 -0
  18. package/dist/modules/Payment/walletpass.d.ts +96 -0
  19. package/dist/modules/Payment/walletpass.js +492 -0
  20. package/dist/modules/Schedule/index.d.ts +9 -0
  21. package/dist/modules/Schedule/index.js +60 -0
  22. package/dist/solution/BookingTicket/index.d.ts +1 -1
  23. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  24. package/dist/solution/Checkout/index.d.ts +415 -0
  25. package/dist/solution/Checkout/index.js +3622 -0
  26. package/dist/solution/Checkout/types.d.ts +737 -0
  27. package/dist/solution/Checkout/types.js +137 -0
  28. package/dist/solution/Checkout/utils/index.d.ts +73 -0
  29. package/dist/{modules/Payment/wallet.js → solution/Checkout/utils/index.js} +363 -70
  30. package/dist/solution/index.d.ts +1 -0
  31. package/dist/solution/index.js +2 -1
  32. package/lib/modules/Order/index.d.ts +13 -2
  33. package/lib/modules/Order/index.js +58 -1
  34. package/lib/modules/Order/types.d.ts +43 -0
  35. package/lib/modules/Payment/cash.d.ts +8 -0
  36. package/lib/modules/Payment/cash.js +14 -1
  37. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  38. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  39. package/lib/modules/Payment/eftpos.js +1 -1
  40. package/lib/modules/Payment/index.d.ts +57 -94
  41. package/lib/modules/Payment/index.js +363 -525
  42. package/lib/modules/Payment/mx51.d.ts +0 -0
  43. package/lib/modules/Payment/mx51.js +0 -0
  44. package/lib/modules/Payment/types.d.ts +358 -50
  45. package/lib/modules/Payment/types.js +37 -2
  46. package/lib/modules/Payment/utils.d.ts +17 -0
  47. package/lib/modules/Payment/utils.js +67 -0
  48. package/lib/modules/Payment/walletpass.d.ts +96 -0
  49. package/lib/modules/Payment/walletpass.js +304 -0
  50. package/lib/modules/Schedule/index.d.ts +9 -0
  51. package/lib/modules/Schedule/index.js +36 -0
  52. package/lib/solution/BookingTicket/index.d.ts +1 -1
  53. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  54. package/lib/solution/Checkout/index.d.ts +415 -0
  55. package/lib/solution/Checkout/index.js +2107 -0
  56. package/lib/solution/Checkout/types.d.ts +737 -0
  57. package/lib/solution/Checkout/types.js +80 -0
  58. package/lib/solution/Checkout/utils/index.d.ts +73 -0
  59. package/lib/solution/Checkout/utils/index.js +266 -0
  60. package/lib/solution/index.d.ts +1 -0
  61. package/lib/solution/index.js +3 -1
  62. package/package.json +1 -1
  63. package/dist/modules/Payment/wallet.d.ts +0 -11
  64. package/lib/modules/Payment/wallet.d.ts +0 -11
  65. package/lib/modules/Payment/wallet.js +0 -51
@@ -0,0 +1,137 @@
1
+ /**
2
+ * 结账状态枚举
3
+ */
4
+ export var CheckoutStatus = /*#__PURE__*/function (CheckoutStatus) {
5
+ CheckoutStatus["Initializing"] = "initializing";
6
+ CheckoutStatus["Ready"] = "ready";
7
+ CheckoutStatus["CreatingOrder"] = "creating_order";
8
+ CheckoutStatus["OrderCreated"] = "order_created";
9
+ CheckoutStatus["ProcessingPayment"] = "processing_payment";
10
+ CheckoutStatus["PaymentCompleted"] = "payment_completed";
11
+ CheckoutStatus["Completed"] = "completed";
12
+ CheckoutStatus["Cancelled"] = "cancelled";
13
+ CheckoutStatus["Error"] = "error";
14
+ return CheckoutStatus;
15
+ }({});
16
+
17
+ /**
18
+ * 结账步骤枚举
19
+ */
20
+ export var CheckoutStep = /*#__PURE__*/function (CheckoutStep) {
21
+ CheckoutStep["OrderConfirmation"] = "order_confirmation";
22
+ CheckoutStep["PaymentMethod"] = "payment_method";
23
+ CheckoutStep["PaymentProcessing"] = "payment_processing";
24
+ CheckoutStep["Complete"] = "complete";
25
+ return CheckoutStep;
26
+ }({});
27
+
28
+ /**
29
+ * 结账错误类型
30
+ */
31
+ export var CheckoutErrorType = /*#__PURE__*/function (CheckoutErrorType) {
32
+ CheckoutErrorType["OrderCreationFailed"] = "order_creation_failed";
33
+ CheckoutErrorType["PaymentFailed"] = "payment_failed";
34
+ CheckoutErrorType["ValidationFailed"] = "validation_failed";
35
+ CheckoutErrorType["NetworkError"] = "network_error";
36
+ CheckoutErrorType["UnknownError"] = "unknown_error";
37
+ return CheckoutErrorType;
38
+ }({});
39
+
40
+ /**
41
+ * 结账错误信息
42
+ */
43
+
44
+ /**
45
+ * 结账初始化参数
46
+ */
47
+
48
+ /**
49
+ * 购物车小计项
50
+ */
51
+
52
+ /**
53
+ * 从购物车小计提取的金额信息
54
+ */
55
+
56
+ /**
57
+ * 本地订单创建参数
58
+ */
59
+
60
+ /**
61
+ * 手动下单参数
62
+ */
63
+
64
+ /**
65
+ * 本地订单数据结构 (基于 appointmentDemo.json)
66
+ */
67
+
68
+ /**
69
+ * 本地预订项
70
+ */
71
+
72
+ /**
73
+ * 本地商品信息
74
+ */
75
+
76
+ /**
77
+ * 本地折扣项
78
+ */
79
+
80
+ /**
81
+ * 本地资源项
82
+ */
83
+
84
+ /**
85
+ * 订单创建参数
86
+ */
87
+
88
+ /**
89
+ * 支付处理参数
90
+ */
91
+
92
+ /**
93
+ * 结账状态信息
94
+ */
95
+
96
+ /**
97
+ * 结账摘要信息
98
+ */
99
+
100
+ /**
101
+ * 结账事件钩子
102
+ */
103
+ export var CheckoutHooks = /*#__PURE__*/function (CheckoutHooks) {
104
+ CheckoutHooks["OnCheckoutInitialized"] = "checkout:onInitialized";
105
+ CheckoutHooks["OnStatusChanged"] = "checkout:onStatusChanged";
106
+ CheckoutHooks["OnStepChanged"] = "checkout:onStepChanged";
107
+ CheckoutHooks["OnOrderCreated"] = "checkout:onOrderCreated";
108
+ CheckoutHooks["OnOrderCreationFailed"] = "checkout:onOrderCreationFailed";
109
+ CheckoutHooks["OnPaymentStarted"] = "checkout:onPaymentStarted";
110
+ CheckoutHooks["OnPaymentSuccess"] = "checkout:onPaymentSuccess";
111
+ CheckoutHooks["OnPaymentFailed"] = "checkout:onPaymentFailed";
112
+ CheckoutHooks["OnCheckoutCompleted"] = "checkout:onCompleted";
113
+ CheckoutHooks["OnCheckoutCancelled"] = "checkout:onCancelled";
114
+ CheckoutHooks["OnError"] = "checkout:onError";
115
+ CheckoutHooks["OnStateAmountChanged"] = "checkout:onStateAmountChanged";
116
+ CheckoutHooks["OnOrderPaymentCompleted"] = "checkout:onOrderPaymentCompleted";
117
+ CheckoutHooks["OnOrderSynced"] = "checkout:onOrderSynced";
118
+ CheckoutHooks["OnOrderNoteChanged"] = "checkout:onOrderNoteChanged";
119
+ CheckoutHooks["OnShopDiscountChanged"] = "checkout:onShopDiscountChanged";
120
+ return CheckoutHooks;
121
+ }({});
122
+
123
+ /**
124
+ * 结账状态数据
125
+ */
126
+
127
+ /**
128
+ * 当前订单基础信息
129
+ */
130
+
131
+ /**
132
+ * 结账解决方案 API 接口
133
+ */
134
+
135
+ /**
136
+ * 结账事件数据类型
137
+ */
@@ -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
+ };
@@ -1,78 +1,371 @@
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
1
  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; }
3
2
  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); } }
4
3
  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); }); }; }
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
- 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); } }
7
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
- 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); }
10
- /**
11
- * 钱包支付实现
12
- */
13
- export var WalletPaymentImpl = /*#__PURE__*/function () {
14
- function WalletPaymentImpl(paymentModule) {
15
- _classCallCheck(this, WalletPaymentImpl);
16
- this.paymentModule = paymentModule;
4
+ 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); }
5
+ import { CheckoutStatus, CheckoutStep } from "../types";
6
+
7
+ /**
8
+ * 验证结账数据
9
+ */
10
+ export function validateCheckoutData(params) {
11
+ var errors = [];
12
+
13
+ // 验证购物车商品
14
+ if (!params.cartItems || params.cartItems.length === 0) {
15
+ errors.push('购物车不能为空');
16
+ }
17
+
18
+ // 验证购物车商品数据完整性
19
+ if (params.cartItems) {
20
+ params.cartItems.forEach(function (item, index) {
21
+ if (!item.id) {
22
+ errors.push("\u8D2D\u7269\u8F66\u5546\u54C1 ".concat(index + 1, " \u7F3A\u5C11\u5546\u54C1ID"));
23
+ }
24
+ if (!item.price || parseFloat(String(item.price)) < 0) {
25
+ errors.push("\u8D2D\u7269\u8F66\u5546\u54C1 ".concat(index + 1, " \u4EF7\u683C\u65E0\u6548"));
26
+ }
27
+ if (!item.num || item.num <= 0) {
28
+ errors.push("\u8D2D\u7269\u8F66\u5546\u54C1 ".concat(index + 1, " \u6570\u91CF\u65E0\u6548"));
29
+ }
30
+ });
31
+ }
32
+
33
+ // 验证订单类型
34
+ if (params.orderType && !['virtual', 'appointment_booking'].includes(params.orderType)) {
35
+ errors.push('订单类型无效,必须是 virtual 或 appointment_booking');
36
+ }
37
+
38
+ // 验证平台类型
39
+ if (params.platform && !['pc', 'h5'].includes(params.platform)) {
40
+ errors.push('平台类型无效,必须是 pc 或 h5');
41
+ }
42
+ return {
43
+ valid: errors.length === 0,
44
+ errors: errors
45
+ };
46
+ }
47
+
48
+ /**
49
+ * 创建结账错误对象
50
+ */
51
+ export function createCheckoutError(type, message, details) {
52
+ return {
53
+ type: type,
54
+ message: message,
55
+ details: details,
56
+ timestamp: Date.now()
57
+ };
58
+ }
59
+
60
+ /**
61
+ * 计算结账进度
62
+ */
63
+ export function calculateProgress(status, step) {
64
+ // 基于状态的基础进度
65
+ var baseProgress = 0;
66
+ switch (status) {
67
+ case CheckoutStatus.Initializing:
68
+ baseProgress = 5;
69
+ break;
70
+ case CheckoutStatus.Ready:
71
+ baseProgress = 10;
72
+ break;
73
+ case CheckoutStatus.CreatingOrder:
74
+ baseProgress = 25;
75
+ break;
76
+ case CheckoutStatus.OrderCreated:
77
+ baseProgress = 40;
78
+ break;
79
+ case CheckoutStatus.ProcessingPayment:
80
+ baseProgress = 65;
81
+ break;
82
+ case CheckoutStatus.PaymentCompleted:
83
+ baseProgress = 85;
84
+ break;
85
+ case CheckoutStatus.Completed:
86
+ baseProgress = 100;
87
+ break;
88
+ case CheckoutStatus.Cancelled:
89
+ case CheckoutStatus.Error:
90
+ baseProgress = 0;
91
+ break;
92
+ default:
93
+ baseProgress = 0;
94
+ }
95
+
96
+ // 基于步骤的额外进度
97
+ var stepProgress = 0;
98
+ switch (step) {
99
+ case CheckoutStep.OrderConfirmation:
100
+ stepProgress = 0;
101
+ break;
102
+ case CheckoutStep.PaymentMethod:
103
+ stepProgress = 10;
104
+ break;
105
+ case CheckoutStep.PaymentProcessing:
106
+ stepProgress = 15;
107
+ break;
108
+ case CheckoutStep.Complete:
109
+ stepProgress = 0; // 已经在状态中体现
110
+ break;
111
+ }
112
+ return Math.min(100, baseProgress + stepProgress);
113
+ }
114
+
115
+ /**
116
+ * 格式化金额
117
+ */
118
+ export function formatAmount(amount) {
119
+ var numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
120
+ if (isNaN(numAmount)) return '0.00';
121
+ return numAmount.toFixed(2);
122
+ }
123
+
124
+ /**
125
+ * 验证金额
126
+ */
127
+ export function validateAmount(amount) {
128
+ var numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
129
+ return !isNaN(numAmount) && numAmount >= 0;
130
+ }
131
+
132
+ /**
133
+ * 生成唯一订单ID
134
+ */
135
+ export function generateOrderId() {
136
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'order';
137
+ var timestamp = Date.now();
138
+ var random = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
139
+ return "".concat(prefix, "_").concat(timestamp, "_").concat(random);
140
+ }
141
+
142
+ /**
143
+ * 检查是否为有效的支付方式代码
144
+ */
145
+ export function isValidPaymentMethodCode(code) {
146
+ // 基本的支付方式代码验证
147
+ return typeof code === 'string' && code.length > 0 && /^[a-zA-Z0-9_-]+$/.test(code);
148
+ }
149
+
150
+ /**
151
+ * 安全地解析JSON
152
+ */
153
+ export function safeJsonParse(jsonString, defaultValue) {
154
+ try {
155
+ return JSON.parse(jsonString);
156
+ } catch (_unused) {
157
+ return defaultValue;
17
158
  }
18
- _createClass(WalletPaymentImpl, [{
19
- key: "processWalletPayment",
20
- value: function () {
21
- var _processWalletPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(amount, orderUuid, voucherId) {
22
- var walletMethod, paymentItem;
23
- return _regeneratorRuntime().wrap(function _callee$(_context) {
24
- while (1) switch (_context.prev = _context.next) {
25
- case 0:
26
- _context.next = 2;
27
- return this.paymentModule.getWalletPaymentMethod();
28
- case 2:
29
- walletMethod = _context.sent;
30
- if (walletMethod) {
31
- _context.next = 5;
32
- break;
159
+ }
160
+
161
+ /**
162
+ * 深度克隆对象
163
+ */
164
+ export function deepClone(obj) {
165
+ if (obj === null || _typeof(obj) !== 'object') {
166
+ return obj;
167
+ }
168
+ if (obj instanceof Date) {
169
+ return new Date(obj.getTime());
170
+ }
171
+ if (obj instanceof Array) {
172
+ return obj.map(function (item) {
173
+ return deepClone(item);
174
+ });
175
+ }
176
+ if (_typeof(obj) === 'object') {
177
+ var clonedObj = {};
178
+ for (var key in obj) {
179
+ if (obj.hasOwnProperty(key)) {
180
+ clonedObj[key] = deepClone(obj[key]);
181
+ }
182
+ }
183
+ return clonedObj;
184
+ }
185
+ return obj;
186
+ }
187
+
188
+ /**
189
+ * 防抖函数
190
+ */
191
+ export function debounce(func, wait) {
192
+ var timeout = null;
193
+ return function () {
194
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
195
+ args[_key] = arguments[_key];
196
+ }
197
+ if (timeout) {
198
+ clearTimeout(timeout);
199
+ }
200
+ timeout = setTimeout(function () {
201
+ func.apply(null, args);
202
+ }, wait);
203
+ };
204
+ }
205
+
206
+ /**
207
+ * 节流函数
208
+ */
209
+ export function throttle(func, wait) {
210
+ var lastTime = 0;
211
+ return function () {
212
+ var now = Date.now();
213
+ if (now - lastTime >= wait) {
214
+ lastTime = now;
215
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
216
+ args[_key2] = arguments[_key2];
217
+ }
218
+ func.apply(null, args);
219
+ }
220
+ };
221
+ }
222
+
223
+ /**
224
+ * 重试函数
225
+ */
226
+ export function retry(_x) {
227
+ return _retry.apply(this, arguments);
228
+ }
229
+
230
+ /**
231
+ * 检查对象是否为空
232
+ */
233
+ function _retry() {
234
+ _retry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(fn) {
235
+ var maxAttempts,
236
+ delay,
237
+ lastError,
238
+ _loop,
239
+ _ret,
240
+ attempt,
241
+ _args2 = arguments;
242
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
243
+ while (1) switch (_context2.prev = _context2.next) {
244
+ case 0:
245
+ maxAttempts = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 3;
246
+ delay = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 1000;
247
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop(attempt) {
248
+ return _regeneratorRuntime().wrap(function _loop$(_context) {
249
+ while (1) switch (_context.prev = _context.next) {
250
+ case 0:
251
+ _context.prev = 0;
252
+ _context.next = 3;
253
+ return fn();
254
+ case 3:
255
+ _context.t0 = _context.sent;
256
+ return _context.abrupt("return", {
257
+ v: _context.t0
258
+ });
259
+ case 7:
260
+ _context.prev = 7;
261
+ _context.t1 = _context["catch"](0);
262
+ lastError = _context.t1;
263
+ if (!(attempt === maxAttempts)) {
264
+ _context.next = 12;
265
+ break;
266
+ }
267
+ throw lastError;
268
+ case 12:
269
+ _context.next = 14;
270
+ return new Promise(function (resolve) {
271
+ return setTimeout(resolve, delay * attempt);
272
+ });
273
+ case 14:
274
+ case "end":
275
+ return _context.stop();
33
276
  }
34
- throw new Error('钱包支付方式未找到');
35
- case 5:
36
- paymentItem = {
37
- amount: amount.toString(),
38
- code: walletMethod.code,
39
- id: walletMethod.id,
40
- name: walletMethod.name,
41
- type: walletMethod.type,
42
- voucher_id: voucherId || ''
43
- };
44
- _context.next = 8;
45
- return this.paymentModule.pushPaymentAsync(orderUuid, paymentItem);
46
- case 8:
47
- case "end":
48
- return _context.stop();
277
+ }, _loop, null, [[0, 7]]);
278
+ });
279
+ attempt = 1;
280
+ case 4:
281
+ if (!(attempt <= maxAttempts)) {
282
+ _context2.next = 12;
283
+ break;
49
284
  }
50
- }, _callee, this);
51
- }));
52
- function processWalletPayment(_x, _x2, _x3) {
53
- return _processWalletPayment.apply(this, arguments);
54
- }
55
- return processWalletPayment;
56
- }()
57
- }, {
58
- key: "getWalletBalance",
59
- value: function () {
60
- var _getWalletBalance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(voucherId) {
61
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
62
- while (1) switch (_context2.prev = _context2.next) {
63
- case 0:
64
- return _context2.abrupt("return", 0);
65
- case 1:
66
- case "end":
67
- return _context2.stop();
285
+ return _context2.delegateYield(_loop(attempt), "t0", 6);
286
+ case 6:
287
+ _ret = _context2.t0;
288
+ if (!_ret) {
289
+ _context2.next = 9;
290
+ break;
68
291
  }
69
- }, _callee2);
70
- }));
71
- function getWalletBalance(_x4) {
72
- return _getWalletBalance.apply(this, arguments);
292
+ return _context2.abrupt("return", _ret.v);
293
+ case 9:
294
+ attempt++;
295
+ _context2.next = 4;
296
+ break;
297
+ case 12:
298
+ throw lastError;
299
+ case 13:
300
+ case "end":
301
+ return _context2.stop();
73
302
  }
74
- return getWalletBalance;
75
- }()
76
- }]);
77
- return WalletPaymentImpl;
78
- }();
303
+ }, _callee);
304
+ }));
305
+ return _retry.apply(this, arguments);
306
+ }
307
+ export function isEmpty(obj) {
308
+ if (obj == null) return true;
309
+ if (Array.isArray(obj) || typeof obj === 'string') return obj.length === 0;
310
+ if (_typeof(obj) === 'object') return Object.keys(obj).length === 0;
311
+ return false;
312
+ }
313
+
314
+ /**
315
+ * 获取错误消息
316
+ */
317
+ export function getErrorMessage(error) {
318
+ if (error instanceof Error) {
319
+ return error.message;
320
+ }
321
+ if (typeof error === 'string') {
322
+ return error;
323
+ }
324
+ if (error && _typeof(error) === 'object' && 'message' in error) {
325
+ return String(error.message);
326
+ }
327
+ return '未知错误';
328
+ }
329
+
330
+ /**
331
+ * 检查是否为生产环境
332
+ */
333
+ export function isProduction() {
334
+ return process.env.NODE_ENV === 'production';
335
+ }
336
+
337
+ /**
338
+ * 日志记录器
339
+ */
340
+ export var logger = {
341
+ info: function info(message) {
342
+ var _console;
343
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
344
+ args[_key3 - 1] = arguments[_key3];
345
+ }
346
+ (_console = console).log.apply(_console, ["[Checkout] ".concat(message)].concat(args));
347
+ },
348
+ warn: function warn(message) {
349
+ var _console2;
350
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
351
+ args[_key4 - 1] = arguments[_key4];
352
+ }
353
+ (_console2 = console).warn.apply(_console2, ["[Checkout] ".concat(message)].concat(args));
354
+ },
355
+ error: function error(message) {
356
+ var _console3;
357
+ for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
358
+ args[_key5 - 1] = arguments[_key5];
359
+ }
360
+ (_console3 = console).error.apply(_console3, ["[Checkout] ".concat(message)].concat(args));
361
+ },
362
+ debug: function debug(message) {
363
+ if (!isProduction()) {
364
+ var _console4;
365
+ for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
366
+ args[_key6 - 1] = arguments[_key6];
367
+ }
368
+ (_console4 = console).debug.apply(_console4, ["[Checkout] ".concat(message)].concat(args));
369
+ }
370
+ }
371
+ };
@@ -2,3 +2,4 @@ export * from './BuyTickets';
2
2
  export * from './BookingByStep';
3
3
  export * from './BookingTicket';
4
4
  export * from './ShopDiscount';
5
+ export * from './Checkout';
@@ -1,4 +1,5 @@
1
1
  export * from "./BuyTickets";
2
2
  export * from "./BookingByStep";
3
3
  export * from "./BookingTicket";
4
- export * from "./ShopDiscount";
4
+ export * from "./ShopDiscount";
5
+ export * from "./Checkout";