rerobe-js-orm 3.6.0 → 3.6.1
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.
|
@@ -3,7 +3,7 @@ export default class OrderHelpers {
|
|
|
3
3
|
getShippingTypeFromShopifyObj(shippingLines: ShippingLineRest[] | null | undefined): string;
|
|
4
4
|
getPaymentTypeUsingTags(tags: string | null | undefined): string | null;
|
|
5
5
|
getSalesChannelUsingTags(tags: string | null | undefined): string | null;
|
|
6
|
-
buildLineItemFromProduct(product: CompleteProduct, currencyCode: string, quantity?: number): ReRobeOrderLineItem;
|
|
6
|
+
buildLineItemFromProduct(product: CompleteProduct, currencyCode: string, quantity?: number, taxProps?: RibbnTaxProps): ReRobeOrderLineItem;
|
|
7
7
|
toFixedPointPrice(price: number | string): string;
|
|
8
8
|
getAmountSumByField(array: OrderRefund[] | ReRobeOrderLineItem[], fieldKey: string): number;
|
|
9
9
|
getOrderInfoWithRefundsAndFulfillments(order: CompleteOrder): OrderWithRefundsAndFulfillmentsInfoObj;
|
|
@@ -25,33 +25,24 @@ export default class OrderHelpers {
|
|
|
25
25
|
additionalDiscount: number;
|
|
26
26
|
currency: string;
|
|
27
27
|
}): string;
|
|
28
|
-
getSubtotalWithoutSalePrice(productsFullInfoWithQuantity?:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
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, }: {
|
|
28
|
+
getSubtotalWithoutSalePrice(productsFullInfoWithQuantity?: ProductsFullInfoWithQuantity): number;
|
|
29
|
+
getSubtotalWithSalePriceIncluded(productsFullInfoWithQuantity?: ProductsFullInfoWithQuantity): number;
|
|
30
|
+
getSaleDiscountAmount(productsFullInfoWithQuantity: ProductsFullInfoWithQuantity): number;
|
|
31
|
+
preparePresentmentData({ merchantName, merchantCurrency, presentmentCurrencyCode, productsFullInfoWithQuantity, currencyConverter, saleDiscountAmount, creditDiscountAmount, additionalDiscount, shippingPrice, itemsTax, shippingFeeTax, subTotalWithSalePriceIncluded, totalIncludingShipping, totalIncludingShippingAndTaxes, }: {
|
|
41
32
|
merchantName: string;
|
|
42
33
|
merchantCurrency: string;
|
|
43
34
|
presentmentCurrencyCode?: string;
|
|
44
|
-
productsFullInfoWithQuantity:
|
|
45
|
-
product: CompleteProduct;
|
|
46
|
-
quantity: number;
|
|
47
|
-
}[];
|
|
35
|
+
productsFullInfoWithQuantity: ProductsFullInfoWithQuantity;
|
|
48
36
|
currencyConverter?(v: number | string, roundUpTo?: number): number;
|
|
49
37
|
saleDiscountAmount: number;
|
|
50
38
|
creditDiscountAmount: number;
|
|
51
39
|
additionalDiscount: number;
|
|
52
40
|
shippingPrice: number;
|
|
41
|
+
itemsTax: number;
|
|
42
|
+
shippingFeeTax: number;
|
|
53
43
|
subTotalWithSalePriceIncluded: number;
|
|
54
44
|
totalIncludingShipping: number;
|
|
45
|
+
totalIncludingShippingAndTaxes: number;
|
|
55
46
|
}): {
|
|
56
47
|
discountTitlePresentment: string;
|
|
57
48
|
saleDiscountPresentment: {
|
|
@@ -88,9 +79,85 @@ export default class OrderHelpers {
|
|
|
88
79
|
unfulfilledQuantity?: string | number | undefined;
|
|
89
80
|
status?: string | undefined;
|
|
90
81
|
isOnSale?: string | undefined;
|
|
91
|
-
isTaxable?: string | undefined;
|
|
92
82
|
salePrice?: string | undefined;
|
|
93
83
|
presentmentTaxPrice?: Money | undefined;
|
|
84
|
+
isTaxable?: boolean | undefined;
|
|
85
|
+
taxRate?: number | undefined;
|
|
86
|
+
fromCountry?: string | undefined;
|
|
87
|
+
toCountry?: string | undefined;
|
|
88
|
+
taxAmount?: Money | undefined;
|
|
89
|
+
discountedPrice?: Money | undefined;
|
|
90
|
+
taxAmountWithDiscount?: Money | undefined;
|
|
91
|
+
title: string;
|
|
92
|
+
quantity: string | number;
|
|
93
|
+
variant: ProductVariant | null;
|
|
94
|
+
originalTotalPrice?: Money | undefined;
|
|
95
|
+
originalUnitPrice?: Money | undefined;
|
|
96
|
+
discountedTotalPrice?: Money | undefined;
|
|
97
|
+
image?: Image | undefined;
|
|
98
|
+
}[];
|
|
99
|
+
subtotalPricePresentment: {
|
|
100
|
+
amount: string;
|
|
101
|
+
currencyCode: string;
|
|
102
|
+
};
|
|
103
|
+
totalDiscountPresentment: {
|
|
104
|
+
amount: string;
|
|
105
|
+
currencyCode: string;
|
|
106
|
+
};
|
|
107
|
+
totalShippingPricePresentment: {
|
|
108
|
+
amount: string;
|
|
109
|
+
currencyCode: string;
|
|
110
|
+
};
|
|
111
|
+
itemsTaxPresentment: {
|
|
112
|
+
amount: string;
|
|
113
|
+
currencyCode: string;
|
|
114
|
+
};
|
|
115
|
+
shippingFeeTax: {
|
|
116
|
+
amount: string;
|
|
117
|
+
currencyCode: string;
|
|
118
|
+
};
|
|
119
|
+
totalTaxPresentment: {
|
|
120
|
+
amount: string;
|
|
121
|
+
currencyCode: string;
|
|
122
|
+
};
|
|
123
|
+
totalPricePresentment: {
|
|
124
|
+
amount: string;
|
|
125
|
+
currencyCode: string;
|
|
126
|
+
};
|
|
127
|
+
shippingFeeTaxPresentment?: undefined;
|
|
128
|
+
} | {
|
|
129
|
+
discountTitlePresentment: string;
|
|
130
|
+
lineItems: {
|
|
131
|
+
presentmentTotalPrice: {
|
|
132
|
+
amount: string;
|
|
133
|
+
currencyCode: string;
|
|
134
|
+
};
|
|
135
|
+
presentmentUnitPrice: {
|
|
136
|
+
amount: string;
|
|
137
|
+
currencyCode: string;
|
|
138
|
+
};
|
|
139
|
+
presentmentSalePrice: {
|
|
140
|
+
amount: string;
|
|
141
|
+
currencyCode: string;
|
|
142
|
+
};
|
|
143
|
+
brand?: string | null | undefined;
|
|
144
|
+
productId?: string | null | undefined;
|
|
145
|
+
shopifyProductId?: string | number | null | undefined;
|
|
146
|
+
refundedQuantity?: string | number | undefined;
|
|
147
|
+
canceledQuantity?: string | number | undefined;
|
|
148
|
+
fulfilledQuantity?: string | number | undefined;
|
|
149
|
+
unfulfilledQuantity?: string | number | undefined;
|
|
150
|
+
status?: string | undefined;
|
|
151
|
+
isOnSale?: string | undefined;
|
|
152
|
+
salePrice?: string | undefined;
|
|
153
|
+
presentmentTaxPrice?: Money | undefined;
|
|
154
|
+
isTaxable?: boolean | undefined;
|
|
155
|
+
taxRate?: number | undefined;
|
|
156
|
+
fromCountry?: string | undefined;
|
|
157
|
+
toCountry?: string | undefined;
|
|
158
|
+
taxAmount?: Money | undefined;
|
|
159
|
+
discountedPrice?: Money | undefined;
|
|
160
|
+
taxAmountWithDiscount?: Money | undefined;
|
|
94
161
|
title: string;
|
|
95
162
|
quantity: string | number;
|
|
96
163
|
variant: ProductVariant | null;
|
|
@@ -99,6 +166,18 @@ export default class OrderHelpers {
|
|
|
99
166
|
discountedTotalPrice?: Money | undefined;
|
|
100
167
|
image?: Image | undefined;
|
|
101
168
|
}[];
|
|
169
|
+
saleDiscountPresentment: {
|
|
170
|
+
amount: string;
|
|
171
|
+
currencyCode: string;
|
|
172
|
+
};
|
|
173
|
+
creditDiscountPresentment: {
|
|
174
|
+
amount: string;
|
|
175
|
+
currencyCode: string;
|
|
176
|
+
};
|
|
177
|
+
additionalDiscountPresentment: {
|
|
178
|
+
amount: string;
|
|
179
|
+
currencyCode: string;
|
|
180
|
+
};
|
|
102
181
|
subtotalPricePresentment: {
|
|
103
182
|
amount: string;
|
|
104
183
|
currencyCode: string;
|
|
@@ -115,5 +194,18 @@ export default class OrderHelpers {
|
|
|
115
194
|
amount: string;
|
|
116
195
|
currencyCode: string;
|
|
117
196
|
};
|
|
197
|
+
itemsTaxPresentment: {
|
|
198
|
+
amount: string;
|
|
199
|
+
currencyCode: string;
|
|
200
|
+
};
|
|
201
|
+
shippingFeeTaxPresentment: {
|
|
202
|
+
amount: string;
|
|
203
|
+
currencyCode: string;
|
|
204
|
+
};
|
|
205
|
+
totalTaxPresentment: {
|
|
206
|
+
amount: string;
|
|
207
|
+
currencyCode: string;
|
|
208
|
+
};
|
|
209
|
+
shippingFeeTax?: undefined;
|
|
118
210
|
};
|
|
119
211
|
}
|
|
@@ -62,8 +62,17 @@ class OrderHelpers {
|
|
|
62
62
|
}
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
|
-
buildLineItemFromProduct(product, currencyCode, quantity = 1) {
|
|
65
|
+
buildLineItemFromProduct(product, currencyCode, quantity = 1, taxProps = {}) {
|
|
66
66
|
const q = quantity || 1;
|
|
67
|
+
const getImgSrc = () => {
|
|
68
|
+
if (product.imageUrls && !!product.imageUrls.length) {
|
|
69
|
+
return product.imageUrls[0];
|
|
70
|
+
}
|
|
71
|
+
if (product.sellRequestImageUrls && !!product.sellRequestImageUrls.length) {
|
|
72
|
+
return product.sellRequestImageUrls[0];
|
|
73
|
+
}
|
|
74
|
+
return '';
|
|
75
|
+
};
|
|
67
76
|
return {
|
|
68
77
|
title: product.title,
|
|
69
78
|
quantity: q,
|
|
@@ -80,13 +89,29 @@ class OrderHelpers {
|
|
|
80
89
|
currencyCode,
|
|
81
90
|
},
|
|
82
91
|
image: {
|
|
83
|
-
originalSrc:
|
|
92
|
+
originalSrc: getImgSrc(),
|
|
84
93
|
},
|
|
85
94
|
shopifyProductId: product.shopifyId || null,
|
|
86
95
|
productId: product.documentId,
|
|
87
96
|
status: product.status || '',
|
|
88
97
|
isOnSale: product.isOnSale === 'yes' && product.clearanceTimestamp ? 'yes' : '',
|
|
89
98
|
salePrice: product.salePrice || '',
|
|
99
|
+
isTaxable: Boolean((taxProps === null || taxProps === void 0 ? void 0 : taxProps.isTaxable) || ''),
|
|
100
|
+
taxAmount: {
|
|
101
|
+
amount: Number(Number((taxProps === null || taxProps === void 0 ? void 0 : taxProps.taxAmount) || 0).toFixed(2)),
|
|
102
|
+
currencyCode,
|
|
103
|
+
},
|
|
104
|
+
taxRate: (taxProps === null || taxProps === void 0 ? void 0 : taxProps.taxRate) || 0,
|
|
105
|
+
fromCountry: (taxProps === null || taxProps === void 0 ? void 0 : taxProps.fromCountry) || '',
|
|
106
|
+
toCountry: (taxProps === null || taxProps === void 0 ? void 0 : taxProps.toCountry) || '',
|
|
107
|
+
discountedPrice: {
|
|
108
|
+
amount: Number(Number((taxProps === null || taxProps === void 0 ? void 0 : taxProps.discountedPrice) || product.price).toFixed(2)),
|
|
109
|
+
currencyCode,
|
|
110
|
+
},
|
|
111
|
+
taxAmountWithDiscount: {
|
|
112
|
+
amount: Number(Number((taxProps === null || taxProps === void 0 ? void 0 : taxProps.taxAmountWithDiscount) || 0).toFixed(2)),
|
|
113
|
+
currencyCode,
|
|
114
|
+
},
|
|
90
115
|
};
|
|
91
116
|
}
|
|
92
117
|
toFixedPointPrice(price) {
|
|
@@ -346,16 +371,26 @@ class OrderHelpers {
|
|
|
346
371
|
})
|
|
347
372
|
.reduce((a, b) => a + b, 0);
|
|
348
373
|
}
|
|
349
|
-
preparePresentmentData({ merchantName, merchantCurrency, presentmentCurrencyCode = '', productsFullInfoWithQuantity, currencyConverter = (v) => Number(v), saleDiscountAmount, creditDiscountAmount, additionalDiscount, shippingPrice, subTotalWithSalePriceIncluded, totalIncludingShipping, }) {
|
|
374
|
+
preparePresentmentData({ merchantName, merchantCurrency, presentmentCurrencyCode = '', productsFullInfoWithQuantity, currencyConverter = (v) => Number(v), saleDiscountAmount, creditDiscountAmount, additionalDiscount, shippingPrice, itemsTax, shippingFeeTax, subTotalWithSalePriceIncluded, totalIncludingShipping, totalIncludingShippingAndTaxes, }) {
|
|
350
375
|
const convertAndFixPrice = (v, roundUpTo = 1) => this.toFixedPointPrice(currencyConverter(Number(this.toFixedPointPrice(v || 0)), roundUpTo));
|
|
351
376
|
const prepareMoneyObj = (amount) => ({
|
|
352
377
|
amount: this.toFixedPointPrice(amount),
|
|
353
378
|
currencyCode: presentmentCurrencyCode || merchantCurrency,
|
|
354
379
|
});
|
|
355
380
|
let subtotalOriginalPresentment = 0;
|
|
381
|
+
const totalTax = Number(itemsTax || 0) + Number(shippingFeeTax || 0);
|
|
356
382
|
const lineItems = productsFullInfoWithQuantity.map((item) => {
|
|
357
383
|
var _a;
|
|
358
|
-
const lineItem = this.buildLineItemFromProduct(item.product, merchantCurrency, item.quantity
|
|
384
|
+
const lineItem = this.buildLineItemFromProduct(item.product, merchantCurrency, item.quantity, {
|
|
385
|
+
price: item.price,
|
|
386
|
+
isTaxable: item.isTaxable,
|
|
387
|
+
taxAmount: item.taxAmount,
|
|
388
|
+
taxRate: item.taxRate,
|
|
389
|
+
fromCountry: item.fromCountry,
|
|
390
|
+
toCountry: item.toCountry,
|
|
391
|
+
discountedPrice: item.discountedPrice,
|
|
392
|
+
taxAmountWithDiscount: item.taxAmountWithDiscount,
|
|
393
|
+
});
|
|
359
394
|
const presentmentUnitPrice = convertAndFixPrice((_a = lineItem.originalUnitPrice) === null || _a === void 0 ? void 0 : _a.amount, 5);
|
|
360
395
|
const presentmentSalePrice = convertAndFixPrice(lineItem.salePrice, 5);
|
|
361
396
|
const presentmentItemPrice = lineItem.isOnSale === 'yes' ? presentmentSalePrice : presentmentUnitPrice;
|
|
@@ -379,7 +414,10 @@ class OrderHelpers {
|
|
|
379
414
|
subtotalPricePresentment: prepareMoneyObj(subTotalWithSalePriceIncluded - creditDiscountAmount - additionalDiscount),
|
|
380
415
|
totalDiscountPresentment: prepareMoneyObj(creditDiscountAmount + additionalDiscount),
|
|
381
416
|
totalShippingPricePresentment: prepareMoneyObj(shippingPrice),
|
|
382
|
-
|
|
417
|
+
itemsTaxPresentment: prepareMoneyObj(itemsTax),
|
|
418
|
+
shippingFeeTax: prepareMoneyObj(shippingFeeTax),
|
|
419
|
+
totalTaxPresentment: prepareMoneyObj(totalTax),
|
|
420
|
+
totalPricePresentment: prepareMoneyObj(totalIncludingShippingAndTaxes || totalIncludingShipping),
|
|
383
421
|
};
|
|
384
422
|
}
|
|
385
423
|
const subtotalPricePresentmentWithSalePrice = lineItems
|
|
@@ -389,6 +427,9 @@ class OrderHelpers {
|
|
|
389
427
|
const creditDiscountPresentmentAmount = convertAndFixPrice(creditDiscountAmount || 0);
|
|
390
428
|
const additionalDiscountPresentmentAmount = convertAndFixPrice(additionalDiscount || 0);
|
|
391
429
|
const totalShippingPricePresentmentAmount = convertAndFixPrice(shippingPrice || 0);
|
|
430
|
+
const itemsTaxPresentmentAmount = convertAndFixPrice(itemsTax || 0);
|
|
431
|
+
const shippingFeeTaxPresentmentAmount = convertAndFixPrice(shippingFeeTax || 0);
|
|
432
|
+
const totalTaxPresentmentAmount = convertAndFixPrice(totalTax || 0);
|
|
392
433
|
let subtotalPricePresentmentAmount = subtotalPricePresentmentWithSalePrice -
|
|
393
434
|
Number(creditDiscountPresentmentAmount) -
|
|
394
435
|
Number(additionalDiscountPresentmentAmount);
|
|
@@ -413,7 +454,12 @@ class OrderHelpers {
|
|
|
413
454
|
subtotalPricePresentment: prepareMoneyObj(subtotalPricePresentmentAmount),
|
|
414
455
|
totalDiscountPresentment: prepareMoneyObj(Number(creditDiscountPresentmentAmount) + Number(additionalDiscountPresentmentAmount)),
|
|
415
456
|
totalShippingPricePresentment: prepareMoneyObj(totalShippingPricePresentmentAmount),
|
|
416
|
-
totalPricePresentment: prepareMoneyObj(Number(subtotalPricePresentmentAmount) +
|
|
457
|
+
totalPricePresentment: prepareMoneyObj(Number(subtotalPricePresentmentAmount) +
|
|
458
|
+
Number(totalShippingPricePresentmentAmount) +
|
|
459
|
+
Number(totalTaxPresentmentAmount)),
|
|
460
|
+
itemsTaxPresentment: prepareMoneyObj(itemsTaxPresentmentAmount),
|
|
461
|
+
shippingFeeTaxPresentment: prepareMoneyObj(shippingFeeTaxPresentmentAmount),
|
|
462
|
+
totalTaxPresentment: prepareMoneyObj(totalTaxPresentmentAmount),
|
|
417
463
|
};
|
|
418
464
|
}
|
|
419
465
|
}
|
|
@@ -228,6 +228,21 @@ type MoneyBag = {
|
|
|
228
228
|
shopMoney: Money;
|
|
229
229
|
presentmentMoney?: Money;
|
|
230
230
|
};
|
|
231
|
+
type RibbnTaxProps = {
|
|
232
|
+
price?: number;
|
|
233
|
+
isTaxable?: boolean;
|
|
234
|
+
taxAmount?: number;
|
|
235
|
+
taxRate?: number;
|
|
236
|
+
fromCountry?: string;
|
|
237
|
+
toCountry?: string;
|
|
238
|
+
discountedPrice?: number;
|
|
239
|
+
taxAmountWithDiscount?: number;
|
|
240
|
+
};
|
|
241
|
+
type ProductsFullInfoWithQuantity = ({
|
|
242
|
+
product: CompleteProduct;
|
|
243
|
+
quantity: number;
|
|
244
|
+
price?: number;
|
|
245
|
+
} & RibbnTaxProps)[];
|
|
231
246
|
interface OrderLineItem {
|
|
232
247
|
title: string;
|
|
233
248
|
quantity: number | string;
|
|
@@ -247,12 +262,18 @@ interface ReRobeOrderLineItem extends OrderLineItem {
|
|
|
247
262
|
unfulfilledQuantity?: number | string;
|
|
248
263
|
status?: ProductSellStatusKeys | string;
|
|
249
264
|
isOnSale?: string;
|
|
250
|
-
isTaxable?: string;
|
|
251
265
|
salePrice?: string;
|
|
252
266
|
presentmentTotalPrice?: Money;
|
|
253
267
|
presentmentUnitPrice?: Money;
|
|
254
268
|
presentmentSalePrice?: Money;
|
|
255
269
|
presentmentTaxPrice?: Money;
|
|
270
|
+
isTaxable?: boolean;
|
|
271
|
+
taxRate?: number;
|
|
272
|
+
fromCountry?: string;
|
|
273
|
+
toCountry?: string;
|
|
274
|
+
taxAmount?: Money;
|
|
275
|
+
discountedPrice?: Money;
|
|
276
|
+
taxAmountWithDiscount?: Money;
|
|
256
277
|
}
|
|
257
278
|
type OrderLineItemConnection = {
|
|
258
279
|
edges: OrderLineItemEdge[];
|