@controleonline/ui-common 1.2.87 → 1.2.88

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 (70) hide show
  1. package/.github/workflows/integration-source-gate.yml +68 -0
  2. package/.github/workflows/manager-worker.yml +7 -156
  3. package/.github/workflows/publish-npm.yml +73 -27
  4. package/.github/workflows/pull-request-checks.yml +7 -5
  5. package/docs/technical/Device-Detail-Alias-UI-Sync.md +141 -0
  6. package/package.json +13 -8
  7. package/src/react/components/BottomNavigationBar.js +178 -174
  8. package/src/react/components/BottomNavigationBar.styles.js +139 -118
  9. package/src/react/components/DefaultProvider.native.js +427 -421
  10. package/src/react/components/DefaultProvider.web.js +131 -125
  11. package/src/react/components/RemoteCheckoutService.js +3 -3
  12. package/src/react/components/RuntimeFooterMarqueeText.js +88 -36
  13. package/src/react/components/RuntimeInfoFooter.js +76 -43
  14. package/src/react/components/RuntimeInfoFooter.styles.js +22 -14
  15. package/src/react/config/deviceConfigBootstrap.js +3 -3
  16. package/src/react/pages/Devices/detail/DeviceDetailAlertsCommandsSection.js +4 -22
  17. package/src/react/pages/Devices/detail/DeviceDetailMovementSections.js +6 -2
  18. package/src/react/pages/Devices/detail/DeviceDetailOrdersPrintSection.js +4 -0
  19. package/src/react/pages/Devices/detail/DeviceDetailScreen.js +23 -338
  20. package/src/react/pages/Devices/detail/createDeviceDetailContext.js +20 -0
  21. package/src/react/pages/Devices/detail/useDeviceDetailActions.js +11 -36
  22. package/src/react/pages/Devices/detail/useDeviceDetailLoaders.js +129 -37
  23. package/src/react/pages/Devices/detail/useDeviceDetailSaves.js +11 -38
  24. package/src/react/pages/Devices/detail/useDeviceDetailStateA.js +9 -28
  25. package/src/react/pages/IntegrationConfigFields.js +1 -0
  26. package/src/react/pages/IntegrationConfigPage.js +101 -45
  27. package/src/react/pages/IntegrationConfigPage.utils.js +21 -13
  28. package/src/react/pages/fetchPeopleConfigs.js +21 -0
  29. package/src/react/pages/integrationsCatalog.js +15 -110
  30. package/src/react/services/Cielo/Cielo.js +9 -9
  31. package/src/react/services/Getnet/Getnet.web.js +25 -0
  32. package/src/react/utils/companyAuthority.js +36 -0
  33. package/src/react/utils/fileUrl.js +14 -5
  34. package/src/react/utils/paymentDevices.js +375 -270
  35. package/src/react/utils/printerDevices.js +2 -2
  36. package/src/react/utils/runtimeFooter.js +178 -224
  37. package/src/react/utils/runtimeFooterText.js +160 -0
  38. package/src/react/utils/runtimeLanguage.js +5 -5
  39. package/src/react/utils/runtimeZoom.js +29 -5
  40. package/src/react/utils/shopFranchises.js +167 -12
  41. package/src/react/utils/storeColumns.js +235 -217
  42. package/src/react/utils/systemErrorMessage.js +2 -1
  43. package/src/store/integration/index.js +43 -0
  44. package/src/tests/browser/manager/device-detail-apply-config-defined.spec.js +31 -0
  45. package/src/tests/browser/manager/device-detail-composition.spec.js +295 -0
  46. package/src/tests/browser/manager/device-detail-copy-config.spec.js +11 -1
  47. package/src/tests/browser/manager/device-detail-pdv-current-company.spec.js +273 -0
  48. package/src/tests/browser/manager/runtime-footer-rotation.spec.js +397 -0
  49. package/src/tests/react/components/DefaultProviderAuthority.test.js +28 -0
  50. package/src/tests/react/components/RuntimeFooterMarqueeText.build.test.js +29 -0
  51. package/src/tests/react/config/deviceConfigBootstrap.test.js +24 -1
  52. package/src/tests/react/pages/applyCurrentDeviceConfig.test.js +85 -0
  53. package/src/tests/react/pages/deviceDetailComposition.test.js +65 -0
  54. package/src/tests/react/pages/deviceDetailHookDependencies.test.mjs +31 -0
  55. package/src/tests/react/pages/deviceDetailLoaderDependencies.test.mjs +28 -0
  56. package/src/tests/react/pages/receitaFederalIntegrationContract.test.mjs +27 -6
  57. package/src/tests/react/services/Cielo.test.js +2 -2
  58. package/src/tests/react/utils/companyAuthority.test.js +53 -0
  59. package/src/tests/react/utils/formatter.test.mjs +6 -0
  60. package/src/tests/react/utils/paymentDevices.test.js +72 -0
  61. package/src/tests/react/utils/runtimeFooter.test.js +35 -0
  62. package/src/tests/react/utils/runtimeFooterText.test.js +88 -0
  63. package/src/tests/react/utils/runtimeLanguage.test.js +4 -4
  64. package/src/tests/react/utils/runtimeZoom.test.js +20 -0
  65. package/src/tests/react/utils/shopFranchises.test.js +32 -13
  66. package/src/tests/react/utils/translate.test.mjs +6 -6
  67. package/src/utils/formatter.js +7 -3
  68. package/src/utils/translate.js +16 -16
  69. package/src/utils/translatePending.js +6 -6
  70. package/src/utils/translateStorage.js +2 -2
