@pisell/private-materials 6.12.157 → 6.12.158

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 (34) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/meta.js +1 -1
  5. package/build/lowcode/preview.js +1 -1
  6. package/build/lowcode/render/default/view.js +6 -6
  7. package/build/lowcode/view.js +6 -6
  8. package/es/components/checkout/PaymentModal.js +552 -392
  9. package/es/components/checkout/components/PaymentOptionsModule/PaymentMethodItem.js +16 -8
  10. package/es/components/checkout/components/PaymentOptionsModule/index.js +2 -1
  11. package/es/components/checkout/components/SearchAndClientModule/index.js +12 -4
  12. package/es/components/checkout/hooks/useCheckoutPaymentScanActivity.js +80 -0
  13. package/es/components/checkout/hooks/useSharedWalletPass.js +54 -7
  14. package/es/components/checkout/hooks/useWalletPass.js +45 -7
  15. package/es/components/checkout/locales.js +15 -0
  16. package/es/components/checkout/paymentRuntime/PaymentMethodRuntime.js +35 -6
  17. package/es/components/pay/toB/components/EFTPOS/index.js +44 -7
  18. package/es/components/pay/toB/components/MX51/index.js +11 -1
  19. package/es/components/pay/toB/paymentMethods/index.js +31 -17
  20. package/es/plus/salesSdk/demo/hosts/legacyOpenProductDetail.js +1 -7
  21. package/lib/components/checkout/PaymentModal.js +552 -392
  22. package/lib/components/checkout/components/PaymentOptionsModule/PaymentMethodItem.js +16 -8
  23. package/lib/components/checkout/components/PaymentOptionsModule/index.js +2 -1
  24. package/lib/components/checkout/components/SearchAndClientModule/index.js +12 -4
  25. package/lib/components/checkout/hooks/useCheckoutPaymentScanActivity.js +81 -0
  26. package/lib/components/checkout/hooks/useSharedWalletPass.js +54 -7
  27. package/lib/components/checkout/hooks/useWalletPass.js +45 -7
  28. package/lib/components/checkout/locales.js +15 -0
  29. package/lib/components/checkout/paymentRuntime/PaymentMethodRuntime.js +35 -6
  30. package/lib/components/pay/toB/components/EFTPOS/index.js +44 -7
  31. package/lib/components/pay/toB/components/MX51/index.js +11 -1
  32. package/lib/components/pay/toB/paymentMethods/index.js +31 -17
  33. package/lib/plus/salesSdk/demo/hosts/legacyOpenProductDetail.js +1 -7
  34. package/package.json +3 -3
@@ -13,7 +13,7 @@ let classnames = require("classnames");
13
13
  classnames = require_runtime.__toESM(classnames);
14
14
  require("./index.less");
15
15
  //#region src/components/checkout/components/PaymentOptionsModule/PaymentMethodItem.tsx
16
- const PaymentMethodItem = ({ method, amountSymbol, customAmount, disabled = false, onClick, getText, size = "default", surchargeDisplay, directCustomPayment = false, currentBaseSales }) => {
16
+ const PaymentMethodItem = ({ method, amountSymbol, customAmount, disabled = false, onClick, getText, size = "default", surchargeDisplay, directCustomPayment = false, beginKioskPaymentActivity, currentBaseSales }) => {
17
17
  var _context$appHelper;
18
18
  const context = require_useEngineContext.default();
19
19
  const { getData, getApp } = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
@@ -72,17 +72,25 @@ const PaymentMethodItem = ({ method, amountSymbol, customAmount, disabled = fals
72
72
  var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
73
73
  if (isEftpos) return;
74
74
  if (paymentChannel === "kiosk") {
75
+ const finishPaymentActivity = beginKioskPaymentActivity === null || beginKioskPaymentActivity === void 0 ? void 0 : beginKioskPaymentActivity(`authorization:${method.code || "unknown"}`);
76
+ if (beginKioskPaymentActivity && !finishPaymentActivity) return;
75
77
  try {
76
78
  var _currentBaseSales$get, _window;
77
79
  const otherParams = (yield Promise.resolve(currentBaseSales === null || currentBaseSales === void 0 || (_currentBaseSales$get = currentBaseSales.getOtherParams) === null || _currentBaseSales$get === void 0 ? void 0 : _currentBaseSales$get.call(currentBaseSales))) || (currentBaseSales === null || currentBaseSales === void 0 ? void 0 : currentBaseSales.otherParams) || {};
78
- (_window = window) === null || _window === void 0 || (_window = _window.app) === null || _window === void 0 || _window.applicationManager.get("global").runFunction("authorizeAction", { params: {
79
- action: "pay",
80
- business_code: otherParams.businessCode || otherParams.business_code,
81
- paymentMethodCode: method.code,
82
- paymentMethodType: method.type,
83
- amount: customAmount
84
- } });
80
+ if (finishPaymentActivity && !finishPaymentActivity.isActive()) return;
81
+ const authorizationResult = yield Promise.resolve((_window = window) === null || _window === void 0 || (_window = _window.app) === null || _window === void 0 ? void 0 : _window.applicationManager.get("global").runFunction("authorizeAction", {
82
+ onClose: finishPaymentActivity,
83
+ params: {
84
+ action: "pay",
85
+ business_code: otherParams.businessCode || otherParams.business_code,
86
+ paymentMethodCode: method.code,
87
+ paymentMethodType: method.type,
88
+ amount: customAmount
89
+ }
90
+ }));
91
+ if (String((authorizationResult === null || authorizationResult === void 0 ? void 0 : authorizationResult.status) || "").toLowerCase() !== "success") finishPaymentActivity === null || finishPaymentActivity === void 0 || finishPaymentActivity();
85
92
  } catch (error) {
93
+ finishPaymentActivity === null || finishPaymentActivity === void 0 || finishPaymentActivity();
86
94
  console.error("[PaymentMethodItem] request payment authorization failed", error);
87
95
  }
88
96
  return;
@@ -13,7 +13,7 @@ classnames = require_runtime.__toESM(classnames);
13
13
  let ahooks = require("ahooks");
14
14
  require("./index.less");
15
15
  //#region src/components/checkout/components/PaymentOptionsModule/index.tsx
16
- function PaymentOptionsModule({ amountSymbol, orderInfo, onClick, paymentMethods = [], customAmount, title, disabled = false, showCashPayment = false, channel = "pos", columnCount, sciSurchargeDisplayMap = {}, directCustomPayment = false, isModalOpen = false, paymentMethodsReady = false, autoTriggerSinglePaymentOption = false, currentBaseSales }) {
16
+ function PaymentOptionsModule({ amountSymbol, orderInfo, onClick, paymentMethods = [], customAmount, title, disabled = false, showCashPayment = false, channel = "pos", columnCount, sciSurchargeDisplayMap = {}, directCustomPayment = false, isModalOpen = false, paymentMethodsReady = false, autoTriggerSinglePaymentOption = false, beginKioskPaymentActivity, currentBaseSales }) {
17
17
  var _context$appHelper, _context$appHelper$ge, _context$appHelper$ge2, _context$appHelper$ut;
18
18
  const context = require_useEngineContext.default();
19
19
  _pisell_utils.locales.init(require_locales.default, ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getApp) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.call(_context$appHelper)) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.locales) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge2 = _context$appHelper$ge.getLocale) === null || _context$appHelper$ge2 === void 0 ? void 0 : _context$appHelper$ge2.call(_context$appHelper$ge)) || ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut = _context$appHelper$ut.storage) === null || _context$appHelper$ut === void 0 ? void 0 : _context$appHelper$ut.get("umi_locale")) || "en");
