rerobe-js-orm 3.7.9 → 3.8.0

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.
@@ -8,6 +8,8 @@ export namespace PAYMENT_TYPES {
8
8
  const klarna: string;
9
9
  const swish: string;
10
10
  const shoppingCredit: string;
11
+ const cash: string;
12
+ const mobilePayment: string;
11
13
  }
12
14
  export namespace ORDER_STATES {
13
15
  const draft: string;
@@ -11,6 +11,8 @@ exports.PAYMENT_TYPES = {
11
11
  klarna: 'KLARNA',
12
12
  swish: 'SWISH',
13
13
  shoppingCredit: 'SHOPPING_CREDIT',
14
+ cash: 'CASH',
15
+ mobilePayment: 'MOBILE_PAYMENT',
14
16
  };
15
17
  exports.ORDER_STATES = {
16
18
  draft: 'DRAFT',
@@ -216,34 +216,9 @@ export default class OrderHelpers {
216
216
  };
217
217
  getPaymentTerminalReceiptInfo(payload?: any): PaymentTerminalReceiptInfo;
218
218
  getFormattedFulfillmentLocation(order: ReRobeOrderObj): string;
219
+ generateReceiptLabels(locale: string, paymentMethod: string, entryMethod?: string): ReceiptLabels;
219
220
  buildReceiptObjFromOrder({ order, merchant }: {
220
221
  order: ReRobeOrderObj;
221
222
  merchant: MerchantObj;
222
- }): {
223
- aid: string;
224
- tvr: string;
225
- authorizationCode: string;
226
- entryMode: string;
227
- applicationName: string;
228
- cardBrand: string;
229
- lastFour: string;
230
- referenceNumber: string;
231
- merchantName: string;
232
- storeAddress: string;
233
- phone: string;
234
- contactEmail: string;
235
- organizationNumber: string | undefined;
236
- primaryDomain: string;
237
- orderDate: string;
238
- lineItems: {
239
- title: string;
240
- price: string;
241
- quantity: string | number;
242
- showUnitPrice: boolean;
243
- unitPrice: string;
244
- }[];
245
- subTotal: string;
246
- amountPaid: string;
247
- tax: string;
248
- };
223
+ }): ReceiptObj;
249
224
  }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Order_1 = require("../models/Order");
4
4
  const Utilities_1 = require("../helpers/Utilities");