@@ -1,13 +1,13 @@
1
- import {Platform} from 'react-native';
2
-
3
- export const PAYMENT_GATEWAY_CIELO = 'cielo';
4
- export const PAYMENT_GATEWAY_INFINITE_PAY = 'infinite-pay';
5
- export const PAYMENT_GATEWAY_GETNET = 'getnet';
6
- export const PAYMENT_GATEWAYS = [
7
- PAYMENT_GATEWAY_CIELO,
8
- PAYMENT_GATEWAY_INFINITE_PAY,
9
- PAYMENT_GATEWAY_GETNET,
10
- ];
1
+ import {Platform} from 'react-native';
2
+
3
+ export const PAYMENT_GATEWAY_CIELO = 'cielo';
4
+ export const PAYMENT_GATEWAY_INFINITE_PAY = 'infinite-pay';
5
+ export const PAYMENT_GATEWAY_GETNET = 'getnet';
6
+ export const PAYMENT_GATEWAYS = [
7
+ PAYMENT_GATEWAY_CIELO,
8
+ PAYMENT_GATEWAY_INFINITE_PAY,
9
+ PAYMENT_GATEWAY_GETNET,
10
+ ];
11
11
  export const POS_GATEWAY_CONFIG_KEY = 'pos-gateway';
12
12
  export const PDV_PRINTER_ENABLED_CONFIG_KEY = 'printer-enabled';
13
13
  export const ORDER_PAYMENT_DEVICES_CONFIG_KEY = 'order-payment-devices';
@@ -17,37 +17,37 @@ export const ORDER_PAYMENT_DEVICE_CHANGE_ALLOWED_CONFIG_KEY =
17
17
  export const ORDER_CHARGE_ON_DELIVERY_ENABLED_CONFIG_KEY =
18
18
  'order-charge-on-delivery-enabled';
19
19
  export const PAYMENT_TYPE_IDS_CONFIG_KEY = 'payment-type-ids';
20
-
21
- const parseJsonValue = (value, fallback) => {
22
- if (value === null || value === undefined || value === '') {
23
- return fallback;
24
- }
25
-
26
- if (typeof value === 'string') {
27
- try {
28
- return JSON.parse(value);
29
- } catch {
30
- return fallback;
31
- }
32
- }
33
-
34
- return value;
35
- };
36
-
37
- export const normalizeDeviceId = value => String(value || '').trim();
38
- export const normalizeEntityId = value =>
39
- String(value?.id || value || '')
40
- .replace(/\D/g, '')
41
- .trim();
42
-
20
+
21
+ const parseJsonValue = (value, fallback) => {
22
+ if (value === null || value === undefined || value === '') {
23
+ return fallback;
24
+ }
25
+
26
+ if (typeof value === 'string') {
27
+ try {
28
+ return JSON.parse(value);
29
+ } catch {
30
+ return fallback;
31
+ }
32
+ }
33
+
34
+ return value;
35
+ };
36
+
37
+ export const normalizeDeviceId = value => String(value || '').trim();
38
+ export const normalizeEntityId = value =>
39
+ String(value?.id || value || '')
40
+ .replace(/\D/g, '')
41
+ .trim();
42
+
43
43
  export const normalizeDeviceIds = value => {
44
44
  const parsed = parseJsonValue(value, []);
45
45
 
46
46
  if (Array.isArray(parsed)) {
47
47
  return parsed.map(normalizeDeviceId).filter(Boolean);
48
48
  }
49
-
50
- const singleId = normalizeDeviceId(parsed);
49
+
50
+ const singleId = normalizeDeviceId(parsed);
51
51
  return singleId ? [singleId] : [];
52
52
  };
