bysquare 2.12.2 → 2.12.4

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/README.md CHANGED
@@ -42,57 +42,86 @@ $ npm install bysquare
42
42
 
43
43
  ## Quick start
44
44
 
45
- There are helper functions for the most common use cases, such as simple payment,
46
- direct debit, and standing order. Also you can use `encode` and `decode` functions
47
- to work with the data model directly.
45
+ This library provides `encode` and `decode` functions to work with the data
46
+ model directly, allowing you to create customized payment solutions.
48
47
 
49
- ### Simple Payment
48
+ ### Creating Payment QR Codes
49
+
50
+ To generate QR codes for different payment types, use the `encode` function with
51
+ the appropriate payment configuration:
52
+
53
+ #### Simple Payment (Payment Order)
50
54
 
51
55
  ```js
52
56
  import {
53
57
  CurrencyCode,
54
- simplePayment,
58
+ encode,
59
+ PaymentOptions,
55
60
  } from "bysquare";
56
61
 
57
- const qrstring = simplePayment({
58
- amount: 50.75,
59
- iban: "SK9611000000002918599669",
60
- variableSymbol: "123456",
61
- currencyCode: CurrencyCode.EUR,
62
+ const qrstring = encode({
63
+ payments: [
64
+ {
65
+ type: PaymentOptions.PaymentOrder, // 1
66
+ amount: 50.75,
67
+ variableSymbol: "123456",
68
+ currencyCode: CurrencyCode.EUR, // "EUR"
69
+ bankAccounts: [
70
+ { iban: "SK9611000000002918599669" },
71
+ ],
72
+ },
73
+ ],
62
74
  });
63
75
  ```
64
76
 
65
- ### Direct Debit
77
+ #### Direct Debit
66
78
 
67
79
  ```js
68
80
  import {
69
81
  CurrencyCode,
70
- directDebit,
82
+ encode,
83
+ PaymentOptions,
71
84
  } from "bysquare";
72
85
 
73
- const qrstring = directDebit({
74
- amount: 25.00,
75
- iban: "SK9611000000002918599669",
76
- variableSymbol: "789012",
77
- currencyCode: CurrencyCode.EUR,
86
+ const qrstring = encode({
87
+ payments: [
88
+ {
89
+ type: PaymentOptions.DirectDebit, // 2
90
+ amount: 25.0,
91
+ variableSymbol: "789012",
92
+ currencyCode: CurrencyCode.EUR, // "EUR"
93
+ bankAccounts: [
94
+ { iban: "SK9611000000002918599669" },
95
+ ],
96
+ },
97
+ ],
78
98
  });
79
99
  ```
80
100
 
81
- ### Standing Order
101
+ #### Standing Order
82
102
 
83
103
  ```js
84
104
  import {
85
105
  CurrencyCode,
106
+ encode,
107
+ PaymentOptions,
86
108
  Periodicity,
87
- standingOrder,
88
109
  } from "bysquare";
89
110
 
90
- const qrstring = standingOrder({
91
- amount: 100.00,
92
- iban: "SK9611000000002918599669",
93
- variableSymbol: "654321",
94
- day: 15,
95
- periodicity: Periodicity.Monthly,
111
+ const qrstring = encode({
112
+ payments: [
113
+ {
114
+ type: PaymentOptions.StandingOrder, // 3
115
+ amount: 100.0,
116
+ variableSymbol: "654321",
117
+ currencyCode: CurrencyCode.EUR, // "EUR"
118
+ day: 15,
119
+ periodicity: Periodicity.Monthly, // "m"
120
+ bankAccounts: [
121
+ { iban: "SK9611000000002918599669" },
122
+ ],
123
+ },
124
+ ],
96
125
  });
97
126
  ```
98
127
 