@@ -89,6 +89,7 @@ function PaymentOptionsModule({ amountSymbol, orderInfo, onClick, paymentMethods
89
89
  getText,
90
90
  surchargeDisplay: sciSurchargeDisplayMap[String(method.id)],
91
91
  directCustomPayment,
92
+ beginKioskPaymentActivity,
92
93
  currentBaseSales
93
94
  })))));
94
95
  }
@@ -73,7 +73,7 @@ function extractContactsInfo(customer) {
73
73
  }
74
74
  const SearchAndClientModule = (props) => {
75
75
  var _context$appHelper2, _baseSales$getBooking, _baseSales$getBooking2, _bookingConfig$config, _context$appHelper4;
76
- const { disabledSwitch, clientInfo, onSearch, onClientChange, baseSales: propBaseSales, baseSalesModuleName, enableScanner = true, showCustomerSelect = true } = props;
76
+ const { disabledSwitch, clientInfo, onSearch, beginScanActivity, onClientChange, baseSales: propBaseSales, baseSalesModuleName, enableScanner = true, showCustomerSelect = true } = props;
77
77
  const [loading, setLoading] = (0, react.useState)(false);
78
78
  const [customerLoading, setCustomerLoading] = (0, react.useState)(false);
79
79
  const [customerLoadingMore, setCustomerLoadingMore] = (0, react.useState)(false);
@@ -113,9 +113,15 @@ const SearchAndClientModule = (props) => {
113
113
  const handleFindSearch = (0, react.useCallback)(function() {
114
114
  var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (keyword) {
115
115
  if (!(keyword === null || keyword === void 0 ? void 0 : keyword.trim())) return;
116
+ const finishScanActivity = beginScanActivity === null || beginScanActivity === void 0 ? void 0 : beginScanActivity();
117
+ if (beginScanActivity && !finishScanActivity) {
118
+ var _findRef$current;
119
+ (_findRef$current = findRef.current) === null || _findRef$current === void 0 || _findRef$current.setKeyword("");
120
+ return;
121
+ }
116
122
  setLoading(true);
117
123
  try {
118
- var _findRef$current;
124
+ var _findRef$current2;
119
125
  const res = yield onSearch === null || onSearch === void 0 ? void 0 : onSearch(keyword);
120
126
  const sharedAsset = res === null || res === void 0 ? void 0 : res.asset;
121
127
  if (!(Boolean(sharedAsset) || (Array.isArray(res === null || res === void 0 ? void 0 : res.data) ? res.data.length > 0 : Boolean(res === null || res === void 0 ? void 0 : res.data)))) {
@@ -137,11 +143,12 @@ const SearchAndClientModule = (props) => {
137
143
  return;
138
144
  }
139
145
  const _customer = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, customer), {}, { latest_wallet_detail: rest });
140
- (_clientSelectorRef$cu = clientSelectorRef.current) === null || _clientSelectorRef$cu === void 0 || (_clientSelectorRef$cu2 = _clientSelectorRef$cu.handleSetClient) === null || _clientSelectorRef$cu2 === void 0 || _clientSelectorRef$cu2.call(_clientSelectorRef$cu, _customer, { sameClientTip: _pisell_utils.locales.getText("pisell2.checkout.client-card.tip.same-client") });
146
+ yield (_clientSelectorRef$cu = clientSelectorRef.current) === null || _clientSelectorRef$cu === void 0 || (_clientSelectorRef$cu2 = _clientSelectorRef$cu.handleSetClient) === null || _clientSelectorRef$cu2 === void 0 ? void 0 : _clientSelectorRef$cu2.call(_clientSelectorRef$cu, _customer, { sameClientTip: _pisell_utils.locales.getText("pisell2.checkout.client-card.tip.same-client") });
141
147
  }
142
- (_findRef$current = findRef.current) === null || _findRef$current === void 0 || _findRef$current.setKeyword("");
148
+ (_findRef$current2 = findRef.current) === null || _findRef$current2 === void 0 || _findRef$current2.setKeyword("");
143
149
  } catch (error) {} finally {
144
150
  setLoading(false);
151
+ finishScanActivity === null || finishScanActivity === void 0 || finishScanActivity();
145
152
  }
146
153
  });
147
154
  return function(_x) {
@@ -149,6 +156,7 @@ const SearchAndClientModule = (props) => {
149
156
  };
150
157
  }(), [
151
158
  Toast,
159
+ beginScanActivity,
152
160
  disabledSwitch,
153
161
  onSearch
154
162
  ]);
