rerobe-js-orm 3.1.6 → 3.1.8
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/lib/constants/product-constants.js +2 -2
- package/lib/factories/Order/OrderFromFormState.js +2 -2
- package/lib/factories/Order/RefundFromFormState.d.ts +2 -0
- package/lib/factories/Order/RefundFromFormState.js +33 -5
- package/lib/form-states/Order/RefundFormState.d.ts +7 -5
- package/lib/form-states/Order/RefundFormState.js +140 -45
- package/lib/helpers/OrderHelpers.d.ts +98 -2
- package/lib/helpers/OrderHelpers.js +160 -25
- package/lib/models/Order.d.ts +1 -0
- package/lib/models/Order.js +4 -0
- package/lib/models/Refund.d.ts +5 -0
- package/lib/models/Refund.js +10 -0
- package/lib/types/rerobe-order-types.d.ts +21 -1
- package/package.json +1 -1
|
@@ -58,7 +58,7 @@ exports.PRODUCT_STATE_LABELS = {
|
|
|
58
58
|
reserved: 'In a shopping cart',
|
|
59
59
|
sold: 'Sold—return period open',
|
|
60
60
|
returned: 'Returned-pending publication',
|
|
61
|
-
soldSellerToBePaid: 'SOLD-
|
|
61
|
+
soldSellerToBePaid: 'SOLD-pending payment',
|
|
62
62
|
soldSellerPaid: 'Paid out',
|
|
63
63
|
sellerSelfReject: 'Declined by you',
|
|
64
64
|
liquidationRequested: 'Requested to take back',
|
|
@@ -66,7 +66,7 @@ exports.PRODUCT_STATE_LABELS = {
|
|
|
66
66
|
sellerLiquidated: 'You’ve taken back',
|
|
67
67
|
loading: 'Loading',
|
|
68
68
|
shoppingBag: 'In a shopping bag',
|
|
69
|
-
reservationQueue: 'In ',
|
|
69
|
+
reservationQueue: 'In waiting list',
|
|
70
70
|
availableInStore: 'Listed for sale in store',
|
|
71
71
|
sellerDonated: 'Donated by you',
|
|
72
72
|
merchantDonated: 'Donated by merchant',
|
|
@@ -5,7 +5,7 @@ const Order_1 = require("../../models/Order");
|
|
|
5
5
|
const order_constants_1 = require("../../constants/order-constants");
|
|
6
6
|
class OrderFromFormState extends OrderFactory_1.default {
|
|
7
7
|
createOrder(fs) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
9
9
|
const currencyCode = fs.fields.currencyCode.inputValue || 'SEK';
|
|
10
10
|
const customer = fs.fields.customer.selectedValue || {};
|
|
11
11
|
const customerAttr = {
|
|
@@ -98,7 +98,7 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
98
98
|
fulfillmentStatus: fs.fields.fulfillmentStatus.selectedValue,
|
|
99
99
|
statusUrl: ((_j = fs.props) === null || _j === void 0 ? void 0 : _j.statusUrl) || '',
|
|
100
100
|
};
|
|
101
|
-
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((_k = fs.props) === null || _k === void 0 ? void 0 : _k.id) || '', documentId: ((_l = fs.props) === null || _l === void 0 ? void 0 : _l.documentId) || '', name: ((_m = fs.props) === null || _m === void 0 ? void 0 : _m.name) || '', orderNumber: (_o = fs.props) === null || _o === void 0 ? void 0 : _o.orderNumber, ribbnOrderNumber: (_p = fs.props) === null || _p === void 0 ? void 0 : _p.ribbnOrderNumber, merchantId: ((_q = fs.props) === null || _q === void 0 ? void 0 : _q.merchantId) || '', currencyCode: fs.fields.currencyCode.inputValue, lineItems: fs.fields.lineItems.selectedValues || [], fulfillments: ((_r = fs.props) === null || _r === void 0 ? void 0 : _r.fulfillments) || [], refunds: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.refunds) || [], paymentType: fs.fields.paymentType.selectedValue, paymentMethod: fs.fields.paymentMethod.selectedValue || '', paymentDetails: fs.fields.paymentDetails.selectedValue || {}, notes: fs.fields.notes.inputValue || '', tags: fs.fields.tags.selectedValues || [], cancelReason: fs.fields.cancelReason.selectedValue || '', canceledAt: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.canceledAt) || '', processedAt: ((_u = fs.props) === null || _u === void 0 ? void 0 : _u.processedAt) || new Date().toUTCString(), adjustments: ((_v = fs.props) === null || _v === void 0 ? void 0 : _v.adjustments) || [], createdAtTimestamp: 0, updatedAtTimestamp: 0 });
|
|
101
|
+
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((_k = fs.props) === null || _k === void 0 ? void 0 : _k.id) || '', documentId: ((_l = fs.props) === null || _l === void 0 ? void 0 : _l.documentId) || '', name: ((_m = fs.props) === null || _m === void 0 ? void 0 : _m.name) || '', orderNumber: (_o = fs.props) === null || _o === void 0 ? void 0 : _o.orderNumber, ribbnOrderNumber: (_p = fs.props) === null || _p === void 0 ? void 0 : _p.ribbnOrderNumber, merchantId: ((_q = fs.props) === null || _q === void 0 ? void 0 : _q.merchantId) || '', currencyCode: fs.fields.currencyCode.inputValue, lineItems: fs.fields.lineItems.selectedValues || [], fulfillments: ((_r = fs.props) === null || _r === void 0 ? void 0 : _r.fulfillments) || [], refunds: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.refunds) || [], paymentType: fs.fields.paymentType.selectedValue, paymentMethod: fs.fields.paymentMethod.selectedValue || '', paymentDetails: fs.fields.paymentDetails.selectedValue || {}, notes: fs.fields.notes.inputValue || '', tags: fs.fields.tags.selectedValues || [], cancelReason: fs.fields.cancelReason.selectedValue || '', canceledAt: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.canceledAt) || '', processedAt: ((_u = fs.props) === null || _u === void 0 ? void 0 : _u.processedAt) || new Date().toUTCString(), adjustments: ((_v = fs.props) === null || _v === void 0 ? void 0 : _v.adjustments) || [], createdAtTimestamp: 0, updatedAtTimestamp: 0, createdByUserId: ((_w = fs.props) === null || _w === void 0 ? void 0 : _w.createdByUserId) || '' });
|
|
102
102
|
return new Order_1.default(Object.assign({}, orderAttributes));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import RefundFormState from '../../form-states/Order/RefundFormState';
|
|
2
2
|
import RefundFactory from './RefundFactory';
|
|
3
|
+
import OrderHelpers from '../../helpers/OrderHelpers';
|
|
3
4
|
export default class RefundFromFormState extends RefundFactory {
|
|
5
|
+
orderHelpers: OrderHelpers;
|
|
4
6
|
createRefund(fs: RefundFormState): OrderRefund;
|
|
5
7
|
}
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const Refund_1 = require("../../models/Refund");
|
|
4
4
|
const RefundFactory_1 = require("./RefundFactory");
|
|
5
|
+
const OrderHelpers_1 = require("../../helpers/OrderHelpers");
|
|
5
6
|
class RefundFromFormState extends RefundFactory_1.default {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.orderHelpers = new OrderHelpers_1.default();
|
|
10
|
+
}
|
|
6
11
|
createRefund(fs) {
|
|
7
|
-
var _a, _b, _c, _d, _e, _f;
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
8
13
|
const currencyCode = fs.props.totalRefunded.currencyCode ||
|
|
9
14
|
((_b = (_a = fs.fields.refundLineItems.selectedValues[0]) === null || _a === void 0 ? void 0 : _a.subtotalRefund) === null || _b === void 0 ? void 0 : _b.currencyCode) ||
|
|
10
15
|
'';
|
|
@@ -16,15 +21,29 @@ class RefundFromFormState extends RefundFactory_1.default {
|
|
|
16
21
|
: fs.fields.refundLineItems.selectedValues.filter(({ quantityRefund, quantityCancel }) => quantityRefund + quantityCancel > 0);
|
|
17
22
|
const refundAttributes = {
|
|
18
23
|
documentId: ((_f = fs.props) === null || _f === void 0 ? void 0 : _f.documentId) || '',
|
|
19
|
-
totalRefunded: {
|
|
24
|
+
totalRefunded: {
|
|
25
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.totalRefunded.inputValue || 0),
|
|
26
|
+
currencyCode,
|
|
27
|
+
},
|
|
20
28
|
subtotalRefunded: { amount: fs.fields.subtotalRefunded.inputValue || 0, currencyCode },
|
|
21
29
|
refundDiscount: { amount: fs.fields.refundDiscount.inputValue || 0, currencyCode },
|
|
22
|
-
|
|
30
|
+
refundCreditDiscount: {
|
|
31
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.refundCreditDiscount.inputValue || 0),
|
|
32
|
+
currencyCode,
|
|
33
|
+
},
|
|
34
|
+
refundCurrency: {
|
|
35
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.refundCurrency.inputValue || 0),
|
|
36
|
+
currencyCode,
|
|
37
|
+
},
|
|
38
|
+
refundShipping: {
|
|
39
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.refundShipping.inputValue || 0),
|
|
40
|
+
currencyCode,
|
|
41
|
+
},
|
|
23
42
|
totalTax: { amount: fs.fields.totalTax.inputValue || 0, currencyCode },
|
|
24
43
|
refundLineItems: preparedRefundLineItems,
|
|
25
44
|
note: fs.fields.note.inputValue || '',
|
|
26
45
|
totalRefundedPresentment: {
|
|
27
|
-
amount: fs.fields.totalRefundedPresentment.inputValue || 0,
|
|
46
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.totalRefundedPresentment.inputValue || 0),
|
|
28
47
|
currencyCode: currencyCodePresentment,
|
|
29
48
|
},
|
|
30
49
|
subtotalRefundedPresentment: {
|
|
@@ -35,14 +54,23 @@ class RefundFromFormState extends RefundFactory_1.default {
|
|
|
35
54
|
amount: fs.fields.refundDiscountPresentment.inputValue || 0,
|
|
36
55
|
currencyCode: currencyCodePresentment,
|
|
37
56
|
},
|
|
57
|
+
refundCreditDiscountPresentment: {
|
|
58
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.refundCreditDiscountPresentment.inputValue || 0),
|
|
59
|
+
currencyCode: currencyCodePresentment,
|
|
60
|
+
},
|
|
61
|
+
refundCurrencyPresentment: {
|
|
62
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.refundCurrencyPresentment.inputValue || 0),
|
|
63
|
+
currencyCode: currencyCodePresentment,
|
|
64
|
+
},
|
|
38
65
|
refundShippingPresentment: {
|
|
39
|
-
amount: fs.fields.refundShippingPresentment.inputValue || 0,
|
|
66
|
+
amount: this.orderHelpers.toFixedPointPrice(fs.fields.refundShippingPresentment.inputValue || 0),
|
|
40
67
|
currencyCode: currencyCodePresentment,
|
|
41
68
|
},
|
|
42
69
|
totalTaxPresentment: {
|
|
43
70
|
amount: fs.fields.totalTaxPresentment.inputValue || 0,
|
|
44
71
|
currencyCode: currencyCodePresentment,
|
|
45
72
|
},
|
|
73
|
+
createdByUserId: ((_g = fs.props) === null || _g === void 0 ? void 0 : _g.createdByUserId) || '',
|
|
46
74
|
};
|
|
47
75
|
return new Refund_1.default(Object.assign({}, refundAttributes));
|
|
48
76
|
}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import FormState from '../FormState';
|
|
2
2
|
import Refund from '../../models/Refund';
|
|
3
|
+
import OrderHelpers from '../../helpers/OrderHelpers';
|
|
3
4
|
export default class RefundFormState extends FormState {
|
|
4
5
|
fields: OrderRefundFormFields;
|
|
5
6
|
props: CompleteRefund;
|
|
7
|
+
orderHelpers: OrderHelpers;
|
|
6
8
|
constructor(props?: any);
|
|
7
9
|
createRefund(): Refund;
|
|
8
10
|
updateTotalRefunded(): void;
|
|
9
|
-
|
|
11
|
+
updateDiscountsAndSubtotals(): void;
|
|
12
|
+
getUpdatedRefundLineItem(lineItem: ReRobeOrderLineItem, quantityRefund?: number | string, quantityCancel?: number | string): RefundLineItem;
|
|
10
13
|
refundLineItemChangeHandler(val: {
|
|
11
14
|
lineItemLike: ReRobeOrderLineItem | RefundLineItem;
|
|
12
|
-
quantityRefund
|
|
13
|
-
quantityCancel
|
|
14
|
-
unitOrderDiscount: number;
|
|
15
|
-
unitOrderDiscountPresentment?: number;
|
|
15
|
+
quantityRefund?: number | string;
|
|
16
|
+
quantityCancel?: number | string;
|
|
16
17
|
}): void;
|
|
18
|
+
updateRelatedField(fieldKey: 'refundShipping' | 'refundShippingPresentment' | 'totalRefunded' | 'totalRefundedPresentment', value: number | string): void;
|
|
17
19
|
private fieldFactory;
|
|
18
20
|
}
|
|
@@ -3,13 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const FormState_1 = require("../FormState");
|
|
4
4
|
const RefundFromFormState_1 = require("../../factories/Order/RefundFromFormState");
|
|
5
5
|
const Refund_1 = require("../../models/Refund");
|
|
6
|
+
const OrderHelpers_1 = require("../../helpers/OrderHelpers");
|
|
6
7
|
class RefundFormState extends FormState_1.default {
|
|
7
8
|
constructor(props) {
|
|
8
9
|
super();
|
|
9
|
-
this.
|
|
10
|
+
this.orderHelpers = new OrderHelpers_1.default();
|
|
11
|
+
this.props = Object.assign(Object.assign({}, new Refund_1.default(props).toObj()), { orderMoreInfo: (props === null || props === void 0 ? void 0 : props.order) ? this.orderHelpers.getOrderInfoWithRefundsAndFulfillments(props === null || props === void 0 ? void 0 : props.order) : {} });
|
|
10
12
|
this.fields.totalRefunded = this.fieldFactory('textInput', 'totalRefunded');
|
|
11
13
|
this.fields.subtotalRefunded = this.fieldFactory('textInput', 'subtotalRefunded');
|
|
12
14
|
this.fields.refundDiscount = this.fieldFactory('textInput', 'refundDiscount');
|
|
15
|
+
this.fields.refundCreditDiscount = this.fieldFactory('textInput', 'refundCreditDiscount');
|
|
16
|
+
this.fields.refundCurrency = this.fieldFactory('textInput', 'refundCurrency');
|
|
13
17
|
this.fields.refundShipping = this.fieldFactory('textInput', 'refundShipping');
|
|
14
18
|
this.fields.totalTax = this.fieldFactory('textInput', 'totalTax');
|
|
15
19
|
this.fields.refundLineItems = this.fieldFactory('multiSelect', 'refundLineItems');
|
|
@@ -17,6 +21,8 @@ class RefundFormState extends FormState_1.default {
|
|
|
17
21
|
this.fields.totalRefundedPresentment = this.fieldFactory('textInput', 'totalRefundedPresentment');
|
|
18
22
|
this.fields.subtotalRefundedPresentment = this.fieldFactory('textInput', 'subtotalRefundedPresentment');
|
|
19
23
|
this.fields.refundDiscountPresentment = this.fieldFactory('textInput', 'refundDiscountPresentment');
|
|
24
|
+
this.fields.refundCreditDiscountPresentment = this.fieldFactory('textInput', 'refundCreditDiscountPresentment');
|
|
25
|
+
this.fields.refundCurrencyPresentment = this.fieldFactory('textInput', 'refundCurrencyPresentment');
|
|
20
26
|
this.fields.refundShippingPresentment = this.fieldFactory('textInput', 'refundShippingPresentment');
|
|
21
27
|
this.fields.totalTaxPresentment = this.fieldFactory('textInput', 'totalTaxPresentment');
|
|
22
28
|
}
|
|
@@ -25,26 +31,87 @@ class RefundFormState extends FormState_1.default {
|
|
|
25
31
|
return refundFactory.createRefund(this);
|
|
26
32
|
}
|
|
27
33
|
updateTotalRefunded() {
|
|
28
|
-
this.fields.totalRefunded.inputValue =
|
|
29
|
-
Number(this.fields.refundDiscount.inputValue) +
|
|
34
|
+
this.fields.totalRefunded.inputValue = this.orderHelpers.toFixedPointPrice(Number(this.fields.subtotalRefunded.inputValue) +
|
|
30
35
|
Number(this.fields.refundShipping.inputValue) +
|
|
31
|
-
Number(this.fields.totalTax.inputValue))
|
|
32
|
-
this.fields.totalRefundedPresentment.inputValue =
|
|
33
|
-
Number(this.fields.refundDiscountPresentment.inputValue) +
|
|
36
|
+
Number(this.fields.totalTax.inputValue));
|
|
37
|
+
this.fields.totalRefundedPresentment.inputValue = this.orderHelpers.toFixedPointPrice(Number(this.fields.subtotalRefundedPresentment.inputValue) +
|
|
34
38
|
Number(this.fields.refundShippingPresentment.inputValue) +
|
|
35
|
-
Number(this.fields.totalTaxPresentment.inputValue))
|
|
39
|
+
Number(this.fields.totalTaxPresentment.inputValue));
|
|
40
|
+
this.fields.refundCurrency.inputValue =
|
|
41
|
+
Number(this.fields.totalRefunded.inputValue) - Number(this.fields.refundCreditDiscount.inputValue);
|
|
42
|
+
this.fields.refundCurrencyPresentment.inputValue =
|
|
43
|
+
Number(this.fields.totalRefundedPresentment.inputValue) -
|
|
44
|
+
Number(this.fields.refundCreditDiscountPresentment.inputValue);
|
|
36
45
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
updateDiscountsAndSubtotals() {
|
|
47
|
+
const calculated = this.fields.refundLineItems.selectedValues.reduce((total, item) => {
|
|
48
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
49
|
+
const lineItemPriceAmount = Number(item.lineItem.isOnSale === 'yes' ? item.lineItem.salePrice || 0 : (_a = item.lineItem.originalUnitPrice) === null || _a === void 0 ? void 0 : _a.amount);
|
|
50
|
+
const lineItemPricePresentmentAmount = Number(item.lineItem.isOnSale === 'yes'
|
|
51
|
+
? ((_b = item.lineItem.presentmentSalePrice) === null || _b === void 0 ? void 0 : _b.amount) || 0
|
|
52
|
+
: ((_c = item.lineItem.presentmentUnitPrice) === null || _c === void 0 ? void 0 : _c.amount) || 0);
|
|
53
|
+
return {
|
|
54
|
+
refundDiscount: total.refundDiscount + Number((_d = item.discountRefund) === null || _d === void 0 ? void 0 : _d.amount),
|
|
55
|
+
refundCreditDiscount: total.refundCreditDiscount + Number((_e = item.creditDiscountRefund) === null || _e === void 0 ? void 0 : _e.amount),
|
|
56
|
+
subtotalRefunded: total.subtotalRefunded + Number(lineItemPriceAmount * (item.quantityRefund + item.quantityCancel)),
|
|
57
|
+
// Presentment:
|
|
58
|
+
refundDiscountPresentment: total.refundDiscountPresentment + Number((_f = item.discountRefundPresentment) === null || _f === void 0 ? void 0 : _f.amount),
|
|
59
|
+
refundCreditDiscountPresentment: total.refundCreditDiscountPresentment + Number((_g = item.creditDiscountRefundPresentment) === null || _g === void 0 ? void 0 : _g.amount),
|
|
60
|
+
subtotalRefundedPresentment: total.subtotalRefundedPresentment +
|
|
61
|
+
Number(lineItemPricePresentmentAmount * (item.quantityRefund + item.quantityCancel)), // Number(item.subtotalRefundPresentment?.amount || 0) + Number(item.subtotalCanceledPresentment?.amount || 0),
|
|
62
|
+
};
|
|
63
|
+
}, {
|
|
64
|
+
refundDiscount: 0,
|
|
65
|
+
refundCreditDiscount: 0,
|
|
66
|
+
subtotalRefunded: 0,
|
|
67
|
+
refundDiscountPresentment: 0,
|
|
68
|
+
refundCreditDiscountPresentment: 0,
|
|
69
|
+
subtotalRefundedPresentment: 0,
|
|
70
|
+
});
|
|
71
|
+
this.fields.refundDiscount.inputValue = calculated.refundDiscount;
|
|
72
|
+
this.fields.refundCreditDiscount.inputValue = this.orderHelpers.toFixedPointPrice(calculated.refundCreditDiscount);
|
|
73
|
+
this.fields.subtotalRefunded.inputValue = calculated.subtotalRefunded - calculated.refundDiscount;
|
|
74
|
+
// Update presentment price
|
|
75
|
+
this.fields.refundDiscountPresentment.inputValue = calculated.refundDiscountPresentment;
|
|
76
|
+
this.fields.refundCreditDiscountPresentment.inputValue = this.orderHelpers.toFixedPointPrice(calculated.refundCreditDiscountPresentment);
|
|
77
|
+
this.fields.subtotalRefundedPresentment.inputValue =
|
|
78
|
+
calculated.subtotalRefundedPresentment - calculated.refundDiscountPresentment;
|
|
79
|
+
}
|
|
80
|
+
getUpdatedRefundLineItem(lineItem, quantityRefund, quantityCancel) {
|
|
81
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
82
|
+
const lineItemPriceAmount = Number(lineItem.isOnSale === 'yes' ? lineItem.salePrice || 0 : (_a = lineItem.originalUnitPrice) === null || _a === void 0 ? void 0 : _a.amount);
|
|
83
|
+
const lineItemPricePresentmentAmount = Number(lineItem.isOnSale === 'yes'
|
|
84
|
+
? ((_b = lineItem.presentmentSalePrice) === null || _b === void 0 ? void 0 : _b.amount) || 0
|
|
85
|
+
: ((_c = lineItem.presentmentUnitPrice) === null || _c === void 0 ? void 0 : _c.amount) || 0);
|
|
86
|
+
const unitOrderDiscountAmount = this.orderHelpers.getLineItemUnitOrderDiscount({
|
|
87
|
+
originalUnitPrice: { amount: lineItemPriceAmount },
|
|
88
|
+
totalDiscount: (_d = this.props.orderMoreInfo) === null || _d === void 0 ? void 0 : _d.totalDiscount,
|
|
89
|
+
subtotalPrice: (_e = this.props.orderMoreInfo) === null || _e === void 0 ? void 0 : _e.subtotalPrice,
|
|
90
|
+
});
|
|
91
|
+
const unitOrderCreditDiscountAmount = this.orderHelpers.getLineItemUnitOrderDiscount({
|
|
92
|
+
originalUnitPrice: { amount: lineItemPriceAmount },
|
|
93
|
+
totalDiscount: (_f = this.props.orderMoreInfo) === null || _f === void 0 ? void 0 : _f.creditDiscount,
|
|
94
|
+
subtotalPrice: (_g = this.props.orderMoreInfo) === null || _g === void 0 ? void 0 : _g.subtotalPrice,
|
|
95
|
+
});
|
|
96
|
+
const unitOrderDiscountPresentmentAmount = this.orderHelpers.getLineItemUnitOrderDiscount({
|
|
97
|
+
originalUnitPrice: { amount: lineItemPricePresentmentAmount },
|
|
98
|
+
totalDiscount: (_h = this.props.orderMoreInfo) === null || _h === void 0 ? void 0 : _h.totalDiscountPresentment,
|
|
99
|
+
subtotalPrice: (_j = this.props.orderMoreInfo) === null || _j === void 0 ? void 0 : _j.subtotalPricePresentment,
|
|
100
|
+
});
|
|
101
|
+
const unitOrderCreditDiscountPresentmentAmount = this.orderHelpers.getLineItemUnitOrderDiscount({
|
|
102
|
+
originalUnitPrice: { amount: lineItemPricePresentmentAmount },
|
|
103
|
+
totalDiscount: (_k = this.props.orderMoreInfo) === null || _k === void 0 ? void 0 : _k.creditDiscountPresentment,
|
|
104
|
+
subtotalPrice: (_l = this.props.orderMoreInfo) === null || _l === void 0 ? void 0 : _l.subtotalPricePresentment,
|
|
105
|
+
});
|
|
41
106
|
const quantityRefundValue = Number(quantityRefund || 0);
|
|
42
107
|
const quantityCancelValue = Number(quantityCancel || 0);
|
|
43
108
|
const discountTotalRefundAmount = Number(unitOrderDiscountAmount * (quantityRefundValue + quantityCancelValue));
|
|
109
|
+
const creditDiscountRefund = Number(unitOrderCreditDiscountAmount * (quantityRefundValue + quantityCancelValue));
|
|
44
110
|
const subtotalRefundWithoutDiscount = Number((lineItemPriceAmount - unitOrderDiscountAmount) * quantityRefundValue);
|
|
45
111
|
const subtotalCanceledWithoutDiscount = Number((lineItemPriceAmount - unitOrderDiscountAmount) * quantityCancelValue);
|
|
46
112
|
// Presentment prices
|
|
47
113
|
const discountTotalRefundPresentmentAmount = Number(unitOrderDiscountPresentmentAmount * (quantityRefundValue + quantityCancelValue));
|
|
114
|
+
const creditDiscountRefundPresentment = Number(unitOrderCreditDiscountPresentmentAmount * (quantityRefundValue + quantityCancelValue));
|
|
48
115
|
const subtotalRefundWithoutPresentmentDiscount = Number((lineItemPricePresentmentAmount - unitOrderDiscountPresentmentAmount) * quantityRefundValue);
|
|
49
116
|
const subtotalCanceledWithoutPresentmentDiscount = Number((lineItemPricePresentmentAmount - unitOrderDiscountPresentmentAmount) * quantityCancelValue);
|
|
50
117
|
return {
|
|
@@ -52,79 +119,102 @@ class RefundFormState extends FormState_1.default {
|
|
|
52
119
|
quantityRefund: quantityRefundValue,
|
|
53
120
|
quantityCancel: quantityCancelValue,
|
|
54
121
|
discountRefund: Object.assign(Object.assign({}, lineItem.originalUnitPrice), { amount: discountTotalRefundAmount }),
|
|
122
|
+
creditDiscountRefund: Object.assign(Object.assign({}, lineItem.originalUnitPrice), { amount: creditDiscountRefund }),
|
|
55
123
|
subtotalRefund: Object.assign(Object.assign({}, lineItem.originalUnitPrice), { amount: subtotalRefundWithoutDiscount }),
|
|
56
124
|
subtotalCanceled: Object.assign(Object.assign({}, lineItem.originalUnitPrice), { amount: subtotalCanceledWithoutDiscount }),
|
|
57
125
|
// Presentment prices
|
|
58
|
-
discountRefundPresentment: Object.assign(Object.assign({}, lineItem.
|
|
59
|
-
|
|
60
|
-
|
|
126
|
+
discountRefundPresentment: Object.assign(Object.assign({}, lineItem.presentmentUnitPrice), { amount: discountTotalRefundPresentmentAmount }),
|
|
127
|
+
creditDiscountRefundPresentment: Object.assign(Object.assign({}, lineItem.presentmentUnitPrice), { amount: creditDiscountRefundPresentment }),
|
|
128
|
+
subtotalRefundPresentment: Object.assign(Object.assign({}, lineItem.presentmentUnitPrice), { amount: subtotalRefundWithoutPresentmentDiscount }),
|
|
129
|
+
subtotalCanceledPresentment: Object.assign(Object.assign({}, lineItem.presentmentUnitPrice), { amount: subtotalCanceledWithoutPresentmentDiscount }),
|
|
61
130
|
};
|
|
62
131
|
}
|
|
63
132
|
refundLineItemChangeHandler(val) {
|
|
64
133
|
const currentLineItems = this.fields.refundLineItems.selectedValues;
|
|
65
|
-
const unitOrderDiscountAmount = val.unitOrderDiscount || 0;
|
|
66
|
-
const unitOrderDiscountPresentmentAmount = val.unitOrderDiscountPresentment || 0;
|
|
67
134
|
// Add new product to line items
|
|
68
135
|
if (val.lineItemLike.productId) {
|
|
69
136
|
const lineItem = val.lineItemLike;
|
|
70
|
-
const newRefundLineItem = this.getUpdatedRefundLineItem(lineItem, val.quantityRefund, val.quantityCancel
|
|
137
|
+
const newRefundLineItem = this.getUpdatedRefundLineItem(lineItem, val.quantityRefund, val.quantityCancel);
|
|
71
138
|
this.fields.refundLineItems.selectedValues = this.utilities.uniqObjArray([...currentLineItems, newRefundLineItem], 'lineItem.productId');
|
|
72
139
|
}
|
|
73
140
|
// Update quantity of a line item
|
|
74
141
|
if ((val.quantityRefund || val.quantityCancel) && val.lineItemLike.lineItem) {
|
|
75
142
|
const refundLineItem = val.lineItemLike;
|
|
76
143
|
const { lineItem, quantityRefund: prevQuantityRefund, quantityCancel: prevQuantityCancel } = refundLineItem;
|
|
77
|
-
const updatedRefundLineItem = this.getUpdatedRefundLineItem(lineItem, val.quantityRefund || prevQuantityRefund, val.quantityCancel || prevQuantityCancel
|
|
144
|
+
const updatedRefundLineItem = this.getUpdatedRefundLineItem(lineItem, val.quantityRefund || prevQuantityRefund, val.quantityCancel || prevQuantityCancel);
|
|
78
145
|
this.fields.refundLineItems.selectedValues = currentLineItems.map((li) => {
|
|
79
146
|
return li.lineItem.productId === refundLineItem.lineItem.productId ? updatedRefundLineItem : li;
|
|
80
147
|
});
|
|
81
148
|
}
|
|
82
|
-
// Update discount
|
|
83
|
-
this.
|
|
84
|
-
|
|
85
|
-
.reduce((a, b) => a + b, 0);
|
|
86
|
-
// Update subtotal price
|
|
87
|
-
this.fields.subtotalRefunded.inputValue = this.fields.refundLineItems.selectedValues
|
|
88
|
-
.map((item) => { var _a; return Number(Number((_a = item.lineItem.originalUnitPrice) === null || _a === void 0 ? void 0 : _a.amount) * (item.quantityRefund + item.quantityCancel)); })
|
|
89
|
-
.reduce((a, b) => a + b, 0);
|
|
90
|
-
// Update discount and subtotal presentment prices
|
|
91
|
-
this.fields.refundDiscountPresentment.inputValue = this.fields.refundLineItems.selectedValues
|
|
92
|
-
.map((item) => { var _a; return Number((_a = item.discountRefundPresentment) === null || _a === void 0 ? void 0 : _a.amount); })
|
|
93
|
-
.reduce((a, b) => a + b, 0);
|
|
94
|
-
this.fields.subtotalRefundedPresentment.inputValue = this.fields.refundLineItems.selectedValues
|
|
95
|
-
.map((item) => { var _a; return Number(Number((_a = item.lineItem.presentmentUnitPrice) === null || _a === void 0 ? void 0 : _a.amount) * (item.quantityRefund + item.quantityCancel)); })
|
|
96
|
-
.reduce((a, b) => a + b, 0);
|
|
97
|
-
// Update total price
|
|
149
|
+
// Update discount and subtotal prices
|
|
150
|
+
this.updateDiscountsAndSubtotals();
|
|
151
|
+
// Update total prices
|
|
98
152
|
this.updateTotalRefunded();
|
|
99
153
|
}
|
|
154
|
+
updateRelatedField(fieldKey, value) {
|
|
155
|
+
var _a, _b, _c, _d;
|
|
156
|
+
const isPresentment = fieldKey.includes('Presentment');
|
|
157
|
+
const fieldToUpdate = (isPresentment ? fieldKey.replace('Presentment', '') : fieldKey + 'Presentment');
|
|
158
|
+
let relatedValue;
|
|
159
|
+
if (fieldKey === 'refundShipping' && Number(((_a = this.props.orderMoreInfo.totalShippingPrice) === null || _a === void 0 ? void 0 : _a.amount) || 0)) {
|
|
160
|
+
relatedValue = this.orderHelpers.toFixedPointPrice((Number(value) / Number(this.props.orderMoreInfo.totalShippingPrice.amount)) *
|
|
161
|
+
Number(this.props.orderMoreInfo.totalShippingPricePresentment.amount));
|
|
162
|
+
}
|
|
163
|
+
if (fieldKey === 'refundShippingPresentment' &&
|
|
164
|
+
Number(((_b = this.props.orderMoreInfo.totalShippingPricePresentment) === null || _b === void 0 ? void 0 : _b.amount) || 0)) {
|
|
165
|
+
relatedValue = this.orderHelpers.toFixedPointPrice((Number(value) / Number(this.props.orderMoreInfo.totalShippingPricePresentment.amount)) *
|
|
166
|
+
Number(this.props.orderMoreInfo.totalShippingPrice.amount));
|
|
167
|
+
}
|
|
168
|
+
if (fieldKey === 'totalRefunded' && Number(((_c = this.props.orderMoreInfo.totalPrice) === null || _c === void 0 ? void 0 : _c.amount) || 0)) {
|
|
169
|
+
relatedValue = this.orderHelpers.toFixedPointPrice((Number(value) / Number(this.props.orderMoreInfo.totalPrice.amount)) *
|
|
170
|
+
Number(this.props.orderMoreInfo.totalPricePresentment.amount));
|
|
171
|
+
}
|
|
172
|
+
if (fieldKey === 'totalRefundedPresentment' &&
|
|
173
|
+
Number(((_d = this.props.orderMoreInfo.totalPricePresentment) === null || _d === void 0 ? void 0 : _d.amount) || 0)) {
|
|
174
|
+
relatedValue = this.orderHelpers.toFixedPointPrice((Number(value) / Number(this.props.orderMoreInfo.totalPricePresentment.amount)) *
|
|
175
|
+
Number(this.props.orderMoreInfo.totalPrice.amount));
|
|
176
|
+
}
|
|
177
|
+
if (this.fields[fieldToUpdate] && 'inputValue' in this.fields[fieldToUpdate] && relatedValue) {
|
|
178
|
+
this.fields[fieldToUpdate].inputValue = relatedValue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
100
181
|
fieldFactory(fieldType, fieldKey, fieldOptions) {
|
|
182
|
+
var _a, _b;
|
|
101
183
|
const options = fieldOptions || [];
|
|
102
184
|
if (fieldType === 'textInput') {
|
|
103
185
|
let inputValue = this.props[fieldKey] || '';
|
|
104
186
|
let onChangeHandler = (val) => this.textInputChangeHandler(fieldKey, String(val));
|
|
105
|
-
const amountTypeFields = [
|
|
187
|
+
const amountTypeFields = [
|
|
188
|
+
'totalRefunded',
|
|
189
|
+
'subtotalRefunded',
|
|
190
|
+
'refundDiscount',
|
|
191
|
+
'refundShipping',
|
|
192
|
+
'totalTax',
|
|
193
|
+
'refundCreditDiscount',
|
|
194
|
+
'refundCurrency',
|
|
195
|
+
];
|
|
106
196
|
const presentmentAmountTypeFields = [
|
|
107
197
|
'totalRefundedPresentment',
|
|
108
198
|
'subtotalRefundedPresentment',
|
|
109
199
|
'refundDiscountPresentment',
|
|
110
200
|
'refundShippingPresentment',
|
|
111
201
|
'totalTaxPresentment',
|
|
202
|
+
'refundCreditDiscountPresentment',
|
|
203
|
+
'refundCurrencyPresentment',
|
|
112
204
|
];
|
|
113
205
|
if ([...amountTypeFields, ...presentmentAmountTypeFields].includes(fieldKey.toString())) {
|
|
114
206
|
inputValue = this.props[fieldKey] ? this.props[fieldKey].amount : 0;
|
|
115
207
|
}
|
|
116
|
-
|
|
117
|
-
if (fieldKey === 'subtotalRefunded' ||
|
|
118
|
-
fieldKey === 'refundDiscount' ||
|
|
119
|
-
fieldKey === 'refundShipping' ||
|
|
120
|
-
fieldKey === 'totalTax' ||
|
|
121
|
-
fieldKey === 'subtotalRefundedPresentment' ||
|
|
122
|
-
fieldKey === 'refundDiscountPresentment' ||
|
|
208
|
+
if (fieldKey === 'refundShipping' ||
|
|
123
209
|
fieldKey === 'refundShippingPresentment' ||
|
|
124
|
-
fieldKey === '
|
|
210
|
+
fieldKey === 'totalRefunded' ||
|
|
211
|
+
fieldKey === 'totalRefundedPresentment') {
|
|
125
212
|
onChangeHandler = (val) => {
|
|
126
213
|
this.fields[fieldKey].inputValue = String(val);
|
|
127
|
-
this.
|
|
214
|
+
this.updateRelatedField(fieldKey, Number(val || 0));
|
|
215
|
+
if (fieldKey === 'refundShipping' || fieldKey === 'refundShippingPresentment') {
|
|
216
|
+
this.updateTotalRefunded();
|
|
217
|
+
}
|
|
128
218
|
};
|
|
129
219
|
}
|
|
130
220
|
const valid = !!this.props[fieldKey];
|
|
@@ -140,7 +230,12 @@ class RefundFormState extends FormState_1.default {
|
|
|
140
230
|
let onChangeHandler = (val) => this.multiSelectChangeHandler(fieldKey, val);
|
|
141
231
|
if (fieldKey === 'refundLineItems') {
|
|
142
232
|
selectedValues = this.props.refundLineItems || [];
|
|
143
|
-
|
|
233
|
+
if (!selectedValues.length && ((_b = (_a = this.props.orderMoreInfo) === null || _a === void 0 ? void 0 : _a.activeLineItems) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
234
|
+
selectedValues = this.props.orderMoreInfo.activeLineItems.map((lineItemLike) => {
|
|
235
|
+
return this.getUpdatedRefundLineItem(lineItemLike);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
valid = (selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.length) > 0;
|
|
144
239
|
onChangeHandler = (val) => this.refundLineItemChangeHandler(val);
|
|
145
240
|
}
|
|
146
241
|
return {
|
|
@@ -5,7 +5,7 @@ export default class OrderHelpers {
|
|
|
5
5
|
getSalesChannelUsingTags(tags: string | null | undefined): string | null;
|
|
6
6
|
buildLineItemFromProduct(product: CompleteProduct, currencyCode: string, quantity?: number): ReRobeOrderLineItem;
|
|
7
7
|
toFixedPointPrice(price: number | string): string;
|
|
8
|
-
getAmountSumByField(array: OrderRefund[], fieldKey: string): number;
|
|
8
|
+
getAmountSumByField(array: OrderRefund[] | ReRobeOrderLineItem[], fieldKey: string): number;
|
|
9
9
|
getOrderInfoWithRefundsAndFulfillments(order: CompleteOrder): OrderWithRefundsAndFulfillmentsInfoObj;
|
|
10
10
|
getUpdatedOrderObjWithRefunds(orderObj: CompleteOrder, refundObj: OrderRefund): CompleteOrder;
|
|
11
11
|
getUpdatedOrderObjWithFulfillment(orderObj: CompleteOrder, fulfillmentObj: FulfillmentAdmin, totalUnfulfilledItems: number): CompleteOrder;
|
|
@@ -14,8 +14,104 @@ export default class OrderHelpers {
|
|
|
14
14
|
getSaleDiscount(lineItems?: ReRobeOrderLineItem[]): number;
|
|
15
15
|
getDiscountAmount(lineItems?: ReRobeOrderLineItem[], userAvailableCredit?: number | string): number;
|
|
16
16
|
getLineItemUnitOrderDiscount({ originalUnitPrice, totalDiscount, subtotalPrice, }: {
|
|
17
|
-
originalUnitPrice
|
|
17
|
+
originalUnitPrice?: Money;
|
|
18
18
|
totalDiscount?: Money;
|
|
19
19
|
subtotalPrice?: Money;
|
|
20
20
|
}): number;
|
|
21
|
+
generateDiscountTitle({ merchantName, saleDiscount, creditDiscount, additionalDiscount, currency, }: {
|
|
22
|
+
merchantName: string;
|
|
23
|
+
saleDiscount: number;
|
|
24
|
+
creditDiscount: number;
|
|
25
|
+
additionalDiscount: number;
|
|
26
|
+
currency: string;
|
|
27
|
+
}): string;
|
|
28
|
+
getSubtotalWithoutSalePrice(productsFullInfoWithQuantity?: {
|
|
29
|
+
product: CompleteProduct;
|
|
30
|
+
quantity: number;
|
|
31
|
+
}[]): number;
|
|
32
|
+
getSubtotalWithSalePriceIncluded(productsFullInfoWithQuantity?: {
|
|
33
|
+
product: CompleteProduct;
|
|
34
|
+
quantity: number;
|
|
35
|
+
}[]): number;
|
|
36
|
+
getSaleDiscountAmount(productsFullInfoWithQuantity: {
|
|
37
|
+
product: CompleteProduct;
|
|
38
|
+
quantity: number;
|
|
39
|
+
}[]): number;
|
|
40
|
+
preparePresentmentData({ merchantName, merchantCurrency, presentmentCurrencyCode, productsFullInfoWithQuantity, currencyConverter, saleDiscountAmount, creditDiscountAmount, additionalDiscount, shippingPrice, subTotalWithSalePriceIncluded, totalIncludingShipping, }: {
|
|
41
|
+
merchantName: string;
|
|
42
|
+
merchantCurrency: string;
|
|
43
|
+
presentmentCurrencyCode?: string;
|
|
44
|
+
productsFullInfoWithQuantity: {
|
|
45
|
+
product: CompleteProduct;
|
|
46
|
+
quantity: number;
|
|
47
|
+
}[];
|
|
48
|
+
currencyConverter?(v: number | string, roundUpTo?: number): number;
|
|
49
|
+
saleDiscountAmount: number;
|
|
50
|
+
creditDiscountAmount: number;
|
|
51
|
+
additionalDiscount: number;
|
|
52
|
+
shippingPrice: number;
|
|
53
|
+
subTotalWithSalePriceIncluded: number;
|
|
54
|
+
totalIncludingShipping: number;
|
|
55
|
+
}): {
|
|
56
|
+
discountTitlePresentment: string;
|
|
57
|
+
saleDiscountPresentment: {
|
|
58
|
+
amount: string;
|
|
59
|
+
currencyCode: string;
|
|
60
|
+
};
|
|
61
|
+
creditDiscountPresentment: {
|
|
62
|
+
amount: string;
|
|
63
|
+
currencyCode: string;
|
|
64
|
+
};
|
|
65
|
+
additionalDiscountPresentment: {
|
|
66
|
+
amount: string;
|
|
67
|
+
currencyCode: string;
|
|
68
|
+
};
|
|
69
|
+
lineItems: {
|
|
70
|
+
presentmentTotalPrice: {
|
|
71
|
+
amount: string;
|
|
72
|
+
currencyCode: string;
|
|
73
|
+
};
|
|
74
|
+
presentmentUnitPrice: {
|
|
75
|
+
amount: string;
|
|
76
|
+
currencyCode: string;
|
|
77
|
+
};
|
|
78
|
+
presentmentSalePrice: {
|
|
79
|
+
amount: string;
|
|
80
|
+
currencyCode: string;
|
|
81
|
+
};
|
|
82
|
+
brand?: string | null | undefined;
|
|
83
|
+
productId?: string | null | undefined;
|
|
84
|
+
shopifyProductId?: string | number | null | undefined;
|
|
85
|
+
refundedQuantity?: string | number | undefined;
|
|
86
|
+
canceledQuantity?: string | number | undefined;
|
|
87
|
+
fulfilledQuantity?: string | number | undefined;
|
|
88
|
+
unfulfilledQuantity?: string | number | undefined;
|
|
89
|
+
status?: string | undefined;
|
|
90
|
+
isOnSale?: string | undefined;
|
|
91
|
+
salePrice?: string | undefined;
|
|
92
|
+
title: string;
|
|
93
|
+
quantity: string | number;
|
|
94
|
+
variant: ProductVariant | null;
|
|
95
|
+
originalTotalPrice?: Money | undefined;
|
|
96
|
+
originalUnitPrice?: Money | undefined;
|
|
97
|
+
discountedTotalPrice?: Money | undefined;
|
|
98
|
+
image?: Image | undefined;
|
|
99
|
+
}[];
|
|
100
|
+
subtotalPricePresentment: {
|
|
101
|
+
amount: string;
|
|
102
|
+
currencyCode: string;
|
|
103
|
+
};
|
|
104
|
+
totalDiscountPresentment: {
|
|
105
|
+
amount: string;
|
|
106
|
+
currencyCode: string;
|
|
107
|
+
};
|
|
108
|
+
totalShippingPricePresentment: {
|
|
109
|
+
amount: string;
|
|
110
|
+
currencyCode: string;
|
|
111
|
+
};
|
|
112
|
+
totalPricePresentment: {
|
|
113
|
+
amount: string;
|
|
114
|
+
currencyCode: string;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
21
117
|
}
|
|
@@ -96,40 +96,49 @@ class OrderHelpers {
|
|
|
96
96
|
return array.map((item) => { var _a; return Number(((_a = item[fieldKey]) === null || _a === void 0 ? void 0 : _a.amount) || 0); }).reduce((a, b) => a + b, 0);
|
|
97
97
|
}
|
|
98
98
|
getOrderInfoWithRefundsAndFulfillments(order) {
|
|
99
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
99
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
100
100
|
const orderRefunds = order.refunds ? [...order.refunds] : [];
|
|
101
101
|
const orderFulfillment = order.fulfillments ? [...order.fulfillments] : [];
|
|
102
|
+
const subtotalPrice = Object.assign(Object.assign({}, order.subtotalPrice), { amount: this.getSubtotalPrice(order.lineItems) });
|
|
103
|
+
const subtotalPricePresentment = Object.assign(Object.assign({}, order.subtotalPricePresentment), { amount: this.getAmountSumByField(order.lineItems, 'presentmentTotalPrice') });
|
|
102
104
|
const preparedOrder = {
|
|
103
105
|
documentId: order.documentId || '',
|
|
104
106
|
name: order.name || '',
|
|
105
107
|
currencyCode: order.currencyCode,
|
|
106
108
|
fulfillmentStatus: order.fulfillmentStatus || '',
|
|
109
|
+
refunds: orderRefunds,
|
|
107
110
|
// Total prices
|
|
108
111
|
totalDiscount: order.totalDiscount ? Object.assign({}, order.totalDiscount) : { amount: 0 },
|
|
112
|
+
creditDiscount: order.creditDiscount ? Object.assign({}, order.creditDiscount) : { amount: 0 },
|
|
113
|
+
saleDiscount: order.saleDiscount ? Object.assign({}, order.saleDiscount) : { amount: 0 },
|
|
114
|
+
additionalDiscount: order.additionalDiscount ? Object.assign({}, order.additionalDiscount) : { amount: 0 },
|
|
109
115
|
totalTax: order.totalTax ? Object.assign({}, order.totalTax) : { amount: 0 },
|
|
110
|
-
subtotalPrice
|
|
116
|
+
subtotalPrice,
|
|
111
117
|
totalRefunded: order.totalRefunded ? Object.assign({}, order.totalRefunded) : { amount: 0 },
|
|
118
|
+
refundCurrency: Object.assign(Object.assign({}, order.totalRefunded), { amount: 0 }),
|
|
112
119
|
totalShippingPrice: order.totalShippingPrice ? Object.assign({}, order.totalShippingPrice) : { amount: 0 },
|
|
113
120
|
totalPrice: order.totalPrice ? Object.assign({}, order.totalPrice) : { amount: 0 },
|
|
114
121
|
// Total prices presentment prices
|
|
115
122
|
totalDiscountPresentment: order.totalDiscountPresentment ? Object.assign({}, order.totalDiscountPresentment) : { amount: 0 },
|
|
123
|
+
creditDiscountPresentment: order.creditDiscountPresentment
|
|
124
|
+
? Object.assign({}, order.creditDiscountPresentment) : { amount: 0 },
|
|
116
125
|
totalTaxPresentment: order.totalTaxPresentment ? Object.assign({}, order.totalTaxPresentment) : { amount: 0 },
|
|
117
|
-
subtotalPricePresentment
|
|
126
|
+
subtotalPricePresentment,
|
|
118
127
|
totalRefundedPresentment: order.totalRefundedPresentment ? Object.assign({}, order.totalRefundedPresentment) : { amount: 0 },
|
|
128
|
+
refundCurrencyPresentment: Object.assign(Object.assign({}, order.totalRefundedPresentment), { amount: 0 }),
|
|
119
129
|
totalShippingPricePresentment: order.totalShippingPricePresentment
|
|
120
130
|
? Object.assign({}, order.totalShippingPricePresentment) : { amount: 0 },
|
|
121
131
|
totalPricePresentment: order.totalPricePresentment ? Object.assign({}, order.totalPricePresentment) : { amount: 0 },
|
|
122
132
|
// Additional order info
|
|
133
|
+
discountType: ((_a = order.appliedDiscount) === null || _a === void 0 ? void 0 : _a.title) || 'Custom discount',
|
|
134
|
+
shippingRate: ((_c = (_b = order.fulfillmentLocations) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.shippingRateName) || 'Custom shipping rate',
|
|
123
135
|
activeLineItems: !order.lineItems || !order.lineItems.length
|
|
124
136
|
? []
|
|
125
137
|
: order.lineItems.map((item) => (Object.assign(Object.assign({}, item), { unfulfilledQuantity: Number(item.quantity), fulfilledQuantity: 0, refundedQuantity: 0, canceledQuantity: 0 }))),
|
|
126
|
-
discountType: ((_a = order.appliedDiscount) === null || _a === void 0 ? void 0 : _a.title) || 'Custom discount',
|
|
127
|
-
shippingRate: ((_c = (_b = order.fulfillmentLocations) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.shippingRateName) || 'Custom shipping rate',
|
|
128
138
|
unfulfilledItems: [],
|
|
129
139
|
fulfilledItems: [],
|
|
130
140
|
refundedItems: [],
|
|
131
141
|
canceledItems: [],
|
|
132
|
-
refunds: orderRefunds,
|
|
133
142
|
};
|
|
134
143
|
if (!preparedOrder.activeLineItems.length) {
|
|
135
144
|
return preparedOrder;
|
|
@@ -158,28 +167,35 @@ class OrderHelpers {
|
|
|
158
167
|
// Subtract existed refunds prices from total prices
|
|
159
168
|
preparedOrder.totalDiscount.amount =
|
|
160
169
|
Number(order.totalDiscount.amount) - this.getAmountSumByField(orderRefunds, 'refundDiscount');
|
|
170
|
+
preparedOrder.creditDiscount.amount =
|
|
171
|
+
Number(((_d = order.creditDiscount) === null || _d === void 0 ? void 0 : _d.amount) || 0) - this.getAmountSumByField(orderRefunds, 'refundCreditDiscount');
|
|
161
172
|
preparedOrder.totalTax.amount =
|
|
162
|
-
Number(((
|
|
173
|
+
Number(((_e = order.totalTax) === null || _e === void 0 ? void 0 : _e.amount) || 0) - this.getAmountSumByField(orderRefunds, 'totalTaxPresentment');
|
|
163
174
|
preparedOrder.subtotalPrice.amount =
|
|
164
|
-
Number(
|
|
175
|
+
Number(preparedOrder.subtotalPrice.amount) - this.getAmountSumByField(orderRefunds, 'subtotalRefunded');
|
|
165
176
|
preparedOrder.totalShippingPrice.amount =
|
|
166
|
-
Number(((
|
|
177
|
+
Number(((_f = order.totalShippingPrice) === null || _f === void 0 ? void 0 : _f.amount) || 0) - this.getAmountSumByField(orderRefunds, 'refundShipping');
|
|
167
178
|
preparedOrder.totalPrice.amount =
|
|
168
179
|
Number(order.totalPrice.amount) - this.getAmountSumByField(orderRefunds, 'totalRefunded');
|
|
180
|
+
preparedOrder.refundCurrency.amount = this.getAmountSumByField(orderRefunds, 'refundCurrency');
|
|
169
181
|
// Subtract existed refunds prices from total presentment prices
|
|
170
182
|
preparedOrder.totalDiscountPresentment.amount =
|
|
171
|
-
Number(((
|
|
183
|
+
Number(((_g = order.totalDiscountPresentment) === null || _g === void 0 ? void 0 : _g.amount) || 0) -
|
|
172
184
|
this.getAmountSumByField(orderRefunds, 'refundDiscountPresentment');
|
|
185
|
+
preparedOrder.creditDiscountPresentment.amount =
|
|
186
|
+
Number(((_h = order.creditDiscountPresentment) === null || _h === void 0 ? void 0 : _h.amount) || 0) -
|
|
187
|
+
this.getAmountSumByField(orderRefunds, 'refundCreditDiscountPresentment');
|
|
188
|
+
preparedOrder.refundCurrencyPresentment.amount = this.getAmountSumByField(orderRefunds, 'refundCurrencyPresentment');
|
|
173
189
|
preparedOrder.totalTaxPresentment.amount =
|
|
174
|
-
Number(((
|
|
190
|
+
Number(((_j = order.totalTaxPresentment) === null || _j === void 0 ? void 0 : _j.amount) || 0) - this.getAmountSumByField(orderRefunds, 'totalTaxPresentment');
|
|
175
191
|
preparedOrder.subtotalPricePresentment.amount =
|
|
176
|
-
Number(((
|
|
192
|
+
Number(((_k = preparedOrder.subtotalPricePresentment) === null || _k === void 0 ? void 0 : _k.amount) || 0) -
|
|
177
193
|
this.getAmountSumByField(orderRefunds, 'subtotalRefundedPresentment');
|
|
178
194
|
preparedOrder.totalShippingPricePresentment.amount =
|
|
179
|
-
Number(((
|
|
195
|
+
Number(((_l = order.totalShippingPricePresentment) === null || _l === void 0 ? void 0 : _l.amount) || 0) -
|
|
180
196
|
this.getAmountSumByField(orderRefunds, 'refundShippingPresentment');
|
|
181
197
|
preparedOrder.totalPricePresentment.amount =
|
|
182
|
-
Number(((
|
|
198
|
+
Number(((_m = order.totalPricePresentment) === null || _m === void 0 ? void 0 : _m.amount) || 0) -
|
|
183
199
|
this.getAmountSumByField(orderRefunds, 'totalRefundedPresentment');
|
|
184
200
|
const lineItemsWithQuantityInfo = preparedOrder.activeLineItems.map((item) => {
|
|
185
201
|
const currentItem = item.productId;
|
|
@@ -206,12 +222,13 @@ class OrderHelpers {
|
|
|
206
222
|
return preparedOrder;
|
|
207
223
|
}
|
|
208
224
|
getUpdatedOrderObjWithRefunds(orderObj, refundObj) {
|
|
209
|
-
|
|
210
|
-
const totalRefundedAmount = Number(
|
|
211
|
-
|
|
212
|
-
updatedOrder.totalRefunded
|
|
213
|
-
|
|
214
|
-
|
|
225
|
+
var _a, _b, _c;
|
|
226
|
+
const totalRefundedAmount = Number(((_a = orderObj.totalRefunded) === null || _a === void 0 ? void 0 : _a.amount) || 0) + Number(refundObj.totalRefunded.amount);
|
|
227
|
+
const totalRefundedPresentmentAmount = Number(((_b = orderObj.totalRefundedPresentment) === null || _b === void 0 ? void 0 : _b.amount) || 0) + Number(refundObj.totalRefundedPresentment.amount);
|
|
228
|
+
const updatedOrder = Object.assign(Object.assign({}, orderObj), { refunds: [...orderObj.refunds, Object.assign({}, refundObj)], totalRefunded: { amount: Number(totalRefundedAmount).toFixed(2), currencyCode: orderObj.currencyCode }, totalRefundedPresentment: {
|
|
229
|
+
amount: Number(totalRefundedPresentmentAmount).toFixed(2),
|
|
230
|
+
currencyCode: ((_c = orderObj.totalPricePresentment) === null || _c === void 0 ? void 0 : _c.currencyCode) || orderObj.currencyCode,
|
|
231
|
+
}, financialStatus: Number(orderObj.totalPrice.amount) - totalRefundedAmount > 0 ? 'PARTIALLY_REFUNDED' : 'REFUNDED' });
|
|
215
232
|
return updatedOrder;
|
|
216
233
|
}
|
|
217
234
|
getUpdatedOrderObjWithFulfillment(orderObj, fulfillmentObj, totalUnfulfilledItems) {
|
|
@@ -233,8 +250,9 @@ class OrderHelpers {
|
|
|
233
250
|
}
|
|
234
251
|
const subtotalWithoutSaleDiscount = lineItems.reduce((acc, lineItem) => {
|
|
235
252
|
var _a;
|
|
236
|
-
const isSaleItem = lineItem.isOnSale === 'yes'
|
|
237
|
-
const
|
|
253
|
+
const isSaleItem = lineItem.isOnSale === 'yes';
|
|
254
|
+
const totalSalePrice = Number(this.toFixedPointPrice(lineItem.salePrice || '')) * Number(lineItem.quantity || 1);
|
|
255
|
+
const itemPrice = isSaleItem ? totalSalePrice : ((_a = lineItem.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount) || 0;
|
|
238
256
|
return acc + Number(itemPrice);
|
|
239
257
|
}, 0);
|
|
240
258
|
let subtotal = subtotalWithoutSaleDiscount;
|
|
@@ -244,7 +262,7 @@ class OrderHelpers {
|
|
|
244
262
|
if (subtotal < 0) {
|
|
245
263
|
subtotal = 0;
|
|
246
264
|
}
|
|
247
|
-
return Number(
|
|
265
|
+
return Number(this.toFixedPointPrice(subtotal));
|
|
248
266
|
}
|
|
249
267
|
getCreditDiscount(lineItems = [], userAvailableCredit) {
|
|
250
268
|
if (!userAvailableCredit || Number(userAvailableCredit) <= 0) {
|
|
@@ -256,7 +274,7 @@ class OrderHelpers {
|
|
|
256
274
|
getSaleDiscount(lineItems = []) {
|
|
257
275
|
return lineItems.reduce((acc, cur) => {
|
|
258
276
|
var _a;
|
|
259
|
-
const isSaleItem = cur.isOnSale === 'yes'
|
|
277
|
+
const isSaleItem = cur.isOnSale === 'yes';
|
|
260
278
|
let prodDiscount = 0;
|
|
261
279
|
if (isSaleItem) {
|
|
262
280
|
prodDiscount = Number((Number((_a = cur.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount) - Number(cur.salePrice)).toFixed(2));
|
|
@@ -274,11 +292,128 @@ class OrderHelpers {
|
|
|
274
292
|
getLineItemUnitOrderDiscount({ originalUnitPrice, totalDiscount, subtotalPrice, }) {
|
|
275
293
|
const td = Number((totalDiscount === null || totalDiscount === void 0 ? void 0 : totalDiscount.amount) || 0);
|
|
276
294
|
const subT = Number((subtotalPrice === null || subtotalPrice === void 0 ? void 0 : subtotalPrice.amount) || 0);
|
|
277
|
-
const unitPrice = Number(originalUnitPrice.amount || 0);
|
|
295
|
+
const unitPrice = Number((originalUnitPrice === null || originalUnitPrice === void 0 ? void 0 : originalUnitPrice.amount) || 0);
|
|
278
296
|
if (subT === 0) {
|
|
279
297
|
return td;
|
|
280
298
|
}
|
|
281
299
|
return (td / subT) * unitPrice;
|
|
282
300
|
}
|
|
301
|
+
generateDiscountTitle({ merchantName, saleDiscount = 0, creditDiscount = 0, additionalDiscount = 0, currency, }) {
|
|
302
|
+
let discountTitle = '';
|
|
303
|
+
if (creditDiscount > 0) {
|
|
304
|
+
discountTitle = `${creditDiscount} ${currency} ${merchantName} Credits`;
|
|
305
|
+
}
|
|
306
|
+
if (saleDiscount > 0) {
|
|
307
|
+
const existedTitle = discountTitle ? `${discountTitle} + ` : '';
|
|
308
|
+
discountTitle = `${existedTitle}${saleDiscount} ${currency} Sale Discount`;
|
|
309
|
+
}
|
|
310
|
+
if (additionalDiscount > 0) {
|
|
311
|
+
const existedTitle = discountTitle ? `${discountTitle} + ` : '';
|
|
312
|
+
discountTitle = `${existedTitle}${additionalDiscount} ${currency} Additional Discount`;
|
|
313
|
+
}
|
|
314
|
+
return discountTitle;
|
|
315
|
+
}
|
|
316
|
+
getSubtotalWithoutSalePrice(productsFullInfoWithQuantity) {
|
|
317
|
+
if (!productsFullInfoWithQuantity || productsFullInfoWithQuantity.length === 0) {
|
|
318
|
+
return 0;
|
|
319
|
+
}
|
|
320
|
+
const cumsum = productsFullInfoWithQuantity
|
|
321
|
+
.map((i) => Number(i.product.price) * Number(i.quantity))
|
|
322
|
+
.reduce((a, b) => a + b, 0);
|
|
323
|
+
return Number(this.toFixedPointPrice(cumsum));
|
|
324
|
+
}
|
|
325
|
+
getSubtotalWithSalePriceIncluded(productsFullInfoWithQuantity) {
|
|
326
|
+
if (!productsFullInfoWithQuantity || productsFullInfoWithQuantity.length === 0) {
|
|
327
|
+
return 0;
|
|
328
|
+
}
|
|
329
|
+
const cumsum = productsFullInfoWithQuantity
|
|
330
|
+
.map((i) => {
|
|
331
|
+
const price = i.product.isOnSale && i.product.clearanceTimestamp ? i.product.salePrice : i.product.price;
|
|
332
|
+
return Number(price || 0) * Number(i.quantity);
|
|
333
|
+
})
|
|
334
|
+
.reduce((a, b) => a + b, 0);
|
|
335
|
+
return Number(this.toFixedPointPrice(cumsum));
|
|
336
|
+
}
|
|
337
|
+
getSaleDiscountAmount(productsFullInfoWithQuantity) {
|
|
338
|
+
return productsFullInfoWithQuantity
|
|
339
|
+
.map((i) => {
|
|
340
|
+
if (i.product.isOnSale === 'yes' && i.product.clearanceTimestamp && i.product.salePrice) {
|
|
341
|
+
const price = this.toFixedPointPrice(Number(i.product.price) - Number(i.product.salePrice));
|
|
342
|
+
return Number(price) * Number(i.quantity);
|
|
343
|
+
}
|
|
344
|
+
return 0;
|
|
345
|
+
})
|
|
346
|
+
.reduce((a, b) => a + b, 0);
|
|
347
|
+
}
|
|
348
|
+
preparePresentmentData({ merchantName, merchantCurrency, presentmentCurrencyCode = '', productsFullInfoWithQuantity, currencyConverter = (v) => Number(v), saleDiscountAmount, creditDiscountAmount, additionalDiscount, shippingPrice, subTotalWithSalePriceIncluded, totalIncludingShipping, }) {
|
|
349
|
+
const convertAndFixPrice = (v, roundUpTo = 1) => this.toFixedPointPrice(currencyConverter(Number(this.toFixedPointPrice(v || 0)), roundUpTo));
|
|
350
|
+
const prepareMoneyObj = (amount) => ({
|
|
351
|
+
amount: this.toFixedPointPrice(amount),
|
|
352
|
+
currencyCode: presentmentCurrencyCode || merchantCurrency,
|
|
353
|
+
});
|
|
354
|
+
let subtotalOriginalPresentment = 0;
|
|
355
|
+
const lineItems = productsFullInfoWithQuantity.map((item) => {
|
|
356
|
+
var _a;
|
|
357
|
+
const lineItem = this.buildLineItemFromProduct(item.product, merchantCurrency, item.quantity);
|
|
358
|
+
const presentmentUnitPrice = convertAndFixPrice((_a = lineItem.originalUnitPrice) === null || _a === void 0 ? void 0 : _a.amount, 5);
|
|
359
|
+
const presentmentSalePrice = convertAndFixPrice(lineItem.salePrice, 5);
|
|
360
|
+
const presentmentItemPrice = lineItem.isOnSale === 'yes' ? presentmentSalePrice : presentmentUnitPrice;
|
|
361
|
+
const presentmentTotalPrice = this.toFixedPointPrice(Number(presentmentItemPrice) * Number(item.quantity));
|
|
362
|
+
subtotalOriginalPresentment += Number(this.toFixedPointPrice(Number(presentmentUnitPrice) * Number(item.quantity)));
|
|
363
|
+
return Object.assign(Object.assign({}, lineItem), { presentmentTotalPrice: prepareMoneyObj(presentmentTotalPrice), presentmentUnitPrice: prepareMoneyObj(presentmentUnitPrice), presentmentSalePrice: prepareMoneyObj(presentmentSalePrice) });
|
|
364
|
+
});
|
|
365
|
+
if (!presentmentCurrencyCode || presentmentCurrencyCode === merchantCurrency) {
|
|
366
|
+
return {
|
|
367
|
+
discountTitlePresentment: this.generateDiscountTitle({
|
|
368
|
+
merchantName,
|
|
369
|
+
saleDiscount: saleDiscountAmount,
|
|
370
|
+
creditDiscount: creditDiscountAmount,
|
|
371
|
+
additionalDiscount,
|
|
372
|
+
currency: merchantCurrency,
|
|
373
|
+
}),
|
|
374
|
+
saleDiscountPresentment: prepareMoneyObj(saleDiscountAmount),
|
|
375
|
+
creditDiscountPresentment: prepareMoneyObj(creditDiscountAmount),
|
|
376
|
+
additionalDiscountPresentment: prepareMoneyObj(additionalDiscount),
|
|
377
|
+
lineItems,
|
|
378
|
+
subtotalPricePresentment: prepareMoneyObj(subTotalWithSalePriceIncluded - creditDiscountAmount - additionalDiscount),
|
|
379
|
+
totalDiscountPresentment: prepareMoneyObj(creditDiscountAmount + additionalDiscount),
|
|
380
|
+
totalShippingPricePresentment: prepareMoneyObj(shippingPrice),
|
|
381
|
+
totalPricePresentment: prepareMoneyObj(totalIncludingShipping),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const subtotalPricePresentmentWithSalePrice = lineItems
|
|
385
|
+
.map((i) => { var _a; return Number((_a = i.presentmentTotalPrice) === null || _a === void 0 ? void 0 : _a.amount); })
|
|
386
|
+
.reduce((a, b) => a + b, 0);
|
|
387
|
+
const saleDiscountPresentmentAmount = subtotalOriginalPresentment - subtotalPricePresentmentWithSalePrice;
|
|
388
|
+
const creditDiscountPresentmentAmount = convertAndFixPrice(creditDiscountAmount || 0);
|
|
389
|
+
const additionalDiscountPresentmentAmount = convertAndFixPrice(additionalDiscount || 0);
|
|
390
|
+
const totalShippingPricePresentmentAmount = convertAndFixPrice(shippingPrice || 0);
|
|
391
|
+
let subtotalPricePresentmentAmount = subtotalPricePresentmentWithSalePrice -
|
|
392
|
+
Number(creditDiscountPresentmentAmount) -
|
|
393
|
+
Number(additionalDiscountPresentmentAmount);
|
|
394
|
+
if (Number(subtotalPricePresentmentAmount) < 0) {
|
|
395
|
+
subtotalPricePresentmentAmount = 0;
|
|
396
|
+
}
|
|
397
|
+
if (Number(subtotalPricePresentmentAmount) < 3) {
|
|
398
|
+
subtotalPricePresentmentAmount = 3;
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
discountTitlePresentment: this.generateDiscountTitle({
|
|
402
|
+
merchantName,
|
|
403
|
+
saleDiscount: Number(saleDiscountPresentmentAmount),
|
|
404
|
+
creditDiscount: Number(creditDiscountPresentmentAmount),
|
|
405
|
+
additionalDiscount: Number(additionalDiscountPresentmentAmount),
|
|
406
|
+
currency: presentmentCurrencyCode || merchantCurrency,
|
|
407
|
+
}),
|
|
408
|
+
lineItems,
|
|
409
|
+
saleDiscountPresentment: prepareMoneyObj(saleDiscountPresentmentAmount),
|
|
410
|
+
creditDiscountPresentment: prepareMoneyObj(creditDiscountPresentmentAmount),
|
|
411
|
+
additionalDiscountPresentment: prepareMoneyObj(additionalDiscountPresentmentAmount),
|
|
412
|
+
subtotalPricePresentment: prepareMoneyObj(subtotalPricePresentmentAmount),
|
|
413
|
+
totalDiscountPresentment: prepareMoneyObj(Number(creditDiscountPresentmentAmount) + Number(additionalDiscountPresentmentAmount)),
|
|
414
|
+
totalShippingPricePresentment: prepareMoneyObj(totalShippingPricePresentmentAmount),
|
|
415
|
+
totalPricePresentment: prepareMoneyObj(Number(subtotalPricePresentmentAmount) + Number(totalShippingPricePresentmentAmount)),
|
|
416
|
+
};
|
|
417
|
+
}
|
|
283
418
|
}
|
|
284
419
|
exports.default = OrderHelpers;
|
package/lib/models/Order.d.ts
CHANGED
|
@@ -100,6 +100,7 @@ export default class Order extends Base {
|
|
|
100
100
|
createdAtTimestamp: number;
|
|
101
101
|
updatedAtTimestamp: number;
|
|
102
102
|
adjustments?: OrderAdjustment[];
|
|
103
|
+
createdByUserId?: string;
|
|
103
104
|
constructor(props?: any);
|
|
104
105
|
toObj(): ReRobeOrderObj;
|
|
105
106
|
generateSchemaForTypesense(name?: string): {
|
package/lib/models/Order.js
CHANGED
|
@@ -127,6 +127,7 @@ class Order extends Base_1.default {
|
|
|
127
127
|
this.createdAtTimestamp = (props === null || props === void 0 ? void 0 : props.createdAtTimestamp) || 0;
|
|
128
128
|
this.updatedAtTimestamp = (props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) || 0;
|
|
129
129
|
this.adjustments = (props === null || props === void 0 ? void 0 : props.adjustments) || [];
|
|
130
|
+
this.createdByUserId = (props === null || props === void 0 ? void 0 : props.createdByUserId) || '';
|
|
130
131
|
}
|
|
131
132
|
toObj() {
|
|
132
133
|
const orderObj = {
|
|
@@ -199,6 +200,9 @@ class Order extends Base_1.default {
|
|
|
199
200
|
if (this.paymentMethod) {
|
|
200
201
|
orderObj.paymentMethod = this.paymentMethod;
|
|
201
202
|
}
|
|
203
|
+
if (this.createdByUserId) {
|
|
204
|
+
orderObj.createdByUserId = this.createdByUserId;
|
|
205
|
+
}
|
|
202
206
|
return orderObj;
|
|
203
207
|
}
|
|
204
208
|
generateSchemaForTypesense(name = 'prod_orders_20220809') {
|
package/lib/models/Refund.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export default class Refund extends Base {
|
|
|
4
4
|
totalRefunded: Money;
|
|
5
5
|
subtotalRefunded: Money;
|
|
6
6
|
refundDiscount?: Money;
|
|
7
|
+
refundCreditDiscount?: Money;
|
|
8
|
+
refundCurrency?: Money;
|
|
7
9
|
refundShipping?: Money;
|
|
8
10
|
totalTax?: Money;
|
|
9
11
|
refundLineItems: RefundLineItem[];
|
|
@@ -11,12 +13,15 @@ export default class Refund extends Base {
|
|
|
11
13
|
totalRefundedPresentment: Money;
|
|
12
14
|
subtotalRefundedPresentment?: Money;
|
|
13
15
|
refundDiscountPresentment?: Money;
|
|
16
|
+
refundCreditDiscountPresentment?: Money;
|
|
17
|
+
refundCurrencyPresentment?: Money;
|
|
14
18
|
refundShippingPresentment?: Money;
|
|
15
19
|
totalTaxPresentment?: Money;
|
|
16
20
|
createdAtTimestamp?: number;
|
|
17
21
|
updatedAtTimestamp?: number;
|
|
18
22
|
createdAt?: string;
|
|
19
23
|
updatedAt?: string;
|
|
24
|
+
createdByUserId?: string;
|
|
20
25
|
constructor(props?: any);
|
|
21
26
|
toObj(): OrderRefund;
|
|
22
27
|
}
|
package/lib/models/Refund.js
CHANGED
|
@@ -8,6 +8,8 @@ class Refund extends Base_1.default {
|
|
|
8
8
|
this.totalRefunded = (props === null || props === void 0 ? void 0 : props.totalRefunded) || { amount: 0 };
|
|
9
9
|
this.subtotalRefunded = (props === null || props === void 0 ? void 0 : props.subtotalRefunded) || { amount: 0 };
|
|
10
10
|
this.refundDiscount = (props === null || props === void 0 ? void 0 : props.refundDiscount) || { amount: 0 };
|
|
11
|
+
this.refundCreditDiscount = (props === null || props === void 0 ? void 0 : props.refundCreditDiscount) || { amount: 0 };
|
|
12
|
+
this.refundCurrency = (props === null || props === void 0 ? void 0 : props.refundCurrency) || { amount: 0 };
|
|
11
13
|
this.refundShipping = (props === null || props === void 0 ? void 0 : props.refundShipping) || { amount: 0 };
|
|
12
14
|
this.totalTax = (props === null || props === void 0 ? void 0 : props.totalTax) || { amount: 0 };
|
|
13
15
|
this.refundLineItems = (props === null || props === void 0 ? void 0 : props.refundLineItems) || [];
|
|
@@ -15,18 +17,23 @@ class Refund extends Base_1.default {
|
|
|
15
17
|
this.totalRefundedPresentment = (props === null || props === void 0 ? void 0 : props.totalRefundedPresentment) || { amount: 0 };
|
|
16
18
|
this.subtotalRefundedPresentment = (props === null || props === void 0 ? void 0 : props.subtotalRefundedPresentment) || { amount: 0 };
|
|
17
19
|
this.refundDiscountPresentment = (props === null || props === void 0 ? void 0 : props.refundDiscountPresentment) || { amount: 0 };
|
|
20
|
+
this.refundCreditDiscountPresentment = (props === null || props === void 0 ? void 0 : props.refundCreditDiscountPresentment) || { amount: 0 };
|
|
21
|
+
this.refundCurrencyPresentment = (props === null || props === void 0 ? void 0 : props.refundCurrencyPresentment) || { amount: 0 };
|
|
18
22
|
this.refundShippingPresentment = (props === null || props === void 0 ? void 0 : props.refundShippingPresentment) || { amount: 0 };
|
|
19
23
|
this.totalTaxPresentment = (props === null || props === void 0 ? void 0 : props.totalTaxPresentment) || { amount: 0 };
|
|
20
24
|
this.createdAtTimestamp = (props === null || props === void 0 ? void 0 : props.createdAtTimestamp) || 0;
|
|
21
25
|
this.updatedAtTimestamp = (props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) || 0;
|
|
22
26
|
this.createdAt = (props === null || props === void 0 ? void 0 : props.createdAt) || '';
|
|
23
27
|
this.updatedAt = (props === null || props === void 0 ? void 0 : props.updatedAt) || '';
|
|
28
|
+
this.createdByUserId = (props === null || props === void 0 ? void 0 : props.createdByUserId) || '';
|
|
24
29
|
}
|
|
25
30
|
toObj() {
|
|
26
31
|
const refundObj = {
|
|
27
32
|
documentId: this.documentId,
|
|
28
33
|
totalRefunded: this.totalRefunded,
|
|
29
34
|
refundDiscount: this.refundDiscount,
|
|
35
|
+
refundCreditDiscount: this.refundCreditDiscount,
|
|
36
|
+
refundCurrency: this.refundCurrency,
|
|
30
37
|
subtotalRefunded: this.subtotalRefunded,
|
|
31
38
|
refundShipping: this.refundShipping,
|
|
32
39
|
totalTax: this.totalTax,
|
|
@@ -35,10 +42,13 @@ class Refund extends Base_1.default {
|
|
|
35
42
|
totalRefundedPresentment: this.totalRefundedPresentment,
|
|
36
43
|
subtotalRefundedPresentment: this.subtotalRefundedPresentment,
|
|
37
44
|
refundDiscountPresentment: this.refundDiscountPresentment,
|
|
45
|
+
refundCreditDiscountPresentment: this.refundCreditDiscountPresentment,
|
|
46
|
+
refundCurrencyPresentment: this.refundCurrencyPresentment,
|
|
38
47
|
refundShippingPresentment: this.refundShippingPresentment,
|
|
39
48
|
totalTaxPresentment: this.totalTaxPresentment,
|
|
40
49
|
createdAtTimestamp: this.createdAtTimestamp,
|
|
41
50
|
createdAt: this.createdAt,
|
|
51
|
+
createdByUserId: this.createdByUserId,
|
|
42
52
|
};
|
|
43
53
|
if (this.createdAt) {
|
|
44
54
|
refundObj.createdAt = this.createdAt;
|
|
@@ -66,6 +66,7 @@ declare type ReRobeOrderObj = {
|
|
|
66
66
|
customerName?: string;
|
|
67
67
|
merchantId?: string;
|
|
68
68
|
refunds?: OrderRefund[];
|
|
69
|
+
createdByUserId?: string;
|
|
69
70
|
createdAt?: string;
|
|
70
71
|
updatedAt?: string;
|
|
71
72
|
subtotalPricePresentment?: Money;
|
|
@@ -87,8 +88,12 @@ declare type OrderWithRefundsAndFulfillmentsInfoObj = {
|
|
|
87
88
|
currencyCode: string;
|
|
88
89
|
fulfillmentStatus?: FulfillmentStatusTypes | string;
|
|
89
90
|
totalDiscount: Money;
|
|
91
|
+
creditDiscount: Money;
|
|
92
|
+
saleDiscount?: Money;
|
|
93
|
+
additionalDiscount?: Money;
|
|
90
94
|
totalPrice: Money;
|
|
91
95
|
totalRefunded?: Money;
|
|
96
|
+
refundCurrency?: Money;
|
|
92
97
|
totalShippingPrice?: Money;
|
|
93
98
|
totalTax?: Money;
|
|
94
99
|
subtotalPrice: Money;
|
|
@@ -102,10 +107,14 @@ declare type OrderWithRefundsAndFulfillmentsInfoObj = {
|
|
|
102
107
|
canceledItems: ReRobeOrderLineItem[];
|
|
103
108
|
subtotalPricePresentment: Money;
|
|
104
109
|
totalDiscountPresentment: Money;
|
|
110
|
+
creditDiscountPresentment: Money;
|
|
111
|
+
saleDiscountPresentment?: Money;
|
|
112
|
+
additionalDiscountPresentment?: Money;
|
|
105
113
|
totalPricePresentment: Money;
|
|
106
114
|
totalRefundedPresentment: Money;
|
|
115
|
+
refundCurrencyPresentment?: Money;
|
|
107
116
|
totalShippingPricePresentment: Money;
|
|
108
|
-
totalTaxPresentment
|
|
117
|
+
totalTaxPresentment?: Money;
|
|
109
118
|
};
|
|
110
119
|
declare type OrderInput = {
|
|
111
120
|
id?: string | null;
|
|
@@ -333,6 +342,8 @@ declare type OrderRefund = {
|
|
|
333
342
|
totalRefunded: Money;
|
|
334
343
|
subtotalRefunded?: Money;
|
|
335
344
|
refundDiscount?: Money;
|
|
345
|
+
refundCreditDiscount?: Money;
|
|
346
|
+
refundCurrency?: Money;
|
|
336
347
|
refundShipping?: Money;
|
|
337
348
|
totalTax?: Money;
|
|
338
349
|
refundLineItems: RefundLineItem[];
|
|
@@ -340,19 +351,24 @@ declare type OrderRefund = {
|
|
|
340
351
|
totalRefundedPresentment: Money;
|
|
341
352
|
subtotalRefundedPresentment?: Money;
|
|
342
353
|
refundDiscountPresentment?: Money;
|
|
354
|
+
refundCreditDiscountPresentment?: Money;
|
|
355
|
+
refundCurrencyPresentment?: Money;
|
|
343
356
|
refundShippingPresentment?: Money;
|
|
344
357
|
totalTaxPresentment?: Money;
|
|
345
358
|
createdAtTimestamp?: number;
|
|
346
359
|
updatedAtTimestamp?: number;
|
|
360
|
+
createdByUserId?: string;
|
|
347
361
|
};
|
|
348
362
|
declare type RefundLineItem = {
|
|
349
363
|
lineItem: ReRobeOrderLineItem;
|
|
350
364
|
quantityRefund: number;
|
|
351
365
|
quantityCancel: number;
|
|
352
366
|
discountRefund?: Money;
|
|
367
|
+
creditDiscountRefund?: Money;
|
|
353
368
|
subtotalRefund?: Money;
|
|
354
369
|
subtotalCanceled?: Money;
|
|
355
370
|
discountRefundPresentment?: Money;
|
|
371
|
+
creditDiscountRefundPresentment?: Money;
|
|
356
372
|
subtotalRefundPresentment?: Money;
|
|
357
373
|
subtotalCanceledPresentment?: Money;
|
|
358
374
|
};
|
|
@@ -756,6 +772,8 @@ declare type OrderRefundFormFields = {
|
|
|
756
772
|
totalRefunded: TextInputFormField<string | number>;
|
|
757
773
|
subtotalRefunded: TextInputFormField<string | number>;
|
|
758
774
|
refundDiscount: TextInputFormField<string | number>;
|
|
775
|
+
refundCreditDiscount: TextInputFormField<string | number>;
|
|
776
|
+
refundCurrency: TextInputFormField<string | number>;
|
|
759
777
|
refundShipping: TextInputFormField<string | number>;
|
|
760
778
|
totalTax: TextInputFormField<string | number>;
|
|
761
779
|
refundLineItems: MultiSelectFormField<RefundLineItem>;
|
|
@@ -763,6 +781,8 @@ declare type OrderRefundFormFields = {
|
|
|
763
781
|
totalRefundedPresentment: TextInputFormField<string | number>;
|
|
764
782
|
subtotalRefundedPresentment: TextInputFormField<string | number>;
|
|
765
783
|
refundDiscountPresentment: TextInputFormField<string | number>;
|
|
784
|
+
refundCreditDiscountPresentment: TextInputFormField<string | number>;
|
|
785
|
+
refundCurrencyPresentment: TextInputFormField<string | number>;
|
|
766
786
|
refundShippingPresentment: TextInputFormField<string | number>;
|
|
767
787
|
totalTaxPresentment: TextInputFormField<string | number>;
|
|
768
788
|
};
|