@pisell/pisellos 0.0.243 → 0.0.245

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.
@@ -384,10 +384,14 @@ export declare enum CheckoutHooks {
384
384
  OnError = "checkout:onError",
385
385
  /** 自定义支付金额变更 */
386
386
  OnStateAmountChanged = "checkout:onStateAmountChanged",
387
+ /** 系统计算的待付金额变更 */
388
+ OnBalanceDueAmountChanged = "checkout:onBalanceDueAmountChanged",
387
389
  /** 订单支付完成(待付款金额 ≤ 0) */
388
390
  OnOrderPaymentCompleted = "checkout:onOrderPaymentCompleted",
389
391
  /** 订单同步到后端完成 */
390
392
  OnOrderSynced = "checkout:onOrderSynced",
393
+ /** 订单同步到后端失败 */
394
+ OnOrderSyncFailed = "checkout:onOrderSyncFailed",
391
395
  /** 订单备注变更 */
392
396
  OnOrderNoteChanged = "checkout:onOrderNoteChanged",
393
397
  /** 商店折扣变更 */
@@ -423,6 +427,8 @@ export interface CheckoutState {
423
427
  lastError?: CheckoutError;
424
428
  /** UI 自定义支付金额 */
425
429
  stateAmount: string;
430
+ /** 系统计算的待付金额(只读,由系统内部计算) */
431
+ balanceDueAmount: string;
426
432
  /** 订单是否已同步到后端 */
427
433
  isOrderSynced: boolean;
428
434
  /** 当前客户信息 */
@@ -562,6 +568,12 @@ export interface CheckoutModuleAPI extends Module {
562
568
  * 获取当前自定义支付金额
563
569
  */
564
570
  getStateAmount(): string;
571
+ /**
572
+ * 获取系统计算的待付金额(只读)
573
+ *
574
+ * @returns 当前系统计算的待付金额
575
+ */
576
+ getBalanceDueAmount(): string;
565
577
  /**
566
578
  * 刷新 stateAmount 为当前剩余未支付金额
567
579
  */
@@ -782,6 +794,12 @@ export interface CheckoutEventData {
782
794
  newAmount: string;
783
795
  timestamp: number;
784
796
  };
797
+ /** 系统计算的待付金额变更事件 */
798
+ balanceDueAmountChanged: {
799
+ oldAmount: string;
800
+ newAmount: string;
801
+ timestamp: number;
802
+ };
785
803
  /** 订单支付完成事件 */
786
804
  orderPaymentCompleted: {
787
805
  orderUuid: string;
@@ -799,6 +817,25 @@ export interface CheckoutEventData {
799
817
  timestamp: number;
800
818
  /** 是否为手动同步 */
801
819
  isManual?: boolean;
820
+ /** 后端响应数据 */
821
+ response?: any;
822
+ };
823
+ /** 订单同步到后端失败事件 */
824
+ orderSyncFailed: {
825
+ orderUuid: string;
826
+ /** 操作类型 */
827
+ operation: 'create' | 'update';
828
+ /** 是否为手动同步 */
829
+ isManual: boolean;
830
+ /** 错误信息 */
831
+ error: string;
832
+ /** 错误类型 */
833
+ errorType: 'network_error' | 'api_error' | 'response_invalid' | 'unknown';
834
+ /** 后端响应数据(如果有) */
835
+ response?: any;
836
+ /** 耗时(毫秒) */
837
+ duration?: number;
838
+ timestamp: number;
802
839
  };
803
840
  /** 订单备注变更事件 */
804
841
  orderNoteChanged: {
@@ -113,8 +113,10 @@ export var CheckoutHooks = /*#__PURE__*/function (CheckoutHooks) {
113
113
  CheckoutHooks["OnCheckoutCancelled"] = "checkout:onCancelled";
114
114
  CheckoutHooks["OnError"] = "checkout:onError";
115
115
  CheckoutHooks["OnStateAmountChanged"] = "checkout:onStateAmountChanged";
116
+ CheckoutHooks["OnBalanceDueAmountChanged"] = "checkout:onBalanceDueAmountChanged";
116
117
  CheckoutHooks["OnOrderPaymentCompleted"] = "checkout:onOrderPaymentCompleted";
117
118
  CheckoutHooks["OnOrderSynced"] = "checkout:onOrderSynced";
119
+ CheckoutHooks["OnOrderSyncFailed"] = "checkout:onOrderSyncFailed";
118
120
  CheckoutHooks["OnOrderNoteChanged"] = "checkout:onOrderNoteChanged";
119
121
  CheckoutHooks["OnShopDiscountChanged"] = "checkout:onShopDiscountChanged";
120
122
  CheckoutHooks["OnOrderCancelled"] = "checkout:onOrderCancelled";
@@ -160,6 +160,14 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
160
160
  * @returns 当前设置的自定义支付金额
161
161
  */
162
162
  getStateAmount(): string;
163
+ /**
164
+ * 获取系统计算的待付金额(只读)
165
+ *
166
+ * 此方法返回系统内部计算的实际待付金额,不允许外部修改
167
+ *
168
+ * @returns 当前系统计算的待付金额
169
+ */
170
+ getBalanceDueAmount(): string;
163
171
  /**
164
172
  * 刷新 stateAmount 为当前剩余未支付金额
165
173
  *
@@ -391,6 +399,10 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
391
399
  * 计算剩余未支付金额(从 Payment 模块获取最新数据)
392
400
  */
393
401
  private calculateRemainingAmountAsync;
402
+ /**
403
+ * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
404
+ */
405
+ private updateBalanceDueAmount;
394
406
  /**
395
407
  * 更新 stateAmount 为当前剩余未支付金额
396
408
  */
@@ -53,6 +53,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
53
53
  cartItems: [],
54
54
  paymentMethods: [],
55
55
  stateAmount: "0.00",
56
+ balanceDueAmount: "0.00",
56
57
  cartSummary: void 0,
57
58
  isOrderSynced: false,
58
59
  currentCustomer: void 0
@@ -120,7 +121,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
120
121
  async initializeCheckoutAsync(params) {
121
122
  try {
122
123
  await this.setStatus(import_types.CheckoutStatus.Initializing);
123
- const validation = await this.validateCheckoutParams(params);
124
+ const validation = this.validateCheckoutParams(params);
124
125
  if (!validation.valid) {
125
126
  throw (0, import_utils.createCheckoutError)(
126
127
  import_types.CheckoutErrorType.ValidationFailed,
@@ -193,7 +194,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
193
194
  try {
194
195
  await this.resetStoreStateAsync();
195
196
  await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
196
- const validation = await this.validateLocalOrderData(params.orderData);
197
+ const validation = this.validateLocalOrderData(params.orderData);
197
198
  if (!validation.valid) {
198
199
  throw (0, import_utils.createCheckoutError)(
199
200
  import_types.CheckoutErrorType.ValidationFailed,
@@ -237,13 +238,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
237
238
  }
238
239
  });
239
240
  this.store.currentOrder = paymentOrder;
240
- await this.initWalletData();
241
+ this.initWalletData();
241
242
  await this.setStatus(import_types.CheckoutStatus.OrderCreated);
242
243
  await this.setStep(import_types.CheckoutStep.PaymentMethod);
243
244
  if (params.autoPayment) {
244
245
  await this.setStep(import_types.CheckoutStep.PaymentProcessing);
245
246
  }
246
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
247
+ this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
247
248
  order: paymentOrder,
248
249
  timestamp: Date.now()
249
250
  });
@@ -262,7 +263,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
262
263
  error,
263
264
  import_types.CheckoutErrorType.OrderCreationFailed
264
265
  );
265
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
266
+ this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
266
267
  error: this.store.lastError,
267
268
  timestamp: Date.now()
268
269
  });
@@ -515,6 +516,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
515
516
  this.payment.wallet.clearAllCache();
516
517
  this.store.cartItems = [];
517
518
  this.store.stateAmount = "0.00";
519
+ this.store.balanceDueAmount = "0.00";
518
520
  this.store.isOrderSynced = false;
519
521
  this.store.currentCustomer = void 0;
520
522
  await this.setStatus(import_types.CheckoutStatus.Cancelled);
@@ -824,6 +826,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
824
826
  getStateAmount() {
825
827
  return this.store.stateAmount;
826
828
  }
829
+ /**
830
+ * 获取系统计算的待付金额(只读)
831
+ *
832
+ * 此方法返回系统内部计算的实际待付金额,不允许外部修改
833
+ *
834
+ * @returns 当前系统计算的待付金额
835
+ */
836
+ getBalanceDueAmount() {
837
+ return this.store.balanceDueAmount;
838
+ }
827
839
  /**
828
840
  * 刷新 stateAmount 为当前剩余未支付金额
829
841
  *
@@ -1456,6 +1468,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1456
1468
  this.store.currentOrder = void 0;
1457
1469
  this.store.localOrderData = void 0;
1458
1470
  this.store.stateAmount = "0.00";
1471
+ this.store.balanceDueAmount = "0.00";
1459
1472
  this.store.isOrderSynced = false;
1460
1473
  this.store.currentCustomer = void 0;
1461
1474
  this.payment.wallet.clearAllCache();
@@ -1786,13 +1799,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1786
1799
  /**
1787
1800
  * 验证结账参数
1788
1801
  */
1789
- async validateCheckoutParams(params) {
1802
+ validateCheckoutParams(params) {
1790
1803
  return (0, import_utils.validateCheckoutData)(params);
1791
1804
  }
1792
1805
  /**
1793
1806
  * 验证本地订单数据
1794
1807
  */
1795
- async validateLocalOrderData(orderData) {
1808
+ validateLocalOrderData(orderData) {
1796
1809
  var _a;
1797
1810
  const errors = [];
1798
1811
  if (!orderData.type) {
@@ -1980,6 +1993,41 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1980
1993
  });
1981
1994
  return result;
1982
1995
  }
1996
+ /**
1997
+ * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
1998
+ */
1999
+ async updateBalanceDueAmount() {
2000
+ var _a;
2001
+ try {
2002
+ const remainingAmount = await this.calculateRemainingAmountAsync();
2003
+ const currentBalanceDueAmount = this.store.balanceDueAmount;
2004
+ console.log("[Checkout] updateBalanceDueAmount: 状态检查:", {
2005
+ calculatedRemainingAmount: remainingAmount,
2006
+ currentBalanceDueAmount,
2007
+ needsUpdate: remainingAmount !== currentBalanceDueAmount,
2008
+ orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
2009
+ });
2010
+ if (remainingAmount !== currentBalanceDueAmount) {
2011
+ this.store.balanceDueAmount = remainingAmount;
2012
+ await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
2013
+ oldAmount: currentBalanceDueAmount,
2014
+ newAmount: remainingAmount,
2015
+ timestamp: Date.now()
2016
+ });
2017
+ console.log("[Checkout] balanceDueAmount 已自动更新:", {
2018
+ oldAmount: currentBalanceDueAmount,
2019
+ newAmount: remainingAmount
2020
+ });
2021
+ } else {
2022
+ console.log("[Checkout] balanceDueAmount 无需更新,当前值已是最新:", {
2023
+ balanceDueAmount: currentBalanceDueAmount,
2024
+ remainingAmount
2025
+ });
2026
+ }
2027
+ } catch (error) {
2028
+ console.error("[Checkout] 更新 balanceDueAmount 失败:", error);
2029
+ }
2030
+ }
1983
2031
  /**
1984
2032
  * 更新 stateAmount 为当前剩余未支付金额
1985
2033
  */
@@ -2011,6 +2059,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2011
2059
  remainingAmount
2012
2060
  });
2013
2061
  }
2062
+ await this.updateBalanceDueAmount();
2014
2063
  await this.checkOrderPaymentCompletion();
2015
2064
  } catch (error) {
2016
2065
  console.error("[Checkout] 更新 stateAmount 为剩余金额失败:", error);
@@ -2253,7 +2302,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2253
2302
  } catch (error) {
2254
2303
  submitSuccess = false;
2255
2304
  submitError = error instanceof Error ? error.message : String(error);
2256
- console.error("[Checkout] 下单接口调用失败:", submitError);
2305
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
2306
+ orderUuid: this.store.currentOrder.uuid,
2307
+ operation: isUpdateOperation ? "update" : "create",
2308
+ isManual,
2309
+ error: submitError,
2310
+ errorType: "network_error",
2311
+ duration: Date.now() - startTime,
2312
+ timestamp: Date.now()
2313
+ });
2257
2314
  throw error;
