@settlr/sdk 0.1.0 → 0.3.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/dist/index.d.ts CHANGED
@@ -5,8 +5,8 @@ import { ReactNode, CSSProperties } from 'react';
5
5
  declare const USDC_MINT_DEVNET: PublicKey;
6
6
  declare const USDC_MINT_MAINNET: PublicKey;
7
7
  declare const SETTLR_CHECKOUT_URL: {
8
- readonly production: "https://settlr.dev/pay";
9
- readonly development: "http://localhost:3000/pay";
8
+ readonly production: "https://settlr.dev/checkout";
9
+ readonly development: "http://localhost:3000/checkout";
10
10
  };
11
11
  declare const SUPPORTED_NETWORKS: readonly ["devnet", "mainnet-beta"];
12
12
  type SupportedNetwork = typeof SUPPORTED_NETWORKS[number];
@@ -182,6 +182,30 @@ declare class Settlr {
182
182
  * Get the current tier
183
183
  */
184
184
  getTier(): 'free' | 'pro' | 'enterprise' | undefined;
185
+ /**
186
+ * Get a checkout URL for redirect-based payments
187
+ *
188
+ * This is the simplest integration - just redirect users to this URL.
189
+ * Settlr handles auth (email or wallet) and payment processing.
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const url = settlr.getCheckoutUrl({
194
+ * amount: 29.99,
195
+ * memo: 'Premium Pack',
196
+ * });
197
+ *
198
+ * // Redirect user to checkout
199
+ * window.location.href = url;
200
+ * ```
201
+ */
202
+ getCheckoutUrl(options: {
203
+ amount: number;
204
+ memo?: string;
205
+ orderId?: string;
206
+ successUrl?: string;
207
+ cancelUrl?: string;
208
+ }): string;
185
209
  /**
186
210
  * Create a payment link
187
211
  *
@@ -314,21 +338,28 @@ declare function parseUSDC(amount: number | string): bigint;
314
338
  */
315
339
  declare function shortenAddress(address: string, chars?: number): string;
316
340
 
341
+ /**
342
+ * Checkout URL options
343
+ */
344
+ interface CheckoutUrlOptions {
345
+ amount: number;
346
+ memo?: string;
347
+ orderId?: string;
348
+ successUrl?: string;
349
+ cancelUrl?: string;
350
+ }
317
351
  /**
318
352
  * Settlr context value
319
353
  */
320
354
  interface SettlrContextValue {
321
355
  /** Settlr client instance */
322
356
  settlr: Settlr | null;
323
- /** Whether wallet is connected */
324
- connected: boolean;
325
- /** Create a payment link */
357
+ /** Whether user is authenticated */
358
+ authenticated: boolean;
359
+ /** Create a payment link (redirect flow) */
326
360
  createPayment: (options: CreatePaymentOptions) => Promise<Payment>;
327
- /** Execute a direct payment */
328
- pay: (options: {
329
- amount: number;
330
- memo?: string;
331
- }) => Promise<PaymentResult>;
361
+ /** Generate checkout URL for redirect */
362
+ getCheckoutUrl: (options: CheckoutUrlOptions) => string;
332
363
  /** Get merchant's USDC balance */
333
364
  getBalance: () => Promise<number>;
334
365
  }
@@ -337,32 +368,41 @@ interface SettlrContextValue {
337
368
  */
338
369
  interface SettlrProviderProps {
339
370
  children: ReactNode;
340
- config: Omit<SettlrConfig, "rpcEndpoint">;
371
+ config: SettlrConfig;
372
+ /** Whether user is authenticated (from Privy or other auth) */
373
+ authenticated?: boolean;
341
374
  }
342
375
  /**
343
376
  * Settlr Provider - Wraps your app to provide Settlr functionality
344
377
  *
378
+ * Works with Privy authentication - just pass the authenticated state.
379
+ *
345
380
  * @example
346
381
  * ```tsx
347
382
  * import { SettlrProvider } from '@settlr/sdk';
383
+ * import { usePrivy } from '@privy-io/react-auth';
348
384
  *
349
385
  * function App() {
386
+ * const { authenticated } = usePrivy();
387
+ *
350
388
  * return (
351
- * <WalletProvider wallets={wallets}>
352
- * <SettlrProvider config={{
389
+ * <SettlrProvider
390
+ * authenticated={authenticated}
391
+ * config={{
392
+ * apiKey: 'sk_live_xxxxxxxxxxxx',
353
393
  * merchant: {
354
- * name: 'My Store',
394
+ * name: 'My Game',
355
395
  * walletAddress: 'YOUR_WALLET',
356
396
  * },
357
- * }}>
358
- * <YourApp />
359
- * </SettlrProvider>
360
- * </WalletProvider>
397
+ * }}
398
+ * >
399
+ * <YourApp />
400
+ * </SettlrProvider>
361
401
  * );
362
402
  * }
363
403
  * ```
364
404
  */
365
- declare function SettlrProvider({ children, config }: SettlrProviderProps): react_jsx_runtime.JSX.Element;
405
+ declare function SettlrProvider({ children, config, authenticated, }: SettlrProviderProps): react_jsx_runtime.JSX.Element;
366
406
  /**
367
407
  * useSettlr hook - Access Settlr functionality in your components
368
408
  *
@@ -371,23 +411,17 @@ declare function SettlrProvider({ children, config }: SettlrProviderProps): reac
371
411
  * import { useSettlr } from '@settlr/sdk';
372
412
  *
373
413
  * function CheckoutButton() {
374
- * const { createPayment, pay, connected } = useSettlr();
375
- *
376
- * const handlePay = async () => {
377
- * // Option 1: Create payment link
378
- * const payment = await createPayment({ amount: 29.99 });
379
- * window.location.href = payment.checkoutUrl;
414
+ * const { getCheckoutUrl, authenticated } = useSettlr();
380
415
  *
381
- * // Option 2: Direct payment
382
- * const result = await pay({ amount: 29.99 });
383
- * if (result.success) {
384
- * console.log('Paid!');
385
- * }
416
+ * const handleCheckout = () => {
417
+ * // Redirect to Settlr checkout (handles Privy auth internally)
418
+ * const url = getCheckoutUrl({ amount: 29.99, memo: 'Premium Pack' });
419
+ * window.location.href = url;
386
420
  * };
387
421
  *
388
422
  * return (
389
- * <button onClick={handlePay} disabled={!connected}>
390
- * Pay $29.99
423
+ * <button onClick={handleCheckout}>
424
+ * Buy Premium Pack - $29.99
391
425
  * </button>
392
426
  * );
393
427
  * }
@@ -455,7 +489,8 @@ interface BuyButtonProps {
455
489
  /** Button size */
456
490
  size?: "sm" | "md" | "lg";
457
491
  }
458
- declare function BuyButton({ amount, memo, orderId, children, onSuccess, onError, onProcessing, useRedirect, successUrl, cancelUrl, className, style, disabled, variant, size, }: BuyButtonProps): react_jsx_runtime.JSX.Element;
492
+ declare function BuyButton({ amount, memo, orderId, children, onSuccess, onError, onProcessing, useRedirect, // Default to redirect flow (works with Privy)
493
+ successUrl, cancelUrl, className, style, disabled, variant, size, }: BuyButtonProps): react_jsx_runtime.JSX.Element;
459
494
  /**
460
495
  * Checkout Widget - Embeddable checkout form
461
496
  *
@@ -549,6 +584,111 @@ declare function usePaymentLink(config: {
549
584
  cancelUrl?: string;
550
585
  }) => string>[0]) => Promise<string>;
551
586
  };
587
+ /**
588
+ * Payment Modal - Iframe-based checkout that keeps users on your site
589
+ *
590
+ * @example
591
+ * ```tsx
592
+ * import { PaymentModal } from '@settlr/sdk';
593
+ *
594
+ * function ProductPage() {
595
+ * const [showPayment, setShowPayment] = useState(false);
596
+ *
597
+ * return (
598
+ * <>
599
+ * <button onClick={() => setShowPayment(true)}>
600
+ * Buy Now - $49.99
601
+ * </button>
602
+ *
603
+ * {showPayment && (
604
+ * <PaymentModal
605
+ * amount={49.99}
606
+ * merchantName="Arena GG"
607
+ * merchantWallet="YOUR_WALLET_ADDRESS"
608
+ * memo="Tournament Entry"
609
+ * onSuccess={(result) => {
610
+ * console.log('Paid!', result.signature);
611
+ * setShowPayment(false);
612
+ * }}
613
+ * onClose={() => setShowPayment(false)}
614
+ * />
615
+ * )}
616
+ * </>
617
+ * );
618
+ * }
619
+ * ```
620
+ */
621
+ interface PaymentModalProps {
622
+ /** Payment amount in USDC */
623
+ amount: number;
624
+ /** Merchant display name */
625
+ merchantName: string;
626
+ /** Merchant wallet address */
627
+ merchantWallet: string;
628
+ /** Optional memo/description */
629
+ memo?: string;
630
+ /** Optional order ID */
631
+ orderId?: string;
632
+ /** Called when payment succeeds */
633
+ onSuccess?: (result: {
634
+ signature: string;
635
+ amount: number;
636
+ }) => void;
637
+ /** Called when modal is closed */
638
+ onClose?: () => void;
639
+ /** Called on error */
640
+ onError?: (error: Error) => void;
641
+ /** Checkout base URL (default: https://settlr.dev/checkout) */
642
+ checkoutUrl?: string;
643
+ }
644
+ declare function PaymentModal({ amount, merchantName, merchantWallet, memo, orderId, onSuccess, onClose, onError, checkoutUrl, }: PaymentModalProps): react_jsx_runtime.JSX.Element;
645
+ /**
646
+ * Hook to open payment modal programmatically
647
+ *
648
+ * @example
649
+ * ```tsx
650
+ * import { usePaymentModal } from '@settlr/sdk';
651
+ *
652
+ * function ProductPage() {
653
+ * const { openPayment, PaymentModalComponent } = usePaymentModal({
654
+ * merchantName: "Arena GG",
655
+ * merchantWallet: "YOUR_WALLET",
656
+ * });
657
+ *
658
+ * return (
659
+ * <>
660
+ * <button onClick={() => openPayment({
661
+ * amount: 49.99,
662
+ * memo: "Tournament Entry",
663
+ * onSuccess: (result) => console.log("Paid!", result),
664
+ * })}>
665
+ * Buy Now
666
+ * </button>
667
+ * <PaymentModalComponent />
668
+ * </>
669
+ * );
670
+ * }
671
+ * ```
672
+ */
673
+ declare function usePaymentModal(config: {
674
+ merchantName: string;
675
+ merchantWallet: string;
676
+ checkoutUrl?: string;
677
+ }): {
678
+ openPayment: (options: {
679
+ amount: number;
680
+ memo?: string;
681
+ orderId?: string;
682
+ onSuccess?: (result: {
683
+ signature: string;
684
+ amount: number;
685
+ }) => void;
686
+ onError?: (error: Error) => void;
687
+ }) => void;
688
+ closePayment: () => void;
689
+ isOpen: boolean;
690
+ PaymentModalComponent: () => react_jsx_runtime.JSX.Element | null;
691
+ };
552
692
 
553
693
  /**
554
694
  * Verify a webhook signature
@@ -632,4 +772,4 @@ declare function createWebhookHandler(options: {
632
772
  onError?: (error: Error) => void;
633
773
  }): (req: any, res: any) => Promise<void>;
634
774
 
635
- export { BuyButton, type BuyButtonProps, CheckoutWidget, type CheckoutWidgetProps, type CreatePaymentOptions, type MerchantConfig, type Payment, type PaymentResult, type PaymentStatus, SETTLR_CHECKOUT_URL, SUPPORTED_NETWORKS, Settlr, type SettlrConfig, SettlrProvider, type TransactionOptions, USDC_MINT_DEVNET, USDC_MINT_MAINNET, type WebhookEventType, type WebhookHandler, type WebhookHandlers, type WebhookPayload, createWebhookHandler, formatUSDC, parseUSDC, parseWebhookPayload, shortenAddress, usePaymentLink, useSettlr, verifyWebhookSignature };
775
+ export { BuyButton, type BuyButtonProps, CheckoutWidget, type CheckoutWidgetProps, type CreatePaymentOptions, type MerchantConfig, type Payment, PaymentModal, type PaymentModalProps, type PaymentResult, type PaymentStatus, SETTLR_CHECKOUT_URL, SUPPORTED_NETWORKS, Settlr, type SettlrConfig, SettlrProvider, type TransactionOptions, USDC_MINT_DEVNET, USDC_MINT_MAINNET, type WebhookEventType, type WebhookHandler, type WebhookHandlers, type WebhookPayload, createWebhookHandler, formatUSDC, parseUSDC, parseWebhookPayload, shortenAddress, usePaymentLink, usePaymentModal, useSettlr, verifyWebhookSignature };