5
+ const order_constants_1 = require("../constants/order-constants");
6
+ const translations_1 = require("../translations");
5
7
  class OrderHelpers {
6
8
  getOrderIdFromShopifyObj(order) {
7
9
  const { id, tags } = order;
@@ -519,13 +521,37 @@ class OrderHelpers {
519
521
  const location = (_a = fulfillmentLocations[0]) === null || _a === void 0 ? void 0 : _a.location;
520
522
  return (0, Utilities_1.convertAddressInputToFormatted)(location);
521
523
  }
524
+ generateReceiptLabels(locale, paymentMethod, entryMethod = '') {
525
+ let paymentMethodLabel = translations_1.cardPaymentTranslations[locale] || translations_1.cardPaymentTranslations['en-US'];
526
+ if (paymentMethod === order_constants_1.PAYMENT_TYPES.cash) {
527
+ paymentMethodLabel = translations_1.cashTranslations[locale] || translations_1.cashTranslations['en-US'];
528
+ }
529
+ if (paymentMethod === order_constants_1.PAYMENT_TYPES.mobilePayment) {
530
+ paymentMethodLabel = translations_1.mobilePaymentTranslations[locale] || translations_1.mobilePaymentTranslations['en-US'];
531
+ }
532
+ let entryMethodLabel = '';
533
+ const contactlessRegex = /contactless|kontaktlos|kontaktløs|kontaktlös|contact-less/i;
534
+ if (contactlessRegex.test(entryMethod)) {
535
+ entryMethodLabel = translations_1.contactlessTranslations[locale] || translations_1.contactlessTranslations['en-US'];
536
+ }
537
+ return {
538
+ receiptLabel: translations_1.receiptTranslations[locale] || translations_1.receiptTranslations['en-US'],
539
+ totalLabel: translations_1.totalTranslations[locale] || translations_1.totalTranslations['en-US'],
540
+ taxLabel: translations_1.taxTranslations[locale] || translations_1.taxTranslations['en-US'],
541
+ purchaseLabel: translations_1.purchaseTranslations[locale] || translations_1.purchaseTranslations['en-US'],
542
+ authorizationCodeLabel: translations_1.authorizationCodeTranslations[locale] || translations_1.authorizationCodeTranslations['en-US'],
543
+ referenceLabel: translations_1.referenceTranslations[locale] || translations_1.referenceTranslations['en-US'],
544
+ paymentMethodLabel,
545
+ entryMethodLabel,
546
+ };
547
+ }
522
548
  buildReceiptObjFromOrder({ order, merchant }) {
523
- var _a, _b, _c, _d, _e, _f, _g;
524
- const { address: merchantAddress, legalName, contactEmail, phone, organizationNumber, primaryDomain, currency: storeCurrencyCode, } = merchant;
549
+ var _a, _b, _c, _d, _e, _f, _g, _h;
550
+ const { address: merchantAddress, legalName, contactEmail, phone = '', organizationNumber = '', primaryDomain, currency: storeCurrencyCode, } = merchant;
525
551
  const currencyCode = ((_a = order.totalPricePresentment) === null || _a === void 0 ? void 0 : _a.currencyCode) || storeCurrencyCode;
526
552
  const presentmentLocale = (0, Utilities_1.getPresentmentLocaleByCurrencyCode)(currencyCode);
527
553
  const mapLineItem = (l) => {
528
- var _a, _b, _c;
554
+ var _a, _b, _c, _d;
529
555
  let totalPrice = Number((_a = l.presentmentTotalPrice) === null || _a === void 0 ? void 0 : _a.amount);
530
556
  if (l.isTaxable && l.taxRate) {
531
557
  const taxRate = Number(l.taxRate);
@@ -538,11 +564,11 @@ class OrderHelpers {
538
564
  amount: totalPrice,
539
565
  fractionDigits: 2,
540
566
  }),
541
- quantity: l === null || l === void 0 ? void 0 : l.quantity,
567
+ quantity: Number((_b = l === null || l === void 0 ? void 0 : l.quantity) !== null && _b !== void 0 ? _b : 0),
542
568
  showUnitPrice: Number(l === null || l === void 0 ? void 0 : l.quantity) > 1,
543
569
  unitPrice: (0, Utilities_1.formatPrice)({
544
570
  currencyCode,
545
- 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 : '',
571
+ amount: (_d = (_c = l === null || l === void 0 ? void 0 : l.originalUnitPrice) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : '',
546
572
  fractionDigits: 2,
547
573
  }),
548
574
  };
@@ -579,22 +605,22 @@ class OrderHelpers {
579
605
  }
580
606
  return address;
581
607
  };
582
- return Object.assign({ merchantName: legalName, storeAddress: buildStoreAddress(), phone,
608
+ const paymentMethod = (_b = order.paymentMethod) !== null && _b !== void 0 ? _b : '';
609
+ return Object.assign(Object.assign({ merchantName: legalName, storeAddress: buildStoreAddress(), phone,
583
610
  contactEmail,
584
- organizationNumber,
585
- primaryDomain, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale), lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
611
+ organizationNumber, primaryDomain: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale), lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
586
612
  currencyCode,
587
- amount: (_c = (_b = order.subtotalPricePresentment) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : '',
613
+ amount: (_d = (_c = order.subtotalPricePresentment) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : '',
588
614
  fractionDigits: 2,
589
615
  }), amountPaid: (0, Utilities_1.formatPrice)({
590
616
  currencyCode,
591
- amount: (_e = (_d = order.totalPricePresentment) === null || _d === void 0 ? void 0 : _d.amount) !== null && _e !== void 0 ? _e : '',
617
+ amount: (_f = (_e = order.totalPricePresentment) === null || _e === void 0 ? void 0 : _e.amount) !== null && _f !== void 0 ? _f : '',
592
618
  fractionDigits: 2,
593
619
  }), tax: (0, Utilities_1.formatPrice)({
594
620
  currencyCode,
595
- amount: (_g = (_f = order.totalTaxPresentment) === null || _f === void 0 ? void 0 : _f.amount) !== null && _g !== void 0 ? _g : '',
621
+ amount: (_h = (_g = order.totalTaxPresentment) === null || _g === void 0 ? void 0 : _g.amount) !== null && _h !== void 0 ? _h : '',
596
622
  fractionDigits: 2,
597
- }) }, this.getPaymentTerminalReceiptInfo(order));
623
+ }) }, this.generateReceiptLabels(presentmentLocale, paymentMethod)), this.getPaymentTerminalReceiptInfo(order));
598
624
  }
599
625
  }
600
626
  exports.default = OrderHelpers;
@@ -10,6 +10,8 @@ export default class Order extends Base {
10
10
  klarna: string;
11
11
  swish: string;
12
12
  shoppingCredit: string;
13
+ cash: string;
14
+ mobilePayment: string;
13
15
  };