53
53
 
@@ -104,137 +104,137 @@ const resolveWalletPaymentTypeId = walletPaymentType =>
104
104
  normalizeEntityId(
105
105
  walletPaymentType?.['@id'] || walletPaymentType?.id,
106
106
  );
107
-
108
- const parseConfigsObject = value => {
109
- if (!value) {
110
- return {};
111
- }
112
-
113
- if (typeof value === 'string') {
114
- try {
115
- const parsed = JSON.parse(value);
116
- return parsed && typeof parsed === 'object' ? parsed : {};
117
- } catch {
118
- return {};
119
- }
120
- }
121
-
122
- return typeof value === 'object' ? value : {};
123
- };
124
-
125
- const resolveConfigsSource = value => {
126
- if (
127
- value &&
128
- typeof value === 'object' &&
129
- !Array.isArray(value) &&
130
- Object.prototype.hasOwnProperty.call(value, 'configs')
131
- ) {
132
- return value.configs;
133
- }
134
-
135
- return value;
136
- };
137
-
138
- export const normalizePaymentGateway = value => {
139
- const rawGateway = String(value || '')
140
- .trim()
141
- .toLowerCase();
142
-
143
- if (!rawGateway) {
144
- return '';
145
- }
146
-
147
- const compactGateway = rawGateway.replace(/[\s_]/g, '-');
148
- if (compactGateway === 'infinitepay') {
149
- return PAYMENT_GATEWAY_INFINITE_PAY;
150
- }
151
- if (compactGateway === PAYMENT_GATEWAY_INFINITE_PAY) {
152
- return PAYMENT_GATEWAY_INFINITE_PAY;
153
- }
154
- if (compactGateway === PAYMENT_GATEWAY_CIELO) {
155
- return PAYMENT_GATEWAY_CIELO;
156
- }
157
- if (compactGateway === 'getnet' || compactGateway === PAYMENT_GATEWAY_GETNET) {
158
- return PAYMENT_GATEWAY_GETNET;
159
- }
160
-
161
- return compactGateway;
162
- };
163
-
164
- const normalizeDeviceType = value =>
165
- String(value || '')
166
- .trim()
167
- .toUpperCase();
168
-
169
- const isTruthyValue = value =>
170
- value === true || value === '1' || value === 1 || value === 'true';
171
-
172
- const resolveDeviceConfigDevice = deviceConfig => {
173
- const nestedDevice = deviceConfig?.device;
174
- if (nestedDevice && typeof nestedDevice === 'object') {
175
- return nestedDevice;
176
- }
177
- if (typeof nestedDevice === 'string') {
178
- return {device: nestedDevice};
179
- }
180
- return {};
181
- };
182
-
183
- const getDeviceConfigDeviceId = deviceConfig => {
184
- const device = resolveDeviceConfigDevice(deviceConfig);
185
- return normalizeDeviceId(
186
- device?.device || deviceConfig?.deviceId || deviceConfig?.device_id || '',
187
- );
188
- };
189
-
190
- const getDeviceConfigType = deviceConfig =>
191
- normalizeDeviceType(deviceConfig?.type || deviceConfig?.device?.type);
192
-
193
- export const filterDeviceConfigsByCompany = (deviceConfigs, companyId) => {
194
- const normalizedCompanyId = normalizeEntityId(companyId);
195
-
196
- return (Array.isArray(deviceConfigs) ? deviceConfigs : []).filter(
197
- deviceConfig =>
198
- !normalizedCompanyId ||
199
- normalizeEntityId(deviceConfig?.people?.id || deviceConfig?.people) ===
200
- normalizedCompanyId,
201
- );
202
- };
203
-
204
- export const getPaymentGatewayFromConfigs = configs =>
205
- normalizePaymentGateway(
206
- parseConfigsObject(resolveConfigsSource(configs))?.[POS_GATEWAY_CONFIG_KEY],
207
- );
208
-
209
- export const getPaymentGateway = deviceConfig =>
210
- getPaymentGatewayFromConfigs(deviceConfig);
211
-
212
- export const isLocalCieloPrintCapableDeviceConfig = deviceConfig =>
213
- getDeviceConfigType(deviceConfig) === 'PDV' &&
214
- getPaymentGateway(deviceConfig) === PAYMENT_GATEWAY_CIELO;
215
-
216
- export const isPdvPrinterEnabled = configs => {
217
- const parsedConfigs = parseConfigsObject(resolveConfigsSource(configs));
218
- const printerEnabled = parsedConfigs?.[PDV_PRINTER_ENABLED_CONFIG_KEY];
219
-
220
- if (
221
- printerEnabled === undefined ||
222
- printerEnabled === null ||
223
- printerEnabled === ''
224
- ) {
225
- return true;
226
- }
227
-
228
- return isTruthyValue(printerEnabled);
229
- };
230
-
231
- export const isOrderChargeOnDeliveryEnabled = configs =>
232
- isTruthyValue(
233
- parseConfigsObject(resolveConfigsSource(configs))?.[
234
- ORDER_CHARGE_ON_DELIVERY_ENABLED_CONFIG_KEY
235
- ],
236
- );
237
-
107
+
108
+ const parseConfigsObject = value => {
109
+ if (!value) {
110
+ return {};
111
+ }
112
+
113
+ if (typeof value === 'string') {
114
+ try {
115
+ const parsed = JSON.parse(value);
116
+ return parsed && typeof parsed === 'object' ? parsed : {};
117
+ } catch {
118
+ return {};
119
+ }
120
+ }
121
+
122
+ return typeof value === 'object' ? value : {};
123
+ };
124
+
125
+ const resolveConfigsSource = value => {
126
+ if (
127
+ value &&
128
+ typeof value === 'object' &&
129
+ !Array.isArray(value) &&
130
+ Object.prototype.hasOwnProperty.call(value, 'configs')
131
+ ) {
132
+ return value.configs;
133
+ }
134
+
135
+ return value;
136
+ };
137
+
138
+ export const normalizePaymentGateway = value => {
139
+ const rawGateway = String(value || '')
140
+ .trim()
141
+ .toLowerCase();
142
+
143
+ if (!rawGateway) {
144
+ return '';
145
+ }
146
+
147
+ const compactGateway = rawGateway.replace(/[\s_]/g, '-');
148
+ if (compactGateway === 'infinitepay') {
149
+ return PAYMENT_GATEWAY_INFINITE_PAY;
150
+ }
151
+ if (compactGateway === PAYMENT_GATEWAY_INFINITE_PAY) {
152
+ return PAYMENT_GATEWAY_INFINITE_PAY;
153
+ }
154
+ if (compactGateway === PAYMENT_GATEWAY_CIELO) {
155
+ return PAYMENT_GATEWAY_CIELO;
156
+ }
157
+ if (compactGateway === 'getnet' || compactGateway === PAYMENT_GATEWAY_GETNET) {
158
+ return PAYMENT_GATEWAY_GETNET;
159
+ }
160
+
161
+ return compactGateway;
162
+ };
163
+
164
+ const normalizeDeviceType = value =>
165
+ String(value || '')
166
+ .trim()
167
+ .toUpperCase();
168
+
169
+ const isTruthyValue = value =>
170
+ value === true || value === '1' || value === 1 || value === 'true';
171
+
172
+ const resolveDeviceConfigDevice = deviceConfig => {
173
+ const nestedDevice = deviceConfig?.device;
174
+ if (nestedDevice && typeof nestedDevice === 'object') {
175
+ return nestedDevice;
176
+ }
177
+ if (typeof nestedDevice === 'string') {
178
+ return {device: nestedDevice};
179
+ }
180
+ return {};
181
+ };
182
+
183
+ const getDeviceConfigDeviceId = deviceConfig => {
184
+ const device = resolveDeviceConfigDevice(deviceConfig);
185
+ return normalizeDeviceId(
186
+ device?.device || deviceConfig?.deviceId || deviceConfig?.device_id || '',
187
+ );
188
+ };
189
+
190
+ const getDeviceConfigType = deviceConfig =>
191
+ normalizeDeviceType(deviceConfig?.type || deviceConfig?.device?.type);
192
+
193
+ export const filterDeviceConfigsByCompany = (deviceConfigs, companyId) => {
194
+ const normalizedCompanyId = normalizeEntityId(companyId);
195
+
196
+ return (Array.isArray(deviceConfigs) ? deviceConfigs : []).filter(
197
+ deviceConfig =>
198
+ !normalizedCompanyId ||
199
+ normalizeEntityId(deviceConfig?.people?.id || deviceConfig?.people) ===
200
+ normalizedCompanyId,
201
+ );
202
+ };
203
+
204
+ export const getPaymentGatewayFromConfigs = configs =>
205
+ normalizePaymentGateway(
206
+ parseConfigsObject(resolveConfigsSource(configs))?.[POS_GATEWAY_CONFIG_KEY],
207
+ );
208
+
209
+ export const getPaymentGateway = deviceConfig =>
210
+ getPaymentGatewayFromConfigs(deviceConfig);
211
+
212
+ export const isLocalCieloPrintCapableDeviceConfig = deviceConfig =>
213
+ getDeviceConfigType(deviceConfig) === 'PDV' &&
214
+ getPaymentGateway(deviceConfig) === PAYMENT_GATEWAY_CIELO;
215
+
216
+ export const isPdvPrinterEnabled = configs => {
217
+ const parsedConfigs = parseConfigsObject(resolveConfigsSource(configs));
218
+ const printerEnabled = parsedConfigs?.[PDV_PRINTER_ENABLED_CONFIG_KEY];
219
+
220
+ if (
221
+ printerEnabled === undefined ||
222
+ printerEnabled === null ||
223
+ printerEnabled === ''
224
+ ) {
225
+ return true;
226
+ }
227
+
228
+ return isTruthyValue(printerEnabled);
229
+ };
230
+
231
+ export const isOrderChargeOnDeliveryEnabled = configs =>
232
+ isTruthyValue(
233
+ parseConfigsObject(resolveConfigsSource(configs))?.[
234
+ ORDER_CHARGE_ON_DELIVERY_ENABLED_CONFIG_KEY
235
+ ],
236
+ );
237
+
238
238
  export const isOrderPaymentDeviceChangeAllowed = configs =>
