@settlr/sdk 0.6.5 → 0.6.7

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/dist/index.d.ts CHANGED
@@ -205,10 +205,51 @@ interface Subscription {
205
205
  trialEnd?: string;
206
206
  createdAt: string;
207
207
  }
208
+ /**
209
+ * Payout status
210
+ */
211
+ type PayoutStatus$1 = 'pending' | 'funded' | 'sent' | 'claimed' | 'expired' | 'failed';
212
+ /**
213
+ * Payout record
214
+ */
215
+ interface Payout {
216
+ id: string;
217
+ email: string;
218
+ amount: number;
219
+ currency: string;
220
+ memo?: string;
221
+ metadata?: Record<string, string>;
222
+ status: PayoutStatus$1;
223
+ claimUrl: string;
224
+ recipientWallet?: string;
225
+ txSignature?: string;
226
+ batchId?: string;
227
+ createdAt: string;
228
+ fundedAt?: string;
229
+ claimedAt?: string;
230
+ expiresAt: string;
231
+ }
232
+ /**
233
+ * Payout batch
234
+ */
235
+ interface PayoutBatch {
236
+ id: string;
237
+ status: string;
238
+ total: number;
239
+ count: number;
240
+ payouts: Array<{
241
+ id: string;
242
+ email: string;
243
+ amount: number;
244
+ status: PayoutStatus$1;
245
+ claimUrl: string;
246
+ }>;
247
+ createdAt: string;
248
+ }
208
249
  /**
209
250
  * Webhook event types
210
251
  */
211
- type WebhookEventType = 'payment.created' | 'payment.completed' | 'payment.failed' | 'payment.expired' | 'payment.refunded' | 'subscription.created' | 'subscription.renewed' | 'subscription.cancelled' | 'subscription.expired';
252
+ type WebhookEventType = 'payment.created' | 'payment.completed' | 'payment.failed' | 'payment.expired' | 'payment.refunded' | 'subscription.created' | 'subscription.renewed' | 'subscription.cancelled' | 'subscription.expired' | 'payout.created' | 'payout.sent' | 'payout.claimed' | 'payout.expired' | 'payout.failed';
212
253
  /**
213
254
  * Webhook payload
214
255
  */
@@ -829,6 +870,11 @@ interface WebhookHandlers {
829
870
  'subscription.renewed'?: WebhookHandler;
830
871
  'subscription.cancelled'?: WebhookHandler;
831
872
  'subscription.expired'?: WebhookHandler;
873
+ 'payout.created'?: WebhookHandler;
874
+ 'payout.sent'?: WebhookHandler;
875
+ 'payout.claimed'?: WebhookHandler;
876
+ 'payout.expired'?: WebhookHandler;
877
+ 'payout.failed'?: WebhookHandler;
832
878
  }
833
879
  /**
834
880
  * Create a webhook handler middleware
@@ -1259,4 +1305,386 @@ declare const UNITY_EXAMPLE = "\n// SettlrPayment.cs - Drop into your Unity proj
1259
1305
  */
1260
1306
  declare const REACT_NATIVE_EXAMPLE = "\n// SettlrPayment.tsx - React Native component\n\nimport { Linking, Alert } from 'react-native';\nimport { useEffect } from 'react';\n\nconst SETTLR_URL = 'https://settlr.dev';\nconst APP_SCHEME = 'mygame';\n\nexport function useSettlrPayment(onSuccess: (sig: string) => void) {\n useEffect(() => {\n const handleDeepLink = ({ url }: { url: string }) => {\n if (url.includes('payment-success')) {\n const sig = new URL(url).searchParams.get('signature');\n if (sig) onSuccess(sig);\n }\n };\n \n Linking.addEventListener('url', handleDeepLink);\n return () => Linking.removeAllListeners('url');\n }, [onSuccess]);\n \n const startPayment = async (amount: number, merchantWallet: string) => {\n const orderId = `order_${Date.now()}`;\n const url = `${SETTLR_URL}/checkout?amount=${amount}&merchant=${merchantWallet}` +\n `&success_url=${APP_SCHEME}://payment-success?order=${orderId}` +\n `&cancel_url=${APP_SCHEME}://payment-cancel?order=${orderId}`;\n \n await Linking.openURL(url);\n };\n \n return { startPayment };\n}\n";