@@ -0,0 +1,81 @@
1
+ require("../../../_virtual/_rolldown/runtime.js");
2
+ let react = require("react");
3
+ let ahooks = require("ahooks");
4
+ //#region src/components/checkout/hooks/useCheckoutPaymentScanActivity.ts
5
+ const NOOP_RELEASE = () => void 0;
6
+ /**
7
+ * Checkout 内部的支付/扫码双向活动锁。
8
+ *
9
+ * 同步 ref 用于事件回调的竞态判断,React state 只用于驱动禁用态。
10
+ * 同一时刻只允许一个活动成功占锁,避免扫码和支付在 React rerender 前同时进入。
11
+ */
12
+ function useCheckoutPaymentScanActivity(enabled) {
13
+ const activeActivityRef = (0, react.useRef)();
14
+ const mountedRef = (0, react.useRef)(true);
15
+ const [isPaymentProcessing, setIsPaymentProcessing] = (0, react.useState)(false);
16
+ const [isScanProcessing, setIsScanProcessing] = (0, react.useState)(false);
17
+ const tryBeginActivity = (0, ahooks.useMemoizedFn)((type) => {
18
+ if (!enabled) return NOOP_RELEASE;
19
+ if (activeActivityRef.current) return null;
20
+ const token = Symbol(type);
21
+ activeActivityRef.current = {
22
+ token,
23
+ type
24
+ };
25
+ if (mountedRef.current) {
26
+ setIsPaymentProcessing(type === "payment");
27
+ setIsScanProcessing(type === "scan");
28
+ }
29
+ let released = false;
30
+ return () => {
31
+ var _activeActivityRef$cu;
32
+ if (released) return;
33
+ released = true;
34
+ if (((_activeActivityRef$cu = activeActivityRef.current) === null || _activeActivityRef$cu === void 0 ? void 0 : _activeActivityRef$cu.token) !== token) return;
35
+ activeActivityRef.current = void 0;
36
+ if (mountedRef.current) {
37
+ setIsPaymentProcessing(false);
38
+ setIsScanProcessing(false);
39
+ }
40
+ };
41
+ });
42
+ const tryBeginPayment = (0, ahooks.useMemoizedFn)(() => tryBeginActivity("payment"));
43
+ const tryBeginScan = (0, ahooks.useMemoizedFn)(() => tryBeginActivity("scan"));
44
+ const getIsPaymentProcessing = (0, ahooks.useMemoizedFn)(() => {
45
+ var _activeActivityRef$cu2;
46
+ return enabled && ((_activeActivityRef$cu2 = activeActivityRef.current) === null || _activeActivityRef$cu2 === void 0 ? void 0 : _activeActivityRef$cu2.type) === "payment";
47
+ });
48
+ const getIsScanProcessing = (0, ahooks.useMemoizedFn)(() => {
49
+ var _activeActivityRef$cu3;
50
+ return enabled && ((_activeActivityRef$cu3 = activeActivityRef.current) === null || _activeActivityRef$cu3 === void 0 ? void 0 : _activeActivityRef$cu3.type) === "scan";
51
+ });
52
+ (0, react.useEffect)(() => {
53
+ mountedRef.current = true;
54
+ return () => {
55
+ mountedRef.current = false;
56
+ };
57
+ }, []);
58
+ (0, react.useEffect)(() => {
59
+ if (enabled) return;
60
+ activeActivityRef.current = void 0;
61
+ setIsPaymentProcessing(false);
62
+ setIsScanProcessing(false);
63
+ }, [enabled]);
64
+ return (0, react.useMemo)(() => ({
65
+ tryBeginPayment,
66
+ tryBeginScan,
67
+ getIsPaymentProcessing,
68
+ getIsScanProcessing,
69
+ isPaymentProcessing,
70
+ isScanProcessing
71
+ }), [
72
+ tryBeginPayment,
73
+ tryBeginScan,
74
+ getIsPaymentProcessing,
75
+ getIsScanProcessing,
76
+ isPaymentProcessing,
77
+ isScanProcessing
78
+ ]);
79
+ }
80
+ //#endregion
81
+ exports.default = useCheckoutPaymentScanActivity;
@@ -65,6 +65,8 @@ function useSharedWalletPass(props) {
65
65
  const [loadingAction, setLoadingAction] = (0, react.useState)(false);
66
66
  const deferWalletStateRef = (0, react.useRef)(false);
67
67
  const deferredWalletStateRef = (0, react.useRef)(null);
68
+ const pendingSearchApplyRef = (0, react.useRef)(null);
69
+ const pendingSearchApplyAttachedRef = (0, react.useRef)(false);
68
70
  (0, react.useEffect)(() => {
69
71
  var _baseSales$getWalletA2, _baseSales$getDiscoun2;
70
72
  const current = baseSales === null || baseSales === void 0 || (_baseSales$getWalletA2 = baseSales.getWalletAssetsState) === null || _baseSales$getWalletA2 === void 0 ? void 0 : _baseSales$getWalletA2.call(baseSales);
@@ -95,8 +97,35 @@ function useSharedWalletPass(props) {
95
97
  };
96
98
  }, [baseSales]);
97
99
  (0, react.useEffect)(() => {
98
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(toSelection(state));
100
+ let notification;
101
+ try {
102
+ notification = onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(toSelection(state));
103
+ } catch (error) {
104
+ var _pendingSearchApplyRe;
105
+ (_pendingSearchApplyRe = pendingSearchApplyRef.current) === null || _pendingSearchApplyRe === void 0 || _pendingSearchApplyRe.call(pendingSearchApplyRef);
106
+ pendingSearchApplyRef.current = null;
107
+ pendingSearchApplyAttachedRef.current = false;
108
+ throw error;
109
+ }
110
+ const resolvePendingSearch = pendingSearchApplyRef.current;
111
+ if (resolvePendingSearch && !pendingSearchApplyAttachedRef.current) {
112
+ pendingSearchApplyAttachedRef.current = true;
113
+ const finishPendingSearch = () => {
114
+ if (pendingSearchApplyRef.current === resolvePendingSearch) {
115
+ pendingSearchApplyRef.current = null;
116
+ pendingSearchApplyAttachedRef.current = false;
117
+ }
118
+ resolvePendingSearch();
119
+ };
120
+ Promise.resolve(notification).then(finishPendingSearch, finishPendingSearch);
121
+ }
99
122
  }, [onSelectChange, state.revision]);
123
+ (0, react.useEffect)(() => () => {
124
+ var _pendingSearchApplyRe2;
125
+ (_pendingSearchApplyRe2 = pendingSearchApplyRef.current) === null || _pendingSearchApplyRe2 === void 0 || _pendingSearchApplyRe2.call(pendingSearchApplyRef);
126
+ pendingSearchApplyRef.current = null;
127
+ pendingSearchApplyAttachedRef.current = false;
128
+ }, []);
100
129
  const selectedWalletIds = (0, react.useMemo)(() => [...state.selectedIds || [], ...state.committedIds || []], [state.committedIds, state.selectedIds]);
101
130
  const committedKeys = (0, react.useMemo)(() => new Set((state.committedIds || []).map((id) => String(id))), [state.committedIds]);
102
131
  const selectedItemByKey = (0, react.useMemo)(() => new Map((state.selectedItems || []).map((asset) => {
@@ -181,14 +210,17 @@ function useSharedWalletPass(props) {
181
210
  }
182
211
  }));
183
212
  const handleSearchIdentificationCode = (0, ahooks.useMemoizedFn)(function() {
184
- var _ref7 = require_asyncToGenerator._asyncToGenerator(function* (code) {
213
+ var _ref7 = require_asyncToGenerator._asyncToGenerator(function* (code, options) {
185
214
  if (!(baseSales === null || baseSales === void 0 ? void 0 : baseSales.scanWalletAsset)) return null;
186
215
  setLoadingAction(true);
187
216
  deferWalletStateRef.current = true;
188
217
  deferredWalletStateRef.current = null;
218
+ let searchCompleted = false;
219
+ const initialRevision = state.revision;
189
220
  try {
190
221
  var _asset$customer_id, _asset$holder, _baseSales$getOrderCu, _ref6, _currentCustomer$id;
191
222
  const result = yield baseSales.scanWalletAsset(code);
223
+ searchCompleted = true;
192
224
  const asset = result === null || result === void 0 ? void 0 : result.asset;
193
225
  const customerId = Number((_asset$customer_id = asset === null || asset === void 0 ? void 0 : asset.customer_id) !== null && _asset$customer_id !== void 0 ? _asset$customer_id : asset === null || asset === void 0 || (_asset$holder = asset.holder) === null || _asset$holder === void 0 ? void 0 : _asset$holder.customer_id);
194
226
  const currentCustomer = baseSales === null || baseSales === void 0 || (_baseSales$getOrderCu = baseSales.getOrderCustomerSnapshot) === null || _baseSales$getOrderCu === void 0 ? void 0 : _baseSales$getOrderCu.call(baseSales);
@@ -208,11 +240,26 @@ function useSharedWalletPass(props) {
208
240
  deferWalletStateRef.current = false;
209
241
  const finalState = (baseSales === null || baseSales === void 0 || (_baseSales$getWalletA3 = baseSales.getWalletAssetsState) === null || _baseSales$getWalletA3 === void 0 ? void 0 : _baseSales$getWalletA3.call(baseSales)) || deferredWalletStateRef.current;
210
242
  deferredWalletStateRef.current = null;
211
- if (finalState) setState(finalState);
212
- setLoadingAction(false);
243
+ let waitForApply;
244
+ try {
245
+ if (finalState) {
246
+ if ((options === null || options === void 0 ? void 0 : options.waitForApply) && searchCompleted && !Object.is(finalState.revision, initialRevision)) {
247
+ var _pendingSearchApplyRe3;
248
+ (_pendingSearchApplyRe3 = pendingSearchApplyRef.current) === null || _pendingSearchApplyRe3 === void 0 || _pendingSearchApplyRe3.call(pendingSearchApplyRef);
249
+ pendingSearchApplyAttachedRef.current = false;
250
+ waitForApply = new Promise((resolve) => {
251
+ pendingSearchApplyRef.current = resolve;
252
+ });
253
+ }
254
+ setState(finalState);
255
+ }
256
+ yield waitForApply;
257
+ } finally {
258
+ setLoadingAction(false);
259
+ }
213
260
  }
214
261
  });
215
- return function(_x2) {
262
+ return function(_x2, _x3) {
216
263
  return _ref7.apply(this, arguments);
217
264
  };
218
265
  }());
@@ -241,7 +288,7 @@ function useSharedWalletPass(props) {
241
288
  setLoadingAction(false);
242
289
  }
243
290
  });
244
- return function(_x3) {
291
+ return function(_x4) {
245
292
  return _ref8.apply(this, arguments);
246
293
  };
247
294
  }());
@@ -284,7 +331,7 @@ function useSharedWalletPass(props) {
284
331
  setLoadingAction(false);
285
332
  }
286
333
  });
287
- return function(_x4, _x5, _x6) {
334
+ return function(_x5, _x6, _x7) {
288
335
  return _ref9.apply(this, arguments);
289
336
  };
290
337
  }());
