rpay-sdk 0.0.0-stage → 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 +330 -2
- package/index.cjs +10 -0
- package/index.d.ts +1104 -0
- package/index.mjs +2 -0
- package/package.json +63 -4
- package/src/client.mjs +1811 -0
- package/src/constants.mjs +474 -0
- package/src/errors.mjs +29 -0
- package/src/http.mjs +261 -0
- package/src/index.mjs +98 -0
- package/src/matcher.mjs +117 -0
- package/src/unified.mjs +367 -0
- package/src/webhooks.mjs +519 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,1104 @@
|
|
|
1
|
+
export type RPayBankKey =
|
|
2
|
+
| "vietcombank"
|
|
3
|
+
| "acb"
|
|
4
|
+
| "mbbank"
|
|
5
|
+
| "techcombank"
|
|
6
|
+
| "bidv"
|
|
7
|
+
| "vietinbank"
|
|
8
|
+
| "vpbank"
|
|
9
|
+
| "tpbank"
|
|
10
|
+
| "agribank"
|
|
11
|
+
| "msb"
|
|
12
|
+
| "ocb"
|
|
13
|
+
| "seabank"
|
|
14
|
+
| "eximbank"
|
|
15
|
+
| "bvbank"
|
|
16
|
+
| "viettelpay";
|
|
17
|
+
|
|
18
|
+
export type RPayBankCode =
|
|
19
|
+
| "VCB"
|
|
20
|
+
| "ACB"
|
|
21
|
+
| "MB"
|
|
22
|
+
| "TCB"
|
|
23
|
+
| "BIDV"
|
|
24
|
+
| "ICB"
|
|
25
|
+
| "VPB"
|
|
26
|
+
| "TPB"
|
|
27
|
+
| "VBA"
|
|
28
|
+
| "MSB"
|
|
29
|
+
| "OCB"
|
|
30
|
+
| "SEAB"
|
|
31
|
+
| "EIB"
|
|
32
|
+
| "BVB"
|
|
33
|
+
| "VTP";
|
|
34
|
+
|
|
35
|
+
export type RPayUsdtNetworkCode =
|
|
36
|
+
| "TRC20"
|
|
37
|
+
| "BEP20"
|
|
38
|
+
| "ERC20"
|
|
39
|
+
| "POLYGON"
|
|
40
|
+
| "ARBITRUM"
|
|
41
|
+
| "OPTIMISM"
|
|
42
|
+
| "SOLANA"
|
|
43
|
+
| "TON"
|
|
44
|
+
| "BASE"
|
|
45
|
+
| "AVALANCHE"
|
|
46
|
+
| "APTOS"
|
|
47
|
+
| "SUI"
|
|
48
|
+
| "OPBNB"
|
|
49
|
+
| "CELO"
|
|
50
|
+
| "SCROLL"
|
|
51
|
+
| "KAVA"
|
|
52
|
+
| "POLKADOT"
|
|
53
|
+
| "OSMOSIS";
|
|
54
|
+
|
|
55
|
+
export type RPayCryptoTokenSymbol = "USDT" | "USDC";
|
|
56
|
+
export type RPayPaymentChannel = "bank" | "usdt";
|
|
57
|
+
|
|
58
|
+
export interface RPayBankSpec {
|
|
59
|
+
readonly key: RPayBankKey;
|
|
60
|
+
readonly code: RPayBankCode;
|
|
61
|
+
readonly shortName: string;
|
|
62
|
+
readonly fullName: string;
|
|
63
|
+
readonly bin: string;
|
|
64
|
+
readonly apiSlug: string;
|
|
65
|
+
readonly primarySlug: string;
|
|
66
|
+
readonly aliases: readonly string[];
|
|
67
|
+
readonly logo: string;
|
|
68
|
+
readonly v3UsesPhonePin: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface RPayUsdtNetworkSpec {
|
|
72
|
+
readonly network: RPayUsdtNetworkCode;
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly chainKey: string;
|
|
75
|
+
readonly tokenStandard: string;
|
|
76
|
+
readonly decimals: number;
|
|
77
|
+
readonly usdtContract: string;
|
|
78
|
+
readonly usdcContract: string;
|
|
79
|
+
readonly explorerBaseUrl: string;
|
|
80
|
+
readonly avgConfirmSeconds: number;
|
|
81
|
+
readonly recommendedFeeText: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface RPayErrorOptions {
|
|
85
|
+
code?: string;
|
|
86
|
+
status?: number;
|
|
87
|
+
details?: unknown;
|
|
88
|
+
endpoint?: string;
|
|
89
|
+
method?: string;
|
|
90
|
+
rawResponse?: unknown;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export declare class RPayError extends Error {
|
|
94
|
+
code: string;
|
|
95
|
+
status: number;
|
|
96
|
+
details: unknown;
|
|
97
|
+
endpoint: string;
|
|
98
|
+
method: string;
|
|
99
|
+
rawResponse: unknown;
|
|
100
|
+
constructor(message: string, options?: RPayErrorOptions);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface RPayClientConfig {
|
|
104
|
+
/** Base URL of the RPAY API server (default: `"https://api.rpay.vn"` or `process.env.RPAY_DOMAIN`). */
|
|
105
|
+
baseUrl?: string;
|
|
106
|
+
/** Target domain or origin (e.g. `"pay.shopa.vn"`, `"https://pay.shopa.vn"`, or `"auto"` in browser). */
|
|
107
|
+
domain?: string;
|
|
108
|
+
/** White-label child site domain forwarded in `X-Site-Domain` and `X-Forwarded-Host`. */
|
|
109
|
+
siteDomain?: string;
|
|
110
|
+
/** Tenant Site ID forwarded in `X-Site-ID`. */
|
|
111
|
+
siteId?: string;
|
|
112
|
+
/** Default Bank API Token (`rpay_<slug>_live_...` or `process.env.RPAY_BANK_TOKEN`). */
|
|
113
|
+
apiToken?: string;
|
|
114
|
+
/** Alias for `apiToken` or `usdtApiKey`. */
|
|
115
|
+
apiKey?: string;
|
|
116
|
+
/** Alias for `apiToken`. */
|
|
117
|
+
bankToken?: string;
|
|
118
|
+
/** Default Merchant ID for USDT/USDC Crypto Store Gateway (`MRCH-...` or `process.env.RPAY_MERCHANT_ID`). */
|
|
119
|
+
merchantId?: string;
|
|
120
|
+
/** Default API Key for USDT/USDC Crypto Store Gateway (`process.env.RPAY_USDT_API_KEY`). */
|
|
121
|
+
usdtApiKey?: string;
|
|
122
|
+
/** Alias for `usdtApiKey`. */
|
|
123
|
+
usdtKey?: string;
|
|
124
|
+
/** Default Webhook HMAC-SHA256 Secret or STC Signature Key (`process.env.RPAY_WEBHOOK_SECRET`). */
|
|
125
|
+
webhookSecret?: string;
|
|
126
|
+
/** Alias for `webhookSecret`. */
|
|
127
|
+
signatureKey?: string;
|
|
128
|
+
/** Alias for `webhookSecret`. */
|
|
129
|
+
secret?: string;
|
|
130
|
+
/** Request timeout in milliseconds (default: `60000`). */
|
|
131
|
+
timeoutMs?: number;
|
|
132
|
+
/** Custom `fetch` implementation. */
|
|
133
|
+
fetch?: typeof globalThis.fetch;
|
|
134
|
+
/** Default HTTP headers included in every request. */
|
|
135
|
+
headers?: Record<string, string>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface RPayRequestOptions {
|
|
139
|
+
domain?: string;
|
|
140
|
+
siteDomain?: string;
|
|
141
|
+
siteId?: string;
|
|
142
|
+
timeoutMs?: number;
|
|
143
|
+
headers?: Record<string, string>;
|
|
144
|
+
idempotencyKey?: string;
|
|
145
|
+
apiToken?: string;
|
|
146
|
+
apiKey?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type RPayBankInvoiceStatus =
|
|
150
|
+
| "pending"
|
|
151
|
+
| "paid"
|
|
152
|
+
| "reconciled"
|
|
153
|
+
| "expired"
|
|
154
|
+
| "cancelled";
|
|
155
|
+
|
|
156
|
+
export type RPayQRLogoMode =
|
|
157
|
+
| "bank"
|
|
158
|
+
| "rpay"
|
|
159
|
+
| "custom_url"
|
|
160
|
+
| "custom_upload"
|
|
161
|
+
| "none";
|
|
162
|
+
|
|
163
|
+
export interface RPayCreateBankInvoiceInput {
|
|
164
|
+
amountVnd?: number;
|
|
165
|
+
amount?: number;
|
|
166
|
+
orderId?: string;
|
|
167
|
+
transferContent?: string;
|
|
168
|
+
description?: string;
|
|
169
|
+
expireMinutes?: number;
|
|
170
|
+
qrLogoMode?: RPayQRLogoMode;
|
|
171
|
+
qrLogoUrl?: string;
|
|
172
|
+
redirectUrl?: string;
|
|
173
|
+
cancelUrl?: string;
|
|
174
|
+
callbackUrl?: string;
|
|
175
|
+
webhookSecret?: string;
|
|
176
|
+
provider?: "bank" | "vnpay" | "sepay";
|
|
177
|
+
apiToken?: string;
|
|
178
|
+
api_token?: string;
|
|
179
|
+
token?: string;
|
|
180
|
+
idempotencyKey?: string;
|
|
181
|
+
domain?: string;
|
|
182
|
+
siteDomain?: string;
|
|
183
|
+
siteId?: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface RPayBankInvoiceBeneficiaryDTO {
|
|
187
|
+
bankKey: string;
|
|
188
|
+
bankCode: string;
|
|
189
|
+
bankShortName: string;
|
|
190
|
+
bankFullName: string;
|
|
191
|
+
bankBin: string;
|
|
192
|
+
bankLogo: string;
|
|
193
|
+
accountNumber: string;
|
|
194
|
+
accountHolder: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface RPayBankInvoiceQRDTO {
|
|
198
|
+
content: string;
|
|
199
|
+
imageUrl: string;
|
|
200
|
+
dataUrl?: string;
|
|
201
|
+
logoMode: RPayQRLogoMode;
|
|
202
|
+
logoUrl?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface RPayBankInvoiceDTO {
|
|
206
|
+
invoiceId: string;
|
|
207
|
+
invoiceCode: string;
|
|
208
|
+
orderId?: string;
|
|
209
|
+
status: RPayBankInvoiceStatus;
|
|
210
|
+
provider: string;
|
|
211
|
+
amountVnd: number;
|
|
212
|
+
paidAmountVnd: number;
|
|
213
|
+
currency: "VND";
|
|
214
|
+
transferContent: string;
|
|
215
|
+
description?: string;
|
|
216
|
+
beneficiary: RPayBankInvoiceBeneficiaryDTO;
|
|
217
|
+
qr: RPayBankInvoiceQRDTO;
|
|
218
|
+
paymentUrl: string;
|
|
219
|
+
checkoutUrl: string;
|
|
220
|
+
checkoutUrls: {
|
|
221
|
+
bank: string;
|
|
222
|
+
vnpay: string;
|
|
223
|
+
sepay: string;
|
|
224
|
+
};
|
|
225
|
+
redirectUrl?: string;
|
|
226
|
+
cancelUrl?: string;
|
|
227
|
+
hasCallback: boolean;
|
|
228
|
+
cancelToken?: string;
|
|
229
|
+
matchedTransactionId?: string;
|
|
230
|
+
matchedTransactionDate?: string;
|
|
231
|
+
matchedDescription?: string;
|
|
232
|
+
remainingSeconds: number;
|
|
233
|
+
expiresAt: string;
|
|
234
|
+
paidAt?: string;
|
|
235
|
+
cancelledAt?: string;
|
|
236
|
+
createdAt: string;
|
|
237
|
+
updatedAt: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Unified Invoice DTO compatible with BOTH Bank (VND) and Crypto (USDT / USDC).
|
|
242
|
+
*/
|
|
243
|
+
export interface RPayUnifiedInvoiceDTO {
|
|
244
|
+
channel: RPayPaymentChannel;
|
|
245
|
+
invoiceId: string;
|
|
246
|
+
invoiceCode: string;
|
|
247
|
+
txCode?: string;
|
|
248
|
+
orderId: string;
|
|
249
|
+
status: "pending" | "paid" | "expired" | "cancelled";
|
|
250
|
+
rawStatus: string;
|
|
251
|
+
isPaid: boolean;
|
|
252
|
+
amount: number;
|
|
253
|
+
paidAmount: number;
|
|
254
|
+
currency: "VND" | "USDT" | "USDC" | string;
|
|
255
|
+
networkOrBank: string;
|
|
256
|
+
bankBin: string;
|
|
257
|
+
recipientAddress: string;
|
|
258
|
+
recipientName: string;
|
|
259
|
+
transferContent: string;
|
|
260
|
+
description: string;
|
|
261
|
+
paymentUrl: string;
|
|
262
|
+
qrContent: string;
|
|
263
|
+
qrImageUrl: string;
|
|
264
|
+
qrDataUrl: string;
|
|
265
|
+
cancelToken?: string;
|
|
266
|
+
transactionId?: string;
|
|
267
|
+
remainingSeconds: number;
|
|
268
|
+
expiresAt?: string;
|
|
269
|
+
paidAt?: string;
|
|
270
|
+
raw: Record<string, unknown>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Unified Transaction DTO (LSGD) compatible with BOTH Bank (POS/V2/V3) and Crypto (USDT/USDC).
|
|
275
|
+
*/
|
|
276
|
+
export interface RPayUnifiedTransactionDTO {
|
|
277
|
+
channel: RPayPaymentChannel;
|
|
278
|
+
transactionID: string;
|
|
279
|
+
invoiceCode: string;
|
|
280
|
+
orderId: string;
|
|
281
|
+
type: "IN" | "OUT";
|
|
282
|
+
status: "completed" | "pending" | "expired" | "cancelled";
|
|
283
|
+
amount: number;
|
|
284
|
+
currency: "VND" | "USDT" | "USDC" | string;
|
|
285
|
+
networkOrBank: string;
|
|
286
|
+
recipientAddress: string;
|
|
287
|
+
senderAddress: string;
|
|
288
|
+
description: string;
|
|
289
|
+
transactionDate: string;
|
|
290
|
+
txHash: string;
|
|
291
|
+
raw: Record<string, unknown>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface RPayUnifiedCreateInvoiceInput {
|
|
295
|
+
channel?: "bank" | "usdt" | "crypto";
|
|
296
|
+
type?: "bank" | "usdt" | "crypto";
|
|
297
|
+
currency?: "VND" | "USDT" | "USDC" | string;
|
|
298
|
+
token?: string;
|
|
299
|
+
amount?: number;
|
|
300
|
+
amountVnd?: number;
|
|
301
|
+
amountUsdt?: number;
|
|
302
|
+
orderId?: string;
|
|
303
|
+
request_id?: string;
|
|
304
|
+
description?: string;
|
|
305
|
+
transferContent?: string;
|
|
306
|
+
network?: RPayUsdtNetworkCode | string;
|
|
307
|
+
walletAddress?: string;
|
|
308
|
+
address?: string;
|
|
309
|
+
expireMinutes?: number;
|
|
310
|
+
qrLogoMode?: RPayQRLogoMode;
|
|
311
|
+
qrLogoUrl?: string;
|
|
312
|
+
callbackUrl?: string;
|
|
313
|
+
redirectUrl?: string;
|
|
314
|
+
returnUrl?: string;
|
|
315
|
+
cancelUrl?: string;
|
|
316
|
+
webhookSecret?: string;
|
|
317
|
+
apiToken?: string;
|
|
318
|
+
apiKey?: string;
|
|
319
|
+
merchantId?: string;
|
|
320
|
+
idempotencyKey?: string;
|
|
321
|
+
useStandardGateway?: boolean;
|
|
322
|
+
domain?: string;
|
|
323
|
+
siteDomain?: string;
|
|
324
|
+
siteId?: string;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface RPayUnifiedHistoryQueryParams {
|
|
328
|
+
channel?: "bank" | "usdt" | "all" | "both";
|
|
329
|
+
type?: "bank" | "usdt" | "all" | "both";
|
|
330
|
+
version?: "v2" | "pos" | "v3" | "v1";
|
|
331
|
+
bank?: string;
|
|
332
|
+
token?: string;
|
|
333
|
+
bankToken?: string;
|
|
334
|
+
cryptoToken?: RPayCryptoTokenSymbol;
|
|
335
|
+
password?: string;
|
|
336
|
+
accountNumber?: string;
|
|
337
|
+
phone?: string;
|
|
338
|
+
pin?: string;
|
|
339
|
+
merchantId?: string;
|
|
340
|
+
usdtApiKey?: string;
|
|
341
|
+
network?: RPayUsdtNetworkCode | string;
|
|
342
|
+
status?: string;
|
|
343
|
+
fromDate?: string;
|
|
344
|
+
toDate?: string;
|
|
345
|
+
limit?: number;
|
|
346
|
+
page?: number;
|
|
347
|
+
domain?: string;
|
|
348
|
+
siteDomain?: string;
|
|
349
|
+
siteId?: string;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface RPayUnifiedHistoryResult {
|
|
353
|
+
channel: "bank" | "usdt" | "all";
|
|
354
|
+
count: number;
|
|
355
|
+
transactions: RPayUnifiedTransactionDTO[];
|
|
356
|
+
bankTransactions?: RPayUnifiedTransactionDTO[];
|
|
357
|
+
usdtTransactions?: RPayUnifiedTransactionDTO[];
|
|
358
|
+
raw: unknown;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export interface RPayEnvelope<T> {
|
|
362
|
+
isSuccess: boolean;
|
|
363
|
+
success: boolean;
|
|
364
|
+
status: number;
|
|
365
|
+
code: string;
|
|
366
|
+
message: string;
|
|
367
|
+
data: T;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export interface RPayStandardBankTransaction {
|
|
371
|
+
transactionID: string;
|
|
372
|
+
amount: string | number;
|
|
373
|
+
description: string;
|
|
374
|
+
transactionDate: string;
|
|
375
|
+
type: "IN" | "OUT";
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface RPayPosTransactionsResponse {
|
|
379
|
+
status: "success" | "error";
|
|
380
|
+
msg: string;
|
|
381
|
+
bankKey?: string;
|
|
382
|
+
bankCode?: string;
|
|
383
|
+
bankShortName?: string;
|
|
384
|
+
bankBin?: string;
|
|
385
|
+
accountNumber?: string;
|
|
386
|
+
accountHolder?: string;
|
|
387
|
+
transactions: RPayStandardBankTransaction[];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export interface RPayV2TransactionsResponse {
|
|
391
|
+
status: "success" | "error";
|
|
392
|
+
msg: string;
|
|
393
|
+
transactions: RPayStandardBankTransaction[];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface RPayBankHistoryQueryParams {
|
|
397
|
+
token?: string;
|
|
398
|
+
bank?: string;
|
|
399
|
+
fromDate?: string;
|
|
400
|
+
toDate?: string;
|
|
401
|
+
limit?: number;
|
|
402
|
+
method?: "POST" | "GET";
|
|
403
|
+
domain?: string;
|
|
404
|
+
siteDomain?: string;
|
|
405
|
+
siteId?: string;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export interface RPayBankV3QueryParams extends RPayBankHistoryQueryParams {
|
|
409
|
+
password?: string;
|
|
410
|
+
accountNumber?: string;
|
|
411
|
+
phone?: string;
|
|
412
|
+
pin?: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export interface RPayTransactionMatchCriteria {
|
|
416
|
+
expectedAmount?: number | string;
|
|
417
|
+
orderCode?: string;
|
|
418
|
+
transferContent?: string;
|
|
419
|
+
exactAmount?: boolean;
|
|
420
|
+
ignoreSeparators?: boolean;
|
|
421
|
+
processedIds?: Iterable<string>;
|
|
422
|
+
mutateProcessedIds?: boolean;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export interface RPayUnifiedMatchCriteria extends RPayTransactionMatchCriteria {
|
|
426
|
+
channel?: "bank" | "usdt" | "all";
|
|
427
|
+
orderId?: string;
|
|
428
|
+
txHash?: string;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export interface RPayMatchedTransaction extends RPayStandardBankTransaction {
|
|
432
|
+
numericAmount: number;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface RPayBankTrafficNodeSnapshot {
|
|
436
|
+
bankKey: string;
|
|
437
|
+
bankCode: string;
|
|
438
|
+
shortName: string;
|
|
439
|
+
bin: string;
|
|
440
|
+
logo: string;
|
|
441
|
+
connected: boolean;
|
|
442
|
+
linkedCount: number;
|
|
443
|
+
activeCount: number;
|
|
444
|
+
errorCount: number;
|
|
445
|
+
inFlightCount: number;
|
|
446
|
+
totalRequests: number;
|
|
447
|
+
successRequests: number;
|
|
448
|
+
failedRequests: number;
|
|
449
|
+
coalescedHits: number;
|
|
450
|
+
lastLatencyMs: number;
|
|
451
|
+
lastPollAt?: string;
|
|
452
|
+
status: "online" | "busy" | "error" | "standby";
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export interface RPayBankTrafficSnapshot {
|
|
456
|
+
updatedAt: string;
|
|
457
|
+
connectedBanksCount: number;
|
|
458
|
+
totalBanksCount: number;
|
|
459
|
+
totalSystemRequests: number;
|
|
460
|
+
totalInFlightRequests: number;
|
|
461
|
+
coalescedRequests: number;
|
|
462
|
+
banks: RPayBankTrafficNodeSnapshot[];
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export interface RPayCreateVietQRInput {
|
|
466
|
+
bank?: string;
|
|
467
|
+
bankBin?: string;
|
|
468
|
+
bankNumber?: string;
|
|
469
|
+
account?: string;
|
|
470
|
+
accountNumber?: string;
|
|
471
|
+
amount?: string | number;
|
|
472
|
+
purpose?: string;
|
|
473
|
+
memo?: string;
|
|
474
|
+
content?: string;
|
|
475
|
+
transferContent?: string;
|
|
476
|
+
orderId?: string;
|
|
477
|
+
size?: number;
|
|
478
|
+
withLogo?: boolean;
|
|
479
|
+
logo?: RPayQRLogoMode;
|
|
480
|
+
logoUrl?: string;
|
|
481
|
+
logoDataUrl?: string;
|
|
482
|
+
domain?: string;
|
|
483
|
+
siteDomain?: string;
|
|
484
|
+
siteId?: string;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export interface RPayVietQRResultDTO {
|
|
488
|
+
bank: {
|
|
489
|
+
code: string;
|
|
490
|
+
shortName: string;
|
|
491
|
+
fullName: string;
|
|
492
|
+
bin: string;
|
|
493
|
+
logoUrl: string;
|
|
494
|
+
};
|
|
495
|
+
bankNumber: string;
|
|
496
|
+
amount?: string;
|
|
497
|
+
purpose?: string;
|
|
498
|
+
isDynamic: boolean;
|
|
499
|
+
withLogo: boolean;
|
|
500
|
+
logoMode: string;
|
|
501
|
+
size: number;
|
|
502
|
+
content: string;
|
|
503
|
+
qrDataUrl: string;
|
|
504
|
+
qrImageUrl: string;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export interface RPayUsdtAddInvoiceInput {
|
|
508
|
+
merchant_id?: string;
|
|
509
|
+
merchantId?: string;
|
|
510
|
+
api_key?: string;
|
|
511
|
+
apiKey?: string;
|
|
512
|
+
name?: string;
|
|
513
|
+
description?: string;
|
|
514
|
+
amount: number | string;
|
|
515
|
+
token?: RPayCryptoTokenSymbol;
|
|
516
|
+
request_id?: string;
|
|
517
|
+
orderId?: string;
|
|
518
|
+
callback_url?: string;
|
|
519
|
+
callbackUrl?: string;
|
|
520
|
+
success_url?: string;
|
|
521
|
+
returnUrl?: string;
|
|
522
|
+
redirectUrl?: string;
|
|
523
|
+
cancel_url?: string;
|
|
524
|
+
cancelUrl?: string;
|
|
525
|
+
network?: RPayUsdtNetworkCode | string;
|
|
526
|
+
address?: string;
|
|
527
|
+
expireMinutes?: number;
|
|
528
|
+
domain?: string;
|
|
529
|
+
siteDomain?: string;
|
|
530
|
+
siteId?: string;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export interface RPayCreatePublicUsdtInvoiceInput {
|
|
534
|
+
apiKey?: string;
|
|
535
|
+
api_key?: string;
|
|
536
|
+
apiToken?: string;
|
|
537
|
+
merchantId?: string;
|
|
538
|
+
merchant_id?: string;
|
|
539
|
+
orderId?: string;
|
|
540
|
+
order_id?: string;
|
|
541
|
+
amountUsdt?: number;
|
|
542
|
+
amount?: number;
|
|
543
|
+
exchangeRate?: number;
|
|
544
|
+
network?: RPayUsdtNetworkCode | string;
|
|
545
|
+
token?: RPayCryptoTokenSymbol;
|
|
546
|
+
walletAddress?: string;
|
|
547
|
+
address?: string;
|
|
548
|
+
expireMinutes?: number;
|
|
549
|
+
description?: string;
|
|
550
|
+
callbackUrl?: string;
|
|
551
|
+
returnUrl?: string;
|
|
552
|
+
cancelUrl?: string;
|
|
553
|
+
domain?: string;
|
|
554
|
+
siteDomain?: string;
|
|
555
|
+
siteId?: string;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export interface RPaySelectUsdtPaymentOptionInput {
|
|
559
|
+
token?: RPayCryptoTokenSymbol;
|
|
560
|
+
network?: RPayUsdtNetworkCode | string;
|
|
561
|
+
walletId?: string;
|
|
562
|
+
walletAddress?: string;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export interface RPayWebhookVerificationResult {
|
|
566
|
+
verified: boolean;
|
|
567
|
+
reason: string;
|
|
568
|
+
scheme: string;
|
|
569
|
+
event: string;
|
|
570
|
+
canonicalPayload?: string;
|
|
571
|
+
bank?: string;
|
|
572
|
+
accountNumber?: string;
|
|
573
|
+
payload: Record<string, unknown> | null;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export interface RPayUnifiedWebhookEvent extends RPayWebhookVerificationResult {
|
|
577
|
+
channel: RPayPaymentChannel;
|
|
578
|
+
invoiceCode: string;
|
|
579
|
+
orderId: string;
|
|
580
|
+
status: string;
|
|
581
|
+
amount: number;
|
|
582
|
+
paidAmount: number;
|
|
583
|
+
currency: string;
|
|
584
|
+
networkOrBank: string;
|
|
585
|
+
transactionId: string;
|
|
586
|
+
transferContent: string;
|
|
587
|
+
recipientAddress: string;
|
|
588
|
+
senderAddress: string;
|
|
589
|
+
transactions: RPayStandardBankTransaction[];
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
export interface RPayWebhookHandlerCallbacks {
|
|
593
|
+
secret?: string;
|
|
594
|
+
onPaid?: (event: RPayUnifiedWebhookEvent, req?: unknown) => Promise<void> | void;
|
|
595
|
+
onTransactions?: (event: RPayUnifiedWebhookEvent, req?: unknown) => Promise<void> | void;
|
|
596
|
+
onEvent?: (event: RPayUnifiedWebhookEvent, req?: unknown) => Promise<void> | void;
|
|
597
|
+
onError?: (err: unknown, req?: unknown, res?: unknown) => void;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
export interface RPayRouteOptions {
|
|
601
|
+
/** Action override (`"lsgd"`, `"history"`, `"transactions"`, `"invoice"`). */
|
|
602
|
+
action?: string;
|
|
603
|
+
/** Channel (`"bank"`, `"usdt"`, `"all"`). */
|
|
604
|
+
channel?: "bank" | "usdt" | "all" | "both";
|
|
605
|
+
/** Target domain override (e.g. `"pay.shopa.vn"`). */
|
|
606
|
+
domain?: string;
|
|
607
|
+
siteDomain?: string;
|
|
608
|
+
siteId?: string;
|
|
609
|
+
/** Router provider name (e.g. `"9ROUTER"`). */
|
|
610
|
+
provider?: string;
|
|
611
|
+
/** Security mode (e.g. `"HMAC_256"`). */
|
|
612
|
+
security?: string;
|
|
613
|
+
/** Coalesced request counter label (e.g. `"498.310 req"`). */
|
|
614
|
+
coalesced?: string;
|
|
615
|
+
/** Target bank code, slug, or BIN (e.g. `"VCB"`). */
|
|
616
|
+
bank?: string;
|
|
617
|
+
/** Target bank BIN (e.g. `"970436"`). */
|
|
618
|
+
bankBin?: string;
|
|
619
|
+
/** Recipient bank account number (when generating VietQR directly). */
|
|
620
|
+
bankNumber?: string;
|
|
621
|
+
accountNumber?: string;
|
|
622
|
+
account?: string;
|
|
623
|
+
/** Payment amount in VND or USDT. */
|
|
624
|
+
amount?: number;
|
|
625
|
+
amountVnd?: number;
|
|
626
|
+
amountUsdt?: number;
|
|
627
|
+
/** Merchant order reference. */
|
|
628
|
+
orderId?: string;
|
|
629
|
+
transferContent?: string;
|
|
630
|
+
description?: string;
|
|
631
|
+
memo?: string;
|
|
632
|
+
/** Blockchain network code for crypto payments (`"TRC20"`, `"BEP20"`, ...). */
|
|
633
|
+
network?: RPayUsdtNetworkCode | string;
|
|
634
|
+
/** Crypto token symbol (`"USDT"` | `"USDC"`). */
|
|
635
|
+
token?: string;
|
|
636
|
+
currency?: string;
|
|
637
|
+
/** Incoming webhook payload to verify & auto-route. */
|
|
638
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
639
|
+
/** Raw webhook request body for `X-RPay-Body-Signature` / `X-STC-HMAC-SHA256` verification. */
|
|
640
|
+
rawBody?: string | Uint8Array;
|
|
641
|
+
/** Incoming HTTP request headers for webhook verification. */
|
|
642
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
643
|
+
/** Webhook secret or signature key. */
|
|
644
|
+
secret?: string;
|
|
645
|
+
webhookSecret?: string;
|
|
646
|
+
signatureKey?: string;
|
|
647
|
+
/** Bank API token override. */
|
|
648
|
+
apiToken?: string;
|
|
649
|
+
apiKey?: string;
|
|
650
|
+
/** Skip network call in router mode and use local snapshot. */
|
|
651
|
+
offline?: boolean;
|
|
652
|
+
/** Throw HTTP errors instead of falling back in router mode. */
|
|
653
|
+
strictHttp?: boolean;
|
|
654
|
+
[key: string]: unknown;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export interface RPayRouteResult {
|
|
658
|
+
ok: boolean;
|
|
659
|
+
mode: "router" | "payment" | "vietqr" | "crypto" | "webhook" | "lsgd";
|
|
660
|
+
provider: string;
|
|
661
|
+
security: string;
|
|
662
|
+
coalesced?: string;
|
|
663
|
+
socketLive?: boolean;
|
|
664
|
+
connectedBanksCount?: number;
|
|
665
|
+
totalBanksCount?: number;
|
|
666
|
+
badge?: string;
|
|
667
|
+
snapshot?: RPayBankTrafficSnapshot;
|
|
668
|
+
bank?: RPayBankSpec | { code: string } | null;
|
|
669
|
+
amount?: number;
|
|
670
|
+
network?: string;
|
|
671
|
+
invoice?: RPayUnifiedInvoiceDTO | RPayBankInvoiceDTO | Record<string, unknown>;
|
|
672
|
+
qr?: RPayVietQRResultDTO | Record<string, unknown>;
|
|
673
|
+
transactions?: RPayUnifiedTransactionDTO[];
|
|
674
|
+
data?: unknown;
|
|
675
|
+
verified?: boolean;
|
|
676
|
+
reason?: string;
|
|
677
|
+
scheme?: string;
|
|
678
|
+
event?: string;
|
|
679
|
+
payload?: Record<string, unknown> | null;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export declare class RPayClient {
|
|
683
|
+
config: Required<
|
|
684
|
+
Pick<
|
|
685
|
+
RPayClientConfig,
|
|
686
|
+
| "baseUrl"
|
|
687
|
+
| "domain"
|
|
688
|
+
| "siteDomain"
|
|
689
|
+
| "siteId"
|
|
690
|
+
| "apiToken"
|
|
691
|
+
| "merchantId"
|
|
692
|
+
| "usdtApiKey"
|
|
693
|
+
| "webhookSecret"
|
|
694
|
+
| "timeoutMs"
|
|
695
|
+
| "headers"
|
|
696
|
+
>
|
|
697
|
+
> & {
|
|
698
|
+
fetch?: typeof globalThis.fetch;
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
constructor(config?: RPayClientConfig);
|
|
702
|
+
|
|
703
|
+
configure(nextConfig?: Partial<RPayClientConfig>): this;
|
|
704
|
+
|
|
705
|
+
/** Alias for `configure(...)` — Khởi tạo nhanh cấu hình RPAY SDK. */
|
|
706
|
+
init(nextConfig?: Partial<RPayClientConfig>): this;
|
|
707
|
+
|
|
708
|
+
/** Registers or updates a domain-scoped client (`"pay.shopa.vn"`). */
|
|
709
|
+
registerDomain(domain: string, overrides?: Partial<RPayClientConfig>): RPayClient;
|
|
710
|
+
|
|
711
|
+
/** Retrieves or creates a domain-scoped client (`"pay.shopa.vn"`). */
|
|
712
|
+
forDomain(domain: string, overrides?: Partial<RPayClientConfig>): RPayClient;
|
|
713
|
+
|
|
714
|
+
/** Lists all registered domain hostnames. */
|
|
715
|
+
listDomains(): string[];
|
|
716
|
+
|
|
717
|
+
request<T = unknown>(options: {
|
|
718
|
+
method: string;
|
|
719
|
+
path: string;
|
|
720
|
+
domain?: string;
|
|
721
|
+
siteDomain?: string;
|
|
722
|
+
siteId?: string;
|
|
723
|
+
query?: Record<string, unknown>;
|
|
724
|
+
body?: unknown;
|
|
725
|
+
headers?: Record<string, string>;
|
|
726
|
+
bearerToken?: string;
|
|
727
|
+
apiKey?: string;
|
|
728
|
+
idempotencyKey?: string;
|
|
729
|
+
timeoutMs?: number;
|
|
730
|
+
allowLogicError?: boolean;
|
|
731
|
+
}): Promise<T>;
|
|
732
|
+
|
|
733
|
+
/** Unified Invoice Creation — works for BOTH Bank (VND) & Crypto (USDT/USDC). */
|
|
734
|
+
createInvoice(
|
|
735
|
+
input: RPayUnifiedCreateInvoiceInput,
|
|
736
|
+
reqOptions?: RPayRequestOptions
|
|
737
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
738
|
+
|
|
739
|
+
/** Shorthand one-liner for `createInvoice(input)` — Tạo thanh toán nhanh cho cả Bank (VNĐ) & USDT/USDC. */
|
|
740
|
+
pay(
|
|
741
|
+
input: RPayUnifiedCreateInvoiceInput,
|
|
742
|
+
reqOptions?: RPayRequestOptions
|
|
743
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
744
|
+
|
|
745
|
+
/** Shorthand one-liner to generate a VietQR code (`{ bank, account, amount, memo }`). */
|
|
746
|
+
qr(
|
|
747
|
+
input: RPayCreateVietQRInput,
|
|
748
|
+
reqOptions?: RPayRequestOptions
|
|
749
|
+
): Promise<RPayVietQRResultDTO>;
|
|
750
|
+
|
|
751
|
+
/** Unified Invoice Status Lookup — works for BOTH Bank (`RPINV...`) & USDT (`USINV...`/`USTX...`). */
|
|
752
|
+
getInvoice(
|
|
753
|
+
invoiceCode: string,
|
|
754
|
+
options?: RPayRequestOptions & { channel?: RPayPaymentChannel }
|
|
755
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
756
|
+
|
|
757
|
+
/** Shorthand alias for `getInvoice(code, options)`. */
|
|
758
|
+
status(
|
|
759
|
+
invoiceCode: string,
|
|
760
|
+
options?: RPayRequestOptions & { channel?: RPayPaymentChannel }
|
|
761
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
762
|
+
|
|
763
|
+
/** Unified Immediate Live Reconciliation Check — works for BOTH Bank & USDT. */
|
|
764
|
+
checkInvoice(
|
|
765
|
+
invoiceCode: string,
|
|
766
|
+
options?: RPayRequestOptions & { channel?: RPayPaymentChannel }
|
|
767
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
768
|
+
|
|
769
|
+
/** Shorthand alias for `checkInvoice(code, options)`. */
|
|
770
|
+
check(
|
|
771
|
+
invoiceCode: string,
|
|
772
|
+
options?: RPayRequestOptions & { channel?: RPayPaymentChannel }
|
|
773
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
774
|
+
|
|
775
|
+
/** Unified Payment Polling — works for BOTH Bank & USDT. */
|
|
776
|
+
waitForPayment(
|
|
777
|
+
invoiceCode: string,
|
|
778
|
+
options?: RPayRequestOptions & {
|
|
779
|
+
channel?: RPayPaymentChannel;
|
|
780
|
+
intervalMs?: number;
|
|
781
|
+
timeoutMs?: number;
|
|
782
|
+
triggerLiveCheck?: boolean;
|
|
783
|
+
onTick?: (invoice: RPayUnifiedInvoiceDTO) => void;
|
|
784
|
+
}
|
|
785
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
786
|
+
|
|
787
|
+
/** Unified Transaction History (LSGD) — works for `"bank"`, `"usdt"`, or `"all"` (both in parallel). */
|
|
788
|
+
getHistory(params?: RPayUnifiedHistoryQueryParams): Promise<RPayUnifiedHistoryResult>;
|
|
789
|
+
|
|
790
|
+
/** Alias for `getHistory` — Tra cứu Lịch sử Giao dịch (LSGD) hợp nhất Bank & USDT. */
|
|
791
|
+
lsgd(params?: RPayUnifiedHistoryQueryParams): Promise<RPayUnifiedHistoryResult>;
|
|
792
|
+
|
|
793
|
+
/** Alias for `getHistory` — Tra cứu danh sách giao dịch hợp nhất Bank & USDT. */
|
|
794
|
+
getTransactions(params?: RPayUnifiedHistoryQueryParams): Promise<RPayUnifiedHistoryResult>;
|
|
795
|
+
|
|
796
|
+
/** Unified Idempotent Payment Matcher across Bank & USDT transactions. */
|
|
797
|
+
matchPayment(
|
|
798
|
+
transactions: RPayUnifiedTransactionDTO[],
|
|
799
|
+
criteria?: RPayUnifiedMatchCriteria
|
|
800
|
+
): RPayUnifiedTransactionDTO[];
|
|
801
|
+
|
|
802
|
+
route(options?: RPayRouteOptions): Promise<RPayRouteResult>;
|
|
803
|
+
|
|
804
|
+
invoices: {
|
|
805
|
+
create(
|
|
806
|
+
input: RPayCreateBankInvoiceInput,
|
|
807
|
+
reqOptions?: RPayRequestOptions
|
|
808
|
+
): Promise<RPayEnvelope<RPayBankInvoiceDTO>>;
|
|
809
|
+
createUnified(
|
|
810
|
+
input: RPayUnifiedCreateInvoiceInput,
|
|
811
|
+
reqOptions?: RPayRequestOptions
|
|
812
|
+
): Promise<RPayUnifiedInvoiceDTO>;
|
|
813
|
+
get(
|
|
814
|
+
invoiceCode: string,
|
|
815
|
+
reqOptions?: RPayRequestOptions
|
|
816
|
+
): Promise<RPayEnvelope<RPayBankInvoiceDTO>>;
|
|
817
|
+
check(
|
|
818
|
+
invoiceCode: string,
|
|
819
|
+
reqOptions?: RPayRequestOptions
|
|
820
|
+
): Promise<RPayEnvelope<RPayBankInvoiceDTO>>;
|
|
821
|
+
cancel(
|
|
822
|
+
invoiceCode: string,
|
|
823
|
+
cancelToken: string,
|
|
824
|
+
reqOptions?: RPayRequestOptions
|
|
825
|
+
): Promise<RPayEnvelope<RPayBankInvoiceDTO>>;
|
|
826
|
+
waitForSettlement(
|
|
827
|
+
invoiceCode: string,
|
|
828
|
+
pollOptions?: {
|
|
829
|
+
domain?: string;
|
|
830
|
+
siteId?: string;
|
|
831
|
+
intervalMs?: number;
|
|
832
|
+
timeoutMs?: number;
|
|
833
|
+
triggerLiveCheck?: boolean;
|
|
834
|
+
onTick?: (invoice: RPayBankInvoiceDTO) => void;
|
|
835
|
+
}
|
|
836
|
+
): Promise<RPayBankInvoiceDTO>;
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
banks: {
|
|
840
|
+
listLocalCatalog(): readonly RPayBankSpec[];
|
|
841
|
+
resolve(identifier: string): RPayBankSpec | null;
|
|
842
|
+
catalog(reqOptions?: RPayRequestOptions): Promise<RPayEnvelope<RPayBankSpec[]>>;
|
|
843
|
+
status(reqOptions?: RPayRequestOptions): Promise<RPayEnvelope<unknown>>;
|
|
844
|
+
trafficSnapshot(
|
|
845
|
+
reqOptions?: RPayRequestOptions
|
|
846
|
+
): Promise<RPayEnvelope<RPayBankTrafficSnapshot>>;
|
|
847
|
+
buildTrafficStreamUrl(domain?: string): string;
|
|
848
|
+
buildTrafficWebSocketUrl(domain?: string): string;
|
|
849
|
+
pos(
|
|
850
|
+
params?: RPayBankHistoryQueryParams | string
|
|
851
|
+
): Promise<RPayPosTransactionsResponse>;
|
|
852
|
+
v2(
|
|
853
|
+
params?: RPayBankHistoryQueryParams | string
|
|
854
|
+
): Promise<RPayV2TransactionsResponse>;
|
|
855
|
+
buildV3GetUrl(params: RPayBankV3QueryParams): string;
|
|
856
|
+
v3(params: RPayBankV3QueryParams): Promise<RPayV2TransactionsResponse>;
|
|
857
|
+
v1(params?: RPayBankHistoryQueryParams | string): Promise<unknown>;
|
|
858
|
+
matchTransactions(
|
|
859
|
+
transactions: RPayStandardBankTransaction[],
|
|
860
|
+
criteria?: RPayTransactionMatchCriteria
|
|
861
|
+
): RPayMatchedTransaction[];
|
|
862
|
+
findMatchingTransaction(
|
|
863
|
+
transactions: RPayStandardBankTransaction[],
|
|
864
|
+
criteria?: RPayTransactionMatchCriteria
|
|
865
|
+
): RPayMatchedTransaction | null;
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
history: RPayClient["banks"];
|
|
869
|
+
|
|
870
|
+
pos: {
|
|
871
|
+
getTransactions(
|
|
872
|
+
params?: RPayBankHistoryQueryParams | string
|
|
873
|
+
): Promise<RPayPosTransactionsResponse>;
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
vietqr: {
|
|
877
|
+
listBanks(reqOptions?: RPayRequestOptions): Promise<RPayEnvelope<unknown>>;
|
|
878
|
+
getBankLogoUrl(bankOrBin: string, domain?: string): string;
|
|
879
|
+
create(
|
|
880
|
+
input: RPayCreateVietQRInput,
|
|
881
|
+
reqOptions?: RPayRequestOptions
|
|
882
|
+
): Promise<RPayEnvelope<RPayVietQRResultDTO>>;
|
|
883
|
+
buildPngUrl(input: RPayCreateVietQRInput): string;
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
usdt: {
|
|
887
|
+
listLocalNetworks(): readonly RPayUsdtNetworkSpec[];
|
|
888
|
+
resolveNetwork(network: string): RPayUsdtNetworkSpec | null;
|
|
889
|
+
listPublicNetworks(
|
|
890
|
+
reqOptions?: RPayRequestOptions
|
|
891
|
+
): Promise<RPayEnvelope<RPayUsdtNetworkSpec[]>>;
|
|
892
|
+
addInvoice(
|
|
893
|
+
input: RPayUsdtAddInvoiceInput,
|
|
894
|
+
reqOptions?: RPayRequestOptions
|
|
895
|
+
): Promise<Record<string, unknown>>;
|
|
896
|
+
getInvoiceStatus(
|
|
897
|
+
input: {
|
|
898
|
+
merchant_id?: string;
|
|
899
|
+
merchantId?: string;
|
|
900
|
+
api_key?: string;
|
|
901
|
+
apiKey?: string;
|
|
902
|
+
trans_id: string;
|
|
903
|
+
network?: string;
|
|
904
|
+
address?: string;
|
|
905
|
+
domain?: string;
|
|
906
|
+
siteId?: string;
|
|
907
|
+
},
|
|
908
|
+
reqOptions?: RPayRequestOptions
|
|
909
|
+
): Promise<Record<string, unknown>>;
|
|
910
|
+
getInvoiceHistory(
|
|
911
|
+
input?: Record<string, unknown>,
|
|
912
|
+
reqOptions?: RPayRequestOptions
|
|
913
|
+
): Promise<Record<string, unknown>>;
|
|
914
|
+
getNetworks(
|
|
915
|
+
input?: Record<string, unknown>,
|
|
916
|
+
reqOptions?: RPayRequestOptions
|
|
917
|
+
): Promise<Record<string, unknown>>;
|
|
918
|
+
createPublicInvoice(
|
|
919
|
+
input: RPayCreatePublicUsdtInvoiceInput,
|
|
920
|
+
reqOptions?: RPayRequestOptions
|
|
921
|
+
): Promise<RPayEnvelope<Record<string, unknown>>>;
|
|
922
|
+
getPublicInvoice(
|
|
923
|
+
code: string,
|
|
924
|
+
reqOptions?: RPayRequestOptions
|
|
925
|
+
): Promise<RPayEnvelope<Record<string, unknown>>>;
|
|
926
|
+
selectPaymentOption(
|
|
927
|
+
code: string,
|
|
928
|
+
selection: RPaySelectUsdtPaymentOptionInput,
|
|
929
|
+
reqOptions?: RPayRequestOptions
|
|
930
|
+
): Promise<RPayEnvelope<Record<string, unknown>>>;
|
|
931
|
+
checkPublicInvoice(
|
|
932
|
+
code: string,
|
|
933
|
+
reqOptions?: RPayRequestOptions
|
|
934
|
+
): Promise<RPayEnvelope<Record<string, unknown>>>;
|
|
935
|
+
waitForSettlement(
|
|
936
|
+
code: string,
|
|
937
|
+
pollOptions?: {
|
|
938
|
+
domain?: string;
|
|
939
|
+
siteId?: string;
|
|
940
|
+
intervalMs?: number;
|
|
941
|
+
timeoutMs?: number;
|
|
942
|
+
triggerOnChainCheck?: boolean;
|
|
943
|
+
onTick?: (invoice: Record<string, unknown>) => void;
|
|
944
|
+
}
|
|
945
|
+
): Promise<Record<string, unknown>>;
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
webhooks: {
|
|
949
|
+
buildCanonicalPayloadString: typeof buildCanonicalPayloadString;
|
|
950
|
+
hmacSha256Hex: typeof hmacSha256Hex;
|
|
951
|
+
safeCompareSignature: typeof safeCompareSignature;
|
|
952
|
+
signCanonicalPayload: typeof signCanonicalPayload;
|
|
953
|
+
signRawBody: typeof signRawBody;
|
|
954
|
+
normalizeUnifiedWebhookEvent: typeof normalizeUnifiedWebhookEvent;
|
|
955
|
+
verifyBankInvoice(options: {
|
|
956
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
957
|
+
rawBody?: string | Uint8Array;
|
|
958
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
959
|
+
secret?: string;
|
|
960
|
+
}): RPayWebhookVerificationResult;
|
|
961
|
+
verifyUsdt(options: {
|
|
962
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
963
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
964
|
+
secret?: string;
|
|
965
|
+
}): RPayWebhookVerificationResult;
|
|
966
|
+
verifyTransaction(options: {
|
|
967
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
968
|
+
rawBody?: string | Uint8Array;
|
|
969
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
970
|
+
signatureKey?: string;
|
|
971
|
+
secret?: string;
|
|
972
|
+
}): RPayWebhookVerificationResult;
|
|
973
|
+
verify(options: {
|
|
974
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
975
|
+
rawBody?: string | Uint8Array;
|
|
976
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
977
|
+
secret?: string;
|
|
978
|
+
signatureKey?: string;
|
|
979
|
+
}): RPayUnifiedWebhookEvent;
|
|
980
|
+
/** Plug-and-play Express.js / Connect route handler. */
|
|
981
|
+
expressHandler(
|
|
982
|
+
callbacks?: RPayWebhookHandlerCallbacks
|
|
983
|
+
): (req: any, res: any) => Promise<unknown>;
|
|
984
|
+
/** Plug-and-play Next.js App Router (`POST`) route handler. */
|
|
985
|
+
nextAppRouterHandler(
|
|
986
|
+
callbacks?: RPayWebhookHandlerCallbacks
|
|
987
|
+
): (request: Request) => Promise<Response>;
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
export declare const RPAY_DEFAULT_BASE_URL: "https://api.rpay.vn";
|
|
992
|
+
export declare const RPAY_DEFAULT_TIMEOUT_MS: 60000;
|
|
993
|
+
export declare const RPAY_BANKS: readonly RPayBankSpec[];
|
|
994
|
+
export declare const RPAY_USDT_NETWORKS: readonly RPayUsdtNetworkSpec[];
|
|
995
|
+
|
|
996
|
+
export declare function resolveBankSpec(rawIdentifier: string): RPayBankSpec | null;
|
|
997
|
+
export declare function resolveUsdtNetworkSpec(rawNetwork: string): RPayUsdtNetworkSpec | null;
|
|
998
|
+
export declare function normalizeBaseUrl(urlOrDomain?: string): string;
|
|
999
|
+
export declare function extractHostFromUrl(urlOrDomain?: string): string;
|
|
1000
|
+
export declare function encodeUrlSegment(segment: string): string;
|
|
1001
|
+
export declare function appendQueryParams(
|
|
1002
|
+
basePath: string,
|
|
1003
|
+
query?: Record<string, unknown>
|
|
1004
|
+
): string;
|
|
1005
|
+
export declare function detectPaymentChannel(
|
|
1006
|
+
inputOrCode: Record<string, unknown> | string,
|
|
1007
|
+
fallback?: RPayPaymentChannel
|
|
1008
|
+
): RPayPaymentChannel;
|
|
1009
|
+
export declare function normalizeInvoiceStatus(
|
|
1010
|
+
rawStatus?: string
|
|
1011
|
+
): "pending" | "paid" | "expired" | "cancelled";
|
|
1012
|
+
export declare function normalizeUnifiedInvoice(
|
|
1013
|
+
rawResponse: unknown,
|
|
1014
|
+
hintChannel?: RPayPaymentChannel
|
|
1015
|
+
): RPayUnifiedInvoiceDTO;
|
|
1016
|
+
export declare function normalizeUnifiedTransaction(
|
|
1017
|
+
rawTx: unknown,
|
|
1018
|
+
channel: RPayPaymentChannel,
|
|
1019
|
+
context?: { bankCode?: string; accountNumber?: string }
|
|
1020
|
+
): RPayUnifiedTransactionDTO;
|
|
1021
|
+
export declare function matchUnifiedTransactions(
|
|
1022
|
+
unifiedTransactions: RPayUnifiedTransactionDTO[],
|
|
1023
|
+
criteria?: RPayUnifiedMatchCriteria
|
|
1024
|
+
): RPayUnifiedTransactionDTO[];
|
|
1025
|
+
export declare function normalizeUnifiedWebhookEvent(
|
|
1026
|
+
verification: RPayWebhookVerificationResult
|
|
1027
|
+
): RPayUnifiedWebhookEvent;
|
|
1028
|
+
export declare function buildCanonicalPayloadString(
|
|
1029
|
+
payload: Record<string, unknown>
|
|
1030
|
+
): string;
|
|
1031
|
+
export declare function hmacSha256Hex(
|
|
1032
|
+
secret: string,
|
|
1033
|
+
message: string | Uint8Array
|
|
1034
|
+
): string;
|
|
1035
|
+
export declare function safeCompareSignature(
|
|
1036
|
+
expected: string,
|
|
1037
|
+
received: string
|
|
1038
|
+
): boolean;
|
|
1039
|
+
export declare function signCanonicalPayload(
|
|
1040
|
+
payload: Record<string, unknown>,
|
|
1041
|
+
secret: string
|
|
1042
|
+
): { signature: string; canonicalPayload: string };
|
|
1043
|
+
export declare function signRawBody(
|
|
1044
|
+
rawBody: string | Uint8Array,
|
|
1045
|
+
secret: string
|
|
1046
|
+
): string;
|
|
1047
|
+
export declare function normalizeHeaders(
|
|
1048
|
+
headers?: Record<string, string | string[] | undefined> | Headers
|
|
1049
|
+
): Record<string, string>;
|
|
1050
|
+
export declare function verifyBankInvoiceWebhook(options: {
|
|
1051
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
1052
|
+
rawBody?: string | Uint8Array;
|
|
1053
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
1054
|
+
secret: string;
|
|
1055
|
+
}): RPayWebhookVerificationResult;
|
|
1056
|
+
export declare function verifyUsdtWebhook(options: {
|
|
1057
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
1058
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
1059
|
+
secret: string;
|
|
1060
|
+
}): RPayWebhookVerificationResult;
|
|
1061
|
+
export declare function verifyTransactionWebhook(options: {
|
|
1062
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
1063
|
+
rawBody?: string | Uint8Array;
|
|
1064
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
1065
|
+
signatureKey: string;
|
|
1066
|
+
}): RPayWebhookVerificationResult;
|
|
1067
|
+
export declare function verifyAnyWebhook(options: {
|
|
1068
|
+
payload?: Record<string, unknown> | string | Uint8Array;
|
|
1069
|
+
rawBody?: string | Uint8Array;
|
|
1070
|
+
headers?: Record<string, string | string[] | undefined> | Headers;
|
|
1071
|
+
secret: string;
|
|
1072
|
+
}): RPayUnifiedWebhookEvent;
|
|
1073
|
+
export declare function normalizeTransferText(
|
|
1074
|
+
value: string,
|
|
1075
|
+
ignoreSeparators?: boolean
|
|
1076
|
+
): string;
|
|
1077
|
+
export declare function matchTransactions(
|
|
1078
|
+
transactions: RPayStandardBankTransaction[],
|
|
1079
|
+
criteria?: RPayTransactionMatchCriteria
|
|
1080
|
+
): RPayMatchedTransaction[];
|
|
1081
|
+
export declare function findMatchingTransaction(
|
|
1082
|
+
transactions: RPayStandardBankTransaction[],
|
|
1083
|
+
criteria?: RPayTransactionMatchCriteria
|
|
1084
|
+
): RPayMatchedTransaction | null;
|
|
1085
|
+
export declare function createRPayClient(config?: RPayClientConfig): RPayClient;
|
|
1086
|
+
|
|
1087
|
+
export type RPayDefaultInstance = RPayClient & {
|
|
1088
|
+
RPayClient: typeof RPayClient;
|
|
1089
|
+
RPayError: typeof RPayError;
|
|
1090
|
+
createClient: typeof createRPayClient;
|
|
1091
|
+
createRPayClient: typeof createRPayClient;
|
|
1092
|
+
RPAY_BANKS: readonly RPayBankSpec[];
|
|
1093
|
+
RPAY_USDT_NETWORKS: readonly RPayUsdtNetworkSpec[];
|
|
1094
|
+
resolveBankSpec: typeof resolveBankSpec;
|
|
1095
|
+
resolveUsdtNetworkSpec: typeof resolveUsdtNetworkSpec;
|
|
1096
|
+
detectPaymentChannel: typeof detectPaymentChannel;
|
|
1097
|
+
normalizeUnifiedInvoice: typeof normalizeUnifiedInvoice;
|
|
1098
|
+
normalizeUnifiedTransaction: typeof normalizeUnifiedTransaction;
|
|
1099
|
+
matchUnifiedTransactions: typeof matchUnifiedTransactions;
|
|
1100
|
+
normalizeUnifiedWebhookEvent: typeof normalizeUnifiedWebhookEvent;
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
export declare const rpay: RPayDefaultInstance;
|
|
1104
|
+
export default rpay;
|