@zendfi/sdk 0.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 +389 -0
- package/dist/index.d.mts +611 -0
- package/dist/index.d.ts +611 -0
- package/dist/index.js +680 -0
- package/dist/index.mjs +640 -0
- package/package.json +53 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZendFi SDK Types
|
|
3
|
+
* Complete type definitions for the ZendFi API
|
|
4
|
+
*/
|
|
5
|
+
type Environment = 'development' | 'staging' | 'production';
|
|
6
|
+
type Currency = 'USD' | 'EUR' | 'GBP';
|
|
7
|
+
type PaymentToken = 'SOL' | 'USDC' | 'USDT';
|
|
8
|
+
type PaymentStatus = 'pending' | 'confirmed' | 'failed' | 'expired';
|
|
9
|
+
type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'paused';
|
|
10
|
+
type InstallmentPlanStatus = 'active' | 'completed' | 'defaulted' | 'cancelled';
|
|
11
|
+
type EscrowStatus = 'pending' | 'funded' | 'released' | 'refunded' | 'disputed' | 'cancelled';
|
|
12
|
+
type InvoiceStatus = 'draft' | 'sent' | 'paid';
|
|
13
|
+
type SplitStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'refunded';
|
|
14
|
+
type WebhookEvent = 'payment.created' | 'payment.confirmed' | 'payment.failed' | 'payment.expired' | 'subscription.created' | 'subscription.activated' | 'subscription.canceled' | 'subscription.payment_failed' | 'split.completed' | 'split.failed' | 'installment.due' | 'installment.paid' | 'installment.late' | 'escrow.funded' | 'escrow.released' | 'escrow.refunded' | 'escrow.disputed' | 'invoice.sent' | 'invoice.paid';
|
|
15
|
+
interface ZendFiConfig {
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
environment?: Environment;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
retries?: number;
|
|
21
|
+
idempotencyEnabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface SplitRecipient {
|
|
24
|
+
recipient_wallet: string;
|
|
25
|
+
recipient_name?: string;
|
|
26
|
+
percentage?: number;
|
|
27
|
+
fixed_amount_usd?: number;
|
|
28
|
+
split_order?: number;
|
|
29
|
+
}
|
|
30
|
+
interface CreatePaymentRequest {
|
|
31
|
+
amount: number;
|
|
32
|
+
currency?: Currency;
|
|
33
|
+
token?: PaymentToken;
|
|
34
|
+
description?: string;
|
|
35
|
+
customer_email?: string;
|
|
36
|
+
redirect_url?: string;
|
|
37
|
+
metadata?: Record<string, any>;
|
|
38
|
+
split_recipients?: SplitRecipient[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Payment Link - Shareable checkout links
|
|
42
|
+
*/
|
|
43
|
+
interface CreatePaymentLinkRequest {
|
|
44
|
+
amount: number;
|
|
45
|
+
currency?: string;
|
|
46
|
+
token?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
max_uses?: number;
|
|
49
|
+
expires_at?: string;
|
|
50
|
+
metadata?: Record<string, any>;
|
|
51
|
+
}
|
|
52
|
+
interface PaymentLink {
|
|
53
|
+
id: string;
|
|
54
|
+
link_code: string;
|
|
55
|
+
payment_url: string;
|
|
56
|
+
hosted_page_url: string;
|
|
57
|
+
amount: number;
|
|
58
|
+
currency: string;
|
|
59
|
+
token: string;
|
|
60
|
+
max_uses?: number;
|
|
61
|
+
uses_count: number;
|
|
62
|
+
expires_at?: string;
|
|
63
|
+
is_active: boolean;
|
|
64
|
+
created_at: string;
|
|
65
|
+
url: string;
|
|
66
|
+
}
|
|
67
|
+
interface Payment {
|
|
68
|
+
id: string;
|
|
69
|
+
merchant_id: string;
|
|
70
|
+
amount_usd?: number;
|
|
71
|
+
amount?: number;
|
|
72
|
+
currency?: string;
|
|
73
|
+
payment_token?: PaymentToken;
|
|
74
|
+
status: PaymentStatus;
|
|
75
|
+
customer_wallet?: string;
|
|
76
|
+
customer_email?: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
checkout_url?: string;
|
|
79
|
+
payment_url?: string;
|
|
80
|
+
qr_code?: string;
|
|
81
|
+
expires_at: string;
|
|
82
|
+
confirmed_at?: string;
|
|
83
|
+
transaction_signature?: string;
|
|
84
|
+
metadata?: Record<string, any>;
|
|
85
|
+
split_ids?: string[];
|
|
86
|
+
created_at?: string;
|
|
87
|
+
updated_at?: string;
|
|
88
|
+
}
|
|
89
|
+
interface ListPaymentsRequest {
|
|
90
|
+
page?: number;
|
|
91
|
+
limit?: number;
|
|
92
|
+
status?: PaymentStatus;
|
|
93
|
+
from_date?: string;
|
|
94
|
+
to_date?: string;
|
|
95
|
+
}
|
|
96
|
+
interface PaginatedResponse<T> {
|
|
97
|
+
data: T[];
|
|
98
|
+
pagination: {
|
|
99
|
+
page: number;
|
|
100
|
+
limit: number;
|
|
101
|
+
total: number;
|
|
102
|
+
total_pages: number;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
interface CreateSubscriptionPlanRequest {
|
|
106
|
+
name: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
amount: number;
|
|
109
|
+
currency?: Currency;
|
|
110
|
+
interval: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
111
|
+
interval_count?: number;
|
|
112
|
+
trial_days?: number;
|
|
113
|
+
metadata?: Record<string, any>;
|
|
114
|
+
}
|
|
115
|
+
interface SubscriptionPlan {
|
|
116
|
+
id: string;
|
|
117
|
+
merchant_id: string;
|
|
118
|
+
name: string;
|
|
119
|
+
description?: string;
|
|
120
|
+
amount: number;
|
|
121
|
+
currency: Currency;
|
|
122
|
+
interval: string;
|
|
123
|
+
interval_count: number;
|
|
124
|
+
trial_days: number;
|
|
125
|
+
is_active: boolean;
|
|
126
|
+
metadata?: Record<string, any>;
|
|
127
|
+
created_at: string;
|
|
128
|
+
updated_at: string;
|
|
129
|
+
}
|
|
130
|
+
interface CreateSubscriptionRequest {
|
|
131
|
+
plan_id: string;
|
|
132
|
+
customer_email: string;
|
|
133
|
+
customer_wallet?: string;
|
|
134
|
+
metadata?: Record<string, any>;
|
|
135
|
+
}
|
|
136
|
+
interface Subscription {
|
|
137
|
+
id: string;
|
|
138
|
+
plan_id: string;
|
|
139
|
+
merchant_id: string;
|
|
140
|
+
customer_email: string;
|
|
141
|
+
customer_wallet?: string;
|
|
142
|
+
status: SubscriptionStatus;
|
|
143
|
+
current_period_start: string;
|
|
144
|
+
current_period_end: string;
|
|
145
|
+
trial_end?: string;
|
|
146
|
+
canceled_at?: string;
|
|
147
|
+
metadata?: Record<string, any>;
|
|
148
|
+
created_at: string;
|
|
149
|
+
updated_at: string;
|
|
150
|
+
}
|
|
151
|
+
interface WebhookPayload {
|
|
152
|
+
event: WebhookEvent;
|
|
153
|
+
timestamp: string;
|
|
154
|
+
merchant_id: string;
|
|
155
|
+
data: Payment | Subscription;
|
|
156
|
+
}
|
|
157
|
+
interface VerifyWebhookRequest {
|
|
158
|
+
payload: string;
|
|
159
|
+
signature: string;
|
|
160
|
+
secret: string;
|
|
161
|
+
}
|
|
162
|
+
declare class ZendFiError extends Error {
|
|
163
|
+
statusCode?: number | undefined;
|
|
164
|
+
code?: string | undefined;
|
|
165
|
+
details?: any | undefined;
|
|
166
|
+
constructor(message: string, statusCode?: number | undefined, code?: string | undefined, details?: any | undefined);
|
|
167
|
+
}
|
|
168
|
+
declare class AuthenticationError extends ZendFiError {
|
|
169
|
+
constructor(message?: string);
|
|
170
|
+
}
|
|
171
|
+
declare class ValidationError extends ZendFiError {
|
|
172
|
+
constructor(message: string, details?: any);
|
|
173
|
+
}
|
|
174
|
+
declare class NetworkError extends ZendFiError {
|
|
175
|
+
constructor(message: string);
|
|
176
|
+
}
|
|
177
|
+
declare class RateLimitError extends ZendFiError {
|
|
178
|
+
constructor(message?: string);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Installment Plans - Pay over time
|
|
182
|
+
*/
|
|
183
|
+
interface InstallmentScheduleItem {
|
|
184
|
+
installment_number: number;
|
|
185
|
+
due_date: string;
|
|
186
|
+
amount: string;
|
|
187
|
+
status: string;
|
|
188
|
+
payment_id?: string;
|
|
189
|
+
paid_at?: string;
|
|
190
|
+
}
|
|
191
|
+
interface CreateInstallmentPlanRequest {
|
|
192
|
+
customer_wallet: string;
|
|
193
|
+
customer_email?: string;
|
|
194
|
+
total_amount: number;
|
|
195
|
+
installment_count: number;
|
|
196
|
+
first_payment_date?: string;
|
|
197
|
+
payment_frequency_days: number;
|
|
198
|
+
description?: string;
|
|
199
|
+
late_fee_amount?: number;
|
|
200
|
+
grace_period_days?: number;
|
|
201
|
+
metadata?: Record<string, any>;
|
|
202
|
+
}
|
|
203
|
+
interface CreateInstallmentPlanResponse {
|
|
204
|
+
plan_id: string;
|
|
205
|
+
status: string;
|
|
206
|
+
}
|
|
207
|
+
interface InstallmentPlan {
|
|
208
|
+
id?: string;
|
|
209
|
+
plan_id?: string;
|
|
210
|
+
merchant_id?: string;
|
|
211
|
+
customer_wallet?: string;
|
|
212
|
+
customer_email?: string;
|
|
213
|
+
total_amount?: string;
|
|
214
|
+
installment_count?: number;
|
|
215
|
+
amount_per_installment?: string;
|
|
216
|
+
payment_schedule?: InstallmentScheduleItem[];
|
|
217
|
+
paid_count?: number;
|
|
218
|
+
status: InstallmentPlanStatus | string;
|
|
219
|
+
description?: string;
|
|
220
|
+
late_fee_amount?: string;
|
|
221
|
+
grace_period_days?: number;
|
|
222
|
+
metadata?: Record<string, any>;
|
|
223
|
+
created_at?: string;
|
|
224
|
+
updated_at?: string;
|
|
225
|
+
completed_at?: string;
|
|
226
|
+
defaulted_at?: string;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Escrow - Secure fund holding
|
|
230
|
+
*/
|
|
231
|
+
interface ReleaseCondition {
|
|
232
|
+
type: 'manual_approval' | 'time_based' | 'confirmation_required' | 'milestone';
|
|
233
|
+
approver?: string;
|
|
234
|
+
approved?: boolean;
|
|
235
|
+
release_after?: string;
|
|
236
|
+
confirmations_needed?: number;
|
|
237
|
+
confirmed_by?: string[];
|
|
238
|
+
description?: string;
|
|
239
|
+
approved_by?: string;
|
|
240
|
+
}
|
|
241
|
+
interface CreateEscrowRequest {
|
|
242
|
+
buyer_wallet: string;
|
|
243
|
+
seller_wallet: string;
|
|
244
|
+
amount: number;
|
|
245
|
+
currency?: Currency;
|
|
246
|
+
token?: PaymentToken;
|
|
247
|
+
description?: string;
|
|
248
|
+
release_conditions: ReleaseCondition;
|
|
249
|
+
metadata?: Record<string, any>;
|
|
250
|
+
}
|
|
251
|
+
interface Escrow {
|
|
252
|
+
id: string;
|
|
253
|
+
payment_id: string;
|
|
254
|
+
merchant_id: string;
|
|
255
|
+
buyer_wallet: string;
|
|
256
|
+
seller_wallet: string;
|
|
257
|
+
escrow_wallet: string;
|
|
258
|
+
amount: number;
|
|
259
|
+
currency: Currency;
|
|
260
|
+
token: PaymentToken;
|
|
261
|
+
release_conditions: ReleaseCondition;
|
|
262
|
+
status: EscrowStatus;
|
|
263
|
+
payment_url?: string;
|
|
264
|
+
qr_code?: string;
|
|
265
|
+
funded_at?: string;
|
|
266
|
+
released_at?: string;
|
|
267
|
+
refunded_at?: string;
|
|
268
|
+
disputed_at?: string;
|
|
269
|
+
dispute_reason?: string;
|
|
270
|
+
release_transaction_signature?: string;
|
|
271
|
+
refund_transaction_signature?: string;
|
|
272
|
+
metadata?: Record<string, any>;
|
|
273
|
+
created_at: string;
|
|
274
|
+
updated_at: string;
|
|
275
|
+
}
|
|
276
|
+
interface ApproveEscrowRequest {
|
|
277
|
+
approver_wallet: string;
|
|
278
|
+
}
|
|
279
|
+
interface RefundEscrowRequest {
|
|
280
|
+
reason: string;
|
|
281
|
+
}
|
|
282
|
+
interface DisputeEscrowRequest {
|
|
283
|
+
reason: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Invoices - Professional billing
|
|
287
|
+
*/
|
|
288
|
+
interface InvoiceLineItem {
|
|
289
|
+
description: string;
|
|
290
|
+
quantity: number;
|
|
291
|
+
unit_price: number;
|
|
292
|
+
}
|
|
293
|
+
interface CreateInvoiceRequest {
|
|
294
|
+
customer_email: string;
|
|
295
|
+
customer_name?: string;
|
|
296
|
+
amount: number;
|
|
297
|
+
token?: PaymentToken;
|
|
298
|
+
description: string;
|
|
299
|
+
line_items?: InvoiceLineItem[];
|
|
300
|
+
due_date?: string;
|
|
301
|
+
metadata?: Record<string, any>;
|
|
302
|
+
}
|
|
303
|
+
interface Invoice {
|
|
304
|
+
id: string;
|
|
305
|
+
invoice_number: string;
|
|
306
|
+
merchant_id: string;
|
|
307
|
+
customer_email: string;
|
|
308
|
+
customer_name?: string;
|
|
309
|
+
amount_usd: number;
|
|
310
|
+
token: PaymentToken;
|
|
311
|
+
description: string;
|
|
312
|
+
line_items?: InvoiceLineItem[];
|
|
313
|
+
status: InvoiceStatus;
|
|
314
|
+
payment_url?: string;
|
|
315
|
+
due_date?: string;
|
|
316
|
+
sent_at?: string;
|
|
317
|
+
paid_at?: string;
|
|
318
|
+
metadata?: Record<string, any>;
|
|
319
|
+
created_at: string;
|
|
320
|
+
updated_at: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* ZendFi SDK Client
|
|
325
|
+
* Zero-config TypeScript SDK for crypto payments
|
|
326
|
+
*/
|
|
327
|
+
declare class ZendFiClient {
|
|
328
|
+
private config;
|
|
329
|
+
constructor(options?: Partial<ZendFiConfig>);
|
|
330
|
+
/**
|
|
331
|
+
* Create a new payment
|
|
332
|
+
*/
|
|
333
|
+
createPayment(request: CreatePaymentRequest): Promise<Payment>;
|
|
334
|
+
/**
|
|
335
|
+
* Get payment by ID
|
|
336
|
+
*/
|
|
337
|
+
getPayment(paymentId: string): Promise<Payment>;
|
|
338
|
+
/**
|
|
339
|
+
* List all payments with pagination
|
|
340
|
+
*/
|
|
341
|
+
listPayments(request?: ListPaymentsRequest): Promise<PaginatedResponse<Payment>>;
|
|
342
|
+
/**
|
|
343
|
+
* Create a subscription plan
|
|
344
|
+
*/
|
|
345
|
+
createSubscriptionPlan(request: CreateSubscriptionPlanRequest): Promise<SubscriptionPlan>;
|
|
346
|
+
/**
|
|
347
|
+
* Get subscription plan by ID
|
|
348
|
+
*/
|
|
349
|
+
getSubscriptionPlan(planId: string): Promise<SubscriptionPlan>;
|
|
350
|
+
/**
|
|
351
|
+
* Create a subscription
|
|
352
|
+
*/
|
|
353
|
+
createSubscription(request: CreateSubscriptionRequest): Promise<Subscription>;
|
|
354
|
+
/**
|
|
355
|
+
* Get subscription by ID
|
|
356
|
+
*/
|
|
357
|
+
getSubscription(subscriptionId: string): Promise<Subscription>;
|
|
358
|
+
/**
|
|
359
|
+
* Cancel a subscription
|
|
360
|
+
*/
|
|
361
|
+
cancelSubscription(subscriptionId: string): Promise<Subscription>;
|
|
362
|
+
/**
|
|
363
|
+
* Create a payment link (shareable checkout URL)
|
|
364
|
+
*/
|
|
365
|
+
createPaymentLink(request: CreatePaymentLinkRequest): Promise<PaymentLink>;
|
|
366
|
+
/**
|
|
367
|
+
* Get payment link by link code
|
|
368
|
+
*/
|
|
369
|
+
getPaymentLink(linkCode: string): Promise<PaymentLink>;
|
|
370
|
+
/**
|
|
371
|
+
* List all payment links
|
|
372
|
+
*/
|
|
373
|
+
listPaymentLinks(): Promise<PaymentLink[]>;
|
|
374
|
+
/**
|
|
375
|
+
* Create an installment plan
|
|
376
|
+
* Split a purchase into multiple scheduled payments
|
|
377
|
+
*/
|
|
378
|
+
createInstallmentPlan(request: CreateInstallmentPlanRequest): Promise<InstallmentPlan>;
|
|
379
|
+
/**
|
|
380
|
+
* Get installment plan by ID
|
|
381
|
+
*/
|
|
382
|
+
getInstallmentPlan(planId: string): Promise<InstallmentPlan>;
|
|
383
|
+
/**
|
|
384
|
+
* List all installment plans for merchant
|
|
385
|
+
*/
|
|
386
|
+
listInstallmentPlans(params?: {
|
|
387
|
+
limit?: number;
|
|
388
|
+
offset?: number;
|
|
389
|
+
}): Promise<InstallmentPlan[]>;
|
|
390
|
+
/**
|
|
391
|
+
* List installment plans for a specific customer
|
|
392
|
+
*/
|
|
393
|
+
listCustomerInstallmentPlans(customerWallet: string): Promise<InstallmentPlan[]>;
|
|
394
|
+
/**
|
|
395
|
+
* Cancel an installment plan
|
|
396
|
+
*/
|
|
397
|
+
cancelInstallmentPlan(planId: string): Promise<{
|
|
398
|
+
message: string;
|
|
399
|
+
plan_id: string;
|
|
400
|
+
}>;
|
|
401
|
+
/**
|
|
402
|
+
* Create an escrow transaction
|
|
403
|
+
* Hold funds until conditions are met
|
|
404
|
+
*/
|
|
405
|
+
createEscrow(request: CreateEscrowRequest): Promise<Escrow>;
|
|
406
|
+
/**
|
|
407
|
+
* Get escrow by ID
|
|
408
|
+
*/
|
|
409
|
+
getEscrow(escrowId: string): Promise<Escrow>;
|
|
410
|
+
/**
|
|
411
|
+
* List all escrows for merchant
|
|
412
|
+
*/
|
|
413
|
+
listEscrows(params?: {
|
|
414
|
+
limit?: number;
|
|
415
|
+
offset?: number;
|
|
416
|
+
}): Promise<Escrow[]>;
|
|
417
|
+
/**
|
|
418
|
+
* Approve escrow release to seller
|
|
419
|
+
*/
|
|
420
|
+
approveEscrow(escrowId: string, request: ApproveEscrowRequest): Promise<{
|
|
421
|
+
status: string;
|
|
422
|
+
transaction_signature?: string;
|
|
423
|
+
message: string;
|
|
424
|
+
}>;
|
|
425
|
+
/**
|
|
426
|
+
* Refund escrow to buyer
|
|
427
|
+
*/
|
|
428
|
+
refundEscrow(escrowId: string, request: RefundEscrowRequest): Promise<{
|
|
429
|
+
status: string;
|
|
430
|
+
transaction_signature: string;
|
|
431
|
+
message: string;
|
|
432
|
+
reason: string;
|
|
433
|
+
}>;
|
|
434
|
+
/**
|
|
435
|
+
* Raise a dispute for an escrow
|
|
436
|
+
*/
|
|
437
|
+
disputeEscrow(escrowId: string, request: DisputeEscrowRequest): Promise<{
|
|
438
|
+
status: string;
|
|
439
|
+
message: string;
|
|
440
|
+
dispute_id: string;
|
|
441
|
+
created_at: string;
|
|
442
|
+
}>;
|
|
443
|
+
/**
|
|
444
|
+
* Create an invoice
|
|
445
|
+
*/
|
|
446
|
+
createInvoice(request: CreateInvoiceRequest): Promise<Invoice>;
|
|
447
|
+
/**
|
|
448
|
+
* Get invoice by ID
|
|
449
|
+
*/
|
|
450
|
+
getInvoice(invoiceId: string): Promise<Invoice>;
|
|
451
|
+
/**
|
|
452
|
+
* List all invoices for merchant
|
|
453
|
+
*/
|
|
454
|
+
listInvoices(): Promise<Invoice[]>;
|
|
455
|
+
/**
|
|
456
|
+
* Send invoice to customer via email
|
|
457
|
+
*/
|
|
458
|
+
sendInvoice(invoiceId: string): Promise<{
|
|
459
|
+
success: boolean;
|
|
460
|
+
invoice_id: string;
|
|
461
|
+
invoice_number: string;
|
|
462
|
+
sent_to: string;
|
|
463
|
+
payment_url: string;
|
|
464
|
+
status: string;
|
|
465
|
+
}>;
|
|
466
|
+
/**
|
|
467
|
+
* Verify webhook signature using HMAC-SHA256
|
|
468
|
+
*
|
|
469
|
+
* @param request - Webhook verification request containing payload, signature, and secret
|
|
470
|
+
* @returns true if signature is valid, false otherwise
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* ```typescript
|
|
474
|
+
* const isValid = zendfi.verifyWebhook({
|
|
475
|
+
* payload: req.body,
|
|
476
|
+
* signature: req.headers['x-zendfi-signature'],
|
|
477
|
+
* secret: process.env.ZENDFI_WEBHOOK_SECRET
|
|
478
|
+
* });
|
|
479
|
+
*
|
|
480
|
+
* if (!isValid) {
|
|
481
|
+
* return res.status(401).json({ error: 'Invalid signature' });
|
|
482
|
+
* }
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
verifyWebhook(request: VerifyWebhookRequest): boolean;
|
|
486
|
+
/**
|
|
487
|
+
* Compute HMAC-SHA256 signature
|
|
488
|
+
* Works in both Node.js and browser environments
|
|
489
|
+
*/
|
|
490
|
+
private computeHmacSignature;
|
|
491
|
+
/**
|
|
492
|
+
* Timing-safe string comparison to prevent timing attacks
|
|
493
|
+
*/
|
|
494
|
+
private timingSafeEqual;
|
|
495
|
+
/**
|
|
496
|
+
* Make an HTTP request with retry logic
|
|
497
|
+
*/
|
|
498
|
+
private request;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Default singleton instance
|
|
502
|
+
* Auto-configured from environment
|
|
503
|
+
*
|
|
504
|
+
* Note: This will throw if ZENDFI_API_KEY is not set.
|
|
505
|
+
* For custom configuration, create your own instance:
|
|
506
|
+
* const client = new ZendFiClient({ apiKey: '...' })
|
|
507
|
+
*/
|
|
508
|
+
declare const zendfi: ZendFiClient;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Configuration loader and environment detector
|
|
512
|
+
*/
|
|
513
|
+
declare class ConfigLoader {
|
|
514
|
+
/**
|
|
515
|
+
* Load configuration from various sources
|
|
516
|
+
*/
|
|
517
|
+
static load(options?: Partial<ZendFiConfig>): Required<ZendFiConfig>;
|
|
518
|
+
/**
|
|
519
|
+
* Detect environment based on various signals
|
|
520
|
+
*/
|
|
521
|
+
private static detectEnvironment;
|
|
522
|
+
/**
|
|
523
|
+
* Load API key from various sources
|
|
524
|
+
*/
|
|
525
|
+
private static loadApiKey;
|
|
526
|
+
/**
|
|
527
|
+
* Get base URL for API
|
|
528
|
+
*/
|
|
529
|
+
private static getBaseURL;
|
|
530
|
+
/**
|
|
531
|
+
* Load credentials from CLI config file (~/.zendfi/credentials.json)
|
|
532
|
+
*/
|
|
533
|
+
private static loadCLICredentials;
|
|
534
|
+
/**
|
|
535
|
+
* Validate API key format
|
|
536
|
+
*/
|
|
537
|
+
static validateApiKey(apiKey: string): void;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Webhook Verification Helpers
|
|
542
|
+
* Convenience functions for common frameworks
|
|
543
|
+
*/
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Verify and parse webhook for Next.js API routes
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```typescript
|
|
550
|
+
* // app/api/webhooks/zendfi/route.ts
|
|
551
|
+
* import { verifyNextWebhook } from '@zendfi/sdk/webhooks';
|
|
552
|
+
*
|
|
553
|
+
* export async function POST(request: Request) {
|
|
554
|
+
* const webhook = await verifyNextWebhook(request);
|
|
555
|
+
*
|
|
556
|
+
* if (!webhook) {
|
|
557
|
+
* return new Response('Invalid signature', { status: 401 });
|
|
558
|
+
* }
|
|
559
|
+
*
|
|
560
|
+
* // Process webhook
|
|
561
|
+
* switch (webhook.event) {
|
|
562
|
+
* case 'payment.confirmed':
|
|
563
|
+
* // Handle payment
|
|
564
|
+
* break;
|
|
565
|
+
* }
|
|
566
|
+
*
|
|
567
|
+
* return new Response('OK');
|
|
568
|
+
* }
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
declare function verifyNextWebhook(request: Request, secret?: string): Promise<WebhookPayload | null>;
|
|
572
|
+
/**
|
|
573
|
+
* Verify and parse webhook for Express.js
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```typescript
|
|
577
|
+
* import { verifyExpressWebhook } from '@zendfi/sdk/webhooks';
|
|
578
|
+
*
|
|
579
|
+
* app.post('/webhooks/zendfi', async (req, res) => {
|
|
580
|
+
* const webhook = await verifyExpressWebhook(req);
|
|
581
|
+
*
|
|
582
|
+
* if (!webhook) {
|
|
583
|
+
* return res.status(401).json({ error: 'Invalid signature' });
|
|
584
|
+
* }
|
|
585
|
+
*
|
|
586
|
+
* // Process webhook
|
|
587
|
+
* console.log('Event:', webhook.event);
|
|
588
|
+
*
|
|
589
|
+
* res.json({ received: true });
|
|
590
|
+
* });
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
declare function verifyExpressWebhook(request: any, secret?: string): Promise<WebhookPayload | null>;
|
|
594
|
+
/**
|
|
595
|
+
* Verify webhook signature manually
|
|
596
|
+
* Use this for custom integrations
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* import { verifyWebhookSignature } from '@zendfi/sdk/webhooks';
|
|
601
|
+
*
|
|
602
|
+
* const isValid = verifyWebhookSignature(
|
|
603
|
+
* payloadString,
|
|
604
|
+
* signatureHeader,
|
|
605
|
+
* process.env.ZENDFI_WEBHOOK_SECRET
|
|
606
|
+
* );
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
declare function verifyWebhookSignature(payload: string, signature: string, secret: string): boolean;
|
|
610
|
+
|
|
611
|
+
export { type ApproveEscrowRequest, AuthenticationError, ConfigLoader, type CreateEscrowRequest, type CreateInstallmentPlanRequest, type CreateInstallmentPlanResponse, type CreateInvoiceRequest, type CreatePaymentLinkRequest, type CreatePaymentRequest, type CreateSubscriptionPlanRequest, type CreateSubscriptionRequest, type Currency, type DisputeEscrowRequest, type Environment, type Escrow, type EscrowStatus, type InstallmentPlan, type InstallmentPlanStatus, type InstallmentScheduleItem, type Invoice, type InvoiceLineItem, type InvoiceStatus, type ListPaymentsRequest, NetworkError, type PaginatedResponse, type Payment, type PaymentLink, type PaymentStatus, type PaymentToken, RateLimitError, type RefundEscrowRequest, type ReleaseCondition, type SplitRecipient, type SplitStatus, type Subscription, type SubscriptionPlan, type SubscriptionStatus, ValidationError, type VerifyWebhookRequest, type WebhookEvent, type WebhookPayload, ZendFiClient, type ZendFiConfig, ZendFiError, verifyExpressWebhook, verifyNextWebhook, verifyWebhookSignature, zendfi };
|