@zendfi/sdk 0.4.0 → 0.5.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/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
|
@@ -0,0 +1,869 @@
|
|
|
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
|
+
/** Session ID (e.g., 'sess_abc123') */
|
|
12
|
+
type SessionId = Brand<string, 'SessionId'>;
|
|
13
|
+
/** Agent Key ID (e.g., 'ak_abc123') */
|
|
14
|
+
type AgentKeyId = Brand<string, 'AgentKeyId'>;
|
|
15
|
+
/** Merchant ID (e.g., 'merch_abc123') */
|
|
16
|
+
type MerchantId = Brand<string, 'MerchantId'>;
|
|
17
|
+
/** Invoice ID (e.g., 'inv_abc123') */
|
|
18
|
+
type InvoiceId = Brand<string, 'InvoiceId'>;
|
|
19
|
+
/** Subscription ID (e.g., 'sub_abc123') */
|
|
20
|
+
type SubscriptionId = Brand<string, 'SubscriptionId'>;
|
|
21
|
+
/** Escrow ID (e.g., 'esc_abc123') */
|
|
22
|
+
type EscrowId = Brand<string, 'EscrowId'>;
|
|
23
|
+
/** Installment Plan ID (e.g., 'inst_abc123') */
|
|
24
|
+
type InstallmentPlanId = Brand<string, 'InstallmentPlanId'>;
|
|
25
|
+
/** Payment Link Code (e.g., 'link_abc123') */
|
|
26
|
+
type PaymentLinkCode = Brand<string, 'PaymentLinkCode'>;
|
|
27
|
+
/** Intent ID (e.g., 'pi_abc123') */
|
|
28
|
+
type IntentId = Brand<string, 'IntentId'>;
|
|
29
|
+
declare const asPaymentId: (id: string) => PaymentId;
|
|
30
|
+
declare const asSessionId: (id: string) => SessionId;
|
|
31
|
+
declare const asAgentKeyId: (id: string) => AgentKeyId;
|
|
32
|
+
declare const asMerchantId: (id: string) => MerchantId;
|
|
33
|
+
declare const asInvoiceId: (id: string) => InvoiceId;
|
|
34
|
+
declare const asSubscriptionId: (id: string) => SubscriptionId;
|
|
35
|
+
declare const asEscrowId: (id: string) => EscrowId;
|
|
36
|
+
declare const asInstallmentPlanId: (id: string) => InstallmentPlanId;
|
|
37
|
+
declare const asPaymentLinkCode: (id: string) => PaymentLinkCode;
|
|
38
|
+
declare const asIntentId: (id: string) => IntentId;
|
|
39
|
+
type Environment = 'development' | 'staging' | 'production';
|
|
40
|
+
type ApiKeyMode = 'test' | 'live';
|
|
41
|
+
type Currency = 'USD' | 'EUR' | 'GBP';
|
|
42
|
+
type PaymentToken = 'SOL' | 'USDC' | 'USDT';
|
|
43
|
+
type PaymentStatus = 'pending' | 'confirmed' | 'failed' | 'expired';
|
|
44
|
+
type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'paused';
|
|
45
|
+
type InstallmentPlanStatus = 'active' | 'completed' | 'defaulted' | 'cancelled';
|
|
46
|
+
type EscrowStatus = 'pending' | 'funded' | 'released' | 'refunded' | 'disputed' | 'cancelled';
|
|
47
|
+
type InvoiceStatus = 'draft' | 'sent' | 'paid';
|
|
48
|
+
type SplitStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'refunded';
|
|
49
|
+
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';
|
|
50
|
+
interface ZendFiConfig {
|
|
51
|
+
apiKey?: string;
|
|
52
|
+
baseURL?: string;
|
|
53
|
+
environment?: Environment;
|
|
54
|
+
mode?: ApiKeyMode;
|
|
55
|
+
timeout?: number;
|
|
56
|
+
retries?: number;
|
|
57
|
+
idempotencyEnabled?: boolean;
|
|
58
|
+
debug?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface SplitRecipient {
|
|
61
|
+
recipient_wallet: string;
|
|
62
|
+
recipient_name?: string;
|
|
63
|
+
percentage?: number;
|
|
64
|
+
fixed_amount_usd?: number;
|
|
65
|
+
split_order?: number;
|
|
66
|
+
}
|
|
67
|
+
interface CreatePaymentRequest {
|
|
68
|
+
amount: number;
|
|
69
|
+
currency?: Currency;
|
|
70
|
+
token?: PaymentToken;
|
|
71
|
+
description?: string;
|
|
72
|
+
customer_email?: string;
|
|
73
|
+
redirect_url?: string;
|
|
74
|
+
metadata?: Record<string, any>;
|
|
75
|
+
split_recipients?: SplitRecipient[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Payment Link - Shareable checkout links
|
|
79
|
+
*/
|
|
80
|
+
interface CreatePaymentLinkRequest {
|
|
81
|
+
amount: number;
|
|
82
|
+
currency?: string;
|
|
83
|
+
token?: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
max_uses?: number;
|
|
86
|
+
expires_at?: string;
|
|
87
|
+
metadata?: Record<string, any>;
|
|
88
|
+
}
|
|
89
|
+
interface PaymentLink {
|
|
90
|
+
link_code: string;
|
|
91
|
+
merchant_id: string;
|
|
92
|
+
title?: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
amount: number;
|
|
95
|
+
currency: string;
|
|
96
|
+
payment_methods?: string[];
|
|
97
|
+
redirect_url?: string;
|
|
98
|
+
expires_at?: string;
|
|
99
|
+
metadata?: Record<string, any>;
|
|
100
|
+
payment_url: string;
|
|
101
|
+
hosted_page_url: string;
|
|
102
|
+
created_at: string;
|
|
103
|
+
updated_at: string;
|
|
104
|
+
url: string;
|
|
105
|
+
id?: string;
|
|
106
|
+
token?: string;
|
|
107
|
+
max_uses?: number;
|
|
108
|
+
uses_count?: number;
|
|
109
|
+
is_active?: boolean;
|
|
110
|
+
}
|
|
111
|
+
interface Payment {
|
|
112
|
+
id: string;
|
|
113
|
+
merchant_id: string;
|
|
114
|
+
amount_usd?: number;
|
|
115
|
+
amount?: number;
|
|
116
|
+
currency?: string;
|
|
117
|
+
payment_token?: PaymentToken;
|
|
118
|
+
status: PaymentStatus;
|
|
119
|
+
customer_wallet?: string;
|
|
120
|
+
customer_email?: string;
|
|
121
|
+
description?: string;
|
|
122
|
+
checkout_url?: string;
|
|
123
|
+
payment_url?: string;
|
|
124
|
+
qr_code?: string;
|
|
125
|
+
expires_at: string;
|
|
126
|
+
confirmed_at?: string;
|
|
127
|
+
transaction_signature?: string;
|
|
128
|
+
metadata?: Record<string, any>;
|
|
129
|
+
split_ids?: string[];
|
|
130
|
+
created_at?: string;
|
|
131
|
+
updated_at?: string;
|
|
132
|
+
}
|
|
133
|
+
interface ListPaymentsRequest {
|
|
134
|
+
page?: number;
|
|
135
|
+
limit?: number;
|
|
136
|
+
status?: PaymentStatus;
|
|
137
|
+
from_date?: string;
|
|
138
|
+
to_date?: string;
|
|
139
|
+
}
|
|
140
|
+
interface PaginatedResponse<T> {
|
|
141
|
+
data: T[];
|
|
142
|
+
pagination: {
|
|
143
|
+
page: number;
|
|
144
|
+
limit: number;
|
|
145
|
+
total: number;
|
|
146
|
+
total_pages: number;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
interface CreateSubscriptionPlanRequest {
|
|
150
|
+
name: string;
|
|
151
|
+
description?: string;
|
|
152
|
+
amount: number;
|
|
153
|
+
currency?: Currency;
|
|
154
|
+
interval: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
155
|
+
interval_count?: number;
|
|
156
|
+
trial_days?: number;
|
|
157
|
+
metadata?: Record<string, any>;
|
|
158
|
+
}
|
|
159
|
+
interface SubscriptionPlan {
|
|
160
|
+
id: string;
|
|
161
|
+
merchant_id: string;
|
|
162
|
+
name: string;
|
|
163
|
+
description?: string;
|
|
164
|
+
amount: number;
|
|
165
|
+
currency: Currency;
|
|
166
|
+
interval: string;
|
|
167
|
+
interval_count: number;
|
|
168
|
+
trial_days: number;
|
|
169
|
+
is_active: boolean;
|
|
170
|
+
metadata?: Record<string, any>;
|
|
171
|
+
created_at: string;
|
|
172
|
+
updated_at: string;
|
|
173
|
+
}
|
|
174
|
+
interface CreateSubscriptionRequest {
|
|
175
|
+
plan_id: string;
|
|
176
|
+
customer_email: string;
|
|
177
|
+
customer_wallet?: string;
|
|
178
|
+
metadata?: Record<string, any>;
|
|
179
|
+
}
|
|
180
|
+
interface Subscription {
|
|
181
|
+
id: string;
|
|
182
|
+
plan_id: string;
|
|
183
|
+
merchant_id: string;
|
|
184
|
+
customer_email: string;
|
|
185
|
+
customer_wallet?: string;
|
|
186
|
+
status: SubscriptionStatus;
|
|
187
|
+
current_period_start: string;
|
|
188
|
+
current_period_end: string;
|
|
189
|
+
trial_end?: string;
|
|
190
|
+
canceled_at?: string;
|
|
191
|
+
metadata?: Record<string, any>;
|
|
192
|
+
created_at: string;
|
|
193
|
+
updated_at: string;
|
|
194
|
+
}
|
|
195
|
+
interface WebhookPayload {
|
|
196
|
+
event: WebhookEvent;
|
|
197
|
+
timestamp: string;
|
|
198
|
+
merchant_id: string;
|
|
199
|
+
data: Payment | Subscription;
|
|
200
|
+
}
|
|
201
|
+
interface VerifyWebhookRequest {
|
|
202
|
+
payload: string | object;
|
|
203
|
+
signature: string;
|
|
204
|
+
secret: string;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Installment Plans - Pay over time
|
|
208
|
+
*/
|
|
209
|
+
interface InstallmentScheduleItem {
|
|
210
|
+
installment_number: number;
|
|
211
|
+
due_date: string;
|
|
212
|
+
amount: string;
|
|
213
|
+
status: string;
|
|
214
|
+
payment_id?: string;
|
|
215
|
+
paid_at?: string;
|
|
216
|
+
}
|
|
217
|
+
interface CreateInstallmentPlanRequest {
|
|
218
|
+
customer_wallet: string;
|
|
219
|
+
customer_email?: string;
|
|
220
|
+
total_amount: number;
|
|
221
|
+
installment_count: number;
|
|
222
|
+
first_payment_date?: string;
|
|
223
|
+
payment_frequency_days: number;
|
|
224
|
+
description?: string;
|
|
225
|
+
late_fee_amount?: number;
|
|
226
|
+
grace_period_days?: number;
|
|
227
|
+
metadata?: Record<string, any>;
|
|
228
|
+
}
|
|
229
|
+
interface CreateInstallmentPlanResponse {
|
|
230
|
+
plan_id: string;
|
|
231
|
+
status: string;
|
|
232
|
+
}
|
|
233
|
+
interface InstallmentPlan {
|
|
234
|
+
id?: string;
|
|
235
|
+
plan_id?: string;
|
|
236
|
+
merchant_id?: string;
|
|
237
|
+
customer_wallet?: string;
|
|
238
|
+
customer_email?: string;
|
|
239
|
+
total_amount?: string;
|
|
240
|
+
installment_count?: number;
|
|
241
|
+
amount_per_installment?: string;
|
|
242
|
+
payment_schedule?: InstallmentScheduleItem[];
|
|
243
|
+
paid_count?: number;
|
|
244
|
+
status: InstallmentPlanStatus | string;
|
|
245
|
+
description?: string;
|
|
246
|
+
late_fee_amount?: string;
|
|
247
|
+
grace_period_days?: number;
|
|
248
|
+
metadata?: Record<string, any>;
|
|
249
|
+
created_at?: string;
|
|
250
|
+
updated_at?: string;
|
|
251
|
+
completed_at?: string;
|
|
252
|
+
defaulted_at?: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Escrow - Secure fund holding
|
|
256
|
+
*/
|
|
257
|
+
interface ReleaseCondition {
|
|
258
|
+
type: 'manual_approval' | 'time_based' | 'confirmation_required' | 'milestone';
|
|
259
|
+
approver?: string;
|
|
260
|
+
approved?: boolean;
|
|
261
|
+
release_after?: string;
|
|
262
|
+
confirmations_needed?: number;
|
|
263
|
+
confirmed_by?: string[];
|
|
264
|
+
description?: string;
|
|
265
|
+
approved_by?: string;
|
|
266
|
+
}
|
|
267
|
+
interface CreateEscrowRequest {
|
|
268
|
+
buyer_wallet: string;
|
|
269
|
+
seller_wallet: string;
|
|
270
|
+
amount: number;
|
|
271
|
+
currency?: Currency;
|
|
272
|
+
token?: PaymentToken;
|
|
273
|
+
description?: string;
|
|
274
|
+
release_conditions: ReleaseCondition;
|
|
275
|
+
metadata?: Record<string, any>;
|
|
276
|
+
}
|
|
277
|
+
interface Escrow {
|
|
278
|
+
id: string;
|
|
279
|
+
payment_id: string;
|
|
280
|
+
merchant_id: string;
|
|
281
|
+
buyer_wallet: string;
|
|
282
|
+
seller_wallet: string;
|
|
283
|
+
escrow_wallet: string;
|
|
284
|
+
amount: number;
|
|
285
|
+
currency: Currency;
|
|
286
|
+
token: PaymentToken;
|
|
287
|
+
release_conditions: ReleaseCondition;
|
|
288
|
+
status: EscrowStatus;
|
|
289
|
+
payment_url?: string;
|
|
290
|
+
qr_code?: string;
|
|
291
|
+
funded_at?: string;
|
|
292
|
+
released_at?: string;
|
|
293
|
+
refunded_at?: string;
|
|
294
|
+
disputed_at?: string;
|
|
295
|
+
dispute_reason?: string;
|
|
296
|
+
release_transaction_signature?: string;
|
|
297
|
+
refund_transaction_signature?: string;
|
|
298
|
+
metadata?: Record<string, any>;
|
|
299
|
+
created_at: string;
|
|
300
|
+
updated_at: string;
|
|
301
|
+
}
|
|
302
|
+
interface ApproveEscrowRequest {
|
|
303
|
+
approver_wallet: string;
|
|
304
|
+
}
|
|
305
|
+
interface RefundEscrowRequest {
|
|
306
|
+
reason: string;
|
|
307
|
+
}
|
|
308
|
+
interface DisputeEscrowRequest {
|
|
309
|
+
reason: string;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Invoices - Professional billing
|
|
313
|
+
*/
|
|
314
|
+
interface InvoiceLineItem {
|
|
315
|
+
description: string;
|
|
316
|
+
quantity: number;
|
|
317
|
+
unit_price: number;
|
|
318
|
+
}
|
|
319
|
+
interface CreateInvoiceRequest {
|
|
320
|
+
customer_email: string;
|
|
321
|
+
customer_name?: string;
|
|
322
|
+
amount: number;
|
|
323
|
+
token?: PaymentToken;
|
|
324
|
+
description: string;
|
|
325
|
+
line_items?: InvoiceLineItem[];
|
|
326
|
+
due_date?: string;
|
|
327
|
+
metadata?: Record<string, any>;
|
|
328
|
+
}
|
|
329
|
+
interface Invoice {
|
|
330
|
+
id: string;
|
|
331
|
+
invoice_number: string;
|
|
332
|
+
merchant_id: string;
|
|
333
|
+
customer_email: string;
|
|
334
|
+
customer_name?: string;
|
|
335
|
+
amount_usd: number;
|
|
336
|
+
token: PaymentToken;
|
|
337
|
+
description: string;
|
|
338
|
+
line_items?: InvoiceLineItem[];
|
|
339
|
+
status: InvoiceStatus;
|
|
340
|
+
payment_url?: string;
|
|
341
|
+
due_date?: string;
|
|
342
|
+
sent_at?: string;
|
|
343
|
+
paid_at?: string;
|
|
344
|
+
metadata?: Record<string, any>;
|
|
345
|
+
created_at: string;
|
|
346
|
+
updated_at: string;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* API Key Scopes for Agent Keys
|
|
350
|
+
* Controls what operations an agent can perform
|
|
351
|
+
*/
|
|
352
|
+
type ApiKeyScope = 'full' | 'read_only' | 'create_payments' | 'manage_escrow' | 'create_subscriptions' | 'manage_installments' | 'read_analytics';
|
|
353
|
+
/**
|
|
354
|
+
* Agent API Key - Scoped access for AI agents
|
|
355
|
+
* Created via zendfi.agent.createKey()
|
|
356
|
+
*/
|
|
357
|
+
interface AgentApiKey {
|
|
358
|
+
/** Unique identifier (UUID) */
|
|
359
|
+
id: string;
|
|
360
|
+
/** First 12 characters of the key for identification */
|
|
361
|
+
key_prefix: string;
|
|
362
|
+
/** Full API key (only returned on creation, starts with zai_) */
|
|
363
|
+
full_key?: string;
|
|
364
|
+
/** Human-readable name for the agent */
|
|
365
|
+
name: string;
|
|
366
|
+
/** Permissions granted to this key */
|
|
367
|
+
scopes: ApiKeyScope[];
|
|
368
|
+
/** Maximum API calls per hour */
|
|
369
|
+
rate_limit_per_hour: number;
|
|
370
|
+
/** Agent metadata (agent_id, agent_name, etc.) */
|
|
371
|
+
agent_metadata: Record<string, unknown>;
|
|
372
|
+
/** ISO 8601 timestamp */
|
|
373
|
+
created_at: string;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Request to create an agent API key
|
|
377
|
+
*/
|
|
378
|
+
interface CreateAgentApiKeyRequest {
|
|
379
|
+
/** Human-readable name for the agent */
|
|
380
|
+
name: string;
|
|
381
|
+
/** Unique identifier for the agent (e.g., "shopping-assistant-v1") */
|
|
382
|
+
agent_id: string;
|
|
383
|
+
/** Display name for the agent */
|
|
384
|
+
agent_name?: string;
|
|
385
|
+
/** Permissions to grant (defaults to ['create_payments']) */
|
|
386
|
+
scopes?: ApiKeyScope[];
|
|
387
|
+
/** Maximum API calls per hour (defaults to 1000) */
|
|
388
|
+
rate_limit_per_hour?: number;
|
|
389
|
+
/** Additional metadata */
|
|
390
|
+
metadata?: Record<string, unknown>;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Session spending limits for AI agents
|
|
394
|
+
*/
|
|
395
|
+
interface SessionLimits {
|
|
396
|
+
/** Maximum USD per single transaction (default: 1000) */
|
|
397
|
+
max_per_transaction?: number;
|
|
398
|
+
/** Maximum USD per day (default: 5000) */
|
|
399
|
+
max_per_day?: number;
|
|
400
|
+
/** Maximum USD per week (default: 20000) */
|
|
401
|
+
max_per_week?: number;
|
|
402
|
+
/** Maximum USD per month (default: 50000) */
|
|
403
|
+
max_per_month?: number;
|
|
404
|
+
/** Require approval for transactions above this amount (default: 500) */
|
|
405
|
+
require_approval_above?: number;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Agent Session - Time-bounded spending authorization
|
|
409
|
+
*/
|
|
410
|
+
interface AgentSession {
|
|
411
|
+
/** Unique identifier (UUID) */
|
|
412
|
+
id: string;
|
|
413
|
+
/** Session token for API calls (zai_session_...) */
|
|
414
|
+
session_token: string;
|
|
415
|
+
/** Agent identifier */
|
|
416
|
+
agent_id: string;
|
|
417
|
+
/** Display name */
|
|
418
|
+
agent_name?: string;
|
|
419
|
+
/** User's Solana wallet address */
|
|
420
|
+
user_wallet: string;
|
|
421
|
+
/** Spending limits for this session */
|
|
422
|
+
limits: SessionLimits;
|
|
423
|
+
/** Whether the session is active */
|
|
424
|
+
is_active: boolean;
|
|
425
|
+
/** ISO 8601 timestamp */
|
|
426
|
+
created_at: string;
|
|
427
|
+
/** When the session expires (ISO 8601) */
|
|
428
|
+
expires_at: string;
|
|
429
|
+
/** Remaining daily spending allowance */
|
|
430
|
+
remaining_today: number;
|
|
431
|
+
/** Remaining weekly spending allowance */
|
|
432
|
+
remaining_this_week: number;
|
|
433
|
+
/** Remaining monthly spending allowance */
|
|
434
|
+
remaining_this_month: number;
|
|
435
|
+
/** Whether a PKP was minted for on-chain session identity */
|
|
436
|
+
mint_pkp?: boolean;
|
|
437
|
+
/** PKP Ethereum address (if mint_pkp was true) */
|
|
438
|
+
pkp_address?: string;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Request to create an agent session
|
|
442
|
+
*/
|
|
443
|
+
interface CreateAgentSessionRequest {
|
|
444
|
+
/** Unique identifier for the agent */
|
|
445
|
+
agent_id: string;
|
|
446
|
+
/** Display name for the agent */
|
|
447
|
+
agent_name?: string;
|
|
448
|
+
/** User's Solana wallet address */
|
|
449
|
+
user_wallet: string;
|
|
450
|
+
/** Spending limits (uses defaults if not provided) */
|
|
451
|
+
limits?: SessionLimits;
|
|
452
|
+
/** Restrict to specific merchants (UUIDs) */
|
|
453
|
+
allowed_merchants?: string[];
|
|
454
|
+
/** Session duration in hours (default: 24, max: 168) */
|
|
455
|
+
duration_hours?: number;
|
|
456
|
+
/**
|
|
457
|
+
* Mint a PKP for on-chain session identity (audit trail).
|
|
458
|
+
* Creates a blockchain-verified session identity via Lit Protocol.
|
|
459
|
+
* Note: Spending limits are enforced server-side.
|
|
460
|
+
*/
|
|
461
|
+
mint_pkp?: boolean;
|
|
462
|
+
/** Additional metadata */
|
|
463
|
+
metadata?: Record<string, unknown>;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Payment Intent Status
|
|
467
|
+
*/
|
|
468
|
+
type PaymentIntentStatus = 'requires_payment' | 'processing' | 'succeeded' | 'canceled' | 'failed';
|
|
469
|
+
/**
|
|
470
|
+
* Capture method for payment intents
|
|
471
|
+
*/
|
|
472
|
+
type CaptureMethod = 'automatic' | 'manual';
|
|
473
|
+
/**
|
|
474
|
+
* Payment Intent - Two-phase payment flow
|
|
475
|
+
*/
|
|
476
|
+
interface PaymentIntent {
|
|
477
|
+
/** Unique identifier (UUID) */
|
|
478
|
+
id: string;
|
|
479
|
+
/** Secret for confirming the intent (keep secure) */
|
|
480
|
+
client_secret: string;
|
|
481
|
+
/** Amount in USD */
|
|
482
|
+
amount: number;
|
|
483
|
+
/** Currency code */
|
|
484
|
+
currency: string;
|
|
485
|
+
/** Description of the payment */
|
|
486
|
+
description?: string;
|
|
487
|
+
/** Current status */
|
|
488
|
+
status: PaymentIntentStatus;
|
|
489
|
+
/** How to capture the payment */
|
|
490
|
+
capture_method: CaptureMethod;
|
|
491
|
+
/** Agent that created this intent */
|
|
492
|
+
agent_id?: string;
|
|
493
|
+
/** Linked payment ID (after confirmation) */
|
|
494
|
+
payment_id?: string;
|
|
495
|
+
/** ISO 8601 timestamp */
|
|
496
|
+
created_at: string;
|
|
497
|
+
/** When the intent expires (ISO 8601) */
|
|
498
|
+
expires_at: string;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Request to create a payment intent
|
|
502
|
+
*/
|
|
503
|
+
interface CreatePaymentIntentRequest {
|
|
504
|
+
/** Amount in USD (must be > 0) */
|
|
505
|
+
amount: number;
|
|
506
|
+
/** Currency code (default: "USD") */
|
|
507
|
+
currency?: string;
|
|
508
|
+
/** Description of the payment */
|
|
509
|
+
description?: string;
|
|
510
|
+
/** Capture method (default: "automatic") */
|
|
511
|
+
capture_method?: CaptureMethod;
|
|
512
|
+
/** Agent identifier */
|
|
513
|
+
agent_id?: string;
|
|
514
|
+
/** Agent display name */
|
|
515
|
+
agent_name?: string;
|
|
516
|
+
/** Additional metadata */
|
|
517
|
+
metadata?: Record<string, unknown>;
|
|
518
|
+
/** Time until expiration in seconds (default: 86400 = 24h) */
|
|
519
|
+
expires_in_seconds?: number;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Request to confirm a payment intent
|
|
523
|
+
*/
|
|
524
|
+
interface ConfirmPaymentIntentRequest {
|
|
525
|
+
/** The client_secret from the payment intent */
|
|
526
|
+
client_secret: string;
|
|
527
|
+
/** Customer's Solana wallet address */
|
|
528
|
+
customer_wallet: string;
|
|
529
|
+
/** Payment type (optional) */
|
|
530
|
+
payment_type?: string;
|
|
531
|
+
/** Enable gasless transaction (optional) */
|
|
532
|
+
auto_gasless?: boolean;
|
|
533
|
+
/** Additional metadata */
|
|
534
|
+
metadata?: Record<string, unknown>;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Payment Intent Event
|
|
538
|
+
*/
|
|
539
|
+
interface PaymentIntentEvent {
|
|
540
|
+
/** Event ID */
|
|
541
|
+
id: string;
|
|
542
|
+
/** Payment Intent ID */
|
|
543
|
+
payment_intent_id: string;
|
|
544
|
+
/** Event type */
|
|
545
|
+
event_type: string;
|
|
546
|
+
/** Event data */
|
|
547
|
+
data: Record<string, unknown>;
|
|
548
|
+
/** ISO 8601 timestamp */
|
|
549
|
+
created_at: string;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Purchasing Power Parity factor for a country
|
|
553
|
+
*/
|
|
554
|
+
interface PPPFactor {
|
|
555
|
+
/** ISO country code (e.g., "BR", "NG", "IN") */
|
|
556
|
+
country_code: string;
|
|
557
|
+
/** Full country name */
|
|
558
|
+
country_name: string;
|
|
559
|
+
/** PPP adjustment factor (0.0 - 1.0) */
|
|
560
|
+
ppp_factor: number;
|
|
561
|
+
/** Local currency code */
|
|
562
|
+
currency_code: string;
|
|
563
|
+
/** Suggested discount percentage */
|
|
564
|
+
adjustment_percentage: number;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* User profile for pricing decisions
|
|
568
|
+
*/
|
|
569
|
+
interface UserProfile {
|
|
570
|
+
/** ISO country code */
|
|
571
|
+
location_country?: string;
|
|
572
|
+
/** Wallet transaction history (for loyalty detection) */
|
|
573
|
+
wallet_history?: Record<string, unknown>;
|
|
574
|
+
/** Context hint (e.g., "first-time", "loyal", "churning") */
|
|
575
|
+
context?: string;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* PPP pricing configuration
|
|
579
|
+
*/
|
|
580
|
+
interface PPPConfig {
|
|
581
|
+
/** Enable PPP adjustments (default: true) */
|
|
582
|
+
enabled?: boolean;
|
|
583
|
+
/** Minimum PPP factor to apply */
|
|
584
|
+
min_factor?: number;
|
|
585
|
+
/** Maximum PPP factor to apply */
|
|
586
|
+
max_factor?: number;
|
|
587
|
+
/** Absolute minimum price in USD */
|
|
588
|
+
floor_price?: number;
|
|
589
|
+
/** Absolute maximum price in USD */
|
|
590
|
+
ceiling_price?: number;
|
|
591
|
+
/** Maximum discount percentage */
|
|
592
|
+
max_discount_percent?: number;
|
|
593
|
+
/** Additional discount percentage on top of PPP */
|
|
594
|
+
extra_discount_percent?: number;
|
|
595
|
+
/** Custom reasoning text */
|
|
596
|
+
custom_reasoning?: string;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Request for AI-powered pricing suggestion
|
|
600
|
+
*/
|
|
601
|
+
interface PricingSuggestionRequest {
|
|
602
|
+
/** Agent identifier */
|
|
603
|
+
agent_id: string;
|
|
604
|
+
/** Product identifier (optional) */
|
|
605
|
+
product_id?: string;
|
|
606
|
+
/** Base price in USD (must be > 0) */
|
|
607
|
+
base_price: number;
|
|
608
|
+
/** Currency code (default: "USD") */
|
|
609
|
+
currency?: string;
|
|
610
|
+
/** User profile for personalization */
|
|
611
|
+
user_profile?: UserProfile;
|
|
612
|
+
/** PPP configuration overrides */
|
|
613
|
+
ppp_config?: PPPConfig;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* AI-powered pricing suggestion response
|
|
617
|
+
*/
|
|
618
|
+
interface PricingSuggestion {
|
|
619
|
+
/** Suggested price in USD */
|
|
620
|
+
suggested_amount: number;
|
|
621
|
+
/** Minimum acceptable price */
|
|
622
|
+
min_amount: number;
|
|
623
|
+
/** Maximum suggested price */
|
|
624
|
+
max_amount: number;
|
|
625
|
+
/** Currency code */
|
|
626
|
+
currency: string;
|
|
627
|
+
/** Human-readable explanation */
|
|
628
|
+
reasoning: string;
|
|
629
|
+
/** Whether PPP was applied */
|
|
630
|
+
ppp_adjusted: boolean;
|
|
631
|
+
/** PPP factor used (if applied) */
|
|
632
|
+
adjustment_factor?: number;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Autonomous Delegate - Enables agent to sign transactions
|
|
636
|
+
*/
|
|
637
|
+
interface AutonomousDelegate {
|
|
638
|
+
/** Unique identifier (UUID) */
|
|
639
|
+
id: string;
|
|
640
|
+
/** Session key this delegate is attached to */
|
|
641
|
+
session_key_id: string;
|
|
642
|
+
/** Whether the delegate is active */
|
|
643
|
+
is_active: boolean;
|
|
644
|
+
/** Maximum spending in USD */
|
|
645
|
+
max_amount_usd: number;
|
|
646
|
+
/** Amount already spent */
|
|
647
|
+
used_amount_usd: number;
|
|
648
|
+
/** Remaining spending allowance */
|
|
649
|
+
remaining_usd: number;
|
|
650
|
+
/** When the delegate expires (ISO 8601) */
|
|
651
|
+
expires_at: string;
|
|
652
|
+
/** When the delegate was created (ISO 8601) */
|
|
653
|
+
created_at: string;
|
|
654
|
+
/** When the delegate was revoked (if applicable) */
|
|
655
|
+
revoked_at?: string;
|
|
656
|
+
/** Last time the delegate was used */
|
|
657
|
+
last_used_at?: string;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Request to enable autonomous signing
|
|
661
|
+
*/
|
|
662
|
+
interface EnableAutonomyRequest {
|
|
663
|
+
/** Maximum spending in USD (must be > 0) */
|
|
664
|
+
max_amount_usd: number;
|
|
665
|
+
/** Duration in hours (1-168, max 7 days) */
|
|
666
|
+
duration_hours: number;
|
|
667
|
+
/** Ed25519 delegation signature (base64) */
|
|
668
|
+
delegation_signature: string;
|
|
669
|
+
/** Explicit expiration time (ISO 8601, optional) */
|
|
670
|
+
expires_at?: string;
|
|
671
|
+
/** Lit Protocol encrypted keypair (for device-bound keys) */
|
|
672
|
+
lit_encrypted_keypair?: string;
|
|
673
|
+
/** Hash of Lit Protocol encrypted data */
|
|
674
|
+
lit_data_hash?: string;
|
|
675
|
+
/** Additional metadata */
|
|
676
|
+
metadata?: Record<string, unknown>;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Response from enabling autonomous signing
|
|
680
|
+
*/
|
|
681
|
+
interface EnableAutonomyResponse {
|
|
682
|
+
/** Delegate ID (UUID) */
|
|
683
|
+
delegate_id: string;
|
|
684
|
+
/** Session key ID (UUID) */
|
|
685
|
+
session_key_id: string;
|
|
686
|
+
/** Maximum spending in USD */
|
|
687
|
+
max_amount_usd: number;
|
|
688
|
+
/** When the delegate expires (ISO 8601) */
|
|
689
|
+
expires_at: string;
|
|
690
|
+
/** Public key of the delegate (base58) */
|
|
691
|
+
delegate_public_key: string;
|
|
692
|
+
/** Confirmation that autonomous mode is enabled */
|
|
693
|
+
autonomous_mode_enabled: boolean;
|
|
694
|
+
/** Whether Lit Protocol is being used */
|
|
695
|
+
lit_protocol_enabled: boolean;
|
|
696
|
+
/** True if device-bound key without Lit (fallback to client signing) */
|
|
697
|
+
requires_lit_for_auto_sign?: boolean;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Request to revoke autonomous mode
|
|
701
|
+
*/
|
|
702
|
+
interface RevokeAutonomyRequest {
|
|
703
|
+
/** Reason for revocation (optional) */
|
|
704
|
+
reason?: string;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Autonomy status response
|
|
708
|
+
*/
|
|
709
|
+
interface AutonomyStatus {
|
|
710
|
+
/** Whether autonomous mode is enabled */
|
|
711
|
+
autonomous_mode_enabled: boolean;
|
|
712
|
+
/** Active delegate (if any) */
|
|
713
|
+
delegate?: AutonomousDelegate;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Request for AI-powered smart payment
|
|
717
|
+
*/
|
|
718
|
+
interface SmartPaymentRequest {
|
|
719
|
+
/** Session token for limit enforcement (optional) */
|
|
720
|
+
session_token?: string;
|
|
721
|
+
/** Agent identifier */
|
|
722
|
+
agent_id: string;
|
|
723
|
+
/** User's Solana wallet address */
|
|
724
|
+
user_wallet: string;
|
|
725
|
+
/** Amount in USD (must be > 0) */
|
|
726
|
+
amount_usd: number;
|
|
727
|
+
/** Target merchant ID (optional) */
|
|
728
|
+
merchant_id?: string;
|
|
729
|
+
/** Token to use (default: "USDC") */
|
|
730
|
+
token?: PaymentToken;
|
|
731
|
+
/** Auto-detect if gasless is needed (optional) */
|
|
732
|
+
auto_detect_gasless?: boolean;
|
|
733
|
+
/** Enable instant settlement (optional) */
|
|
734
|
+
instant_settlement?: boolean;
|
|
735
|
+
/** Create escrow for this payment (optional) */
|
|
736
|
+
enable_escrow?: boolean;
|
|
737
|
+
/** Payment description */
|
|
738
|
+
description?: string;
|
|
739
|
+
/** Product details for receipt */
|
|
740
|
+
product_details?: Record<string, unknown>;
|
|
741
|
+
/** Additional metadata */
|
|
742
|
+
metadata?: Record<string, unknown>;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Smart Payment Status
|
|
746
|
+
*/
|
|
747
|
+
type SmartPaymentStatus = 'pending' | 'confirmed' | 'awaiting_signature' | 'failed';
|
|
748
|
+
/**
|
|
749
|
+
* Response from smart payment
|
|
750
|
+
*/
|
|
751
|
+
interface SmartPaymentResponse {
|
|
752
|
+
/** Payment ID (UUID) */
|
|
753
|
+
payment_id: string;
|
|
754
|
+
/** Current status */
|
|
755
|
+
status: SmartPaymentStatus;
|
|
756
|
+
/** Amount in USD */
|
|
757
|
+
amount_usd: number;
|
|
758
|
+
/** Whether gasless transaction was used */
|
|
759
|
+
gasless_used: boolean;
|
|
760
|
+
/** Whether settlement is complete */
|
|
761
|
+
settlement_complete: boolean;
|
|
762
|
+
/** Escrow ID if escrow was enabled */
|
|
763
|
+
escrow_id?: string;
|
|
764
|
+
/** Base64 encoded transaction (for signing) */
|
|
765
|
+
unsigned_transaction?: string;
|
|
766
|
+
/** Whether client signature is required */
|
|
767
|
+
requires_signature: boolean;
|
|
768
|
+
/** Transaction signature (if auto-signed) */
|
|
769
|
+
transaction_signature?: string;
|
|
770
|
+
/** Confirmation time in milliseconds */
|
|
771
|
+
confirmed_in_ms?: number;
|
|
772
|
+
/** URL to payment receipt */
|
|
773
|
+
receipt_url: string;
|
|
774
|
+
/** NFT receipt address (if minted) */
|
|
775
|
+
receipt_nft?: string;
|
|
776
|
+
/** Human-readable next steps */
|
|
777
|
+
next_steps: string;
|
|
778
|
+
/** URL to submit signed transaction */
|
|
779
|
+
submit_url?: string;
|
|
780
|
+
/** ISO 8601 timestamp */
|
|
781
|
+
created_at: string;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Analytics data for an agent
|
|
785
|
+
*/
|
|
786
|
+
interface AgentAnalytics {
|
|
787
|
+
/** Total number of payments */
|
|
788
|
+
total_payments: number;
|
|
789
|
+
/** Total volume in USD */
|
|
790
|
+
total_volume_usd: number;
|
|
791
|
+
/** Average payment amount in USD */
|
|
792
|
+
average_payment_usd: number;
|
|
793
|
+
/** Payment success rate (0-1) */
|
|
794
|
+
success_rate: number;
|
|
795
|
+
/** Number of active sessions */
|
|
796
|
+
active_sessions: number;
|
|
797
|
+
/** Number of active autonomous delegates */
|
|
798
|
+
active_delegates: number;
|
|
799
|
+
/** Total PPP savings in USD */
|
|
800
|
+
ppp_savings_usd: number;
|
|
801
|
+
/** Payments broken down by token */
|
|
802
|
+
payments_by_token: Record<PaymentToken, number>;
|
|
803
|
+
/** Daily payment statistics */
|
|
804
|
+
payments_by_day: Array<{
|
|
805
|
+
date: string;
|
|
806
|
+
count: number;
|
|
807
|
+
volume_usd: number;
|
|
808
|
+
}>;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* ZendFi Webhook Handlers
|
|
813
|
+
* Type-safe webhook handlers with automatic verification and deduplication
|
|
814
|
+
*/
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Webhook handler configuration
|
|
818
|
+
*/
|
|
819
|
+
interface WebhookHandlerConfig {
|
|
820
|
+
/** Your webhook secret from ZendFi dashboard */
|
|
821
|
+
secret: string;
|
|
822
|
+
/** Optional: Path to store processed webhook IDs (for deduplication) */
|
|
823
|
+
onProcessed?: (webhookId: string) => Promise<void>;
|
|
824
|
+
/** Optional: Check if webhook was already processed */
|
|
825
|
+
isProcessed?: (webhookId: string) => Promise<boolean>;
|
|
826
|
+
/** Optional: Custom error handler */
|
|
827
|
+
onError?: (error: Error, event?: WebhookEvent) => void | Promise<void>;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Event handler function type
|
|
831
|
+
*/
|
|
832
|
+
type WebhookEventHandler<T = any> = (data: T, event: WebhookPayload) => void | Promise<void>;
|
|
833
|
+
/**
|
|
834
|
+
* Webhook handlers map - type-safe event handlers
|
|
835
|
+
*/
|
|
836
|
+
type WebhookHandlers = Partial<{
|
|
837
|
+
'payment.created': WebhookEventHandler;
|
|
838
|
+
'payment.confirmed': WebhookEventHandler;
|
|
839
|
+
'payment.failed': WebhookEventHandler;
|
|
840
|
+
'payment.expired': WebhookEventHandler;
|
|
841
|
+
'subscription.created': WebhookEventHandler;
|
|
842
|
+
'subscription.activated': WebhookEventHandler;
|
|
843
|
+
'subscription.canceled': WebhookEventHandler;
|
|
844
|
+
'subscription.payment_failed': WebhookEventHandler;
|
|
845
|
+
'split.completed': WebhookEventHandler;
|
|
846
|
+
'split.failed': WebhookEventHandler;
|
|
847
|
+
'installment.due': WebhookEventHandler;
|
|
848
|
+
'installment.paid': WebhookEventHandler;
|
|
849
|
+
'installment.late': WebhookEventHandler;
|
|
850
|
+
'escrow.funded': WebhookEventHandler;
|
|
851
|
+
'escrow.released': WebhookEventHandler;
|
|
852
|
+
'escrow.refunded': WebhookEventHandler;
|
|
853
|
+
'escrow.disputed': WebhookEventHandler;
|
|
854
|
+
'invoice.sent': WebhookEventHandler;
|
|
855
|
+
'invoice.paid': WebhookEventHandler;
|
|
856
|
+
}>;
|
|
857
|
+
/**
|
|
858
|
+
* Webhook processing result
|
|
859
|
+
*/
|
|
860
|
+
interface WebhookResult {
|
|
861
|
+
success: boolean;
|
|
862
|
+
processed: boolean;
|
|
863
|
+
error?: string;
|
|
864
|
+
event?: WebhookEvent;
|
|
865
|
+
statusCode?: number;
|
|
866
|
+
}
|
|
867
|
+
declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
|
|
868
|
+
|
|
869
|
+
export { type PaymentLinkCode as $, type AgentApiKey as A, type CreateInvoiceRequest as B, type CreateAgentApiKeyRequest as C, type DisputeEscrowRequest as D, type EnableAutonomyRequest as E, type Invoice as F, type WebhookPayload as G, processWebhook as H, type InstallmentPlan as I, type WebhookResult as J, type WebhookEventHandler as K, type ListPaymentsRequest as L, type Brand as M, type PaymentId as N, type SessionId as O, type PaymentIntent as P, type AgentKeyId as Q, type RefundEscrowRequest as R, type SmartPaymentRequest as S, type MerchantId as T, type InvoiceId as U, type VerifyWebhookRequest as V, type WebhookHandlerConfig as W, type SubscriptionId as X, type EscrowId as Y, type ZendFiConfig as Z, type InstallmentPlanId as _, type WebhookHandlers as a, type IntentId as a0, asPaymentId as a1, asSessionId as a2, asAgentKeyId as a3, asMerchantId as a4, asInvoiceId as a5, asSubscriptionId as a6, asEscrowId as a7, asInstallmentPlanId as a8, asPaymentLinkCode as a9, asIntentId as aa, type Environment as ab, type ApiKeyMode as ac, type Currency as ad, type PaymentToken as ae, type PaymentStatus as af, type SubscriptionStatus as ag, type InstallmentPlanStatus as ah, type EscrowStatus as ai, type InvoiceStatus as aj, type SplitStatus as ak, type WebhookEvent as al, type SplitRecipient as am, type InstallmentScheduleItem as an, type CreateInstallmentPlanResponse as ao, type ReleaseCondition as ap, type InvoiceLineItem as aq, type ApiKeyScope as ar, type SessionLimits as as, type PaymentIntentStatus as at, type CaptureMethod as au, type UserProfile as av, type PPPConfig as aw, type AutonomousDelegate as ax, type RevokeAutonomyRequest as ay, type SmartPaymentStatus as az, type CreateAgentSessionRequest as b, type AgentSession as c, type AgentAnalytics as d, type CreatePaymentIntentRequest as e, type ConfirmPaymentIntentRequest as f, type PaymentIntentEvent as g, type PPPFactor as h, type PricingSuggestionRequest as i, type PricingSuggestion as j, type EnableAutonomyResponse as k, type AutonomyStatus as l, type SmartPaymentResponse as m, type CreatePaymentRequest as n, type Payment as o, type PaginatedResponse as p, type CreateSubscriptionPlanRequest as q, type SubscriptionPlan as r, type CreateSubscriptionRequest as s, type Subscription as t, type CreatePaymentLinkRequest as u, type PaymentLink as v, type CreateInstallmentPlanRequest as w, type CreateEscrowRequest as x, type Escrow as y, type ApproveEscrowRequest as z };
|