@pisell/pisellos 2.3.233 → 2.3.234

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 (30) hide show
  1. package/dist/modules/Order/index.d.ts +9 -8
  2. package/dist/modules/Order/index.js +273 -255
  3. package/dist/modules/Order/utils.d.ts +1 -0
  4. package/dist/modules/Order/utils.js +3 -2
  5. package/dist/shared/payment/loadPaymentMethods.d.ts +2 -1
  6. package/dist/shared/payment/loadPaymentMethods.js +13 -12
  7. package/dist/solution/BaseSales/index.d.ts +3 -0
  8. package/dist/solution/BaseSales/index.js +445 -402
  9. package/dist/solution/BookingTicket/index.d.ts +3 -1
  10. package/dist/solution/BookingTicket/index.js +49 -43
  11. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -1
  12. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +69 -13
  13. package/dist/utils/platform.d.ts +2 -0
  14. package/dist/utils/platform.js +4 -0
  15. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  16. package/lib/modules/Order/index.d.ts +9 -8
  17. package/lib/modules/Order/index.js +57 -43
  18. package/lib/modules/Order/utils.d.ts +1 -0
  19. package/lib/modules/Order/utils.js +2 -1
  20. package/lib/shared/payment/loadPaymentMethods.d.ts +2 -1
  21. package/lib/shared/payment/loadPaymentMethods.js +10 -9
  22. package/lib/solution/BaseSales/index.d.ts +3 -0
  23. package/lib/solution/BaseSales/index.js +45 -22
  24. package/lib/solution/BookingTicket/index.d.ts +3 -1
  25. package/lib/solution/BookingTicket/index.js +4 -1
  26. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -1
  27. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +44 -5
  28. package/lib/utils/platform.d.ts +2 -0
  29. package/lib/utils/platform.js +5 -0
  30. package/package.json +1 -1
