@pisell/pisellos 2.2.204 → 2.2.205

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 (39) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/Order/index.js +9 -3
  3. package/dist/modules/Payment/index.d.ts +0 -13
  4. package/dist/modules/Payment/index.js +449 -833
  5. package/dist/plugins/request.d.ts +1 -0
  6. package/dist/server/index.d.ts +6 -0
  7. package/dist/server/index.js +730 -619
  8. package/dist/server/modules/index.d.ts +2 -0
  9. package/dist/server/modules/index.js +2 -0
  10. package/dist/server/modules/payment/index.d.ts +28 -0
  11. package/dist/server/modules/payment/index.js +305 -0
  12. package/dist/server/modules/payment/types.d.ts +9 -0
  13. package/dist/server/modules/payment/types.js +1 -0
  14. package/dist/solution/BaseSales/index.d.ts +6 -1
  15. package/dist/solution/BaseSales/index.js +67 -18
  16. package/dist/solution/BookingTicket/index.js +1 -1
  17. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +51 -52
  18. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  19. package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
  20. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  21. package/lib/modules/Order/index.js +5 -1
  22. package/lib/modules/Payment/index.d.ts +0 -13
  23. package/lib/modules/Payment/index.js +6 -149
  24. package/lib/plugins/request.d.ts +1 -0
  25. package/lib/server/index.d.ts +6 -0
  26. package/lib/server/index.js +46 -0
  27. package/lib/server/modules/index.d.ts +2 -0
  28. package/lib/server/modules/index.js +3 -0
  29. package/lib/server/modules/payment/index.d.ts +28 -0
  30. package/lib/server/modules/payment/index.js +192 -0
  31. package/lib/server/modules/payment/types.d.ts +9 -0
  32. package/lib/server/modules/payment/types.js +17 -0
  33. package/lib/solution/BaseSales/index.d.ts +6 -1
  34. package/lib/solution/BaseSales/index.js +51 -5
  35. package/lib/solution/BookingTicket/index.js +1 -1
  36. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +1 -2
  37. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  38. package/lib/solution/BookingTicket/utils/scan/index.js +17 -3
  39. package/package.json +1 -1
@@ -76,9 +76,6 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
76
76
  this.defaultVersion = "1.0.0";
77
77
  // LoggerManager 实例
78
78
  this.voucherUpdateLockByOrderUuid = /* @__PURE__ */ new Map();
79
- this.payMethodMemoryCache = null;
80
- this.payMethodListInFlight = null;
81
- this.isRefreshingPaymentMethods = false;
82
79
  this.otherParams = {};
83
80
  this.cash = new import_cash.CashPaymentImpl(this);
84
81
  this.eftpos = new import_eftpos.EftposPaymentImpl(this);
@@ -213,66 +210,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
213
210
  }
214
211
  });
215
212
  }
216
- async filterPayMethods(payMethods) {
217
- payMethods = payMethods.filter((method) => method.status === 1 && method.disable === 0);
218
- const walletPassMethod = payMethods.find((method) => method.code === "WALLET_PASS");
219
- if (walletPassMethod) {
220
- payMethods.forEach((method) => {
221
- if (method.code === "PRODUCTVOUCHER" || method.code === "GIFTCARD" || method.code === "POINTCARD") {
222
- method.channel_application = walletPassMethod.channel_application;
223
- }
224
- });
225
- } else {
226
- payMethods = payMethods.filter((method) => method.code !== "PRODUCTVOUCHER" && method.code !== "GIFTCARD" && method.code !== "POINTCARD");
227
- }
228
- return payMethods;
229
- }
230
213
  /**
231
214
  * 获取支付方式列表
232
215
  */
