@pisell/pisellos 0.0.260 → 0.0.261

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.
@@ -1030,7 +1030,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1030
1030
  key: "addPaymentItemAsync",
1031
1031
  value: (function () {
1032
1032
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(paymentItem) {
1033
- var _paymentItem$type, _paymentItem$code, orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, isEftposPayment, syncResult;
1033
+ var orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type, _paymentItem$code, isEftposPayment, syncResult;
1034
1034
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1035
1035
  while (1) switch (_context15.prev = _context15.next) {
1036
1036
  case 0:
@@ -1062,6 +1062,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1062
1062
  case 12:
1063
1063
  this.logInfo('支付项添加成功');
1064
1064
 
1065
+ // 支付项添加后,更新 stateAmount 为剩余未支付金额
1066
+ _context15.next = 15;
1067
+ return this.updateStateAmountToRemaining();
1068
+ case 15:
1069
+ _context15.next = 17;
1070
+ return this.calculateRemainingAmountAsync();
1071
+ case 17:
1072
+ remainingAmount = _context15.sent;
1073
+ if (!(Number(remainingAmount) > 0)) {
1074
+ _context15.next = 36;
1075
+ break;
1076
+ }
1077
+ this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
1065
1078
  // 检查是否是 EFTPOS 支付,如果是则立即同步订单
1066
1079
  isEftposPayment = ((_paymentItem$type = paymentItem.type) === null || _paymentItem$type === void 0 ? void 0 : _paymentItem$type.toLowerCase()) === 'eftpos' || ((_paymentItem$code = paymentItem.code) === null || _paymentItem$code === void 0 ? void 0 : _paymentItem$code.toUpperCase().includes('EFTPOS'));
1067
1080
  this.logInfo('EFTPOS 支付检查:', {
@@ -1071,34 +1084,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1071
1084
  currentOrderSynced: this.store.isOrderSynced
1072
1085
  });
1073
1086
  if (!isEftposPayment) {
1074
- _context15.next = 29;
1087
+ _context15.next = 36;
1075
1088
  break;
1076
1089
  }
1077
1090
  this.logInfo('检测到 EFTPOS 支付,立即同步订单到后端...');
1078
- _context15.prev = 17;
1079
- _context15.next = 20;
1091
+ _context15.prev = 24;
1092
+ _context15.next = 27;
1080
1093
  return this.syncOrderToBackendWithReturn(true);
1081
- case 20:
1094
+ case 27:
1082
1095
  syncResult = _context15.sent;
1083
1096
  this.logInfo('EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1084
1097
  orderId: syncResult.orderId,
1085
1098
  isOrderSynced: this.store.isOrderSynced,
1086
1099
  backendResponse: syncResult.response
1087
1100
  });
1088
- _context15.next = 29;
1101
+ _context15.next = 36;
1089
1102
  break;
1090
- case 24:
1091
- _context15.prev = 24;
1092
- _context15.t0 = _context15["catch"](17);
1103
+ case 31:
1104
+ _context15.prev = 31;
1105
+ _context15.t0 = _context15["catch"](24);
1093
1106
  this.logError('EFTPOS 支付后订单同步失败:', _context15.t0);
1094
1107
  // 不抛出错误,避免影响支付流程,但记录错误
1095
- _context15.next = 29;
1108
+ _context15.next = 36;
1096
1109
  return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0))), CheckoutErrorType.OrderCreationFailed);
1097
- case 29:
1098
- _context15.next = 31;
1099
- return this.updateStateAmountToRemaining();
1100
- case 31:
1101
- _context15.next = 33;
1110
+ case 36:
1111
+ _context15.next = 38;
1102
1112
  return this.core.effects.emit(CheckoutHooks.OnPaymentItemAdded, {
1103
1113
  orderUuid: this.store.currentOrder.uuid,
1104
1114
  paymentMethodCode: paymentItem.code,
@@ -1106,22 +1116,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1106
1116
  amount: String(paymentItem.amount),
1107
1117
  timestamp: Date.now()
1108
1118
  });
1109
- case 33:
1110
- _context15.next = 41;
1119
+ case 38:
1120
+ _context15.next = 46;
1111
1121
  break;
1112
- case 35:
1113
- _context15.prev = 35;
1122
+ case 40:
1123
+ _context15.prev = 40;
1114
1124
  _context15.t1 = _context15["catch"](1);
1115
1125
  this.logError('添加支付项失败:', _context15.t1);
1116
- _context15.next = 40;
1126
+ _context15.next = 45;
1117
1127
  return this.handleError(_context15.t1, CheckoutErrorType.PaymentFailed);
1118
- case 40:
1128
+ case 45:
1119
1129
  throw _context15.t1;
1120
- case 41:
1130
+ case 46:
1121
1131
  case "end":
1122
1132
  return _context15.stop();
1123
1133
  }
1124
- }, _callee15, this, [[1, 35], [17, 24]]);
1134
+ }, _callee15, this, [[1, 40], [24, 31]]);
1125
1135
  }));
1126
1136
  function addPaymentItemAsync(_x14) {
1127
1137
  return _addPaymentItemAsync.apply(this, arguments);
@@ -638,33 +638,37 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
638
638
  paymentItemWithType
639
639
  );
640
640
  this.logInfo("支付项添加成功");
641
- const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
642
- this.logInfo("EFTPOS 支付检查:", {
643
- paymentCode: paymentItem.code,
644
- paymentType: paymentItem.type,
645
- isEftposPayment,
646
- currentOrderSynced: this.store.isOrderSynced
647
- });
648
- if (isEftposPayment) {
649
- this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
650
- try {
651
- const syncResult = await this.syncOrderToBackendWithReturn(true);
652
- this.logInfo("EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
653
- orderId: syncResult.orderId,
654
- isOrderSynced: this.store.isOrderSynced,
655
- backendResponse: syncResult.response
656
- });
657
- } catch (error) {
658
- this.logError("EFTPOS 支付后订单同步失败:", error);
659
- await this.handleError(
660
- new Error(
661
- `EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`
662
- ),
663
- import_types.CheckoutErrorType.OrderCreationFailed
664
- );
641
+ await this.updateStateAmountToRemaining();
642
+ const remainingAmount = await this.calculateRemainingAmountAsync();
643
+ if (Number(remainingAmount) > 0) {
644
+ this.logInfo("订单金额还有待付的,同步 EFTPOS 支付");
645
+ const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
646
+ this.logInfo("EFTPOS 支付检查:", {
647
+ paymentCode: paymentItem.code,
648
+ paymentType: paymentItem.type,
649
+ isEftposPayment,
650
+ currentOrderSynced: this.store.isOrderSynced
651
+ });
652
+ if (isEftposPayment) {
653
+ this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
654
+ try {
655
+ const syncResult = await this.syncOrderToBackendWithReturn(true);
656
+ this.logInfo("EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
657
+ orderId: syncResult.orderId,
658
+ isOrderSynced: this.store.isOrderSynced,
659
+ backendResponse: syncResult.response
660
+ });
661
+ } catch (error) {
662
+ this.logError("EFTPOS 支付后订单同步失败:", error);
663
+ await this.handleError(
664
+ new Error(
665
+ `EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`
666
+ ),
667
+ import_types.CheckoutErrorType.OrderCreationFailed
668
+ );
669
+ }
665
670
  }
666
671
  }
667
- await this.updateStateAmountToRemaining();
668
672
  await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentItemAdded, {
669
673
  orderUuid: this.store.currentOrder.uuid,
670
674
  paymentMethodCode: paymentItem.code,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.260",
4
+ "version": "0.0.261",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",