rerobe-js-orm 3.7.8 → 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',
@@ -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;
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;
9
9
  const currencyCode = fs.fields.currencyCode.inputValue || 'SEK';
10
10
  const customer = fs.fields.customer.selectedValue || {};
11
11
  const customerAttr = {
@@ -98,7 +98,13 @@ 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({}, 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 || '' });
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) && {
102
+ zettleTransactionObj: (_y = fs.props) === null || _y === void 0 ? void 0 : _y.zettleTransactionObj,
103
+ })), (((_z = fs.props) === null || _z === void 0 ? void 0 : _z.paymentIntentObj) && {
104
+ paymentIntentObj: (_0 = fs.props) === null || _0 === void 0 ? void 0 : _0.paymentIntentObj,
105
+ })), (((_1 = fs.props) === null || _1 === void 0 ? void 0 : _1.paymentIntentId) && {
106
+ paymentIntentId: (_2 = fs.props) === null || _2 === void 0 ? void 0 : _2.paymentIntentId,
107
+ }));
102
108
  return new Order_1.default(Object.assign({}, orderAttributes));
103
109
  }
104
110
  }
@@ -214,4 +214,11 @@ export default class OrderHelpers {
214
214
  };
215
215
  shippingFeeTax?: undefined;
216
216
  };