@@ -170,8 +170,8 @@ class OrderModule extends _BaseModule.BaseModule {
170
170
  moduleHooksOverride;
171
171
  orderHooks;
172
172
  cartCommandQueue = Promise.resolve();
173
- posVirtualPaymentRevision = 0;
174
- posVirtualPaymentSnapshot;
173
+ terminalVirtualPaymentRevision = 0;
174
+ terminalVirtualPaymentSnapshots = new Map();
175
175
  queueCartCommand(run) {
176
176
  if (!this.orderHooks?.onBeforeCartCommit && !this.store.tempOrder?._extend?.productVoucherGroups?.length) return run();
177
177
  const pending = this.cartCommandQueue.then(run, run);
@@ -3818,51 +3818,61 @@ class OrderModule extends _BaseModule.BaseModule {
3818
3818
  isMultiCurrencySettlementEnabled() {
3819
3819
  return this.otherParams?.enableMultiCurrencySettlement === true;
3820
3820
  }
3821
- requiresPosVirtualCurrencyPayment(product) {
3822
- return this.isMultiCurrencySettlementEnabled() && (0, _platform.isPosTerminalPlatform)(this.otherParams?.platform) && (0, _virtualSettlement.isVirtualSettlementProduct)(product);
3821
+ getVirtualCurrencyPaymentChannel() {
3822
+ if (!this.isMultiCurrencySettlementEnabled()) return undefined;
3823
+ return (0, _platform.resolveTerminalVirtualCurrencyChannel)(this.otherParams?.platform, this.otherParams?.businessCode ?? this.otherParams?.business_code);
3823
3824
  }
3824
- getPosVirtualPaymentShopId() {
3825
+ getVirtualPaymentShopId() {
3825
3826
  return String(this.core?.context?.getData?.('shop_id') ?? '');
3826
3827
  }
3827
- syncPosVirtualCurrencyPaymentMethods(methods) {
3828
- const shopId = this.getPosVirtualPaymentShopId();
3828
+ syncTerminalVirtualCurrencyPaymentMethods(channel, methods) {
3829
+ const shopId = this.getVirtualPaymentShopId();
3829
3830
  const sourceShopId = methods.find(method => Number(method?.shop_id) > 0)?.shop_id;
3830
3831
  if (shopId && sourceShopId != null && String(sourceShopId) !== shopId) return;
3831
- this.posVirtualPaymentSnapshot = {
3832
+ this.terminalVirtualPaymentSnapshots.set(channel, {
3832
3833
  shopId,
3833
3834
  methods,
3834
- revision: ++this.posVirtualPaymentRevision
3835
- };
3836
- }
3837
- getPosVirtualCurrencyPaymentMethod(initialMethods = []) {
3838
- const shopId = this.getPosVirtualPaymentShopId();
3839
- const snapshot = this.posVirtualPaymentSnapshot;
3840
- return (0, _loadPaymentMethods.requirePosVirtualCurrencyPaymentMethod)(snapshot?.shopId === shopId ? snapshot.methods : initialMethods, shopId);
3841
- }
3842
- async refreshPosVirtualCurrencyPaymentMethod() {
3843
- const shopId = this.getPosVirtualPaymentShopId();
3844
- const revision = ++this.posVirtualPaymentRevision;
3845
- const methods = await (0, _loadPaymentMethods.loadPaymentMethods)(this.request, {
3846
- transport: 'remote',
3847
- filterPaymentMethods: false
3835
+ revision: ++this.terminalVirtualPaymentRevision
3848
3836
  });
3849
- if (shopId !== this.getPosVirtualPaymentShopId()) {
3850
- throw new Error('[Order] Payment methods belong to a previous shop');
3837
+ }
3838
+ getTerminalVirtualCurrencyPaymentMethod(channel, initialMethods = []) {
3839
+ const shopId = this.getVirtualPaymentShopId();
3840
+ const snapshot = this.terminalVirtualPaymentSnapshots.get(channel);
3841
+ return (0, _loadPaymentMethods.requireTerminalVirtualCurrencyPaymentMethod)(snapshot?.shopId === shopId ? snapshot.methods : initialMethods, channel, shopId);
3842
+ }
3843
+ async refreshTerminalVirtualCurrencyPaymentMethod(channel) {
3844
+ const shopId = this.getVirtualPaymentShopId();
3845
+ const revision = ++this.terminalVirtualPaymentRevision;
3846
+ const publish = methods => {
3847
+ const snapshot = this.terminalVirtualPaymentSnapshots.get(channel);
3848
+ // A slow lookup must not overwrite a newer lookup or payment methods event.
3849
+ if (snapshot?.shopId !== shopId || snapshot.revision < revision) {
3850
+ this.terminalVirtualPaymentSnapshots.set(channel, {
3851
+ shopId,
3852
+ methods,
3853
+ revision
3854
+ });
3855
+ }
3856
+ };
3857
+ let methods;
3858
+ try {
3859
+ methods = await (0, _loadPaymentMethods.loadPaymentMethods)(this.request, {
3860
+ transport: 'remote',
3861
+ filterPaymentMethods: false
3862
+ });
3863
+ } catch (error) {
3864
+ if (channel === 'kiosk' && shopId === this.getVirtualPaymentShopId()) publish([]);
3865
+ throw error;
3851
3866
  }
3852
- const snapshot = this.posVirtualPaymentSnapshot;
3853
- // Slow reads must not overwrite a newer lookup or a payment methods sync event.
3854
- if (snapshot?.shopId !== shopId || snapshot.revision < revision) {
3855
- this.posVirtualPaymentSnapshot = {
3856
- shopId,
3857
- methods,
3858
- revision
3859
- };
3867
+ if (shopId !== this.getVirtualPaymentShopId()) {
3868
+ throw new Error('[Order] Payment methods belong to a previous shop');
3860
3869
  }
3861
- return this.getPosVirtualCurrencyPaymentMethod();
3870
+ publish(methods);
3871
+ return this.getTerminalVirtualCurrencyPaymentMethod(channel);
3862
3872
  }
3863
- async validatePosVirtualCurrencyCart(order) {
3864
- await this.refreshPosVirtualCurrencyPaymentMethod();
3865
- if (this.getTempOrder() !== order) {
3873
+ async validateTerminalVirtualCurrencyCart(order, channel) {
3874
+ await this.refreshTerminalVirtualCurrencyPaymentMethod(channel);
3875
+ if (this.getTempOrder() !== order || this.getVirtualCurrencyPaymentChannel() !== channel) {
3866
3876
  throw new Error('[Order] Cart intent belongs to a previous order or business');
3867
3877
  }
3868
3878
  }
@@ -4233,8 +4243,9 @@ class OrderModule extends _BaseModule.BaseModule {
4233
4243
  availabilityCommitGuard?.();
4234
4244
  const liveTempOrder = this.ensureTempOrder();
4235
4245
  const beforeCommit = this.createCartIntentCommitGuard('add_product', liveTempOrder);
4236
- if (this.requiresPosVirtualCurrencyPayment(product)) {
4237
- await this.validatePosVirtualCurrencyCart(liveTempOrder);
4246
+ const virtualPaymentChannel = this.getVirtualCurrencyPaymentChannel();
4247
+ if (virtualPaymentChannel && (0, _virtualSettlement.isVirtualSettlementProduct)(product)) {
4248
+ await this.validateTerminalVirtualCurrencyCart(liveTempOrder, virtualPaymentChannel);
4238
4249
  availabilityCommitGuard?.();
4239
4250
  }
4240
4251
  const mutation = this.beginCartMutation();
@@ -4550,10 +4561,11 @@ class OrderModule extends _BaseModule.BaseModule {
4550
4561
  if (!Array.isArray(items) || items.length === 0) return tempOrder.products;
4551
4562
  const beforeCommit = this.createCartIntentCommitGuard('add_product');
4552
4563
  const beforeAppend = mutation.commit ? undefined : beforeCommit;
4553
- if (items.some(({
4564
+ const virtualPaymentChannel = this.getVirtualCurrencyPaymentChannel();
4565
+ if (virtualPaymentChannel && items.some(({
4554
4566
  product
4555
- }) => product && this.requiresPosVirtualCurrencyPayment(product))) {
4556
- await this.validatePosVirtualCurrencyCart(this.ensureTempOrder());
4567
+ }) => product && (0, _virtualSettlement.isVirtualSettlementProduct)(product))) {
4568
+ await this.validateTerminalVirtualCurrencyCart(this.ensureTempOrder(), virtualPaymentChannel);
4557
4569
  }
4558
4570
  for (const item of items || []) {
4559
4571
  const {
@@ -5128,11 +5140,12 @@ class OrderModule extends _BaseModule.BaseModule {
5128
5140
  }
5129
5141
  }
5130
5142
  const beforeCommit = normalizedProduct.num > targetProduct.num ? this.createCartIntentCommitGuard('increase_quantity') : undefined;
5131
- if (beforeCommit && this.requiresPosVirtualCurrencyPayment(normalizedProduct)) {
5143
+ const virtualPaymentChannel = this.getVirtualCurrencyPaymentChannel();
5144
+ if (beforeCommit && virtualPaymentChannel && (0, _virtualSettlement.isVirtualSettlementProduct)(normalizedProduct)) {
5132
5145
  const liveOrder = this.ensureTempOrder();
5133
5146
  const products = (0, _lodashEs.cloneDeep)(liveOrder.products);
5134
5147
  const customerId = liveOrder.customer_id;
5135
- await this.validatePosVirtualCurrencyCart(liveOrder);
5148
+ await this.validateTerminalVirtualCurrencyCart(liveOrder, virtualPaymentChannel);
5136
5149
  if (liveOrder.customer_id !== customerId || !(0, _lodashEs.isEqual)(liveOrder.products, products)) {
5137
5150
  throw Object.assign(new Error('The cart changed. Please try again.'), {
5138
5151
  code: 'SALES_GUARD_REJECTED'
@@ -5572,6 +5585,7 @@ class OrderModule extends _BaseModule.BaseModule {
5572
5585
  summary: latestSummary,
5573
5586
  request_unique_idempotency_token: params?.request_unique_idempotency_token,
5574
5587
  includePaymentStatus: !isOnlineStorePlatform,
5588
+ enableMultiCurrencySettlement: this.isMultiCurrencySettlementEnabled(),
5575
5589
  enhance: enhancePayload
5576
5590
  });
5577
5591
  if (params?.syncMode) {
@@ -257,6 +257,7 @@ export declare function buildSubmitPayload(params: {
257
257
  summary?: OrderSummary | null;
258
258
  request_unique_idempotency_token?: string;
259
259
  includePaymentStatus?: boolean;
260
+ enableMultiCurrencySettlement?: boolean;
260
261
  enhance?: SubmitPayloadEnhancer;
261
262
  }): OrderSubmitPayload;
262
263
  export declare function mapPaymentItemToOrderPayment(paymentItem: OrderPaymentSource): OrderPaymentData;
@@ -1707,10 +1707,11 @@ function buildSubmitPayload(params) {
1707
1707
  now
1708
1708
  }) ?? payload;
1709
1709
  const submitSummary = enhancedPayload.summary ?? payload.summary;
1710
+ const retailKioskSettlement = params.enableMultiCurrencySettlement === true && (0, _platform.resolveTerminalVirtualCurrencyChannel)(enhancedPayload.platform, resolvedBusinessCode) === 'kiosk';
1710
1711
  return {
1711
1712
  ...enhancedPayload,
1712
1713
  summary: submitSummary,
1713
- ...((0, _platform.isPosTerminalPlatform)(enhancedPayload.platform) ? {
1714
+ ...((0, _platform.isPosTerminalPlatform)(enhancedPayload.platform) || retailKioskSettlement ? {
1714
1715
  product_tax_fee: virtualSettlementMode ? '0.00' : submitSummary?.tax_fee ?? '0.00'
1715
1716
  } : {})
1716
1717
  };
@@ -1,12 +1,13 @@
1
1
  import type { RequestPlugin } from '../../plugins/request';
2
2
  import type { PaymentMethod } from '../../modules/Payment/types';
3
+ import type { TerminalVirtualCurrencyChannel } from '../../utils/platform';
3
4
  type PaymentMethodsTransport = 'remote' | 'os-server';
4
5
  /** Shared read-only transport; customer hosts route the remote path under /h5. */
5
6
  export declare function loadPaymentMethods(request: RequestPlugin, options: {
6
7
  transport: PaymentMethodsTransport;
7
8
  filterPaymentMethods: boolean;
8
9
  }): Promise<PaymentMethod[]>;
9
- export declare function requirePosVirtualCurrencyPaymentMethod(methods: readonly PaymentMethod[], shopId?: string): PaymentMethod;
10
+ export declare function requireTerminalVirtualCurrencyPaymentMethod(methods: readonly PaymentMethod[], channel: TerminalVirtualCurrencyChannel, shopId?: string): PaymentMethod;
10
11
  /** Enrich a copy: never overwrite historical names or change payment amounts. */
11
12
  export declare function withPaymentMethodNames(order: Record<string, any>, methods: PaymentMethod[]): Record<string, any>;
12
13
  export {};
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.loadPaymentMethods = loadPaymentMethods;
7
- exports.requirePosVirtualCurrencyPaymentMethod = requirePosVirtualCurrencyPaymentMethod;
7
+ exports.requireTerminalVirtualCurrencyPaymentMethod = requireTerminalVirtualCurrencyPaymentMethod;
8
8
  exports.withPaymentMethodNames = withPaymentMethodNames;
9
9
  /** Shared read-only transport; customer hosts route the remote path under /h5. */
10
10
  async function loadPaymentMethods(request, options) {
@@ -20,16 +20,17 @@ async function loadPaymentMethods(request, options) {
20
20
  if (!Array.isArray(methods)) throw new Error('Payment methods are unavailable');
21
21
  return methods;
22
22
  }
23
- class PosVirtualCurrencyPaymentUnavailableError extends Error {
24
- code = 'POS_VIRTUAL_CURRENCY_PAYMENT_UNAVAILABLE';
25
- constructor() {
26
- super('Virtual currency payment is not enabled on this POS.');
27
- this.name = 'PosVirtualCurrencyPaymentUnavailableError';
23
+ class TerminalVirtualCurrencyPaymentUnavailableError extends Error {
24
+ code;
25
+ constructor(channel) {
26
+ super(channel === 'kiosk' ? 'Virtual currency payment is not enabled on this Kiosk.' : 'Virtual currency payment is not enabled on this POS.');
27
+ this.code = channel === 'kiosk' ? 'KIOSK_VIRTUAL_CURRENCY_PAYMENT_UNAVAILABLE' : 'POS_VIRTUAL_CURRENCY_PAYMENT_UNAVAILABLE';
28
+ this.name = channel === 'kiosk' ? 'KioskVirtualCurrencyPaymentUnavailableError' : 'PosVirtualCurrencyPaymentUnavailableError';
28
29
  }
29
30
  }
30
- function requirePosVirtualCurrencyPaymentMethod(methods, shopId) {
31
- const method = methods.find(candidate => candidate?.code === 'VIRTUALCURRENCY' && (!shopId || candidate.shop_id == null || String(candidate.shop_id) === shopId) && candidate.status === 1 && candidate.disable === 0 && Array.isArray(candidate.channel_application) && candidate.channel_application.includes('pos'));
32
- if (!method) throw new PosVirtualCurrencyPaymentUnavailableError();
31
+ function requireTerminalVirtualCurrencyPaymentMethod(methods, channel, shopId) {
32
+ const method = methods.find(candidate => candidate?.code === 'VIRTUALCURRENCY' && (channel === 'pos' || Boolean(shopId)) && (!shopId || candidate.shop_id == null || String(candidate.shop_id) === shopId) && candidate.status === 1 && candidate.disable === 0 && Array.isArray(candidate.channel_application) && candidate.channel_application.includes(channel));
33
+ if (!method) throw new TerminalVirtualCurrencyPaymentUnavailableError(channel);
33
34
  return method;
34
35
  }
35
36
 
@@ -246,6 +246,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
246
246
  private getPaymentNumberDevicePrefixSync;
247
247
  private getPaymentNumberDevicePrefixAsync;
248
248
  private isMultiCurrencySettlementEnabled;
249
+ private getTerminalVirtualCurrencyChannel;
249
250
  private isActiveVirtualSettlementOrder;
250
251
  private isHistoricalVirtualSettlementOrder;
251
252
  private syncAppDataToTempOrder;
@@ -503,7 +504,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
503
504
  getPaymentMethodsAsync(): Promise<PaymentMethod[]>;
504
505
  /** 同步读取初始化时缓存的支付方式列表。 */
505
506
  getPaymentMethods(): PaymentMethod[];
507
+ private checkTerminalVirtualCurrencyPaymentMethod;
506
508
  hasPosVirtualCurrencyPaymentMethod(): Promise<boolean>;
509
+ hasTerminalVirtualCurrencyPaymentMethod(): Promise<boolean>;
507
510
  private findCashPaymentMethod;
508
511
  private getPendingWalletPaymentAmount;
509
512
  /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
@@ -752,8 +752,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
752
752
  if (!effects || typeof effects.on !== 'function') return;
753
753
  this.paymentMethodsChangedUnsubscribe = effects.on(PAYMENT_METHODS_CHANGED_EVENT, async payload => {
754
754
  if (!Array.isArray(payload?.newMethods)) return;
755
- if (this.isMultiCurrencySettlementEnabled() && (0, _platform.isPosTerminalPlatform)(this.otherParams?.platform)) {
756
- this.store.order?.syncPosVirtualCurrencyPaymentMethods(payload.newMethods);
755
+ const channel = this.getTerminalVirtualCurrencyChannel();
756
+ if (channel) {
757
+ this.store.order?.syncTerminalVirtualCurrencyPaymentMethods(channel, payload.newMethods);
757
758
  }
758
759
  await this.getPaymentMethodsAsync();
759
760
  });
@@ -1645,6 +1646,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1645
1646
  isMultiCurrencySettlementEnabled() {
1646
1647
  return this.otherParams?.enableMultiCurrencySettlement === true;
1647
1648
  }
1649
+ getTerminalVirtualCurrencyChannel() {
1650
+ if (!this.isMultiCurrencySettlementEnabled()) return undefined;
1651
+ return (0, _platform.resolveTerminalVirtualCurrencyChannel)(this.otherParams?.platform, this.otherParams?.businessCode ?? this.otherParams?.business_code);
1652
+ }
1648
1653
  isActiveVirtualSettlementOrder(tempOrder) {
1649
1654
  return this.isMultiCurrencySettlementEnabled() && (0, _virtualSettlement.isVirtualSettlementOrder)(tempOrder);
1650
1655
  }
@@ -2840,7 +2845,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2840
2845
  currencyFormat: String(tempOrder?.currency_format || 'symbol_first')
2841
2846
  };
2842
2847
  }
2843
- async buildVirtualSettlementSubmitData(settlement, posPaymentMethod) {
2848
+ async buildVirtualSettlementSubmitData(settlement, terminalPaymentMethod) {
2844
2849
  if (!settlement || !this.store.order) return null;
2845
2850
  const tempOrder = this.store.order.getTempOrder();
2846
2851
  const {
@@ -2851,7 +2856,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2851
2856
  });
2852
2857
  const amount = new _decimal.default(summary?.total_amount || 0).toDecimalPlaces(2);
2853
2858
  const customerId = Number(tempOrder?.customer_id || 0);
2854
- if (posPaymentMethod && amount.gt(0) && !(customerId > 1)) {
2859
+ if (terminalPaymentMethod && amount.gt(0) && !(customerId > 1)) {
2855
2860
  throw new _virtualSettlement.VirtualCurrencyCustomerRequiredError();
2856
2861
  }
2857
2862
  if (amount.gt(0) && customerId > 0 && customerId !== 1) {
@@ -2878,14 +2883,15 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2878
2883
  }
2879
2884
  const amountText = amount.toFixed(2);
2880
2885
  const paymentNumber = `LOCAL_${(0, _utils.createUuidV4)()}`;
2886
+ const metadata = {
2887
+ unique_payment_number: (0, _utils.createUuidV4)()
2888
+ };
2881
2889
  let payment;
2882
- if (!posPaymentMethod && this.store.order.isOnlineStorePlatform()) {
2890
+ if (!terminalPaymentMethod && this.store.order.isOnlineStorePlatform()) {
2883
2891
  payment = {
2884
2892
  payment_number: paymentNumber,
2885
2893
  amount: amount.toNumber(),
2886
- metadata: {
2887
- unique_payment_number: (0, _utils.createUuidV4)()
2888
- },
2894
+ metadata,
2889
2895
  tag: asset.tag,
2890
2896
  voucher_id: asset.id,
2891
2897
  wallet_pass_usage_unit: {
@@ -2895,7 +2901,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2895
2901
  wallet_pass_use_value: amountText
2896
2902
  };
2897
2903
  } else {
2898
- const paymentMethod = posPaymentMethod ?? (await this.getPaymentMethodsAsync()).find(method => String(method.code || '').toUpperCase() === 'PRODUCTVOUCHER');
2904
+ const paymentMethod = terminalPaymentMethod ?? (await this.getPaymentMethodsAsync()).find(method => String(method.code || '').toUpperCase() === 'PRODUCTVOUCHER');
2899
2905
  if (!paymentMethod) {
2900
2906
  throw new Error('PRODUCTVOUCHER payment method is unavailable.');
2901
2907
  }
@@ -2915,7 +2921,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2915
2921
  points: 1
2916
2922
  },
2917
2923
  wallet_pass_use_value: amountText,
2918
- metadata: {}
2924
+ metadata
2919
2925
  };
2920
2926
  }
2921
2927
  return {
@@ -2943,16 +2949,18 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2943
2949
  const virtualOrderData = this.buildVirtualSettlementOrderData();
2944
2950
  const checkoutCustomerId = checkoutOrder?.customer_id;
2945
2951
  const checkoutSettlementKey = (0, _virtualSettlement.getTempOrderSettlementKey)(checkoutOrder);
2946
- const posPaymentMethod = virtualOrderData && (0, _platform.isPosTerminalPlatform)(this.otherParams?.platform) ? this.store.order.getPosVirtualCurrencyPaymentMethod(this.getPaymentMethods()) : undefined;
2952
+ const virtualPaymentChannel = virtualOrderData ? this.getTerminalVirtualCurrencyChannel() : undefined;
2953
+ const terminalPaymentMethod = virtualPaymentChannel ? this.store.order.getTerminalVirtualCurrencyPaymentMethod(virtualPaymentChannel, virtualPaymentChannel === 'pos' ? this.getPaymentMethods() : undefined) : undefined;
2947
2954
  const readCheckoutLines = () => checkoutOrder?.products.map(product => [String(product.product_id), String(product.product_variant_id ?? 0), Number(product.num ?? 1)]);
2948
- const checkoutLines = posPaymentMethod && !isDeferredPayment ? readCheckoutLines() : undefined;
2955
+ const checkoutLines = terminalPaymentMethod && !isDeferredPayment ? readCheckoutLines() : undefined;
2949
2956
  const assertCheckoutCartUnchanged = () => {
2950
- if (posPaymentMethod && (this.store.order?.getTempOrder() !== checkoutOrder || checkoutOrder?.customer_id !== checkoutCustomerId || (0, _virtualSettlement.getTempOrderSettlementKey)(checkoutOrder) !== checkoutSettlementKey || checkoutLines && !(0, _lodashEs.isEqual)(readCheckoutLines(), checkoutLines))) {
2957
+ if (terminalPaymentMethod && (this.store.order?.getTempOrder() !== checkoutOrder || checkoutOrder?.customer_id !== checkoutCustomerId || (0, _virtualSettlement.getTempOrderSettlementKey)(checkoutOrder) !== checkoutSettlementKey || checkoutLines && !(0, _lodashEs.isEqual)(readCheckoutLines(), checkoutLines))) {
2951
2958
  throw (0, _inventory.salesGuardError)('The cart changed. Please try again.');
2952
2959
  }
2953
2960
  };
2954
- const virtualPaymentSettlement = isDeferredPayment ? null : await this.buildVirtualSettlementSubmitData(virtualOrderData, posPaymentMethod);
2961
+ const virtualPaymentSettlement = isDeferredPayment ? null : await this.buildVirtualSettlementSubmitData(virtualOrderData, terminalPaymentMethod);
2955
2962
  assertCheckoutCartUnchanged();
2963
+ const submitsTerminalVirtualPayment = Boolean(terminalPaymentMethod && virtualPaymentSettlement?.payments.length);
2956
2964
  const virtualSettlement = isDeferredPayment ? virtualOrderData : virtualPaymentSettlement;
2957
2965
  // this.store.order.persistTempOrder();
2958
2966
  const inferredPaymentStatus = isDeferredPayment ? undefined : this.getSubmitPaymentStatus(params?.paymentStatus);
@@ -2992,9 +3000,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2992
3000
  } : configuredEnhancePayload;
2993
3001
  const submitParams = {
2994
3002
  cacheId: this.cacheId,
2995
- platform: this.otherParams?.platform,
3003
+ platform: virtualPaymentChannel === 'kiosk' ? 'kiosk' : this.otherParams?.platform,
2996
3004
  businessCode: this.otherParams?.businessCode || this.otherParams?.business_code,
2997
- channel: this.getSubmitOrderSalesChannel(),
3005
+ channel: virtualPaymentChannel === 'kiosk' ? 'kiosk' : this.getSubmitOrderSalesChannel(),
2998
3006
  type: this.otherParams?.type,
2999
3007
  request_unique_idempotency_token: this.store.order.generateIdempotencyToken(),
3000
3008
  ...(isDeferredPayment ? {
@@ -3018,11 +3026,17 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3018
3026
  ...(virtualSettlement ? {
3019
3027
  enhancePayload: (payload, ctx) => {
3020
3028
  const callerPayload = enhancePayload ? enhancePayload(payload, ctx) : payload;
3021
- if (posPaymentMethod && virtualPaymentSettlement) {
3029
+ if (terminalPaymentMethod && virtualPaymentSettlement) {
3022
3030
  assertCheckoutCartUnchanged();
3031
+ if (virtualPaymentChannel === 'kiosk') {
3032
+ const currentMethod = this.store.order?.getTerminalVirtualCurrencyPaymentMethod('kiosk');
3033
+ if (this.getTerminalVirtualCurrencyChannel() !== 'kiosk' || currentMethod?.id !== terminalPaymentMethod.id) {
3034
+ throw (0, _inventory.salesGuardError)('The payment method changed. Please try again.');
3035
+ }
3036
+ }
3023
3037
  const summary = callerPayload.summary ?? payload.summary;
3024
3038
  const orderAmount = _decimal.default.max(0, summary?.total_amount ?? 0).toDecimalPlaces(2);
3025
- const payment = callerPayload.payments?.find(item => item.code === posPaymentMethod.code);
3039
+ const payment = callerPayload.payments?.find(item => item.code === terminalPaymentMethod.code);
3026
3040
  if (!orderAmount.eq(payment?.amount ?? 0)) {
3027
3041
  throw (0, _inventory.salesGuardError)('The cart changed. Please try again.');
3028
3042
  }
@@ -3030,6 +3044,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3030
3044
  const currencySettlementConfig = callerPayload.metadata?.currency_settlement_config || {};
3031
3045
  return {
3032
3046
  ...callerPayload,
3047
+ ...(submitsTerminalVirtualPayment ? {
3048
+ payment_status: 'paid'
3049
+ } : {}),
3033
3050
  metadata: {
3034
3051
  ...(callerPayload.metadata || {}),
3035
3052
  currency_settlement_config: {
@@ -3048,8 +3065,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3048
3065
  enhancePayload
3049
3066
  } : {})
3050
3067
  };
3051
- const waitForVirtualPayment = Boolean(posPaymentMethod && virtualPaymentSettlement?.payments.length);
3052
- return !waitForVirtualPayment && this.shouldUseCheckoutSyncTask() ? this.store.order.submitTempOrder(submitParams) : this.store.order.submitTempOrderAsync(submitParams);
3068
+ return !submitsTerminalVirtualPayment && this.shouldUseCheckoutSyncTask() ? this.store.order.submitTempOrder(submitParams) : this.store.order.submitTempOrderAsync(submitParams);
3053
3069
  }
3054
3070
  pendingLocalEftposFinalizations = new Map();
3055
3071
  async finalizeLocalEftposPayment(params) {
@@ -3949,15 +3965,22 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3949
3965
  getPaymentMethods() {
3950
3966
  return [...this.paymentMethodsCache];
3951
3967
  }
3952
- async hasPosVirtualCurrencyPaymentMethod() {
3968
+ async checkTerminalVirtualCurrencyPaymentMethod(channel) {
3953
3969
  if (!this.store.order) return false;
3954
3970
  try {
3955
- await this.store.order.refreshPosVirtualCurrencyPaymentMethod();
3971
+ await this.store.order.refreshTerminalVirtualCurrencyPaymentMethod(channel);
3956
3972
  return true;
3957
3973
  } catch {
3958
3974
  return false;
3959
3975
  }
3960
3976
  }
3977
+ hasPosVirtualCurrencyPaymentMethod() {
3978
+ return this.checkTerminalVirtualCurrencyPaymentMethod('pos');
3979
+ }
3980
+ async hasTerminalVirtualCurrencyPaymentMethod() {
3981
+ const channel = this.getTerminalVirtualCurrencyChannel();
3982
+ return channel ? this.checkTerminalVirtualCurrencyPaymentMethod(channel) : false;
3983
+ }
3961
3984
  findCashPaymentMethod(paymentMethods, paymentMethodId) {
3962
3985
  return paymentMethods.find(method => {
3963
3986
  if (method?.enabled === false || method?.enable === false) return false;
@@ -85,7 +85,9 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
85
85
  * 让现有 setActiveCustomer / getActiveCustomer 调用方零成本拿到详情态客户。
86
86
  */
87
87
  loadSalesDetail(orderIdOrParams: number | string | LoadSalesDetailParams): Promise<ISalesDetail>;
88
- scanPromotionCode(code: string, customerId?: number): Promise<BaseSalesScanCodeResult>;
88
+ scanPromotionCode(code: string, customerId?: number, options?: {
89
+ productVouchersOnly?: boolean;
90
+ }): Promise<BaseSalesScanCodeResult>;
89
91
  private hydrateOrderCustomerFromScanDiscounts;
90
92
  private getDiscountCustomerId;
91
93
  resolveCustomerById(customerId: string | number): Promise<ICustomer | null>;
@@ -474,7 +474,10 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
474
474
  }
475
475
  return sales;
476
476
  }
477
- async scanPromotionCode(code, customerId) {
477
+ async scanPromotionCode(code, customerId, options) {
478
+ if (options?.productVouchersOnly && (customerId === 0 || customerId === 1)) {
479
+ return super.scanPromotionCode(code, customerId, options);
480
+ }
478
481
  if (!this.store.order) throw new Error('order 模块未初始化');
479
482
  const raw = await this.store.order.scanCode(code, customerId);
480
483
  const scannedList = raw.scannedDiscountList || [];
@@ -4,5 +4,5 @@ import type { GlobalScanFormattedResult } from './formatGlobalScan';
4
4
  export interface ProductVoucherCollectionScanHost extends GlobalScanApplyHost {
5
5
  loadCustomerDiscounts(): Promise<Record<string, any>[]>;
6
6
  }
7
- /** Resolve the scanned account, then collect all of that customer's vouchers. */
7
+ /** Collect vouchers by member account or by scan code for a walk-in. */
8
8
  export declare function applyProductVoucherCollectionScan(host: ProductVoucherCollectionScanHost, formatted: GlobalScanFormattedResult, bridge: GlobalScanHostBridge): Promise<GlobalScanHandleResult>;
@@ -4,25 +4,64 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.applyProductVoucherCollectionScan = applyProductVoucherCollectionScan;
7
+ var _cartView = require("../cartView");
7
8
  var _applyGlobalScan = require("./applyGlobalScan");
8
- /** Resolve the scanned account, then collect all of that customer's vouchers. */
9
+ /** Collect vouchers by member account or by scan code for a walk-in. */
9
10
  async function applyProductVoucherCollectionScan(host, formatted, bridge) {
10
11
  const assertCurrent = () => {
11
12
  if (bridge.isCurrent?.() === false) {
12
13
  throw new DOMException('Scan session ended', 'AbortError');
13
14
  }
14
15
  };
16
+ assertCurrent();
15
17
  const isPass = formatted.searchType === 'walletPass';
16
- // Order numbers and wristbands resolve through batch-search. Their returned
17
- // passes identify the customer; they are not the collection's voucher list.
18
+ const customerId = formatted.customerId ?? formatted.data?.id ?? formatted.data?.customer_id;
19
+ if (isPass && customerId != null && customerId !== '' && (0, _cartView.isWalkInCustomer)({
20
+ id: customerId
21
+ })) {
22
+ if (formatted.isWalletPassUnavailableAtStore) {
23
+ return {
24
+ status: 'failed',
25
+ reason: 'invalid_data'
26
+ };
27
+ }
28
+ if (!bridge.applyPromotionCode) return {
29
+ status: 'failed',
30
+ reason: 'no_bridge'
31
+ };
32
+ const promotion = await bridge.applyPromotionCode(formatted.scanCode, Number(customerId), {
33
+ productVouchersOnly: true,
34
+ suppressFailureNotification: true
35
+ });
36
+ assertCurrent();
37
+ if (!Array.isArray(promotion.scannedDiscountList)) {
38
+ return {
39
+ status: 'failed',
40
+ reason: 'entry_resolution_failed'
41
+ };
42
+ }
43
+ const redemption = {
44
+ source: 'scan',
45
+ vouchers: promotion.scannedDiscountList
46
+ };
47
+ return promotion.isAccepted ?? promotion.isAvailable ? {
48
+ status: 'success',
49
+ kind: 'promotion',
50
+ redemption
51
+ } : {
52
+ status: 'failed',
53
+ reason: 'not_found',
54
+ redemption
55
+ };
56
+ }
57
+
18
58
  // Resolve source-shop IDs before reusing the wallet customer-binding flow.
19
59
  const customerScan = isPass ? {
20
60
  ...formatted,
21
61
  searchType: 'wallet',
22
- customerId: formatted.customerId ?? formatted.data?.id ?? formatted.data?.customer_id,
62
+ customerId,
23
63
  isCrossShopWallet: true
24
64
  } : formatted;
25
- assertCurrent();
26
65
  const result = await (0, _applyGlobalScan.applyGlobalScan)({
27
66
  ...host,
28
67
  setOrderCustomer: customer => {
@@ -3,6 +3,8 @@
3
3
  */
4
4
  export declare function normalizeRuntimePlatform(platform: unknown): string;
5
5
  export declare function isPosTerminalPlatform(platform: unknown): boolean;
6
+ export type TerminalVirtualCurrencyChannel = 'pos' | 'kiosk';
7
+ export declare function resolveTerminalVirtualCurrencyChannel(platform: unknown, businessCode: unknown): TerminalVirtualCurrencyChannel | undefined;
6
8
  /**
7
9
  * PC and H5 are authenticated-customer clients rather than staff terminals.
8
10
  */
@@ -7,6 +7,7 @@ exports.isCustomerUserPlatform = isCustomerUserPlatform;
7
7
  exports.isPosTerminalPlatform = isPosTerminalPlatform;
8
8
  exports.isSelfServicePlatform = isSelfServicePlatform;
9
9
  exports.normalizeRuntimePlatform = normalizeRuntimePlatform;
10
+ exports.resolveTerminalVirtualCurrencyChannel = resolveTerminalVirtualCurrencyChannel;
10
11
  const CUSTOMER_USER_PLATFORMS = new Set(['pc', 'h5']);
11
12
  const SELF_SERVICE_PLATFORMS = new Set(['kiosk', 'vending']);
12
13
 
@@ -20,6 +21,10 @@ function isPosTerminalPlatform(platform) {
20
21
  const normalized = normalizeRuntimePlatform(platform);
21
22
  return normalized === 'pos' || normalized === 'webpos';
22
23
  }
24
+ function resolveTerminalVirtualCurrencyChannel(platform, businessCode) {
25
+ if (isPosTerminalPlatform(platform)) return 'pos';
26
+ if (normalizeRuntimePlatform(platform) === 'kiosk' && businessCode === 'retail') return 'kiosk';
27
+ }
23
28
 
24
29
  /**
25
30
  * PC and H5 are authenticated-customer clients rather than staff terminals.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.233",
4
+ "version": "2.3.234",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",