bysquare 2.13.2 → 2.13.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.
package/lib/decode.js CHANGED
@@ -36,6 +36,25 @@ function decodeNumber(value) {
36
36
  function decodeString(value) {
37
37
  return value?.length ? value : undefined;
38
38
  }
39
+ /**
40
+ * Prevedie dátum z formátu YYYYMMDD na ISO 8601 formát (YYYY-MM-DD)
41
+ * podľa požiadavky Pay by Square špecifikácie sekcia 3.7.
42
+ *
43
+ * Poznámka: Táto konverzia sa podľa špecifikácie používa len pre paymentDueDate.
44
+ * lastDate ostáva vo formáte YYYYMMDD.
45
+ *
46
+ * @param input - Dátum vo formáte YYYYMMDD
47
+ * @returns Dátum vo formáte ISO 8601 (YYYY-MM-DD) | undefined
48
+ */
49
+ function deserializeDate(input) {
50
+ if (!input || input.length !== 8) {
51
+ return undefined;
52
+ }
53
+ const year = input.slice(0, 4);
54
+ const month = input.slice(4, 6);
55
+ const day = input.slice(6, 8);
56
+ return year + "-" + month + "-" + day;
57
+ }
39
58
  /**
40
59
  * Generating by square Code
41
60
  *
@@ -63,7 +82,7 @@ export function deserialize(qr) {
63
82
  type: Number(paymentOptions),
64
83
  currencyCode: currency ?? CurrencyCode.EUR,
65
84
  amount: Number(ammount),
66
- paymentDueDate: dueDate || undefined,
85
+ paymentDueDate: deserializeDate(dueDate),
67
86
  variableSymbol: variableSymbol || undefined,
68
87
  constantSymbol: constantSymbol || undefined,
69
88
  specificSymbol: specificSymbol || undefined,
@@ -92,6 +111,7 @@ export function deserialize(qr) {
92
111
  day: decodeNumber(data.shift()),
93
112
  month: decodeNumber(data.shift()),
94
113
  periodicity: decodeString(data.shift()),
114
+ // lastDate stays in YYYYMMDD format (not converted per specification)
95
115
  lastDate: decodeString(data.shift()),
96
116
  };
97
117
  }
package/lib/encode.js CHANGED
@@ -4,6 +4,22 @@ import { crc32 } from "./crc32.js";
4
4
  import { deburr } from "./deburr.js";
5
5
  import { Month, PaymentOptions, Version, } from "./types.js";
6
6
  import { validateDataModel } from "./validations.js";
7
+ /**
8
+ * Prevedie dátum z ISO 8601 formátu (YYYY-MM-DD) na formát YYYYMMDD
9
+ * podľa požiadavky Pay by Square špecifikácie sekcia 3.7.
10
+ *
11
+ * Poznámka: Táto konverzia sa podľa špecifikácie používa len pre paymentDueDate.
12
+ * lastDate očakáva priamo formát YYYYMMDD.
13
+ *
14
+ * @param input - Dátum vo formáte ISO 8601 (YYYY-MM-DD)
15
+ * @returns Dátum vo formáte YYYYMMDD | undefined
16
+ */
17
+ function serializeDate(input) {
18
+ if (!input) {
19
+ return undefined;
20
+ }
21
+ return input.split("-").join("");
22
+ }
7
23
  export const EncodeErrorMessage = {
8
24
  /**
9
25
  * @description - find invalid value in extensions
@@ -123,7 +139,7 @@ export function serialize(data) {
123
139
  serialized.push(p.type.toString());
124
140
  serialized.push(p.amount?.toString());
125
141
  serialized.push(p.currencyCode);
126
- serialized.push(p.paymentDueDate);
142
+ serialized.push(serializeDate(p.paymentDueDate));
127
143
  serialized.push(p.variableSymbol);
128
144
  serialized.push(p.constantSymbol);
129
145
  serialized.push(p.specificSymbol);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "bysquare",
3
3
  "description": "It's a national standard for payment QR codes adopted by Slovak Banking Association (SBA)",
4
4
  "type": "module",
5
- "version": "2.13.2",
5
+ "version": "2.13.3",
6
6
  "license": "Apache-2.0",
7
7
  "funding": "https://github.com/sponsors/xseman",
8
8
  "homepage": "https://github.com/xseman/bysquare#readme",