@zendfi/sdk 0.4.0 → 0.5.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 +1161 -0
- package/dist/express.d.mts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/index.d.mts +1490 -3
- package/dist/index.d.ts +1490 -3
- package/dist/index.js +2539 -411
- package/dist/index.mjs +2501 -401
- package/dist/nextjs.d.mts +1 -1
- package/dist/nextjs.d.ts +1 -1
- package/dist/webhook-handler-D8wEoYd7.d.mts +869 -0
- package/dist/webhook-handler-D8wEoYd7.d.ts +869 -0
- package/package.json +21 -1
- package/dist/webhook-handler-B9ZczHQn.d.mts +0 -373
- package/dist/webhook-handler-B9ZczHQn.d.ts +0 -373
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ZendFi SDK Types
|
|
3
|
-
* Complete type definitions for the ZendFi API
|
|
4
|
-
*/
|
|
5
|
-
type Environment = 'development' | 'staging' | 'production';
|
|
6
|
-
type ApiKeyMode = 'test' | 'live';
|
|
7
|
-
type Currency = 'USD' | 'EUR' | 'GBP';
|
|
8
|
-
type PaymentToken = 'SOL' | 'USDC' | 'USDT';
|
|
9
|
-
type PaymentStatus = 'pending' | 'confirmed' | 'failed' | 'expired';
|
|
10
|
-
type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'paused';
|
|
11
|
-
type InstallmentPlanStatus = 'active' | 'completed' | 'defaulted' | 'cancelled';
|
|
12
|
-
type EscrowStatus = 'pending' | 'funded' | 'released' | 'refunded' | 'disputed' | 'cancelled';
|
|
13
|
-
type InvoiceStatus = 'draft' | 'sent' | 'paid';
|
|
14
|
-
type SplitStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'refunded';
|
|
15
|
-
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';
|
|
16
|
-
interface ZendFiConfig {
|
|
17
|
-
apiKey?: string;
|
|
18
|
-
baseURL?: string;
|
|
19
|
-
environment?: Environment;
|
|
20
|
-
mode?: ApiKeyMode;
|
|
21
|
-
timeout?: number;
|
|
22
|
-
retries?: number;
|
|
23
|
-
idempotencyEnabled?: boolean;
|
|
24
|
-
debug?: boolean;
|
|
25
|
-
}
|
|
26
|
-
interface SplitRecipient {
|
|
27
|
-
recipient_wallet: string;
|
|
28
|
-
recipient_name?: string;
|
|
29
|
-
percentage?: number;
|
|
30
|
-
fixed_amount_usd?: number;
|
|
31
|
-
split_order?: number;
|
|
32
|
-
}
|
|
33
|
-
interface CreatePaymentRequest {
|
|
34
|
-
amount: number;
|
|
35
|
-
currency?: Currency;
|
|
36
|
-
token?: PaymentToken;
|
|
37
|
-
description?: string;
|
|
38
|
-
customer_email?: string;
|
|
39
|
-
redirect_url?: string;
|
|
40
|
-
metadata?: Record<string, any>;
|
|
41
|
-
split_recipients?: SplitRecipient[];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Payment Link - Shareable checkout links
|
|
45
|
-
*/
|
|
46
|
-
interface CreatePaymentLinkRequest {
|
|
47
|
-
amount: number;
|
|
48
|
-
currency?: string;
|
|
49
|
-
token?: string;
|
|
50
|
-
description?: string;
|
|
51
|
-
max_uses?: number;
|
|
52
|
-
expires_at?: string;
|
|
53
|
-
metadata?: Record<string, any>;
|
|
54
|
-
}
|
|
55
|
-
interface PaymentLink {
|
|
56
|
-
link_code: string;
|
|
57
|
-
merchant_id: string;
|
|
58
|
-
title?: string;
|
|
59
|
-
description?: string;
|
|
60
|
-
amount: number;
|
|
61
|
-
currency: string;
|
|
62
|
-
payment_methods?: string[];
|
|
63
|
-
redirect_url?: string;
|
|
64
|
-
expires_at?: string;
|
|
65
|
-
metadata?: Record<string, any>;
|
|
66
|
-
payment_url: string;
|
|
67
|
-
hosted_page_url: string;
|
|
68
|
-
created_at: string;
|
|
69
|
-
updated_at: string;
|
|
70
|
-
url: string;
|
|
71
|
-
id?: string;
|
|
72
|
-
token?: string;
|
|
73
|
-
max_uses?: number;
|
|
74
|
-
uses_count?: number;
|
|
75
|
-
is_active?: boolean;
|
|
76
|
-
}
|
|
77
|
-
interface Payment {
|
|
78
|
-
id: string;
|
|
79
|
-
merchant_id: string;
|
|
80
|
-
amount_usd?: number;
|
|
81
|
-
amount?: number;
|
|
82
|
-
currency?: string;
|
|
83
|
-
payment_token?: PaymentToken;
|
|
84
|
-
status: PaymentStatus;
|
|
85
|
-
customer_wallet?: string;
|
|
86
|
-
customer_email?: string;
|
|
87
|
-
description?: string;
|
|
88
|
-
checkout_url?: string;
|
|
89
|
-
payment_url?: string;
|
|
90
|
-
qr_code?: string;
|
|
91
|
-
expires_at: string;
|
|
92
|
-
confirmed_at?: string;
|
|
93
|
-
transaction_signature?: string;
|
|
94
|
-
metadata?: Record<string, any>;
|
|
95
|
-
split_ids?: string[];
|
|
96
|
-
created_at?: string;
|
|
97
|
-
updated_at?: string;
|
|
98
|
-
}
|
|
99
|
-
interface ListPaymentsRequest {
|
|
100
|
-
page?: number;
|
|
101
|
-
limit?: number;
|
|
102
|
-
status?: PaymentStatus;
|
|
103
|
-
from_date?: string;
|
|
104
|
-
to_date?: string;
|
|
105
|
-
}
|
|
106
|
-
interface PaginatedResponse<T> {
|
|
107
|
-
data: T[];
|
|
108
|
-
pagination: {
|
|
109
|
-
page: number;
|
|
110
|
-
limit: number;
|
|
111
|
-
total: number;
|
|
112
|
-
total_pages: number;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
interface CreateSubscriptionPlanRequest {
|
|
116
|
-
name: string;
|
|
117
|
-
description?: string;
|
|
118
|
-
amount: number;
|
|
119
|
-
currency?: Currency;
|
|
120
|
-
interval: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
121
|
-
interval_count?: number;
|
|
122
|
-
trial_days?: number;
|
|
123
|
-
metadata?: Record<string, any>;
|
|
124
|
-
}
|
|
125
|
-
interface SubscriptionPlan {
|
|
126
|
-
id: string;
|
|
127
|
-
merchant_id: string;
|
|
128
|
-
name: string;
|
|
129
|
-
description?: string;
|
|
130
|
-
amount: number;
|
|
131
|
-
currency: Currency;
|
|
132
|
-
interval: string;
|
|
133
|
-
interval_count: number;
|
|
134
|
-
trial_days: number;
|
|
135
|
-
is_active: boolean;
|
|
136
|
-
metadata?: Record<string, any>;
|
|
137
|
-
created_at: string;
|
|
138
|
-
updated_at: string;
|
|
139
|
-
}
|
|
140
|
-
interface CreateSubscriptionRequest {
|
|
141
|
-
plan_id: string;
|
|
142
|
-
customer_email: string;
|
|
143
|
-
customer_wallet?: string;
|
|
144
|
-
metadata?: Record<string, any>;
|
|
145
|
-
}
|
|
146
|
-
interface Subscription {
|
|
147
|
-
id: string;
|
|
148
|
-
plan_id: string;
|
|
149
|
-
merchant_id: string;
|
|
150
|
-
customer_email: string;
|
|
151
|
-
customer_wallet?: string;
|
|
152
|
-
status: SubscriptionStatus;
|
|
153
|
-
current_period_start: string;
|
|
154
|
-
current_period_end: string;
|
|
155
|
-
trial_end?: string;
|
|
156
|
-
canceled_at?: string;
|
|
157
|
-
metadata?: Record<string, any>;
|
|
158
|
-
created_at: string;
|
|
159
|
-
updated_at: string;
|
|
160
|
-
}
|
|
161
|
-
interface WebhookPayload {
|
|
162
|
-
event: WebhookEvent;
|
|
163
|
-
timestamp: string;
|
|
164
|
-
merchant_id: string;
|
|
165
|
-
data: Payment | Subscription;
|
|
166
|
-
}
|
|
167
|
-
interface VerifyWebhookRequest {
|
|
168
|
-
payload: string | object;
|
|
169
|
-
signature: string;
|
|
170
|
-
secret: string;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Installment Plans - Pay over time
|
|
174
|
-
*/
|
|
175
|
-
interface InstallmentScheduleItem {
|
|
176
|
-
installment_number: number;
|
|
177
|
-
due_date: string;
|
|
178
|
-
amount: string;
|
|
179
|
-
status: string;
|
|
180
|
-
payment_id?: string;
|
|
181
|
-
paid_at?: string;
|
|
182
|
-
}
|
|
183
|
-
interface CreateInstallmentPlanRequest {
|
|
184
|
-
customer_wallet: string;
|
|
185
|
-
customer_email?: string;
|
|
186
|
-
total_amount: number;
|
|
187
|
-
installment_count: number;
|
|
188
|
-
first_payment_date?: string;
|
|
189
|
-
payment_frequency_days: number;
|
|
190
|
-
description?: string;
|
|
191
|
-
late_fee_amount?: number;
|
|
192
|
-
grace_period_days?: number;
|
|
193
|
-
metadata?: Record<string, any>;
|
|
194
|
-
}
|
|
195
|
-
interface CreateInstallmentPlanResponse {
|
|
196
|
-
plan_id: string;
|
|
197
|
-
status: string;
|
|
198
|
-
}
|
|
199
|
-
interface InstallmentPlan {
|
|
200
|
-
id?: string;
|
|
201
|
-
plan_id?: string;
|
|
202
|
-
merchant_id?: string;
|
|
203
|
-
customer_wallet?: string;
|
|
204
|
-
customer_email?: string;
|
|
205
|
-
total_amount?: string;
|
|
206
|
-
installment_count?: number;
|
|
207
|
-
amount_per_installment?: string;
|
|
208
|
-
payment_schedule?: InstallmentScheduleItem[];
|
|
209
|
-
paid_count?: number;
|
|
210
|
-
status: InstallmentPlanStatus | string;
|
|
211
|
-
description?: string;
|
|
212
|
-
late_fee_amount?: string;
|
|
213
|
-
grace_period_days?: number;
|
|
214
|
-
metadata?: Record<string, any>;
|
|
215
|
-
created_at?: string;
|
|
216
|
-
updated_at?: string;
|
|
217
|
-
completed_at?: string;
|
|
218
|
-
defaulted_at?: string;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Escrow - Secure fund holding
|
|
222
|
-
*/
|
|
223
|
-
interface ReleaseCondition {
|
|
224
|
-
type: 'manual_approval' | 'time_based' | 'confirmation_required' | 'milestone';
|
|
225
|
-
approver?: string;
|
|
226
|
-
approved?: boolean;
|
|
227
|
-
release_after?: string;
|
|
228
|
-
confirmations_needed?: number;
|
|
229
|
-
confirmed_by?: string[];
|
|
230
|
-
description?: string;
|
|
231
|
-
approved_by?: string;
|
|
232
|
-
}
|
|
233
|
-
interface CreateEscrowRequest {
|
|
234
|
-
buyer_wallet: string;
|
|
235
|
-
seller_wallet: string;
|
|
236
|
-
amount: number;
|
|
237
|
-
currency?: Currency;
|
|
238
|
-
token?: PaymentToken;
|
|
239
|
-
description?: string;
|
|
240
|
-
release_conditions: ReleaseCondition;
|
|
241
|
-
metadata?: Record<string, any>;
|
|
242
|
-
}
|
|
243
|
-
interface Escrow {
|
|
244
|
-
id: string;
|
|
245
|
-
payment_id: string;
|
|
246
|
-
merchant_id: string;
|
|
247
|
-
buyer_wallet: string;
|
|
248
|
-
seller_wallet: string;
|
|
249
|
-
escrow_wallet: string;
|
|
250
|
-
amount: number;
|
|
251
|
-
currency: Currency;
|
|
252
|
-
token: PaymentToken;
|
|
253
|
-
release_conditions: ReleaseCondition;
|
|
254
|
-
status: EscrowStatus;
|
|
255
|
-
payment_url?: string;
|
|
256
|
-
qr_code?: string;
|
|
257
|
-
funded_at?: string;
|
|
258
|
-
released_at?: string;
|
|
259
|
-
refunded_at?: string;
|
|
260
|
-
disputed_at?: string;
|
|
261
|
-
dispute_reason?: string;
|
|
262
|
-
release_transaction_signature?: string;
|
|
263
|
-
refund_transaction_signature?: string;
|
|
264
|
-
metadata?: Record<string, any>;
|
|
265
|
-
created_at: string;
|
|
266
|
-
updated_at: string;
|
|
267
|
-
}
|
|
268
|
-
interface ApproveEscrowRequest {
|
|
269
|
-
approver_wallet: string;
|
|
270
|
-
}
|
|
271
|
-
interface RefundEscrowRequest {
|
|
272
|
-
reason: string;
|
|
273
|
-
}
|
|
274
|
-
interface DisputeEscrowRequest {
|
|
275
|
-
reason: string;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Invoices - Professional billing
|
|
279
|
-
*/
|
|
280
|
-
interface InvoiceLineItem {
|
|
281
|
-
description: string;
|
|
282
|
-
quantity: number;
|
|
283
|
-
unit_price: number;
|
|
284
|
-
}
|
|
285
|
-
interface CreateInvoiceRequest {
|
|
286
|
-
customer_email: string;
|
|
287
|
-
customer_name?: string;
|
|
288
|
-
amount: number;
|
|
289
|
-
token?: PaymentToken;
|
|
290
|
-
description: string;
|
|
291
|
-
line_items?: InvoiceLineItem[];
|
|
292
|
-
due_date?: string;
|
|
293
|
-
metadata?: Record<string, any>;
|
|
294
|
-
}
|
|
295
|
-
interface Invoice {
|
|
296
|
-
id: string;
|
|
297
|
-
invoice_number: string;
|
|
298
|
-
merchant_id: string;
|
|
299
|
-
customer_email: string;
|
|
300
|
-
customer_name?: string;
|
|
301
|
-
amount_usd: number;
|
|
302
|
-
token: PaymentToken;
|
|
303
|
-
description: string;
|
|
304
|
-
line_items?: InvoiceLineItem[];
|
|
305
|
-
status: InvoiceStatus;
|
|
306
|
-
payment_url?: string;
|
|
307
|
-
due_date?: string;
|
|
308
|
-
sent_at?: string;
|
|
309
|
-
paid_at?: string;
|
|
310
|
-
metadata?: Record<string, any>;
|
|
311
|
-
created_at: string;
|
|
312
|
-
updated_at: string;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* ZendFi Webhook Handlers
|
|
317
|
-
* Type-safe webhook handlers with automatic verification and deduplication
|
|
318
|
-
*/
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Webhook handler configuration
|
|
322
|
-
*/
|
|
323
|
-
interface WebhookHandlerConfig {
|
|
324
|
-
/** Your webhook secret from ZendFi dashboard */
|
|
325
|
-
secret: string;
|
|
326
|
-
/** Optional: Path to store processed webhook IDs (for deduplication) */
|
|
327
|
-
onProcessed?: (webhookId: string) => Promise<void>;
|
|
328
|
-
/** Optional: Check if webhook was already processed */
|
|
329
|
-
isProcessed?: (webhookId: string) => Promise<boolean>;
|
|
330
|
-
/** Optional: Custom error handler */
|
|
331
|
-
onError?: (error: Error, event?: WebhookEvent) => void | Promise<void>;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Event handler function type
|
|
335
|
-
*/
|
|
336
|
-
type WebhookEventHandler<T = any> = (data: T, event: WebhookPayload) => void | Promise<void>;
|
|
337
|
-
/**
|
|
338
|
-
* Webhook handlers map - type-safe event handlers
|
|
339
|
-
*/
|
|
340
|
-
type WebhookHandlers = Partial<{
|
|
341
|
-
'payment.created': WebhookEventHandler;
|
|
342
|
-
'payment.confirmed': WebhookEventHandler;
|
|
343
|
-
'payment.failed': WebhookEventHandler;
|
|
344
|
-
'payment.expired': WebhookEventHandler;
|
|
345
|
-
'subscription.created': WebhookEventHandler;
|
|
346
|
-
'subscription.activated': WebhookEventHandler;
|
|
347
|
-
'subscription.canceled': WebhookEventHandler;
|
|
348
|
-
'subscription.payment_failed': WebhookEventHandler;
|
|
349
|
-
'split.completed': WebhookEventHandler;
|
|
350
|
-
'split.failed': WebhookEventHandler;
|
|
351
|
-
'installment.due': WebhookEventHandler;
|
|
352
|
-
'installment.paid': WebhookEventHandler;
|
|
353
|
-
'installment.late': WebhookEventHandler;
|
|
354
|
-
'escrow.funded': WebhookEventHandler;
|
|
355
|
-
'escrow.released': WebhookEventHandler;
|
|
356
|
-
'escrow.refunded': WebhookEventHandler;
|
|
357
|
-
'escrow.disputed': WebhookEventHandler;
|
|
358
|
-
'invoice.sent': WebhookEventHandler;
|
|
359
|
-
'invoice.paid': WebhookEventHandler;
|
|
360
|
-
}>;
|
|
361
|
-
/**
|
|
362
|
-
* Webhook processing result
|
|
363
|
-
*/
|
|
364
|
-
interface WebhookResult {
|
|
365
|
-
success: boolean;
|
|
366
|
-
processed: boolean;
|
|
367
|
-
error?: string;
|
|
368
|
-
event?: WebhookEvent;
|
|
369
|
-
statusCode?: number;
|
|
370
|
-
}
|
|
371
|
-
declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
|
|
372
|
-
|
|
373
|
-
export { type ApproveEscrowRequest as A, type SplitRecipient as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, type InstallmentScheduleItem as F, type CreateInstallmentPlanResponse as G, type ReleaseCondition as H, type InstallmentPlan as I, type InvoiceLineItem as J, type ListPaymentsRequest as L, type Payment as P, type RefundEscrowRequest as R, type SubscriptionPlan as S, type VerifyWebhookRequest as V, type WebhookHandlerConfig as W, type ZendFiConfig as Z, type WebhookHandlers as a, type PaginatedResponse as b, type CreateSubscriptionPlanRequest as c, type CreateSubscriptionRequest as d, type Subscription as e, type CreatePaymentLinkRequest as f, type PaymentLink as g, type CreateInstallmentPlanRequest as h, type CreateEscrowRequest as i, type CreateInvoiceRequest as j, type Invoice as k, type WebhookPayload as l, type WebhookResult as m, type WebhookEventHandler as n, type Environment as o, processWebhook as p, type ApiKeyMode as q, type Currency as r, type PaymentToken as s, type PaymentStatus as t, type SubscriptionStatus as u, type InstallmentPlanStatus as v, type EscrowStatus as w, type InvoiceStatus as x, type SplitStatus as y, type WebhookEvent as z };
|