@pisell/pisellos 0.0.254 → 0.0.256

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.
@@ -45,7 +45,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
45
45
  if (!this.request) {
46
46
  throw new Error("Checkout 解决方案需要 request 插件支持");
47
47
  }
48
- this.logger = core.getPlugin("logger");
48
+ const appPlugin = core.getPlugin("app");
49
+ if (!appPlugin) {
50
+ throw new Error("Checkout 解决方案需要 app 插件支持");
51
+ }
52
+ const app = appPlugin.getApp();
53
+ this.logger = app.logger;
49
54
  this.order = new import_Order.OrderModule();
50
55
  this.payment = new import_Payment.PaymentModule();
51
56
  this.store = {
@@ -874,6 +879,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
874
879
  if (oldAmount === formattedAmount) {
875
880
  return;
876
881
  }
882
+ this.logger.info("[Checkout] 设置自定义支付金额:", {
883
+ oldAmount,
884
+ newAmount: formattedAmount
885
+ });
877
886
  this.store.stateAmount = formattedAmount;
878
887
  await this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
879
888
  oldAmount,
@@ -997,7 +1006,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
997
1006
  * @throws 当前没有活跃订单时抛出错误
998
1007
  */
999
1008
  async addPaymentItemAsync(paymentItem) {
1000
- var _a, _b, _c, _d;
1009
+ var _a, _b, _c, _d, _e, _f;
1001
1010
  this.logInfo("addPaymentItemAsync called", {
1002
1011
  paymentCode: paymentItem.code,
1003
1012
  paymentType: paymentItem.type,
@@ -1018,13 +1027,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1018
1027
  );
1019
1028
  }
1020
1029
  const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
1030
+ const processedPaymentItem = await this.processCashPaymentItem(paymentItem);
1021
1031
  const metadata = {
1022
- ...paymentItem.metadata,
1032
+ ...processedPaymentItem.metadata,
1023
1033
  rounding_rule: this.otherParams.order_rounding_setting,
1024
1034
  shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
1025
1035
  };
1026
1036
  const paymentItemWithType = {
1027
- ...paymentItem,
1037
+ ...processedPaymentItem,
1028
1038
  order_payment_type: orderPaymentType,
1029
1039
  metadata
1030
1040
  };
@@ -1042,14 +1052,20 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1042
1052
  metadata: paymentItemWithType.metadata
1043
1053
  },
1044
1054
  orderDepositStatus: this.store.currentOrder.is_deposit,
1045
- calculatedOrderPaymentType: orderPaymentType
1055
+ calculatedOrderPaymentType: orderPaymentType,
1056
+ // 现金支付找零详情
1057
+ isCashPayment: this.isCashPayment(paymentItem.code, paymentItem.type),
1058
+ originalAmount: paymentItem.amount,
1059
+ processedAmount: paymentItemWithType.amount,
1060
+ actualPaidAmount: (_c = paymentItemWithType.metadata) == null ? void 0 : _c.actual_paid_amount,
1061
+ changeGivenAmount: (_d = paymentItemWithType.metadata) == null ? void 0 : _d.change_given_amount
1046
1062
  });
1047
1063
  await this.payment.addPaymentItemAsync(
1048
1064
  this.store.currentOrder.uuid,
1049
1065
  paymentItemWithType
1050
1066
  );
1051
1067
  console.log("[Checkout] 支付项添加成功");