@@ -121,6 +121,8 @@ const useWalletPass = (props) => {
121
121
  const historyDiscountIdsRef = (0, react.useRef)(/* @__PURE__ */ new Set());
122
122
  const historyDiscountOrderKeyRef = (0, react.useRef)("");
123
123
  const activeClientKeyRef = (0, react.useRef)("");
124
+ const pendingSearchApplyRef = (0, react.useRef)(null);
125
+ const pendingSearchApplyAttachedRef = (0, react.useRef)(false);
124
126
  const [searchIdentificationCodeList, setSearchIdentificationCodeList] = (0, react.useState)([]);
125
127
  const [orderInfo, setOrderInfo] = (0, react.useState)({});
126
128
  const [selectedWallet, setSelectedWallet] = (0, react.useState)([]);
@@ -454,10 +456,37 @@ const useWalletPass = (props) => {
454
456
  baseSales
455
457
  ]);
456
458
  (0, ahooks.useDebounceEffect)(() => {
457
- notifySelectChange(selectedWithDetails);
459
+ let notification;
460
+ try {
461
+ notification = notifySelectChange(selectedWithDetails);
462
+ } catch (error) {
463
+ var _pendingSearchApplyRe;
464
+ (_pendingSearchApplyRe = pendingSearchApplyRef.current) === null || _pendingSearchApplyRe === void 0 || _pendingSearchApplyRe.call(pendingSearchApplyRef);
465
+ pendingSearchApplyRef.current = null;
466
+ pendingSearchApplyAttachedRef.current = false;
467
+ throw error;
468
+ }
458
469
  setWalletSelect(selectedWithDetails);
459
470
  setLoading(false);
471
+ const resolvePendingSearch = pendingSearchApplyRef.current;
472
+ if (resolvePendingSearch && !pendingSearchApplyAttachedRef.current) {
473
+ pendingSearchApplyAttachedRef.current = true;
474
+ const finishPendingSearch = () => {
475
+ if (pendingSearchApplyRef.current === resolvePendingSearch) {
476
+ pendingSearchApplyRef.current = null;
477
+ pendingSearchApplyAttachedRef.current = false;
478
+ }
479
+ resolvePendingSearch();
480
+ };
481
+ Promise.resolve(notification).then(finishPendingSearch, finishPendingSearch);
482
+ }
460
483
  }, [selectedWithDetails], { wait: 200 });
