rerobe-js-orm 3.8.0 → 3.8.2
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.
|
@@ -217,8 +217,9 @@ export default class OrderHelpers {
|
|
|
217
217
|
getPaymentTerminalReceiptInfo(payload?: any): PaymentTerminalReceiptInfo;
|
|
218
218
|
getFormattedFulfillmentLocation(order: ReRobeOrderObj): string;
|
|
219
219
|
generateReceiptLabels(locale: string, paymentMethod: string, entryMethod?: string): ReceiptLabels;
|
|
220
|
-
buildReceiptObjFromOrder({ order, merchant }: {
|
|
220
|
+
buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl, }: {
|
|
221
221
|
order: ReRobeOrderObj;
|
|
222
222
|
merchant: MerchantObj;
|
|
223
|
+
merchantLogoUrl: string;
|
|
223
224
|
}): ReceiptObj;
|
|
224
225
|
}
|
|
@@ -545,7 +545,7 @@ class OrderHelpers {
|
|
|
545
545
|
entryMethodLabel,
|
|
546
546
|
};
|
|
547
547
|
}
|
|
548
|
-
buildReceiptObjFromOrder({ order, merchant }) {
|
|
548
|
+
buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl = '', }) {
|
|
549
549
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
550
550
|
const { address: merchantAddress, legalName, contactEmail, phone = '', organizationNumber = '', primaryDomain, currency: storeCurrencyCode, } = merchant;
|
|
551
551
|
const currencyCode = ((_a = order.totalPricePresentment) === null || _a === void 0 ? void 0 : _a.currencyCode) || storeCurrencyCode;
|
|
@@ -598,6 +598,35 @@ class OrderHelpers {
|
|
|
598
598
|
}
|
|
599
599
|
return result;
|
|
600
600
|
};
|
|
601
|
+
const taxRates = order.lineItems
|
|
602
|
+
.map((lineItem) => {
|
|
603
|
+
var _a;
|
|
604
|
+
if (lineItem.isTaxable) {
|
|
605
|
+
return {
|
|
606
|
+
taxRate: lineItem.taxRate,
|
|
607
|
+
taxAmount: ((_a = lineItem.taxAmountWithDiscount) === null || _a === void 0 ? void 0 : _a.amount) || 0,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
return {};
|
|
611
|
+
})
|
|
612
|
+
.reduce((acc, cur) => {
|
|
613
|
+
if (cur.taxRate) {
|
|
614
|
+
if (!acc[cur.taxRate]) {
|
|
615
|
+
acc[cur.taxRate] = 0;
|
|
616
|
+
}
|
|
617
|
+
acc[cur.taxRate] += Number(cur.taxAmount);
|
|
618
|
+
acc[cur.taxRate] = parseFloat(acc[cur.taxRate].toFixed(2));
|
|
619
|
+
}
|
|
620
|
+
return acc;
|
|
621
|
+
}, {});
|
|
622
|
+
const formattedTaxRates = Object.keys(taxRates).reduce((formattedAcc, taxRate) => {
|
|
623
|
+
formattedAcc[taxRate] = (0, Utilities_1.formatPrice)({
|
|
624
|
+
currencyCode,
|
|
625
|
+
amount: taxRates[taxRate],
|
|
626
|
+
fractionDigits: 2,
|
|
627
|
+
});
|
|
628
|
+
return formattedAcc;
|
|
629
|
+
}, {});
|
|
601
630
|
const buildStoreAddress = () => {
|
|
602
631
|
let address = this.getFormattedFulfillmentLocation(order);
|
|
603
632
|
if (!address) {
|
|
@@ -606,7 +635,7 @@ class OrderHelpers {
|
|
|
606
635
|
return address;
|
|
607
636
|
};
|
|
608
637
|
const paymentMethod = (_b = order.paymentMethod) !== null && _b !== void 0 ? _b : '';
|
|
609
|
-
return Object.assign(Object.assign({ merchantName: legalName, storeAddress: buildStoreAddress(), phone,
|
|
638
|
+
return Object.assign(Object.assign({ merchantLogoUrl, merchantName: legalName, storeAddress: buildStoreAddress(), phone,
|
|
610
639
|
contactEmail,
|
|
611
640
|
organizationNumber, primaryDomain: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale), lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
|
|
612
641
|
currencyCode,
|
|
@@ -620,7 +649,7 @@ class OrderHelpers {
|
|
|
620
649
|
currencyCode,
|
|
621
650
|
amount: (_h = (_g = order.totalTaxPresentment) === null || _g === void 0 ? void 0 : _g.amount) !== null && _h !== void 0 ? _h : '',
|
|
622
651
|
fractionDigits: 2,
|
|
623
|
-
}) }, this.generateReceiptLabels(presentmentLocale, paymentMethod)), this.getPaymentTerminalReceiptInfo(order));
|
|
652
|
+
}), taxRates: formattedTaxRates }, this.generateReceiptLabels(presentmentLocale, paymentMethod)), this.getPaymentTerminalReceiptInfo(order));
|
|
624
653
|
}
|
|
625
654
|
}
|
|
626
655
|
exports.default = OrderHelpers;
|
|
@@ -46,7 +46,7 @@ type ReceiptLineItem = {
|
|
|
46
46
|
quantity: number;
|
|
47
47
|
unitPrice: string;
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
interface ReceiptLabels {
|
|
50
50
|
receiptLabel: string;
|
|
51
51
|
totalLabel: string;
|
|
52
52
|
taxLabel: string;
|
|
@@ -55,8 +55,10 @@ type ReceiptLabels = {
|
|
|
55
55
|
entryMethodLabel: string;
|
|
56
56
|
authorizationCodeLabel: string;
|
|
57
57
|
referenceLabel: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
58
|
+
}
|
|
59
|
+
type ReceiptLabelsAndPaymentTerminalInfo = ReceiptLabels & PaymentTerminalReceiptInfo;
|
|
60
|
+
interface ReceiptObj extends ReceiptLabelsAndPaymentTerminalInfo {
|
|
61
|
+
merchantLogoUrl: string;
|
|
60
62
|
merchantName: string;
|
|
61
63
|
storeAddress: string;
|
|
62
64
|
phone: string;
|
|
@@ -68,8 +70,9 @@ interface ReceiptObj extends PaymentTerminalReceiptInfo {
|
|
|
68
70
|
subTotal: string;
|
|
69
71
|
amountPaid: string;
|
|
70
72
|
tax: string;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
taxRates: {
|
|
74
|
+
[key: string]: string;
|
|
75
|
+
};
|
|
73
76
|
}
|
|
74
77
|
type ReRobeOrderObj = {
|
|
75
78
|
id: string;
|