@zendfi/sdk 0.1.1 → 0.2.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.
@@ -0,0 +1,388 @@
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
+ link_code: string;
54
+ merchant_id: string;
55
+ title?: string;
56
+ description?: string;
57
+ amount: number;
58
+ currency: string;
59
+ payment_methods?: string[];
60
+ redirect_url?: string;
61
+ expires_at?: string;
62
+ metadata?: Record<string, any>;
63
+ payment_url: string;
64
+ hosted_page_url: string;
65
+ created_at: string;
66
+ updated_at: string;
67
+ url: string;
68
+ id?: string;
69
+ token?: string;
70
+ max_uses?: number;
71
+ uses_count?: number;
72
+ is_active?: boolean;
73
+ }
74
+ interface Payment {
75
+ id: string;
76
+ merchant_id: string;
77
+ amount_usd?: number;
78
+ amount?: number;
79
+ currency?: string;
80
+ payment_token?: PaymentToken;
81
+ status: PaymentStatus;
82
+ customer_wallet?: string;
83
+ customer_email?: string;
84
+ description?: string;
85
+ checkout_url?: string;
86
+ payment_url?: string;
87
+ qr_code?: string;
88
+ expires_at: string;
89
+ confirmed_at?: string;
90
+ transaction_signature?: string;
91
+ metadata?: Record<string, any>;
92
+ split_ids?: string[];
93
+ created_at?: string;
94
+ updated_at?: string;
95
+ }
96
+ interface ListPaymentsRequest {
97
+ page?: number;
98
+ limit?: number;
99
+ status?: PaymentStatus;
100
+ from_date?: string;
101
+ to_date?: string;
102
+ }
103
+ interface PaginatedResponse<T> {
104
+ data: T[];
105
+ pagination: {
106
+ page: number;
107
+ limit: number;
108
+ total: number;
109
+ total_pages: number;
110
+ };
111
+ }
112
+ interface CreateSubscriptionPlanRequest {
113
+ name: string;
114
+ description?: string;
115
+ amount: number;
116
+ currency?: Currency;
117
+ interval: 'daily' | 'weekly' | 'monthly' | 'yearly';
118
+ interval_count?: number;
119
+ trial_days?: number;
120
+ metadata?: Record<string, any>;
121
+ }
122
+ interface SubscriptionPlan {
123
+ id: string;
124
+ merchant_id: string;
125
+ name: string;
126
+ description?: string;
127
+ amount: number;
128
+ currency: Currency;
129
+ interval: string;
130
+ interval_count: number;
131
+ trial_days: number;
132
+ is_active: boolean;
133
+ metadata?: Record<string, any>;
134
+ created_at: string;
135
+ updated_at: string;
136
+ }
137
+ interface CreateSubscriptionRequest {
138
+ plan_id: string;
139
+ customer_email: string;
140
+ customer_wallet?: string;
141
+ metadata?: Record<string, any>;
142
+ }
143
+ interface Subscription {
144
+ id: string;
145
+ plan_id: string;
146
+ merchant_id: string;
147
+ customer_email: string;
148
+ customer_wallet?: string;
149
+ status: SubscriptionStatus;
150
+ current_period_start: string;
151
+ current_period_end: string;
152
+ trial_end?: string;
153
+ canceled_at?: string;
154
+ metadata?: Record<string, any>;
155
+ created_at: string;
156
+ updated_at: string;
157
+ }
158
+ interface WebhookPayload {
159
+ event: WebhookEvent;
160
+ timestamp: string;
161
+ merchant_id: string;
162
+ data: Payment | Subscription;
163
+ }
164
+ interface VerifyWebhookRequest {
165
+ payload: string | object;
166
+ signature: string;
167
+ secret: string;
168
+ }
169
+ declare class ZendFiError extends Error {
170
+ statusCode?: number | undefined;
171
+ code?: string | undefined;
172
+ details?: any | undefined;
173
+ constructor(message: string, statusCode?: number | undefined, code?: string | undefined, details?: any | undefined);
174
+ }
175
+ declare class AuthenticationError extends ZendFiError {
176
+ constructor(message?: string);
177
+ }
178
+ declare class ValidationError extends ZendFiError {
179
+ constructor(message: string, details?: any);
180
+ }
181
+ declare class NetworkError extends ZendFiError {
182
+ constructor(message: string);
183
+ }
184
+ declare class RateLimitError extends ZendFiError {
185
+ constructor(message?: string);
186
+ }
187
+ /**
188
+ * Installment Plans - Pay over time
189
+ */
190
+ interface InstallmentScheduleItem {
191
+ installment_number: number;
192
+ due_date: string;
193
+ amount: string;
194
+ status: string;
195
+ payment_id?: string;
196
+ paid_at?: string;
197
+ }
198
+ interface CreateInstallmentPlanRequest {
199
+ customer_wallet: string;
200
+ customer_email?: string;
201
+ total_amount: number;
202
+ installment_count: number;
203
+ first_payment_date?: string;
204
+ payment_frequency_days: number;
205
+ description?: string;
206
+ late_fee_amount?: number;
207
+ grace_period_days?: number;
208
+ metadata?: Record<string, any>;
209
+ }
210
+ interface CreateInstallmentPlanResponse {
211
+ plan_id: string;
212
+ status: string;
213
+ }
214
+ interface InstallmentPlan {
215
+ id?: string;
216
+ plan_id?: string;
217
+ merchant_id?: string;
218
+ customer_wallet?: string;
219
+ customer_email?: string;
220
+ total_amount?: string;
221
+ installment_count?: number;
222
+ amount_per_installment?: string;
223
+ payment_schedule?: InstallmentScheduleItem[];
224
+ paid_count?: number;
225
+ status: InstallmentPlanStatus | string;
226
+ description?: string;
227
+ late_fee_amount?: string;
228
+ grace_period_days?: number;
229
+ metadata?: Record<string, any>;
230
+ created_at?: string;
231
+ updated_at?: string;
232
+ completed_at?: string;
233
+ defaulted_at?: string;
234
+ }
235
+ /**
236
+ * Escrow - Secure fund holding
237
+ */
238
+ interface ReleaseCondition {
239
+ type: 'manual_approval' | 'time_based' | 'confirmation_required' | 'milestone';
240
+ approver?: string;
241
+ approved?: boolean;
242
+ release_after?: string;
243
+ confirmations_needed?: number;
244
+ confirmed_by?: string[];
245
+ description?: string;
246
+ approved_by?: string;
247
+ }
248
+ interface CreateEscrowRequest {
249
+ buyer_wallet: string;
250
+ seller_wallet: string;
251
+ amount: number;
252
+ currency?: Currency;
253
+ token?: PaymentToken;
254
+ description?: string;
255
+ release_conditions: ReleaseCondition;
256
+ metadata?: Record<string, any>;
257
+ }
258
+ interface Escrow {
259
+ id: string;
260
+ payment_id: string;
261
+ merchant_id: string;
262
+ buyer_wallet: string;
263
+ seller_wallet: string;
264
+ escrow_wallet: string;
265
+ amount: number;
266
+ currency: Currency;
267
+ token: PaymentToken;
268
+ release_conditions: ReleaseCondition;
269
+ status: EscrowStatus;
270
+ payment_url?: string;
271
+ qr_code?: string;
272
+ funded_at?: string;
273
+ released_at?: string;
274
+ refunded_at?: string;
275
+ disputed_at?: string;
276
+ dispute_reason?: string;
277
+ release_transaction_signature?: string;
278
+ refund_transaction_signature?: string;
279
+ metadata?: Record<string, any>;
280
+ created_at: string;
281
+ updated_at: string;
282
+ }
283
+ interface ApproveEscrowRequest {
284
+ approver_wallet: string;
285
+ }
286
+ interface RefundEscrowRequest {
287
+ reason: string;
288
+ }
289
+ interface DisputeEscrowRequest {
290
+ reason: string;
291
+ }
292
+ /**
293
+ * Invoices - Professional billing
294
+ */
295
+ interface InvoiceLineItem {
296
+ description: string;
297
+ quantity: number;
298
+ unit_price: number;
299
+ }
300
+ interface CreateInvoiceRequest {
301
+ customer_email: string;
302
+ customer_name?: string;
303
+ amount: number;
304
+ token?: PaymentToken;
305
+ description: string;
306
+ line_items?: InvoiceLineItem[];
307
+ due_date?: string;
308
+ metadata?: Record<string, any>;
309
+ }
310
+ interface Invoice {
311
+ id: string;
312
+ invoice_number: string;
313
+ merchant_id: string;
314
+ customer_email: string;
315
+ customer_name?: string;
316
+ amount_usd: number;
317
+ token: PaymentToken;
318
+ description: string;
319
+ line_items?: InvoiceLineItem[];
320
+ status: InvoiceStatus;
321
+ payment_url?: string;
322
+ due_date?: string;
323
+ sent_at?: string;
324
+ paid_at?: string;
325
+ metadata?: Record<string, any>;
326
+ created_at: string;
327
+ updated_at: string;
328
+ }
329
+
330
+ /**
331
+ * ZendFi Webhook Handlers
332
+ * Type-safe webhook handlers with automatic verification and deduplication
333
+ */
334
+
335
+ /**
336
+ * Webhook handler configuration
337
+ */
338
+ interface WebhookHandlerConfig {
339
+ /** Your webhook secret from ZendFi dashboard */
340
+ secret: string;
341
+ /** Optional: Path to store processed webhook IDs (for deduplication) */
342
+ onProcessed?: (webhookId: string) => Promise<void>;
343
+ /** Optional: Check if webhook was already processed */
344
+ isProcessed?: (webhookId: string) => Promise<boolean>;
345
+ /** Optional: Custom error handler */
346
+ onError?: (error: Error, event?: WebhookEvent) => void | Promise<void>;
347
+ }
348
+ /**
349
+ * Event handler function type
350
+ */
351
+ type WebhookEventHandler<T = any> = (data: T, event: WebhookPayload) => void | Promise<void>;
352
+ /**
353
+ * Webhook handlers map - type-safe event handlers
354
+ */
355
+ type WebhookHandlers = Partial<{
356
+ 'payment.created': WebhookEventHandler;
357
+ 'payment.confirmed': WebhookEventHandler;
358
+ 'payment.failed': WebhookEventHandler;
359
+ 'payment.expired': WebhookEventHandler;
360
+ 'subscription.created': WebhookEventHandler;
361
+ 'subscription.activated': WebhookEventHandler;
362
+ 'subscription.canceled': WebhookEventHandler;
363
+ 'subscription.payment_failed': WebhookEventHandler;
364
+ 'split.completed': WebhookEventHandler;
365
+ 'split.failed': WebhookEventHandler;
366
+ 'installment.due': WebhookEventHandler;
367
+ 'installment.paid': WebhookEventHandler;
368
+ 'installment.late': WebhookEventHandler;
369
+ 'escrow.funded': WebhookEventHandler;
370
+ 'escrow.released': WebhookEventHandler;
371
+ 'escrow.refunded': WebhookEventHandler;
372
+ 'escrow.disputed': WebhookEventHandler;
373
+ 'invoice.sent': WebhookEventHandler;
374
+ 'invoice.paid': WebhookEventHandler;
375
+ }>;
376
+ /**
377
+ * Webhook processing result
378
+ */
379
+ interface WebhookResult {
380
+ success: boolean;
381
+ processed: boolean;
382
+ error?: string;
383
+ event?: WebhookEvent;
384
+ statusCode?: number;
385
+ }
386
+ declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
387
+
388
+ export { type ApproveEscrowRequest as A, ZendFiError as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, AuthenticationError as F, ValidationError as G, RateLimitError as H, type InstallmentPlan as I, type InstallmentScheduleItem as J, type CreateInstallmentPlanResponse as K, type ListPaymentsRequest as L, type ReleaseCondition as M, NetworkError as N, type InvoiceLineItem as O, 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 Currency as q, type PaymentToken as r, type PaymentStatus as s, type SubscriptionStatus as t, type InstallmentPlanStatus as u, type EscrowStatus as v, type InvoiceStatus as w, type SplitStatus as x, type WebhookEvent as y, type SplitRecipient as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendfi/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Zero-config TypeScript SDK for ZendFi crypto payments",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -8,16 +8,23 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./dist/index.mjs",
11
- "require": "./dist/index.js",
12
- "types": "./dist/index.d.ts"
11
+ "require": "./dist/index.js"
12
+ },
13
+ "./nextjs": {
14
+ "import": "./dist/nextjs.mjs",
15
+ "require": "./dist/nextjs.js"
16
+ },
17
+ "./express": {
18
+ "import": "./dist/express.mjs",
19
+ "require": "./dist/express.js"
13
20
  }
14
21
  },
15
22
  "files": [
16
23
  "dist"
17
24
  ],
18
25
  "scripts": {
19
- "build": "tsup src/index.ts --format esm,cjs --dts --clean",
20
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
26
+ "build": "tsup src/index.ts src/nextjs.ts src/express.ts --format esm,cjs --dts --clean",
27
+ "dev": "tsup src/index.ts src/nextjs.ts src/express.ts --format esm,cjs --dts --watch",
21
28
  "test": "vitest run",
22
29
  "test:watch": "vitest",
23
30
  "lint": "tsc --noEmit",