@@ -104,33 +133,41 @@ page:
104
133
  ```html
105
134
  <!DOCTYPE html>
106
135
  <html lang="en">
107
- <head>
108
- <meta charset="UTF-8">
109
- <title>Payment QR Code</title>
110
- </head>
111
- <body>
112
- <div id="qrcode" style="width: 200px"></div>
113
-
114
- <script type="module">
115
- import { QRCode } from "https://esm.sh/@lostinbrittany/qr-esm@latest";
116
- import { simplePayment } from "https://esm.sh/bysquare@latest";
117
-
118
- const qrstring = simplePayment({
119
- amount: 123.45,
120
- iban: "SK9611000000002918599669",
121
- variableSymbol: "987654",
122
- });
123
-
124
- const qrElement = document.getElementById('qrcode');
125
- qrElement.appendChild(QRCode.generateSVG(qrstring));
126
- </script>
127
- </body>
136
+ <head>
137
+ <meta charset="UTF-8" />
138
+ <title>Payment QR Code</title>
139
+ </head>
140
+ <body>
141
+ <div id="qrcode" style="width: 200px"></div>
142
+
143
+ <script type="module">
144
+ import { QRCode } from "https://esm.sh/@lostinbrittany/qr-esm@latest";
145
+ import { encode, PaymentOptions, CurrencyCode } from "https://esm.sh/bysquare@latest";
146
+
147
+ const qrstring = encode({
148
+ payments: [
149
+ {
150
+ type: PaymentOptions.PaymentOrder,
151
+ amount: 123.45,
152
+ variableSymbol: "987654",
153
+ rrencyCode: CurrencyCode.EUR,
154
+ bankAccounts: [
155
+ { iban: "SK9611000000002918599669" }
156
+ ],
157
+ },
158
+ ],
159
+ });
160
+
161
+ const qrElement = document.getElementById("qrcode");
162
+ qrElement.appendChild(QRCode.generateSVG(qrstring));
163
+ </script>
164
+ </body>
128
165
  </html>
129
166
  ```
130
167
 
131
- ### Adavanced usage
168
+ ### Advanced usage
132
169
 
133
- For more complex data use `encode` and `decode` functions:
170
+ For more complex data with multiple payments and additional fields:
134
171
 
135
172
  > [!NOTE]
136
173
  > Encoded data are without diacritics
@@ -0,0 +1,34 @@
1
+ import { type BankAccount, SimplePayment, type StandingOrder } from "./types.js";
2
+ type PaymentInput = Pick<BankAccount, "iban"> & Pick<SimplePayment, "amount" | "currencyCode" | "variableSymbol">;
3
+ /**
4
+ * @deprecated Will be removed as of v3.
5
+ * This was intended to simplify the main API, but it has complicated it
6
+ * instead, serving only as a limited wrapper. The main goal should be to
7
+ * enhance documentation for the main API, enabling users to create their own
8
+ * wrappers.
9
+ *
10
+ * Vytvorí QR pre jednorázovú platbu
11
+ */
12
+ export declare function simplePayment(input: PaymentInput): string;
13
+ /**
14
+ * @deprecated Will be removed as of v3.
15
+ * This was intended to simplify the main API, but it has complicated it
16
+ * instead, serving only as a limited wrapper. The main goal should be to
17
+ * enhance documentation for the main API, enabling users to create their own
18
+ * wrappers.
19
+ *
20
+ * Vytvorí QR pre inkaso
21
+ */
22
+ export declare function directDebit(input: PaymentInput): string;
23
+ type StandingInput = PaymentInput & Pick<StandingOrder, "day" | "periodicity">;
24
+ /**
25
+ * @deprecated Will be removed as of v3.
26
+ * This was intended to simplify the main API, but it has complicated it
27
+ * instead, serving only as a limited wrapper. The main goal should be to
28
+ * enhance documentation for the main API, enabling users to create their own
29
+ * wrappers.
30
+ *
31
+ * Vytvorí QR pre trvalý príkaz
32
+ */
33
+ export declare function standingOrder(input: StandingInput): string;
34
+ export {};
@@ -1,6 +1,12 @@
1
1
  import { encode } from "./encode.js";
2
2
  import { CurrencyCode, PaymentOptions, } from "./types.js";
3
3
  /**
4
+ * @deprecated Will be removed as of v3.
5
+ * This was intended to simplify the main API, but it has complicated it
6
+ * instead, serving only as a limited wrapper. The main goal should be to
7
+ * enhance documentation for the main API, enabling users to create their own
8
+ * wrappers.
9
+ *
4
10
  * Vytvorí QR pre jednorázovú platbu
5
11
  */
6
12
  export function simplePayment(input) {
@@ -17,6 +23,12 @@ export function simplePayment(input) {
17
23
  });
18
24
  }
