gamemoney 3.0.0 → 4.1.1
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 +15 -82
- package/index.d.ts +396 -0
- package/index.js +138 -0
- package/package.json +59 -22
- package/utils.d.ts +17 -0
- package/utils.js +51 -0
- package/LICENSE +0 -21
- package/dist/index.d.ts +0 -257
- package/dist/index.js +0 -82
- package/dist/index.js.map +0 -1
- package/dist/request.d.ts +0 -18
- package/dist/request.js +0 -53
- package/dist/request.js.map +0 -1
- package/dist/utils.d.ts +0 -11
- package/dist/utils.js +0 -64
- package/dist/utils.js.map +0 -1
- package/tsconfig.json +0 -22
- package/tslint.json +0 -18
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
[GameMoney](https://
|
|
3
|
+
[GameMoney](https://gmpays.com/) API wrapper for Node.js
|
|
4
4
|
|
|
5
|
-
Full API documentation [here](https://cp.
|
|
5
|
+
Full API documentation [here](https://cp.gmpays.com/apidoc)
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
```sh
|
|
@@ -14,92 +14,25 @@ $ npm install gamemoney
|
|
|
14
14
|
### Initialization
|
|
15
15
|
```typescript
|
|
16
16
|
import fs from 'fs'
|
|
17
|
-
import
|
|
17
|
+
import GameMoney from 'gamemoney'
|
|
18
18
|
|
|
19
19
|
const gm = new GameMoney({
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
project: 42,
|
|
21
|
+
hmacPrivateKey: 'test',
|
|
22
|
+
|
|
23
|
+
// Optional. But to make checkouts must be specified
|
|
24
|
+
rsaPrivateKey: {
|
|
22
25
|
key: fs.readFileSync('./private.pem').toString(),
|
|
23
26
|
passphrase: '123' // Optional
|
|
24
27
|
},
|
|
25
28
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Invoicing using API
|
|
33
|
-
```typescript
|
|
34
|
-
const result = await gm.createInvoice({
|
|
35
|
-
wallet: '79253642685',
|
|
36
|
-
amount: 200.50,
|
|
37
|
-
type: 'qiwi',
|
|
38
|
-
comment: 'testing',
|
|
39
|
-
user: 1,
|
|
40
|
-
ip: '1.2.3.4',
|
|
41
|
-
add_some_field: 'some value'
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
console.log(result)
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Invoicing using the Terminal
|
|
48
|
-
```typescript
|
|
49
|
-
const body = {
|
|
50
|
-
project: 123,
|
|
51
|
-
user: 1
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const sign = gm.generateHmacSignature(body)
|
|
55
|
-
```
|
|
56
|
-
```html
|
|
57
|
-
<form method="post" action="https://pay.gamemoney.com/terminal/">
|
|
58
|
-
<input type="hidden" name="project" value="123">
|
|
59
|
-
<input type="hidden" name="user" value="1">
|
|
60
|
-
<input type="hidden" name="signature" value="{{ sign }}">
|
|
61
|
-
<input type="submit" value="Pay">
|
|
62
|
-
</form>
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Checkout
|
|
66
|
-
```typescript
|
|
67
|
-
const result = await gm.createCheckout({
|
|
68
|
-
wallet: '79253642685',
|
|
69
|
-
amount: 200.50,
|
|
70
|
-
type: 'qiwi',
|
|
71
|
-
description: 'testing',
|
|
72
|
-
user: 1,
|
|
73
|
-
ip: '1.2.3.4',
|
|
74
|
-
projectId: 1235,
|
|
75
|
-
currency: 'rur'
|
|
29
|
+
// OR:
|
|
30
|
+
// rsaPrivateKey: Buffer.from(
|
|
31
|
+
// process.env.GM_RSA_PRIVATE_KEY ?? '',
|
|
32
|
+
// 'base64',
|
|
33
|
+
// )
|
|
76
34
|
})
|
|
77
|
-
|
|
78
|
-
console.log(result)
|
|
79
35
|
```
|
|
80
36
|
|
|
81
|
-
###
|
|
82
|
-
|
|
83
|
-
import express from 'express'
|
|
84
|
-
import bodyParser from 'body-parser'
|
|
85
|
-
import { verifyRsaSignature } from 'gamemoney'
|
|
86
|
-
|
|
87
|
-
const app = express()
|
|
88
|
-
|
|
89
|
-
app.use(bodyParser.urlencoded({ extended: false }))
|
|
90
|
-
|
|
91
|
-
app.post('/gamemoney/callback/url', (req, res) => {
|
|
92
|
-
const { body } = req
|
|
93
|
-
|
|
94
|
-
if (!verifyRsaSignature(body)) {
|
|
95
|
-
return res.send({
|
|
96
|
-
success: false,
|
|
97
|
-
error: 'signature mismatch'
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
console.log(body)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
app.listen(3000)
|
|
105
|
-
```
|
|
37
|
+
### Examples
|
|
38
|
+
See examples in [src/examples](https://github.com/gamemoney-ps/gamemoney-node-sdk/tree/master/src/examples) directory
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { RsaKey, HmacKey } from './utils.js';
|
|
2
|
+
export declare enum SignType {
|
|
3
|
+
'HMAC' = "HMAC",
|
|
4
|
+
'RSA' = "RSA"
|
|
5
|
+
}
|
|
6
|
+
export interface GenericRequest {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
rand?: string;
|
|
9
|
+
project: number;
|
|
10
|
+
signature?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface GenericResponse {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
state: 'success' | 'error';
|
|
15
|
+
time: number;
|
|
16
|
+
error?: string;
|
|
17
|
+
rand?: string;
|
|
18
|
+
signature: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Config {
|
|
21
|
+
rsaPrivateKey?: RsaKey;
|
|
22
|
+
hmacPrivateKey: HmacKey;
|
|
23
|
+
project: number;
|
|
24
|
+
}
|
|
25
|
+
export interface CreateInvoiceRequest {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
type: string;
|
|
28
|
+
user: string;
|
|
29
|
+
ip: string;
|
|
30
|
+
amount: number;
|
|
31
|
+
comment?: string;
|
|
32
|
+
success_url?: string;
|
|
33
|
+
fail_url?: string;
|
|
34
|
+
wallet: string;
|
|
35
|
+
project_invoice?: string;
|
|
36
|
+
currency?: string;
|
|
37
|
+
user_currency?: string;
|
|
38
|
+
language?: string;
|
|
39
|
+
mode?: 'card_direct';
|
|
40
|
+
}
|
|
41
|
+
export interface CreateInvoiceResponse {
|
|
42
|
+
invoice: number;
|
|
43
|
+
type: 'message' | 'redirect' | 'cardrequest' | 'error';
|
|
44
|
+
data: string;
|
|
45
|
+
}
|
|
46
|
+
export interface GetInvoiceStatusRequestWithProjectInvoiceId {
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
invoice: number;
|
|
49
|
+
}
|
|
50
|
+
export interface GetInvoiceStatusRequestWithGamemoneyInvoiceId {
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
project_invoice: string;
|
|
53
|
+
}
|
|
54
|
+
export declare type GetInvoiceStatusRequest = GetInvoiceStatusRequestWithProjectInvoiceId | GetInvoiceStatusRequestWithGamemoneyInvoiceId;
|
|
55
|
+
export interface GetInvoiceStatusResponse {
|
|
56
|
+
project: number;
|
|
57
|
+
invoice: number;
|
|
58
|
+
status: string;
|
|
59
|
+
amount: number;
|
|
60
|
+
net_amount: number;
|
|
61
|
+
recieved_amount: number;
|
|
62
|
+
user: string;
|
|
63
|
+
type: string;
|
|
64
|
+
wallet: string;
|
|
65
|
+
project_invoice: string;
|
|
66
|
+
currency_project: string;
|
|
67
|
+
currency_user: string;
|
|
68
|
+
date_create: string;
|
|
69
|
+
date_pay: string;
|
|
70
|
+
rate?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface GetInvoiceListRequest {
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
start: string;
|
|
75
|
+
finish: string;
|
|
76
|
+
}
|
|
77
|
+
export interface GetInvoiceListResponse {
|
|
78
|
+
list: GetInvoiceStatusResponse[];
|
|
79
|
+
is_limit_exceeded: 'yes' | 'no';
|
|
80
|
+
}
|
|
81
|
+
export interface CancelCheckoutRequest {
|
|
82
|
+
[key: string]: any;
|
|
83
|
+
projectId: string;
|
|
84
|
+
}
|
|
85
|
+
export interface GetCheckoutStatusRequest {
|
|
86
|
+
[key: string]: any;
|
|
87
|
+
projectId: string;
|
|
88
|
+
}
|
|
89
|
+
export interface Refund {
|
|
90
|
+
id: number;
|
|
91
|
+
amount: number;
|
|
92
|
+
net_amount: number;
|
|
93
|
+
paid_amount: number;
|
|
94
|
+
comment: string;
|
|
95
|
+
}
|
|
96
|
+
export interface GetCheckoutStatusResponse {
|
|
97
|
+
id: number;
|
|
98
|
+
project: number;
|
|
99
|
+
projectId: string;
|
|
100
|
+
amount: number;
|
|
101
|
+
net_amount: number;
|
|
102
|
+
paid_amount: number;
|
|
103
|
+
status: number;
|
|
104
|
+
user: string;
|
|
105
|
+
wallet: string;
|
|
106
|
+
description: string;
|
|
107
|
+
comment: string;
|
|
108
|
+
redirect_url: string;
|
|
109
|
+
type: string;
|
|
110
|
+
currency_project: string;
|
|
111
|
+
currency_user: string;
|
|
112
|
+
date_create: string;
|
|
113
|
+
rate?: string;
|
|
114
|
+
refunds: Refund[];
|
|
115
|
+
}
|
|
116
|
+
export interface GetCheckoutListRequest {
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
start: string;
|
|
119
|
+
finish: string;
|
|
120
|
+
}
|
|
121
|
+
export interface GetCheckoutListResponse {
|
|
122
|
+
list: GetCheckoutStatusResponse[];
|
|
123
|
+
}
|
|
124
|
+
export interface CreateCheckoutRequest {
|
|
125
|
+
[key: string]: any;
|
|
126
|
+
projectId: string;
|
|
127
|
+
user: string;
|
|
128
|
+
ip: string;
|
|
129
|
+
amount: number;
|
|
130
|
+
wallet: string;
|
|
131
|
+
description: string;
|
|
132
|
+
type: string;
|
|
133
|
+
currency?: string;
|
|
134
|
+
userCurrency?: string;
|
|
135
|
+
}
|
|
136
|
+
export interface AddCardRequest {
|
|
137
|
+
[key: string]: any;
|
|
138
|
+
user: string;
|
|
139
|
+
redirect: string;
|
|
140
|
+
}
|
|
141
|
+
export interface AddCardResponse {
|
|
142
|
+
url: string;
|
|
143
|
+
}
|
|
144
|
+
export interface AddTokenCardRequest {
|
|
145
|
+
[key: string]: any;
|
|
146
|
+
user: string;
|
|
147
|
+
}
|
|
148
|
+
export interface AddTokenCardResponse {
|
|
149
|
+
token: string;
|
|
150
|
+
}
|
|
151
|
+
export interface GetCardListRequest {
|
|
152
|
+
[key: string]: any;
|
|
153
|
+
user: string;
|
|
154
|
+
}
|
|
155
|
+
export interface GetCardListResponse {
|
|
156
|
+
pans: string[];
|
|
157
|
+
}
|
|
158
|
+
export interface GetCardFullListRequest {
|
|
159
|
+
[key: string]: any;
|
|
160
|
+
user: string;
|
|
161
|
+
}
|
|
162
|
+
export interface GetCardFullListResponse {
|
|
163
|
+
cards?: Array<{
|
|
164
|
+
pan: string;
|
|
165
|
+
expire_month: string;
|
|
166
|
+
expire_year: string;
|
|
167
|
+
cardholder: string;
|
|
168
|
+
}>;
|
|
169
|
+
}
|
|
170
|
+
export interface DeleteCardRequest {
|
|
171
|
+
[key: string]: any;
|
|
172
|
+
user: string;
|
|
173
|
+
pan: string;
|
|
174
|
+
}
|
|
175
|
+
export interface PrepareExchangeRequest {
|
|
176
|
+
[key: string]: any;
|
|
177
|
+
externalId: string;
|
|
178
|
+
minAmount: number;
|
|
179
|
+
maxAmount: number;
|
|
180
|
+
from: string;
|
|
181
|
+
to: string;
|
|
182
|
+
livetime?: number;
|
|
183
|
+
}
|
|
184
|
+
export interface PrepareExchangeResponse {
|
|
185
|
+
id: number;
|
|
186
|
+
rate: number;
|
|
187
|
+
exchanged_amount_from: number;
|
|
188
|
+
exchanged_amount_to: number;
|
|
189
|
+
}
|
|
190
|
+
export interface ConvertExchangeRequest {
|
|
191
|
+
[key: string]: any;
|
|
192
|
+
id: number;
|
|
193
|
+
amount: number;
|
|
194
|
+
}
|
|
195
|
+
export interface FastConvertExchangeRequest {
|
|
196
|
+
[key: string]: any;
|
|
197
|
+
amount: number;
|
|
198
|
+
from: string;
|
|
199
|
+
to: string;
|
|
200
|
+
}
|
|
201
|
+
export interface FastConvertExchangeResponse {
|
|
202
|
+
id: number;
|
|
203
|
+
rate: number;
|
|
204
|
+
}
|
|
205
|
+
export interface GetExchangeInfoRequest {
|
|
206
|
+
[key: string]: any;
|
|
207
|
+
minAmount: number;
|
|
208
|
+
maxAmount: number;
|
|
209
|
+
from: string;
|
|
210
|
+
to: string;
|
|
211
|
+
livetime?: number;
|
|
212
|
+
rateType?: 'exchange' | 'invoice' | 'checkout';
|
|
213
|
+
}
|
|
214
|
+
export interface GetExchangeInfoResponse {
|
|
215
|
+
rate: number;
|
|
216
|
+
exchanged_amount_from: number;
|
|
217
|
+
exchanged_amount_to: number;
|
|
218
|
+
}
|
|
219
|
+
export interface GetExchangeStatusRequest {
|
|
220
|
+
[key: string]: any;
|
|
221
|
+
id?: number;
|
|
222
|
+
externalId?: string;
|
|
223
|
+
}
|
|
224
|
+
export interface GetExchangeStatusResponse {
|
|
225
|
+
id: number;
|
|
226
|
+
from: string;
|
|
227
|
+
to: string;
|
|
228
|
+
rate: number;
|
|
229
|
+
amount_from: number;
|
|
230
|
+
amount_to: number;
|
|
231
|
+
status: string;
|
|
232
|
+
}
|
|
233
|
+
export interface GetBalanceStatisticsRequest {
|
|
234
|
+
[key: string]: any;
|
|
235
|
+
currency: string;
|
|
236
|
+
}
|
|
237
|
+
export interface GetBalanceStatisticsResponse {
|
|
238
|
+
project: number;
|
|
239
|
+
currency: string;
|
|
240
|
+
project_income: number;
|
|
241
|
+
project_outcome: number;
|
|
242
|
+
project_balance: number;
|
|
243
|
+
contract_income: number;
|
|
244
|
+
contract_outcome: number;
|
|
245
|
+
contract_balance: number;
|
|
246
|
+
}
|
|
247
|
+
export interface GetDaysBalanceStatisticsRequest {
|
|
248
|
+
[key: string]: any;
|
|
249
|
+
currency: string;
|
|
250
|
+
start: string;
|
|
251
|
+
finish: string;
|
|
252
|
+
}
|
|
253
|
+
export interface DaysBalance {
|
|
254
|
+
date: string;
|
|
255
|
+
income: number;
|
|
256
|
+
outcome: number;
|
|
257
|
+
}
|
|
258
|
+
export interface GetDaysBalanceStatisticsResponse {
|
|
259
|
+
project: number;
|
|
260
|
+
currency: string;
|
|
261
|
+
days_balance: DaysBalance[];
|
|
262
|
+
}
|
|
263
|
+
export interface PaySystem {
|
|
264
|
+
type: string;
|
|
265
|
+
fee: number;
|
|
266
|
+
fixed_fee: number;
|
|
267
|
+
currency: string;
|
|
268
|
+
image_url: string;
|
|
269
|
+
min_sum?: number;
|
|
270
|
+
max_sum?: number;
|
|
271
|
+
terminal?: 'enabled' | 'disabled';
|
|
272
|
+
}
|
|
273
|
+
export interface GetPayTypesStatisticsResponse {
|
|
274
|
+
project: number;
|
|
275
|
+
invoice: PaySystem[];
|
|
276
|
+
checkout: PaySystem[];
|
|
277
|
+
}
|
|
278
|
+
export interface CreateTerminalRequest {
|
|
279
|
+
[key: string]: any;
|
|
280
|
+
user: string;
|
|
281
|
+
ip: string;
|
|
282
|
+
amount?: number;
|
|
283
|
+
comment?: string;
|
|
284
|
+
success_url?: string;
|
|
285
|
+
fail_url?: string;
|
|
286
|
+
project_invoice?: string;
|
|
287
|
+
currency?: string;
|
|
288
|
+
use_user_select_currency?: 'yes' | 'no';
|
|
289
|
+
language?: string;
|
|
290
|
+
terminal_allow_methods?: string[];
|
|
291
|
+
terminal_disable_methods?: string[];
|
|
292
|
+
}
|
|
293
|
+
export interface CreateTerminalResponse {
|
|
294
|
+
url: string;
|
|
295
|
+
}
|
|
296
|
+
export interface InvoiceNotification {
|
|
297
|
+
project: number;
|
|
298
|
+
invoice: number;
|
|
299
|
+
status: 'New' | 'Processing' | 'Paid' | 'Chargeback' | 'Chargeback_cancel' | 'Refused';
|
|
300
|
+
amount: number;
|
|
301
|
+
net_amount: number;
|
|
302
|
+
recieved_amount: number;
|
|
303
|
+
rate?: number;
|
|
304
|
+
user: string;
|
|
305
|
+
type: string;
|
|
306
|
+
wallet: string;
|
|
307
|
+
comment: string;
|
|
308
|
+
time: string;
|
|
309
|
+
project_invoice?: string;
|
|
310
|
+
currency_project: string;
|
|
311
|
+
currency_user: string;
|
|
312
|
+
reason?: string;
|
|
313
|
+
signature: string;
|
|
314
|
+
}
|
|
315
|
+
export interface CheckoutNotification {
|
|
316
|
+
id: number;
|
|
317
|
+
project: number;
|
|
318
|
+
projectId: string;
|
|
319
|
+
amount: number;
|
|
320
|
+
net_amount: number;
|
|
321
|
+
paid_amount: number;
|
|
322
|
+
rate?: number;
|
|
323
|
+
status: string;
|
|
324
|
+
user: string;
|
|
325
|
+
wallet: string;
|
|
326
|
+
description: string;
|
|
327
|
+
comment: string;
|
|
328
|
+
type: string;
|
|
329
|
+
currency_project: string;
|
|
330
|
+
currency_user: string;
|
|
331
|
+
time: string;
|
|
332
|
+
signature: string;
|
|
333
|
+
refunds?: Refund[];
|
|
334
|
+
}
|
|
335
|
+
export interface TransferNotification {
|
|
336
|
+
amount: number;
|
|
337
|
+
currency: string;
|
|
338
|
+
user: string;
|
|
339
|
+
type: string;
|
|
340
|
+
ip: string;
|
|
341
|
+
time: number;
|
|
342
|
+
comment: string;
|
|
343
|
+
signature: string;
|
|
344
|
+
}
|
|
345
|
+
declare type Payload = Record<string, unknown>;
|
|
346
|
+
export default class GameMoney {
|
|
347
|
+
private readonly config;
|
|
348
|
+
private readonly got;
|
|
349
|
+
constructor(config: Config);
|
|
350
|
+
request<T extends GenericResponse>(url: string, payload?: Payload, signType?: SignType): Promise<T>;
|
|
351
|
+
generateHmacSignature(body: any): string;
|
|
352
|
+
verifyRsaSignature(body: any): boolean;
|
|
353
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#invoice_insert_api) */
|
|
354
|
+
createInvoice(body: CreateInvoiceRequest): Promise<CreateInvoiceResponse & GenericResponse>;
|
|
355
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#invoice_status) */
|
|
356
|
+
getInvoiceStatus(body: GetInvoiceStatusRequest): Promise<GetInvoiceStatusResponse & GenericResponse>;
|
|
357
|
+
/** For more details and usage information see [docs](https://cp.gamemoney.com/apidoc#invoice_list) */
|
|
358
|
+
getInvoiceList(body: GetInvoiceListRequest): Promise<GetInvoiceListResponse & GenericResponse>;
|
|
359
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#checkout_insert) */
|
|
360
|
+
createCheckout(body: CreateCheckoutRequest): Promise<GenericResponse>;
|
|
361
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#checkout_cancel) */
|
|
362
|
+
cancelCheckout(body: CancelCheckoutRequest): Promise<GenericResponse>;
|
|
363
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#checkout_status) */
|
|
364
|
+
getCheckoutStatus(body: GetCheckoutStatusRequest): Promise<GetCheckoutStatusResponse & GenericResponse>;
|
|
365
|
+
/** For more details and usage information see [docs](https://cp.gamemoney.com/apidoc#checkout_list) */
|
|
366
|
+
getCheckoutList(body: GetCheckoutListRequest): Promise<GetCheckoutListResponse & GenericResponse>;
|
|
367
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_add) */
|
|
368
|
+
addCard(body: AddCardRequest): Promise<AddCardResponse & GenericResponse>;
|
|
369
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_add_token) */
|
|
370
|
+
addTokenCard(body: AddTokenCardRequest): Promise<AddTokenCardResponse & GenericResponse>;
|
|
371
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_list) */
|
|
372
|
+
getCardList(body: GetCardListRequest): Promise<GetCardListResponse & GenericResponse>;
|
|
373
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_fulllist) */
|
|
374
|
+
getCardFullList(body: GetCardFullListRequest): Promise<GetCardFullListResponse & GenericResponse>;
|
|
375
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_list) */
|
|
376
|
+
deleteCard(body: DeleteCardRequest): Promise<GenericResponse>;
|
|
377
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_prepare) */
|
|
378
|
+
prepareExchange(body: PrepareExchangeRequest): Promise<PrepareExchangeResponse & GenericResponse>;
|
|
379
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_convert) */
|
|
380
|
+
convertExchange(body: ConvertExchangeRequest): Promise<GenericResponse>;
|
|
381
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_fastconvert) */
|
|
382
|
+
fastConvertExchange(body: FastConvertExchangeRequest): Promise<FastConvertExchangeResponse & GenericResponse>;
|
|
383
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_info) */
|
|
384
|
+
getExchangeInfo(body: GetExchangeInfoRequest): Promise<GetExchangeInfoResponse & GenericResponse>;
|
|
385
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_status) */
|
|
386
|
+
getExchangeStatus(body: GetExchangeStatusRequest): Promise<GetExchangeStatusResponse & GenericResponse>;
|
|
387
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#stat_balance) */
|
|
388
|
+
getBalanceStatistics(body: GetBalanceStatisticsRequest): Promise<GetBalanceStatisticsResponse & GenericResponse>;
|
|
389
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#stat_days_balance) */
|
|
390
|
+
getDaysBalanceStatistics(body: GetDaysBalanceStatisticsRequest): Promise<GetDaysBalanceStatisticsResponse & GenericResponse>;
|
|
391
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#stat_paytypes) */
|
|
392
|
+
getPayTypesStatistics(): Promise<GetPayTypesStatisticsResponse & GenericResponse>;
|
|
393
|
+
/** For more details and usage information see [docs](https://cp.gamemoney.com/apidoc#invoice_api_terminal) */
|
|
394
|
+
createTerminal(body: CreateTerminalRequest): Promise<CreateTerminalResponse & GenericResponse>;
|
|
395
|
+
}
|
|
396
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import got from 'got';
|
|
2
|
+
import { generateRsaSignature, generateHmacSignature, getRandomString, verifyRsaSignature, } from './utils.js';
|
|
3
|
+
export var SignType;
|
|
4
|
+
(function (SignType) {
|
|
5
|
+
SignType["HMAC"] = "HMAC";
|
|
6
|
+
SignType["RSA"] = "RSA";
|
|
7
|
+
})(SignType || (SignType = {}));
|
|
8
|
+
export default class GameMoney {
|
|
9
|
+
config;
|
|
10
|
+
got = got.extend({
|
|
11
|
+
prefixUrl: 'https://paygate.gamemoney.com',
|
|
12
|
+
responseType: 'json',
|
|
13
|
+
});
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
async request(url, payload = {}, signType = SignType.HMAC) {
|
|
18
|
+
const form = {
|
|
19
|
+
rand: getRandomString(20),
|
|
20
|
+
project: this.config.project,
|
|
21
|
+
...payload,
|
|
22
|
+
};
|
|
23
|
+
if (signType === SignType.RSA) {
|
|
24
|
+
if (!this.config.rsaPrivateKey) {
|
|
25
|
+
throw new Error("To make requests with RSA sign type, 'rsaPrivateKey' must be provided");
|
|
26
|
+
}
|
|
27
|
+
form.signature = generateRsaSignature(form, this.config.rsaPrivateKey);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
form.signature = generateHmacSignature(form, this.config.hmacPrivateKey);
|
|
31
|
+
}
|
|
32
|
+
const response = await this.got.post({
|
|
33
|
+
url,
|
|
34
|
+
form,
|
|
35
|
+
resolveBodyOnly: true,
|
|
36
|
+
});
|
|
37
|
+
if (!verifyRsaSignature(response)) {
|
|
38
|
+
throw new Error('Response signature mismatch');
|
|
39
|
+
}
|
|
40
|
+
if (form.rand !== response.rand) {
|
|
41
|
+
throw new Error(`Wrong rand parameter: ${response.rand}`);
|
|
42
|
+
}
|
|
43
|
+
if (response.state === 'error') {
|
|
44
|
+
throw new Error(response.error);
|
|
45
|
+
}
|
|
46
|
+
return response;
|
|
47
|
+
}
|
|
48
|
+
generateHmacSignature(body) {
|
|
49
|
+
return generateHmacSignature(body, this.config.hmacPrivateKey);
|
|
50
|
+
}
|
|
51
|
+
verifyRsaSignature(body) {
|
|
52
|
+
return verifyRsaSignature(body);
|
|
53
|
+
}
|
|
54
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#invoice_insert_api) */
|
|
55
|
+
async createInvoice(body) {
|
|
56
|
+
return this.request('invoice/', body);
|
|
57
|
+
}
|
|
58
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#invoice_status) */
|
|
59
|
+
async getInvoiceStatus(body) {
|
|
60
|
+
return this.request('invoice/status', body);
|
|
61
|
+
}
|
|
62
|
+
/** For more details and usage information see [docs](https://cp.gamemoney.com/apidoc#invoice_list) */
|
|
63
|
+
async getInvoiceList(body) {
|
|
64
|
+
return this.request('invoice/list', body);
|
|
65
|
+
}
|
|
66
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#checkout_insert) */
|
|
67
|
+
async createCheckout(body) {
|
|
68
|
+
return this.request('checkout/insert', body, SignType.RSA);
|
|
69
|
+
}
|
|
70
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#checkout_cancel) */
|
|
71
|
+
async cancelCheckout(body) {
|
|
72
|
+
return this.request('checkout/cancel', body);
|
|
73
|
+
}
|
|
74
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#checkout_status) */
|
|
75
|
+
async getCheckoutStatus(body) {
|
|
76
|
+
return this.request('checkout/status', body);
|
|
77
|
+
}
|
|
78
|
+
/** For more details and usage information see [docs](https://cp.gamemoney.com/apidoc#checkout_list) */
|
|
79
|
+
async getCheckoutList(body) {
|
|
80
|
+
return this.request('checkout/list', body);
|
|
81
|
+
}
|
|
82
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_add) */
|
|
83
|
+
async addCard(body) {
|
|
84
|
+
return this.request('card/add', body);
|
|
85
|
+
}
|
|
86
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_add_token) */
|
|
87
|
+
async addTokenCard(body) {
|
|
88
|
+
return this.request('card/addtoken', body);
|
|
89
|
+
}
|
|
90
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_list) */
|
|
91
|
+
async getCardList(body) {
|
|
92
|
+
return this.request('card/list', body);
|
|
93
|
+
}
|
|
94
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_fulllist) */
|
|
95
|
+
async getCardFullList(body) {
|
|
96
|
+
return this.request('card/fulllist', body);
|
|
97
|
+
}
|
|
98
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#card_list) */
|
|
99
|
+
async deleteCard(body) {
|
|
100
|
+
return this.request('card/delete', body);
|
|
101
|
+
}
|
|
102
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_prepare) */
|
|
103
|
+
async prepareExchange(body) {
|
|
104
|
+
return this.request('exchange/prepare', body);
|
|
105
|
+
}
|
|
106
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_convert) */
|
|
107
|
+
async convertExchange(body) {
|
|
108
|
+
return this.request('exchange/convert', body);
|
|
109
|
+
}
|
|
110
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_fastconvert) */
|
|
111
|
+
async fastConvertExchange(body) {
|
|
112
|
+
return this.request('exchange/fastconvert', body);
|
|
113
|
+
}
|
|
114
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_info) */
|
|
115
|
+
async getExchangeInfo(body) {
|
|
116
|
+
return this.request('exchange/info', body);
|
|
117
|
+
}
|
|
118
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#exchange_status) */
|
|
119
|
+
async getExchangeStatus(body) {
|
|
120
|
+
return this.request('exchange/status', body);
|
|
121
|
+
}
|
|
122
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#stat_balance) */
|
|
123
|
+
async getBalanceStatistics(body) {
|
|
124
|
+
return this.request('statistics/balance', body);
|
|
125
|
+
}
|
|
126
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#stat_days_balance) */
|
|
127
|
+
async getDaysBalanceStatistics(body) {
|
|
128
|
+
return this.request('statistics/days_balance_project', body);
|
|
129
|
+
}
|
|
130
|
+
/** For more details and usage information see [docs](https://cp.gmpays.com/apidoc#stat_paytypes) */
|
|
131
|
+
async getPayTypesStatistics() {
|
|
132
|
+
return this.request('statistics/paytypes');
|
|
133
|
+
}
|
|
134
|
+
/** For more details and usage information see [docs](https://cp.gamemoney.com/apidoc#invoice_api_terminal) */
|
|
135
|
+
async createTerminal(body) {
|
|
136
|
+
return this.request('terminal/create', body);
|
|
137
|
+
}
|
|
138
|
+
}
|