simplepay-js-sdk 0.6.0 → 0.7.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/README.md CHANGED
@@ -33,7 +33,9 @@ Set the following environment variables in your `.env` file:
33
33
 
34
34
  You should create 3 endpoints, to start the payment, get the payment response and handle the IPN.
35
35
 
36
- ### Start Payment Endpoint
36
+ ### One Time Payment
37
+
38
+ #### Start Payment Endpoint
37
39
 
38
40
  ```typescript
39
41
  import { startPayment } from 'simplepay-js-sdk'
@@ -64,7 +66,7 @@ try {
64
66
 
65
67
  `response.paymentUrl` will contain the Simplepay payment URL, which you can redirect the customer to.
66
68
 
67
- ### Get Payment Response Endpoint
69
+ #### Get Payment Response Endpoint
68
70
 
69
71
  When the customer returns from the Simplepay payment page, you need to get the payment response at your `SIMPLEPAY_REDIRECT_URL`. The url will contain 2 parameters: `r` and `s`.
70
72
 
@@ -84,7 +86,7 @@ const response = getPaymentResponse(r, s)
84
86
  - `merchantId`: the merchant id
85
87
  - `orderRef`: the order id
86
88
 
87
- ### IPN Endpoint
89
+ #### IPN Endpoint
88
90
 
89
91
  Simplepay will send a `POST` request to the IPN url and you should send a response back.
90
92
  At this endpoint you should
@@ -94,6 +96,82 @@ At this endpoint you should
94
96
  - calculate the new signature - use `generateSignature(responseText, SIMPLEPAY_MERCHANT_KEY_HUF)`
95
97
  - send the `response` with the new `signature`
96
98
 
99
+
100
+ ### Recurring Payment
101
+
102
+ #### Start Recurring Payment Endpoint
103
+
104
+ Here you have to use the `startRecurringPayment()` function what works the same way as the `startPayment()` function. The only difference is that you have to pass 2 additional properties: `customer` and `recurring`.
105
+
106
+ ```typescript
107
+ try {
108
+ const response = await startRecurringPayment({
109
+ // ... other preoperties
110
+ customer: 'Radharadhya Dasa',
111
+ recurring: {
112
+ times: 3, // how many times the payment will be made, number of tokens
113
+ until: '2025-12-31T18:00:00+02:00', // the end date of the recurring payment - use the toISO8601DateString() helper function
114
+ maxAmount: 100000 // the maximum amount of the recurring payment
115
+ }
116
+ })
117
+ }
118
+ ```
119
+
120
+ The response will have an additional `tokens` property, what will contain the tokens of the registered cards.
121
+ You are responsible to save the tokens to your database, so you can use them later to make a payment.
122
+
123
+
124
+ #### Get Recurring Payment Response Endpoint
125
+
126
+ Use the same enpoint as the one time payment.
127
+
128
+ #### IPN Endpoint on card registration
129
+
130
+ It works the same as the `IPN` endpoint of the one time payment.
131
+ The response will have the same properties, and 2 additional properties:
132
+
133
+ - `cardMask`: xxxx-xxxx-xxxx-1234 - the masked card number what is registered
134
+ - `expiry`: 2025-01-31T00:00:00+02:00 - the expiry date of the registered card
135
+
136
+ #### Token Payment Endpoint
137
+
138
+ After a card is registered you can use the tokens to make a payment without any user intercation for example by a daily `cron`
139
+
140
+ ```typescript
141
+ import { startTokenPayment } from 'simplepay-js-sdk'
142
+
143
+ // TODO: get payment data from your database, where you saved the tokens
144
+
145
+ const payment = {
146
+ token: '1234567890123456',
147
+ total: 1212,
148
+ currency: 'HUF' as Currency,
149
+ customer: 'Radharadhya Dasa',
150
+ customerEmail: 'rrd@webmania.cc',
151
+ invoice: {
152
+ name: 'Radharadhya Dasa',
153
+ country: 'HU',
154
+ state: 'Budapest',
155
+ city: 'Budapest',
156
+ zip: '1234',
157
+ address: 'Sehol u. 0',
158
+ },
159
+ }
160
+
161
+ try {
162
+ const response = await startTokenPayment({
163
+ orderRef: Date.now().toString(),
164
+ language: 'HU',
165
+ method: 'CARD', // must be CARD
166
+ ...payment,
167
+ })
168
+ return response
169
+ } catch (error) {
170
+ console.error('Token payment initiation failed:', error)
171
+ return error
172
+ }
173
+ ```
174
+
97
175
  ## License
98
176
 
99
177
  MIT
package/dist/index.d.ts CHANGED
@@ -2,28 +2,15 @@ export declare const checkSignature: (responseText: string, signature: string, m
2
2
 
3
3
  declare const CURRENCIES: readonly ["HUF", "EUR", "USD"];
4
4
 
5
- declare type Currency = typeof CURRENCIES[number];
5
+ export declare type Currency = typeof CURRENCIES[number];
6
6
 
7
7
  export declare const generateSignature: (body: string, merchantKey: string) => string;
8
8
 
9
- export declare const getCurrencyFromMerchantId: (merchantId: string) => "HUF" | "EUR" | "USD";
9
+ export declare const getPaymentResponse: (r: string, signature: string) => SimplePayResult;
10
10
 
11
- export declare const getPaymentResponse: (r: string, signature: string) => {
12
- responseCode: number;
13
- transactionId: string;
14
- event: "success" | "fail" | "timeout" | "cancel";
15
- merchantId: string;
16
- orderRef: string;
17
- };
11
+ declare type ISO8601DateString = string;
18
12
 
19
- export declare const getSimplePayConfig: (currency: Currency) => {
20
- MERCHANT_KEY: string | undefined;
21
- MERCHANT_ID: string | undefined;
22
- API_URL: string;
23
- SDK_VERSION: string;
24
- };
25
-
26
- declare type Language = typeof LANGUAGES[number];
13
+ export declare type Language = typeof LANGUAGES[number];
27
14
 
28
15
  declare const LANGUAGES: readonly ["AR", "BG", "CS", "DE", "EN", "ES", "FR", "IT", "HR", "HU", "PL", "RO", "RU", "SK", "TR", "ZH"];
29
16
 
@@ -46,7 +33,24 @@ declare interface PaymentData {
46
33
  };
47
34
  }
48
35
 
49
- declare type PaymentMethod = 'CARD' | 'WIRE';
36
+ export declare type PaymentMethod = 'CARD' | 'WIRE';
37
+
38
+ declare interface Recurring {
39
+ times: number;
40
+ until: ISO8601DateString;
41
+ maxAmount: number;
42
+ }
43
+
44
+ declare interface RecurringPaymentData extends PaymentData {
45
+ customer: string;
46
+ recurring: Recurring;
47
+ }
48
+
49
+ declare type SimplePayEvents = 'SUCCESS' | 'FAIL' | 'TIMEOUT' | 'CANCEL';
50
+
51
+ declare interface SimplePayRecurringResponse extends SimplePayResponse {
52
+ tokens: string[];
53
+ }
50
54
 
51
55
  declare interface SimplePayResponse {
52
56
  salt: string;
@@ -54,12 +58,36 @@ declare interface SimplePayResponse {
54
58
  orderRef: string;
55
59
  currency: Currency;
56
60
  transactionId: string;
57
- timeout: string;
61
+ timeout: ISO8601DateString;
58
62
  total: string;
59
63
  paymentUrl: string;
60
64
  errorCodes?: string[];
61
65
  }
62
66
 
67
+ declare interface SimplePayResult {
68
+ responseCode: number;
69
+ transactionId: string;
70
+ event: SimplePayEvents;
71
+ merchantId: string;
72
+ orderRef: string;
73
+ tokens?: string[];
74
+ }
75
+
76
+ declare interface SimplePayTokenResponse extends Omit<SimplePayResponse, 'paymentUrl' | 'timeout'> {
77
+ }
78
+
63
79
  export declare const startPayment: (paymentData: PaymentData) => Promise<SimplePayResponse>;
64
80
 
81
+ export declare const startRecurringPayment: (paymentData: RecurringPaymentData) => Promise<SimplePayRecurringResponse>;
82
+
83
+ export declare const startTokenPayment: (paymentData: TokenPaymentData) => Promise<SimplePayTokenResponse>;
84
+
85
+ export declare const toISO8601DateString: (date: Date) => ISO8601DateString;
86
+
87
+ declare interface TokenPaymentData extends Omit<PaymentData, 'method'> {
88
+ method: 'CARD';
89
+ customer: string;
90
+ token: string;
91
+ }
92
+
65
93
  export { }
package/dist/index.js CHANGED
@@ -1,88 +1,147 @@
1
- const P = {}, I = ["HUF", "EUR", "USD"], a = (...e) => {
2
- process.env.SIMPLEPAY_LOGGER === "true" && console.log(...e);
3
- }, R = (e, t) => {
4
- const r = P.createHmac("sha384", t.trim());
5
- return r.update(e, "utf8"), r.digest("base64");
6
- }, _ = (e, t, r) => t === R(e, r), g = (e) => JSON.stringify(e).replace(/\//g, "\\/"), h = (e) => {
7
- if (!I.includes(e))
1
+ import S from "crypto";
2
+ const d = ["HUF", "EUR", "USD"], i = (...e) => {
3
+ process.env.SIMPLEPAY_LOGGER === "true" && console.log("👉 ", ...e);
4
+ }, m = (e) => {
5
+ if (!d.includes(e))
8
6
  throw new Error(`Unsupported currency: ${e}`);
9
- const t = "https://secure.simplepay.hu/payment/v2", r = "https://sandbox.simplepay.hu/payment/v2/start", o = "SimplePayV2.1_Rrd_0.5.0", s = process.env[`SIMPLEPAY_MERCHANT_KEY_${e}`], c = process.env[`SIMPLEPAY_MERCHANT_ID_${e}`], n = process.env.SIMPLEPAY_PRODUCTION === "true" ? t : r;
7
+ const r = "https://secure.simplepay.hu/payment/v2", t = "https://sandbox.simplepay.hu/payment/v2/start", n = "SimplePayV2.1_Rrd_0.6.1", s = process.env[`SIMPLEPAY_MERCHANT_KEY_${e}`], c = process.env[`SIMPLEPAY_MERCHANT_ID_${e}`], o = process.env.SIMPLEPAY_PRODUCTION === "true" ? r : t, u = process.env.SIMPLEPAY_PRODUCTION === "true" ? r : "https://sandbox.simplepay.hu/payment/v2/dorecurring";
10
8
  return {
11
9
  MERCHANT_KEY: s,
12
10
  MERCHANT_ID: c,
13
- API_URL: n,
14
- SDK_VERSION: o
11
+ API_URL: o,
12
+ API_URL_RECURRING: u,
13
+ SDK_VERSION: n
15
14
  };
16
- }, l = async (e) => {
17
- const t = e.currency || "HUF", { MERCHANT_KEY: r, MERCHANT_ID: o, API_URL: s, SDK_VERSION: c } = h(t);
18
- if (a({ MERCHANT_KEY: r, MERCHANT_ID: o, API_URL: s }), !r || !o)
19
- throw new Error("Missing SimplePay configuration");
20
- const n = {
21
- salt: P.randomBytes(16).toString("hex"),
22
- merchant: o,
23
- orderRef: e.orderRef,
24
- currency: t,
25
- customerEmail: e.customerEmail,
26
- language: e.language || "HU",
27
- sdkVersion: c,
28
- methods: [e.method || "CARD"],
29
- total: String(e.total),
30
- timeout: new Date(Date.now() + 30 * 60 * 1e3).toISOString().replace(/\.\d{3}Z$/, "+00:00"),
31
- url: process.env.SIMPLEPAY_REDIRECT_URL || "http://url.to.redirect",
32
- invoice: e.invoice
33
- }, p = g(n), u = R(p, r);
34
- a({ bodyString: p, signature: u });
15
+ }, p = (e) => JSON.stringify(e).replace(/\//g, "\\/"), l = (e, r) => {
16
+ const t = S.createHmac("sha384", r.trim());
17
+ return t.update(e, "utf8"), t.digest("base64");
18
+ }, g = (e, r, t) => r === l(e, t), R = (e) => e.toISOString().replace(/\.\d{3}Z$/, "+00:00"), _ = (e) => {
19
+ var t, n;
20
+ const r = (n = (t = Object.entries(process.env).find(
21
+ ([s, c]) => s.startsWith("SIMPLEPAY_MERCHANT_ID_") && c === e
22
+ )) == null ? void 0 : t[0]) == null ? void 0 : n.replace("SIMPLEPAY_MERCHANT_ID_", "");
23
+ if (!r)
24
+ throw new Error(`Merchant id not found in the environment: ${e}`);
25
+ return r;
26
+ }, I = async (e, r, t) => E(e, r, t, "oneTime"), f = async (e, r, t) => E(e, r, t, "recurring"), h = async (e, r, t) => E(e, r, t, "token"), E = async (e, r, t, n) => {
27
+ const s = p(r), c = l(s, t);
28
+ i({ function: `SimplePay/makeRequest/${n}`, bodyString: s, signature: c });
35
29
  try {
36
- const i = await fetch(s, {
30
+ const o = await fetch(e, {
37
31
  method: "POST",
38
32
  headers: {
39
33
  "Content-Type": "application/json",
40
- Signature: u
34
+ Signature: c
41
35
  },
42
- body: p
36
+ body: s
43
37
  });
44
- if (a({ response: i }), !i.ok)
45
- throw new Error(`SimplePay API error: ${i.status}`);
46
- const S = i.headers.get("Signature");
47
- if (a({ responseSignature: S }), !S)
38
+ if (i({ function: `SimplePay/makeRequest/${n}`, response: o }), !o.ok)
39
+ throw new Error(`SimplePay API error: ${o.status}`);
40
+ const u = o.headers.get("Signature");
41
+ if (i({ function: `SimplePay/makeRequest/${n}`, responseSignature: u }), !u)
48
42
  throw new Error("Missing response signature");
49
- const d = await i.text(), E = JSON.parse(d);
50
- if (a({ responseText: d, responseJSON: E }), E.errorCodes)
51
- throw new Error(`SimplePay API error: ${E.errorCodes}`);
52
- if (!_(d, S, r))
43
+ const P = await o.text(), a = JSON.parse(P);
44
+ if (i({ function: `SimplePay/makeRequest/${n}`, responseText: P, responseJSON: a }), a.errorCodes)
45
+ throw new Error(`SimplePay API error: ${a.errorCodes}`);
46
+ if (!g(P, u, t))
53
47
  throw new Error("Invalid response signature");
54
- return E;
55
- } catch (i) {
56
- throw i;
48
+ return a;
49
+ } catch (o) {
50
+ throw o;
57
51
  }
58
- }, f = (e) => {
59
- var r, o;
60
- const t = (o = (r = Object.entries(process.env).find(
61
- ([s, c]) => s.startsWith("SIMPLEPAY_MERCHANT_ID_") && c === e
62
- )) == null ? void 0 : r[0]) == null ? void 0 : o.replace("SIMPLEPAY_MERCHANT_ID_", "");
63
- if (!t)
64
- throw new Error(`Merchant id not found in the environment: ${e}`);
65
- return t;
66
- }, m = (e, t) => {
67
- t = decodeURIComponent(t), t = Buffer.from(t, "base64").toString("utf-8");
68
- const r = Buffer.from(e, "base64").toString("utf-8"), o = JSON.parse(r), s = f(o.m), { MERCHANT_KEY: c } = h(s);
69
- if (!_(r, t, c || ""))
70
- throw a({ rDecoded: r, signature: t }), new Error("Invalid response signature");
71
- const n = JSON.parse(r);
52
+ }, C = (e, r) => {
53
+ i({ function: "SimplePay/getPaymentResponse", r: e, signature: r }), r = decodeURIComponent(r);
54
+ const t = Buffer.from(e, "base64").toString("utf-8"), n = JSON.parse(t), s = _(n.m), { MERCHANT_KEY: c } = m(s);
55
+ if (!g(t, r, c || ""))
56
+ throw i({ function: "SimplePay/getPaymentResponse", rDecoded: t, signature: r }), new Error("Invalid response signature");
57
+ const o = JSON.parse(t);
72
58
  return {
73
- responseCode: n.r,
74
- transactionId: n.t,
75
- event: n.e,
76
- merchantId: n.m,
77
- orderRef: n.o
59
+ responseCode: o.r,
60
+ transactionId: o.t,
61
+ event: o.e,
62
+ merchantId: o.m,
63
+ orderRef: o.o,
64
+ tokens: o.tokens
65
+ };
66
+ }, w = async (e) => {
67
+ i({ function: "SimplePay/startPayment", paymentData: e });
68
+ const r = e.currency || "HUF", { MERCHANT_KEY: t, MERCHANT_ID: n, API_URL: s, SDK_VERSION: c } = m(r);
69
+ if (i({ function: "SimplePay/startPayment", MERCHANT_KEY: t, MERCHANT_ID: n, API_URL: s }), !t || !n)
70
+ throw new Error(`Missing SimplePay configuration for ${r}`);
71
+ const o = {
72
+ salt: S.randomBytes(16).toString("hex"),
73
+ merchant: n,
74
+ orderRef: e.orderRef,
75
+ currency: r,
76
+ customerEmail: e.customerEmail,
77
+ language: e.language || "HU",
78
+ sdkVersion: c,
79
+ methods: [e.method || "CARD"],
80
+ total: String(e.total),
81
+ timeout: R(new Date(Date.now() + 30 * 60 * 1e3)),
82
+ url: process.env.SIMPLEPAY_REDIRECT_URL || "http://url.to.redirect",
83
+ invoice: e.invoice
84
+ };
85
+ return I(s, o, t);
86
+ }, A = 6, y = new Date(Date.now() + A * 30 * 24 * 60 * 60 * 1e3), M = 12e3, T = 3, U = async (e) => {
87
+ i({ function: "SimplePay/startRecurringPayment", paymentData: e });
88
+ const r = e.currency || "HUF", { MERCHANT_KEY: t, MERCHANT_ID: n, API_URL: s, SDK_VERSION: c } = m(r);
89
+ if (i({ function: "SimplePay/startRecurringPayment", MERCHANT_KEY: t, MERCHANT_ID: n, API_URL: s }), !t || !n)
90
+ throw new Error(`Missing SimplePay configuration for ${r}`);
91
+ const o = {
92
+ salt: S.randomBytes(16).toString("hex"),
93
+ merchant: n,
94
+ orderRef: e.orderRef,
95
+ currency: r,
96
+ customer: e.customer,
97
+ customerEmail: e.customerEmail,
98
+ language: e.language || "HU",
99
+ sdkVersion: c,
100
+ methods: ["CARD"],
101
+ recurring: {
102
+ times: e.recurring.times || T,
103
+ until: e.recurring.until || R(y),
104
+ maxAmount: e.recurring.maxAmount || M
105
+ },
106
+ threeDSReqAuthMethod: "02",
107
+ total: String(e.total),
108
+ timeout: R(new Date(Date.now() + 30 * 60 * 1e3)),
109
+ url: process.env.SIMPLEPAY_REDIRECT_URL || "http://url.to.redirect",
110
+ invoice: e.invoice
111
+ };
112
+ return f(s, o, t);
113
+ }, L = async (e) => {
114
+ i({ function: "SimplePay/startTokenPayment", paymentData: e });
115
+ const r = e.currency || "HUF", { MERCHANT_KEY: t, MERCHANT_ID: n, API_URL_RECURRING: s, SDK_VERSION: c } = m(r);
116
+ if (i({ function: "SimplePay/startTokenPayment", MERCHANT_KEY: t, MERCHANT_ID: n, API_URL_RECURRING: s }), !t || !n)
117
+ throw new Error(`Missing SimplePay configuration for ${r}`);
118
+ const o = {
119
+ salt: S.randomBytes(16).toString("hex"),
120
+ merchant: n,
121
+ orderRef: e.orderRef,
122
+ currency: r,
123
+ customer: e.customer,
124
+ customerEmail: e.customerEmail,
125
+ language: e.language || "HU",
126
+ sdkVersion: c,
127
+ methods: ["CARD"],
128
+ token: e.token,
129
+ type: "MIT",
130
+ threeDSReqAuthMethod: "02",
131
+ total: String(e.total),
132
+ timeout: R(new Date(Date.now() + 30 * 60 * 1e3)),
133
+ url: process.env.SIMPLEPAY_REDIRECT_URL || "http://recurring.url.to.redirect",
134
+ invoice: e.invoice
78
135
  };
136
+ return h(s, o, t);
79
137
  };
80
138
  export {
81
- _ as checkSignature,
82
- R as generateSignature,
83
- f as getCurrencyFromMerchantId,
84
- m as getPaymentResponse,
85
- h as getSimplePayConfig,
86
- l as startPayment
139
+ g as checkSignature,
140
+ l as generateSignature,
141
+ C as getPaymentResponse,
142
+ w as startPayment,
143
+ U as startRecurringPayment,
144
+ L as startTokenPayment,
145
+ R as toISO8601DateString
87
146
  };
88
147
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../__vite-browser-external","../src/types.ts","../src/index.ts"],"sourcesContent":["export default {}","type PaymentMethod = 'CARD' | 'WIRE'\n\nconst CURRENCIES = ['HUF', 'EUR', 'USD'] as const\ntype Currency = typeof CURRENCIES[number]\n\nconst LANGUAGES = [\n 'AR', // Arabic\n 'BG', // Bulgarian\n 'CS', // Czech\n 'DE', // German\n 'EN', // English\n 'ES', // Spanish\n 'FR', // French\n 'IT', // Italian\n 'HR', // Croatian\n 'HU', // Hungarian\n 'PL', // Polish\n 'RO', // Romanian\n 'RU', // Russian\n 'SK', // Slovak\n 'TR', // Turkish\n 'ZH', // Chinese\n] as const\ntype Language = typeof LANGUAGES[number]\n\ninterface PaymentData {\n orderRef: string\n total: number | string\n customerEmail: string\n currency?: Currency\n language?: Language\n method?: PaymentMethod\n invoice?: {\n name: string\n country: string\n state: string\n city: string\n zip: string\n address: string\n address2?: string\n phone?: string\n }\n}\n\ninterface SimplePayRequestBody extends Omit<PaymentData, 'total'> {\n total: string\n salt: string\n merchant: string\n sdkVersion: string\n methods: PaymentMethod[]\n timeout: string\n url: string\n}\n\ninterface SimplePayResponse {\n salt: string\n merchant: string\n orderRef: string\n currency: Currency\n transactionId: string\n timeout: string\n total: string\n paymentUrl: string\n errorCodes?: string[]\n}\n\ninterface SimplepayResult {\n r: number // response code\n t: string // transaction id\n e: 'success' | 'fail' | 'timeout' | 'cancel' // event\n m: string // merchant id\n o: string // order id\n}\n\nexport { PaymentData, SimplePayRequestBody, SimplePayResponse, SimplepayResult, CURRENCIES, Currency, PaymentMethod, LANGUAGES, Language }","import crypto from 'crypto'\nimport { PaymentData, SimplePayRequestBody, SimplePayResponse, SimplepayResult, Currency, CURRENCIES } from './types'\n\n// Existing interfaces remain the same\n\nconst simplepayLogger = (...args: any[]) => {\n if (process.env.SIMPLEPAY_LOGGER !== 'true') {\n return\n }\n console.log(...args)\n}\n\nconst generateSignature = (body: string, merchantKey: string) => {\n const hmac = crypto.createHmac('sha384', merchantKey.trim())\n hmac.update(body, 'utf8')\n return hmac.digest('base64')\n}\n\nconst checkSignature = (responseText: string, signature: string, merchantKey: string) =>\n signature === generateSignature(responseText, merchantKey)\n\n// escaping slashes for the request body to prevent strange SimplePay API errors (eg Missing Signature)\nconst prepareRequestBody = (body: SimplePayRequestBody) =>\n JSON.stringify(body).replace(/\\//g, '\\\\/')\n\n\nconst getSimplePayConfig = (currency: Currency) => {\n if (!CURRENCIES.includes(currency)) {\n throw new Error(`Unsupported currency: ${currency}`)\n }\n\n const SIMPLEPAY_API_URL = 'https://secure.simplepay.hu/payment/v2'\n const SIMPLEPAY_SANDBOX_URL = 'https://sandbox.simplepay.hu/payment/v2/start'\n const SDK_VERSION = 'SimplePayV2.1_Rrd_0.5.0'\n const MERCHANT_KEY = process.env[`SIMPLEPAY_MERCHANT_KEY_${currency}`]\n const MERCHANT_ID = process.env[`SIMPLEPAY_MERCHANT_ID_${currency}`]\n const API_URL = process.env.SIMPLEPAY_PRODUCTION === 'true' ? SIMPLEPAY_API_URL : SIMPLEPAY_SANDBOX_URL\n\n return {\n MERCHANT_KEY,\n MERCHANT_ID,\n API_URL,\n SDK_VERSION\n }\n}\n\nconst startPayment = async (paymentData: PaymentData) => {\n const currency = paymentData.currency || 'HUF'\n const { MERCHANT_KEY, MERCHANT_ID, API_URL, SDK_VERSION } = getSimplePayConfig(currency)\n simplepayLogger({ MERCHANT_KEY, MERCHANT_ID, API_URL })\n\n if (!MERCHANT_KEY || !MERCHANT_ID) {\n throw new Error('Missing SimplePay configuration')\n }\n\n const requestBody: SimplePayRequestBody = {\n salt: crypto.randomBytes(16).toString('hex'),\n merchant: MERCHANT_ID,\n orderRef: paymentData.orderRef,\n currency,\n customerEmail: paymentData.customerEmail,\n language: paymentData.language || 'HU',\n sdkVersion: SDK_VERSION,\n methods: [paymentData.method || 'CARD'],\n total: String(paymentData.total),\n timeout: new Date(Date.now() + 30 * 60 * 1000)\n .toISOString()\n .replace(/\\.\\d{3}Z$/, '+00:00'),\n url: process.env.SIMPLEPAY_REDIRECT_URL || 'http://url.to.redirect',\n invoice: paymentData.invoice,\n }\n\n const bodyString = prepareRequestBody(requestBody)\n const signature = generateSignature(bodyString, MERCHANT_KEY)\n simplepayLogger({ bodyString, signature })\n\n try {\n const response = await fetch(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Signature': signature,\n },\n body: bodyString,\n })\n\n simplepayLogger({ response })\n\n if (!response.ok) {\n throw new Error(`SimplePay API error: ${response.status}`)\n }\n\n const responseSignature = response.headers.get('Signature')\n simplepayLogger({ responseSignature })\n if (!responseSignature) {\n throw new Error('Missing response signature')\n }\n\n const responseText = await response.text()\n const responseJSON = JSON.parse(responseText) as SimplePayResponse\n simplepayLogger({ responseText, responseJSON })\n\n if (responseJSON.errorCodes) {\n throw new Error(`SimplePay API error: ${responseJSON.errorCodes}`)\n }\n\n if (!checkSignature(responseText, responseSignature, MERCHANT_KEY)) {\n throw new Error('Invalid response signature')\n }\n\n return responseJSON\n\n } catch (error) {\n throw error\n }\n}\n\nconst getCurrencyFromMerchantId = (merchantId: string) => {\n const currency = Object.entries(process.env)\n .find(([key, value]) =>\n key.startsWith('SIMPLEPAY_MERCHANT_ID_') && value === merchantId\n )?.[0]?.replace('SIMPLEPAY_MERCHANT_ID_', '') as Currency\n if (!currency) {\n throw new Error(`Merchant id not found in the environment: ${merchantId}`)\n }\n return currency\n}\n\nconst getPaymentResponse = (r: string, signature: string) => {\n signature = decodeURIComponent(signature)\n signature = Buffer.from(signature, 'base64').toString('utf-8')\n const rDecoded = Buffer.from(r, 'base64').toString('utf-8')\n const rDecodedJSON = JSON.parse(rDecoded)\n const currency = getCurrencyFromMerchantId(rDecodedJSON.m)\n const { MERCHANT_KEY } = getSimplePayConfig(currency as Currency)\n\n if (!checkSignature(rDecoded, signature, MERCHANT_KEY || '')) {\n simplepayLogger({ rDecoded, signature })\n throw new Error('Invalid response signature')\n }\n\n const responseJson: SimplepayResult = JSON.parse(rDecoded)\n const response = {\n responseCode: responseJson.r,\n transactionId: responseJson.t,\n event: responseJson.e,\n merchantId: responseJson.m,\n orderRef: responseJson.o,\n }\n\n return response\n}\n\nexport {\n startPayment,\n getPaymentResponse,\n getSimplePayConfig,\n generateSignature,\n checkSignature,\n getCurrencyFromMerchantId\n}"],"names":["crypto","CURRENCIES","simplepayLogger","args","generateSignature","body","merchantKey","hmac","checkSignature","responseText","signature","prepareRequestBody","getSimplePayConfig","currency","SIMPLEPAY_API_URL","SIMPLEPAY_SANDBOX_URL","SDK_VERSION","MERCHANT_KEY","MERCHANT_ID","API_URL","startPayment","paymentData","requestBody","bodyString","response","responseSignature","responseJSON","error","getCurrencyFromMerchantId","merchantId","_a","_b","key","value","getPaymentResponse","r","rDecoded","rDecodedJSON","responseJson"],"mappings":"AAAA,MAAeA,IAAA,CAAA,GCETC,IAAa,CAAC,OAAO,OAAO,KAAK,GCGjCC,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;AAEd,GAEMC,IAA4B,CAACC,MAAuB;AFrH1D,MAAAC,GAAAC;AEsHI,QAAMlB,KAAWkB,KAAAD,IAAA,OAAO,QAAQ,QAAQ,GAAG,EACtC;AAAA,IAAK,CAAC,CAACE,GAAKC,CAAK,MACdD,EAAI,WAAW,wBAAwB,KAAKC,MAAUJ;AAAA,EACtD,MAHS,gBAAAC,EAGT,OAHS,gBAAAC,EAGL,QAAQ,0BAA0B;AAC9C,MAAI,CAAClB;AACD,UAAM,IAAI,MAAM,6CAA6CgB,CAAU,EAAE;AAEtE,SAAAhB;AACX,GAEMqB,IAAqB,CAACC,GAAWzB,MAAsB;AACzD,EAAAA,IAAY,mBAAmBA,CAAS,GACxCA,IAAY,OAAO,KAAKA,GAAW,QAAQ,EAAE,SAAS,OAAO;AAC7D,QAAM0B,IAAW,OAAO,KAAKD,GAAG,QAAQ,EAAE,SAAS,OAAO,GACpDE,IAAe,KAAK,MAAMD,CAAQ,GAClCvB,IAAWe,EAA0BS,EAAa,CAAC,GACnD,EAAE,cAAApB,EAAA,IAAiBL,EAAmBC,CAAoB;AAEhE,MAAI,CAACL,EAAe4B,GAAU1B,GAAWO,KAAgB,EAAE;AACvC,UAAAf,EAAA,EAAE,UAAAkC,GAAU,WAAA1B,GAAW,GACjC,IAAI,MAAM,4BAA4B;AAG1C,QAAA4B,IAAgC,KAAK,MAAMF,CAAQ;AASlD,SARU;AAAA,IACb,cAAcE,EAAa;AAAA,IAC3B,eAAeA,EAAa;AAAA,IAC5B,OAAOA,EAAa;AAAA,IACpB,YAAYA,EAAa;AAAA,IACzB,UAAUA,EAAa;AAAA,EAC3B;AAGJ;"}
1
+ {"version":3,"file":"index.js","sources":["../src/types.ts","../src/utils.ts","../src/oneTime.ts","../src/recurring.ts"],"sourcesContent":["export type PaymentMethod = 'CARD' | 'WIRE'\n\nexport const CURRENCIES = ['HUF', 'EUR', 'USD'] as const\nexport type Currency = typeof CURRENCIES[number]\n\nexport const LANGUAGES = [\n 'AR', // Arabic\n 'BG', // Bulgarian\n 'CS', // Czech\n 'DE', // German\n 'EN', // English\n 'ES', // Spanish\n 'FR', // French\n 'IT', // Italian\n 'HR', // Croatian\n 'HU', // Hungarian\n 'PL', // Polish\n 'RO', // Romanian\n 'RU', // Russian\n 'SK', // Slovak\n 'TR', // Turkish\n 'ZH', // Chinese\n] as const\nexport type Language = typeof LANGUAGES[number]\n\nexport interface PaymentData {\n orderRef: string\n total: number | string\n customerEmail: string\n currency?: Currency\n language?: Language\n method?: PaymentMethod\n invoice?: {\n name: string\n country: string\n state: string\n city: string\n zip: string\n address: string\n address2?: string\n phone?: string\n }\n}\n\nexport type ISO8601DateString = string\nexport interface Recurring {\n times: number,\n until: ISO8601DateString,\n maxAmount: number\n}\nexport interface RecurringPaymentData extends PaymentData {\n customer: string,\n recurring: Recurring\n}\n\nexport interface TokenPaymentData extends Omit<PaymentData, 'method'> {\n method: 'CARD',\n customer: string,\n token: string\n}\n\nexport interface SimplePayRequestBody extends Omit<PaymentData, 'total'> {\n total: string\n salt: string\n merchant: string\n sdkVersion: string\n methods: PaymentMethod[]\n timeout: string\n url: string\n}\n\nexport interface SimplePayRecurringRequestBody extends SimplePayRequestBody {\n customer: string\n recurring: Recurring\n threeDSReqAuthMethod: '02' // only registered users can use this\n}\n\nexport interface SimplePayTokenRequestBody extends SimplePayRequestBody {\n customer: string\n token: string\n threeDSReqAuthMethod: '02' // only registered users can use this\n type: 'MIT' // Merchant Initiated Transaction\n}\n\nexport interface SimplePayResponse {\n salt: string\n merchant: string\n orderRef: string\n currency: Currency\n transactionId: string\n timeout: ISO8601DateString\n total: string\n paymentUrl: string\n errorCodes?: string[]\n}\n\nexport interface SimplePayRecurringResponse extends SimplePayResponse {\n tokens: string[]\n}\n\nexport interface SimplePayTokenResponse extends Omit<SimplePayResponse, 'paymentUrl' | 'timeout'> { }\n\nexport type SimplePayEvents = 'SUCCESS' | 'FAIL' | 'TIMEOUT' | 'CANCEL'\n\nexport interface SimplePayAPIResult {\n r: number // response code\n t: string // transaction id\n e: SimplePayEvents // event\n m: string // merchant id\n o: string // order id\n}\n\nexport interface SimplePayResult {\n responseCode: number,\n transactionId: string,\n event: SimplePayEvents,\n merchantId: string,\n orderRef: string,\n tokens?: string[],\n}\n","import crypto from 'crypto'\nimport { CURRENCIES, Currency, ISO8601DateString, SimplePayAPIResult, SimplePayRecurringRequestBody, SimplePayRecurringResponse, SimplePayRequestBody, SimplePayResponse, SimplePayResult, SimplePayTokenRequestBody, SimplePayTokenResponse } from \"./types\"\n\nexport const simplepayLogger = (...args: any[]) => {\n if (process.env.SIMPLEPAY_LOGGER !== 'true') {\n return\n }\n\n console.log('👉 ', ...args)\n}\n\nexport const getSimplePayConfig = (currency: Currency) => {\n if (!CURRENCIES.includes(currency)) {\n throw new Error(`Unsupported currency: ${currency}`)\n }\n\n const SIMPLEPAY_API_URL = 'https://secure.simplepay.hu/payment/v2'\n const SIMPLEPAY_SANDBOX_URL = 'https://sandbox.simplepay.hu/payment/v2/start'\n const SDK_VERSION = 'SimplePayV2.1_Rrd_0.6.1'\n const MERCHANT_KEY = process.env[`SIMPLEPAY_MERCHANT_KEY_${currency}`]\n const MERCHANT_ID = process.env[`SIMPLEPAY_MERCHANT_ID_${currency}`]\n const API_URL = process.env.SIMPLEPAY_PRODUCTION === 'true' ? SIMPLEPAY_API_URL : SIMPLEPAY_SANDBOX_URL\n const API_URL_RECURRING = process.env.SIMPLEPAY_PRODUCTION === 'true' ? SIMPLEPAY_API_URL : 'https://sandbox.simplepay.hu/payment/v2/dorecurring'\n\n return {\n MERCHANT_KEY,\n MERCHANT_ID,\n API_URL,\n API_URL_RECURRING,\n SDK_VERSION\n }\n}\n\n// escaping slashes for the request body to prevent strange SimplePay API errors (eg Missing Signature)\nexport const prepareRequestBody = (body: any) =>\n JSON.stringify(body).replace(/\\//g, '\\\\/')\n\nexport const generateSignature = (body: string, merchantKey: string) => {\n const hmac = crypto.createHmac('sha384', merchantKey.trim())\n hmac.update(body, 'utf8')\n return hmac.digest('base64')\n}\n\nexport const checkSignature = (responseText: string, signature: string, merchantKey: string) =>\n signature === generateSignature(responseText, merchantKey)\n\nexport const toISO8601DateString = (date: Date): ISO8601DateString => date.toISOString().replace(/\\.\\d{3}Z$/, '+00:00')\n\nexport const getCurrencyFromMerchantId = (merchantId: string) => {\n const currency = Object.entries(process.env)\n .find(([key, value]) =>\n key.startsWith('SIMPLEPAY_MERCHANT_ID_') && value === merchantId\n )?.[0]?.replace('SIMPLEPAY_MERCHANT_ID_', '') as Currency\n if (!currency) {\n throw new Error(`Merchant id not found in the environment: ${merchantId}`)\n }\n return currency\n}\n\nexport const makeSimplePayRequest = async (apiUrl: string, requestBody: SimplePayRequestBody, merchantKey: string) => {\n return makeRequest(apiUrl, requestBody, merchantKey, 'oneTime') as Promise<SimplePayResponse>\n}\n\nexport const makeSimplePayRecurringRequest = async (apiUrl: string, requestBody: SimplePayRecurringRequestBody, merchantKey: string) => {\n return makeRequest(apiUrl, requestBody, merchantKey, 'recurring') as Promise<SimplePayRecurringResponse>\n}\n\nexport const makeSimplePayTokenRequest = async (apiUrl: string, requestBody: SimplePayTokenRequestBody, merchantKey: string) => {\n return makeRequest(apiUrl, requestBody, merchantKey, 'token') as Promise<SimplePayTokenResponse>\n}\n\nconst makeRequest = async (apiUrl: string, requestBody: SimplePayRequestBody | SimplePayRecurringRequestBody | SimplePayTokenRequestBody, merchantKey: string, type: 'oneTime' | 'recurring' | 'token') => {\n const bodyString = prepareRequestBody(requestBody)\n const signature = generateSignature(bodyString, merchantKey)\n simplepayLogger({ function: `SimplePay/makeRequest/${type}`, bodyString, signature })\n\n try {\n const response = await fetch(apiUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Signature': signature,\n },\n body: bodyString,\n })\n\n simplepayLogger({ function: `SimplePay/makeRequest/${type}`, response })\n\n if (!response.ok) {\n throw new Error(`SimplePay API error: ${response.status}`)\n }\n\n const responseSignature = response.headers.get('Signature')\n simplepayLogger({ function: `SimplePay/makeRequest/${type}`, responseSignature })\n if (!responseSignature) {\n throw new Error('Missing response signature')\n }\n\n const responseText = await response.text()\n const responseJSON = JSON.parse(responseText) as { errorCodes?: string[] }\n simplepayLogger({ function: `SimplePay/makeRequest/${type}`, responseText, responseJSON })\n\n if (responseJSON.errorCodes) {\n throw new Error(`SimplePay API error: ${responseJSON.errorCodes}`)\n }\n\n if (!checkSignature(responseText, responseSignature, merchantKey)) {\n throw new Error('Invalid response signature')\n }\n\n return responseJSON\n\n } catch (error) {\n throw error\n }\n}\n\nexport const getPaymentResponse = (r: string, signature: string) => {\n simplepayLogger({ function: 'SimplePay/getPaymentResponse', r, signature })\n signature = decodeURIComponent(signature)\n const rDecoded = Buffer.from(r, 'base64').toString('utf-8')\n const rDecodedJSON = JSON.parse(rDecoded) as SimplePayAPIResult\n const currency = getCurrencyFromMerchantId(rDecodedJSON.m)\n const { MERCHANT_KEY } = getSimplePayConfig(currency as Currency)\n\n if (!checkSignature(rDecoded, signature, MERCHANT_KEY || '')) {\n simplepayLogger({ function: 'SimplePay/getPaymentResponse', rDecoded, signature })\n throw new Error('Invalid response signature')\n }\n\n const responseJson = JSON.parse(rDecoded)\n const response: SimplePayResult = {\n responseCode: responseJson.r,\n transactionId: responseJson.t,\n event: responseJson.e,\n merchantId: responseJson.m,\n orderRef: responseJson.o,\n tokens: responseJson.tokens,\n }\n\n return response\n}\n","import crypto from 'crypto'\nimport { PaymentData, SimplePayRequestBody } from './types'\nimport { simplepayLogger, getSimplePayConfig, toISO8601DateString, makeSimplePayRequest } from './utils'\n\nconst startPayment = async (paymentData: PaymentData) => {\n simplepayLogger({ function: 'SimplePay/startPayment', paymentData })\n const currency = paymentData.currency || 'HUF'\n const { MERCHANT_KEY, MERCHANT_ID, API_URL, SDK_VERSION } = getSimplePayConfig(currency)\n simplepayLogger({ function: 'SimplePay/startPayment', MERCHANT_KEY, MERCHANT_ID, API_URL })\n\n if (!MERCHANT_KEY || !MERCHANT_ID) {\n throw new Error(`Missing SimplePay configuration for ${currency}`)\n }\n\n const requestBody: SimplePayRequestBody = {\n salt: crypto.randomBytes(16).toString('hex'),\n merchant: MERCHANT_ID,\n orderRef: paymentData.orderRef,\n currency,\n customerEmail: paymentData.customerEmail,\n language: paymentData.language || 'HU',\n sdkVersion: SDK_VERSION,\n methods: [paymentData.method || 'CARD'],\n total: String(paymentData.total),\n timeout: toISO8601DateString(new Date(Date.now() + 30 * 60 * 1000)),\n url: process.env.SIMPLEPAY_REDIRECT_URL || 'http://url.to.redirect',\n invoice: paymentData.invoice,\n }\n\n return makeSimplePayRequest(API_URL, requestBody, MERCHANT_KEY)\n}\n\nexport { startPayment }\n","import crypto from 'crypto'\nimport { SimplePayRecurringRequestBody, RecurringPaymentData, TokenPaymentData, SimplePayTokenRequestBody} from './types'\nimport { getSimplePayConfig, simplepayLogger, toISO8601DateString, makeSimplePayTokenRequest, makeSimplePayRecurringRequest} from './utils'\n\nconst INTERVAL_IN_MONTHS = 6\nconst DEFAULT_UNTIL = new Date(Date.now() + INTERVAL_IN_MONTHS * 30 * 24 * 60 * 60 * 1000)\nconst DEFAULT_MAX_AMOUNT = 12000\nconst DEFAULT_TIMES = 3\n\nconst startRecurringPayment = async (paymentData: RecurringPaymentData) => {\n simplepayLogger({ function: 'SimplePay/startRecurringPayment', paymentData })\n const currency = paymentData.currency || 'HUF'\n const { MERCHANT_KEY, MERCHANT_ID, API_URL, SDK_VERSION } = getSimplePayConfig(currency)\n simplepayLogger({ function: 'SimplePay/startRecurringPayment', MERCHANT_KEY, MERCHANT_ID, API_URL })\n\n if (!MERCHANT_KEY || !MERCHANT_ID) {\n throw new Error(`Missing SimplePay configuration for ${currency}`)\n }\n\n const requestBody: SimplePayRecurringRequestBody = {\n salt: crypto.randomBytes(16).toString('hex'),\n merchant: MERCHANT_ID,\n orderRef: paymentData.orderRef,\n currency,\n customer: paymentData.customer,\n customerEmail: paymentData.customerEmail,\n language: paymentData.language || 'HU',\n sdkVersion: SDK_VERSION,\n methods: ['CARD'],\n recurring: {\n times: paymentData.recurring.times || DEFAULT_TIMES,\n until: paymentData.recurring.until || toISO8601DateString(DEFAULT_UNTIL),\n maxAmount: paymentData.recurring.maxAmount || DEFAULT_MAX_AMOUNT\n },\n threeDSReqAuthMethod: '02', \n total: String(paymentData.total),\n timeout: toISO8601DateString(new Date(Date.now() + 30 * 60 * 1000)),\n url: process.env.SIMPLEPAY_REDIRECT_URL || 'http://url.to.redirect',\n invoice: paymentData.invoice,\n }\n\n return makeSimplePayRecurringRequest(API_URL, requestBody, MERCHANT_KEY)\n}\n\nconst startTokenPayment = async (paymentData: TokenPaymentData) => {\n simplepayLogger({ function: 'SimplePay/startTokenPayment', paymentData })\n const currency = paymentData.currency || 'HUF'\n const { MERCHANT_KEY, MERCHANT_ID, API_URL_RECURRING, SDK_VERSION } = getSimplePayConfig(currency)\n simplepayLogger({ function: 'SimplePay/startTokenPayment', MERCHANT_KEY, MERCHANT_ID, API_URL_RECURRING })\n\n if (!MERCHANT_KEY || !MERCHANT_ID) {\n throw new Error(`Missing SimplePay configuration for ${currency}`)\n }\n\n const requestBody: SimplePayTokenRequestBody = {\n salt: crypto.randomBytes(16).toString('hex'),\n merchant: MERCHANT_ID,\n orderRef: paymentData.orderRef,\n currency,\n customer: paymentData.customer,\n customerEmail: paymentData.customerEmail,\n language: paymentData.language || 'HU',\n sdkVersion: SDK_VERSION,\n methods: ['CARD'],\n token: paymentData.token,\n type: 'MIT',\n threeDSReqAuthMethod: '02',\n total: String(paymentData.total),\n timeout: toISO8601DateString(new Date(Date.now() + 30 * 60 * 1000)),\n url: process.env.SIMPLEPAY_REDIRECT_URL || 'http://recurring.url.to.redirect',\n invoice: paymentData.invoice,\n }\n\n return makeSimplePayTokenRequest(API_URL_RECURRING, requestBody, MERCHANT_KEY)\n}\n\nexport { startRecurringPayment, startTokenPayment }"],"names":["CURRENCIES","simplepayLogger","args","getSimplePayConfig","currency","SIMPLEPAY_API_URL","SIMPLEPAY_SANDBOX_URL","SDK_VERSION","MERCHANT_KEY","MERCHANT_ID","API_URL","API_URL_RECURRING","prepareRequestBody","body","generateSignature","merchantKey","hmac","crypto","checkSignature","responseText","signature","toISO8601DateString","date","getCurrencyFromMerchantId","merchantId","_b","_a","key","value","makeSimplePayRequest","apiUrl","requestBody","makeRequest","makeSimplePayRecurringRequest","makeSimplePayTokenRequest","type","bodyString","response","responseSignature","responseJSON","error","getPaymentResponse","r","rDecoded","rDecodedJSON","responseJson","startPayment","paymentData","INTERVAL_IN_MONTHS","DEFAULT_UNTIL","DEFAULT_MAX_AMOUNT","DEFAULT_TIMES","startRecurringPayment","startTokenPayment"],"mappings":";AAEO,MAAMA,IAAa,CAAC,OAAO,OAAO,KAAK,GCCjCC,IAAkB,IAAIC,MAAgB;AAC3C,EAAA,QAAQ,IAAI,qBAAqB,UAI7B,QAAA,IAAI,OAAO,GAAGA,CAAI;AAC9B,GAEaC,IAAqB,CAACC,MAAuB;AACtD,MAAI,CAACJ,EAAW,SAASI,CAAQ;AAC7B,UAAM,IAAI,MAAM,yBAAyBA,CAAQ,EAAE;AAGvD,QAAMC,IAAoB,0CACpBC,IAAwB,iDACxBC,IAAc,2BACdC,IAAe,QAAQ,IAAI,0BAA0BJ,CAAQ,EAAE,GAC/DK,IAAc,QAAQ,IAAI,yBAAyBL,CAAQ,EAAE,GAC7DM,IAAU,QAAQ,IAAI,yBAAyB,SAASL,IAAoBC,GAC5EK,IAAoB,QAAQ,IAAI,yBAAyB,SAASN,IAAoB;AAErF,SAAA;AAAA,IACH,cAAAG;AAAA,IACA,aAAAC;AAAA,IACA,SAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,aAAAJ;AAAA,EACJ;AACJ,GAGaK,IAAqB,CAACC,MAC/B,KAAK,UAAUA,CAAI,EAAE,QAAQ,OAAO,KAAK,GAEhCC,IAAoB,CAACD,GAAcE,MAAwB;AACpE,QAAMC,IAAOC,EAAO,WAAW,UAAUF,EAAY,MAAM;AACtD,SAAAC,EAAA,OAAOH,GA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a,mBAAAE,GAAmB,GAErG,CAACH,KAAgB,CAACC;AAClB,UAAM,IAAI,MAAM,uCAAuCL,CAAQ,EAAE;AAGrE,QAAM2B,IAAyC;AAAA,IAC3C,MAAMd,EAAO,YAAY,EAAE,EAAE,SAAS,KAAK;AAAA,IAC3C,UAAUR;AAAA,IACV,UAAUsC,EAAY;AAAA,IACtB,UAAA3C;AAAA,IACA,UAAU2C,EAAY;AAAA,IACtB,eAAeA,EAAY;AAAA,IAC3B,UAAUA,EAAY,YAAY;AAAA,IAClC,YAAYxC;AAAA,IACZ,SAAS,CAAC,MAAM;AAAA,IAChB,OAAOwC,EAAY;AAAA,IACnB,MAAM;AAAA,IACN,sBAAsB;AAAA,IACtB,OAAO,OAAOA,EAAY,KAAK;AAAA,IAC/B,SAAS1B,EAAoB,IAAI,KAAK,KAAK,QAAQ,KAAK,KAAK,GAAI,CAAC;AAAA,IAClE,KAAK,QAAQ,IAAI,0BAA0B;AAAA,IAC3C,SAAS0B,EAAY;AAAA,EACzB;AAEK,SAAAb,EAA0BvB,GAAmBoB,GAAavB,CAAY;AAC/E;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplepay-js-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A Node.js utility for SimplePay payment integration",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,8 @@
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js"
14
+ "import": "./dist/index.js",
15
+ "node": "./dist/index.js"
15
16
  }
16
17
  },
17
18
  "types": "./dist/index.d.ts",
@@ -37,12 +38,13 @@
37
38
  "license": "MIT",
38
39
  "devDependencies": {
39
40
  "@types/node": "^22.0.0",
40
- "typescript": "^5.7.2",
41
+ "typescript": "~5.4.2",
41
42
  "vite": "^6.0.3",
42
43
  "vite-plugin-dts": "^4.3.0",
43
44
  "vitest": "^2.1.6"
44
45
  },
45
46
  "engines": {
46
47
  "node": ">=20.0.0"
47
- }
48
+ },
49
+ "browser": false
48
50
  }