19
25
  /**
26
+ * @deprecated Will be removed as of v3.
27
+ * This was intended to simplify the main API, but it has complicated it
28
+ * instead, serving only as a limited wrapper. The main goal should be to
29
+ * enhance documentation for the main API, enabling users to create their own
30
+ * wrappers.
31
+ *
20
32
  * Vytvorí QR pre inkaso
21
33
  */
22
34
  export function directDebit(input) {
@@ -33,6 +45,12 @@ export function directDebit(input) {
33
45
  });
34
46
  }
35
47
  /**
48
+ * @deprecated Will be removed as of v3.
49
+ * This was intended to simplify the main API, but it has complicated it
50
+ * instead, serving only as a limited wrapper. The main goal should be to
51
+ * enhance documentation for the main API, enabling users to create their own
52
+ * wrappers.
53
+ *
36
54
  * Vytvorí QR pre trvalý príkaz
37
55
  */
38
56
  export function standingOrder(input) {
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.12.2",
5
+ "version": "2.12.4",
6
6
  "license": "Apache-2.0",
7
7
  "funding": "https://github.com/sponsors/xseman",
8
8
  "homepage": "https://github.com/xseman/bysquare#readme",
@@ -22,30 +22,30 @@
22
22
  "fmt": "dprint fmt",
23
23
  "fmt:check": "dprint check",
24
24
  "typecheck": "tsc --noEmit",
25
- "test": "TS_NODE_TRANSPILE_ONLY=true node --test --experimental-test-coverage --test-coverage-exclude=src/**/*.test.ts --loader=ts-node/esm --no-warnings src/*.test.ts",
26
- "test:watch": "TS_NODE_TRANSPILE_ONLY=true node --test --watch --loader=ts-node/esm --no-warnings src/*.test.ts"
25
+ "test": "bun test --coverage ./src/*.test.ts",
26
+ "test:watch": "bun test --watch --coverage ./src/*.test.ts"
27
27
  },
28
28
  "dependencies": {
29
- "lzma1": "0.0.5",
29
+ "lzma1": "0.0.3",
30
30
  "validator": "^13.12.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.7.0",
34
34
  "@types/validator": "^13.12.0",
35
- "dprint": "~0.47.0",
36
- "ts-node": "~10.9.0",
35
+ "dprint": "~0.49.0",
37
36
  "typescript": "~5.8.0"
38
37
  },
39
- "bin": "./dist/cli.js",
38
+ "bin": "./lib/cli.js",
40
39
  "exports": {
40
+ "./package.json": "./package.json",
41
41
  ".": {
42
- "import": "./dist/index.js",
43
- "types": "./dist/index.d.ts"
42
+ "import": "./lib/index.js",
43
+ "types": "./lib/index.d.ts"
44
44
  }
45
45
  },
46
46
  "files": [
47
- "dist/*.js",
48
- "dist/*.d.ts",
49
- "!dist/*.test.*"
47
+ "lib/*.js",
48
+ "lib/*.d.ts",
49
+ "!lib/*test*"
50
50
  ]
51
51
  }