233
216
  async getPayMethodListAsync() {
234
- var _a;
235
217
  this.logInfo("Starting getPayMethodListAsync");
236
- if ((_a = this.payMethodMemoryCache) == null ? void 0 : _a.length) {
237
- return this.payMethodMemoryCache;
238
- }
239
- if (this.payMethodListInFlight) {
240
- return this.payMethodListInFlight;
241
- }
242
- this.payMethodListInFlight = this.loadPayMethodListAsync().finally(() => {
243
- this.payMethodListInFlight = null;
244
- });
245
- return this.payMethodListInFlight;
246
- }
247
- async loadPayMethodListAsync() {
248
218
  try {
249
- let cachedMethods = [];
250
- try {
251
- cachedMethods = await this.dbManager.getAll("pay_method");
252
- } catch (dbError) {
253
- console.warn("[PaymentModule] pay_method 表不存在,将从服务器获取数据");
254
- }
255
- const hasCache = cachedMethods.length > 0;
256
- if (hasCache) {
257
- this.payMethodMemoryCache = cachedMethods;
258
- this.refreshPaymentMethodsInBackground(cachedMethods);
259
- return cachedMethods;
260
- }
261
- const response = await this.request.get("/pay/custom-payment/all");
262
- response.data = await this.filterPayMethods(response.data);
263
- const payMethods = response.data || [];
264
- this.payMethodMemoryCache = payMethods;
265
- try {
266
- for (const method of payMethods) {
267
- await this.dbManager.update("pay_method", method);
268
- }
269
- } catch (dbError) {
270
- console.warn("[PaymentModule] 无法缓存支付方式,pay_method 表不存在");
271
- }
272
- await this.core.effects.emit(
273
- `${this.name}:onPaymentMethodsLoaded`,
274
- payMethods
275
- );
219
+ const response = await this.request.get("/pay/custom-payment/all", {
220
+ filterPaymentMethods: true
221
+ }, {
222
+ osServer: true
223
+ });
224
+ const payMethods = (response == null ? void 0 : response.data) || response || [];
276
225
  this.logInfo("getPayMethodListAsync completed successfully", {
277
226
  payMethods
278
227
  });
@@ -283,98 +232,6 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
283
232
  return [];
284
233
  }
285
234
  }
