rerobe-js-orm 3.8.5 → 3.8.7

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.
@@ -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, _w, _x, _y, _z, _0, _1, _2;
8
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
9
9
  const currencyCode = fs.fields.currencyCode.inputValue || 'SEK';
10
10
  const customer = fs.fields.customer.selectedValue || {};
11
11
  const customerAttr = {
@@ -98,12 +98,14 @@ 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(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) || '', taxTitle: fs.fields.taxTitle.inputValue || '' }), (((_x = fs.props) === null || _x === void 0 ? void 0 : _x.zettleTransactionObj) && {
101
+ const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(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) || '', taxTitle: fs.fields.taxTitle.inputValue || '' }), (((_x = fs.props) === null || _x === void 0 ? void 0 : _x.zettleTransactionObj) && {
102
102
  zettleTransactionObj: (_y = fs.props) === null || _y === void 0 ? void 0 : _y.zettleTransactionObj,
103
103
  })), (((_z = fs.props) === null || _z === void 0 ? void 0 : _z.paymentIntentObj) && {
104
104
  paymentIntentObj: (_0 = fs.props) === null || _0 === void 0 ? void 0 : _0.paymentIntentObj,
105
105
  })), (((_1 = fs.props) === null || _1 === void 0 ? void 0 : _1.paymentIntentId) && {
106
106
  paymentIntentId: (_2 = fs.props) === null || _2 === void 0 ? void 0 : _2.paymentIntentId,
107
+ })), (((_3 = fs.props) === null || _3 === void 0 ? void 0 : _3.receiptObj) && {
108
+ receiptObj: (_4 = fs.props) === null || _4 === void 0 ? void 0 : _4.receiptObj,
107
109
  }));
108
110
  return new Order_1.default(Object.assign({}, orderAttributes));
109
111
  }
@@ -216,7 +216,7 @@ 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
+ generateReceiptLabels(locale: string, paymentMethod: string, entryMode?: string): ReceiptLabels;
220
220
  buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl, receiptNumber, }: {
221
221
  order: ReRobeOrderObj;
222
222
  merchant: MerchantObj;
@@ -471,7 +471,7 @@ class OrderHelpers {
471
471
  };
472
472
  }