239
239
  isTruthyValue(
240
240
  parseConfigsObject(resolveConfigsSource(configs))?.[
@@ -297,107 +297,212 @@ export const groupWalletPaymentTypesByWalletId = walletPaymentTypes =>
297
297
  );
298
298
 
299
299
  export const isPaymentGateway = gateway => PAYMENT_GATEWAYS.includes(gateway);
300
-
301
- export const isPaymentCapableDeviceConfig = deviceConfig =>
302
- isPaymentGateway(getPaymentGateway(deviceConfig));
303
-
304
- export const isRemotePaymentCapableDeviceConfig = deviceConfig =>
305
- getDeviceConfigType(deviceConfig) === 'PDV' &&
306
- isPaymentCapableDeviceConfig(deviceConfig);
307
-
308
- export const getPaymentDeviceLabel = deviceConfig =>
309
- resolveDeviceConfigDevice(deviceConfig)?.alias ||
310
- resolveDeviceConfigDevice(deviceConfig)?.name ||
311
- resolveDeviceConfigDevice(deviceConfig)?.device ||
312
- 'Device sem nome';
313
-
314
- export const getPaymentGatewayLabel = gateway => {
315
- if (gateway === PAYMENT_GATEWAY_CIELO) return 'Cielo';
316
- if (gateway === PAYMENT_GATEWAY_INFINITE_PAY) return 'Infinite Pay';
317
- if (gateway === PAYMENT_GATEWAY_GETNET) return 'Getnet';
318
- return 'Gateway nao configurado';
319
- };
320
-
321
- export const getCompanyPaymentDeviceOptions = deviceConfigs =>
322
- (Array.isArray(deviceConfigs) ? deviceConfigs : [])
323
- .filter(isRemotePaymentCapableDeviceConfig)
324
- .map(deviceConfig => ({
325
- alias: getPaymentDeviceLabel(deviceConfig),
326
- deviceId: getDeviceConfigDeviceId(deviceConfig),
327
- gateway: getPaymentGateway(deviceConfig),
328
- gatewayLabel: getPaymentGatewayLabel(getPaymentGateway(deviceConfig)),
329
- config: deviceConfig,
330
- }))
331
- .filter(option => option.deviceId);
332
-
333
- export const resolveConfiguredRemotePaymentDeviceIds = ({
334
- deviceConfig,
335
- companyConfigs,
336
- }) => {
337
- const configuredCompanyDeviceIds = normalizeDeviceIds(
338
- companyConfigs?.[ORDER_PAYMENT_DEVICES_CONFIG_KEY],
339
- );
340
-
341
- if (configuredCompanyDeviceIds.length > 0) {
342
- return configuredCompanyDeviceIds;
343
- }
344
-
345
- const configs = parseConfigsObject(deviceConfig?.configs);
346
- const preferredDeviceId = normalizeDeviceId(
347
- configs?.[ORDER_PAYMENT_DEVICE_CONFIG_KEY],
348
- );
349
-
350
- return preferredDeviceId ? [preferredDeviceId] : [];
351
- };
352
-
353
- export const resolveRemotePaymentDeviceOptions = ({
354
- deviceConfig,
355
- deviceConfigs,
356
- companyConfigs,
357
- }) => {
358
- const currentDeviceId = getDeviceConfigDeviceId(deviceConfig);
359
- const availableOptions = getCompanyPaymentDeviceOptions(deviceConfigs).filter(
360
- option => option.deviceId !== currentDeviceId,
361
- );
362
- const configuredDeviceIds = resolveConfiguredRemotePaymentDeviceIds({
363
- deviceConfig,
364
- companyConfigs,
365
- });
366
-
367
- if (!configuredDeviceIds.length) {
368
- return availableOptions;
369
- }
370
-
371
- const availableOptionsMap = new Map(
372
- availableOptions.map(option => [option.deviceId, option]),
373
- );
374
-
375
- const configuredOptions = configuredDeviceIds
376
- .map(deviceId => availableOptionsMap.get(deviceId))
377
- .filter(Boolean);
378
-
379
- return configuredOptions.length > 0 ? configuredOptions : availableOptions;
380
- };
381
-
382
- export const supportsLocalCardPayment = ({deviceConfig, platform = Platform.OS}) =>
383
- platform !== 'web' && isPaymentCapableDeviceConfig(deviceConfig);
384
-
385
- export const buildWalletIdsForGateway = ({
386
- gateway,
387
- companyConfigs,
388
- includeCashWallet = true,
389
- }) => {
390
- const walletIds = [];
391
- const gatewayWallet = companyConfigs?.[`pos-${gateway}-wallet`];
392
- const cashWallet = companyConfigs?.['pos-cash-wallet'];
393
-
394
- if (gatewayWallet) {
395
- walletIds.push(gatewayWallet);
396
- }
397
-
398
- if (includeCashWallet && cashWallet) {
399
- walletIds.push(cashWallet);
400
- }
401
-
402
- return walletIds;
403
- };
300
+
301
+ export const isPaymentCapableDeviceConfig = deviceConfig =>
302
+ isPaymentGateway(getPaymentGateway(deviceConfig));
303
+
304
+ export const isRemotePaymentCapableDeviceConfig = deviceConfig =>
305
+ getDeviceConfigType(deviceConfig) === 'PDV' &&
306
+ isPaymentCapableDeviceConfig(deviceConfig);
307
+
308
+ export const getPaymentDeviceLabel = deviceConfig =>
309
+ resolveDeviceConfigDevice(deviceConfig)?.alias ||
310
+ resolveDeviceConfigDevice(deviceConfig)?.name ||
311
+ resolveDeviceConfigDevice(deviceConfig)?.device ||
312
+ 'Device sem nome';
313
+
314
+ export const getPaymentGatewayLabel = gateway => {
315
+ if (gateway === PAYMENT_GATEWAY_CIELO) return 'Cielo';
316
+ if (gateway === PAYMENT_GATEWAY_INFINITE_PAY) return 'Infinite Pay';
317
+ if (gateway === PAYMENT_GATEWAY_GETNET) return 'Getnet';
318
+ return 'Gateway nao configurado';
319
+ };
320
+
321
+ export const getCompanyPaymentDeviceOptions = deviceConfigs =>
322
+ (Array.isArray(deviceConfigs) ? deviceConfigs : [])
323
+ .filter(isRemotePaymentCapableDeviceConfig)
324
+ .map(deviceConfig => ({
325
+ alias: getPaymentDeviceLabel(deviceConfig),
326
+ deviceId: getDeviceConfigDeviceId(deviceConfig),
327
+ gateway: getPaymentGateway(deviceConfig),
328
+ gatewayLabel: getPaymentGatewayLabel(getPaymentGateway(deviceConfig)),
329
+ config: deviceConfig,
330
+ }))
331
+ .filter(option => option.deviceId);
332
+
333
+ export const resolveConfiguredRemotePaymentDeviceIds = ({
334
+ deviceConfig,
335
+ companyConfigs,
336
+ }) => {
337
+ const configuredCompanyDeviceIds = normalizeDeviceIds(
338
+ companyConfigs?.[ORDER_PAYMENT_DEVICES_CONFIG_KEY],
339
+ );
340
+
341
+ if (configuredCompanyDeviceIds.length > 0) {
342
+ return configuredCompanyDeviceIds;
343
+ }
344
+
345
+ const configs = parseConfigsObject(deviceConfig?.configs);
346
+ const preferredDeviceId = normalizeDeviceId(
347
+ configs?.[ORDER_PAYMENT_DEVICE_CONFIG_KEY],
348
+ );
349
+
350
+ return preferredDeviceId ? [preferredDeviceId] : [];
351
+ };
352
+
353
+ export const resolveRemotePaymentDeviceOptions = ({
354
+ deviceConfig,
355
+ deviceConfigs,
356
+ companyConfigs,
357
+ }) => {
358
+ const currentDeviceId = getDeviceConfigDeviceId(deviceConfig);
359
+ const availableOptions = getCompanyPaymentDeviceOptions(deviceConfigs).filter(
360
+ option => option.deviceId !== currentDeviceId,
361
+ );
362
+ const configuredDeviceIds = resolveConfiguredRemotePaymentDeviceIds({
363
+ deviceConfig,
364
+ companyConfigs,
365
+ });
366
+
367
+ if (!configuredDeviceIds.length) {
368
+ return availableOptions;
369
+ }
370
+
371
+ const availableOptionsMap = new Map(
372
+ availableOptions.map(option => [option.deviceId, option]),
373
+ );
374
+
375
+ const configuredOptions = configuredDeviceIds
376
+ .map(deviceId => availableOptionsMap.get(deviceId))
377
+ .filter(Boolean);
378
+
379
+ return configuredOptions.length > 0 ? configuredOptions : availableOptions;
380
+ };
381
+
382
+ export const supportsLocalCardPayment = ({deviceConfig, platform = Platform.OS}) =>
383
+ platform !== 'web' && isPaymentCapableDeviceConfig(deviceConfig);
384
+
385
+ export const buildWalletIdsForGateway = ({
386
+ gateway,
387
+ companyConfigs,
388
+ includeCashWallet = true,
389
+ }) => {
390
+ const walletIds = [];
391
+ const gatewayWallet = companyConfigs?.[`pos-${gateway}-wallet`];
392
+ const cashWallet = companyConfigs?.['pos-cash-wallet'];
393
+
394
+ if (gatewayWallet) {
395
+ walletIds.push(gatewayWallet);
396
+ }
397
+
398
+ if (includeCashWallet && cashWallet) {
399
+ walletIds.push(cashWallet);
400
+ }
401
+
402
+ return walletIds;
403
+ };
404
+
405
+ const resolveWalletDisplayName = walletPaymentType =>
406
+ String(
407
+ walletPaymentType?.wallet?.wallet ||
408
+ walletPaymentType?.wallet?.name ||
409
+ walletPaymentType?.walletName ||
410
+ '',
411
+ )
412
+ .trim()
413
+ .toLowerCase();
414
+
415
+ export const isCashWalletPaymentType = walletPaymentType => {
416
+ const name = resolveWalletDisplayName(walletPaymentType);
417
+ return (
418
+ name.includes('dinheiro') ||
419
+ name.includes('cash') ||
420
+ name.includes('money') ||
421
+ name === 'especie' ||
422
+ name.includes('espécie')
423
+ );
424
+ };
425
+
426
+ export const walletPaymentTypeMatchesGateway = (walletPaymentType, gateway) => {
427
+ const normalizedGateway = normalizePaymentGateway(gateway);
428
+ if (!normalizedGateway) {
429
+ return false;
430
+ }
431
+
432
+ const name = resolveWalletDisplayName(walletPaymentType);
433
+ if (!name) {
434
+ return false;
435
+ }
436
+
437
+ if (normalizedGateway === PAYMENT_GATEWAY_CIELO) {
438
+ return name.includes('cielo');
439
+ }
440
+ if (normalizedGateway === PAYMENT_GATEWAY_INFINITE_PAY) {
441
+ return name.includes('infinite');
442
+ }
443
+ if (normalizedGateway === PAYMENT_GATEWAY_GETNET) {
444
+ return name.includes('getnet');
445
+ }
446
+
447
+ return name.includes(normalizedGateway);
448
+ };
449
+
450
+ export const filterWalletPaymentTypesByWalletIds = (
451
+ walletPaymentTypes,
452
+ walletIds,
453
+ ) => {
454
+ const allowedWalletIds = new Set(
455
+ (Array.isArray(walletIds) ? walletIds : [])
456
+ .map(normalizeEntityId)
457
+ .filter(Boolean),
458
+ );
459
+
460
+ if (!allowedWalletIds.size) {
461
+ return [];
462
+ }
463
+
464
+ return (Array.isArray(walletPaymentTypes) ? walletPaymentTypes : []).filter(
465
+ walletPaymentType =>
466
+ allowedWalletIds.has(resolveWalletPaymentTypeWalletId(walletPaymentType)),
467
+ );
468
+ };
469
+
470
+ export const selectPosWalletPaymentTypes = ({
471
+ walletPaymentTypes,
472
+ deviceConfigs,
473
+ companyConfigs,
474
+ gateway,
475
+ } = {}) => {
476
+ const items = Array.isArray(walletPaymentTypes) ? walletPaymentTypes : [];
477
+ const normalizedGateway =
478
+ normalizePaymentGateway(gateway) ||
479
+ getPaymentGatewayFromConfigs(deviceConfigs);
480
+
481
+ const configuredWalletIds = buildWalletIdsForGateway({
482
+ gateway: normalizedGateway,
483
+ companyConfigs,
484
+ includeCashWallet: true,
485
+ }).map(normalizeEntityId).filter(Boolean);
486
+
487
+ let selected = items;
488
+
489
+ if (configuredWalletIds.length) {
490
+ selected = filterWalletPaymentTypesByWalletIds(items, configuredWalletIds);
491
+ } else if (normalizedGateway) {
492
+ selected = items.filter(
493
+ walletPaymentType =>
494
+ walletPaymentTypeMatchesGateway(walletPaymentType, normalizedGateway) ||
495
+ isCashWalletPaymentType(walletPaymentType),
496
+ );
497
+ }
498
+
499
+ const allowedPaymentTypeIds = resolveDevicePaymentTypeIds(deviceConfigs);
500
+ if (allowedPaymentTypeIds.length) {
501
+ selected = filterWalletPaymentTypesByAllowedIds(
502
+ selected,
503
+ allowedPaymentTypeIds,
504
+ );
505
+ }
506
+
507
+ return selected;
508
+ };
@@ -1,9 +1,9 @@
1
- import {parseConfigsObject} from '@controleonline/ui-common/src/react/config/deviceConfigBootstrap';
1
+ import {parseConfigsObject} from '@controleonline/ui-common/src/react/config/deviceConfigBootstrap.js';
2
2
  import {
3
3
  filterDeviceConfigsByCompany,
4
4
  isPdvPrinterEnabled,
5
5
  normalizeDeviceId,
6
- } from '@controleonline/ui-common/src/react/utils/paymentDevices';
6
+ } from '@controleonline/ui-common/src/react/utils/paymentDevices.js';
7
7
 
8
8
  export const PRINT_DEVICE_TYPE = 'PRINT';
9
9
  export const PRINTER_DEVICE_TYPE = 'PRINTER';