@settlr/sdk 0.4.0 → 0.4.2
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 +26 -11
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +56 -15
- package/dist/index.mjs +56 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -430,13 +430,17 @@ export async function POST(request: Request) {
|
|
|
430
430
|
|
|
431
431
|
### Webhook Events
|
|
432
432
|
|
|
433
|
-
| Event
|
|
434
|
-
|
|
|
435
|
-
| `payment.created`
|
|
436
|
-
| `payment.completed`
|
|
437
|
-
| `payment.failed`
|
|
438
|
-
| `payment.expired`
|
|
439
|
-
| `payment.refunded`
|
|
433
|
+
| Event | Description |
|
|
434
|
+
| ------------------------ | -------------------------- |
|
|
435
|
+
| `payment.created` | Payment link was created |
|
|
436
|
+
| `payment.completed` | Payment confirmed on-chain |
|
|
437
|
+
| `payment.failed` | Payment failed |
|
|
438
|
+
| `payment.expired` | Payment link expired |
|
|
439
|
+
| `payment.refunded` | Payment was refunded |
|
|
440
|
+
| `subscription.created` | Subscription was created |
|
|
441
|
+
| `subscription.renewed` | Subscription was renewed |
|
|
442
|
+
| `subscription.cancelled` | Subscription was cancelled |
|
|
443
|
+
| `subscription.expired` | Subscription expired |
|
|
440
444
|
|
|
441
445
|
### Webhook Payload
|
|
442
446
|
|
|
@@ -480,10 +484,21 @@ shortenAddress("ABC...XYZ"); // "ABC...XYZ"
|
|
|
480
484
|
|
|
481
485
|
## Networks
|
|
482
486
|
|
|
483
|
-
| Network | USDC Mint |
|
|
484
|
-
| ------- | ---------------------------------------------- |
|
|
485
|
-
| Devnet | `4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU` |
|
|
486
|
-
| Mainnet | `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` |
|
|
487
|
+
| Network | USDC Mint | USDT Mint |
|
|
488
|
+
| ------- | ---------------------------------------------- | ---------------------------------------------- |
|
|
489
|
+
| Devnet | `4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU` | `EJwZgeZrdC8TXTQbQBoL6bfuAnFUUy1PVCMB4DYPzVaS` |
|
|
490
|
+
| Mainnet | `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` | `Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB` |
|
|
491
|
+
|
|
492
|
+
## Supported Tokens
|
|
493
|
+
|
|
494
|
+
```typescript
|
|
495
|
+
import { SUPPORTED_TOKENS, getTokenMint, getTokenDecimals } from "@settlr/sdk";
|
|
496
|
+
|
|
497
|
+
// Get token info
|
|
498
|
+
const usdcMint = getTokenMint("USDC", "mainnet-beta");
|
|
499
|
+
const usdtMint = getTokenMint("USDT", "mainnet-beta");
|
|
500
|
+
const decimals = getTokenDecimals("USDC"); // 6
|
|
501
|
+
```
|
|
487
502
|
|
|
488
503
|
## License
|
|
489
504
|
|
package/dist/index.d.mts
CHANGED
|
@@ -127,8 +127,8 @@ interface PaymentResult {
|
|
|
127
127
|
interface MerchantConfig {
|
|
128
128
|
/** Merchant display name */
|
|
129
129
|
name: string;
|
|
130
|
-
/** Merchant wallet address (receives payments) */
|
|
131
|
-
walletAddress
|
|
130
|
+
/** Merchant wallet address (receives payments) - optional if using registered API key */
|
|
131
|
+
walletAddress?: string | PublicKey;
|
|
132
132
|
/** Optional logo URL */
|
|
133
133
|
logoUrl?: string;
|
|
134
134
|
/** Optional website URL */
|
|
@@ -262,6 +262,7 @@ declare class Settlr {
|
|
|
262
262
|
private connection;
|
|
263
263
|
private usdcMint;
|
|
264
264
|
private merchantWallet;
|
|
265
|
+
private merchantWalletFromValidation?;
|
|
265
266
|
private apiBaseUrl;
|
|
266
267
|
private validated;
|
|
267
268
|
private merchantId?;
|
|
@@ -403,10 +404,15 @@ declare class Settlr {
|
|
|
403
404
|
* Get the connection instance
|
|
404
405
|
*/
|
|
405
406
|
getConnection(): Connection;
|
|
407
|
+
/**
|
|
408
|
+
* Get merchant wallet - from config or from API validation
|
|
409
|
+
* @internal
|
|
410
|
+
*/
|
|
411
|
+
private getMerchantWallet;
|
|
406
412
|
/**
|
|
407
413
|
* Get merchant wallet address
|
|
408
414
|
*/
|
|
409
|
-
getMerchantAddress(): PublicKey;
|
|
415
|
+
getMerchantAddress(): PublicKey | null;
|
|
410
416
|
/**
|
|
411
417
|
* Get USDC mint address
|
|
412
418
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -127,8 +127,8 @@ interface PaymentResult {
|
|
|
127
127
|
interface MerchantConfig {
|
|
128
128
|
/** Merchant display name */
|
|
129
129
|
name: string;
|
|
130
|
-
/** Merchant wallet address (receives payments) */
|
|
131
|
-
walletAddress
|
|
130
|
+
/** Merchant wallet address (receives payments) - optional if using registered API key */
|
|
131
|
+
walletAddress?: string | PublicKey;
|
|
132
132
|
/** Optional logo URL */
|
|
133
133
|
logoUrl?: string;
|
|
134
134
|
/** Optional website URL */
|
|
@@ -262,6 +262,7 @@ declare class Settlr {
|
|
|
262
262
|
private connection;
|
|
263
263
|
private usdcMint;
|
|
264
264
|
private merchantWallet;
|
|
265
|
+
private merchantWalletFromValidation?;
|
|
265
266
|
private apiBaseUrl;
|
|
266
267
|
private validated;
|
|
267
268
|
private merchantId?;
|
|
@@ -403,10 +404,15 @@ declare class Settlr {
|
|
|
403
404
|
* Get the connection instance
|
|
404
405
|
*/
|
|
405
406
|
getConnection(): Connection;
|
|
407
|
+
/**
|
|
408
|
+
* Get merchant wallet - from config or from API validation
|
|
409
|
+
* @internal
|
|
410
|
+
*/
|
|
411
|
+
private getMerchantWallet;
|
|
406
412
|
/**
|
|
407
413
|
* Get merchant wallet address
|
|
408
414
|
*/
|
|
409
|
-
getMerchantAddress(): PublicKey;
|
|
415
|
+
getMerchantAddress(): PublicKey | null;
|
|
410
416
|
/**
|
|
411
417
|
* Get USDC mint address
|
|
412
418
|
*/
|
package/dist/index.js
CHANGED
|
@@ -160,16 +160,19 @@ var Settlr = class {
|
|
|
160
160
|
if (!config.apiKey) {
|
|
161
161
|
throw new Error("API key is required. Get one at https://settlr.dev/dashboard");
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
if (
|
|
165
|
-
|
|
163
|
+
let walletAddress;
|
|
164
|
+
if (config.merchant.walletAddress) {
|
|
165
|
+
walletAddress = typeof config.merchant.walletAddress === "string" ? config.merchant.walletAddress : config.merchant.walletAddress.toBase58();
|
|
166
|
+
if (!isValidSolanaAddress(walletAddress)) {
|
|
167
|
+
throw new Error("Invalid merchant wallet address");
|
|
168
|
+
}
|
|
166
169
|
}
|
|
167
170
|
const network = config.network ?? "devnet";
|
|
168
171
|
const testMode = config.testMode ?? network === "devnet";
|
|
169
172
|
this.config = {
|
|
170
173
|
merchant: {
|
|
171
174
|
...config.merchant,
|
|
172
|
-
walletAddress
|
|
175
|
+
walletAddress: walletAddress || ""
|
|
173
176
|
},
|
|
174
177
|
apiKey: config.apiKey,
|
|
175
178
|
network,
|
|
@@ -179,7 +182,7 @@ var Settlr = class {
|
|
|
179
182
|
this.apiBaseUrl = testMode ? SETTLR_API_URL.development : SETTLR_API_URL.production;
|
|
180
183
|
this.connection = new import_web32.Connection(this.config.rpcEndpoint, "confirmed");
|
|
181
184
|
this.usdcMint = network === "devnet" ? USDC_MINT_DEVNET : USDC_MINT_MAINNET;
|
|
182
|
-
this.merchantWallet = new import_web32.PublicKey(walletAddress);
|
|
185
|
+
this.merchantWallet = walletAddress ? new import_web32.PublicKey(walletAddress) : null;
|
|
183
186
|
}
|
|
184
187
|
/**
|
|
185
188
|
* Validate API key with Settlr backend
|
|
@@ -194,7 +197,7 @@ var Settlr = class {
|
|
|
194
197
|
"X-API-Key": this.config.apiKey
|
|
195
198
|
},
|
|
196
199
|
body: JSON.stringify({
|
|
197
|
-
walletAddress: this.config.merchant.walletAddress
|
|
200
|
+
walletAddress: this.config.merchant.walletAddress || void 0
|
|
198
201
|
})
|
|
199
202
|
});
|
|
200
203
|
if (!response.ok) {
|
|
@@ -208,6 +211,13 @@ var Settlr = class {
|
|
|
208
211
|
this.validated = true;
|
|
209
212
|
this.merchantId = data.merchantId;
|
|
210
213
|
this.tier = data.tier;
|
|
214
|
+
if (data.merchantWallet && !this.merchantWallet) {
|
|
215
|
+
this.merchantWallet = new import_web32.PublicKey(data.merchantWallet);
|
|
216
|
+
this.config.merchant.walletAddress = data.merchantWallet;
|
|
217
|
+
}
|
|
218
|
+
if (data.merchantName && !this.config.merchant.name) {
|
|
219
|
+
this.config.merchant.name = data.merchantName;
|
|
220
|
+
}
|
|
211
221
|
} catch (error) {
|
|
212
222
|
if (error instanceof Error && error.message.includes("fetch")) {
|
|
213
223
|
if (this.config.apiKey.startsWith("sk_test_")) {
|
|
@@ -244,11 +254,15 @@ var Settlr = class {
|
|
|
244
254
|
*/
|
|
245
255
|
getCheckoutUrl(options) {
|
|
246
256
|
const { amount, memo, orderId, successUrl, cancelUrl } = options;
|
|
257
|
+
const walletAddress = this.config.merchant.walletAddress?.toString() || this.merchantWalletFromValidation;
|
|
258
|
+
if (!walletAddress) {
|
|
259
|
+
throw new Error("Wallet address not available. Either provide walletAddress in config or call validateApiKey() first.");
|
|
260
|
+
}
|
|
247
261
|
const baseUrl = this.config.testMode ? SETTLR_CHECKOUT_URL.development : SETTLR_CHECKOUT_URL.production;
|
|
248
262
|
const params = new URLSearchParams({
|
|
249
263
|
amount: amount.toString(),
|
|
250
264
|
merchant: this.config.merchant.name,
|
|
251
|
-
to:
|
|
265
|
+
to: walletAddress
|
|
252
266
|
});
|
|
253
267
|
if (memo) params.set("memo", memo);
|
|
254
268
|
if (orderId) params.set("orderId", orderId);
|
|
@@ -277,6 +291,10 @@ var Settlr = class {
|
|
|
277
291
|
if (amount <= 0) {
|
|
278
292
|
throw new Error("Amount must be greater than 0");
|
|
279
293
|
}
|
|
294
|
+
const walletAddress = this.config.merchant.walletAddress?.toString() || this.merchantWalletFromValidation;
|
|
295
|
+
if (!walletAddress) {
|
|
296
|
+
throw new Error("Wallet address not available. Ensure your API key is linked to a merchant with a wallet.");
|
|
297
|
+
}
|
|
280
298
|
const paymentId = generatePaymentId();
|
|
281
299
|
const amountLamports = parseUSDC(amount);
|
|
282
300
|
const createdAt = /* @__PURE__ */ new Date();
|
|
@@ -285,7 +303,7 @@ var Settlr = class {
|
|
|
285
303
|
const params = new URLSearchParams({
|
|
286
304
|
amount: amount.toString(),
|
|
287
305
|
merchant: this.config.merchant.name,
|
|
288
|
-
to:
|
|
306
|
+
to: walletAddress
|
|
289
307
|
});
|
|
290
308
|
if (memo) params.set("memo", memo);
|
|
291
309
|
if (orderId) params.set("orderId", orderId);
|
|
@@ -301,7 +319,7 @@ var Settlr = class {
|
|
|
301
319
|
// Default to USDC
|
|
302
320
|
amountLamports,
|
|
303
321
|
status: "pending",
|
|
304
|
-
merchantAddress:
|
|
322
|
+
merchantAddress: walletAddress,
|
|
305
323
|
checkoutUrl,
|
|
306
324
|
qrCode,
|
|
307
325
|
memo,
|
|
@@ -327,10 +345,14 @@ var Settlr = class {
|
|
|
327
345
|
*/
|
|
328
346
|
async buildTransaction(options) {
|
|
329
347
|
await this.validateApiKey();
|
|
348
|
+
const merchantWallet = this.getMerchantWallet();
|
|
349
|
+
if (!merchantWallet) {
|
|
350
|
+
throw new Error("Wallet address not available. Ensure your API key is linked to a merchant with a wallet.");
|
|
351
|
+
}
|
|
330
352
|
const { payerPublicKey, amount, memo } = options;
|
|
331
353
|
const amountLamports = parseUSDC(amount);
|
|
332
354
|
const payerAta = await (0, import_spl_token.getAssociatedTokenAddress)(this.usdcMint, payerPublicKey);
|
|
333
|
-
const merchantAta = await (0, import_spl_token.getAssociatedTokenAddress)(this.usdcMint,
|
|
355
|
+
const merchantAta = await (0, import_spl_token.getAssociatedTokenAddress)(this.usdcMint, merchantWallet);
|
|
334
356
|
const instructions = [];
|
|
335
357
|
try {
|
|
336
358
|
await (0, import_spl_token.getAccount)(this.connection, merchantAta);
|
|
@@ -340,7 +362,7 @@ var Settlr = class {
|
|
|
340
362
|
(0, import_spl_token.createAssociatedTokenAccountInstruction)(
|
|
341
363
|
payerPublicKey,
|
|
342
364
|
merchantAta,
|
|
343
|
-
|
|
365
|
+
merchantWallet,
|
|
344
366
|
this.usdcMint
|
|
345
367
|
)
|
|
346
368
|
);
|
|
@@ -412,18 +434,20 @@ var Settlr = class {
|
|
|
412
434
|
lastValidBlockHeight,
|
|
413
435
|
signature
|
|
414
436
|
});
|
|
437
|
+
const merchantWallet = this.getMerchantWallet();
|
|
415
438
|
return {
|
|
416
439
|
success: true,
|
|
417
440
|
signature,
|
|
418
441
|
amount,
|
|
419
|
-
merchantAddress:
|
|
442
|
+
merchantAddress: merchantWallet?.toBase58() || ""
|
|
420
443
|
};
|
|
421
444
|
} catch (error) {
|
|
445
|
+
const merchantWallet = this.getMerchantWallet();
|
|
422
446
|
return {
|
|
423
447
|
success: false,
|
|
424
448
|
signature: "",
|
|
425
449
|
amount,
|
|
426
|
-
merchantAddress:
|
|
450
|
+
merchantAddress: merchantWallet?.toBase58() || "",
|
|
427
451
|
error: error instanceof Error ? error.message : "Payment failed"
|
|
428
452
|
};
|
|
429
453
|
}
|
|
@@ -500,7 +524,11 @@ var Settlr = class {
|
|
|
500
524
|
*/
|
|
501
525
|
async getMerchantBalance() {
|
|
502
526
|
try {
|
|
503
|
-
const
|
|
527
|
+
const merchantWallet = this.getMerchantWallet();
|
|
528
|
+
if (!merchantWallet) {
|
|
529
|
+
throw new Error("Merchant wallet not available");
|
|
530
|
+
}
|
|
531
|
+
const ata = await (0, import_spl_token.getAssociatedTokenAddress)(this.usdcMint, merchantWallet);
|
|
504
532
|
const account = await (0, import_spl_token.getAccount)(this.connection, ata);
|
|
505
533
|
return Number(account.amount) / 1e6;
|
|
506
534
|
} catch {
|
|
@@ -520,11 +548,24 @@ var Settlr = class {
|
|
|
520
548
|
getConnection() {
|
|
521
549
|
return this.connection;
|
|
522
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Get merchant wallet - from config or from API validation
|
|
553
|
+
* @internal
|
|
554
|
+
*/
|
|
555
|
+
getMerchantWallet() {
|
|
556
|
+
if (this.merchantWallet) {
|
|
557
|
+
return this.merchantWallet;
|
|
558
|
+
}
|
|
559
|
+
if (this.merchantWalletFromValidation) {
|
|
560
|
+
return new import_web32.PublicKey(this.merchantWalletFromValidation);
|
|
561
|
+
}
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
523
564
|
/**
|
|
524
565
|
* Get merchant wallet address
|
|
525
566
|
*/
|
|
526
567
|
getMerchantAddress() {
|
|
527
|
-
return this.
|
|
568
|
+
return this.getMerchantWallet();
|
|
528
569
|
}
|
|
529
570
|
/**
|
|
530
571
|
* Get USDC mint address
|
package/dist/index.mjs
CHANGED
|
@@ -113,16 +113,19 @@ var Settlr = class {
|
|
|
113
113
|
if (!config.apiKey) {
|
|
114
114
|
throw new Error("API key is required. Get one at https://settlr.dev/dashboard");
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
116
|
+
let walletAddress;
|
|
117
|
+
if (config.merchant.walletAddress) {
|
|
118
|
+
walletAddress = typeof config.merchant.walletAddress === "string" ? config.merchant.walletAddress : config.merchant.walletAddress.toBase58();
|
|
119
|
+
if (!isValidSolanaAddress(walletAddress)) {
|
|
120
|
+
throw new Error("Invalid merchant wallet address");
|
|
121
|
+
}
|
|
119
122
|
}
|
|
120
123
|
const network = config.network ?? "devnet";
|
|
121
124
|
const testMode = config.testMode ?? network === "devnet";
|
|
122
125
|
this.config = {
|
|
123
126
|
merchant: {
|
|
124
127
|
...config.merchant,
|
|
125
|
-
walletAddress
|
|
128
|
+
walletAddress: walletAddress || ""
|
|
126
129
|
},
|
|
127
130
|
apiKey: config.apiKey,
|
|
128
131
|
network,
|
|
@@ -132,7 +135,7 @@ var Settlr = class {
|
|
|
132
135
|
this.apiBaseUrl = testMode ? SETTLR_API_URL.development : SETTLR_API_URL.production;
|
|
133
136
|
this.connection = new Connection(this.config.rpcEndpoint, "confirmed");
|
|
134
137
|
this.usdcMint = network === "devnet" ? USDC_MINT_DEVNET : USDC_MINT_MAINNET;
|
|
135
|
-
this.merchantWallet = new PublicKey2(walletAddress);
|
|
138
|
+
this.merchantWallet = walletAddress ? new PublicKey2(walletAddress) : null;
|
|
136
139
|
}
|
|
137
140
|
/**
|
|
138
141
|
* Validate API key with Settlr backend
|
|
@@ -147,7 +150,7 @@ var Settlr = class {
|
|
|
147
150
|
"X-API-Key": this.config.apiKey
|
|
148
151
|
},
|
|
149
152
|
body: JSON.stringify({
|
|
150
|
-
walletAddress: this.config.merchant.walletAddress
|
|
153
|
+
walletAddress: this.config.merchant.walletAddress || void 0
|
|
151
154
|
})
|
|
152
155
|
});
|
|
153
156
|
if (!response.ok) {
|
|
@@ -161,6 +164,13 @@ var Settlr = class {
|
|
|
161
164
|
this.validated = true;
|
|
162
165
|
this.merchantId = data.merchantId;
|
|
163
166
|
this.tier = data.tier;
|
|
167
|
+
if (data.merchantWallet && !this.merchantWallet) {
|
|
168
|
+
this.merchantWallet = new PublicKey2(data.merchantWallet);
|
|
169
|
+
this.config.merchant.walletAddress = data.merchantWallet;
|
|
170
|
+
}
|
|
171
|
+
if (data.merchantName && !this.config.merchant.name) {
|
|
172
|
+
this.config.merchant.name = data.merchantName;
|
|
173
|
+
}
|
|
164
174
|
} catch (error) {
|
|
165
175
|
if (error instanceof Error && error.message.includes("fetch")) {
|
|
166
176
|
if (this.config.apiKey.startsWith("sk_test_")) {
|
|
@@ -197,11 +207,15 @@ var Settlr = class {
|
|
|
197
207
|
*/
|
|
198
208
|
getCheckoutUrl(options) {
|
|
199
209
|
const { amount, memo, orderId, successUrl, cancelUrl } = options;
|
|
210
|
+
const walletAddress = this.config.merchant.walletAddress?.toString() || this.merchantWalletFromValidation;
|
|
211
|
+
if (!walletAddress) {
|
|
212
|
+
throw new Error("Wallet address not available. Either provide walletAddress in config or call validateApiKey() first.");
|
|
213
|
+
}
|
|
200
214
|
const baseUrl = this.config.testMode ? SETTLR_CHECKOUT_URL.development : SETTLR_CHECKOUT_URL.production;
|
|
201
215
|
const params = new URLSearchParams({
|
|
202
216
|
amount: amount.toString(),
|
|
203
217
|
merchant: this.config.merchant.name,
|
|
204
|
-
to:
|
|
218
|
+
to: walletAddress
|
|
205
219
|
});
|
|
206
220
|
if (memo) params.set("memo", memo);
|
|
207
221
|
if (orderId) params.set("orderId", orderId);
|
|
@@ -230,6 +244,10 @@ var Settlr = class {
|
|
|
230
244
|
if (amount <= 0) {
|
|
231
245
|
throw new Error("Amount must be greater than 0");
|
|
232
246
|
}
|
|
247
|
+
const walletAddress = this.config.merchant.walletAddress?.toString() || this.merchantWalletFromValidation;
|
|
248
|
+
if (!walletAddress) {
|
|
249
|
+
throw new Error("Wallet address not available. Ensure your API key is linked to a merchant with a wallet.");
|
|
250
|
+
}
|
|
233
251
|
const paymentId = generatePaymentId();
|
|
234
252
|
const amountLamports = parseUSDC(amount);
|
|
235
253
|
const createdAt = /* @__PURE__ */ new Date();
|
|
@@ -238,7 +256,7 @@ var Settlr = class {
|
|
|
238
256
|
const params = new URLSearchParams({
|
|
239
257
|
amount: amount.toString(),
|
|
240
258
|
merchant: this.config.merchant.name,
|
|
241
|
-
to:
|
|
259
|
+
to: walletAddress
|
|
242
260
|
});
|
|
243
261
|
if (memo) params.set("memo", memo);
|
|
244
262
|
if (orderId) params.set("orderId", orderId);
|
|
@@ -254,7 +272,7 @@ var Settlr = class {
|
|
|
254
272
|
// Default to USDC
|
|
255
273
|
amountLamports,
|
|
256
274
|
status: "pending",
|
|
257
|
-
merchantAddress:
|
|
275
|
+
merchantAddress: walletAddress,
|
|
258
276
|
checkoutUrl,
|
|
259
277
|
qrCode,
|
|
260
278
|
memo,
|
|
@@ -280,10 +298,14 @@ var Settlr = class {
|
|
|
280
298
|
*/
|
|
281
299
|
async buildTransaction(options) {
|
|
282
300
|
await this.validateApiKey();
|
|
301
|
+
const merchantWallet = this.getMerchantWallet();
|
|
302
|
+
if (!merchantWallet) {
|
|
303
|
+
throw new Error("Wallet address not available. Ensure your API key is linked to a merchant with a wallet.");
|
|
304
|
+
}
|
|
283
305
|
const { payerPublicKey, amount, memo } = options;
|
|
284
306
|
const amountLamports = parseUSDC(amount);
|
|
285
307
|
const payerAta = await getAssociatedTokenAddress(this.usdcMint, payerPublicKey);
|
|
286
|
-
const merchantAta = await getAssociatedTokenAddress(this.usdcMint,
|
|
308
|
+
const merchantAta = await getAssociatedTokenAddress(this.usdcMint, merchantWallet);
|
|
287
309
|
const instructions = [];
|
|
288
310
|
try {
|
|
289
311
|
await getAccount(this.connection, merchantAta);
|
|
@@ -293,7 +315,7 @@ var Settlr = class {
|
|
|
293
315
|
createAssociatedTokenAccountInstruction(
|
|
294
316
|
payerPublicKey,
|
|
295
317
|
merchantAta,
|
|
296
|
-
|
|
318
|
+
merchantWallet,
|
|
297
319
|
this.usdcMint
|
|
298
320
|
)
|
|
299
321
|
);
|
|
@@ -365,18 +387,20 @@ var Settlr = class {
|
|
|
365
387
|
lastValidBlockHeight,
|
|
366
388
|
signature
|
|
367
389
|
});
|
|
390
|
+
const merchantWallet = this.getMerchantWallet();
|
|
368
391
|
return {
|
|
369
392
|
success: true,
|
|
370
393
|
signature,
|
|
371
394
|
amount,
|
|
372
|
-
merchantAddress:
|
|
395
|
+
merchantAddress: merchantWallet?.toBase58() || ""
|
|
373
396
|
};
|
|
374
397
|
} catch (error) {
|
|
398
|
+
const merchantWallet = this.getMerchantWallet();
|
|
375
399
|
return {
|
|
376
400
|
success: false,
|
|
377
401
|
signature: "",
|
|
378
402
|
amount,
|
|
379
|
-
merchantAddress:
|
|
403
|
+
merchantAddress: merchantWallet?.toBase58() || "",
|
|
380
404
|
error: error instanceof Error ? error.message : "Payment failed"
|
|
381
405
|
};
|
|
382
406
|
}
|
|
@@ -453,7 +477,11 @@ var Settlr = class {
|
|
|
453
477
|
*/
|
|
454
478
|
async getMerchantBalance() {
|
|
455
479
|
try {
|
|
456
|
-
const
|
|
480
|
+
const merchantWallet = this.getMerchantWallet();
|
|
481
|
+
if (!merchantWallet) {
|
|
482
|
+
throw new Error("Merchant wallet not available");
|
|
483
|
+
}
|
|
484
|
+
const ata = await getAssociatedTokenAddress(this.usdcMint, merchantWallet);
|
|
457
485
|
const account = await getAccount(this.connection, ata);
|
|
458
486
|
return Number(account.amount) / 1e6;
|
|
459
487
|
} catch {
|
|
@@ -473,11 +501,24 @@ var Settlr = class {
|
|
|
473
501
|
getConnection() {
|
|
474
502
|
return this.connection;
|
|
475
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Get merchant wallet - from config or from API validation
|
|
506
|
+
* @internal
|
|
507
|
+
*/
|
|
508
|
+
getMerchantWallet() {
|
|
509
|
+
if (this.merchantWallet) {
|
|
510
|
+
return this.merchantWallet;
|
|
511
|
+
}
|
|
512
|
+
if (this.merchantWalletFromValidation) {
|
|
513
|
+
return new PublicKey2(this.merchantWalletFromValidation);
|
|
514
|
+
}
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
476
517
|
/**
|
|
477
518
|
* Get merchant wallet address
|
|
478
519
|
*/
|
|
479
520
|
getMerchantAddress() {
|
|
480
|
-
return this.
|
|
521
|
+
return this.getMerchantWallet();
|
|
481
522
|
}
|
|
482
523
|
/**
|
|
483
524
|
* Get USDC mint address
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlr/sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Settlr SDK - Accept Solana USDC payments in games and apps. Email checkout, gasless transactions, no wallet required. The easiest way to add crypto payments.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|