14
16
  static ORDER_STATES: {
15
17
  draft: string;
@@ -0,0 +1,30 @@
1
+ export declare const receiptTranslations: {
2
+ [key: string]: string;
3
+ };
4
+ export declare const totalTranslations: {
5
+ [key: string]: string;
6
+ };
7
+ export declare const taxTranslations: {
8
+ [key: string]: string;
9
+ };
10
+ export declare const purchaseTranslations: {
11
+ [key: string]: string;
12
+ };
13
+ export declare const cashTranslations: {
14
+ [key: string]: string;
15
+ };
16
+ export declare const cardPaymentTranslations: {
17
+ [key: string]: string;
18
+ };
19
+ export declare const mobilePaymentTranslations: {
20
+ [key: string]: string;
21
+ };
22
+ export declare const authorizationCodeTranslations: {
23
+ [key: string]: string;
24
+ };
25
+ export declare const contactlessTranslations: {
26
+ [key: string]: string;
27
+ };
28
+ export declare const referenceTranslations: {
29
+ [key: string]: string;
30
+ };
@@ -0,0 +1,73 @@
1
+ "use strict";
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;
4
+ exports.receiptTranslations = {
5
+ 'sv-SE': 'Kvitto',
6
+ 'nb-NO': 'Kvittering',
7
+ 'en-US': 'Receipt',
8
+ 'en-UK': 'Receipt',
9
+ 'en-DE': 'Quittung',
10
+ };
11
+ exports.totalTranslations = {
12
+ 'sv-SE': 'Totalt',
13
+ 'nb-NO': 'Total',
14
+ 'en-US': 'Total',
15
+ 'en-UK': 'Total',
16
+ 'en-DE': 'Gesamt',
17
+ };
18
+ exports.taxTranslations = {
19
+ 'sv-SE': 'Moms',
20
+ 'nb-NO': 'MVA',
21
+ 'en-US': 'Tax',
22
+ 'en-UK': 'Tax',
23
+ 'en-DE': 'MwSt',
24
+ };
25
+ exports.purchaseTranslations = {
26
+ 'sv-SE': 'Köp',
27
+ 'nb-NO': 'Kjøp',
28
+ 'en-US': 'Purchase',
29
+ 'en-UK': 'Purchase',
30
+ 'en-DE': 'Kauf',
31
+ };
32
+ exports.cashTranslations = {
33
+ 'sv-SE': 'Kontant',
34
+ 'nb-NO': 'Kontant',
35
+ 'en-US': 'Cash',
36
+ 'en-UK': 'Cash',
37
+ 'en-DE': 'Bar',
38
+ };
39
+ exports.cardPaymentTranslations = {
40
+ 'sv-SE': 'Kortbetalning',
41
+ 'nb-NO': 'Kortbetaling',
42
+ 'en-US': 'Card Payment',
43
+ 'en-UK': 'Card Payment',
44
+ 'en-DE': 'Kartenzahlung',
45
+ };
46
+ exports.mobilePaymentTranslations = {
47
+ 'sv-SE': 'Swish',
48
+ 'nb-NO': 'Vipps',
49
+ 'en-US': 'Mobile Payment',
50
+ 'en-UK': 'Mobile Payment',
51
+ 'en-DE': 'Mobiles Bezahlen',
52
+ };
53
+ exports.authorizationCodeTranslations = {
54
+ 'sv-SE': 'Auktoriseringskod',
55
+ 'nb-NO': 'Autorisasjonskode',
56
+ 'en-US': 'Authorization Code',
57
+ 'en-UK': 'Authorization Code',
58
+ 'en-DE': 'Autorisierungscode',
59
+ };
60
+ exports.contactlessTranslations = {
61
+ 'sv-SE': 'Kontaktlös',
62
+ 'nb-NO': 'Kontaktløs',
63
+ 'en-US': 'Contactless',
64
+ 'en-UK': 'Contactless',
65
+ 'en-DE': 'Kontaktlos',
66
+ };
67
+ exports.referenceTranslations = {
68
+ 'sv-SE': 'Referens',
69
+ 'nb-NO': 'Referanse',
70
+ 'en-US': 'Reference',
71
+ 'en-UK': 'Reference',
72
+ 'en-DE': 'Referenz',
73
+ };
@@ -39,6 +39,38 @@ interface PaymentTerminalReceiptInfo {
39
39
  lastFour: string;
40
40
  referenceNumber: string;
41
41
  }
42
+ type ReceiptLineItem = {
43
+ title: string;
44
+ price: string;
45
+ showUnitPrice: boolean;
46
+ quantity: number;
47
+ unitPrice: string;
48
+ };
49
+ type ReceiptLabels = {
50
+ receiptLabel: string;
51
+ totalLabel: string;
52
+ taxLabel: string;
53
+ purchaseLabel: string;
54
+ paymentMethodLabel: string;
55
+ entryMethodLabel: string;
56
+ authorizationCodeLabel: string;
57
+ referenceLabel: string;
58
+ };
59
+ interface ReceiptObj extends PaymentTerminalReceiptInfo {
60
+ merchantName: string;
61
+ storeAddress: string;
62
+ phone: string;
63
+ contactEmail: string;
64
+ organizationNumber: string;
65
+ primaryDomain: string;
66
+ orderDate: string;
67
+ lineItems: ReceiptLineItem[];
68
+ subTotal: string;
69
+ amountPaid: string;
70
+ tax: string;
71
+ receiptLabel: string;
72
+ totalLabel: string;
73
+ }
42
74
  type ReRobeOrderObj = {
43
75
  id: string;
44
76
  appliedDiscount: AppliedDiscount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.7.9",
3
+ "version": "3.8.0",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",