473
473
  getPaymentTerminalReceiptInfo(payload) {
474
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
474
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
475
475
  let aid = '';
476
476
  let tvr = '';
477
477
  let authorizationCode = '';
@@ -496,10 +496,12 @@ class OrderHelpers {
496
496
  tvr = (_1 = (_0 = (_z = (_y = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _y === void 0 ? void 0 : _y.cardPresentDetails) === null || _z === void 0 ? void 0 : _z.receipt) === null || _0 === void 0 ? void 0 : _0.terminalVerificationResults) !== null && _1 !== void 0 ? _1 : '';
497
497
  authorizationCode = (_5 = (_4 = (_3 = (_2 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _2 === void 0 ? void 0 : _2.cardPresentDetails) === null || _3 === void 0 ? void 0 : _3.receipt) === null || _4 === void 0 ? void 0 : _4.authorizationCode) !== null && _5 !== void 0 ? _5 : '';
498
498
  entryMode = (_8 = (_7 = (_6 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _6 === void 0 ? void 0 : _6.cardPresentDetails) === null || _7 === void 0 ? void 0 : _7.readMethod) !== null && _8 !== void 0 ? _8 : '';
499
- applicationName = (_12 = (_11 = (_10 = (_9 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _9 === void 0 ? void 0 : _9.cardPresentDetails) === null || _10 === void 0 ? void 0 : _10.receipt) === null || _11 === void 0 ? void 0 : _11.applicationPreferredName) !== null && _12 !== void 0 ? _12 : '';
500
- cardBrand = (_15 = (_14 = (_13 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _13 === void 0 ? void 0 : _13.cardPresentDetails) === null || _14 === void 0 ? void 0 : _14.brand) !== null && _15 !== void 0 ? _15 : '';
501
- lastFour = (_18 = (_17 = (_16 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _16 === void 0 ? void 0 : _16.cardPresentDetails) === null || _17 === void 0 ? void 0 : _17.last4) !== null && _18 !== void 0 ? _18 : '';
502
- referenceNumber = (_19 = charge === null || charge === void 0 ? void 0 : charge.id) !== null && _19 !== void 0 ? _19 : '';
499
+ applicationName =
500
+ (_14 = (((_11 = (_10 = (_9 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _9 === void 0 ? void 0 : _9.cardPresentDetails) === null || _10 === void 0 ? void 0 : _10.receipt) === null || _11 === void 0 ? void 0 : _11.applicationPreferredName) ||
501
+ ((_13 = (_12 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _12 === void 0 ? void 0 : _12.cardPresentDetails) === null || _13 === void 0 ? void 0 : _13.brand))) !== null && _14 !== void 0 ? _14 : '';
502
+ cardBrand = (_17 = (_16 = (_15 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _15 === void 0 ? void 0 : _15.cardPresentDetails) === null || _16 === void 0 ? void 0 : _16.brand) !== null && _17 !== void 0 ? _17 : '';
503
+ lastFour = (_20 = (_19 = (_18 = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _18 === void 0 ? void 0 : _18.cardPresentDetails) === null || _19 === void 0 ? void 0 : _19.last4) !== null && _20 !== void 0 ? _20 : '';
504
+ referenceNumber = (_21 = charge === null || charge === void 0 ? void 0 : charge.id) !== null && _21 !== void 0 ? _21 : '';
503
505
  }
504
506
  return {
505
507
  aid,
@@ -521,7 +523,7 @@ class OrderHelpers {
521
523
  const location = (_a = fulfillmentLocations[0]) === null || _a === void 0 ? void 0 : _a.location;
522
524
  return (0, Utilities_1.convertAddressInputToFormatted)(location);
523
525
  }
524
- generateReceiptLabels(locale, paymentMethod, entryMethod = '') {
526
+ generateReceiptLabels(locale, paymentMethod, entryMode = '') {
525
527
  let paymentMethodLabel = translations_1.cardPaymentTranslations[locale] || translations_1.cardPaymentTranslations['en-US'];
526
528
  if (paymentMethod === order_constants_1.PAYMENT_TYPES.cash) {
527
529
  paymentMethodLabel = translations_1.cashTranslations[locale] || translations_1.cashTranslations['en-US'];
@@ -529,10 +531,10 @@ class OrderHelpers {
529
531
  if (paymentMethod === order_constants_1.PAYMENT_TYPES.mobilePayment) {
530
532
  paymentMethodLabel = translations_1.mobilePaymentTranslations[locale] || translations_1.mobilePaymentTranslations['en-US'];
531
533
  }
532
- let entryMethodLabel = '';
534
+ let entryModeLabel = '';
533
535
  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
+ if (contactlessRegex.test(entryMode.toLowerCase())) {
537
+ entryModeLabel = translations_1.contactlessTranslations[locale] || translations_1.contactlessTranslations['en-US'];
536
538
  }
537
539
  return {
538
540
  receiptLabel: translations_1.receiptTranslations[locale] || translations_1.receiptTranslations['en-US'],
@@ -542,11 +544,11 @@ class OrderHelpers {
542
544
  authorizationCodeLabel: translations_1.authorizationCodeTranslations[locale] || translations_1.authorizationCodeTranslations['en-US'],
543
545
  referenceLabel: translations_1.referenceTranslations[locale] || translations_1.referenceTranslations['en-US'],
544
546
  paymentMethodLabel,
545
- entryMethodLabel,
547
+ entryModeLabel,
546
548
  };
547
549
  }
548
550
  buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl = '', receiptNumber = '', }) {
549
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
551
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
550
552
  const { address: merchantAddress, legalName, contactEmail, phone = '', organizationNumber = '', primaryDomain, currency: storeCurrencyCode, } = merchant;
551
553
  const currencyCode = ((_a = order.totalPricePresentment) === null || _a === void 0 ? void 0 : _a.currencyCode) || storeCurrencyCode;
552
554
  const presentmentLocale = (0, Utilities_1.getPresentmentLocaleByCurrencyCode)(currencyCode);
@@ -628,26 +630,28 @@ class OrderHelpers {
628
630
  }
629
631
  return address;
630
632
  };
631
- const paymentMethod = (_b = order.paymentMethod) !== null && _b !== void 0 ? _b : '';
633
+ const paymentTerminalInfo = this.getPaymentTerminalReceiptInfo(order);
634
+ const receiptLabels = this.generateReceiptLabels(presentmentLocale, (_b = order.paymentType) !== null && _b !== void 0 ? _b : '', (_c = paymentTerminalInfo.entryMode) !== null && _c !== void 0 ? _c : '');
632
635
  return Object.assign(Object.assign({ merchantLogoUrl, merchantName: legalName, storeAddress: buildStoreAddress(), phone,
633
636
  contactEmail,
634
- organizationNumber, primaryDomain: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale), receiptNumber, lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
637
+ organizationNumber,
638
+ primaryDomain, storeUrl: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale), receiptNumber, lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
635
639
  currencyCode,
636
- amount: (_d = (_c = order.subtotalPricePresentment) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : '',
640
+ amount: (_e = (_d = order.subtotalPricePresentment) === null || _d === void 0 ? void 0 : _d.amount) !== null && _e !== void 0 ? _e : '',
637
641
  fractionDigits: 2,
638
642
  }), total: (0, Utilities_1.formatPrice)({
639
643
  currencyCode,
640
- amount: (_f = (_e = order.totalPricePresentment) === null || _e === void 0 ? void 0 : _e.amount) !== null && _f !== void 0 ? _f : '',
644
+ amount: (_g = (_f = order.totalPricePresentment) === null || _f === void 0 ? void 0 : _f.amount) !== null && _g !== void 0 ? _g : '',
641
645
  fractionDigits: 2,
642
646
  }), amountPaid: (0, Utilities_1.formatPrice)({
643
647
  currencyCode,
644
- amount: (_h = (_g = order.totalPricePresentment) === null || _g === void 0 ? void 0 : _g.amount) !== null && _h !== void 0 ? _h : '',
648
+ amount: (_j = (_h = order.totalPricePresentment) === null || _h === void 0 ? void 0 : _h.amount) !== null && _j !== void 0 ? _j : '',
645
649
  fractionDigits: 2,
646
650
  }), tax: (0, Utilities_1.formatPrice)({
647
651
  currencyCode,
648
- amount: (_k = (_j = order.totalTaxPresentment) === null || _j === void 0 ? void 0 : _j.amount) !== null && _k !== void 0 ? _k : '',
652
+ amount: (_l = (_k = order.totalTaxPresentment) === null || _k === void 0 ? void 0 : _k.amount) !== null && _l !== void 0 ? _l : '',
649
653
  fractionDigits: 2,
650
- }), taxRates: formattedTaxRates }, this.generateReceiptLabels(presentmentLocale, paymentMethod)), this.getPaymentTerminalReceiptInfo(order));
654
+ }), taxRates: formattedTaxRates }, paymentTerminalInfo), receiptLabels);
651
655
  }
652
656
  }
653
657
  exports.default = OrderHelpers;
@@ -109,6 +109,7 @@ export default class Order extends Base {
109
109
  zettleTransactionObj?: ZettleTransactionObj;
110
110
  paymentIntentObj?: any;
111
111
  paymentIntentId?: string;
112
+ receiptObj?: ReceiptObj;
112
113
  constructor(props?: any);
113
114
  toObj(): ReRobeOrderObj;
114
115
  generateSchemaForTypesense(name?: string): {
@@ -138,6 +138,9 @@ class Order extends Base_1.default {
138
138
  if (props === null || props === void 0 ? void 0 : props.paymentIntentId) {
139
139
  this.paymentIntentId = props.paymentIntentId;
140
140
  }
141
+ if (props === null || props === void 0 ? void 0 : props.receiptObj) {
142
+ this.receiptObj = props.receiptObj;
143
+ }
141
144
  }
142
145
  toObj() {
143
146
  const orderObj = {
@@ -223,6 +226,9 @@ class Order extends Base_1.default {
223
226
  if (this.paymentIntentId) {
224
227
  orderObj.paymentIntentId = this.paymentIntentId;
225
228
  }
229
+ if (this.receiptObj) {
230
+ orderObj.receiptObj = this.receiptObj;
231
+ }
226
232
  return orderObj;
227
233
  }
228
234
  generateSchemaForTypesense(name = 'prod_orders_20220809') {
@@ -49,7 +49,7 @@ interface ReceiptLabels {
49
49
  taxLabel: string;
50
50
  purchaseLabel: string;
51
51
  paymentMethodLabel: string;
52
- entryMethodLabel: string;
52
+ entryModeLabel: string;
53
53
  authorizationCodeLabel: string;
54
54
  referenceLabel: string;
55
55
  }
@@ -62,6 +62,7 @@ type ReceiptObj = {
62
62
  contactEmail: string;
63
63
  organizationNumber: string;
64
64
  primaryDomain: string;
65
+ storeUrl: string;
65
66
  orderDate: string;
66
67
  receiptNumber: string;
67
68
  lineItems: ReceiptLineItem[];
@@ -143,6 +144,7 @@ type ReRobeOrderObj = {
143
144
  zettleTransactionObj?: ZettleTransactionObj;
144
145
  paymentIntentObj?: any;
145
146
  paymentIntentId?: string;
147
+ receiptObj?: ReceiptObj;
146
148
  };
147
149
  type OrderWithRefundsAndFulfillmentsInfoObj = {
148
150
  documentId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.8.5",
3
+ "version": "3.8.7",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",