@darkpos/pricing 1.0.171 → 1.0.173

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 (40) hide show
  1. package/README.md +2 -5
  2. package/__TEST__/invoice.test.js +5 -1
  3. package/__TEST__/item/getModifierTags.test.js +1 -1
  4. package/__TEST__/item/unpick.item.test.js +2 -0
  5. package/__TEST__/item.test.js +2 -0
  6. package/__TEST__/mocks/storeSettings.js +427 -0
  7. package/__TEST__/mocks/stores.js +0 -429
  8. package/__TEST__/modifier/addItemModifier.test.js +2 -0
  9. package/__TEST__/modifier/hasModifier.test.js +2 -0
  10. package/__TEST__/modifier/overrideModifiers.test.js +2 -0
  11. package/__TEST__/modifier.test.js +2 -0
  12. package/__TEST__/order/addItem.test.js +2 -0
  13. package/__TEST__/order/addItemsToSubOrder.js +9 -3
  14. package/__TEST__/order/applyRefund.test.js +2 -0
  15. package/__TEST__/order/conditionsNotMet.test.js +2 -0
  16. package/__TEST__/order/createSubOrder.test.js +10 -2
  17. package/__TEST__/order/getGiftModifierSources.test.js +8 -2
  18. package/__TEST__/order/getPaidGiftModifiers.test.js +3 -3
  19. package/__TEST__/order/getParentTotals.test.js +2 -0
  20. package/__TEST__/order/getSameItems.test.js +2 -0
  21. package/__TEST__/order/hasSerial.test.js +2 -0
  22. package/__TEST__/order/manualSplit.test.js +2 -0
  23. package/__TEST__/order/normalizeEndDate.test.js +11 -13
  24. package/__TEST__/order/order-payment-modifier.test.js +2 -0
  25. package/__TEST__/order/order.test.js +8 -6
  26. package/__TEST__/order/pickEndDate.test.js +48 -54
  27. package/__TEST__/order/setPieces.test.js +2 -0
  28. package/__TEST__/order/split.test.js +14 -16
  29. package/__TEST__/order/unpick.order.test.js +2 -0
  30. package/__TEST__/payment/getPaymentItemIds.test.js +33 -9
  31. package/__TEST__/payment/getPaymentOrderIds.test.js +24 -8
  32. package/__TEST__/payment.test.js +79 -53
  33. package/lib/index.js +7 -2
  34. package/lib/order/getCustomerStoreCredit.js +1 -0
  35. package/lib/payment/getMaxAmountsToRefund.js +31 -0
  36. package/lib/payment/getMethodLabel.js +1 -1
  37. package/lib/payment/index.js +2 -4
  38. package/package.json +2 -2
  39. package/lib/payment/getMaxAmountToRefund.js +0 -14
  40. package/lib/payment/getMaxAmountToVoid.js +0 -14