286
- /**
287
- * 后台刷新支付方式列表
288
- */
289
- async refreshPaymentMethodsInBackground(cachedMethods) {
290
- if (this.isRefreshingPaymentMethods)
291
- return;
292
- this.isRefreshingPaymentMethods = true;
293
- this.logInfo("Starting refreshPaymentMethodsInBackground", {
294
- cachedMethodsCount: cachedMethods.length
295
- });
296
- try {
297
- console.log("[PaymentModule] 后台刷新支付方式列表...");
298
- const response = await this.request.get("/pay/custom-payment/all");
299
- response.data = await this.filterPayMethods(response.data);
300
- const newPayMethods = response.data || [];
301
- this.payMethodMemoryCache = newPayMethods;
302
- const hasChanges = this.hasPaymentMethodsChanged(
303
- cachedMethods,
304
- newPayMethods
305
- );
306
- if (hasChanges) {
307
- console.log("[PaymentModule] 支付方式列表已更新");
308
- this.logInfo("Payment methods updated in background", {
309
- oldCount: cachedMethods.length,
310
- newCount: newPayMethods.length
311
- });
312
- try {
313
- for (const method of cachedMethods) {
314
- await this.dbManager.delete("pay_method", method.id);
315
- }
316
- for (const method of newPayMethods) {
317
- await this.dbManager.update("pay_method", method);
318
- }
319
- } catch (dbError) {
320
- console.warn("[PaymentModule] 无法更新支付方式缓存", dbError);
321
- }
322
- const eventData = {
323
- oldMethods: cachedMethods,
324
- newMethods: newPayMethods
325
- };
326
- await this.core.effects.emit(
327
- `${this.name}:onPaymentMethodsChanged`,
328
- eventData
329
- );
330
- } else {
331
- console.log("[PaymentModule] 支付方式列表无变化");
332
- }
333
- } catch (error) {
334
- console.error("[PaymentModule] 后台刷新支付方式失败", error);
335
- } finally {
336
- this.isRefreshingPaymentMethods = false;
337
- }
338
- }
339
- /**
340
- * 检查支付方式列表是否有变化
341
- */
342
- hasPaymentMethodsChanged(oldMethods, newMethods) {
343
- if (oldMethods.length !== newMethods.length) {
344
- return true;
345
- }
346
- const oldMethodsMap = new Map(
347
- oldMethods.map((method) => [method.id, method])
348
- );
349
- for (const newMethod of newMethods) {
350
- const oldMethod = oldMethodsMap.get(newMethod.id);
351
- if (!oldMethod) {
352
- return true;
353
- }
354
- if (oldMethod.code !== newMethod.code || oldMethod.name !== newMethod.name || oldMethod.type !== newMethod.type || oldMethod.description !== newMethod.description || oldMethod.status !== newMethod.status || oldMethod.disable !== newMethod.disable || oldMethod.is_surcharge !== newMethod.is_surcharge || oldMethod.fixed !== newMethod.fixed || oldMethod.percentage !== newMethod.percentage || oldMethod.enabled !== newMethod.enabled || JSON.stringify(oldMethod.channel_application || []) !== JSON.stringify(newMethod.channel_application || []) || JSON.stringify(oldMethod.companies || []) !== JSON.stringify(newMethod.companies || []) || JSON.stringify(oldMethod.metadata || {}) !== JSON.stringify(newMethod.metadata || {})) {
355
- console.log(`[PaymentModule] 支付方式 ${newMethod.id} (${newMethod.code}) 发生变化:`, {
356
- id: newMethod.id,
357
- changes: {
358
- code: oldMethod.code !== newMethod.code ? { old: oldMethod.code, new: newMethod.code } : void 0,
359
- name: oldMethod.name !== newMethod.name ? { old: oldMethod.name, new: newMethod.name } : void 0,
360
- type: oldMethod.type !== newMethod.type ? { old: oldMethod.type, new: newMethod.type } : void 0,
361
- description: oldMethod.description !== newMethod.description ? { old: oldMethod.description, new: newMethod.description } : void 0,
362
- status: oldMethod.status !== newMethod.status ? { old: oldMethod.status, new: newMethod.status } : void 0,
363
- disable: oldMethod.disable !== newMethod.disable ? { old: oldMethod.disable, new: newMethod.disable } : void 0,
364
- is_surcharge: oldMethod.is_surcharge !== newMethod.is_surcharge ? { old: oldMethod.is_surcharge, new: newMethod.is_surcharge } : void 0,
365
- fixed: oldMethod.fixed !== newMethod.fixed ? { old: oldMethod.fixed, new: newMethod.fixed } : void 0,
366
- percentage: oldMethod.percentage !== newMethod.percentage ? { old: oldMethod.percentage, new: newMethod.percentage } : void 0,
367
- enabled: oldMethod.enabled !== newMethod.enabled ? { old: oldMethod.enabled, new: newMethod.enabled } : void 0,
368
- channel_application: JSON.stringify(oldMethod.channel_application || []) !== JSON.stringify(newMethod.channel_application || []) ? { old: oldMethod.channel_application, new: newMethod.channel_application } : void 0,
369
- companies: JSON.stringify(oldMethod.companies || []) !== JSON.stringify(newMethod.companies || []) ? { old: oldMethod.companies, new: newMethod.companies } : void 0,
370
- metadata: JSON.stringify(oldMethod.metadata || {}) !== JSON.stringify(newMethod.metadata || {}) ? { old: oldMethod.metadata, new: newMethod.metadata } : void 0
371
- }
372
- });
373
- return true;
374
- }
375
- }
376
- return false;
377
- }
378
235
  /**
379
236
  * 获取订单列表
380
237
  */
@@ -69,6 +69,7 @@ export interface RequestOptions {
69
69
  customToast?: () => void;
70
70
  cache?: CacheProps;
71
71
  osServer?: boolean;
72
+ prefix?: boolean;
72
73
  callback?: (res: any) => void;
73
74
  subscriberId?: string;
74
75
  }
@@ -4,6 +4,7 @@ import { QuotationModule } from './modules/quotation';
4
4
  import { ScheduleModuleEx } from './modules/schedule';
5
5
  import { ResourceModule } from './modules/resource';
6
6
  import { FloorPlanModule } from './modules/floor-plan';
7
+ import { PaymentServerModule } from './modules/payment';
7
8
  import { PisellCore, ServerModuleConfig, InitializeServerOptions } from '../types';
8
9
  import type { RouteHandler, HttpMethod, RouteDefinition, Router, ModuleRegistryConfig, RequestSetting } from './types';
9
10
  import { OrderModule } from './modules/order';
