simplepay-js-sdk 0.6.1 → 0.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.
- package/README-ENG.md +203 -0
- package/README.md +138 -36
- package/dist/index.d.ts +57 -19
- package/dist/index.js +140 -68
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +8 -157
- package/src/oneTime.spec.ts +97 -0
- package/src/oneTime.ts +33 -0
- package/src/recurring.spec.ts +71 -0
- package/src/recurring.ts +94 -0
- package/src/types.ts +72 -12
- package/src/{index.spec.ts → utils.spec.ts} +6 -78
- package/src/utils.ts +149 -0
package/README-ENG.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# SimplePay JS SDK
|
|
2
|
+
|
|
3
|
+
[Magyar README](README.md)
|
|
4
|
+
|
|
5
|
+
A lightweight utility for integrating Hungary's SimplePay payments in Node.js applications.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
Please read the [SimplePay documentation](https://simplepay.hu/fejlesztoknek) for more information.
|
|
10
|
+
|
|
11
|
+
> 🫵 If this package is useful to you, please star it on GitHub.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# npm
|
|
17
|
+
npm install simplepay-js-sdk
|
|
18
|
+
|
|
19
|
+
# yarn
|
|
20
|
+
yarn add simplepay-js-sdk
|
|
21
|
+
|
|
22
|
+
# pnpm
|
|
23
|
+
pnpm add simplepay-js-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
Set the following environment variables in your `.env` file:
|
|
29
|
+
|
|
30
|
+
- `SIMPLEPAY_LOGGER` If it set to `true`, it will log varibles - useful only for debugging.
|
|
31
|
+
- `SIMPLEPAY_MERCHANT_KEY_HUF` Your Simplepay secret merchant key. Set `SIMPLEPAY_MERCHANT_KEY_EUR` and `SIMPLEPAY_MERCHANT_KEY_USD` for accepting EUR and USD payments.
|
|
32
|
+
- `SIMPLEPAY_MERCHANT_ID_HUF` Your Simplepay merchant id. Set `SIMPLEPAY_MERCHANT_ID_EUR` and `SIMPLEPAY_MERCHANT_ID_USD` for accepting EUR and USD payments.
|
|
33
|
+
- `SIMPLEPAY_PRODUCTION` If it set to `true`, it will use production environment, otherwise it will use sandbox environment.
|
|
34
|
+
- `SIMPLEPAY_REDIRECT_URL` The URL of your site, where the customer will be redirected after the payment.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
You should create 3 endpoints, to start the payment, get the payment response and handle the IPN.
|
|
39
|
+
|
|
40
|
+
### One Time Payment
|
|
41
|
+
|
|
42
|
+
#### Start Payment Endpoint
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { startPayment } from 'simplepay-js-sdk'
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const response = await startPayment({
|
|
49
|
+
orderRef: 'order-12',
|
|
50
|
+
total: 1212,
|
|
51
|
+
currency: 'HUF', // optional, HUF | EUR | USD, defaults to HUF
|
|
52
|
+
customerEmail: 'rrd@webmania.cc',
|
|
53
|
+
language: 'HU', // optional, AR | BG | CS | DE | EN | ES | FR | IT | HR | HU | PL | RO | RU | SK | TR | ZH, defaults to HU
|
|
54
|
+
method: 'CARD', // optional, CARD | WIRE, defaults to CARD
|
|
55
|
+
invoice: {
|
|
56
|
+
name: 'Radharadhya Dasa',
|
|
57
|
+
country: 'HU',
|
|
58
|
+
state: 'Budapest',
|
|
59
|
+
city: 'Budapest',
|
|
60
|
+
zip: '1234',
|
|
61
|
+
address: 'Sehol u. 0',
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
return response
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('Payment initiation failed:', error)
|
|
67
|
+
return error
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`response.paymentUrl` will contain the Simplepay payment URL, which you can redirect the customer to.
|
|
72
|
+
|
|
73
|
+
#### Get Payment Response Endpoint
|
|
74
|
+
|
|
75
|
+
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`.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { getPaymentResponse } from 'simplepay-js-sdk'
|
|
79
|
+
|
|
80
|
+
// get "r" and "s" from the url the way you do it on your app and framework
|
|
81
|
+
|
|
82
|
+
const response = getPaymentResponse(r, s)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`response` will have the following properties:
|
|
86
|
+
|
|
87
|
+
- `responseCode`: `0` on success, or an error code
|
|
88
|
+
- `transactionId`: the transaction id
|
|
89
|
+
- `event`: the event type: `success` | `fail` | `timeout` | `cancel`
|
|
90
|
+
- `merchantId`: the merchant id
|
|
91
|
+
- `orderRef`: the order id
|
|
92
|
+
|
|
93
|
+
#### IPN Endpoint
|
|
94
|
+
|
|
95
|
+
Simplepay will send a `POST` request to the IPN url and you should send a response back.
|
|
96
|
+
At this endpoint you should
|
|
97
|
+
|
|
98
|
+
- check if the signature is valid - use `checkSignature(ipnBody, signatureHeader, SIMPLEPAY_MERCHANT_KEY_HUF)`
|
|
99
|
+
- add a `receiveDate` property to the received JSON
|
|
100
|
+
- calculate the new signature - use `generateSignature(responseText, SIMPLEPAY_MERCHANT_KEY_HUF)`
|
|
101
|
+
- send the `response` with the new `signature`
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Recurring Payment
|
|
105
|
+
|
|
106
|
+
#### Start Recurring Payment Endpoint
|
|
107
|
+
|
|
108
|
+
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`.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
try {
|
|
112
|
+
const response = await startRecurringPayment({
|
|
113
|
+
// ... other preoperties
|
|
114
|
+
customer: 'Radharadhya Dasa',
|
|
115
|
+
recurring: {
|
|
116
|
+
times: 3, // how many times the payment will be made, number of tokens
|
|
117
|
+
until: '2025-12-31T18:00:00+02:00', // the end date of the recurring payment - use the toISO8601DateString() helper function
|
|
118
|
+
maxAmount: 100000 // the maximum amount of the recurring payment
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The response will have an additional `tokens` property, what will contain the tokens of the registered cards.
|
|
125
|
+
You are responsible to save the tokens to your database, so you can use them later to make a payment.
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
#### Get Recurring Payment Response Endpoint
|
|
129
|
+
|
|
130
|
+
Use the same enpoint as the one time payment.
|
|
131
|
+
|
|
132
|
+
#### IPN Endpoint on card registration
|
|
133
|
+
|
|
134
|
+
It works the same as the `IPN` endpoint of the one time payment.
|
|
135
|
+
The response will have the same properties, and 2 additional properties:
|
|
136
|
+
|
|
137
|
+
- `cardMask`: xxxx-xxxx-xxxx-1234 - the masked card number what is registered
|
|
138
|
+
- `expiry`: 2025-01-31T00:00:00+02:00 - the expiry date of the registered card
|
|
139
|
+
|
|
140
|
+
#### Token Payment Endpoint
|
|
141
|
+
|
|
142
|
+
After a card is registered you can use the tokens to make a payment without any user intercation for example by a daily `cron`
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { startTokenPayment } from 'simplepay-js-sdk'
|
|
146
|
+
|
|
147
|
+
// TODO: get payment data from your database, where you saved the tokens
|
|
148
|
+
|
|
149
|
+
const payment = {
|
|
150
|
+
token: '1234567890123456',
|
|
151
|
+
total: 1212,
|
|
152
|
+
currency: 'HUF' as Currency,
|
|
153
|
+
customer: 'Radharadhya Dasa',
|
|
154
|
+
customerEmail: 'rrd@webmania.cc',
|
|
155
|
+
invoice: {
|
|
156
|
+
name: 'Radharadhya Dasa',
|
|
157
|
+
country: 'HU',
|
|
158
|
+
state: 'Budapest',
|
|
159
|
+
city: 'Budapest',
|
|
160
|
+
zip: '1234',
|
|
161
|
+
address: 'Sehol u. 0',
|
|
162
|
+
},
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const response = await startTokenPayment({
|
|
167
|
+
orderRef: Date.now().toString(),
|
|
168
|
+
language: 'HU',
|
|
169
|
+
method: 'CARD', // must be CARD
|
|
170
|
+
...payment,
|
|
171
|
+
})
|
|
172
|
+
return response
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error('Token payment initiation failed:', error)
|
|
175
|
+
return error
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Card Cancelation
|
|
180
|
+
|
|
181
|
+
Paying customers should be able to delete their registered card on the website.
|
|
182
|
+
To do this, use the `cancelCard` function. Use SimplePay transaction id of the card registration transaction as `cardId`.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { cancelCard } from 'simplepay-js-sdk'
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
const response = await cancelCard(cardId)
|
|
189
|
+
|
|
190
|
+
if (response.status == 'DISABLED') {
|
|
191
|
+
// The card has been successfully deleted
|
|
192
|
+
// TODO: delete the unused tokens and the card from the database
|
|
193
|
+
}
|
|
194
|
+
return response
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error('Card deletion failed:', error)
|
|
197
|
+
return error
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# SimplePay JS SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English README](README-ENG.md)
|
|
4
|
+
|
|
5
|
+
Egy pehelysúlyú segédprogram a magyarországi SimplePay fizetések integrálásához Node.js alkalmazásokban.
|
|
4
6
|
|
|
5
7
|

|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
További információkért kérlek, olvasd el a [SimplePay dokumentációt](https://simplepay.hu/fejlesztoknek).
|
|
10
|
+
|
|
11
|
+
> 🫵 Ha a csomag hasznos a számodra, akkor ne feletjs el rányomni a star-ra GitHub-on.
|
|
8
12
|
|
|
9
|
-
##
|
|
13
|
+
## Telepítés
|
|
10
14
|
|
|
11
15
|
```bash
|
|
12
16
|
# npm
|
|
@@ -19,21 +23,23 @@ yarn add simplepay-js-sdk
|
|
|
19
23
|
pnpm add simplepay-js-sdk
|
|
20
24
|
```
|
|
21
25
|
|
|
22
|
-
##
|
|
26
|
+
## Konfiguráció
|
|
27
|
+
|
|
28
|
+
Állítsd be a következő környezeti változókat a `.env` fájlban:
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
- `SIMPLEPAY_LOGGER` Ha `true`-ra van állítva, naplózza a változókat - csak hibakereséshez hasznos.
|
|
31
|
+
- `SIMPLEPAY_MERCHANT_KEY_HUF` A te SimplePay titkos kereskedői kulcsod. Állítsd be a `SIMPLEPAY_MERCHANT_KEY_EUR` és `SIMPLEPAY_MERCHANT_KEY_USD` értékeket EUR és USD fizetések elfogadásához.
|
|
32
|
+
- `SIMPLEPAY_MERCHANT_ID_HUF` A te SimplePay kereskedői azonosítód. Állítsd be a `SIMPLEPAY_MERCHANT_ID_EUR` és `SIMPLEPAY_MERCHANT_ID_USD` értékeket EUR és USD fizetések elfogadásához.
|
|
33
|
+
- `SIMPLEPAY_PRODUCTION` Ha `true`-ra van állítva, éles környezetet használ, egyébként teszt környezetet.
|
|
34
|
+
- `SIMPLEPAY_REDIRECT_URL` A te weboldalad URL-je, ahova a vásárló átirányításra kerül a fizetés után.
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
- `SIMPLEPAY_MERCHANT_KEY_HUF` Your Simplepay secret merchant key. Set `SIMPLEPAY_MERCHANT_KEY_EUR` and `SIMPLEPAY_MERCHANT_KEY_USD` for accepting EUR and USD payments.
|
|
28
|
-
- `SIMPLEPAY_MERCHANT_ID_HUF` Your Simplepay merchant id. Set `SIMPLEPAY_MERCHANT_ID_EUR` and `SIMPLEPAY_MERCHANT_ID_USD` for accepting EUR and USD payments.
|
|
29
|
-
- `SIMPLEPAY_PRODUCTION` If it set to `true`, it will use production environment, otherwise it will use sandbox environment.
|
|
30
|
-
- `SIMPLEPAY_REDIRECT_URL` The URL of your site, where the customer will be redirected after the payment.
|
|
36
|
+
## Használat
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
Három végpontot kell létrehoznia: egyet a fizetés indításához, egyet a fizetési válasz fogadásához és egyet az IPN kezeléséhez.
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
### Egyszeri fizetés
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
#### Fizetés indítása végpont
|
|
37
43
|
|
|
38
44
|
```typescript
|
|
39
45
|
import { startPayment } from 'simplepay-js-sdk'
|
|
@@ -42,10 +48,10 @@ try {
|
|
|
42
48
|
const response = await startPayment({
|
|
43
49
|
orderRef: 'order-12',
|
|
44
50
|
total: 1212,
|
|
45
|
-
currency: 'HUF', //
|
|
51
|
+
currency: 'HUF', // opcionális, HUF | EUR | USD, alapértelmezett: HUF
|
|
46
52
|
customerEmail: 'rrd@webmania.cc',
|
|
47
|
-
language: 'HU', //
|
|
48
|
-
method: 'CARD', //
|
|
53
|
+
language: 'HU', // opcionális, AR | BG | CS | DE | EN | ES | FR | IT | HR | HU | PL | RO | RU | SK | TR | ZH, alapértelmezett: HU
|
|
54
|
+
method: 'CARD', // opcionális, CARD | WIRE, alapértelmezett: CARD
|
|
49
55
|
invoice: {
|
|
50
56
|
name: 'Radharadhya Dasa',
|
|
51
57
|
country: 'HU',
|
|
@@ -57,43 +63,139 @@ try {
|
|
|
57
63
|
})
|
|
58
64
|
return response
|
|
59
65
|
} catch (error) {
|
|
60
|
-
console.error('
|
|
66
|
+
console.error('Fizetés indítása sikertelen:', error)
|
|
61
67
|
return error
|
|
62
68
|
}
|
|
63
69
|
```
|
|
64
70
|
|
|
65
|
-
`response.paymentUrl`
|
|
71
|
+
A `response.paymentUrl` tartalmazza a SimplePay fizetési URL-t, ahova a vásárlót átirányíthatja.
|
|
66
72
|
|
|
67
|
-
|
|
73
|
+
#### Fizetési válasz fogadása végpont
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
Amikor a vásárló visszatér a SimplePay fizetési oldalról, a fizetési választ a `SIMPLEPAY_REDIRECT_URL` címen kell fogadni. Az URL két paramétert tartalmaz: `r` és `s`.
|
|
70
76
|
|
|
71
77
|
```typescript
|
|
72
78
|
import { getPaymentResponse } from 'simplepay-js-sdk'
|
|
73
79
|
|
|
74
|
-
//
|
|
80
|
+
// az "r" és "s" paraméterek kinyerése az URL-ből az alkalmazásod és keretrendszerének megfelelően
|
|
75
81
|
|
|
76
82
|
const response = getPaymentResponse(r, s)
|
|
77
83
|
```
|
|
78
84
|
|
|
79
|
-
`response`
|
|
85
|
+
A `response` a következő tulajdonságokkal rendelkezik:
|
|
86
|
+
|
|
87
|
+
- `responseCode`: `0` siker esetén, vagy hibakód
|
|
88
|
+
- `transactionId`: a tranzakció azonosítója
|
|
89
|
+
- `event`: az esemény típusa: `success` | `fail` | `timeout` | `cancel`
|
|
90
|
+
- `merchantId`: a kereskedő azonosítója
|
|
91
|
+
- `orderRef`: a rendelés azonosítója
|
|
92
|
+
|
|
93
|
+
#### IPN végpont
|
|
94
|
+
|
|
95
|
+
A SimplePay `POST` kérést küld az IPN URL-re, és válaszolnunk kell rá.
|
|
96
|
+
Ennél a végpontnál a következőket kell tenned:
|
|
97
|
+
|
|
98
|
+
- ellenőrizd az aláírás érvényességét - használd a `checkSignature(ipnBody, signatureHeader, SIMPLEPAY_MERCHANT_KEY_HUF)` függvényt
|
|
99
|
+
- adj hozzá egy `receiveDate` tulajdonságot a kapott JSON-hoz
|
|
100
|
+
- számítsa ki az új aláírást - használd a `generateSignature(responseText, SIMPLEPAY_MERCHANT_KEY_HUF)` függvényt
|
|
101
|
+
- küldd el a `response`-t az új `signature`-rel
|
|
102
|
+
|
|
103
|
+
### Ismétlődő fizetés
|
|
104
|
+
|
|
105
|
+
#### Ismétlődő fizetés indítása végpont
|
|
106
|
+
|
|
107
|
+
Itt a `startRecurringPayment()` függvényt kell használnod, ami ugyanúgy működik, mint a `startPayment()`. Az egyetlen különbség, hogy két további tulajdonságot kell megadni: `customer` és `recurring`.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
try {
|
|
111
|
+
const response = await startRecurringPayment({
|
|
112
|
+
// ... egyéb tulajdonságok
|
|
113
|
+
customer: 'Radharadhya Dasa',
|
|
114
|
+
recurring: {
|
|
115
|
+
times: 3, // hányszor történik meg a fizetés, tokenek száma
|
|
116
|
+
until: '2025-12-31T18:00:00+02:00', // az ismétlődő fizetés végdátuma - használd a toISO8601DateString() segédfüggvényt
|
|
117
|
+
maxAmount: 100000 // az ismétlődő fizetés maximális összege
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
A válasz egy további `tokens` tulajdonsággal rendelkezik, ami tartalmazza a regisztrált kártyák tokenjeit.
|
|
124
|
+
A te dolgod a tokenek mentése az adatbázisba, hogy később használhasd őket fizetéshez.
|
|
125
|
+
|
|
126
|
+
#### Ismétlődő fizetési válasz fogadása végpont
|
|
127
|
+
|
|
128
|
+
Használd ugyanazt a végpontot, mint az egyszeri fizetésnél.
|
|
129
|
+
|
|
130
|
+
#### IPN végpont kártyaregisztrációnál
|
|
131
|
+
|
|
132
|
+
Ugyanúgy működik, mint az egyszeri fizetés `IPN` végpontja.
|
|
133
|
+
A válasz ugyanazokkal a tulajdonságokkal rendelkezik, és 2 további tulajdonsággal:
|
|
80
134
|
|
|
81
|
-
- `
|
|
82
|
-
- `
|
|
83
|
-
- `event`: the event type: `success` | `fail` | `timeout` | `cancel`
|
|
84
|
-
- `merchantId`: the merchant id
|
|
85
|
-
- `orderRef`: the order id
|
|
135
|
+
- `cardMask`: xxxx-xxxx-xxxx-1234 - a regisztrált kártya maszkolt száma
|
|
136
|
+
- `expiry`: 2025-01-31T00:00:00+02:00 - a regisztrált kártya lejárati dátuma
|
|
86
137
|
|
|
87
|
-
|
|
138
|
+
#### Tokenes fizetés
|
|
88
139
|
|
|
89
|
-
|
|
90
|
-
At this endpoint you should
|
|
140
|
+
Miután egy kártya regisztrálva van, használhatod a tokeneket fizetéshez felhasználói interakció nélkül, például napi `cron` feladattal
|
|
91
141
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
142
|
+
```typescript
|
|
143
|
+
import { startTokenPayment } from 'simplepay-js-sdk'
|
|
144
|
+
|
|
145
|
+
// TODO: fizetési adatok lekérése az adatbázisból, ahol a tokeneket tárolod
|
|
146
|
+
|
|
147
|
+
const payment = {
|
|
148
|
+
token: '1234567890123456',
|
|
149
|
+
total: 1212,
|
|
150
|
+
currency: 'HUF' as Currency,
|
|
151
|
+
customer: 'Radharadhya Dasa',
|
|
152
|
+
customerEmail: 'rrd@webmania.cc',
|
|
153
|
+
invoice: {
|
|
154
|
+
name: 'Radharadhya Dasa',
|
|
155
|
+
country: 'HU',
|
|
156
|
+
state: 'Budapest',
|
|
157
|
+
city: 'Budapest',
|
|
158
|
+
zip: '1234',
|
|
159
|
+
address: 'Sehol u. 0',
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
const response = await startTokenPayment({
|
|
165
|
+
orderRef: Date.now().toString(),
|
|
166
|
+
language: 'HU',
|
|
167
|
+
method: 'CARD', // kötelezően CARD
|
|
168
|
+
...payment,
|
|
169
|
+
})
|
|
170
|
+
return response
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error('Token fizetés indítása sikertelen:', error)
|
|
173
|
+
return error
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Kártya törlése
|
|
178
|
+
|
|
179
|
+
A fizető ügyfelek számára lehetővé kell tenni, hogy a honlapodon belépve törölni tudja a regisztrált kártyáját.
|
|
180
|
+
Ehhez használd a `cancelCard` függvényt. `cardId`-ként a kártya regisztrációs tranzakció SimplePay azonosítóját kell megadnod.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { cancelCard } from 'simplepay-js-sdk'
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const response = await cancelCard(cardId)
|
|
187
|
+
|
|
188
|
+
if (response.status == 'DISABLED') {
|
|
189
|
+
// A kártya sikeresen törölve
|
|
190
|
+
// TODO: a fel nem használt tokenek és a kártya törlése az adatbázisból
|
|
191
|
+
}
|
|
192
|
+
return response
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error('Kártya törlése sikertelen:', error)
|
|
195
|
+
return error
|
|
196
|
+
}
|
|
197
|
+
```
|
|
96
198
|
|
|
97
|
-
##
|
|
199
|
+
## Licenc
|
|
98
200
|
|
|
99
|
-
MIT
|
|
201
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
1
|
+
export declare const cardCancel: (cardId: string) => Promise<SimplePayCardCancelResponse>;
|
|
2
|
+
|
|
1
3
|
export declare const checkSignature: (responseText: string, signature: string, merchantKey: string) => boolean;
|
|
2
4
|
|
|
3
5
|
declare const CURRENCIES: readonly ["HUF", "EUR", "USD"];
|
|
4
6
|
|
|
5
|
-
declare type Currency = typeof CURRENCIES[number];
|
|
7
|
+
export declare type Currency = typeof CURRENCIES[number];
|
|
6
8
|
|
|
7
9
|
export declare const generateSignature: (body: string, merchantKey: string) => string;
|
|
8
10
|
|
|
9
|
-
export declare const
|
|
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
|
+
export declare const getPaymentResponse: (r: string, signature: string) => SimplePayResult;
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
MERCHANT_KEY: string | undefined;
|
|
21
|
-
MERCHANT_ID: string | undefined;
|
|
22
|
-
API_URL: string;
|
|
23
|
-
SDK_VERSION: string;
|
|
24
|
-
};
|
|
13
|
+
declare type ISO8601DateString = string;
|
|
25
14
|
|
|
26
|
-
declare type Language = typeof LANGUAGES[number];
|
|
15
|
+
export declare type Language = typeof LANGUAGES[number];
|
|
27
16
|
|
|
28
17
|
declare const LANGUAGES: readonly ["AR", "BG", "CS", "DE", "EN", "ES", "FR", "IT", "HR", "HU", "PL", "RO", "RU", "SK", "TR", "ZH"];
|
|
29
18
|
|
|
@@ -46,7 +35,32 @@ declare interface PaymentData {
|
|
|
46
35
|
};
|
|
47
36
|
}
|
|
48
37
|
|
|
49
|
-
declare type PaymentMethod = 'CARD' | 'WIRE';
|
|
38
|
+
export declare type PaymentMethod = 'CARD' | 'WIRE';
|
|
39
|
+
|
|
40
|
+
declare interface Recurring {
|
|
41
|
+
times: number;
|
|
42
|
+
until: ISO8601DateString;
|
|
43
|
+
maxAmount: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare interface RecurringPaymentData extends PaymentData {
|
|
47
|
+
customer: string;
|
|
48
|
+
recurring: Recurring;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare interface SimplePayCardCancelResponse {
|
|
52
|
+
salt: string;
|
|
53
|
+
merchant: string;
|
|
54
|
+
cardId: string;
|
|
55
|
+
status: 'DISABLED';
|
|
56
|
+
expiry: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare type SimplePayEvents = 'SUCCESS' | 'FAIL' | 'TIMEOUT' | 'CANCEL';
|
|
60
|
+
|
|
61
|
+
declare interface SimplePayRecurringResponse extends SimplePayResponse {
|
|
62
|
+
tokens: string[];
|
|
63
|
+
}
|
|
50
64
|
|
|
51
65
|
declare interface SimplePayResponse {
|
|
52
66
|
salt: string;
|
|
@@ -54,12 +68,36 @@ declare interface SimplePayResponse {
|
|
|
54
68
|
orderRef: string;
|
|
55
69
|
currency: Currency;
|
|
56
70
|
transactionId: string;
|
|
57
|
-
timeout:
|
|
71
|
+
timeout: ISO8601DateString;
|
|
58
72
|
total: string;
|
|
59
73
|
paymentUrl: string;
|
|
60
74
|
errorCodes?: string[];
|
|
61
75
|
}
|
|
62
76
|
|
|
77
|
+
declare interface SimplePayResult {
|
|
78
|
+
responseCode: number;
|
|
79
|
+
transactionId: string;
|
|
80
|
+
event: SimplePayEvents;
|
|
81
|
+
merchantId: string;
|
|
82
|
+
orderRef: string;
|
|
83
|
+
tokens?: string[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare interface SimplePayTokenResponse extends Omit<SimplePayResponse, 'paymentUrl' | 'timeout'> {
|
|
87
|
+
}
|
|
88
|
+
|
|
63
89
|
export declare const startPayment: (paymentData: PaymentData) => Promise<SimplePayResponse>;
|
|
64
90
|
|
|
91
|
+
export declare const startRecurringPayment: (paymentData: RecurringPaymentData) => Promise<SimplePayRecurringResponse>;
|
|
92
|
+
|
|
93
|
+
export declare const startTokenPayment: (paymentData: TokenPaymentData) => Promise<SimplePayTokenResponse>;
|
|
94
|
+
|
|
95
|
+
export declare const toISO8601DateString: (date: Date) => ISO8601DateString;
|
|
96
|
+
|
|
97
|
+
declare interface TokenPaymentData extends Omit<PaymentData, 'method'> {
|
|
98
|
+
method: 'CARD';
|
|
99
|
+
customer: string;
|
|
100
|
+
token: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
65
103
|
export { }
|