1261
1307
 
1262
- export { type ApproveOneClickOptions, BuyButton, type BuyButtonProps, type ChargeOneClickOptions, CheckoutWidget, type CheckoutWidgetProps, type CreatePaymentOptions, type CreateSubscriptionOptions, INCO_LIGHTNING_PROGRAM_ID, type IssuePrivateReceiptResult, type MerchantConfig, type MobileCheckoutOptions, type MobileCheckoutResult, OneClickClient, type OneClickResult, type Payment, PaymentModal, type PaymentModalProps, type PaymentResult, type PaymentStatus, PrivacyFeatures, type PrivateReceiptConfig, REACT_NATIVE_EXAMPLE, REST_API, SETTLR_CHECKOUT_URL, SETTLR_PROGRAM_ID, SUPPORTED_NETWORKS, SUPPORTED_TOKENS, Settlr, type SettlrConfig, SettlrProvider, type SpendingApproval, type Subscription, type SubscriptionInterval, type SubscriptionPlan, type SubscriptionStatus, type SupportedToken, type TransactionOptions, UNITY_EXAMPLE, USDC_MINT_DEVNET, USDC_MINT_MAINNET, USDT_MINT_DEVNET, USDT_MINT_MAINNET, type WebhookEventType, type WebhookHandler, type WebhookHandlers, type WebhookPayload, buildAllowanceRemainingAccounts, buildPrivateReceiptAccounts, createOneClickClient, createWebhookHandler, encryptAmount, findAllowancePda, findPrivateReceiptPda, formatUSDC, generateCheckoutUrl, generateDeepLinkCheckout, getTokenDecimals, getTokenMint, parseCallbackUrl, parseUSDC, parseWebhookPayload, shortenAddress, simulateAndGetHandle, usePaymentLink, usePaymentModal, useSettlr, verifyWebhookSignature };
1308
+ /**
1309
+ * @settlr/sdk — Subscription Client
1310
+ *
1311
+ * Manage recurring stablecoin payments for your SaaS or AI product.
1312
+ *
1313
+ * @example
1314
+ * ```typescript
1315
+ * import { SubscriptionClient } from '@settlr/sdk';
1316
+ *
1317
+ * const subs = new SubscriptionClient({
1318
+ * apiKey: 'sk_live_xxxxxxxxxxxx',
1319
+ * baseUrl: 'https://settlr.dev',
1320
+ * });
1321
+ *
1322
+ * // Create a plan
1323
+ * const plan = await subs.createPlan({
1324
+ * name: 'Pro',
1325
+ * amount: 29.99,
1326
+ * interval: 'monthly',
1327
+ * });
1328
+ *
1329
+ * // Subscribe a customer
1330
+ * const sub = await subs.subscribe({
1331
+ * planId: plan.id,
1332
+ * customerWallet: '7xKX...',
1333
+ * merchantWallet: 'DjLF...',
1334
+ * });
1335
+ *
1336
+ * // Cancel at end of period
1337
+ * await subs.cancel(sub.id);
1338
+ * ```
1339
+ */
1340
+
1341
+ interface SubscriptionClientConfig {
1342
+ /** Settlr API key */
1343
+ apiKey: string;
1344
+ /** Base URL of your Settlr instance (default: https://settlr.dev) */
1345
+ baseUrl?: string;
1346
+ /** Merchant ID (resolved from API key if not provided) */
1347
+ merchantId?: string;
1348
+ /** Merchant wallet address */
1349
+ merchantWallet?: string;
1350
+ }
1351
+ interface CreatePlanOptions {
1352
+ /** Plan display name */
1353
+ name: string;
1354
+ /** Optional description */
1355
+ description?: string;
1356
+ /** Amount in USDC per interval */
1357
+ amount: number;
1358
+ /** Billing interval */
1359
+ interval: SubscriptionInterval;
1360
+ /** Number of intervals between charges (default: 1) */
1361
+ intervalCount?: number;
1362
+ /** Free trial days (default: 0) */
1363
+ trialDays?: number;
1364
+ /** Feature list for display */
1365
+ features?: string[];
1366
+ }
1367
+ interface UpdatePlanOptions {
1368
+ name?: string;
1369
+ description?: string;
1370
+ amount?: number;
1371
+ active?: boolean;
1372
+ features?: string[];
1373
+ }
1374
+ interface SubscribeOptions {
1375
+ /** Plan ID */
1376
+ planId: string;
1377
+ /** Customer wallet address */
1378
+ customerWallet: string;
1379
+ /** Merchant wallet address (uses default if not provided) */
1380
+ merchantWallet?: string;
1381
+ /** Customer email for notifications */
1382
+ customerEmail?: string;
1383
+ /** Custom metadata */
1384
+ metadata?: Record<string, string>;
1385
+ }
1386
+ interface ListSubscriptionsOptions {
1387
+ /** Filter by status */
1388
+ status?: SubscriptionStatus;
1389
+ /** Filter by customer wallet */
1390
+ customerWallet?: string;
1391
+ /** Filter by plan */
1392
+ planId?: string;
1393
+ }
1394
+ interface SubscriptionPayment {
1395
+ id: string;
1396
+ amount: number;
1397
+ platformFee: number;
1398
+ status: "pending" | "completed" | "failed" | "refunded";
1399
+ txSignature?: string;
1400
+ periodStart: string;
1401
+ periodEnd: string;
1402
+ attemptCount: number;
1403
+ failureReason?: string;
1404
+ createdAt: string;
1405
+ }
1406
+ interface SubscriptionDetail extends Subscription {
1407
+ plan: SubscriptionPlan;
1408
+ payments?: SubscriptionPayment[];
1409
+ }
1410
+ declare class SubscriptionClient {
1411
+ private apiKey;
1412
+ private baseUrl;
1413
+ private merchantId?;
1414
+ private merchantWallet?;
1415
+ constructor(config: SubscriptionClientConfig);
1416
+ private fetch;
1417
+ /**
1418
+ * Resolve merchant ID from API key
1419
+ */
1420
+ private ensureMerchantId;
1421
+ /**
1422
+ * Create a subscription plan
1423
+ */
1424
+ createPlan(options: CreatePlanOptions): Promise<SubscriptionPlan>;
1425
+ /**
1426
+ * List all plans for the merchant
1427
+ */
1428
+ listPlans(): Promise<SubscriptionPlan[]>;
1429
+ /**
1430
+ * Update a plan
1431
+ */
1432
+ updatePlan(planId: string, options: UpdatePlanOptions): Promise<SubscriptionPlan>;
1433
+ /**
1434
+ * Deactivate a plan (stops new subscriptions)
1435
+ */
1436
+ deactivatePlan(planId: string): Promise<void>;
1437
+ /**
1438
+ * Subscribe a customer to a plan
1439
+ */
1440
+ subscribe(options: SubscribeOptions): Promise<{
1441
+ subscription: Subscription;
1442
+ payment?: {
1443
+ id: string;
1444
+ amount: number;
1445
+ signature: string;
1446
+ };
1447
+ message: string;
1448
+ }>;
1449
+ /**
1450
+ * List subscriptions
1451
+ */
1452
+ listSubscriptions(options?: ListSubscriptionsOptions): Promise<Subscription[]>;
1453
+ /**
1454
+ * Get subscription details including payment history
1455
+ */
1456
+ getSubscription(subscriptionId: string): Promise<SubscriptionDetail>;
1457
+ /**
1458
+ * Cancel a subscription
1459
+ * @param immediately - If true, cancels now. If false (default), cancels at end of billing period.
1460
+ */
1461
+ cancel(subscriptionId: string, immediately?: boolean): Promise<{
1462
+ success: boolean;
1463
+ message: string;
1464
+ cancelAt?: string;
1465
+ }>;
1466
+ /**
1467
+ * Pause a subscription (stops billing, preserves subscription)
1468
+ */
1469
+ pause(subscriptionId: string): Promise<{
1470
+ success: boolean;
1471
+ message: string;
1472
+ }>;
1473
+ /**
1474
+ * Resume a paused subscription
1475
+ */
1476
+ resume(subscriptionId: string): Promise<{
1477
+ success: boolean;
1478
+ message: string;
1479
+ nextCharge?: string;
1480
+ }>;
1481
+ /**
1482
+ * Manually charge a subscription (useful for metered billing)
1483
+ */
1484
+ charge(subscriptionId: string): Promise<{
1485
+ success: boolean;
1486
+ payment?: {
1487
+ id: string;
1488
+ amount: number;
1489
+ signature: string;
1490
+ };
1491
+ }>;
1492
+ }
1493
+ /**
1494
+ * Factory function to create a SubscriptionClient
1495
+ */
1496
+ declare function createSubscriptionClient(config: SubscriptionClientConfig): SubscriptionClient;
1497
+
1498
+ /**
1499
+ * @settlr/sdk — Payout Client
1500
+ *
1501
+ * Send USDC to anyone in the world with just their email address.
1502
+ *
1503
+ * @example
1504
+ * ```typescript
1505
+ * import { PayoutClient } from '@settlr/sdk';
1506
+ *
1507
+ * const payouts = new PayoutClient({
1508
+ * apiKey: 'sk_live_xxxxxxxxxxxx',
1509
+ * });
1510
+ *
1511
+ * // Send a payout
1512
+ * const payout = await payouts.create({
1513
+ * email: 'creator@example.com',
1514
+ * amount: 150.00,
1515
+ * memo: 'March earnings',
1516
+ * });
1517
+ *
1518
+ * // Check status
1519
+ * const status = await payouts.get(payout.id);
1520
+ * console.log(status.status); // "sent" | "claimed"
1521
+ *
1522
+ * // Send batch payouts
1523
+ * const batch = await payouts.createBatch([
1524
+ * { email: 'alice@example.com', amount: 250.00, memo: 'March' },
1525
+ * { email: 'bob@example.com', amount: 180.00, memo: 'March' },
1526
+ * ]);
1527
+ * ```
1528
+ */
1529
+ type PayoutStatus = "pending" | "funded" | "sent" | "claimed" | "expired" | "failed";
1530
+ interface CreatePayoutOptions {
1531
+ /** Recipient email address */
1532
+ email: string;
1533
+ /** Amount in USDC */
1534
+ amount: number;
1535
+ /** Currency (default: "USDC") */
1536
+ currency?: string;
1537
+ /** Description shown in the claim email */
1538
+ memo?: string;
1539
+ /** Custom key-value metadata for your records */
1540
+ metadata?: Record<string, string>;
1541
+ }
1542
+ interface PayoutRecord {
1543
+ /** Unique payout ID (e.g. "po_abc123") */
1544
+ id: string;
1545
+ /** Recipient email */
1546
+ email: string;
1547
+ /** Amount in USDC */
1548
+ amount: number;
1549
+ /** Currency */
1550
+ currency: string;
1551
+ /** Memo / description */
1552
+ memo?: string;
1553
+ /** Custom metadata */
1554
+ metadata?: Record<string, string>;
1555
+ /** Current status */
1556
+ status: PayoutStatus;
1557
+ /** URL the recipient uses to claim the payout */
1558
+ claimUrl: string;
1559
+ /** Recipient wallet address (set after claim) */
1560
+ recipientWallet?: string;
1561
+ /** On-chain transaction signature (set after claim) */
1562
+ txSignature?: string;
1563
+ /** Batch ID if part of a batch */
1564
+ batchId?: string;
1565
+ /** ISO timestamp */
1566
+ createdAt: string;
1567
+ /** ISO timestamp — when funds were escrowed */
1568
+ fundedAt?: string;
1569
+ /** ISO timestamp — when recipient claimed */
1570
+ claimedAt?: string;
1571
+ /** ISO timestamp — when payout expires */
1572
+ expiresAt: string;
1573
+ }
1574
+ interface PayoutBatchResult {
1575
+ /** Batch ID */
1576
+ id: string;
1577
+ /** Batch status */
1578
+ status: string;
1579
+ /** Total USDC amount */
1580
+ total: number;
1581
+ /** Number of payouts */
1582
+ count: number;
1583
+ /** Individual payout records */
1584
+ payouts: Array<{
1585
+ id: string;
1586
+ email: string;
1587
+ amount: number;
1588
+ status: PayoutStatus;
1589
+ claimUrl: string;
1590
+ }>;
1591
+ /** ISO timestamp */
1592
+ createdAt: string;
1593
+ }
1594
+ interface ListPayoutsOptions {
1595
+ /** Filter by status */
1596
+ status?: PayoutStatus;
1597
+ /** Max results (default 20, max 100) */
1598
+ limit?: number;
1599
+ /** Offset for pagination */
1600
+ offset?: number;
1601
+ }
1602
+ interface ListPayoutsResult {
1603
+ data: PayoutRecord[];
1604
+ count: number;
1605
+ limit: number;
1606
+ offset: number;
1607
+ }
1608
+ interface PayoutClientConfig {
1609
+ /** Settlr API key */
1610
+ apiKey: string;
1611
+ /** Base URL of your Settlr instance (default: https://settlr.dev) */
1612
+ baseUrl?: string;
1613
+ }
1614
+ declare class PayoutClient {
1615
+ private apiKey;
1616
+ private baseUrl;
1617
+ constructor(config: PayoutClientConfig);
1618
+ private fetch;
1619
+ /**
1620
+ * Send a payout to a recipient by email.
1621
+ * They'll receive an email with a claim link — no wallet or bank details needed.
1622
+ *
1623
+ * @example
1624
+ * ```typescript
1625
+ * const payout = await payouts.create({
1626
+ * email: 'alice@example.com',
1627
+ * amount: 250.00,
1628
+ * memo: 'March data labeling — 500 tasks',
1629
+ * });
1630
+ * console.log(payout.id); // "po_abc123"
1631
+ * console.log(payout.status); // "sent"
1632
+ * console.log(payout.claimUrl); // "https://settlr.dev/claim/..."
1633
+ * ```
1634
+ */
1635
+ create(options: CreatePayoutOptions): Promise<PayoutRecord>;
1636
+ /**
1637
+ * Send multiple payouts at once. Each recipient gets their own email.
1638
+ *
1639
+ * @example
1640
+ * ```typescript
1641
+ * const batch = await payouts.createBatch([
1642
+ * { email: 'alice@example.com', amount: 250.00, memo: 'March' },
1643
+ * { email: 'bob@example.com', amount: 180.00, memo: 'March' },
1644
+ * ]);
1645
+ * console.log(batch.id); // "batch_xyz"
1646
+ * console.log(batch.total); // 430.00
1647
+ * ```
1648
+ */
1649
+ createBatch(payoutsList: Array<{
1650
+ email: string;
1651
+ amount: number;
1652
+ memo?: string;
1653
+ metadata?: Record<string, string>;
1654
+ }>): Promise<PayoutBatchResult>;
1655
+ /**
1656
+ * Get a payout by ID.
1657
+ *
1658
+ * @example
1659
+ * ```typescript
1660
+ * const payout = await payouts.get('po_abc123');
1661
+ * console.log(payout.status); // "claimed"
1662
+ * console.log(payout.claimedAt); // "2024-03-15T14:30:00Z"
1663
+ * ```
1664
+ */
1665
+ get(id: string): Promise<PayoutRecord>;
1666
+ /**
1667
+ * List payouts for the authenticated merchant.
1668
+ *
1669
+ * @example
1670
+ * ```typescript
1671
+ * const result = await payouts.list({ status: 'claimed', limit: 50 });
1672
+ * result.data.forEach(p => console.log(p.email, p.amount, p.status));
1673
+ * ```
1674
+ */
1675
+ list(options?: ListPayoutsOptions): Promise<ListPayoutsResult>;
1676
+ }
1677
+ /**
1678
+ * Create a standalone PayoutClient instance.
1679
+ *
1680
+ * @example
1681
+ * ```typescript
1682
+ * import { createPayoutClient } from '@settlr/sdk';
1683
+ *
1684
+ * const payouts = createPayoutClient({ apiKey: 'sk_live_xxx' });
1685
+ * const payout = await payouts.create({ email: 'alice@test.com', amount: 50 });
1686
+ * ```
1687
+ */
1688
+ declare function createPayoutClient(config: PayoutClientConfig): PayoutClient;
1689
+
1690
+ export { type ApproveOneClickOptions, BuyButton, type BuyButtonProps, type ChargeOneClickOptions, CheckoutWidget, type CheckoutWidgetProps, type CreatePaymentOptions, type CreatePayoutOptions, type CreatePlanOptions, type CreateSubscriptionOptions, INCO_LIGHTNING_PROGRAM_ID, type IssuePrivateReceiptResult, type ListPayoutsOptions, type ListPayoutsResult, type ListSubscriptionsOptions, type MerchantConfig, type MobileCheckoutOptions, type MobileCheckoutResult, OneClickClient, type OneClickResult, type Payment, PaymentModal, type PaymentModalProps, type PaymentResult, type PaymentStatus, type Payout, type PayoutBatch, type PayoutBatchResult, PayoutClient, type PayoutClientConfig, type PayoutRecord, type PayoutStatus$1 as PayoutStatus, PrivacyFeatures, type PrivateReceiptConfig, REACT_NATIVE_EXAMPLE, REST_API, SETTLR_CHECKOUT_URL, SETTLR_PROGRAM_ID, SUPPORTED_NETWORKS, SUPPORTED_TOKENS, Settlr, type SettlrConfig, SettlrProvider, type SpendingApproval, type SubscribeOptions, type Subscription, SubscriptionClient, type SubscriptionClientConfig, type SubscriptionDetail, type SubscriptionInterval, type SubscriptionPayment, type SubscriptionPlan, type SubscriptionStatus, type SupportedToken, type TransactionOptions, UNITY_EXAMPLE, USDC_MINT_DEVNET, USDC_MINT_MAINNET, USDT_MINT_DEVNET, USDT_MINT_MAINNET, type UpdatePlanOptions, type WebhookEventType, type WebhookHandler, type WebhookHandlers, type WebhookPayload, buildAllowanceRemainingAccounts, buildPrivateReceiptAccounts, createOneClickClient, createPayoutClient, createSubscriptionClient, createWebhookHandler, encryptAmount, findAllowancePda, findPrivateReceiptPda, formatUSDC, generateCheckoutUrl, generateDeepLinkCheckout, getTokenDecimals, getTokenMint, parseCallbackUrl, parseUSDC, parseWebhookPayload, shortenAddress, simulateAndGetHandle, usePaymentLink, usePaymentModal, useSettlr, verifyWebhookSignature };