484
+ (0, react.useEffect)(() => () => {
485
+ var _pendingSearchApplyRe2;
486
+ (_pendingSearchApplyRe2 = pendingSearchApplyRef.current) === null || _pendingSearchApplyRe2 === void 0 || _pendingSearchApplyRe2.call(pendingSearchApplyRef);
487
+ pendingSearchApplyRef.current = null;
488
+ pendingSearchApplyAttachedRef.current = false;
489
+ }, []);
461
490
  const data = (0, react.useMemo)(() => {
462
491
  return require_utils$1.formatMachineCodeServer2CardList((0, _pisell_utils.uniqueByKey)(mergeDataWithInitialOrder([
463
492
  ...selectedWithDetails,
@@ -589,6 +618,7 @@ const useWalletPass = (props) => {
589
618
  setNoApplicableVoucher(allDisabledData);
590
619
  setWalletSelect(newValues);
591
620
  setSelectedVoucherIds(newValues.map((item) => item.id));
621
+ return isAvailableData.length === 1;
592
622
  });
593
623
  const applyWalletInitResult = (0, ahooks.useMemoizedFn)((result) => {
594
624
  var _baseSales$getOrderSn5, _walletApi$getStoredW;
@@ -761,23 +791,31 @@ const useWalletPass = (props) => {
761
791
  select
762
792
  }
763
793
  });
764
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(select);
794
+ return onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(select);
765
795
  });
766
796
  const handleSearchIdentificationCode = (0, ahooks.useMemoizedFn)(function() {
767
- var _ref12 = require_asyncToGenerator._asyncToGenerator(function* (value) {
797
+ var _ref12 = require_asyncToGenerator._asyncToGenerator(function* (value, options) {
768
798
  var _walletApi$formatWall3;
769
799
  if (!(walletApi === null || walletApi === void 0 ? void 0 : walletApi.searchIdentificationCodeAsync)) return null;
770
800
  const result = yield walletApi.searchIdentificationCodeAsync({
771
801
  code: value,
772
802
  prepare_payments: ((_walletApi$formatWall3 = walletApi.formatWalletPassList2PreparePayments) === null || _walletApi$formatWall3 === void 0 ? void 0 : _walletApi$formatWall3.call(walletApi, selectedWithDetails)) || []
773
803
  });
774
- handleSearchIdentificationCodeCompleted({
804
+ const willApplySelection = handleSearchIdentificationCodeCompleted({
775
805
  currentSearchResults: (result === null || result === void 0 ? void 0 : result.data) || [],
776
806
  cachedSearchResults: searchIdentificationCodeList
777
807
  });
808
+ if ((options === null || options === void 0 ? void 0 : options.waitForApply) && willApplySelection) {
809
+ var _pendingSearchApplyRe3;
810
+ (_pendingSearchApplyRe3 = pendingSearchApplyRef.current) === null || _pendingSearchApplyRe3 === void 0 || _pendingSearchApplyRe3.call(pendingSearchApplyRef);
811
+ pendingSearchApplyAttachedRef.current = false;
812
+ yield new Promise((resolve) => {
813
+ pendingSearchApplyRef.current = resolve;
814
+ });
815
+ }
778
816
  return result;
779
817
  });
780
- return function(_x3) {
818
+ return function(_x3, _x4) {
781
819
  return _ref12.apply(this, arguments);
782
820
  };
783
821
  }());
@@ -927,7 +965,7 @@ const useWalletPass = (props) => {
927
965
  setLoading(false);
928
966
  }
929
967
  });
930
- return function(_x4, _x5) {
968
+ return function(_x5, _x6) {
931
969
  return _ref13.apply(this, arguments);
932
970
  };
933
971
  }());
@@ -983,7 +1021,7 @@ const useWalletPass = (props) => {
983
1021
  var _ref14 = require_asyncToGenerator._asyncToGenerator(function* (value, index, data) {
984
1022
  return true;
985
1023
  });
986
- return function(_x6, _x7, _x8) {
1024
+ return function(_x7, _x8, _x9) {
987
1025
  return _ref14.apply(this, arguments);
988
1026
  };
989
1027
  }()),
@@ -45,6 +45,9 @@ var locales_default = {
45
45
  "payment.failed": "Payment Failed",
46
46
  "payment.cancelled": "Payment Cancelled",
47
47
  "payment.processing": "Processing Payment",
48
+ "pisell2.checkout.scan-blocked-by-payment": "Payment is processing. This scan was not applied. Please scan again after payment is complete.",
49
+ "pisell2.checkout.payment-blocked-by-scan": "A wallet pass is being applied. Please wait before starting payment.",
50
+ "pisell2.checkout.wallet-scan-processing": "A wallet pass is being applied. Please wait before scanning again.",
48
51
  "close": "Close",
49
52
  "cancel": "Cancel",
50
53
  "confirm": "Confirm",
@@ -245,6 +248,9 @@ var locales_default = {
245
248
  "payment.failed": "支付失败",
246
249
  "payment.cancelled": "支付取消",
247
250
  "payment.processing": "支付处理中",
251
+ "pisell2.checkout.scan-blocked-by-payment": "支付处理中,本次扫码未生效,请在支付完成后重新扫码",
252
+ "pisell2.checkout.payment-blocked-by-scan": "卡券处理中,请稍后再支付",
253
+ "pisell2.checkout.wallet-scan-processing": "卡券处理中,请稍后再扫码",
248
254
  "close": "关闭",
249
255
  "cancel": "取消",
250
256
  "confirm": "确认",
@@ -447,6 +453,9 @@ var locales_default = {
447
453
  "payment.failed": "支付失敗",
448
454
  "payment.cancelled": "支付取消",
449
455
  "payment.processing": "支付處理中",
456
+ "pisell2.checkout.scan-blocked-by-payment": "支付處理中,本次掃碼未生效,請在支付完成後重新掃碼",
457
+ "pisell2.checkout.payment-blocked-by-scan": "卡券處理中,請稍後再支付",
458
+ "pisell2.checkout.wallet-scan-processing": "卡券處理中,請稍後再掃碼",
450
459
  "close": "關閉",
451
460
  "cancel": "取消",
452
461
  "confirm": "確認",
@@ -649,6 +658,9 @@ var locales_default = {
649
658
  "payment.failed": "支払い失敗",
650
659
  "payment.cancelled": "支払いキャンセル",
651
660
  "payment.processing": "支払い処理中",
661
+ "pisell2.checkout.scan-blocked-by-payment": "支払い処理中のため、このスキャンは適用されませんでした。支払い完了後にもう一度スキャンしてください。",
662
+ "pisell2.checkout.payment-blocked-by-scan": "ウォレットパスを処理中です。処理完了後に支払いを開始してください。",
663
+ "pisell2.checkout.wallet-scan-processing": "ウォレットパスを処理中です。処理完了後にもう一度スキャンしてください。",
652
664
  "close": "閉じる",
653
665
  "cancel": "キャンセル",
654
666
  "confirm": "確認",
@@ -848,6 +860,9 @@ var locales_default = {
848
860
  "payment.failed": "Pagamento Falhou",
849
861
  "payment.cancelled": "Pagamento Cancelado",
850
862
  "payment.processing": "Processando Pagamento",
863
+ "pisell2.checkout.scan-blocked-by-payment": "O pagamento está sendo processado. Esta leitura não foi aplicada. Leia novamente após a conclusão do pagamento.",
864
+ "pisell2.checkout.payment-blocked-by-scan": "Um passe da carteira está sendo aplicado. Aguarde antes de iniciar o pagamento.",
865
+ "pisell2.checkout.wallet-scan-processing": "Um passe da carteira está sendo aplicado. Aguarde antes de ler novamente.",
851
866
  "close": "Fechar",
852
867
  "cancel": "Cancelar",
853
868
  "confirm": "Confirmar",
@@ -71,8 +71,8 @@ const PaymentMethodRuntime = (0, react.forwardRef)(function PaymentMethodRuntime
71
71
  };
72
72
  (0, react.useImperativeHandle)(ref, () => ({
73
73
  onPay: (type, params) => {
74
- var _paymentMethodsRef$cu;
75
- return (_paymentMethodsRef$cu = paymentMethodsRef.current) === null || _paymentMethodsRef$cu === void 0 ? void 0 : _paymentMethodsRef$cu.onPay(type, params);
74
+ var _paymentMethodsRef$cu, _paymentMethodsRef$cu2;
75
+ return (_paymentMethodsRef$cu = (_paymentMethodsRef$cu2 = paymentMethodsRef.current) === null || _paymentMethodsRef$cu2 === void 0 ? void 0 : _paymentMethodsRef$cu2.onPay(type, params)) !== null && _paymentMethodsRef$cu !== void 0 ? _paymentMethodsRef$cu : Promise.resolve(false);
76
76
  },
77
77
  openPi: (options) => {
78
78
  var _piPaymentRef$current;
@@ -112,8 +112,17 @@ const PaymentMethodRuntime = (0, react.forwardRef)(function PaymentMethodRuntime
112
112
  const configuredSurcharge = calculateSurcharge(method, amount);
113
113
  const formattedSurcharge = String((0, _pisell_utils.formatAmount)(configuredSurcharge, 2));
114
114
  if (require_constants.SPI_PAYMENT_CODES.includes(code)) return new Promise((resolve) => {
115
- var _paymentMethodsRef$cu2, _baseSales$getOrderId3;
116
- (_paymentMethodsRef$cu2 = paymentMethodsRef.current) === null || _paymentMethodsRef$cu2 === void 0 || _paymentMethodsRef$cu2.onPay("mx51", {
115
+ var _baseSales$getOrderId3;
116
+ const paymentMethods = paymentMethodsRef.current;
117
+ if (!paymentMethods) {
118
+ resolve({
119
+ status: "failed",
120
+ amount,
121
+ message: "Payment method is unavailable."
122
+ });
123
+ return;
124
+ }
125
+ paymentMethods.onPay("mx51", {
117
126
  source: "normal",
118
127
  data: {
119
128
  payMethod: method,
@@ -165,6 +174,12 @@ const PaymentMethodRuntime = (0, react.forwardRef)(function PaymentMethodRuntime
165
174
  raw: data
166
175
  });
167
176
  }
177
+ }).then((opened) => {
178
+ if (!opened) resolve({
179
+ status: "failed",
180
+ amount,
181
+ message: "Payment method is unavailable."
182
+ });
168
183
  });
169
184
  });
170
185
  const usePiPayment = !!(context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.businessUtils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$i = _context$appHelper2.isPiPaymentEnabled) === null || _context$appHelper2$i === void 0 ? void 0 : _context$appHelper2$i.call(_context$appHelper2));
@@ -275,8 +290,16 @@ const PaymentMethodRuntime = (0, react.forwardRef)(function PaymentMethodRuntime
275
290
  }
276
291
  const orderId = yield ensureRemoteOrderId(baseSales);
277
292
  return new Promise((resolve) => {
278
- var _paymentMethodsRef$cu3;
279
- (_paymentMethodsRef$cu3 = paymentMethodsRef.current) === null || _paymentMethodsRef$cu3 === void 0 || _paymentMethodsRef$cu3.onPay("eftpos", {
293
+ const paymentMethods = paymentMethodsRef.current;
294
+ if (!paymentMethods) {
295
+ resolve({
296
+ status: "failed",
297
+ amount,
298
+ message: "Payment method is unavailable."
299
+ });
300
+ return;
301
+ }
302
+ paymentMethods.onPay("eftpos", {
280
303
  source: "normal",
281
304
  data: {
282
305
  payMethod: method,
@@ -324,6 +347,12 @@ const PaymentMethodRuntime = (0, react.forwardRef)(function PaymentMethodRuntime
324
347
  raw: data
325
348
  });
326
349
  }
350
+ }).then((opened) => {
351
+ if (!opened) resolve({
352
+ status: "failed",
353
+ amount,
354
+ message: "Payment method is unavailable."
355
+ });
327
356
  });
328
357
  });
329
358
  });
@@ -20,12 +20,14 @@ const updateTransactionReceiveStatus = function() {
20
20
  }();
21
21
  const EFTPOS = (props, ref) => {
22
22
  var _context$appHelper;
23
- const { interaction } = ((_context$appHelper = require_useEngineContext.default().appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
23
+ const { interaction, getData } = ((_context$appHelper = require_useEngineContext.default().appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
24
+ const paymentChannel = String((getData === null || getData === void 0 ? void 0 : getData("channel")) || "pos").trim().toLowerCase();
24
25
  const logger = require_useLogger.default();
25
26
  const network = (0, ahooks.useNetwork)();
26
27
  const [visible, setVisible] = (0, react.useState)(false);
27
28
  const eftposRef = (0, react.useRef)(null);
28
29
  const payCallbackRef = (0, react.useRef)(null);
30
+ const openResultResolveRef = (0, react.useRef)(null);
29
31
  const eftposHandlingRef = (0, react.useRef)(false);
30
32
  const eftposOpenParamsRef = (0, react.useRef)(null);
31
33
  const eftposInitDataRef = (0, react.useRef)(null);
@@ -36,11 +38,23 @@ const EFTPOS = (props, ref) => {
36
38
  (_eftposRef$current = eftposRef.current) === null || _eftposRef$current === void 0 || (_eftposRef$current$up = _eftposRef$current.updateNetwork) === null || _eftposRef$current$up === void 0 || _eftposRef$current$up.call(_eftposRef$current, { network: network.online });
37
39
  }
38
40
  }, [network.online]);
41
+ const settleOpenResult = (accepted) => {
42
+ const resolve = openResultResolveRef.current;
43
+ if (!resolve) return;
44
+ openResultResolveRef.current = null;
45
+ resolve(accepted);
46
+ };
39
47
  const closeModal = () => {
48
+ settleOpenResult(false);
40
49
  setIsEftposLoading(false);
41
50
  eftposHandlingRef.current = false;
42
51
  setVisible(false);
43
52
  };
53
+ (0, react.useEffect)(() => () => {
54
+ const resolve = openResultResolveRef.current;
55
+ openResultResolveRef.current = null;
56
+ resolve === null || resolve === void 0 || resolve(false);
57
+ }, []);
44
58
  /**
45
59
  * @title: 打开支付弹窗
46
60
  * @param {ToBPayParams} data 支付参数
@@ -48,26 +62,45 @@ const EFTPOS = (props, ref) => {
48
62
  * @param {string} source 支付来源(正常支付、恢复支付)
49
63
  */
50
64
  const onOpen = function() {
51
- var _ref2 = require_asyncToGenerator._asyncToGenerator(function* ({ source, data, payCallback }) {
65
+ var _ref2 = require_asyncToGenerator._asyncToGenerator(function* ({ source, data, payCallback, isActive }) {
52
66
  if (eftposHandlingRef.current || visible) {
53
67
  logger === null || logger === void 0 || logger.addLog({
54
68
  type: "info",
55
69
  title: "ToB_EFTPOS_onOpen 重复触发被拦截",
56
70
  metadata: { data }
57
71
  });
58
- return;
72
+ return false;
59
73
  }
60
74
  eftposHandlingRef.current = true;
61
- let device_number = "";
62
- try {
75
+ const openResult = new Promise((resolve) => {
76
+ openResultResolveRef.current = resolve;
77
+ });
78
+ const initializationResult = yield Promise.race([Promise.resolve().then(() => {
63
79
  var _interaction$utils, _interaction$utils$as;
64
- device_number = yield interaction === null || interaction === void 0 || (_interaction$utils = interaction.utils) === null || _interaction$utils === void 0 || (_interaction$utils$as = _interaction$utils.asyncDataManager) === null || _interaction$utils$as === void 0 ? void 0 : _interaction$utils$as.call(_interaction$utils, {
80
+ return interaction === null || interaction === void 0 || (_interaction$utils = interaction.utils) === null || _interaction$utils === void 0 || (_interaction$utils$as = _interaction$utils.asyncDataManager) === null || _interaction$utils$as === void 0 ? void 0 : _interaction$utils$as.call(_interaction$utils, {
65
81
  module: "get",
66
82
  key: "device_number"
67
83
  });
68
- } catch (error) {
84
+ }).then((deviceNumber) => ({
85
+ status: "ready",
86
+ deviceNumber: deviceNumber || ""
87
+ })).catch((error) => {
69
88
  console.error("获取设备编号失败", error);
89
+ return {
90
+ status: "ready",
91
+ deviceNumber: ""
92
+ };
93
+ }), openResult.then((accepted) => ({
94
+ status: "settled",
95
+ accepted
96
+ }))]);
97
+ if (initializationResult.status === "settled") return initializationResult.accepted;
98
+ if (isActive && !isActive()) {
99
+ eftposHandlingRef.current = false;
100
+ settleOpenResult(false);
101
+ return false;
70
102
  }
103
+ const device_number = initializationResult.deviceNumber;
71
104
  const { type, payMethod, params, mode } = data;
72
105
  const newData = {
73
106
  type,
@@ -110,6 +143,7 @@ const EFTPOS = (props, ref) => {
110
143
  };
111
144
  setVisible(true);
112
145
  setIsEftposLoading(true);
146
+ return openResult;
113
147
  });
114
148
  return function onOpen(_x2) {
115
149
  return _ref2.apply(this, arguments);
@@ -122,6 +156,7 @@ const EFTPOS = (props, ref) => {
122
156
  metadata: { status }
123
157
  });
124
158
  setIsEftposLoading(false);
159
+ settleOpenResult(status);
125
160
  if (!status) closeModal();
126
161
  };
127
162
  const onAfterOpenChange = (v) => {
@@ -162,6 +197,7 @@ const EFTPOS = (props, ref) => {
162
197
  params
163
198
  }
164
199
  });
200
+ if (status === "success" || status === "fail") settleOpenResult(true);
165
201
  handleResult(status, params);
166
202
  if (status === "success" || status === "fail") {
167
203
  var _payCallbackRef$curre;
@@ -179,6 +215,7 @@ const EFTPOS = (props, ref) => {
179
215
  return /* @__PURE__ */ react.default.createElement(antd.Modal, {
180
216
  open: visible,
181
217
  onCancel: closeModal,
218
+ keyboard: paymentChannel !== "kiosk",
182
219
  footer: null,
183
220
  closable: false,
184
221
  width: "fit-content",