@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.
- package/dist/cjs/slices/refund.d.ts +2 -2
- package/dist/cjs/types/api/refund.d.ts +6 -6
- package/dist/cjs/utils/refunds.d.ts +3 -1
- package/dist/cjs/utils/refunds.js +97 -43
- package/dist/esm/slices/refund.d.ts +2 -2
- package/dist/esm/types/api/refund.d.ts +6 -6
- package/dist/esm/utils/refunds.d.ts +3 -1
- package/dist/esm/utils/refunds.js +95 -42
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Order, Orders,
|
|
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 |
|
|
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
|
|
13
|
-
all_taxes
|
|
14
|
-
items
|
|
15
|
-
surcharges
|
|
16
|
-
tip
|
|
17
|
-
shipping
|
|
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 (
|
|
39
|
-
return
|
|
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 (
|
|
45
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
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,
|
|
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 |
|
|
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
|
|
13
|
-
all_taxes
|
|
14
|
-
items
|
|
15
|
-
surcharges
|
|
16
|
-
tip
|
|
17
|
-
shipping
|
|
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 (
|
|
34
|
-
return
|
|
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 (
|
|
40
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
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.
|
|
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",
|