2258
2315
  } finally {
2259
2316
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitEnd, {
@@ -2273,6 +2330,30 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2273
2330
  message: checkoutResponse == null ? void 0 : checkoutResponse.message,
2274
2331
  data: checkoutResponse == null ? void 0 : checkoutResponse.data
2275
2332
  });
2333
+ const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
2334
+ const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
2335
+ if (!isSuccessResponse) {
2336
+ const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
2337
+ console.error("[Checkout] 订单同步失败,响应状态检查未通过:", {
2338
+ expectedSuccess: true,
2339
+ actualStatus: responseStatus,
2340
+ code: checkoutResponse == null ? void 0 : checkoutResponse.code,
2341
+ message: checkoutResponse == null ? void 0 : checkoutResponse.message,
2342
+ errorMessage
2343
+ });
2344
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
2345
+ orderUuid: this.store.currentOrder.uuid,
2346
+ operation: isUpdateOperation ? "update" : "create",
2347
+ isManual,
2348
+ error: errorMessage,
2349
+ errorType: "api_error",
2350
+ response: checkoutResponse,
2351
+ duration: Date.now() - startTime,
2352
+ timestamp: Date.now()
2353
+ });
2354
+ throw new Error(errorMessage);
2355
+ }
2356
+ console.log("[Checkout] 响应状态检查通过,开始处理订单数据");
2276
2357
  let realOrderId;