@@ -23,6 +24,9 @@ declare class Server {
23
24
  resource?: ResourceModule;
24
25
  order?: OrderModule;
25
26
  floor_plan?: FloorPlanModule;
27
+ payment?: PaymentServerModule;
28
+ private paymentRouteModule?;
29
+ private paymentRouteModuleInFlight?;
26
30
  /** GET 前缀路由(最长前缀优先匹配) */
27
31
  private prefixRouterGet;
28
32
  router: Router;
@@ -167,6 +171,8 @@ declare class Server {
167
171
  * @private
168
172
  */
169
173
  private registerServerRoutes;
174
+ private getPaymentRouteModule;
175
+ private handlePaymentMethods;
170
176
  /**
171
177
  * 根据 subscriberId 移除商品查询订阅者
172
178
  */
@@ -41,6 +41,7 @@ var import_schedule = require("./modules/schedule");
41
41
  var import_resource = require("./modules/resource");
42
42
  var import_floor_plan = require("./modules/floor-plan");
43
43
  var import_types = require("./modules/floor-plan/types");
44
+ var import_payment = require("./modules/payment");
44
45
  var import_schedule2 = require("./utils/schedule");
45
46
  var import_types2 = require("./modules/products/types");
46
47
  var import_product = require("./utils/product");
@@ -120,6 +121,15 @@ var Server = class {
120
121
  list: []
121
122
  }
122
123
  },
124
+ payment: {
125
+ name: "payment",
126
+ moduleClass: import_payment.PaymentServerModule,
127
+ moduleName: "server_payment",
128
+ version: "1.0.0",
129
+ defaultStore: {
130
+ payMethods: []
131
+ }
132
+ },
123
133
  resource: {
124
134
  name: "resource",
125
135
  moduleClass: import_resource.ResourceModule,
@@ -143,6 +153,18 @@ var Server = class {
143
153
  }
144
154
  }
145
155
  };
156
+ this.handlePaymentMethods = async ({ data, config }) => {
157
+ debugger;
158
+ const payment = await this.getPaymentRouteModule();
159
+ const payMethods = await payment.getPayMethodListAsync({
160
+ shouldFilter: (data == null ? void 0 : data.filterPaymentMethods) === true || (config == null ? void 0 : config.filterPaymentMethods) === true
161
+ });
162
+ return {
163
+ code: 200,
164
+ status: true,
165
+ data: payMethods
166
+ };
167
+ };
146
168
  /**
147
169
  * 处理商品查询请求
148
170
  * 存储订阅者信息,便于数据变更时推送最新结果
@@ -1262,6 +1284,11 @@ var Server = class {
1262
1284
  path: "/update/localOrder",
1263
1285
  handler: this.handleUpdateLocalOrder.bind(this)
1264
1286
  },
1287
+ {
1288
+ method: "get",
1289
+ path: "/shop/pay/custom-payment/all",
1290
+ handler: this.handlePaymentMethods.bind(this)
1291
+ },
1265
1292
  {
1266
1293
  method: "post",
1267
1294
  path: "/shop/order/sales/checkout",
@@ -1286,6 +1313,25 @@ var Server = class {
1286
1313
  }
1287
1314
  ]);
1288
1315
  }
1316
+ async getPaymentRouteModule() {
1317
+ if (this.payment)
1318
+ return this.payment;
1319
+ if (this.paymentRouteModule)
1320
+ return this.paymentRouteModule;
1321
+ if (this.paymentRouteModuleInFlight)
1322
+ return this.paymentRouteModuleInFlight;
1323
+ this.paymentRouteModuleInFlight = (async () => {
1324
+ const module2 = new import_payment.PaymentServerModule("server_payment_route", "1.0.0");
1325
+ await module2.initialize(this.core, {
1326
+ store: { payMethods: [] }
1327
+ });
1328
+ this.paymentRouteModule = module2;
1329
+ return module2;
1330
+ })().finally(() => {
1331
+ this.paymentRouteModuleInFlight = void 0;
1332
+ });
1333
+ return this.paymentRouteModuleInFlight;
1334
+ }
1289
1335
  /**
1290
1336
  * 根据 subscriberId 移除商品查询订阅者
1291
1337
  */
@@ -16,6 +16,8 @@ export type { ScheduleState, ScheduleItem } from './schedule/types';
16
16
  export { OrderModule } from './order';
