@open-tender/store 0.3.93 → 0.3.94

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.
@@ -1,8 +1,8 @@
1
- import { Order, Orders, Refund, RefundArgs, RequestError, RequestStatus } from '../types';
1
+ import { Order, Orders, RefundArgs, RequestError, RequestStatus } from '../types';
2
2
  import { AppState } from '../app';
3
3
  export interface RefundState {
4
4
  previous: Orders | null;
5
- refund: Order | Refund | null;
5
+ refund: Order | null;
6
6
  loading: RequestStatus;
7
7
  error: RequestError;
8
8
  compeleted: boolean;
@@ -9,12 +9,12 @@ export interface RefundSurcharge {
9
9
  }
10
10
  export declare type RefundSurcharges = Array<RefundSurcharge>;
11
11
  export interface Refund {
12
- full_refund: boolean;
13
- all_taxes: boolean;
14
- items: RefundItems;
15
- surcharges: RefundSurcharges;
16
- tip: Money;
17
- shipping: Money;
12
+ full_refund?: boolean;
13
+ all_taxes?: boolean;
14
+ items?: RefundItems;
15
+ surcharges?: RefundSurcharges;
16
+ tip?: Money;
17
+ shipping?: Money;
18
18
  }
19
19
  export interface RefundArgs {
20
20
  orderId: string;
@@ -1,8 +1,9 @@
1
- import { Order, OrderCart, RequestErrorAPI } from '../types';
1
+ import { Order, OrderCart, Orders, RequestErrorAPI } from '../types';
2
2
  export declare const emptyRefund: (error: RequestErrorAPI) => boolean;
3
3
  export declare const makeRefundCartLookup: (cart: OrderCart) => Record<string, unknown>;
4
4
  export declare const makeRefundLookup: (order: Order) => {
5
5
  cart: Record<string, unknown>;
6
+ gift_cards: Record<string, `${number}.${number}`>;
6
7
  surcharges: Record<string, `${number}.${number}`>;
7
8
  discounts: Record<string, `${number}.${number}`>;
8
9
  taxes: Record<string, `${number}.${number}`>;
@@ -16,3 +17,4 @@ export declare const makeRefundLookup: (order: Order) => {
16
17
  shipping: `${number}.${number}`;
17
18
  total: `${number}.${number}`;
18
19
  };
20
+ export declare const makeNetOrder: (order: Order, refunds: Orders) => Order;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeRefundLookup = exports.makeRefundCartLookup = exports.emptyRefund = void 0;
3
+ exports.makeNetOrder = exports.makeRefundLookup = exports.makeRefundCartLookup = exports.emptyRefund = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var emptyRefund = function (error) {
6
6
  if (!error || !error.params)
@@ -23,6 +23,14 @@ var makeRefundCartLookup = function (cart) {
23
23
  return lookup;
24
24
  };
25
25
  exports.makeRefundCartLookup = makeRefundCartLookup;
26
+ var makeGiftCardAmountsLookup = function (gift_cards) {
27
+ return gift_cards.reduce(function (obj, i) {
28
+ var _a;
29
+ if (!i.code)
30
+ return obj;
31
+ return tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.code] = i.amount, _a));
32
+ }, {});
33
+ };
26
34
  var makeSurchargeAmountsLookup = function (surcharges) {
27
35
  return surcharges.reduce(function (obj, i) {
28
36
  var _a;
@@ -35,24 +43,24 @@ var makeDiscountsAmountsLookup = function (discounts) {
35
43
  return (tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
36
44
  }, {});
37
45
  };
38
- var makeTaxesAmountsLookup = function (discounts) {
39
- return discounts.reduce(function (obj, i) {
46
+ var makeTaxesAmountsLookup = function (taxes) {
47
+ return taxes.reduce(function (obj, i) {
40
48
  var _a;
41
49
  return (tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
42
50
  }, {});
43
51
  };
44
- var makeTendersAmountsLookup = function (discounts) {
45
- return discounts.reduce(function (obj, i, idx) {
52
+ var makeTendersAmountsLookup = function (tenders) {
53
+ return tenders.reduce(function (obj, i, idx) {
46
54
  var _a;
47
55
  return (tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.tender_index || idx] = i.amount, _a)));
48
56
  }, {});
49
57
  };
50
58
  var makeRefundLookup = function (order) {
51
- var cart = order.cart, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
59
+ var cart = order.cart, gift_cards = order.gift_cards, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
52
60
  var subtotal = totals.subtotal, gift_card = totals.gift_card, surcharge = totals.surcharge, discount = totals.discount, tax = totals.tax, tip = totals.tip, shipping = totals.shipping, total = totals.total;
53
61
  return {
54
62
  cart: (0, exports.makeRefundCartLookup)(cart),
55
- // gift_cards: makeAmountsLookup(gift_cards, 'code'),
63
+ gift_cards: makeGiftCardAmountsLookup(gift_cards),
56
64
  surcharges: makeSurchargeAmountsLookup(surcharges),
57
65
  discounts: makeDiscountsAmountsLookup(discounts),
58
66
  taxes: makeTaxesAmountsLookup(taxes),
@@ -68,11 +76,19 @@ var makeRefundLookup = function (order) {
68
76
  };
69
77
  };
70
78
  exports.makeRefundLookup = makeRefundLookup;
71
- // const adjustAmount = (amount: Money, refundAmount: Money) => {
72
- // return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2)
73
- // }
74
- // export const adjustAmounts = (order, lookup, list, key = 'id') => {
75
- // if (!order[list]) return order
79
+ var adjustAmount = function (amount, refundAmount) {
80
+ return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
81
+ };
82
+ var adjustAmountNegative = function (amount, refundAmount) {
83
+ return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
84
+ };
85
+ // export const adjustAmounts = (
86
+ // order: Order,
87
+ // lookup: Record<string, Record<string, Money> | Record<string, unknown>>,
88
+ // list: 'gift_cards' | 'surcharges' | 'discounts' | 'taxes' | 'tenders',
89
+ // key: 'id' | 'code' = 'id'
90
+ // ) => {
91
+ // if (!list || !order[list]) return order
76
92
  // order[list].forEach(i => {
77
93
  // const amount = lookup[list][i[key]]
78
94
  // if (amount) i.amount = adjustAmount(i.amount, amount)
@@ -89,34 +105,72 @@ exports.makeRefundLookup = makeRefundLookup;
89
105
  // 'shipping',
90
106
  // 'total'
91
107
  // ]
92
- // export const makeNetOrder = (order: Order, refunds) => {
93
- // if (!refunds || !refunds.length) return order
94
- // let copy = JSON.parse(JSON.stringify(order))
95
- // refunds.forEach(refund => {
96
- // const lookup = makeRefundLookup(refund)
97
- // copy.cart.forEach(i => {
98
- // const item = lookup.cart[i.line_no]
99
- // if (item) {
100
- // i.quantity -= item.quantity
101
- // i.price_total = adjustAmount(i.price_total, item.price_total)
102
- // }
103
- // if (i.quantity === 0) {
104
- // i.groups.forEach(group =>
105
- // group.options.forEach(option => {
106
- // option.quantity = 0
107
- // option.price_total = '0.00'
108
- // })
109
- // )
110
- // }
111
- // })
112
- // copy = adjustAmounts(copy, lookup, 'gift_cards', 'code')
113
- // copy = adjustAmounts(copy, lookup, 'surcharges')
114
- // copy = adjustAmounts(copy, lookup, 'discounts')
115
- // copy = adjustAmounts(copy, lookup, 'taxes')
116
- // copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index')
117
- // amounts.forEach(i => {
118
- // copy.totals[i] = adjustAmount(copy.totals[i], lookup[i])
119
- // })
120
- // })
121
- // return copy
122
- // }
108
+ var makeNetOrder = function (order, refunds) {
109
+ if (!refunds || !refunds.length)
110
+ return order;
111
+ var copy = JSON.parse(JSON.stringify(order));
112
+ refunds.forEach(function (refund) {
113
+ var lookup = (0, exports.makeRefundLookup)(refund);
114
+ // adjust cart
115
+ copy.cart.forEach(function (i) {
116
+ var item = lookup.cart[i.line_no];
117
+ if (item) {
118
+ i.quantity -= item.quantity;
119
+ i.price_total = adjustAmount(i.price_total, item.price_total);
120
+ }
121
+ if (i.quantity === 0 && i.groups) {
122
+ i.groups.forEach(function (group) {
123
+ return group.options.forEach(function (option) {
124
+ option.quantity = 0;
125
+ option.price_total = '0.00';
126
+ });
127
+ });
128
+ }
129
+ });
130
+ // adjust arrays
131
+ // copy = adjustAmounts(copy, lookup, 'gift_cards', 'code')
132
+ // copy = adjustAmounts(copy, lookup, 'surcharges')
133
+ // copy = adjustAmounts(copy, lookup, 'discounts')
134
+ // copy = adjustAmounts(copy, lookup, 'taxes')
135
+ // copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index')
136
+ order.gift_cards.forEach(function (i) {
137
+ var amount = i.code ? lookup.gift_cards[i.code] : null;
138
+ if (amount)
139
+ i.amount = adjustAmount(i.amount, amount);
140
+ });
141
+ order.surcharges.forEach(function (i) {
142
+ var amount = lookup.surcharges[i.id];
143
+ if (amount)
144
+ i.amount = adjustAmount(i.amount, amount);
145
+ });
146
+ order.discounts.forEach(function (i) {
147
+ var amount = lookup.discounts[i.id];
148
+ if (amount)
149
+ i.amount = adjustAmount(i.amount, amount);
150
+ });
151
+ order.taxes.forEach(function (i) {
152
+ var amount = lookup.taxes[i.id];
153
+ if (amount)
154
+ i.amount = adjustAmount(i.amount, amount);
155
+ });
156
+ order.tenders.forEach(function (i, idx) {
157
+ var amount = lookup.tenders[i.tender_index || idx];
158
+ if (amount)
159
+ i.amount = adjustAmount(i.amount, amount);
160
+ });
161
+ // adjust totals
162
+ // amounts.forEach(i => {
163
+ // copy.totals[i] = adjustAmount(copy.totals[i], lookup[i])
164
+ // })
165
+ copy.totals.subtotal = adjustAmount(copy.totals.subtotal, lookup.subtotal);
166
+ copy.totals.gift_card = adjustAmount(copy.totals.gift_card, lookup.gift_card);
167
+ copy.totals.surcharge = adjustAmount(copy.totals.surcharge, lookup.surcharge);
168
+ copy.totals.discount = adjustAmountNegative(copy.totals.discount, lookup.discount);
169
+ copy.totals.tax = adjustAmount(copy.totals.tax, lookup.tax);
170
+ copy.totals.tip = adjustAmount(copy.totals.tip, lookup.tip);
171
+ copy.totals.shipping = adjustAmount(copy.totals.shipping, lookup.shipping);
172
+ copy.totals.total = adjustAmount(copy.totals.total, lookup.total);
173
+ });
174
+ return copy;
175
+ };
176
+ exports.makeNetOrder = makeNetOrder;
@@ -1,8 +1,8 @@
1
- import { Order, Orders, Refund, RefundArgs, RequestError, RequestStatus } from '../types';
1
+ import { Order, Orders, RefundArgs, RequestError, RequestStatus } from '../types';
2
2
  import { AppState } from '../app';
3
3
  export interface RefundState {
4
4
  previous: Orders | null;
5
- refund: Order | Refund | null;
5
+ refund: Order | null;
6
6
  loading: RequestStatus;
7
7
  error: RequestError;
8
8
  compeleted: boolean;
@@ -9,12 +9,12 @@ export interface RefundSurcharge {
9
9
  }
10
10
  export declare type RefundSurcharges = Array<RefundSurcharge>;
11
11
  export interface Refund {
12
- full_refund: boolean;
13
- all_taxes: boolean;
14
- items: RefundItems;
15
- surcharges: RefundSurcharges;
16
- tip: Money;
17
- shipping: Money;
12
+ full_refund?: boolean;
13
+ all_taxes?: boolean;
14
+ items?: RefundItems;
15
+ surcharges?: RefundSurcharges;
16
+ tip?: Money;
17
+ shipping?: Money;
18
18
  }
19
19
  export interface RefundArgs {
20
20
  orderId: string;
@@ -1,8 +1,9 @@
1
- import { Order, OrderCart, RequestErrorAPI } from '../types';
1
+ import { Order, OrderCart, Orders, RequestErrorAPI } from '../types';
2
2
  export declare const emptyRefund: (error: RequestErrorAPI) => boolean;
3
3
  export declare const makeRefundCartLookup: (cart: OrderCart) => Record<string, unknown>;
4
4
  export declare const makeRefundLookup: (order: Order) => {
5
5
  cart: Record<string, unknown>;
6
+ gift_cards: Record<string, `${number}.${number}`>;
6
7
  surcharges: Record<string, `${number}.${number}`>;
7
8
  discounts: Record<string, `${number}.${number}`>;
8
9
  taxes: Record<string, `${number}.${number}`>;
@@ -16,3 +17,4 @@ export declare const makeRefundLookup: (order: Order) => {
16
17
  shipping: `${number}.${number}`;
17
18
  total: `${number}.${number}`;
18
19
  };
20
+ export declare const makeNetOrder: (order: Order, refunds: Orders) => Order;
@@ -18,6 +18,14 @@ export var makeRefundCartLookup = function (cart) {
18
18
  });
19
19
  return lookup;
20
20
  };
21
+ var makeGiftCardAmountsLookup = function (gift_cards) {
22
+ return gift_cards.reduce(function (obj, i) {
23
+ var _a;
24
+ if (!i.code)
25
+ return obj;
26
+ return __assign(__assign({}, obj), (_a = {}, _a[i.code] = i.amount, _a));
27
+ }, {});
28
+ };
21
29
  var makeSurchargeAmountsLookup = function (surcharges) {
22
30
  return surcharges.reduce(function (obj, i) {
23
31
  var _a;
@@ -30,24 +38,24 @@ var makeDiscountsAmountsLookup = function (discounts) {
30
38
  return (__assign(__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
31
39
  }, {});
32
40
  };
33
- var makeTaxesAmountsLookup = function (discounts) {
34
- return discounts.reduce(function (obj, i) {
41
+ var makeTaxesAmountsLookup = function (taxes) {
42
+ return taxes.reduce(function (obj, i) {
35
43
  var _a;
36
44
  return (__assign(__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
37
45
  }, {});
38
46
  };
39
- var makeTendersAmountsLookup = function (discounts) {
40
- return discounts.reduce(function (obj, i, idx) {
47
+ var makeTendersAmountsLookup = function (tenders) {
48
+ return tenders.reduce(function (obj, i, idx) {
41
49
  var _a;
42
50
  return (__assign(__assign({}, obj), (_a = {}, _a[i.tender_index || idx] = i.amount, _a)));
43
51
  }, {});
44
52
  };
45
53
  export var makeRefundLookup = function (order) {
46
- var cart = order.cart, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
54
+ var cart = order.cart, gift_cards = order.gift_cards, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
47
55
  var subtotal = totals.subtotal, gift_card = totals.gift_card, surcharge = totals.surcharge, discount = totals.discount, tax = totals.tax, tip = totals.tip, shipping = totals.shipping, total = totals.total;
48
56
  return {
49
57
  cart: makeRefundCartLookup(cart),
50
- // gift_cards: makeAmountsLookup(gift_cards, 'code'),
58
+ gift_cards: makeGiftCardAmountsLookup(gift_cards),
51
59
  surcharges: makeSurchargeAmountsLookup(surcharges),
52
60
  discounts: makeDiscountsAmountsLookup(discounts),
53
61
  taxes: makeTaxesAmountsLookup(taxes),
@@ -62,11 +70,19 @@ export var makeRefundLookup = function (order) {
62
70
  total: total
63
71
  };
64
72
  };
65
- // const adjustAmount = (amount: Money, refundAmount: Money) => {
66
- // return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2)
67
- // }
68
- // export const adjustAmounts = (order, lookup, list, key = 'id') => {
69
- // if (!order[list]) return order
73
+ var adjustAmount = function (amount, refundAmount) {
74
+ return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
75
+ };
76
+ var adjustAmountNegative = function (amount, refundAmount) {
77
+ return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
78
+ };
79
+ // export const adjustAmounts = (
80
+ // order: Order,
81
+ // lookup: Record<string, Record<string, Money> | Record<string, unknown>>,
82
+ // list: 'gift_cards' | 'surcharges' | 'discounts' | 'taxes' | 'tenders',
83
+ // key: 'id' | 'code' = 'id'
84
+ // ) => {
85
+ // if (!list || !order[list]) return order
70
86
  // order[list].forEach(i => {
71
87
  // const amount = lookup[list][i[key]]
72
88
  // if (amount) i.amount = adjustAmount(i.amount, amount)
@@ -83,34 +99,71 @@ export var makeRefundLookup = function (order) {
83
99
  // 'shipping',
84
100
  // 'total'
85
101
  // ]
86
- // export const makeNetOrder = (order: Order, refunds) => {
87
- // if (!refunds || !refunds.length) return order
88
- // let copy = JSON.parse(JSON.stringify(order))
89
- // refunds.forEach(refund => {
90
- // const lookup = makeRefundLookup(refund)
91
- // copy.cart.forEach(i => {
92
- // const item = lookup.cart[i.line_no]
93
- // if (item) {
94
- // i.quantity -= item.quantity
95
- // i.price_total = adjustAmount(i.price_total, item.price_total)
96
- // }
97
- // if (i.quantity === 0) {
98
- // i.groups.forEach(group =>
99
- // group.options.forEach(option => {
100
- // option.quantity = 0
101
- // option.price_total = '0.00'
102
- // })
103
- // )
104
- // }
105
- // })
106
- // copy = adjustAmounts(copy, lookup, 'gift_cards', 'code')
107
- // copy = adjustAmounts(copy, lookup, 'surcharges')
108
- // copy = adjustAmounts(copy, lookup, 'discounts')
109
- // copy = adjustAmounts(copy, lookup, 'taxes')
110
- // copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index')
111
- // amounts.forEach(i => {
112
- // copy.totals[i] = adjustAmount(copy.totals[i], lookup[i])
113
- // })
114
- // })
115
- // return copy
116
- // }
102
+ export var makeNetOrder = function (order, refunds) {
103
+ if (!refunds || !refunds.length)
104
+ return order;
105
+ var copy = JSON.parse(JSON.stringify(order));
106
+ refunds.forEach(function (refund) {
107
+ var lookup = makeRefundLookup(refund);
108
+ // adjust cart
109
+ copy.cart.forEach(function (i) {
110
+ var item = lookup.cart[i.line_no];
111
+ if (item) {
112
+ i.quantity -= item.quantity;
113
+ i.price_total = adjustAmount(i.price_total, item.price_total);
114
+ }
115
+ if (i.quantity === 0 && i.groups) {
116
+ i.groups.forEach(function (group) {
117
+ return group.options.forEach(function (option) {
118
+ option.quantity = 0;
119
+ option.price_total = '0.00';
120
+ });
121
+ });
122
+ }
123
+ });
124
+ // adjust arrays
125
+ // copy = adjustAmounts(copy, lookup, 'gift_cards', 'code')
126
+ // copy = adjustAmounts(copy, lookup, 'surcharges')
127
+ // copy = adjustAmounts(copy, lookup, 'discounts')
128
+ // copy = adjustAmounts(copy, lookup, 'taxes')
129
+ // copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index')
130
+ order.gift_cards.forEach(function (i) {
131
+ var amount = i.code ? lookup.gift_cards[i.code] : null;
132
+ if (amount)
133
+ i.amount = adjustAmount(i.amount, amount);
134
+ });
135
+ order.surcharges.forEach(function (i) {
136
+ var amount = lookup.surcharges[i.id];
137
+ if (amount)
138
+ i.amount = adjustAmount(i.amount, amount);
139
+ });
140
+ order.discounts.forEach(function (i) {
141
+ var amount = lookup.discounts[i.id];
142
+ if (amount)
143
+ i.amount = adjustAmount(i.amount, amount);
144
+ });
145
+ order.taxes.forEach(function (i) {
146
+ var amount = lookup.taxes[i.id];
147
+ if (amount)
148
+ i.amount = adjustAmount(i.amount, amount);
149
+ });
150
+ order.tenders.forEach(function (i, idx) {
151
+ var amount = lookup.tenders[i.tender_index || idx];
152
+ if (amount)
153
+ i.amount = adjustAmount(i.amount, amount);
154
+ });
155
+ // adjust totals
156
+ // amounts.forEach(i => {
157
+ // copy.totals[i] = adjustAmount(copy.totals[i], lookup[i])
158
+ // })
159
+ copy.totals.subtotal = adjustAmount(copy.totals.subtotal, lookup.subtotal);
160
+ copy.totals.gift_card = adjustAmount(copy.totals.gift_card, lookup.gift_card);
161
+ copy.totals.surcharge = adjustAmount(copy.totals.surcharge, lookup.surcharge);
162
+ copy.totals.discount = adjustAmountNegative(copy.totals.discount, lookup.discount);
163
+ copy.totals.tax = adjustAmount(copy.totals.tax, lookup.tax);
164
+ copy.totals.tip = adjustAmount(copy.totals.tip, lookup.tip);
165
+ copy.totals.shipping = adjustAmount(copy.totals.shipping, lookup.shipping);
166
+ copy.totals.total = adjustAmount(copy.totals.total, lookup.total);
167
+ });
168
+ return copy;
169
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/store",
3
- "version": "0.3.93",
3
+ "version": "0.3.94",
4
4
  "description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",