@zendfi/sdk 0.8.4 → 1.0.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 +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/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# @zendfi/sdk
|
|
2
2
|
|
|
3
|
-
> The
|
|
3
|
+
> The simplest crypto payment SDK for Solana
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@zendfi/sdk)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
Accept **SOL, USDC, and USDT** payments in 7 lines of code. Built for e-commerce.
|
|
8
|
+
Accept **SOL, USDC, and USDT** payments in 7 lines of code. Built for e-commerce.
|
|
9
9
|
|
|
10
10
|
```typescript
|
|
11
11
|
import { zendfi } from '@zendfi/sdk';
|
|
@@ -18,7 +18,7 @@ const payment = await zendfi.createPayment({
|
|
|
18
18
|
console.log(payment.payment_url); // Send customer here
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
**That's it.**
|
|
21
|
+
**That's it.** Full type safety. Instant settlements. 0.6% fees.
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
@@ -29,10 +29,9 @@ console.log(payment.payment_url); // Send customer here
|
|
|
29
29
|
| **Fees** | 2.9% + $0.30 | 3.5% + $0.49 | **0.6% flat** |
|
|
30
30
|
| **Settlement** | 7 days | 3-5 days | **Instant** |
|
|
31
31
|
| **Crypto Native** | Via 3rd party | Via 3rd party | **Built-in** |
|
|
32
|
-
| **AI Agent Ready** | ACP | NO | **Native** |
|
|
33
32
|
| **Setup Time** | 30 min | 30 min | **5 min** |
|
|
34
33
|
|
|
35
|
-
**Save 81% on fees.** Get paid instantly.
|
|
34
|
+
**Save 81% on fees.** Get paid instantly.
|
|
36
35
|
|
|
37
36
|
---
|
|
38
37
|
|
|
@@ -52,15 +51,6 @@ console.log(payment.payment_url); // Send customer here
|
|
|
52
51
|
- **Invoices** — Professional invoicing with email
|
|
53
52
|
- **Payment Splits** — Revenue sharing for marketplaces
|
|
54
53
|
|
|
55
|
-
### **AI-Ready** (Optional Advanced)
|
|
56
|
-
- **Agent Keys** — Scoped API keys for AI with spending limits
|
|
57
|
-
- **Session Keys** — Pre-funded wallets for autonomous payments
|
|
58
|
-
- **Payment Intents** — Two-phase commit for reliable checkout
|
|
59
|
-
- **PPP Pricing** — Auto-adjust prices for 27+ countries
|
|
60
|
-
- **Smart Payments** — AI-optimized payment routing
|
|
61
|
-
|
|
62
|
-
Don't need AI features? **Ignore them.** The SDK works perfectly for traditional payments.
|
|
63
|
-
|
|
64
54
|
---
|
|
65
55
|
|
|
66
56
|
## Installation
|
|
@@ -215,7 +205,7 @@ When ready for production:
|
|
|
215
205
|
|
|
216
206
|
---
|
|
217
207
|
|
|
218
|
-
## Pricing
|
|
208
|
+
## Pricing
|
|
219
209
|
|
|
220
210
|
**Platform Fee: 0.6%** (all-inclusive)
|
|
221
211
|
|
|
@@ -233,79 +223,19 @@ This covers:
|
|
|
233
223
|
|
|
234
224
|
---
|
|
235
225
|
|
|
236
|
-
## AI-Ready Features (Optional Advanced)
|
|
237
|
-
|
|
238
|
-
Building AI agents? ZendFi has native support for autonomous payments with cryptographic security and spending limits.
|
|
239
|
-
|
|
240
|
-
### When Do I Need This?
|
|
241
|
-
|
|
242
|
-
**Use traditional payments if:**
|
|
243
|
-
- Building e-commerce, SaaS, or creator tools
|
|
244
|
-
- User clicks "Pay" button for each transaction
|
|
245
|
-
- Standard checkout flow
|
|
246
|
-
|
|
247
|
-
**Use AI features if:**
|
|
248
|
-
- Building AI agents that make purchases
|
|
249
|
-
- Need autonomous payments without per-transaction approval
|
|
250
|
-
- Want spending limits and scoped permissions
|
|
251
|
-
|
|
252
|
-
### Quick Example: AI Agent Payment
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
import { zendfi } from '@zendfi/sdk';
|
|
256
|
-
|
|
257
|
-
// 1. Create agent key with limited permissions
|
|
258
|
-
const agentKey = await zendfi.agent.createKey({
|
|
259
|
-
name: 'Shopping Assistant',
|
|
260
|
-
agent_id: 'shopping-assistant-v1',
|
|
261
|
-
scopes: ['create_payments'],
|
|
262
|
-
rate_limit_per_hour: 100,
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// 2. Create device-bound session key (one-time setup with PIN)
|
|
266
|
-
const sessionKey = await zendfi.sessionKeys.create({
|
|
267
|
-
userWallet: 'Hx7B...abc',
|
|
268
|
-
agentId: 'shopping-assistant-v1',
|
|
269
|
-
agentName: 'Shopping Assistant',
|
|
270
|
-
limitUSDC: 200,
|
|
271
|
-
durationDays: 1,
|
|
272
|
-
pin: '123456',
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
// 3. Unlock for payments (client-side)
|
|
276
|
-
await zendfi.sessionKeys.unlock(sessionKey.sessionKeyId, '123456');
|
|
277
|
-
|
|
278
|
-
// 4. AI agent makes payments autonomously (within limits)
|
|
279
|
-
const payment = await zendfi.sessionKeys.makePayment(
|
|
280
|
-
sessionKey.sessionKeyId,
|
|
281
|
-
{
|
|
282
|
-
recipientWallet: 'merchant-wallet',
|
|
283
|
-
amountUSD: 25.00,
|
|
284
|
-
description: 'Coffee order',
|
|
285
|
-
}
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
// Done! User approved once, AI pays within limits
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
**Learn more:** [AI Payments Documentation](https://docs.zendfi.tech/agentic)
|
|
292
|
-
|
|
293
|
-
---
|
|
294
|
-
|
|
295
226
|
## Core API Reference
|
|
296
227
|
|
|
297
|
-
###
|
|
228
|
+
### API Methods
|
|
298
229
|
|
|
299
230
|
```typescript
|
|
300
231
|
import { zendfi, ZendFiEmbeddedCheckout } from '@zendfi/sdk';
|
|
301
232
|
|
|
302
|
-
// Embedded Checkout
|
|
233
|
+
// Embedded Checkout
|
|
303
234
|
const checkout = new ZendFiEmbeddedCheckout({...});
|
|
304
235
|
|
|
305
|
-
//
|
|
236
|
+
// Payments
|
|
306
237
|
zendfi.createPayment(...)
|
|
307
238
|
zendfi.getPayment(...)
|
|
308
|
-
zendfi.listPayments(...)
|
|
309
239
|
|
|
310
240
|
// Payment Links
|
|
311
241
|
zendfi.createPaymentLink(...)
|
|
@@ -314,160 +244,65 @@ zendfi.createPaymentLink(...)
|
|
|
314
244
|
zendfi.createSubscription(...)
|
|
315
245
|
zendfi.cancelSubscription(...)
|
|
316
246
|
|
|
317
|
-
//
|
|
318
|
-
zendfi.
|
|
319
|
-
zendfi.
|
|
320
|
-
zendfi.agent.pay(...) // Autonomous payments
|
|
321
|
-
zendfi.intents.create(...) // Two-phase checkout
|
|
322
|
-
zendfi.sessionKeys.create(...) // Pre-funded wallets
|
|
323
|
-
zendfi.autonomy.enable(...) // User-granted delegation
|
|
324
|
-
zendfi.pricing.getPPPFactor(...) // Global pricing
|
|
247
|
+
// Invoices
|
|
248
|
+
zendfi.createInvoice(...)
|
|
249
|
+
zendfi.sendInvoice(...)
|
|
325
250
|
```
|
|
326
251
|
|
|
327
|
-
###
|
|
252
|
+
### Payments
|
|
328
253
|
|
|
329
|
-
Create
|
|
254
|
+
Create payments for your customers:
|
|
330
255
|
|
|
331
256
|
```typescript
|
|
332
|
-
// Create
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
rate_limit_per_hour: 500,
|
|
257
|
+
// Create a simple payment
|
|
258
|
+
const payment = await zendfi.createPayment({
|
|
259
|
+
amount: 50,
|
|
260
|
+
description: 'Premium subscription',
|
|
261
|
+
customer_email: 'customer@example.com',
|
|
338
262
|
});
|
|
339
263
|
|
|
340
|
-
//
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
// List agent keys
|
|
344
|
-
const keys = await zendfi.agent.listKeys();
|
|
345
|
-
|
|
346
|
-
// Revoke a key
|
|
347
|
-
await zendfi.agent.revokeKey(keyId);
|
|
264
|
+
// Get payment status
|
|
265
|
+
const status = await zendfi.getPayment(payment.id);
|
|
348
266
|
```
|
|
349
267
|
|
|
350
|
-
|
|
351
|
-
- `full` - Full access to all APIs
|
|
352
|
-
- `read_only` - Read-only access
|
|
353
|
-
- `create_payments` - Create new payments
|
|
354
|
-
- `create_subscriptions` - Create subscriptions
|
|
355
|
-
- `manage_escrow` - Manage escrow transactions
|
|
356
|
-
- `manage_installments` - Manage installment plans
|
|
357
|
-
- `read_analytics` - Access analytics data
|
|
358
|
-
|
|
359
|
-
### Agent Sessions
|
|
268
|
+
### Payment Links
|
|
360
269
|
|
|
361
|
-
Create
|
|
270
|
+
Create reusable payment links:
|
|
362
271
|
|
|
363
272
|
```typescript
|
|
364
|
-
// Create a
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
max_per_transaction: 50, // $50 max per payment
|
|
370
|
-
max_per_day: 200, // $200 daily limit
|
|
371
|
-
allowed_merchants: ['merchant_123'], // Optional whitelist
|
|
372
|
-
},
|
|
373
|
-
duration_hours: 24,
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
// Make payments within the session (spending limits enforced!)
|
|
377
|
-
const payment = await zendfi.agent.pay({
|
|
378
|
-
session_token: session.session_token,
|
|
379
|
-
amount: 29.99,
|
|
380
|
-
description: 'Premium widget',
|
|
381
|
-
auto_gasless: true,
|
|
273
|
+
// Create a payment link
|
|
274
|
+
const link = await zendfi.createPaymentLink({
|
|
275
|
+
amount: 99.99,
|
|
276
|
+
description: 'Pro Plan',
|
|
277
|
+
max_uses: 100,
|
|
382
278
|
});
|
|
383
279
|
|
|
384
|
-
|
|
385
|
-
// Device-bound: user must sign
|
|
386
|
-
console.log('Sign transaction:', payment.unsigned_transaction);
|
|
387
|
-
console.log('Submit to:', payment.submit_url);
|
|
388
|
-
} else {
|
|
389
|
-
// Auto-signed: payment complete
|
|
390
|
-
console.log('Payment confirmed:', payment.transaction_signature);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// List active sessions
|
|
394
|
-
const sessions = await zendfi.agent.listSessions();
|
|
395
|
-
|
|
396
|
-
// Get specific session
|
|
397
|
-
const session = await zendfi.agent.getSession(sessionId);
|
|
398
|
-
|
|
399
|
-
// Revoke session
|
|
400
|
-
await zendfi.agent.revokeSession(sessionId);
|
|
280
|
+
console.log(link.url); // Share with customers
|
|
401
281
|
```
|
|
402
282
|
|
|
403
|
-
###
|
|
283
|
+
### Subscriptions
|
|
404
284
|
|
|
405
|
-
|
|
285
|
+
Set up recurring billing:
|
|
406
286
|
|
|
407
287
|
```typescript
|
|
408
|
-
//
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
288
|
+
// Create a subscription plan
|
|
289
|
+
const plan = await zendfi.createSubscriptionPlan({
|
|
290
|
+
name: 'Pro Plan',
|
|
291
|
+
amount: 29.99,
|
|
292
|
+
interval: 'monthly',
|
|
293
|
+
trial_days: 14,
|
|
413
294
|
});
|
|
414
295
|
|
|
415
|
-
//
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const confirmed = await zendfi.intents.confirm(intent.id, {
|
|
420
|
-
client_secret: intent.client_secret,
|
|
421
|
-
customer_wallet: 'Hx7B...abc',
|
|
296
|
+
// Subscribe a customer
|
|
297
|
+
const subscription = await zendfi.createSubscription({
|
|
298
|
+
plan_id: plan.id,
|
|
299
|
+
customer_email: 'customer@example.com',
|
|
422
300
|
});
|
|
423
301
|
|
|
424
|
-
//
|
|
425
|
-
await zendfi.
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
**Intent Statuses:**
|
|
429
|
-
- `requires_payment` - Waiting for confirmation
|
|
430
|
-
- `processing` - Payment in progress
|
|
431
|
-
- `succeeded` - Payment complete
|
|
432
|
-
- `canceled` - Canceled by user/merchant
|
|
433
|
-
- `failed` - Payment failed
|
|
434
|
-
|
|
435
|
-
### PPP Pricing (Purchasing Power Parity)
|
|
436
|
-
|
|
437
|
-
Automatically adjust prices based on customer location:
|
|
438
|
-
|
|
439
|
-
```typescript
|
|
440
|
-
// Get PPP factor for a country
|
|
441
|
-
const factor = await zendfi.pricing.getPPPFactor('BR');
|
|
442
|
-
// {
|
|
443
|
-
// country_code: 'BR',
|
|
444
|
-
// country_name: 'Brazil',
|
|
445
|
-
// ppp_factor: 0.35,
|
|
446
|
-
// adjustment_percentage: 35.0,
|
|
447
|
-
// currency_code: 'BRL'
|
|
448
|
-
// }
|
|
449
|
-
|
|
450
|
-
// Calculate localized price
|
|
451
|
-
const basePrice = 100;
|
|
452
|
-
const localPrice = basePrice * factor.ppp_factor;
|
|
453
|
-
console.log(`$${localPrice} for Brazilian customers`); // $35
|
|
454
|
-
|
|
455
|
-
// List all supported countries
|
|
456
|
-
const factors = await zendfi.pricing.listFactors();
|
|
457
|
-
|
|
458
|
-
// Get AI pricing suggestion
|
|
459
|
-
const suggestion = await zendfi.pricing.getSuggestion({
|
|
460
|
-
agent_id: 'my-agent',
|
|
461
|
-
base_price: 99.99,
|
|
462
|
-
user_profile: {
|
|
463
|
-
location_country: 'BR',
|
|
464
|
-
},
|
|
465
|
-
});
|
|
302
|
+
// Cancel subscription
|
|
303
|
+
await zendfi.cancelSubscription(subscription.id);
|
|
466
304
|
```
|
|
467
305
|
|
|
468
|
-
**Supported Countries (27+):**
|
|
469
|
-
Argentina, Australia, Brazil, Canada, China, Colombia, Egypt, France, Germany, Ghana, Hong Kong, Hungary, India, Indonesia, Israel, Japan, Kenya, Mexico, Nigeria, Philippines, Poland, South Africa, Thailand, Turkey, Ukraine, United Kingdom, Vietnam, and more.
|
|
470
|
-
|
|
471
306
|
---
|
|
472
307
|
|
|
473
308
|
## Optional Helper Utilities
|
|
@@ -476,7 +311,6 @@ Production-ready utilities to simplify common integration patterns. All helpers
|
|
|
476
311
|
|
|
477
312
|
```typescript
|
|
478
313
|
import {
|
|
479
|
-
SessionKeyCache,
|
|
480
314
|
WalletConnector,
|
|
481
315
|
TransactionPoller,
|
|
482
316
|
DevTools
|
|
@@ -488,42 +322,18 @@ import {
|
|
|
488
322
|
- **Optional**: Import only what you need
|
|
489
323
|
- **Tree-shakeable**: Unused code eliminated by bundlers
|
|
490
324
|
- **Zero config**: Sensible defaults, works out of the box
|
|
491
|
-
- **Pluggable**: Bring your own storage
|
|
325
|
+
- **Pluggable**: Bring your own storage providers
|
|
492
326
|
- **Production-ready**: Full TypeScript types, error handling
|
|
493
327
|
|
|
494
328
|
### Available Helpers
|
|
495
329
|
|
|
496
330
|
| Helper | Purpose | Use Case |
|
|
497
331
|
|--------|---------|----------|
|
|
498
|
-
| `SessionKeyCache` | Cache encrypted session keys | Avoid re-prompting for PIN |
|
|
499
332
|
| `WalletConnector` | Detect & connect Solana wallets | Phantom, Solflare, Backpack |
|
|
500
|
-
| `PaymentIntentParser` | Parse natural language to payments | AI chat interfaces |
|
|
501
|
-
| `PINValidator` | Validate PIN strength | Device-bound security |
|
|
502
333
|
| `TransactionPoller` | Poll for confirmations | Wait for on-chain finality |
|
|
503
334
|
| `RetryStrategy` | Exponential backoff retries | Handle network failures |
|
|
504
|
-
| `SessionKeyLifecycle` | High-level session key manager | One-liner setup |
|
|
505
335
|
| `DevTools` | Debug mode & test utilities | Development & testing |
|
|
506
336
|
|
|
507
|
-
### Session Key Cache
|
|
508
|
-
|
|
509
|
-
Cache encrypted session keys to avoid re-prompting users for their PIN:
|
|
510
|
-
|
|
511
|
-
```typescript
|
|
512
|
-
import { SessionKeyCache, QuickCaches } from '@zendfi/sdk/helpers';
|
|
513
|
-
|
|
514
|
-
// Use presets
|
|
515
|
-
const cache = QuickCaches.persistent(); // 1 hour localStorage
|
|
516
|
-
|
|
517
|
-
// Use with device-bound session keys
|
|
518
|
-
const keypair = await cache.getCached(
|
|
519
|
-
sessionKeyId,
|
|
520
|
-
async () => {
|
|
521
|
-
const pin = await promptUserForPIN();
|
|
522
|
-
return await decryptKeypair(pin);
|
|
523
|
-
}
|
|
524
|
-
);
|
|
525
|
-
```
|
|
526
|
-
|
|
527
337
|
### Wallet Connector
|
|
528
338
|
|
|
529
339
|
Auto-detect and connect to Solana wallets:
|
|
@@ -548,147 +358,7 @@ const poller = new TransactionPoller({ connection: rpcConnection });
|
|
|
548
358
|
const result = await poller.waitForConfirmation(signature);
|
|
549
359
|
```
|
|
550
360
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
High-level wrapper for complete session key management:
|
|
554
|
-
|
|
555
|
-
```typescript
|
|
556
|
-
import { SessionKeyLifecycle } from '@zendfi/sdk/helpers';
|
|
557
|
-
|
|
558
|
-
const lifecycle = new SessionKeyLifecycle(zendfi, {
|
|
559
|
-
cache: QuickCaches.persistent(),
|
|
560
|
-
autoCleanup: true,
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
await lifecycle.createAndFund({
|
|
564
|
-
userWallet: userAddress,
|
|
565
|
-
agentId: 'my-agent',
|
|
566
|
-
limitUsdc: 100,
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
await lifecycle.pay(5.00, 'Coffee');
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-
**Full documentation:** See [Helper Utilities Guide](https://docs.zendfi.tech/helpers) for complete API reference and examples.
|
|
573
|
-
|
|
574
|
-
---
|
|
575
|
-
|
|
576
|
-
### Autonomous Delegation
|
|
577
|
-
|
|
578
|
-
Enable agents to make payments without per-transaction approval:
|
|
579
|
-
|
|
580
|
-
```typescript
|
|
581
|
-
// Enable autonomous mode for a wallet
|
|
582
|
-
await zendfi.autonomy.enable(sessionKeyId, {
|
|
583
|
-
max_amount_usd: 100, // Total amount, not per-day
|
|
584
|
-
duration_hours: 24, // Duration
|
|
585
|
-
delegation_signature: sig, // Required signature
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
// Check autonomy status
|
|
589
|
-
const status = await zendfi.autonomy.getStatus(walletAddress);
|
|
590
|
-
|
|
591
|
-
// Revoke delegation
|
|
592
|
-
await zendfi.autonomy.revoke(delegateId);
|
|
593
|
-
```
|
|
594
|
-
|
|
595
|
-
### Session Keys (Device-Bound Non-Custodial)
|
|
596
|
-
|
|
597
|
-
Session keys are TRUE non-custodial wallets where:
|
|
598
|
-
- **Client generates keypair** (backend NEVER sees private key)
|
|
599
|
-
- **PIN encryption** using Argon2id + AES-256-GCM
|
|
600
|
-
- **Device fingerprint binding** for security
|
|
601
|
-
- **Autonomous payments** within spending limits
|
|
602
|
-
|
|
603
|
-
**The Flow:**
|
|
604
|
-
1. **Create** - Client generates keypair, encrypts with PIN (SDK handles this)
|
|
605
|
-
2. **Unlock** - Decrypt with PIN once, enable auto-signing
|
|
606
|
-
3. **Pay** - Make payments instantly without re-entering PIN
|
|
607
|
-
|
|
608
|
-
```typescript
|
|
609
|
-
// Create a device-bound session key
|
|
610
|
-
const key = await zendfi.sessionKeys.create({
|
|
611
|
-
userWallet: 'Hx7B...abc',
|
|
612
|
-
agentId: 'shopping-assistant-v1',
|
|
613
|
-
agentName: 'AI Shopping Assistant',
|
|
614
|
-
limitUSDC: 100,
|
|
615
|
-
durationDays: 7,
|
|
616
|
-
pin: '123456', // SDK encrypts keypair with this
|
|
617
|
-
generateRecoveryQR: true,
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
console.log(`Session key: ${key.sessionKeyId}`);
|
|
621
|
-
console.log(`Session wallet: ${key.sessionWallet}`);
|
|
622
|
-
console.log(`Recovery QR: ${key.recoveryQR}`);
|
|
623
|
-
|
|
624
|
-
// Session key is auto-unlocked after create()
|
|
625
|
-
// Make payments without PIN!
|
|
626
|
-
const payment = await zendfi.sessionKeys.makePayment(
|
|
627
|
-
key.sessionKeyId,
|
|
628
|
-
{
|
|
629
|
-
recipientWallet: '8xYZA...',
|
|
630
|
-
amountUSD: 5.0,
|
|
631
|
-
description: 'Coffee purchase',
|
|
632
|
-
}
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
// Or unlock an existing session key
|
|
636
|
-
await zendfi.sessionKeys.unlock(key.sessionKeyId, '123456');
|
|
637
|
-
|
|
638
|
-
// Check status
|
|
639
|
-
const status = await zendfi.sessionKeys.getStatus(key.sessionKeyId);
|
|
640
|
-
console.log(`Active: ${status.isActive}`);
|
|
641
|
-
console.log(`Remaining: $${status.remainingUSDC}`);
|
|
642
|
-
console.log(`Spent: $${status.usedAmountUSDC}`);
|
|
643
|
-
|
|
644
|
-
// Revoke when done
|
|
645
|
-
await zendfi.sessionKeys.revoke(key.sessionKeyId);
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
**Security Features:**
|
|
649
|
-
- **Backend cannot decrypt** - Keys encrypted client-side
|
|
650
|
-
- **Device fingerprint** - Binds key to specific device
|
|
651
|
-
- **Recovery QR** - Migrate to new device
|
|
652
|
-
- **Auto-signing cache** - Instant payments after unlock
|
|
653
|
-
|
|
654
|
-
### Smart Payments
|
|
655
|
-
|
|
656
|
-
AI-powered payments that automatically apply optimizations:
|
|
657
|
-
|
|
658
|
-
```typescript
|
|
659
|
-
// Create a smart payment with automatic PPP
|
|
660
|
-
const payment = await zendfi.smart.execute({
|
|
661
|
-
agent_id: 'my-agent',
|
|
662
|
-
user_wallet: 'Hx7B...abc',
|
|
663
|
-
amount_usd: 99.99,
|
|
664
|
-
country_code: 'BR', // Apply PPP automatically
|
|
665
|
-
auto_detect_gasless: true,
|
|
666
|
-
description: 'Pro subscription',
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
// Response includes discount applied
|
|
670
|
-
console.log(`Original: $${payment.original_amount_usd}`);
|
|
671
|
-
console.log(`Final: $${payment.final_amount_usd}`);
|
|
672
|
-
// Original: $99.99
|
|
673
|
-
// Final: $64.99 (35% PPP discount applied)
|
|
674
|
-
```
|
|
675
|
-
|
|
676
|
-
#### Device-Bound Flow
|
|
677
|
-
|
|
678
|
-
For payments requiring user signatures:
|
|
679
|
-
|
|
680
|
-
```typescript
|
|
681
|
-
// After user signs the transaction locally
|
|
682
|
-
const result = await zendfi.smart.submitSigned(
|
|
683
|
-
'pay_123...',
|
|
684
|
-
signedTransactionBase64
|
|
685
|
-
);
|
|
686
|
-
|
|
687
|
-
console.log(result.status); // "confirmed"
|
|
688
|
-
console.log(result.transaction_signature);
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
> **Tip:** `zendfi.smartPayment()` is also available as an alias for `zendfi.smart.execute()`.
|
|
361
|
+
**Full documentation:** See [Helper Utilities Guide](https://docs.zendfi.tech/developer-tools/helper-utilities) for complete API reference and examples.
|
|
692
362
|
|
|
693
363
|
---
|
|
694
364
|
|
|
@@ -726,23 +396,6 @@ console.log(payment.status);
|
|
|
726
396
|
// => "Pending" | "Confirmed" | "Failed" | "Expired"
|
|
727
397
|
```
|
|
728
398
|
|
|
729
|
-
#### List Payments (with filters)
|
|
730
|
-
|
|
731
|
-
```typescript
|
|
732
|
-
const payments = await zendfi.listPayments({
|
|
733
|
-
page: 1,
|
|
734
|
-
limit: 50,
|
|
735
|
-
status: 'Confirmed',
|
|
736
|
-
from_date: '2025-01-01',
|
|
737
|
-
to_date: '2025-12-31',
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
console.log(`Found ${payments.pagination.total} payments`);
|
|
741
|
-
payments.data.forEach(payment => {
|
|
742
|
-
console.log(`${payment.id}: $${payment.amount} - ${payment.status}`);
|
|
743
|
-
});
|
|
744
|
-
```
|
|
745
|
-
|
|
746
399
|
---
|
|
747
400
|
|
|
748
401
|
### Payment Links
|
|
@@ -949,10 +602,6 @@ Get notified when payments are confirmed, subscriptions renew, etc.
|
|
|
949
602
|
'installment.due'
|
|
950
603
|
'installment.paid'
|
|
951
604
|
'installment.late'
|
|
952
|
-
'escrow.funded'
|
|
953
|
-
'escrow.released'
|
|
954
|
-
'escrow.refunded'
|
|
955
|
-
'escrow.disputed'
|
|
956
605
|
'invoice.sent'
|
|
957
606
|
'invoice.paid'
|
|
958
607
|
```
|
|
@@ -988,14 +637,9 @@ export const POST = createNextWebhookHandler({
|
|
|
988
637
|
},
|
|
989
638
|
|
|
990
639
|
'subscription.activated': async (subscription) => {
|
|
991
|
-
console.log(
|
|
640
|
+
console.log(`Subscription activated for ${subscription.customer_email}`);
|
|
992
641
|
await grantAccess(subscription.customer_email);
|
|
993
642
|
},
|
|
994
|
-
|
|
995
|
-
'escrow.released': async (escrow) => {
|
|
996
|
-
console.log(`🔓 Escrow released: $${escrow.amount}`);
|
|
997
|
-
await notifySeller(escrow.seller_email);
|
|
998
|
-
},
|
|
999
643
|
},
|
|
1000
644
|
});
|
|
1001
645
|
```
|
|
@@ -1366,40 +1010,6 @@ const subscription = await zendfi.createSubscription({
|
|
|
1366
1010
|
// - subscription.canceled → Revoke access
|
|
1367
1011
|
```
|
|
1368
1012
|
|
|
1369
|
-
### Marketplace Escrow
|
|
1370
|
-
|
|
1371
|
-
```typescript
|
|
1372
|
-
// 1. Buyer purchases from seller
|
|
1373
|
-
const escrow = await zendfi.createEscrow({
|
|
1374
|
-
amount: 500,
|
|
1375
|
-
buyer_email: buyer.email,
|
|
1376
|
-
seller_email: seller.email,
|
|
1377
|
-
buyer_wallet: buyer.wallet,
|
|
1378
|
-
seller_wallet: seller.wallet,
|
|
1379
|
-
description: 'Freelance project milestone',
|
|
1380
|
-
metadata: {
|
|
1381
|
-
project_id: project.id,
|
|
1382
|
-
milestone: 'design-complete',
|
|
1383
|
-
},
|
|
1384
|
-
});
|
|
1385
|
-
|
|
1386
|
-
// 2. Buyer pays into escrow
|
|
1387
|
-
// Funds held securely
|
|
1388
|
-
|
|
1389
|
-
// 3. When work is delivered:
|
|
1390
|
-
await zendfi.approveEscrow(escrow.id, {
|
|
1391
|
-
approved_by: buyer.email,
|
|
1392
|
-
});
|
|
1393
|
-
// Funds released to seller
|
|
1394
|
-
|
|
1395
|
-
// OR if there's an issue:
|
|
1396
|
-
await zendfi.disputeEscrow(escrow.id, {
|
|
1397
|
-
dispute_reason: 'Work incomplete',
|
|
1398
|
-
raised_by: buyer.email,
|
|
1399
|
-
});
|
|
1400
|
-
// ZendFi team mediates
|
|
1401
|
-
```
|
|
1402
|
-
|
|
1403
1013
|
---
|
|
1404
1014
|
|
|
1405
1015
|
## Troubleshooting
|
|
@@ -1537,5 +1147,3 @@ Need help? We're here for you!
|
|
|
1537
1147
|
---
|
|
1538
1148
|
|
|
1539
1149
|
**Built with ❤️ by the ZendFi team**
|
|
1540
|
-
|
|
1541
|
-
*Making crypto payments as easy as traditional payments.*
|