1052
- const isEftposPayment = ((_c = paymentItem.type) == null ? void 0 : _c.toLowerCase()) === "eftpos" || ((_d = paymentItem.code) == null ? void 0 : _d.toUpperCase().includes("EFTPOS"));
1068
+ const isEftposPayment = ((_e = paymentItem.type) == null ? void 0 : _e.toLowerCase()) === "eftpos" || ((_f = paymentItem.code) == null ? void 0 : _f.toUpperCase().includes("EFTPOS"));
1053
1069
  console.log("[Checkout] EFTPOS 支付检查:", {
1054
1070
  paymentCode: paymentItem.code,
1055
1071
  paymentType: paymentItem.type,
@@ -1905,6 +1921,75 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1905
1921
  validateCheckoutParams(params) {
1906
1922
  return (0, import_utils.validateCheckoutData)(params);
1907
1923
  }
1924
+ /**
1925
+ * 处理现金支付项的找零逻辑
1926
+ *
1927
+ * @param paymentItem 原始支付项
1928
+ * @returns 处理后的支付项(包含找零信息)
1929
+ */
1930
+ async processCashPaymentItem(paymentItem) {
1931
+ const isCashPayment = this.isCashPayment(paymentItem.code, paymentItem.type);
1932
+ if (!isCashPayment) {
1933
+ return paymentItem;
1934
+ }
1935
+ try {
1936
+ const remainingAmountStr = await this.calculateRemainingAmountAsync();
1937
+ const remainingAmount = parseFloat(remainingAmountStr);
1938
+ const cashAmount = parseFloat(String(paymentItem.amount));
1939
+ console.log("[Checkout] 现金支付处理:", {
1940
+ cashAmount,
1941
+ remainingAmount,
1942
+ needsChange: cashAmount > remainingAmount
1943
+ });
1944
+ if (cashAmount <= remainingAmount) {
1945
+ return paymentItem;
1946
+ }
1947
+ const changeAmount = cashAmount - remainingAmount;
1948
+ console.log("[Checkout] 现金支付需要找零:", {
1949
+ actualPaidAmount: cashAmount,
1950
+ chargedAmount: remainingAmount,
1951
+ changeGivenAmount: changeAmount
1952
+ });
1953
+ const processedPaymentItem = {
1954
+ ...paymentItem,
1955
+ amount: remainingAmount,
1956
+ // 将 amount 设置为剩余待付金额
1957
+ metadata: {
1958
+ ...paymentItem.metadata,
1959
+ actual_paid_amount: cashAmount,
1960
+ // 实付金额
1961
+ change_given_amount: changeAmount
1962
+ // 找零金额
1963
+ }
1964
+ };
1965
+ this.logInfo("Cash payment with change processed", {
1966
+ originalAmount: cashAmount,
1967
+ chargedAmount: remainingAmount,
1968
+ changeAmount,
1969
+ paymentCode: paymentItem.code,
1970
+ paymentType: paymentItem.type
1971
+ });
1972
+ return processedPaymentItem;
1973
+ } catch (error) {
1974
+ console.error("[Checkout] 处理现金支付项时出错:", error);
1975
+ return paymentItem;
1976
+ }
1977
+ }
1978
+ /**
1979
+ * 判断是否为现金支付
1980
+ *
1981
+ * @param paymentCode 支付代码
1982
+ * @param paymentType 支付类型
1983
+ * @returns 是否为现金支付
1984
+ */
1985
+ isCashPayment(paymentCode, paymentType) {
1986
+ const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
1987
+ const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
1988
+ const cashIdentifiers = ["CASH", "CASHMANUAL", "MANUAL"];
1989
+ return cashIdentifiers.some(
1990
+ (identifier) => codeUpper.includes(identifier) || typeUpper.includes(identifier)
1991
+ );
1992
+ }
1908
1993
  /**
1909
1994
  * 预加载支付方式(在初始化时调用)
1910
1995
  */
@@ -2311,11 +2396,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2311
2396
  originalCount: paymentItems.length,
2312
2397
  processedCount: processedPaymentItems.length,
2313
2398
  sampleMetadata: (_b = processedPaymentItems[0]) == null ? void 0 : _b.metadata,
2314
- allPaymentItems: processedPaymentItems.map((p) => ({
2315
- code: p.code,
2316
- amount: p.amount,
2317
- metadata: p.metadata
2318
- }))
2399
+ allPaymentItems: processedPaymentItems.map((p) => {
2400
+ var _a2, _b2;
2401
+ return {
2402
+ code: p.code,
2403
+ amount: p.amount,
2404
+ voucherId: p.voucher_id,
2405
+ orderPaymentType: p.order_payment_type,
2406
+ metadata: p.metadata,
2407
+ // 现金支付找零信息
2408
+ actualPaidAmount: (_a2 = p.metadata) == null ? void 0 : _a2.actual_paid_amount,
2409
+ changeGivenAmount: (_b2 = p.metadata) == null ? void 0 : _b2.change_given_amount
2410
+ };
2411
+ })
2319
2412
  });
2320
2413
  const orderParams = {
2321
2414
  ...this.store.localOrderData,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.254",
4
+ "version": "0.0.256",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",