2277
2358
  if (isUpdateOperation) {
2278
2359
  realOrderId = currentOrderId;
@@ -2599,6 +2680,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2599
2680
  this.store.localOrderData = void 0;
2600
2681
  this.store.cartSummary = void 0;
2601
2682
  this.store.stateAmount = "0.00";
2683
+ this.store.balanceDueAmount = "0.00";
2602
2684
  this.store.isOrderSynced = false;
2603
2685
  this.store.currentCustomer = void 0;
2604
2686
  this.store.lastError = void 0;
@@ -384,10 +384,14 @@ export declare enum CheckoutHooks {
384
384
  OnError = "checkout:onError",
385
385
  /** 自定义支付金额变更 */
386
386
  OnStateAmountChanged = "checkout:onStateAmountChanged",
387
+ /** 系统计算的待付金额变更 */
388
+ OnBalanceDueAmountChanged = "checkout:onBalanceDueAmountChanged",
387
389
  /** 订单支付完成(待付款金额 ≤ 0) */
388
390
  OnOrderPaymentCompleted = "checkout:onOrderPaymentCompleted",
389
391
  /** 订单同步到后端完成 */
390
392
  OnOrderSynced = "checkout:onOrderSynced",
393
+ /** 订单同步到后端失败 */
394
+ OnOrderSyncFailed = "checkout:onOrderSyncFailed",
391
395
  /** 订单备注变更 */
392
396
  OnOrderNoteChanged = "checkout:onOrderNoteChanged",
393
397
  /** 商店折扣变更 */
@@ -423,6 +427,8 @@ export interface CheckoutState {
423
427
  lastError?: CheckoutError;
424
428
  /** UI 自定义支付金额 */
425
429
  stateAmount: string;
430
+ /** 系统计算的待付金额(只读,由系统内部计算) */
431
+ balanceDueAmount: string;
426
432
  /** 订单是否已同步到后端 */
427
433
  isOrderSynced: boolean;
428
434
  /** 当前客户信息 */
@@ -562,6 +568,12 @@ export interface CheckoutModuleAPI extends Module {
562
568
  * 获取当前自定义支付金额
563
569
  */
564
570
  getStateAmount(): string;
571
+ /**
572
+ * 获取系统计算的待付金额(只读)
573
+ *
574
+ * @returns 当前系统计算的待付金额
575
+ */
576
+ getBalanceDueAmount(): string;
565
577
  /**
566
578
  * 刷新 stateAmount 为当前剩余未支付金额
567
579
  */
@@ -782,6 +794,12 @@ export interface CheckoutEventData {
782
794
  newAmount: string;
783
795
  timestamp: number;
784
796
  };
797
+ /** 系统计算的待付金额变更事件 */
798
+ balanceDueAmountChanged: {
799
+ oldAmount: string;
800
+ newAmount: string;
801
+ timestamp: number;
802
+ };
785
803
  /** 订单支付完成事件 */
786
804
  orderPaymentCompleted: {
787
805
  orderUuid: string;
@@ -799,6 +817,25 @@ export interface CheckoutEventData {
799
817
  timestamp: number;
800
818
  /** 是否为手动同步 */
801
819
  isManual?: boolean;
820
+ /** 后端响应数据 */
821
+ response?: any;
822
+ };
823
+ /** 订单同步到后端失败事件 */
824
+ orderSyncFailed: {
825
+ orderUuid: string;
826
+ /** 操作类型 */
827
+ operation: 'create' | 'update';
828
+ /** 是否为手动同步 */
829
+ isManual: boolean;
830
+ /** 错误信息 */
831
+ error: string;
832
+ /** 错误类型 */
833
+ errorType: 'network_error' | 'api_error' | 'response_invalid' | 'unknown';
834
+ /** 后端响应数据(如果有) */
835
+ response?: any;
836
+ /** 耗时(毫秒) */
837
+ duration?: number;
838
+ timestamp: number;
802
839
  };
803
840
  /** 订单备注变更事件 */
804
841
  orderNoteChanged: {
@@ -65,8 +65,10 @@ var CheckoutHooks = /* @__PURE__ */ ((CheckoutHooks2) => {
65
65
  CheckoutHooks2["OnCheckoutCancelled"] = "checkout:onCancelled";
66
66
  CheckoutHooks2["OnError"] = "checkout:onError";
67
67
  CheckoutHooks2["OnStateAmountChanged"] = "checkout:onStateAmountChanged";
68
+ CheckoutHooks2["OnBalanceDueAmountChanged"] = "checkout:onBalanceDueAmountChanged";
68
69
  CheckoutHooks2["OnOrderPaymentCompleted"] = "checkout:onOrderPaymentCompleted";
69
70
  CheckoutHooks2["OnOrderSynced"] = "checkout:onOrderSynced";
71
+ CheckoutHooks2["OnOrderSyncFailed"] = "checkout:onOrderSyncFailed";
70
72
  CheckoutHooks2["OnOrderNoteChanged"] = "checkout:onOrderNoteChanged";
71
73
  CheckoutHooks2["OnShopDiscountChanged"] = "checkout:onShopDiscountChanged";
72
74
  CheckoutHooks2["OnOrderCancelled"] = "checkout:onOrderCancelled";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.243",
4
+ "version": "0.0.245",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",