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