@blazium/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +306 -0
- package/dist/index.d.mts +333 -0
- package/dist/index.d.ts +333 -0
- package/dist/index.js +530 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +503 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BlaziumPay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# @blazium/sdk
|
|
2
|
+
|
|
3
|
+
Official Node.js SDK for BlaziumPay - Production-ready crypto payment infrastructure.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 **Secure**: HMAC-SHA256 webhook verification with timing-safe comparison
|
|
8
|
+
- 💰 **Multi-Chain**: TON, Solana, Bitcoin support
|
|
9
|
+
- 🎯 **Reward Locking**: Lock rewards at payment creation (400 coins = exactly 400 coins)
|
|
10
|
+
- 🔄 **Idempotency**: Built-in duplicate payment prevention
|
|
11
|
+
- ⚡ **Real-time**: Long polling and webhook support
|
|
12
|
+
- 📊 **Balance Management**: Track earnings and withdrawals
|
|
13
|
+
- 🛡️ **Type-Safe**: Full TypeScript support with Zod validation
|
|
14
|
+
- 🚫 **No Database Required**: Works with any backend stack
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @blazium/sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { BlaziumPayClient } from '@blazium/sdk';
|
|
26
|
+
|
|
27
|
+
const client = new BlaziumPayClient({
|
|
28
|
+
apiKey: process.env.BLAZIUM_API_KEY,
|
|
29
|
+
webhookSecret: process.env.BLAZIUM_WEBHOOK_SECRET,
|
|
30
|
+
environment: 'production'
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Create payment with locked reward
|
|
34
|
+
const payment = await client.createPayment(
|
|
35
|
+
{
|
|
36
|
+
amount: 10.00,
|
|
37
|
+
currency: 'USD',
|
|
38
|
+
description: 'Premium Pack',
|
|
39
|
+
rewardAmount: 400,
|
|
40
|
+
rewardCurrency: 'coins'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
idempotencyKey: 'order_12345'
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
console.log('Checkout URL:', payment.checkoutUrl);
|
|
48
|
+
console.log('Reward (LOCKED):', payment.rewardAmount); // Always 400
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Core Concepts
|
|
52
|
+
|
|
53
|
+
### Reward Metadata (Developer Controlled)
|
|
54
|
+
|
|
55
|
+
The `rewardAmount` and `rewardCurrency` fields are **optional metadata** that you can use to track what you plan to give users.
|
|
56
|
+
**BlaziumPay does NOT automatically grant rewards** - you must implement your own logic in webhook handlers.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// Set reward metadata when creating payment
|
|
60
|
+
const payment = await client.createPayment({
|
|
61
|
+
amount: 3.00,
|
|
62
|
+
currency: 'USD',
|
|
63
|
+
rewardAmount: 1000, // Metadata: 1000 gold to grant
|
|
64
|
+
rewardCurrency: 'gold' // Metadata: Gold currency
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// The rewardAmount is stored in the payment object
|
|
68
|
+
// You must implement your own logic to grant rewards when payment confirms
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Payment Lifecycle
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
CREATE → PENDING → CONFIRMED → [Your Custom Logic]
|
|
75
|
+
↓
|
|
76
|
+
EXPIRED / FAILED / CANCELLED
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Important:** When a payment reaches `CONFIRMED` status, **you must implement your own webhook handler** to grant
|
|
80
|
+
premium features, add currency, unlock content, or perform any other actions. BlaziumPay handles payment processing;
|
|
81
|
+
you handle the business logic.
|
|
82
|
+
|
|
83
|
+
### Webhook Verification (Critical)
|
|
84
|
+
|
|
85
|
+
**Important:** Only verified webhooks receive events from BlaziumPay. You must verify your webhook endpoint in the dashboard before it will receive any events. Unverified webhooks will not receive any webhook events.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import express from 'express';
|
|
89
|
+
|
|
90
|
+
app.post('/webhooks/blazium', express.json({
|
|
91
|
+
verify: (req, res, buf) => {
|
|
92
|
+
req.rawBody = buf.toString('utf8');
|
|
93
|
+
}
|
|
94
|
+
}), async (req, res) => {
|
|
95
|
+
const signature = req.headers['x-blazium-signature'];
|
|
96
|
+
|
|
97
|
+
// CRITICAL: Verify signature
|
|
98
|
+
// Note: If webhookSecret is not configured, this will throw a ValidationError
|
|
99
|
+
// with a helpful message explaining that webhooks must be verified first
|
|
100
|
+
if (!client.verifyWebhookSignature(req.rawBody, signature)) {
|
|
101
|
+
return res.status(401).send('Invalid signature');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const webhook = client.parseWebhook(req.rawBody, signature);
|
|
105
|
+
|
|
106
|
+
if (webhook.event === 'payment.confirmed') {
|
|
107
|
+
const payment = webhook.payment;
|
|
108
|
+
const userId = payment.metadata.userId;
|
|
109
|
+
|
|
110
|
+
// YOUR CUSTOM LOGIC HERE - You decide what happens:
|
|
111
|
+
|
|
112
|
+
// Example: Grant premium features
|
|
113
|
+
if (payment.rewardCurrency === 'premium') {
|
|
114
|
+
await database.users.update(userId, { isPremium: true });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Example: Add in-game currency
|
|
118
|
+
if (payment.rewardCurrency === 'coins') {
|
|
119
|
+
await database.users.incrementCoins(userId, payment.rewardAmount);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// You have full control - implement whatever logic you need!
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
res.status(200).send({ received: true });
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Webhook Verification Process:**
|
|
130
|
+
1. Create a webhook endpoint in the dashboard
|
|
131
|
+
2. Verify the endpoint ownership (BlaziumPay will send a challenge token)
|
|
132
|
+
3. Save the webhook secret securely (shown only once after verification)
|
|
133
|
+
4. Configure the secret in your SDK client
|
|
134
|
+
5. Only verified webhooks receive events - unverified webhooks are ignored by BlaziumPay
|
|
135
|
+
|
|
136
|
+
## API Reference
|
|
137
|
+
|
|
138
|
+
### Initialize Client
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const client = new BlaziumPayClient({
|
|
142
|
+
apiKey: string, // Required: Your API key
|
|
143
|
+
webhookSecret?: string, // Optional: For webhook verification
|
|
144
|
+
baseUrl?: string, // Optional: Custom API URL
|
|
145
|
+
timeout?: number, // Optional: Request timeout (default: 15000ms)
|
|
146
|
+
environment?: 'production' | 'sandbox'
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Create Payment
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const payment = await client.createPayment(
|
|
154
|
+
{
|
|
155
|
+
amount: number, // Amount in fiat currency
|
|
156
|
+
currency: string, // USD, EUR, TRY, etc.
|
|
157
|
+
description?: string, // Payment description
|
|
158
|
+
metadata?: object, // Custom data
|
|
159
|
+
redirectUrl?: string, // Success redirect
|
|
160
|
+
cancelUrl?: string, // Cancel redirect
|
|
161
|
+
expiresIn?: number, // Expiration in seconds (60-86400)
|
|
162
|
+
rewardAmount?: number, // LOCKED reward amount
|
|
163
|
+
rewardCurrency?: string, // Reward currency
|
|
164
|
+
rewardData?: object // Additional reward data
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
idempotencyKey?: string // Prevent duplicates
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Get Payment
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const payment = await client.getPayment(paymentId);
|
|
176
|
+
|
|
177
|
+
console.log(payment.status); // PENDING, CONFIRMED, etc.
|
|
178
|
+
console.log(payment.rewardAmount); // Locked reward
|
|
179
|
+
console.log(payment.txHash); // Blockchain transaction
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Wait for Confirmation
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
try {
|
|
186
|
+
const confirmed = await client.waitForPayment(
|
|
187
|
+
paymentId,
|
|
188
|
+
300000, // 5 minutes timeout
|
|
189
|
+
3000 // Poll every 3 seconds
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
console.log('Payment confirmed!', confirmed.txHash);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error('Payment timeout or failed');
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Balance & Withdrawals
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// Check merchant balance
|
|
202
|
+
const balance = await client.getBalance('TON');
|
|
203
|
+
|
|
204
|
+
console.log('Total Earned:', balance.totalEarned);
|
|
205
|
+
console.log('Available:', balance.availableBalance);
|
|
206
|
+
console.log('Pending:', balance.pendingBalance);
|
|
207
|
+
|
|
208
|
+
// Request withdrawal
|
|
209
|
+
const withdrawal = await client.requestWithdrawal({
|
|
210
|
+
chain: 'TON',
|
|
211
|
+
amount: 10,
|
|
212
|
+
destinationAddress: 'YOUR_TON_ADDRESS'
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Webhook Verification
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// Verify signature (timing-safe)
|
|
220
|
+
const isValid = client.verifyWebhookSignature(rawBody, signature);
|
|
221
|
+
|
|
222
|
+
// Parse webhook
|
|
223
|
+
const webhook = client.parseWebhook(rawBody, signature);
|
|
224
|
+
|
|
225
|
+
console.log(webhook.event); // payment.confirmed, etc.
|
|
226
|
+
console.log(webhook.payment); // Full payment object
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Utility Methods
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
client.isPaid(payment); // true if CONFIRMED
|
|
233
|
+
client.isPartiallyPaid(payment); // true if underpaid
|
|
234
|
+
client.isExpired(payment); // true if expired
|
|
235
|
+
client.isFinal(payment); // true if no more updates
|
|
236
|
+
client.getPaymentProgress(payment); // % of amount paid
|
|
237
|
+
client.formatAmount(1.5, 'TON'); // "1.5000 TON"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Error Handling
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import {
|
|
244
|
+
BlaziumError,
|
|
245
|
+
AuthenticationError,
|
|
246
|
+
ValidationError,
|
|
247
|
+
NetworkError,
|
|
248
|
+
TimeoutError,
|
|
249
|
+
PaymentError
|
|
250
|
+
} from '@blazium/sdk';
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
const payment = await client.createPayment({ /* ... */ });
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (error instanceof AuthenticationError) {
|
|
256
|
+
console.error('Invalid API key');
|
|
257
|
+
} else if (error instanceof ValidationError) {
|
|
258
|
+
console.error('Invalid input:', error.details);
|
|
259
|
+
} else if (error instanceof NetworkError) {
|
|
260
|
+
console.error('Network error, retry...');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## TypeScript Support
|
|
266
|
+
|
|
267
|
+
Full TypeScript support with type definitions:
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import type {
|
|
271
|
+
Payment,
|
|
272
|
+
PaymentStatus,
|
|
273
|
+
CreatePaymentParams,
|
|
274
|
+
WebhookPayload,
|
|
275
|
+
MerchantBalance
|
|
276
|
+
} from '@blazium/sdk';
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Security Best Practices
|
|
280
|
+
|
|
281
|
+
1. **Never trust frontend signals** - Always verify payments server-side
|
|
282
|
+
2. **Verify webhook signatures** - Use `verifyWebhookSignature()` - CRITICAL for security
|
|
283
|
+
3. **Use idempotency keys** - Prevent duplicate payments
|
|
284
|
+
4. **Implement your own reward logic** - BlaziumPay does NOT automatically grant rewards. You must implement webhook handlers to grant premium features, add currency, or perform other actions
|
|
285
|
+
5. **Use rewardAmount as metadata** - Store what you promise users, but implement your own logic to grant it
|
|
286
|
+
6. **Store API keys securely** - Use environment variables
|
|
287
|
+
7. **Implement timeout handling** - Network issues happen
|
|
288
|
+
8. **Log webhook failures** - Monitor for issues
|
|
289
|
+
9. **Make webhook handlers idempotent** - Handle duplicate webhook deliveries gracefully
|
|
290
|
+
|
|
291
|
+
## Requirements
|
|
292
|
+
|
|
293
|
+
- Node.js >= 18
|
|
294
|
+
- No database required
|
|
295
|
+
- No Prisma required
|
|
296
|
+
- Works with any backend framework (Express, Fastify, NestJS, etc.)
|
|
297
|
+
|
|
298
|
+
## Support
|
|
299
|
+
|
|
300
|
+
- Documentation: https://docs.blaziumpay.com
|
|
301
|
+
- Issues: https://github.com/blaziumpay/sdk/issues
|
|
302
|
+
- Email: support@blaziumpay.com
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
MIT © BlaziumPay
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare enum BlaziumChain {
|
|
4
|
+
SOL = "SOL",
|
|
5
|
+
TON = "TON",
|
|
6
|
+
BTC = "BTC"
|
|
7
|
+
}
|
|
8
|
+
declare enum BlaziumFiat {
|
|
9
|
+
USD = "USD",
|
|
10
|
+
EUR = "EUR",
|
|
11
|
+
TRY = "TRY"
|
|
12
|
+
}
|
|
13
|
+
declare enum PaymentStatus {
|
|
14
|
+
CREATED = "CREATED",
|
|
15
|
+
PENDING = "PENDING",
|
|
16
|
+
PARTIALLY_PAID = "PARTIALLY_PAID",
|
|
17
|
+
CONFIRMED = "CONFIRMED",
|
|
18
|
+
FAILED = "FAILED",
|
|
19
|
+
EXPIRED = "EXPIRED",
|
|
20
|
+
CANCELLED = "CANCELLED"
|
|
21
|
+
}
|
|
22
|
+
declare enum BlaziumEnvironment {
|
|
23
|
+
PRODUCTION = "production",
|
|
24
|
+
SANDBOX = "sandbox"
|
|
25
|
+
}
|
|
26
|
+
declare enum WithdrawalStatus {
|
|
27
|
+
PENDING = "PENDING",
|
|
28
|
+
PROCESSING = "PROCESSING",
|
|
29
|
+
COMPLETED = "COMPLETED",
|
|
30
|
+
FAILED = "FAILED",
|
|
31
|
+
CANCELLED = "CANCELLED"
|
|
32
|
+
}
|
|
33
|
+
declare const BlaziumConfigSchema: z.ZodObject<{
|
|
34
|
+
apiKey: z.ZodString;
|
|
35
|
+
baseUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
36
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
37
|
+
environment: z.ZodDefault<z.ZodOptional<z.ZodNativeEnum<typeof BlaziumEnvironment>>>;
|
|
38
|
+
webhookSecret: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
apiKey: string;
|
|
41
|
+
baseUrl: string;
|
|
42
|
+
timeout: number;
|
|
43
|
+
environment: BlaziumEnvironment;
|
|
44
|
+
webhookSecret?: string | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
apiKey: string;
|
|
47
|
+
baseUrl?: string | undefined;
|
|
48
|
+
timeout?: number | undefined;
|
|
49
|
+
environment?: BlaziumEnvironment | undefined;
|
|
50
|
+
webhookSecret?: string | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
type BlaziumConfig = z.input<typeof BlaziumConfigSchema>;
|
|
53
|
+
type BlaziumConfigInternal = z.output<typeof BlaziumConfigSchema>;
|
|
54
|
+
interface Payment {
|
|
55
|
+
id: string;
|
|
56
|
+
status: PaymentStatus;
|
|
57
|
+
amount: number;
|
|
58
|
+
currency: string;
|
|
59
|
+
checkoutUrl: string;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
expiresAt: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
metadata?: Record<string, unknown>;
|
|
64
|
+
updatedAt?: string;
|
|
65
|
+
payCurrency?: BlaziumChain;
|
|
66
|
+
payAmount?: number;
|
|
67
|
+
payAddress?: string;
|
|
68
|
+
txHash?: string;
|
|
69
|
+
networkFee?: number;
|
|
70
|
+
blockHeight?: string;
|
|
71
|
+
confirmedAt?: string;
|
|
72
|
+
addressIndex?: number;
|
|
73
|
+
quotedRate?: number;
|
|
74
|
+
quoteExpiresAt?: string;
|
|
75
|
+
rewardAmount?: number;
|
|
76
|
+
rewardCurrency?: string;
|
|
77
|
+
rewardData?: Record<string, unknown>;
|
|
78
|
+
rewardDelivered?: boolean;
|
|
79
|
+
partialPayment?: {
|
|
80
|
+
amount: number;
|
|
81
|
+
txHash: string;
|
|
82
|
+
detectedAt: string;
|
|
83
|
+
expectedAmount: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
declare const CreatePaymentSchema: z.ZodObject<{
|
|
87
|
+
amount: z.ZodNumber;
|
|
88
|
+
currency: z.ZodString;
|
|
89
|
+
description: z.ZodOptional<z.ZodString>;
|
|
90
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
91
|
+
redirectUrl: z.ZodOptional<z.ZodString>;
|
|
92
|
+
cancelUrl: z.ZodOptional<z.ZodString>;
|
|
93
|
+
expiresIn: z.ZodOptional<z.ZodNumber>;
|
|
94
|
+
rewardAmount: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
rewardCurrency: z.ZodOptional<z.ZodString>;
|
|
96
|
+
rewardData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
amount: number;
|
|
99
|
+
currency: string;
|
|
100
|
+
description?: string | undefined;
|
|
101
|
+
metadata?: Record<string, unknown> | undefined;
|
|
102
|
+
redirectUrl?: string | undefined;
|
|
103
|
+
cancelUrl?: string | undefined;
|
|
104
|
+
expiresIn?: number | undefined;
|
|
105
|
+
rewardAmount?: number | undefined;
|
|
106
|
+
rewardCurrency?: string | undefined;
|
|
107
|
+
rewardData?: Record<string, unknown> | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
amount: number;
|
|
110
|
+
currency: string;
|
|
111
|
+
description?: string | undefined;
|
|
112
|
+
metadata?: Record<string, unknown> | undefined;
|
|
113
|
+
redirectUrl?: string | undefined;
|
|
114
|
+
cancelUrl?: string | undefined;
|
|
115
|
+
expiresIn?: number | undefined;
|
|
116
|
+
rewardAmount?: number | undefined;
|
|
117
|
+
rewardCurrency?: string | undefined;
|
|
118
|
+
rewardData?: Record<string, unknown> | undefined;
|
|
119
|
+
}>;
|
|
120
|
+
type CreatePaymentParams = z.infer<typeof CreatePaymentSchema>;
|
|
121
|
+
interface CreatePaymentOptions {
|
|
122
|
+
idempotencyKey?: string;
|
|
123
|
+
}
|
|
124
|
+
declare enum WebhookEventType {
|
|
125
|
+
PAYMENT_CREATED = "payment.created",
|
|
126
|
+
PAYMENT_PENDING = "payment.pending",
|
|
127
|
+
PAYMENT_CONFIRMED = "payment.confirmed",
|
|
128
|
+
PAYMENT_FAILED = "payment.failed",
|
|
129
|
+
PAYMENT_EXPIRED = "payment.expired",
|
|
130
|
+
PAYMENT_PARTIALLY_PAID = "payment.partially_paid"
|
|
131
|
+
}
|
|
132
|
+
interface WebhookPayload {
|
|
133
|
+
id: string;
|
|
134
|
+
webhook_id: string;
|
|
135
|
+
event: WebhookEventType;
|
|
136
|
+
payment_id: string;
|
|
137
|
+
payment: Payment;
|
|
138
|
+
timestamp: string;
|
|
139
|
+
createdAt: string;
|
|
140
|
+
}
|
|
141
|
+
interface PaymentStats {
|
|
142
|
+
total: number;
|
|
143
|
+
confirmed: number;
|
|
144
|
+
pending: number;
|
|
145
|
+
failed: number;
|
|
146
|
+
totalVolume: number;
|
|
147
|
+
currency: string;
|
|
148
|
+
}
|
|
149
|
+
interface PaginatedResponse<T> {
|
|
150
|
+
data: T[];
|
|
151
|
+
pagination: {
|
|
152
|
+
page: number;
|
|
153
|
+
pageSize: number;
|
|
154
|
+
totalPages: number;
|
|
155
|
+
totalItems: number;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
interface ListPaymentsParams {
|
|
159
|
+
status?: PaymentStatus;
|
|
160
|
+
currency?: string;
|
|
161
|
+
page?: number;
|
|
162
|
+
pageSize?: number;
|
|
163
|
+
startDate?: string;
|
|
164
|
+
endDate?: string;
|
|
165
|
+
}
|
|
166
|
+
interface MerchantBalance {
|
|
167
|
+
chain: string;
|
|
168
|
+
totalEarned: string;
|
|
169
|
+
availableBalance: string;
|
|
170
|
+
pendingBalance: string;
|
|
171
|
+
totalWithdrawn: string;
|
|
172
|
+
holdAmount: string;
|
|
173
|
+
settlementPeriodDays: number;
|
|
174
|
+
}
|
|
175
|
+
interface Withdrawal {
|
|
176
|
+
id: string;
|
|
177
|
+
status: WithdrawalStatus;
|
|
178
|
+
amount: string;
|
|
179
|
+
chain: string;
|
|
180
|
+
destinationAddress: string;
|
|
181
|
+
txHash?: string;
|
|
182
|
+
networkFee?: string;
|
|
183
|
+
finalAmount?: string;
|
|
184
|
+
errorMessage?: string;
|
|
185
|
+
requestedAt: string;
|
|
186
|
+
completedAt?: string;
|
|
187
|
+
}
|
|
188
|
+
interface WithdrawalRequest {
|
|
189
|
+
chain: string;
|
|
190
|
+
amount: number;
|
|
191
|
+
destinationAddress: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare class BlaziumError extends Error {
|
|
195
|
+
code: string;
|
|
196
|
+
details?: unknown;
|
|
197
|
+
constructor(message: string, code?: string, details?: unknown);
|
|
198
|
+
/**
|
|
199
|
+
* Convert error to JSON format
|
|
200
|
+
*/
|
|
201
|
+
toJSON(): {
|
|
202
|
+
name: string;
|
|
203
|
+
message: string;
|
|
204
|
+
code: string;
|
|
205
|
+
details: unknown;
|
|
206
|
+
stack: string | undefined;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
declare class AuthenticationError extends BlaziumError {
|
|
210
|
+
constructor(message?: string);
|
|
211
|
+
}
|
|
212
|
+
declare class ValidationError extends BlaziumError {
|
|
213
|
+
constructor(message: string, errors?: unknown);
|
|
214
|
+
}
|
|
215
|
+
declare class NetworkError extends BlaziumError {
|
|
216
|
+
constructor(message?: string);
|
|
217
|
+
}
|
|
218
|
+
declare class RateLimitError extends BlaziumError {
|
|
219
|
+
retryAfter?: number;
|
|
220
|
+
constructor(message?: string, retryAfter?: number);
|
|
221
|
+
}
|
|
222
|
+
declare class TimeoutError extends BlaziumError {
|
|
223
|
+
constructor(message?: string, code?: string);
|
|
224
|
+
}
|
|
225
|
+
declare class APIError extends BlaziumError {
|
|
226
|
+
statusCode: number;
|
|
227
|
+
constructor(message: string, statusCode: number, code?: string);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* ✅ NEW: Payment specific errors
|
|
231
|
+
*/
|
|
232
|
+
declare class PaymentError extends BlaziumError {
|
|
233
|
+
constructor(message: string, code?: string, details?: unknown);
|
|
234
|
+
}
|
|
235
|
+
declare class PaymentNotFoundError extends PaymentError {
|
|
236
|
+
constructor(paymentId: string);
|
|
237
|
+
}
|
|
238
|
+
declare class PaymentExpiredError extends PaymentError {
|
|
239
|
+
constructor(paymentId: string);
|
|
240
|
+
}
|
|
241
|
+
declare class InsufficientPaymentError extends PaymentError {
|
|
242
|
+
constructor(received: number, expected: number);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* ✅ NEW: Webhook specific errors
|
|
246
|
+
*/
|
|
247
|
+
declare class WebhookError extends BlaziumError {
|
|
248
|
+
constructor(message: string, code?: string, details?: unknown);
|
|
249
|
+
}
|
|
250
|
+
declare class InvalidSignatureError extends WebhookError {
|
|
251
|
+
constructor();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class BlaziumPayClient {
|
|
255
|
+
private client;
|
|
256
|
+
private config;
|
|
257
|
+
constructor(config: BlaziumConfig);
|
|
258
|
+
/**
|
|
259
|
+
* Create a new payment with idempotency support.
|
|
260
|
+
*
|
|
261
|
+
* Note: rewardAmount and rewardCurrency are optional metadata fields for developer reference.
|
|
262
|
+
* BlaziumPay does NOT automatically grant rewards - developers must implement their own
|
|
263
|
+
* logic in webhook handlers to grant premium features, add currency, or perform other actions.
|
|
264
|
+
*/
|
|
265
|
+
createPayment(params: CreatePaymentParams, options?: CreatePaymentOptions): Promise<Payment>;
|
|
266
|
+
/**
|
|
267
|
+
* Get payment details
|
|
268
|
+
*/
|
|
269
|
+
getPayment(paymentId: string): Promise<Payment>;
|
|
270
|
+
/**
|
|
271
|
+
* List payments with filters
|
|
272
|
+
*/
|
|
273
|
+
listPayments(params?: ListPaymentsParams): Promise<PaginatedResponse<Payment>>;
|
|
274
|
+
/**
|
|
275
|
+
* Cancel a payment
|
|
276
|
+
*/
|
|
277
|
+
cancelPayment(paymentId: string): Promise<Payment>;
|
|
278
|
+
/**
|
|
279
|
+
* Get payment statistics
|
|
280
|
+
*/
|
|
281
|
+
getStats(): Promise<PaymentStats>;
|
|
282
|
+
/**
|
|
283
|
+
* Get merchant balance for a specific chain
|
|
284
|
+
*/
|
|
285
|
+
getBalance(chain: string): Promise<MerchantBalance>;
|
|
286
|
+
/**
|
|
287
|
+
* Request withdrawal
|
|
288
|
+
*/
|
|
289
|
+
requestWithdrawal(request: WithdrawalRequest): Promise<Withdrawal>;
|
|
290
|
+
/**
|
|
291
|
+
* List withdrawal history
|
|
292
|
+
*/
|
|
293
|
+
listWithdrawals(): Promise<Withdrawal[]>;
|
|
294
|
+
/**
|
|
295
|
+
* Get specific withdrawal status
|
|
296
|
+
*/
|
|
297
|
+
getWithdrawal(withdrawalId: string): Promise<Withdrawal>;
|
|
298
|
+
/**
|
|
299
|
+
* Wait for a payment to be confirmed (Long Polling helper)
|
|
300
|
+
*/
|
|
301
|
+
waitForPayment(paymentId: string, timeoutMs?: number, pollIntervalMs?: number): Promise<Payment>;
|
|
302
|
+
/**
|
|
303
|
+
* Verify webhook signature
|
|
304
|
+
*
|
|
305
|
+
* Note: Only verified webhooks receive events. Unverified webhooks will not receive
|
|
306
|
+
* any webhook events from BlaziumPay. You must verify your webhook endpoint in the
|
|
307
|
+
* dashboard before it will receive events and require signature verification.
|
|
308
|
+
*/
|
|
309
|
+
verifyWebhookSignature(payload: string, signature: string): boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Parse and verify webhook payload
|
|
312
|
+
*
|
|
313
|
+
* @param rawPayload - Raw JSON string of webhook payload
|
|
314
|
+
* @param signature - Signature from HTTP header 'X-Blazium-Signature'
|
|
315
|
+
* @returns Parsed and verified webhook payload
|
|
316
|
+
*
|
|
317
|
+
* Note: Signature is verified from HTTP header, not from payload.
|
|
318
|
+
* Only verified webhooks receive events. Unverified webhooks will not receive
|
|
319
|
+
* any webhook events from BlaziumPay.
|
|
320
|
+
*/
|
|
321
|
+
parseWebhook(rawPayload: string, signature: string): WebhookPayload;
|
|
322
|
+
private normalizePayment;
|
|
323
|
+
private sleep;
|
|
324
|
+
private isFinalStatus;
|
|
325
|
+
isFinal(payment: Payment): boolean;
|
|
326
|
+
isPaid(payment: Payment): boolean;
|
|
327
|
+
isPartiallyPaid(payment: Payment): boolean;
|
|
328
|
+
isExpired(payment: Payment): boolean;
|
|
329
|
+
getPaymentProgress(payment: Payment): number;
|
|
330
|
+
formatAmount(amount: number, currency: string): string;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export { APIError, AuthenticationError, BlaziumChain, type BlaziumConfig, type BlaziumConfigInternal, BlaziumConfigSchema, BlaziumEnvironment, BlaziumError, BlaziumFiat, BlaziumPayClient, type CreatePaymentOptions, type CreatePaymentParams, CreatePaymentSchema, InsufficientPaymentError, InvalidSignatureError, type ListPaymentsParams, type MerchantBalance, NetworkError, type PaginatedResponse, type Payment, PaymentError, PaymentExpiredError, PaymentNotFoundError, type PaymentStats, PaymentStatus, RateLimitError, TimeoutError, ValidationError, WebhookError, WebhookEventType, type WebhookPayload, type Withdrawal, type WithdrawalRequest, WithdrawalStatus };
|