package/dist/helpers.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { type BankAccount, SimplePayment, type StandingOrder } from "./types.js";
2
- type PaymentInput = Pick<BankAccount, "iban"> & Pick<SimplePayment, "amount" | "currencyCode" | "variableSymbol">;
3
- /**
4
- * Vytvorí QR pre jednorázovú platbu
5
- */
6
- export declare function simplePayment(input: PaymentInput): string;
7
- /**
8
- * Vytvorí QR pre inkaso
9
- */
10
- export declare function directDebit(input: PaymentInput): string;
11
- type StandingInput = PaymentInput & Pick<StandingOrder, "day" | "periodicity">;
12
- /**
13
- * Vytvorí QR pre trvalý príkaz
14
- */
15
- export declare function standingOrder(input: StandingInput): string;
16
- export {};
@@ -1,42 +0,0 @@
1
- export declare const payloadWithPaymentOrder: {
2
- invoiceId: string;
3
- payments: {
4
- type: 1;
5
- amount: number;
6
- bankAccounts: {
7
- iban: string;
8
- }[];
9
- currencyCode: "EUR";
10
- variableSymbol: string;
11
- }[];
12
- };
13
- export declare const serializedPaymentOrder: string;
14
- export declare const payloadWithStandingOrder: {
15
- invoiceId: string;
16
- payments: {
17
- type: 2;
18
- amount: number;
19
- bankAccounts: {
20
- iban: string;
21
- }[];
22
- periodicity: "m";
23
- currencyCode: "EUR";
24
- variableSymbol: string;
25
- lastDate: string;
26
- day: number;
27
- }[];
28
- };
29
- export declare const serializedStandingOrder: string;
30
- export declare const payloadWithDirectDebit: {
31
- invoiceId: string;
32
- payments: {
33
- type: 4;
34
- amount: number;
35
- bankAccounts: {
36
- iban: string;
37
- }[];
38
- currencyCode: "EUR";
39
- variableSymbol: string;
40
- }[];
41
- };
42
- export declare const serializedDirectDebit: string;
@@ -1,123 +0,0 @@
1
- import { CurrencyCode, PaymentOptions, Periodicity, } from "./types.js";
2
- export const payloadWithPaymentOrder = {
3
- invoiceId: "random-id",
4
- payments: [
5
- {
6
- type: PaymentOptions.PaymentOrder,
7
- amount: 100.0,
8
- bankAccounts: [
9
- { iban: "SK9611000000002918599669" },
10
- ],
11
- currencyCode: CurrencyCode.EUR,
12
- variableSymbol: "123",
13
- },
14
- ],
15
- };
16
- export const serializedPaymentOrder = /** dprint-ignore */ [
17
- "random-id",
18
- "\t", "1",
19
- "\t", "1",
20
- "\t", "100",
21
- "\t", "EUR",
22
- "\t",
23
- "\t", "123",
24
- "\t",
25
- "\t",
26
- "\t",
27
- "\t",
28
- "\t", "1",
29
- "\t", "SK9611000000002918599669",
30
- "\t",
31
- "\t", "0",
32
- "\t", "0",
33
- "\t",
34
- "\t",
35
- "\t",
36
- ].join("");
37
- export const payloadWithStandingOrder = {
38
- invoiceId: "random-id",
39
- payments: [
40
- {
41
- type: PaymentOptions.StandingOrder,
42
- amount: 100.0,
43
- bankAccounts: [
44
- { iban: "SK9611000000002918599669" },
45
- ],
46
- periodicity: Periodicity.Monthly,
47
- currencyCode: CurrencyCode.EUR,
48
- variableSymbol: "123",
49
- lastDate: "20241011",
50
- day: 1,
51
- },
52
- ],
53
- };
54
- export const serializedStandingOrder = /** dprint-ignore */ [
55
- "random-id",
56
- "\t", "1",
57
- "\t", "2",
58
- "\t", "100",
59
- "\t", "EUR",
60
- "\t",
61
- "\t", "123",
62
- "\t",
63
- "\t",
64
- "\t",
65
- "\t",
66
- "\t", "1",
67
- "\t", "SK9611000000002918599669",
68
- "\t",
69
- "\t", "1",
70
- "\t", "1",
71
- "\t",
72
- "\t", "m",
73
- "\t", "20241011",
74
- "\t", "0",
75
- "\t",
76
- "\t",
77
- "\t",
78
- ].join("");
79
- export const payloadWithDirectDebit = {
80
- invoiceId: "random-id",
81
- payments: [
82
- {
83
- type: PaymentOptions.DirectDebit,
84
- amount: 100.0,
85
- bankAccounts: [
86
- { iban: "SK9611000000002918599669" },
87
- ],
88
- currencyCode: CurrencyCode.EUR,
89
- variableSymbol: "123",
90
- },
91
- ],
92
- };
93
- export const serializedDirectDebit = /** dprint-ignore */ [
94
- "random-id",
95
- "\t", "1",
96
- "\t", "4",
97
- "\t", "100",
98
- "\t", "EUR",
99
- "\t",
100
- "\t", "123",
101
- "\t",
102
- "\t",
103
- "\t",
104
- "\t",
105
- "\t", "1",
106
- "\t", "SK9611000000002918599669",
107
- "\t",
108
- "\t", "0",
109
- "\t", "1",
110
- "\t",
111
- "\t",
112
- "\t", "123",
113
- "\t",
114
- "\t",
115
- "\t",
116
- "\t",
117
- "\t",
118
- "\t",
119
- "\t",
120
- "\t",
121
- "\t",
122
- "\t",
123
- ].join("");
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes