rerobe-js-orm 4.8.2 → 4.8.3

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.
@@ -47,12 +47,15 @@ export default class OrderHelpers {
47
47
  getPaymentTerminalReceiptInfo(payload?: any): PaymentTerminalReceiptInfo;
48
48
  getFormattedFulfillmentLocation(order: ReRobeOrderObj): string;
49
49
  generateReceiptLabels(locale: string, paymentMethod: string, entryMode?: string): ReceiptLabels;
50
- buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl, receiptNumber, additionalInfo, }: {
50
+ buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl, receiptNumber, additionalInfo, isRefund, refundId, originalReceiptNumber, }: {
51
51
  order: ReRobeOrderObj;
52
52
  merchant: MerchantObj;
53
53
  merchantLogoUrl: string;
54
54
  receiptNumber: string;
55
55
  additionalInfo: string;
56
+ isRefund?: boolean;
57
+ refundId?: string | null;
58
+ originalReceiptNumber?: string | null;
56
59
  }): ReceiptObj;
57
60
  /**
58
61
  * Generates an idempotency key from a ReRobeOrderObj to prevent duplicate order creation
@@ -579,23 +579,29 @@ class OrderHelpers {
579
579
  entryModeLabel,
580
580
  };
581
581
  }
582
- buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl = '', receiptNumber = '', additionalInfo = '', }) {
583
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
582
+ buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl = '', receiptNumber = '', additionalInfo = '', isRefund = false, refundId = null, originalReceiptNumber = null, }) {
583
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
584
584
  const { address: merchantAddress, legalName, name, contactEmail, phone = '', organizationNumber = '', primaryDomain, currency: storeCurrencyCode, returnPolicy, } = merchant;
585
585
  const currencyCode = ((_a = order.totalPricePresentment) === null || _a === void 0 ? void 0 : _a.currencyCode) || storeCurrencyCode;
586
586
  const presentmentLocale = (0, Utilities_1.getPresentmentLocaleByCurrencyCode)(currencyCode);
587
587
  const mapLineItem = (l) => {
588
- var _a, _b, _c;
588
+ var _a, _b, _c, _d, _e;
589
589
  let totalPrice = Number((_a = l.presentmentTotalPrice) === null || _a === void 0 ? void 0 : _a.amount);
590
590
  if (l.isTaxable && l.taxRate) {
591
591
  const taxRate = Number(l.taxRate);
592
592
  totalPrice *= 1 + taxRate;
593
593
  }
594
+ if (isRefund) {
595
+ totalPrice = -Math.abs(totalPrice);
596
+ }
594
597
  let title = l.title || l.brand || '';
595
598
  if (Number(l === null || l === void 0 ? void 0 : l.quantity) > 1) {
599
+ const unitPrice = isRefund
600
+ ? -Math.abs(Number((_c = (_b = l === null || l === void 0 ? void 0 : l.originalUnitPrice) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0))
601
+ : (_e = (_d = l === null || l === void 0 ? void 0 : l.originalUnitPrice) === null || _d === void 0 ? void 0 : _d.amount) !== null && _e !== void 0 ? _e : '';
596
602
  title += `\n${Number(l === null || l === void 0 ? void 0 : l.quantity)} x ${(0, Utilities_1.formatPrice)({
597
603
  currencyCode,
598
- amount: (_c = (_b = l === null || l === void 0 ? void 0 : l.originalUnitPrice) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : '',
604
+ amount: unitPrice,
599
605
  fractionDigits: 2,
600
606
  })}`;
601
607
  }
@@ -642,7 +648,8 @@ class OrderHelpers {
642
648
  if (!acc[cur.taxRate]) {
643
649
  acc[cur.taxRate] = 0;
644
650
  }
645
- acc[cur.taxRate] += Number(cur.taxAmount);
651
+ const amount = Number(cur.taxAmount);
652
+ acc[cur.taxRate] += isRefund ? -Math.abs(amount) : amount;
646
653
  acc[cur.taxRate] = parseFloat(acc[cur.taxRate].toFixed(2));
647
654
  }
648
655
  return acc;
@@ -664,31 +671,42 @@ class OrderHelpers {
664
671
  };
665
672
  const paymentTerminalInfo = this.getPaymentTerminalReceiptInfo(order);
666
673
  const receiptLabels = this.generateReceiptLabels(presentmentLocale, (_b = order.paymentType) !== null && _b !== void 0 ? _b : '', (_c = paymentTerminalInfo.entryMode) !== null && _c !== void 0 ? _c : '');
674
+ if (isRefund) {
675
+ receiptLabels.receiptLabel = translations_1.refundReceiptTranslations[presentmentLocale] || translations_1.refundReceiptTranslations['en-US'];
676
+ receiptLabels.purchaseLabel =
677
+ translations_1.refundPurchaseTranslations[presentmentLocale] || translations_1.refundPurchaseTranslations['en-US'];
678
+ }
667
679
  let info = additionalInfo;
668
- if (returnPolicy) {
680
+ if (returnPolicy && !isRefund) {
669
681
  info = `${returnPolicy}`;
670
682
  if (additionalInfo) {
671
683
  info = `${info}\n\n${additionalInfo}`;
672
684
  }
673
685
  }
686
+ const negateForRefund = (amount) => {
687
+ if (!isRefund)
688
+ return amount;
689
+ const num = Number(amount);
690
+ return isNaN(num) ? amount : -Math.abs(num);
691
+ };
674
692
  return Object.assign(Object.assign({ merchantLogoUrl, merchantName: name, legalName, storeAddress: buildStoreAddress(), phone,
675
693
  contactEmail,
676
694
  organizationNumber,
677
- primaryDomain, storeUrl: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale, order === null || order === void 0 ? void 0 : order.createdAtTimestamp), receiptNumber, additionalInfo: info, lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
695
+ primaryDomain, storeUrl: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale, order === null || order === void 0 ? void 0 : order.createdAtTimestamp), receiptNumber, additionalInfo: info, isRefund, originalReceiptNumber: originalReceiptNumber || null, originalReceiptLabel: translations_1.originalReceiptTranslations[presentmentLocale] || translations_1.originalReceiptTranslations['en-US'], lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
678
696
  currencyCode,
679
- amount: (_e = (_d = order.subtotalPricePresentment) === null || _d === void 0 ? void 0 : _d.amount) !== null && _e !== void 0 ? _e : '',
697
+ amount: (_f = negateForRefund((_e = (_d = order.subtotalPricePresentment) === null || _d === void 0 ? void 0 : _d.amount) !== null && _e !== void 0 ? _e : '')) !== null && _f !== void 0 ? _f : '',
680
698
  fractionDigits: 2,
681
699
  }), total: (0, Utilities_1.formatPrice)({
682
700
  currencyCode,
683
- amount: (_g = (_f = order.totalPricePresentment) === null || _f === void 0 ? void 0 : _f.amount) !== null && _g !== void 0 ? _g : '',
701
+ amount: (_j = negateForRefund((_h = (_g = order.totalPricePresentment) === null || _g === void 0 ? void 0 : _g.amount) !== null && _h !== void 0 ? _h : '')) !== null && _j !== void 0 ? _j : '',
684
702
  fractionDigits: 2,
685
703
  }), amountPaid: (0, Utilities_1.formatPrice)({
686
704
  currencyCode,
687
- amount: (_j = (_h = order.totalPricePresentment) === null || _h === void 0 ? void 0 : _h.amount) !== null && _j !== void 0 ? _j : '',
705
+ amount: (_m = negateForRefund((_l = (_k = order.totalPricePresentment) === null || _k === void 0 ? void 0 : _k.amount) !== null && _l !== void 0 ? _l : '')) !== null && _m !== void 0 ? _m : '',
688
706
  fractionDigits: 2,
689
707
  }), tax: (0, Utilities_1.formatPrice)({
690
708
  currencyCode,
691
- amount: (_l = (_k = order.totalTaxPresentment) === null || _k === void 0 ? void 0 : _k.amount) !== null && _l !== void 0 ? _l : '',
709
+ amount: (_q = negateForRefund((_p = (_o = order.totalTaxPresentment) === null || _o === void 0 ? void 0 : _o.amount) !== null && _p !== void 0 ? _p : '')) !== null && _q !== void 0 ? _q : '',
692
710
  fractionDigits: 2,
693
711
  }), taxRates: formattedTaxRates }, paymentTerminalInfo), receiptLabels);
694
712
  }
@@ -28,3 +28,12 @@ export declare const contactlessTranslations: {
28
28
  export declare const referenceTranslations: {
29
29
  [key: string]: string;
30
30
  };
31
+ export declare const refundReceiptTranslations: {
32
+ [key: string]: string;
33
+ };
34
+ export declare const refundPurchaseTranslations: {
35
+ [key: string]: string;
36
+ };
37
+ export declare const originalReceiptTranslations: {
38
+ [key: string]: string;
39
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.referenceTranslations = exports.contactlessTranslations = exports.authorizationCodeTranslations = exports.mobilePaymentTranslations = exports.cardPaymentTranslations = exports.cashTranslations = exports.purchaseTranslations = exports.taxTranslations = exports.totalTranslations = exports.receiptTranslations = void 0;
3
+ exports.originalReceiptTranslations = exports.refundPurchaseTranslations = exports.refundReceiptTranslations = exports.referenceTranslations = exports.contactlessTranslations = exports.authorizationCodeTranslations = exports.mobilePaymentTranslations = exports.cardPaymentTranslations = exports.cashTranslations = exports.purchaseTranslations = exports.taxTranslations = exports.totalTranslations = exports.receiptTranslations = void 0;
4
4
  exports.receiptTranslations = {
5
5
  'sv-SE': 'Kvitto',
6
6
  'nb-NO': 'Kvittering',
@@ -71,3 +71,24 @@ exports.referenceTranslations = {
71
71
  'en-UK': 'Reference',
72
72
  'en-DE': 'Referenz',
73
73
  };
74
+ exports.refundReceiptTranslations = {
75
+ 'sv-SE': 'RETUR',
76
+ 'nb-NO': 'RETUR',
77
+ 'en-US': 'REFUND',
78
+ 'en-UK': 'REFUND',
79
+ 'en-DE': 'RÜCKERSTATTUNG',
80
+ };
81
+ exports.refundPurchaseTranslations = {
82
+ 'sv-SE': 'Retur',
83
+ 'nb-NO': 'Retur',
84
+ 'en-US': 'Refund',
85
+ 'en-UK': 'Refund',
86
+ 'en-DE': 'Rückerstattung',
87
+ };
88
+ exports.originalReceiptTranslations = {
89
+ 'sv-SE': 'Originalkvitto',
90
+ 'nb-NO': 'Originalkvittering',
91
+ 'en-US': 'Original receipt',
92
+ 'en-UK': 'Original receipt',
93
+ 'en-DE': 'Originalquittung',
94
+ };
@@ -75,6 +75,9 @@ type ReceiptObj = {
75
75
  [key: string]: string;
76
76
  };
77
77
  additionalInfo: string;
78
+ isRefund?: boolean;
79
+ originalReceiptNumber?: string | null;
80
+ originalReceiptLabel?: string;
78
81
  } & ReceiptLabelsAndPaymentTerminalInfo;
79
82
  type ReceiptLog = {
80
83
  createdAtTimestamp: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.8.2",
3
+ "version": "4.8.3",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",