package/README.md CHANGED
@@ -9,11 +9,8 @@
9
9
  ```
10
10
  const usePricing = require('@darkpos/pricing');
11
11
 
12
- const options = {
13
- ...localization,
14
- };
15
-
16
- const pricingService = usePricing(options);
12
+ // store: the store itself; settings: its settings by group ({ localization, order, payment, ... })
13
+ const pricingService = usePricing({ store, settings });
17
14
 
18
15
  //
19
16
  const newOrder = pricingService.order.calculate(oldOrder);
@@ -18,7 +18,11 @@ describe('invoice.distributeTip tests', () => {
18
18
  { amount: 1, tip: 0.33 },
19
19
  { amount: 1, tip: 0.34 },
20
20
  ]);
21
- expect(invoicesOptions).toEqual([{ amount: 1 }, { amount: 1 }, { amount: 1 }]);
21
+ expect(invoicesOptions).toEqual([
22
+ { amount: 1 },
23
+ { amount: 1 },
24
+ { amount: 1 },
25
+ ]);
22
26
  });
23
27
 
24
28
  test('assigns undistributed tip to the last invoice option when total amount is zero', () => {
@@ -2,7 +2,7 @@ const usePricing = require('../../lib/index');
2
2
 
3
3
  const pricingService = usePricing();
4
4
  const pricingServiceGroupModifiers = usePricing({
5
- store: { _settings: { order: { groupModifiers: true } } },
5
+ settings: { order: { groupModifiers: true } },
6
6
  });
7
7
 
8
8
  const mockModifier = {
@@ -1,8 +1,10 @@
1
1
  const usePricing = require('../../index');
2
2
  const mockStores = require('../mocks/stores');
3
+ const mockStoreSettings = require('../mocks/storeSettings');
3
4
 
4
5
  const session = {
5
6
  store: mockStores[0],
7
+ settings: mockStoreSettings,
6
8
  };
7
9
 
8
10
  const pricingService = usePricing(session);
@@ -1,9 +1,11 @@
1
1
  const usePricing = require('../index');
2
2
  const mockStores = require('./mocks/stores');
3
+ const mockStoreSettings = require('./mocks/storeSettings');
3
4
  const itemMerge = require('./mocks/items/addItemMerge.json');
4
5
 
5
6
  const session = {
6
7
  store: mockStores[0],
8
+ settings: mockStoreSettings,
7
9
  };
8
10
 
9
11
  const pricingService = usePricing(session);
@@ -0,0 +1,427 @@
1
+ // The settings of mocks/stores' store, by group
2
+ module.exports = {
3
+ message: {
4
+ number: '+14703224772',
5
+ email: 'support@mail.darkpos.io',
6
+ },
7
+ notification: {
8
+ blacklist: {
9
+ sms: ['989126368711', '989122797384', '11111'],
10
+ email: ['nabil@darkpos.com', 'marjan@darkpos.com'],
11
+ },
12
+ methods: {
13
+ sms: {
14
+ config: {
15
+ from: '+14703224772',
16
+ userId: 'u-chyznmhvk2atp7maydzxdtq',
17
+ apiToken: 't-ki5lp5yzvtjpik5q5v3rpfi',
18
+ apiSecret: '7mhybvragwlqk5cj52vulc3iyx74aqe4gfndmhi',
19
+ script: 'bandwidth',
20
+ },
21
+ },
22
+ sms1: {
23
+ config: {
24
+ region: 'us-east-1',
25
+ secretAccessKey: 'XXXXXXXXX',
26
+ accessKeyId: 'XXXXXXX',
27
+ script: 'aws',
28
+ },
29
+ },
30
+ email: {
31
+ config: {
32
+ domain: 'mail.darkpos.io',
33
+ apiKey: 'key-770c869441dfd9ae8c23fd52c1843fca',
34
+ script: 'mailgun',
35
+ },
36
+ },
37
+ },
38
+ },
39
+ payment: {
40
+ methods: {
41
+ cash: {
42
+ label: 'Cash',
43
+ type: 'cash',
44
+ },
45
+ check: {
46
+ label: 'Check',
47
+ type: 'check',
48
+ },
49
+ 'bank-transfer': {
50
+ label: 'Bank Transfer',
51
+ type: 'bank-transfer',
52
+ },
53
+ 'credit-card': {
54
+ label: 'Credit Card Manual',
55
+ type: 'credit-card',
56
+ },
57
+ 'credit-card-ppec': {
58
+ label: 'Credit Card (PPEC)',
59
+ type: 'credit-card',
60
+ config: {
61
+ publishableKey: 'pk_test_Luwi4BLEwuEVwd4GoKa7iAac',
62
+ script: 'stripe',
63
+ currency: 'usd',
64
+ apiKey: 'sk_test_a7NUqKXZU5zEdv5tK5r3qq1f',
65
+ method: 'stripe',
66
+ type: 'script',
67
+ },
68
+ },
69
+ 'credit-card-mxm': {
70
+ label: 'Credit Card MXM',
71
+ type: 'credit-card',
72
+ config: {
73
+ script: 'mxmerchant',
74
+ merchantId: '282060674',
75
+ consumerKey: 'CvhdZl5CxNW1CPhuyZQWDgiG',
76
+ consumerSecret: '0aGwqTT2XmUVuQ5THyh4inrpC+0=',
77
+ serviceUrl: 'https://sandbox.api.mxmerchant.com/checkout/v3/',
78
+ type: 'script',
79
+ method: 'mxmerchant',
80
+ },
81
+ },
82
+ 'credit-card-bluepay': {
83
+ label: 'Credit Card Blue Pay',
84
+ type: 'credit-card',
85
+ config: {
86
+ type: 'script',
87
+ method: 'bluepay',
88
+ accountId: '100463947973',
89
+ secretKey: 'T3N3UPJRGLK0APLP6RXTODX8UX4YU.BZ',
90
+ script: 'bluepay',
91
+ apiAccountId: '5a03e6bb5b284ed5b2ce6785a2f1c760',
92
+ apiSecretKey: '5a03e6bb5b284ed5b2ce6785a2f1c760',
93
+ mode: 'TEST',
94
+ darkApiUrl: 'https://api-dev.darkpos.io',
95
+ darkApiSecretKey: 'Q0UyQUJEMTJFOTJFNEJDQThGNDQzNkY2MjYzN0ZEQzc=',
96
+ },
97
+ },
98
+ 'credit-card-square': {
99
+ label: 'Credit Card Square',
100
+ type: 'credit-card',
101
+ config: {
102
+ type: 'script',
103
+ method: 'square',
104
+ currency: 'USD',
105
+ location: 'BXNVBAX7CEC79',
106
+ account: '2821a140-8875-430e-8cb7-fd67913c8ca0',
107
+ stripe: 'square',
108
+ mode: 'LIVE',
109
+ applicationId: 'sq0idp-EJUDUzYbGvJNY5xFC5zPDw',
110
+ placeholders: {
111
+ number: 'Card Number (4532759734545858)',
112
+ cvv: 'CVC (258)',
113
+ expDate: 'Month/Year (01/20)',
114
+ zipCode: 'Zip Code (94103)',
115
+ },
116
+ },
117
+ },
118
+ 'creadit-card-elavon': {
119
+ label: 'Credit Card Elavon',
120
+ type: 'credit-card',
121
+ config: {
122
+ type: 'script',
123
+ method: 'elavon',
124
+ merchantId: '008099',
125
+ userId: 'webpage',
126
+ pin: '1QG5UN',
127
+ },
128
+ },
129
+ 'credit-card-vantiv': {
130
+ label: 'Credit Card Vantiv',
131
+ type: 'credit-card',
132
+ config: {
133
+ type: 'terminal',
134
+ method: 'vantiv',
135
+ applicationId: '8235',
136
+ acceptorId: '3928907',
137
+ accountId: '1044125',
138
+ token:
139
+ 'B8407759ECBA126AAC5AADAB76C3B426A546FFC7D7C89BB51047C52B995DDC682D9F2C01',
140
+ },
141
+ },
142
+ 'credit-card-datacap': {
143
+ label: 'Credit Card DataCap',
144
+ type: 'credit-card',
145
+ config: {
146
+ type: 'terminal',
147
+ method: 'datacap',
148
+ merchantId: '100463947973',
149
+ tranDeviceId: 'PT7205282705',
150
+ accountId: 'DarkPOSTest',
151
+ authCode: 'VfPYvD9HLWJjrWdgEYARaZqh',
152
+ testMode: 'true',
153
+ },
154
+ },
155
+ gift: {
156
+ label: 'Gift',
157
+ type: 'gift',
158
+ },
159
+ 'stored-credit': {
160
+ label: 'storedCredit',
161
+ type: 'credit',
162
+ },
163
+ },
164
+ currency: '$',
165
+ coins: [0.01, 0.05, 0.1, 0.25, 0.5, 1],
166
+ notes: [1, 5, 10, 20, 50, 100],
167
+ gratuities: [5, 10],
168
+ },
169
+ loyalty: {
170
+ methods: {
171
+ nexus: {
172
+ config: {
173
+ type: 'nexus',
174
+ grant_type: 'password',
175
+ merchant_id: '207',
176
+ username: 'enlite_api',
177
+ password: 'enlite%1378#',
178
+ POSStoreID: 'S1',
179
+ POSUserID: 'E123',
180
+ domain: 'enlite',
181
+ },
182
+ lookupField: 'emails',
183
+ refresh: 86400,
184
+ },
185
+ },
186
+ },
187
+ types: {
188
+ 'modifier-groups': ['Size', 'Extra', 'No', 'Sauces', 'Taxes', 'Toast'],
189
+ orders: ['walk-in', 'dine-in', 'to-go', 'delivery'],
190
+ templates: ['receipt', 'kitchen'],
191
+ payments: ['cash', 'check', 'credit-card', 'bank-transfer'],
192
+ loyalty: ['nexus'],
193
+ automation: {
194
+ schedules: {
195
+ daily: 'Daily',
196
+ weekly: 'Weekly',
197
+ monthly: 'Monthly',
198
+ },
199
+ entities: ['order'],
200
+ trigger: {
201
+ pre: 'Before',
202
+ post: 'After',
203
+ },
204
+ actions: ['create', 'update', 'remove', 'find'],
205
+ events: {
206
+ message: 'Send a Message',
207
+ print: 'Send to Print',
208
+ },
209
+ },
210
+ tags: [
211
+ 'vip',
212
+ 'default',
213
+ 'formal',
214
+ 'dummy-customer',
215
+ 'test',
216
+ 'all',
217
+ 'test3',
218
+ 'tteesstt',
219
+ 'test4',
220
+ 'normal',
221
+ 'ok',
222
+ 'samim',
223
+ 'sdf',
224
+ 'defaults',
225
+ ],
226
+ notes: [
227
+ {
228
+ id: 1,
229
+ value: 'coffee',
230
+ },
231
+ ],
232
+ defaultType: 'dineIn',
233
+ modifierGroups: [
234
+ 'test4',
235
+ 'TestGroup',
236
+ "Naeem's Group",
237
+ 'grouptest',
238
+ 'naa',
239
+ 'samim',
240
+ 'ast',
241
+ 'Add',
242
+ ],
243
+ },
244
+ hooks: {
245
+ order: {
246
+ type: 'post',
247
+ method: 'create',
248
+ events: [
249
+ 'notify',
250
+ 'print',
251
+ 'export',
252
+ {
253
+ config: {
254
+ template: 'receipt',
255
+ },
256
+ name: 'receipt-sms',
257
+ },
258
+ {
259
+ config: {
260
+ printer: 'receipt',
261
+ template: 'receipt',
262
+ },
263
+ name: 'receipt-print',
264
+ },
265
+ {
266
+ config: {
267
+ template: 'receipt',
268
+ },
269
+ name: 'receipt-email',
270
+ },
271
+ ],
272
+ },
273
+ },
274
+ theme: {
275
+ delite: {
276
+ type: 'dark',
277
+ selected: 'true',
278
+ },
279
+ 'delite-red': {
280
+ type: 'light',
281
+ },
282
+ },
283
+ security: {
284
+ pin: {
285
+ type: 'numeric',
286
+ length: 3,
287
+ complexity: 'simple',
288
+ },
289
+ },
290
+ features: {
291
+ tables: {
292
+ name: 'tables',
293
+ label: 'Tables',
294
+ icon: 'table',
295
+ shortcut: false,
296
+ },
297
+ reservations: {
298
+ name: 'reservations',
299
+ label: 'Reservations',
300
+ icon: 'table',
301
+ shortcut: false,
302
+ },
303
+ schedules: {
304
+ name: 'schedules',
305
+ label: 'Schedules',
306
+ icon: 'table',
307
+ shortcut: true,
308
+ },
309
+ orders: [
310
+ {
311
+ name: 'walk-in',
312
+ label: 'Walk In',
313
+ icon: 'store',
314
+ shortcut: true,
315
+ },
316
+ {
317
+ name: 'dine-in',
318
+ label: 'Dine In',
319
+ icon: 'event_seat',
320
+ shortcut: true,
321
+ },
322
+ {
323
+ name: 'to-go',
324
+ label: 'To Go',
325
+ icon: 'shopping_basket',
326
+ shortcut: true,
327
+ },
328
+ {
329
+ name: 'delivery',
330
+ label: 'Delivery',
331
+ icon: 'drive_eta',
332
+ shortcut: false,
333
+ },
334
+ ],
335
+ },
336
+ data: {
337
+ 'display-ids': {
338
+ orders: {
339
+ type: 'numeric',
340
+ length: 3,
341
+ lastValue: 839,
342
+ },
343
+ order: {
344
+ type: 'numeric',
345
+ length: '',
346
+ },
347
+ customer: {
348
+ type: 'numeric',
349
+ length: '',
350
+ },
351
+ invoice: {
352
+ type: 'numeric',
353
+ length: '',
354
+ },
355
+ user: {
356
+ type: 'numeric',
357
+ length: '',
358
+ },
359
+ },
360
+ preload: {
361
+ customer: true,
362
+ item: true,
363
+ category: true,
364
+ modifier: true,
365
+ rawMenu: true,
366
+ table: true,
367
+ area: true,
368
+ },
369
+ },
370
+ general: {
371
+ name: 'store name',
372
+ address: 'store address',
373
+ phone: 'store phone #',
374
+ web: 'store web address',
375
+ email: 'support@mail.darkpos.io',
376
+ notes: 'store notes',
377
+ banner:
378
+ 'https://images.unsplash.com/photo-1536506591919-966afe6f7c09?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&h=400&fit=crop&ixid=eyJhcHBfaWQiOjF9&s=8cf33a0acf87d4348fd1ab14e13fa488',
379
+ logo: 'https://images.unsplash.com/photo-1536506591919-966afe6f7c09?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&h=400&fit=crop&ixid=eyJhcHBfaWQiOjF9&s=8cf33a0acf87d4348fd1ab14e13fa488',
380
+ receiptMessage: 'Thanks for buying',
381
+ background:
382
+ 'https://images.unsplash.com/photo-1533137138-ba67dc90d752?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjF9',
383
+ },
384
+ slack: {
385
+ accessToken:
386
+ 'xoxp-251861074629-425343643221-445864104630-940ef57c8162fded89f88c91eb838ce8',
387
+ botAccessToken: 'xoxb-251861074629-436722880101-57QMYYIzG3uMuD5hooGlaAyn',
388
+ botUserId: 'UCUM8RW2Z',
389
+ teamId: 'T7DRB26JH',
390
+ teamName: 'DarkPOS',
391
+ },
392
+ order: {
393
+ allowSuborder: true,
394
+ orderAddToTop: true,
395
+ modifiersHaveColumn: true,
396
+ modifiersHaveColumns: false,
397
+ aggregateItems: true,
398
+ hideBreadcrumbs: false,
399
+ modifierCollapsedDisplay: true,
400
+ itemDetailDisplay: true,
401
+ },
402
+ url: '',
403
+ localization: {
404
+ language: 'en-US',
405
+ currency: 'USD',
406
+ phoneFormat: 'INTERNATIONAL',
407
+ timezone: null,
408
+ defaultCountry: {
409
+ label: 'United States',
410
+ value: 'US',
411
+ },
412
+ },
413
+ defaultTypes: {
414
+ toGo: true,
415
+ walkIn: false,
416
+ dineIn: true,
417
+ },
418
+ forms: {
419
+ required: {
420
+ categorySchema: ['name'],
421
+ itemSchema: ['name', 'price'],
422
+ modifierSchema: ['name'],
423
+ customerSchema: ['firstName', 'lastName'],
424
+ creditCardSchema: ['number', 'cvv', 'expDate', 'zipCode'],
425
+ },
426
+ },
427
+ };