17
17
  export type { OrderState, OrderData, OrderId, OrderSummary, OrderBookingItem, OrderProductLineItem, OrderPaymentItem, OrderSurchargeItem, OrderProductDiscountItem, OrderWithoutBookings, BookingData, OrderFilters, BookingFilters, OrderFilterResult, OrderFilterRejectDetail, OrderFilterRejectedEntry, BookingFilterResult, OrderModulePagedResult, } from './order/types';
18
18
  export { OrderHooks } from './order/types';
19
+ export { PaymentServerModule } from './payment';
20
+ export type { PaymentMethod, PaymentMethodsChangedEventData, PaymentServerState } from './payment/types';
19
21
  export { FloorPlanModule } from './floor-plan';
20
22
  export type { FloorPlanItem, FloorPlanState, FloorPlanSyncMessage } from './floor-plan/types';
21
23
  export { FloorPlanHooks } from './floor-plan/types';
@@ -25,6 +25,7 @@ __export(modules_exports, {
25
25
  MenuModule: () => import_menu.MenuModule,
26
26
  OrderHooks: () => import_types4.OrderHooks,
27
27
  OrderModule: () => import_order.OrderModule,
28
+ PaymentServerModule: () => import_payment.PaymentServerModule,
28
29
  ProductsHooks: () => import_types.ProductsHooks,
29
30
  ProductsModule: () => import_products.ProductsModule,
30
31
  QuotationHooks: () => import_types3.QuotationHooks,
@@ -44,6 +45,7 @@ var import_types3 = require("./quotation/types");
44
45
  var import_schedule = require("./schedule");
45
46
  var import_order = require("./order");
46
47
  var import_types4 = require("./order/types");
48
+ var import_payment = require("./payment");
47
49
  var import_floor_plan = require("./floor-plan");
48
50
  var import_types5 = require("./floor-plan/types");
49
51
  var import_resource = require("./resource");
@@ -56,6 +58,7 @@ var import_resource2 = require("./resource");
56
58
  MenuModule,
57
59
  OrderHooks,
58
60
  OrderModule,
61
+ PaymentServerModule,
59
62
  ProductsHooks,
60
63
  ProductsModule,
61
64
  QuotationHooks,
@@ -0,0 +1,28 @@
1
+ import { Module, ModuleOptions, PisellCore } from '../../../types';
2
+ import { BaseModule } from '../../../modules/BaseModule';
3
+ import type { PaymentMethod } from './types';
4
+ export declare class PaymentServerModule extends BaseModule implements Module {
5
+ protected defaultName: string;
6
+ protected defaultVersion: string;
7
+ private request;
8
+ private app;
9
+ private logger;
10
+ private store;
11
+ private payMethodMemoryCache;
12
+ private payMethodListInFlight;
13
+ constructor(name?: string, version?: string);
14
+ initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
15
+ getPayMethodListAsync(options?: {
16
+ shouldFilter?: boolean;
17
+ }): Promise<PaymentMethod[]>;
18
+ clearPayMethodCache(): void;
19
+ private loadPayMethodListAsync;
20
+ private fetchRemotePayMethods;
21
+ private shouldFilterPayMethods;
22
+ private resolvePayMethods;
23
+ private filterPayMethods;
24
+ private setPayMethodCache;
25
+ private logInfo;
26
+ private logWarning;
27
+ private logError;
28
+ }
@@ -0,0 +1,192 @@
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/server/modules/payment/index.ts
20
+ var payment_exports = {};
21
+ __export(payment_exports, {
22
+ PaymentServerModule: () => PaymentServerModule
23
+ });
24
+ module.exports = __toCommonJS(payment_exports);
25
+ var import_BaseModule = require("../../../modules/BaseModule");
26
+ var WALLET_PASS_CODE = "WALLET_PASS";
27
+ var WALLET_DEPENDENT_CODES = /* @__PURE__ */ new Set(["PRODUCTVOUCHER", "GIFTCARD", "POINTCARD"]);
28
+ var PAYMENT_METHODS_LOADED_EVENT = "payment:onPaymentMethodsLoaded";
29
+ var PaymentServerModule = class extends import_BaseModule.BaseModule {
30
+ constructor(name, version) {
31
+ super(name || "payment", version);
32
+ this.defaultName = "payment";
33
+ this.defaultVersion = "1.0.0";
34
+ this.payMethodMemoryCache = null;
35
+ this.payMethodListInFlight = null;
36
+ }
37
+ async initialize(core, options) {
38
+ var _a, _b, _c;
39
+ this.core = core;
40
+ this.store = options == null ? void 0 : options.store;
41
+ if (!this.store)
42
+ this.store = { payMethods: [] };
43
+ if (!Array.isArray(this.store.payMethods))
44
+ this.store.payMethods = [];
45
+ this.request = core.getPlugin("request");
46
+ const appPlugin = core.getPlugin("app");
47
+ this.app = appPlugin == null ? void 0 : appPlugin.getApp();
48
+ this.logger = (_a = this.app) == null ? void 0 : _a.logger;
49
+ if (!this.request && !((_b = this.app) == null ? void 0 : _b.request)) {
50
+ throw new Error("PaymentServerModule 需要 request 插件或 app.request 支持");
51
+ }
52
+ this.logInfo("PaymentServerModule initialized successfully", {
53
+ hasAppRequest: !!((_c = this.app) == null ? void 0 : _c.request)
54
+ });
55
+ }
56
+ // getRoutes(): RouteDefinition[] {
57
+ // return [
58
+ // {
59
+ // method: 'get',
60
+ // path: '/pay/custom-payment/all',
61
+ // handler: async ({ data, config }) => {
62
+ // const payMethods = await this.getPayMethodListAsync({
63
+ // shouldFilter: this.shouldFilterPayMethods(data, config),
64
+ // });
65
+ // return {
66
+ // code: 200,
67
+ // status: true,
68
+ // data: payMethods,
69
+ // };
70
+ // },
71
+ // },
72
+ // ];
73
+ // }
74
+ async getPayMethodListAsync(options = {}) {
75
+ var _a;
76
+ this.logInfo("Starting getPayMethodListAsync");
77
+ if ((_a = this.payMethodMemoryCache) == null ? void 0 : _a.length) {
78
+ return this.resolvePayMethods(this.payMethodMemoryCache, options);
79
+ }
80
+ if (this.payMethodListInFlight) {
81
+ const payMethods2 = await this.payMethodListInFlight;
82
+ return this.resolvePayMethods(payMethods2, options);
83
+ }
84
+ this.payMethodListInFlight = this.loadPayMethodListAsync().finally(() => {
85
+ this.payMethodListInFlight = null;
86
+ });
87
+ const payMethods = await this.payMethodListInFlight;
88
+ return this.resolvePayMethods(payMethods, options);
89
+ }
90
+ clearPayMethodCache() {
91
+ this.payMethodMemoryCache = null;
92
+ this.store.payMethods = [];
93
+ }
94
+ async loadPayMethodListAsync() {
95
+ try {
96
+ const payMethods = await this.fetchRemotePayMethods();
97
+ this.setPayMethodCache(payMethods);
98
+ await this.core.effects.emit(PAYMENT_METHODS_LOADED_EVENT, payMethods);
99
+ this.logInfo("getPayMethodListAsync completed successfully", {
100
+ payMethods
101
+ });
102
+ return payMethods;
103
+ } catch (error) {
104
+ console.error("[PaymentServerModule] 获取支付方式列表失败", error);
105
+ this.logError("getPayMethodListAsync failed", error);
106
+ return [];
107
+ }
108
+ }
109
+ async fetchRemotePayMethods() {
110
+ var _a;
111
+ const requester = ((_a = this.app) == null ? void 0 : _a.request) || this.request;
112
+ const response = await requester.get("/shop/pay/custom-payment/all", void 0);
113
+ const payMethods = (response == null ? void 0 : response.data) || response || [];
114
+ return Array.isArray(payMethods) ? payMethods : [];
115
+ }
116
+ shouldFilterPayMethods(data, config) {
117
+ return (data == null ? void 0 : data.filterPaymentMethods) === true || (config == null ? void 0 : config.filterPaymentMethods) === true;
118
+ }
119
+ resolvePayMethods(payMethods, options) {
120
+ if (!options.shouldFilter)
121
+ return payMethods;
122
+ return this.filterPayMethods(payMethods);
123
+ }
124
+ filterPayMethods(payMethods) {
125
+ if (!Array.isArray(payMethods))
126
+ return [];
127
+ let availableMethods = payMethods.filter(
128
+ (method) => method.status === 1 && method.disable === 0
129
+ );
130
+ const walletPassMethod = availableMethods.find(
131
+ (method) => method.code === WALLET_PASS_CODE
132
+ );
133
+ if (!walletPassMethod) {
134
+ return availableMethods.filter(
135
+ (method) => !WALLET_DEPENDENT_CODES.has(method.code)
136
+ );
137
+ }
138
+ availableMethods = availableMethods.map((method) => {
139
+ if (!WALLET_DEPENDENT_CODES.has(method.code))
140
+ return method;
141
+ return {
142
+ ...method,
143
+ channel_application: walletPassMethod.channel_application
144
+ };
145
+ });
146
+ return availableMethods;
147
+ }
148
+ setPayMethodCache(payMethods) {
149
+ this.payMethodMemoryCache = payMethods;
150
+ this.store.payMethods = payMethods;
151
+ }
152
+ logInfo(title, metadata) {
153
+ try {
154
+ if (this.logger) {
155
+ this.logger.addLog({
156
+ type: "info",
157
+ title: `[PaymentServerModule] ${title}`,
158
+ metadata: metadata || {}
159
+ });
160
+ }
161
+ } catch {
162
+ }
163
+ }
164
+ logWarning(title, metadata) {
165
+ try {
166
+ if (this.logger) {
167
+ this.logger.addLog({
168
+ type: "warning",
169
+ title: `[PaymentServerModule] ${title}`,
170
+ metadata: metadata || {}
171
+ });
172
+ }
173
+ } catch {
174
+ }
175
+ }
176
+ logError(title, metadata) {
177
+ try {
178
+ if (this.logger) {
179
+ this.logger.addLog({
180
+ type: "error",
181
+ title: `[PaymentServerModule] ${title}`,
182
+ metadata: metadata || {}
183
+ });
184
+ }
185
+ } catch {
186
+ }
187
+ }
188
+ };
189
+ // Annotate the CommonJS export names for ESM import in node:
190
+ 0 && (module.exports = {
191
+ PaymentServerModule
192
+ });
@@ -0,0 +1,9 @@
1
+ import type { PaymentMethod } from '../../../modules/Payment/types';
2
+ export interface PaymentServerState {
3
+ payMethods: PaymentMethod[];
4
+ }
5
+ export interface PaymentMethodsChangedEventData {
6
+ oldMethods: PaymentMethod[];
7
+ newMethods: PaymentMethod[];
8
+ }
9
+ export type { PaymentMethod };
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/server/modules/payment/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -9,6 +9,7 @@ import { RequestPlugin, WindowPlugin } from '../../plugins';
9
9
  export * from './types';
10
10
  import { ProductList } from '../../modules/ProductList';
11
11
  import { PaymentModule } from '../../modules/Payment';
12
+ import type { PaymentMethod } from '../../modules/Payment/types';
12
13
  import type { SalesSummaryModule } from '../../modules/SalesSummary';
13
14
  import type { ScheduleModule } from '../../modules/Schedule';
14
15
  import { QuotationModule } from '../../modules/Quotation';
@@ -41,6 +42,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
41
42
  protected currentSalesDetail: ISalesDetail | null;
42
43
  protected discountConfigCacheKey: string | null;
43
44
  protected hasManualDiscountSelection: boolean;
45
+ private paymentMethodsCache;
44
46
  constructor(name?: string, version?: string);
45
47
  /**
46
48
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -59,6 +61,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
59
61
  * 记录错误日志
60
62
  */
61
63
  private logError;
64
+ private hydrateOrderPaymentNames;
62
65
  get payment(): PaymentModule | undefined;
63
66
  private getCurrentOrderCustomerId;
64
67
  private applyQuotationScheduleResolver;
@@ -212,7 +215,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
212
215
  email: string;
213
216
  };
214
217
  /** 获取可用支付方式列表,供 PaymentModal 渲染支付选项。 */
215
- getPaymentMethodsAsync(): Promise<any[]>;
218
+ getPaymentMethodsAsync(): Promise<PaymentMethod[]>;
219
+ /** 同步读取初始化时缓存的支付方式列表。 */
220
+ getPaymentMethods(): PaymentMethod[];
216
221
  /** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
217
222
  roundAmount(params: {
218
223
  amount: string | number;