@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/README.md +33 -69
- package/dist/index.d.mts +174 -34
- package/dist/index.d.ts +174 -34
- package/dist/index.js +252 -62
- package/dist/index.mjs +252 -63
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
# @settlr/sdk
|
|
2
2
|
|
|
3
|
-
> Solana USDC payments
|
|
3
|
+
> Solana USDC payments for games - email checkout, no wallet required
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @settlr/sdk
|
|
9
|
-
# or
|
|
10
|
-
yarn add @settlr/sdk
|
|
11
|
-
# or
|
|
12
|
-
pnpm add @settlr/sdk
|
|
13
9
|
```
|
|
14
10
|
|
|
15
11
|
## Quick Start
|
|
16
12
|
|
|
17
13
|
### 1. Get Your API Key
|
|
18
14
|
|
|
19
|
-
Sign up at [settlr.
|
|
15
|
+
Sign up at [settlr.app/dashboard](https://settlr.app/dashboard) and create an API key.
|
|
20
16
|
|
|
21
17
|
### 2. Create a Payment Link
|
|
22
18
|
|
|
@@ -87,97 +83,65 @@ import { CheckoutWidget } from "@settlr/sdk";
|
|
|
87
83
|
/>;
|
|
88
84
|
```
|
|
89
85
|
|
|
90
|
-
###
|
|
86
|
+
### How It Works
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
import { Settlr } from "@settlr/sdk";
|
|
94
|
-
import { useWallet } from "@solana/wallet-adapter-react";
|
|
88
|
+
Settlr checkout handles authentication via Privy:
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
merchant: {
|
|
99
|
-
name: "My Store",
|
|
100
|
-
walletAddress: "YOUR_WALLET",
|
|
101
|
-
},
|
|
102
|
-
});
|
|
90
|
+
- **Email login** → Creates embedded Solana wallet automatically
|
|
91
|
+
- **Wallet login** → Connects Phantom, Solflare, or Backpack
|
|
103
92
|
|
|
104
|
-
|
|
105
|
-
const wallet = useWallet();
|
|
106
|
-
|
|
107
|
-
const result = await settlr.pay({
|
|
108
|
-
wallet: {
|
|
109
|
-
publicKey: wallet.publicKey!,
|
|
110
|
-
signTransaction: wallet.signTransaction!,
|
|
111
|
-
},
|
|
112
|
-
amount: 29.99,
|
|
113
|
-
memo: "Order #1234",
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
if (result.success) {
|
|
117
|
-
console.log("Payment successful!", result.signature);
|
|
118
|
-
}
|
|
119
|
-
```
|
|
93
|
+
No wallet-adapter setup needed. Just redirect to checkout.
|
|
120
94
|
|
|
121
95
|
### React Hook
|
|
122
96
|
|
|
123
97
|
```tsx
|
|
124
98
|
import { SettlrProvider, useSettlr } from "@settlr/sdk";
|
|
125
99
|
|
|
126
|
-
// Wrap your app
|
|
127
100
|
function App() {
|
|
128
101
|
return (
|
|
129
|
-
<
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
<YourApp />
|
|
141
|
-
</SettlrProvider>
|
|
142
|
-
</ConnectionProvider>
|
|
143
|
-
</WalletProvider>
|
|
102
|
+
<SettlrProvider
|
|
103
|
+
config={{
|
|
104
|
+
apiKey: "sk_live_xxxxxxxxxxxx",
|
|
105
|
+
merchant: {
|
|
106
|
+
name: "My Game",
|
|
107
|
+
walletAddress: "YOUR_WALLET",
|
|
108
|
+
},
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<YourApp />
|
|
112
|
+
</SettlrProvider>
|
|
144
113
|
);
|
|
145
114
|
}
|
|
146
115
|
|
|
147
116
|
// In your component
|
|
148
117
|
function CheckoutButton() {
|
|
149
|
-
const {
|
|
118
|
+
const { getCheckoutUrl } = useSettlr();
|
|
150
119
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
120
|
+
const handlePay = () => {
|
|
121
|
+
const url = getCheckoutUrl({ amount: 29.99, memo: "Premium Pack" });
|
|
122
|
+
window.location.href = url;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return <button onClick={handlePay}>Pay $29.99</button>;
|
|
156
126
|
}
|
|
157
127
|
```
|
|
158
128
|
|
|
159
|
-
### Payment Link Generator Hook
|
|
129
|
+
### Payment Link Generator Hook
|
|
160
130
|
|
|
161
131
|
Generate shareable payment links programmatically:
|
|
162
132
|
|
|
163
133
|
```tsx
|
|
164
|
-
import {
|
|
134
|
+
import { useSettlr } from "@settlr/sdk";
|
|
165
135
|
|
|
166
136
|
function InvoicePage() {
|
|
167
|
-
const {
|
|
168
|
-
merchantWallet: "YOUR_WALLET",
|
|
169
|
-
merchantName: "My Store",
|
|
170
|
-
});
|
|
137
|
+
const { getCheckoutUrl } = useSettlr();
|
|
171
138
|
|
|
172
|
-
const link =
|
|
139
|
+
const link = getCheckoutUrl({
|
|
173
140
|
amount: 500,
|
|
174
141
|
memo: "Invoice #1234",
|
|
175
142
|
orderId: "inv_1234",
|
|
176
143
|
});
|
|
177
|
-
// → https://settlr.
|
|
178
|
-
|
|
179
|
-
const qrCode = await generateQRCode({ amount: 500 });
|
|
180
|
-
// → QR code image URL
|
|
144
|
+
// → https://settlr.app/checkout?amount=500&merchant=My+Game&...
|
|
181
145
|
}
|
|
182
146
|
```
|
|
183
147
|
|
|
@@ -250,7 +214,7 @@ Full checkout UI component with product info.
|
|
|
250
214
|
|
|
251
215
|
### Get Your API Key
|
|
252
216
|
|
|
253
|
-
1. Go to [settlr.
|
|
217
|
+
1. Go to [settlr.app/dashboard](https://settlr.app/dashboard)
|
|
254
218
|
2. Connect your wallet
|
|
255
219
|
3. Click "Create API Key"
|
|
256
220
|
4. Save the key securely (only shown once!)
|
|
@@ -298,7 +262,7 @@ const payment = await settlr.createPayment({
|
|
|
298
262
|
id: 'pay_abc123',
|
|
299
263
|
amount: 29.99,
|
|
300
264
|
status: 'pending',
|
|
301
|
-
checkoutUrl: 'https://settlr.
|
|
265
|
+
checkoutUrl: 'https://settlr.app/checkout?...',
|
|
302
266
|
qrCode: 'data:image/svg+xml,...',
|
|
303
267
|
createdAt: Date,
|
|
304
268
|
expiresAt: Date,
|
|
@@ -372,7 +336,7 @@ window.location.href = session.url;
|
|
|
372
336
|
// Returns
|
|
373
337
|
{
|
|
374
338
|
id: 'cs_abc123...',
|
|
375
|
-
url: 'https://settlr.
|
|
339
|
+
url: 'https://settlr.app/checkout/cs_abc123...',
|
|
376
340
|
expiresAt: 1702659600000, // 30 min expiry
|
|
377
341
|
}
|
|
378
342
|
```
|
package/dist/index.d.mts
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/
|
|
9
|
-
readonly development: "http://localhost:3000/
|
|
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
|
|
324
|
-
|
|
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
|
-
/**
|
|
328
|
-
|
|
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:
|
|
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
|
-
* <
|
|
352
|
-
*
|
|
389
|
+
* <SettlrProvider
|
|
390
|
+
* authenticated={authenticated}
|
|
391
|
+
* config={{
|
|
392
|
+
* apiKey: 'sk_live_xxxxxxxxxxxx',
|
|
353
393
|
* merchant: {
|
|
354
|
-
* name: 'My
|
|
394
|
+
* name: 'My Game',
|
|
355
395
|
* walletAddress: 'YOUR_WALLET',
|
|
356
396
|
* },
|
|
357
|
-
* }}
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
* </
|
|
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 {
|
|
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
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
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={
|
|
390
|
-
*
|
|
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,
|
|
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 };
|