@hypay/typescript-sdk 1.0.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.
- package/LICENSE +21 -0
- package/README.md +735 -0
- package/dist/chunk-LKIXYEBZ.mjs +103 -0
- package/dist/helpers-T6ONVODW.mjs +30 -0
- package/dist/index.d.mts +1363 -0
- package/dist/index.d.ts +1363 -0
- package/dist/index.js +1227 -0
- package/dist/index.mjs +1067 -0
- package/package.json +52 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/helpers.ts
|
|
2
|
+
function parseQueryString(qs) {
|
|
3
|
+
const result = {};
|
|
4
|
+
const trimmed = qs.trim();
|
|
5
|
+
if (!trimmed) return result;
|
|
6
|
+
for (const pair of trimmed.split("&")) {
|
|
7
|
+
const eqIndex = pair.indexOf("=");
|
|
8
|
+
if (eqIndex === -1) {
|
|
9
|
+
const key = decodeURIComponent(pair);
|
|
10
|
+
if (key) result[key] = "";
|
|
11
|
+
} else {
|
|
12
|
+
const key = decodeURIComponent(pair.slice(0, eqIndex));
|
|
13
|
+
const value = decodeURIComponent(pair.slice(eqIndex + 1));
|
|
14
|
+
if (key) result[key] = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
function toQueryString(params) {
|
|
20
|
+
const parts = [];
|
|
21
|
+
for (const [key, value] of Object.entries(params)) {
|
|
22
|
+
if (value === void 0) continue;
|
|
23
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
24
|
+
}
|
|
25
|
+
return parts.join("&");
|
|
26
|
+
}
|
|
27
|
+
function serializeParams(params) {
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const [key, value] of Object.entries(params)) {
|
|
30
|
+
if (value === void 0) continue;
|
|
31
|
+
if (typeof value === "boolean") {
|
|
32
|
+
result[key] = value ? "True" : "False";
|
|
33
|
+
} else {
|
|
34
|
+
result[key] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function parseRedirectUrl(url) {
|
|
40
|
+
const qsIndex = url.indexOf("?");
|
|
41
|
+
if (qsIndex === -1) return {};
|
|
42
|
+
return parseQueryString(url.slice(qsIndex + 1));
|
|
43
|
+
}
|
|
44
|
+
function parsePaymentPageResponse(url) {
|
|
45
|
+
const params = parseRedirectUrl(url);
|
|
46
|
+
return params;
|
|
47
|
+
}
|
|
48
|
+
function parseTokef(tokef) {
|
|
49
|
+
if (!tokef || tokef.length !== 4) {
|
|
50
|
+
throw new Error(`Invalid Tokef format: "${tokef}". Expected 4-digit YYMM string.`);
|
|
51
|
+
}
|
|
52
|
+
const yy = tokef.slice(0, 2);
|
|
53
|
+
const mm = tokef.slice(2, 4);
|
|
54
|
+
return {
|
|
55
|
+
Tmonth: mm,
|
|
56
|
+
Tyear: `20${yy}`
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function buildItemsString(items) {
|
|
60
|
+
return items.map((item) => `[${item.code}~${item.description}~${item.quantity}~${item.price}]`).join("");
|
|
61
|
+
}
|
|
62
|
+
function calculateItemsTotal(items) {
|
|
63
|
+
return items.reduce((sum, item) => sum + item.quantity * item.price, 0);
|
|
64
|
+
}
|
|
65
|
+
function isValidMasof(masof) {
|
|
66
|
+
return /^\d{10}$/.test(masof);
|
|
67
|
+
}
|
|
68
|
+
function isTestMasof(masof) {
|
|
69
|
+
return isValidMasof(masof) && masof.startsWith("00100");
|
|
70
|
+
}
|
|
71
|
+
function isValidToken(token) {
|
|
72
|
+
return /^\d{19}$/.test(token);
|
|
73
|
+
}
|
|
74
|
+
function isValidEmail(email) {
|
|
75
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
76
|
+
}
|
|
77
|
+
function isValidIsraeliId(id) {
|
|
78
|
+
if (!/^\d{9}$/.test(id)) return false;
|
|
79
|
+
if (id === "000000000") return true;
|
|
80
|
+
let sum = 0;
|
|
81
|
+
for (let i = 0; i < 9; i++) {
|
|
82
|
+
let digit = parseInt(id[i], 10) * (i % 2 + 1);
|
|
83
|
+
if (digit > 9) digit -= 9;
|
|
84
|
+
sum += digit;
|
|
85
|
+
}
|
|
86
|
+
return sum % 10 === 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
parseQueryString,
|
|
91
|
+
toQueryString,
|
|
92
|
+
serializeParams,
|
|
93
|
+
parseRedirectUrl,
|
|
94
|
+
parsePaymentPageResponse,
|
|
95
|
+
parseTokef,
|
|
96
|
+
buildItemsString,
|
|
97
|
+
calculateItemsTotal,
|
|
98
|
+
isValidMasof,
|
|
99
|
+
isTestMasof,
|
|
100
|
+
isValidToken,
|
|
101
|
+
isValidEmail,
|
|
102
|
+
isValidIsraeliId
|
|
103
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildItemsString,
|
|
3
|
+
calculateItemsTotal,
|
|
4
|
+
isTestMasof,
|
|
5
|
+
isValidEmail,
|
|
6
|
+
isValidIsraeliId,
|
|
7
|
+
isValidMasof,
|
|
8
|
+
isValidToken,
|
|
9
|
+
parsePaymentPageResponse,
|
|
10
|
+
parseQueryString,
|
|
11
|
+
parseRedirectUrl,
|
|
12
|
+
parseTokef,
|
|
13
|
+
serializeParams,
|
|
14
|
+
toQueryString
|
|
15
|
+
} from "./chunk-LKIXYEBZ.mjs";
|
|
16
|
+
export {
|
|
17
|
+
buildItemsString,
|
|
18
|
+
calculateItemsTotal,
|
|
19
|
+
isTestMasof,
|
|
20
|
+
isValidEmail,
|
|
21
|
+
isValidIsraeliId,
|
|
22
|
+
isValidMasof,
|
|
23
|
+
isValidToken,
|
|
24
|
+
parsePaymentPageResponse,
|
|
25
|
+
parseQueryString,
|
|
26
|
+
parseRedirectUrl,
|
|
27
|
+
parseTokef,
|
|
28
|
+
serializeParams,
|
|
29
|
+
toQueryString
|
|
30
|
+
};
|