217
+ getPaymentTerminalReceiptInfo(payload?: any): PaymentTerminalReceiptInfo;
218
+ getFormattedFulfillmentLocation(order: ReRobeOrderObj): string;
219
+ generateReceiptLabels(locale: string, paymentMethod: string, entryMethod?: string): ReceiptLabels;
220
+ buildReceiptObjFromOrder({ order, merchant }: {
221
+ order: ReRobeOrderObj;
222
+ merchant: MerchantObj;
223
+ }): ReceiptObj;
217
224
  }
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Order_1 = require("../models/Order");
4
+ const Utilities_1 = require("../helpers/Utilities");
5
+ const order_constants_1 = require("../constants/order-constants");
6
+ const translations_1 = require("../translations");
4
7
  class OrderHelpers {
5
8
  getOrderIdFromShopifyObj(order) {
6
9
  const { id, tags } = order;
@@ -467,5 +470,157 @@ class OrderHelpers {
467
470
  totalTaxPresentment: prepareMoneyObj(totalTaxPresentmentAmount),
468
471
  };
469
472
  }
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;
475
+ let aid = '';
476
+ let tvr = '';
477
+ let authorizationCode = '';
478
+ let entryMode = '';
479
+ let applicationName = '';
480
+ let cardBrand = '';
481
+ let lastFour = '';
482
+ let referenceNumber = '';
483
+ if (payload === null || payload === void 0 ? void 0 : payload.zettleTransactionObj) {
484
+ aid = (_b = (_a = payload.zettleTransactionObj) === null || _a === void 0 ? void 0 : _a.applicationIdentifier) !== null && _b !== void 0 ? _b : '';
485
+ tvr = (_d = (_c = payload.zettleTransactionObj) === null || _c === void 0 ? void 0 : _c.tvr) !== null && _d !== void 0 ? _d : '';
486
+ authorizationCode = (_f = (_e = payload.zettleTransactionObj) === null || _e === void 0 ? void 0 : _e.authorizationCode) !== null && _f !== void 0 ? _f : '';
487
+ entryMode = (_h = (_g = payload.zettleTransactionObj) === null || _g === void 0 ? void 0 : _g.entryMode) !== null && _h !== void 0 ? _h : '';
488
+ applicationName = (_k = (_j = payload.zettleTransactionObj) === null || _j === void 0 ? void 0 : _j.applicationName) !== null && _k !== void 0 ? _k : '';
489
+ cardBrand = (_m = (_l = payload.zettleTransactionObj) === null || _l === void 0 ? void 0 : _l.cardBrand) !== null && _m !== void 0 ? _m : '';
490
+ lastFour = (_q = (_p = (_o = payload.zettleTransactionObj) === null || _o === void 0 ? void 0 : _o.obfuscatedPan) === null || _p === void 0 ? void 0 : _p.slice(-4)) !== null && _q !== void 0 ? _q : '';
491
+ referenceNumber = (_s = (_r = payload.zettleTransactionObj) === null || _r === void 0 ? void 0 : _r.referenceNumber) !== null && _s !== void 0 ? _s : '';
492
+ }
493
+ else if (payload === null || payload === void 0 ? void 0 : payload.paymentIntentObj) {
494
+ const charge = (_t = payload.paymentIntentObj.charges) === null || _t === void 0 ? void 0 : _t[0];
495
+ aid = (_x = (_w = (_v = (_u = charge === null || charge === void 0 ? void 0 : charge.paymentMethodDetails) === null || _u === void 0 ? void 0 : _u.cardPresentDetails) === null || _v === void 0 ? void 0 : _v.receipt) === null || _w === void 0 ? void 0 : _w.dedicatedFileName) !== null && _x !== void 0 ? _x : '';
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
+ 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
+ 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 : '';
503
+ }
504
+ return {
505
+ aid,
506
+ tvr,
507
+ authorizationCode,
508
+ entryMode,
509
+ applicationName,
510
+ cardBrand,
511
+ lastFour,
512
+ referenceNumber,
513
+ };
514
+ }
515
+ getFormattedFulfillmentLocation(order) {
516
+ var _a;
517
+ const { fulfillmentLocations = [] } = order;
518
+ if (fulfillmentLocations.length === 0) {
519
+ return 'No fulfillment location available';
520
+ }
521
+ const location = (_a = fulfillmentLocations[0]) === null || _a === void 0 ? void 0 : _a.location;
522
+ return (0, Utilities_1.convertAddressInputToFormatted)(location);
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
+ }
548
+ buildReceiptObjFromOrder({ order, merchant }) {
549
+ var _a, _b, _c, _d, _e, _f, _g, _h;
550
+ const { address: merchantAddress, legalName, contactEmail, phone = '', organizationNumber = '', primaryDomain, currency: storeCurrencyCode, } = merchant;
551
+ const currencyCode = ((_a = order.totalPricePresentment) === null || _a === void 0 ? void 0 : _a.currencyCode) || storeCurrencyCode;
552
+ const presentmentLocale = (0, Utilities_1.getPresentmentLocaleByCurrencyCode)(currencyCode);
553
+ const mapLineItem = (l) => {
554
+ var _a, _b, _c, _d;
555
+ let totalPrice = Number((_a = l.presentmentTotalPrice) === null || _a === void 0 ? void 0 : _a.amount);
556
+ if (l.isTaxable && l.taxRate) {
557
+ const taxRate = Number(l.taxRate);
558
+ totalPrice *= 1 + taxRate;
559
+ }
560
+ return {
561
+ title: l.title || l.brand || '',
562
+ price: (0, Utilities_1.formatPrice)({
563
+ currencyCode,
564
+ amount: totalPrice,
565
+ fractionDigits: 2,
566
+ }),
567
+ quantity: Number((_b = l === null || l === void 0 ? void 0 : l.quantity) !== null && _b !== void 0 ? _b : 0),
568
+ showUnitPrice: Number(l === null || l === void 0 ? void 0 : l.quantity) > 1,
569
+ unitPrice: (0, Utilities_1.formatPrice)({
570
+ currencyCode,
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 : '',
572
+ fractionDigits: 2,
573
+ }),
574
+ };
575
+ };
576
+ const buildLineItems = () => {
577
+ var _a, _b, _c, _d;
578
+ let result = order.lineItems.map(mapLineItem);
579
+ if (((_a = order.totalDiscountPresentment) === null || _a === void 0 ? void 0 : _a.amount) && Number((_b = order.totalDiscountPresentment) === null || _b === void 0 ? void 0 : _b.amount) > 0) {
580
+ result = [
581
+ ...result,
582
+ {
583
+ title: 'Discount',
584
+ price: (0, Utilities_1.formatPrice)({
585
+ currencyCode,
586
+ amount: (_c = order.totalDiscountPresentment) === null || _c === void 0 ? void 0 : _c.amount,
587
+ fractionDigits: 2,
588
+ }),
589
+ showUnitPrice: false,
590
+ quantity: 1,
591
+ unitPrice: (0, Utilities_1.formatPrice)({
592
+ currencyCode,
593
+ amount: (_d = order.totalDiscountPresentment) === null || _d === void 0 ? void 0 : _d.amount,
594
+ fractionDigits: 2,
595
+ }),
596
+ },
597
+ ];
598
+ }
599
+ return result;
600
+ };
601
+ const buildStoreAddress = () => {
602
+ let address = this.getFormattedFulfillmentLocation(order);
603
+ if (!address) {
604
+ address = (0, Utilities_1.convertAddressInputToFormatted)(merchantAddress);
605
+ }
606
+ return address;
607
+ };
608
+ const paymentMethod = (_b = order.paymentMethod) !== null && _b !== void 0 ? _b : '';
609
+ return Object.assign(Object.assign({ merchantName: legalName, storeAddress: buildStoreAddress(), phone,
610
+ contactEmail,
611
+ organizationNumber, primaryDomain: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale), lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
612
+ currencyCode,
613
+ amount: (_d = (_c = order.subtotalPricePresentment) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : '',
614
+ fractionDigits: 2,
615
+ }), amountPaid: (0, Utilities_1.formatPrice)({
616
+ currencyCode,
617
+ amount: (_f = (_e = order.totalPricePresentment) === null || _e === void 0 ? void 0 : _e.amount) !== null && _f !== void 0 ? _f : '',
618
+ fractionDigits: 2,
619
+ }), tax: (0, Utilities_1.formatPrice)({
620
+ currencyCode,
621
+ amount: (_h = (_g = order.totalTaxPresentment) === null || _g === void 0 ? void 0 : _g.amount) !== null && _h !== void 0 ? _h : '',
622
+ fractionDigits: 2,
623
+ }) }, this.generateReceiptLabels(presentmentLocale, paymentMethod)), this.getPaymentTerminalReceiptInfo(order));
624
+ }
470
625
  }
471
626
  exports.default = OrderHelpers;
@@ -30,3 +30,11 @@ export default class Utilities {
30
30
  humanize(str: string): string;
31
31
  singularizeProductType(word: string): string;
32
32
  }
33
+ export declare function getPresentmentLocaleByCurrencyCode(currencyCode: string): string;
34
+ export declare function convertAddressInputToFormatted(address?: AddressInput | null): string;
35
+ export declare function formatPrice({ currencyCode, amount, fractionDigits, }: {
36
+ currencyCode: string;
37
+ amount: string | number;
38
+ fractionDigits?: number;
39
+ }): string;
40
+ export declare function getFormattedTimestamp(locale: string): string;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFormattedTimestamp = exports.formatPrice = exports.convertAddressInputToFormatted = exports.getPresentmentLocaleByCurrencyCode = void 0;
3
4
  // @ts-ignore
4
5
  const lodash_1 = require("lodash");
5
6
  class Utilities {
@@ -205,3 +206,60 @@ class Utilities {
205
206
  }
206
207
  }
207
208
  exports.default = Utilities;
209
+ function initFormatter(locale = 'en-US', currency = 'SEK') {
210
+ return new Intl.NumberFormat(locale, {
211
+ style: 'currency',
212
+ currency: currency || 'SEK',
213
+ // These options are needed to round to whole numbers if that's what you want.
214
+ // minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
215
+ // maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
216
+ });
217
+ }
218
+ function getPresentmentLocaleByCurrencyCode(currencyCode) {
219
+ let presentmentLocale = 'en-US';
220
+ if (currencyCode) {
221
+ if (currencyCode === 'SEK') {
222
+ presentmentLocale = 'sv-SE';
223
+ }
224
+ if (currencyCode === 'NOK') {
225
+ presentmentLocale = 'nb-NO';
226
+ }
227
+ if (currencyCode === 'USD') {
228
+ presentmentLocale = 'en-US';
229
+ }
230
+ if (currencyCode === 'GBP') {
231
+ presentmentLocale = 'en-UK';
232
+ }
233
+ if (currencyCode === 'EUR') {
234
+ presentmentLocale = 'en-DE';
235
+ }
236
+ }
237
+ return presentmentLocale;
238
+ }
239
+ exports.getPresentmentLocaleByCurrencyCode = getPresentmentLocaleByCurrencyCode;
240
+ function convertAddressInputToFormatted(address) {
241
+ if (!address) {
242
+ return '';
243
+ }
244
+ const { address1 = '', address2 = '', city = '', province = '', zip = '', country = '' } = address;
245
+ if (!address1 && !city && !zip && !country) {
246
+ return '';
247
+ }
248
+ const formattedAddress = `${address1}${address2 ? `\n${address2}` : ''}\n${city}${province ? `, ${province}` : ''}, ${zip}, ${country}`;
249
+ return formattedAddress;
250
+ }
251
+ exports.convertAddressInputToFormatted = convertAddressInputToFormatted;
252
+ function formatPrice({ currencyCode, amount, fractionDigits = 2, }) {
253
+ const presentmentLocale = getPresentmentLocaleByCurrencyCode(currencyCode);
254
+ const priceFormatter = initFormatter(presentmentLocale, currencyCode);
255
+ const valueToFormat = Number(parseFloat(String(amount)).toFixed(fractionDigits));
256
+ return priceFormatter.format(valueToFormat);
257
+ }
258
+ exports.formatPrice = formatPrice;
259
+ function getFormattedTimestamp(locale) {
260
+ const date = new Date();
261
+ const hours = String(date.getHours()).padStart(2, '0');
262
+ const minutes = String(date.getMinutes()).padStart(2, '0');
263
+ return `${date.toLocaleDateString(locale)} ${hours}:${minutes}`;
264
+ }
265
+ exports.getFormattedTimestamp = getFormattedTimestamp;
@@ -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;
@@ -104,6 +106,9 @@ export default class Order extends Base {
104
106
  updatedAtTimestamp: number;
105
107
  adjustments?: OrderAdjustment[];
106
108
  createdByUserId?: string;
109
+ zettleTransactionObj?: ZettleTransactionObj;
110
+ paymentIntentObj?: any;
111
+ paymentIntentId?: string;
107
112
  constructor(props?: any);
108
113
  toObj(): ReRobeOrderObj;
109
114
  generateSchemaForTypesense(name?: string): {
@@ -129,6 +129,15 @@ class Order extends Base_1.default {
129
129
  this.updatedAtTimestamp = (props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) || 0;
130
130
  this.adjustments = (props === null || props === void 0 ? void 0 : props.adjustments) || [];
131
131
  this.createdByUserId = (props === null || props === void 0 ? void 0 : props.createdByUserId) || '';
132
+ if (props === null || props === void 0 ? void 0 : props.zettleTransactionObj) {
133
+ this.zettleTransactionObj = props.zettleTransactionObj;
134
+ }
135
+ if (props === null || props === void 0 ? void 0 : props.paymentIntentObj) {
136
+ this.paymentIntentObj = props.paymentIntentObj;
137
+ }
138
+ if (props === null || props === void 0 ? void 0 : props.paymentIntentId) {
139
+ this.paymentIntentId = props.paymentIntentId;
140
+ }
132
141
  }
133
142
  toObj() {
134
143
  const orderObj = {
@@ -205,6 +214,15 @@ class Order extends Base_1.default {
205
214
  if (this.createdByUserId) {
206
215
  orderObj.createdByUserId = this.createdByUserId;
207
216
  }
217
+ if (this.zettleTransactionObj) {
218
+ this.zettleTransactionObj = this.zettleTransactionObj;
219
+ }
220
+ if (this.paymentIntentObj) {
221
+ orderObj.paymentIntentObj = this.paymentIntentObj;
222
+ }
223
+ if (this.paymentIntentId) {
224
+ orderObj.paymentIntentId = this.paymentIntentId;
225
+ }
208
226
  return orderObj;
209
227
  }
210
228
  generateSchemaForTypesense(name = 'prod_orders_20220809') {
@@ -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
+ };
@@ -22,6 +22,7 @@ type MerchantMutableData = {
22
22
  primaryDomain: string;
23
23
  webhooks: MerchantWebHook[];
24
24
  socialLinks: SocialLinksType | null;
25
+ organizationNumber?: string;
25
26
  };
26
27
  type MerchantSystemOnlyMutableData = {
27
28
  paymentTier: RibbnPaymentTiers | string;
@@ -35,6 +36,7 @@ type MerchantSystemOnlyMutableData = {
35
36
  ribbnId: string;
36
37
  webshopHomePageId: string;
37
38
  defaultLocation: string;
39
+ isZettleUser?: boolean;
38
40
  };
39
41
  type MerchantObj = MerchantMutableData & MerchantSystemOnlyMutableData;
40
42
  type MerchantTypes = 'INDIVIDUAL' | 'BUSINESS';
@@ -15,6 +15,62 @@ type DraftOrderObj = {
15
15
  billingAddress?: AddressInput;
16
16
  shippingAddress?: AddressInput;
17
17
  };
18
+ type ZettleTransactionObj = {
19
+ applicationIdentifier: string;
20
+ obfuscatedPan: string;
21
+ cardBrand: string;
22
+ referenceNumber: string;
23
+ transactionId: string;
24
+ gratuityAmount: string;
25
+ tvr: string;
26
+ amount: string;
27
+ authorizationCode: string;
28
+ entryMode: string;
29
+ applicationName: string;
30
+ panHash: string;
31
+ };
32
+ interface PaymentTerminalReceiptInfo {
33
+ aid: string;
34
+ tvr: string;
35
+ authorizationCode: string;
36
+ entryMode: string;
37
+ applicationName: string;
38
+ cardBrand: string;
39
+ lastFour: string;
40
+ referenceNumber: string;
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
+ }
18
74
  type ReRobeOrderObj = {
19
75
  id: string;
20
76
  appliedDiscount: AppliedDiscount;
@@ -82,6 +138,9 @@ type ReRobeOrderObj = {
82
138
  adjustments?: OrderAdjustment[];
83
139
  createdAtTimestamp: number;
84
140
  updatedAtTimestamp: number;
141
+ zettleTransactionObj?: ZettleTransactionObj;
142
+ paymentIntentObj?: any;
143
+ paymentIntentId?: string;
85
144
  };
86
145
  type OrderWithRefundsAndFulfillmentsInfoObj = {
87
146
  documentId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.7.8",
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",