@settlr/sdk 0.6.1 → 0.6.3
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.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +46 -5
- package/dist/index.mjs +62 -15
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -31,7 +31,7 @@ declare const SUPPORTED_TOKENS: {
|
|
|
31
31
|
type SupportedToken = keyof typeof SUPPORTED_TOKENS;
|
|
32
32
|
declare const SETTLR_CHECKOUT_URL: {
|
|
33
33
|
readonly production: "https://settlr.dev/checkout";
|
|
34
|
-
readonly development: "
|
|
34
|
+
readonly development: "https://settlr.dev/checkout";
|
|
35
35
|
};
|
|
36
36
|
declare const SUPPORTED_NETWORKS: readonly ["devnet", "mainnet-beta"];
|
|
37
37
|
type SupportedNetwork = typeof SUPPORTED_NETWORKS[number];
|
|
@@ -270,8 +270,10 @@ declare class Settlr {
|
|
|
270
270
|
constructor(config: SettlrConfig);
|
|
271
271
|
/**
|
|
272
272
|
* Validate API key with Settlr backend
|
|
273
|
+
* This is called automatically by SettlrProvider, but can also be called manually.
|
|
274
|
+
* Fetches merchant wallet address if not provided in config.
|
|
273
275
|
*/
|
|
274
|
-
|
|
276
|
+
validateApiKey(): Promise<void>;
|
|
275
277
|
/**
|
|
276
278
|
* Get the current tier
|
|
277
279
|
*/
|
|
@@ -455,6 +457,10 @@ interface SettlrContextValue {
|
|
|
455
457
|
settlr: Settlr | null;
|
|
456
458
|
/** Whether user is authenticated */
|
|
457
459
|
authenticated: boolean;
|
|
460
|
+
/** Whether the SDK is ready (API key validated) */
|
|
461
|
+
ready: boolean;
|
|
462
|
+
/** Error if initialization failed */
|
|
463
|
+
error: Error | null;
|
|
458
464
|
/** Create a payment link (redirect flow) */
|
|
459
465
|
createPayment: (options: CreatePaymentOptions) => Promise<Payment>;
|
|
460
466
|
/** Generate checkout URL for redirect */
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare const SUPPORTED_TOKENS: {
|
|
|
31
31
|
type SupportedToken = keyof typeof SUPPORTED_TOKENS;
|
|
32
32
|
declare const SETTLR_CHECKOUT_URL: {
|
|
33
33
|
readonly production: "https://settlr.dev/checkout";
|
|
34
|
-
readonly development: "
|
|
34
|
+
readonly development: "https://settlr.dev/checkout";
|
|
35
35
|
};
|
|
36
36
|
declare const SUPPORTED_NETWORKS: readonly ["devnet", "mainnet-beta"];
|
|
37
37
|
type SupportedNetwork = typeof SUPPORTED_NETWORKS[number];
|
|
@@ -270,8 +270,10 @@ declare class Settlr {
|
|
|
270
270
|
constructor(config: SettlrConfig);
|
|
271
271
|
/**
|
|
272
272
|
* Validate API key with Settlr backend
|
|
273
|
+
* This is called automatically by SettlrProvider, but can also be called manually.
|
|
274
|
+
* Fetches merchant wallet address if not provided in config.
|
|
273
275
|
*/
|
|
274
|
-
|
|
276
|
+
validateApiKey(): Promise<void>;
|
|
275
277
|
/**
|
|
276
278
|
* Get the current tier
|
|
277
279
|
*/
|
|
@@ -455,6 +457,10 @@ interface SettlrContextValue {
|
|
|
455
457
|
settlr: Settlr | null;
|
|
456
458
|
/** Whether user is authenticated */
|
|
457
459
|
authenticated: boolean;
|
|
460
|
+
/** Whether the SDK is ready (API key validated) */
|
|
461
|
+
ready: boolean;
|
|
462
|
+
/** Error if initialization failed */
|
|
463
|
+
error: Error | null;
|
|
458
464
|
/** Create a payment link (redirect flow) */
|
|
459
465
|
createPayment: (options: CreatePaymentOptions) => Promise<Payment>;
|
|
460
466
|
/** Generate checkout URL for redirect */
|
package/dist/index.js
CHANGED
|
@@ -107,11 +107,13 @@ var SUPPORTED_TOKENS = {
|
|
|
107
107
|
};
|
|
108
108
|
var SETTLR_API_URL = {
|
|
109
109
|
production: "https://settlr.dev/api",
|
|
110
|
-
development: "
|
|
110
|
+
development: "https://settlr.dev/api"
|
|
111
|
+
// Always use production API
|
|
111
112
|
};
|
|
112
113
|
var SETTLR_CHECKOUT_URL = {
|
|
113
114
|
production: "https://settlr.dev/checkout",
|
|
114
|
-
development: "
|
|
115
|
+
development: "https://settlr.dev/checkout"
|
|
116
|
+
// Always use production checkout
|
|
115
117
|
};
|
|
116
118
|
var SUPPORTED_NETWORKS = ["devnet", "mainnet-beta"];
|
|
117
119
|
var USDC_DECIMALS = 6;
|
|
@@ -203,6 +205,8 @@ var Settlr = class {
|
|
|
203
205
|
}
|
|
204
206
|
/**
|
|
205
207
|
* Validate API key with Settlr backend
|
|
208
|
+
* This is called automatically by SettlrProvider, but can also be called manually.
|
|
209
|
+
* Fetches merchant wallet address if not provided in config.
|
|
206
210
|
*/
|
|
207
211
|
async validateApiKey() {
|
|
208
212
|
if (this.validated) return;
|
|
@@ -230,6 +234,7 @@ var Settlr = class {
|
|
|
230
234
|
this.tier = data.tier;
|
|
231
235
|
if (data.merchantWallet && !this.merchantWallet) {
|
|
232
236
|
this.merchantWallet = new import_web32.PublicKey(data.merchantWallet);
|
|
237
|
+
this.merchantWalletFromValidation = data.merchantWallet;
|
|
233
238
|
this.config.merchant.walletAddress = data.merchantWallet;
|
|
234
239
|
}
|
|
235
240
|
if (data.merchantName && !this.config.merchant.name) {
|
|
@@ -511,7 +516,7 @@ var Settlr = class {
|
|
|
511
516
|
if (amount <= 0) {
|
|
512
517
|
throw new Error("Amount must be greater than 0");
|
|
513
518
|
}
|
|
514
|
-
const baseUrl =
|
|
519
|
+
const baseUrl = "https://settlr.dev";
|
|
515
520
|
const response = await fetch(`${baseUrl}/api/checkout/sessions`, {
|
|
516
521
|
method: "POST",
|
|
517
522
|
headers: {
|
|
@@ -601,27 +606,54 @@ function SettlrProvider({
|
|
|
601
606
|
config,
|
|
602
607
|
authenticated = false
|
|
603
608
|
}) {
|
|
609
|
+
const [ready, setReady] = (0, import_react.useState)(false);
|
|
610
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
604
611
|
const settlr = (0, import_react.useMemo)(() => {
|
|
605
612
|
return new Settlr({
|
|
606
613
|
...config,
|
|
607
614
|
rpcEndpoint: config.rpcEndpoint ?? "https://api.devnet.solana.com"
|
|
608
615
|
});
|
|
609
616
|
}, [config]);
|
|
617
|
+
(0, import_react.useEffect)(() => {
|
|
618
|
+
let cancelled = false;
|
|
619
|
+
settlr.validateApiKey().then(() => {
|
|
620
|
+
if (!cancelled) {
|
|
621
|
+
setReady(true);
|
|
622
|
+
setError(null);
|
|
623
|
+
}
|
|
624
|
+
}).catch((err) => {
|
|
625
|
+
if (!cancelled) {
|
|
626
|
+
console.error("[Settlr] API key validation failed:", err);
|
|
627
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
628
|
+
if (config.apiKey?.startsWith("sk_test_")) {
|
|
629
|
+
setReady(true);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
return () => {
|
|
634
|
+
cancelled = true;
|
|
635
|
+
};
|
|
636
|
+
}, [settlr, config.apiKey]);
|
|
610
637
|
const value = (0, import_react.useMemo)(
|
|
611
638
|
() => ({
|
|
612
639
|
settlr,
|
|
613
640
|
authenticated,
|
|
641
|
+
ready,
|
|
642
|
+
error,
|
|
614
643
|
createPayment: (options) => {
|
|
615
644
|
return settlr.createPayment(options);
|
|
616
645
|
},
|
|
617
646
|
getCheckoutUrl: (options) => {
|
|
647
|
+
if (!ready) {
|
|
648
|
+
console.warn("[Settlr] SDK not ready yet. Ensure API key is valid.");
|
|
649
|
+
}
|
|
618
650
|
return settlr.getCheckoutUrl(options);
|
|
619
651
|
},
|
|
620
652
|
getBalance: () => {
|
|
621
653
|
return settlr.getMerchantBalance();
|
|
622
654
|
}
|
|
623
655
|
}),
|
|
624
|
-
[settlr, authenticated]
|
|
656
|
+
[settlr, authenticated, ready, error]
|
|
625
657
|
);
|
|
626
658
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SettlrContext.Provider, { value, children });
|
|
627
659
|
}
|
|
@@ -701,11 +733,18 @@ function BuyButton({
|
|
|
701
733
|
variant = "primary",
|
|
702
734
|
size = "md"
|
|
703
735
|
}) {
|
|
704
|
-
const { getCheckoutUrl, createPayment } = useSettlr();
|
|
736
|
+
const { getCheckoutUrl, createPayment, ready, error: sdkError } = useSettlr();
|
|
705
737
|
const [loading, setLoading] = (0, import_react2.useState)(false);
|
|
706
738
|
const [status, setStatus] = (0, import_react2.useState)("idle");
|
|
707
739
|
const handleClick = (0, import_react2.useCallback)(async () => {
|
|
708
740
|
if (disabled || loading) return;
|
|
741
|
+
if (!ready) {
|
|
742
|
+
const notReadyError = new Error(
|
|
743
|
+
sdkError?.message || "Settlr SDK not ready. Please check your API key configuration."
|
|
744
|
+
);
|
|
745
|
+
onError?.(notReadyError);
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
709
748
|
setLoading(true);
|
|
710
749
|
setStatus("processing");
|
|
711
750
|
onProcessing?.();
|
|
@@ -729,6 +768,8 @@ function BuyButton({
|
|
|
729
768
|
orderId,
|
|
730
769
|
disabled,
|
|
731
770
|
loading,
|
|
771
|
+
ready,
|
|
772
|
+
sdkError,
|
|
732
773
|
successUrl,
|
|
733
774
|
cancelUrl,
|
|
734
775
|
getCheckoutUrl,
|
package/dist/index.mjs
CHANGED
|
@@ -43,11 +43,13 @@ var SUPPORTED_TOKENS = {
|
|
|
43
43
|
};
|
|
44
44
|
var SETTLR_API_URL = {
|
|
45
45
|
production: "https://settlr.dev/api",
|
|
46
|
-
development: "
|
|
46
|
+
development: "https://settlr.dev/api"
|
|
47
|
+
// Always use production API
|
|
47
48
|
};
|
|
48
49
|
var SETTLR_CHECKOUT_URL = {
|
|
49
50
|
production: "https://settlr.dev/checkout",
|
|
50
|
-
development: "
|
|
51
|
+
development: "https://settlr.dev/checkout"
|
|
52
|
+
// Always use production checkout
|
|
51
53
|
};
|
|
52
54
|
var SUPPORTED_NETWORKS = ["devnet", "mainnet-beta"];
|
|
53
55
|
var USDC_DECIMALS = 6;
|
|
@@ -139,6 +141,8 @@ var Settlr = class {
|
|
|
139
141
|
}
|
|
140
142
|
/**
|
|
141
143
|
* Validate API key with Settlr backend
|
|
144
|
+
* This is called automatically by SettlrProvider, but can also be called manually.
|
|
145
|
+
* Fetches merchant wallet address if not provided in config.
|
|
142
146
|
*/
|
|
143
147
|
async validateApiKey() {
|
|
144
148
|
if (this.validated) return;
|
|
@@ -166,6 +170,7 @@ var Settlr = class {
|
|
|
166
170
|
this.tier = data.tier;
|
|
167
171
|
if (data.merchantWallet && !this.merchantWallet) {
|
|
168
172
|
this.merchantWallet = new PublicKey2(data.merchantWallet);
|
|
173
|
+
this.merchantWalletFromValidation = data.merchantWallet;
|
|
169
174
|
this.config.merchant.walletAddress = data.merchantWallet;
|
|
170
175
|
}
|
|
171
176
|
if (data.merchantName && !this.config.merchant.name) {
|
|
@@ -447,7 +452,7 @@ var Settlr = class {
|
|
|
447
452
|
if (amount <= 0) {
|
|
448
453
|
throw new Error("Amount must be greater than 0");
|
|
449
454
|
}
|
|
450
|
-
const baseUrl =
|
|
455
|
+
const baseUrl = "https://settlr.dev";
|
|
451
456
|
const response = await fetch(`${baseUrl}/api/checkout/sessions`, {
|
|
452
457
|
method: "POST",
|
|
453
458
|
headers: {
|
|
@@ -529,7 +534,13 @@ var Settlr = class {
|
|
|
529
534
|
};
|
|
530
535
|
|
|
531
536
|
// src/react.tsx
|
|
532
|
-
import {
|
|
537
|
+
import {
|
|
538
|
+
createContext,
|
|
539
|
+
useContext,
|
|
540
|
+
useMemo,
|
|
541
|
+
useEffect,
|
|
542
|
+
useState
|
|
543
|
+
} from "react";
|
|
533
544
|
import { jsx } from "react/jsx-runtime";
|
|
534
545
|
var SettlrContext = createContext(null);
|
|
535
546
|
function SettlrProvider({
|
|
@@ -537,27 +548,54 @@ function SettlrProvider({
|
|
|
537
548
|
config,
|
|
538
549
|
authenticated = false
|
|
539
550
|
}) {
|
|
551
|
+
const [ready, setReady] = useState(false);
|
|
552
|
+
const [error, setError] = useState(null);
|
|
540
553
|
const settlr = useMemo(() => {
|
|
541
554
|
return new Settlr({
|
|
542
555
|
...config,
|
|
543
556
|
rpcEndpoint: config.rpcEndpoint ?? "https://api.devnet.solana.com"
|
|
544
557
|
});
|
|
545
558
|
}, [config]);
|
|
559
|
+
useEffect(() => {
|
|
560
|
+
let cancelled = false;
|
|
561
|
+
settlr.validateApiKey().then(() => {
|
|
562
|
+
if (!cancelled) {
|
|
563
|
+
setReady(true);
|
|
564
|
+
setError(null);
|
|
565
|
+
}
|
|
566
|
+
}).catch((err) => {
|
|
567
|
+
if (!cancelled) {
|
|
568
|
+
console.error("[Settlr] API key validation failed:", err);
|
|
569
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
570
|
+
if (config.apiKey?.startsWith("sk_test_")) {
|
|
571
|
+
setReady(true);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
return () => {
|
|
576
|
+
cancelled = true;
|
|
577
|
+
};
|
|
578
|
+
}, [settlr, config.apiKey]);
|
|
546
579
|
const value = useMemo(
|
|
547
580
|
() => ({
|
|
548
581
|
settlr,
|
|
549
582
|
authenticated,
|
|
583
|
+
ready,
|
|
584
|
+
error,
|
|
550
585
|
createPayment: (options) => {
|
|
551
586
|
return settlr.createPayment(options);
|
|
552
587
|
},
|
|
553
588
|
getCheckoutUrl: (options) => {
|
|
589
|
+
if (!ready) {
|
|
590
|
+
console.warn("[Settlr] SDK not ready yet. Ensure API key is valid.");
|
|
591
|
+
}
|
|
554
592
|
return settlr.getCheckoutUrl(options);
|
|
555
593
|
},
|
|
556
594
|
getBalance: () => {
|
|
557
595
|
return settlr.getMerchantBalance();
|
|
558
596
|
}
|
|
559
597
|
}),
|
|
560
|
-
[settlr, authenticated]
|
|
598
|
+
[settlr, authenticated, ready, error]
|
|
561
599
|
);
|
|
562
600
|
return /* @__PURE__ */ jsx(SettlrContext.Provider, { value, children });
|
|
563
601
|
}
|
|
@@ -571,9 +609,9 @@ function useSettlr() {
|
|
|
571
609
|
|
|
572
610
|
// src/components.tsx
|
|
573
611
|
import {
|
|
574
|
-
useState,
|
|
612
|
+
useState as useState2,
|
|
575
613
|
useCallback,
|
|
576
|
-
useEffect
|
|
614
|
+
useEffect as useEffect2
|
|
577
615
|
} from "react";
|
|
578
616
|
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
579
617
|
var defaultStyles = {
|
|
@@ -641,11 +679,18 @@ function BuyButton({
|
|
|
641
679
|
variant = "primary",
|
|
642
680
|
size = "md"
|
|
643
681
|
}) {
|
|
644
|
-
const { getCheckoutUrl, createPayment } = useSettlr();
|
|
645
|
-
const [loading, setLoading] =
|
|
646
|
-
const [status, setStatus] =
|
|
682
|
+
const { getCheckoutUrl, createPayment, ready, error: sdkError } = useSettlr();
|
|
683
|
+
const [loading, setLoading] = useState2(false);
|
|
684
|
+
const [status, setStatus] = useState2("idle");
|
|
647
685
|
const handleClick = useCallback(async () => {
|
|
648
686
|
if (disabled || loading) return;
|
|
687
|
+
if (!ready) {
|
|
688
|
+
const notReadyError = new Error(
|
|
689
|
+
sdkError?.message || "Settlr SDK not ready. Please check your API key configuration."
|
|
690
|
+
);
|
|
691
|
+
onError?.(notReadyError);
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
649
694
|
setLoading(true);
|
|
650
695
|
setStatus("processing");
|
|
651
696
|
onProcessing?.();
|
|
@@ -669,6 +714,8 @@ function BuyButton({
|
|
|
669
714
|
orderId,
|
|
670
715
|
disabled,
|
|
671
716
|
loading,
|
|
717
|
+
ready,
|
|
718
|
+
sdkError,
|
|
672
719
|
successUrl,
|
|
673
720
|
cancelUrl,
|
|
674
721
|
getCheckoutUrl,
|
|
@@ -820,7 +867,7 @@ function CheckoutWidget({
|
|
|
820
867
|
showBranding = true
|
|
821
868
|
}) {
|
|
822
869
|
const { getCheckoutUrl } = useSettlr();
|
|
823
|
-
const [status, setStatus] =
|
|
870
|
+
const [status, setStatus] = useState2("idle");
|
|
824
871
|
const containerStyle = {
|
|
825
872
|
...widgetStyles.container,
|
|
826
873
|
...theme === "dark" ? widgetStyles.containerDark : widgetStyles.containerLight,
|
|
@@ -1003,7 +1050,7 @@ function PaymentModal({
|
|
|
1003
1050
|
onError,
|
|
1004
1051
|
checkoutUrl = "https://settlr.dev/checkout"
|
|
1005
1052
|
}) {
|
|
1006
|
-
const [loading, setLoading] =
|
|
1053
|
+
const [loading, setLoading] = useState2(true);
|
|
1007
1054
|
const params = new URLSearchParams({
|
|
1008
1055
|
amount: amount.toString(),
|
|
1009
1056
|
merchant: merchantName,
|
|
@@ -1013,7 +1060,7 @@ function PaymentModal({
|
|
|
1013
1060
|
if (memo) params.set("memo", memo);
|
|
1014
1061
|
if (orderId) params.set("orderId", orderId);
|
|
1015
1062
|
const iframeSrc = `${checkoutUrl}?${params.toString()}`;
|
|
1016
|
-
|
|
1063
|
+
useEffect2(() => {
|
|
1017
1064
|
const handleMessage = (event) => {
|
|
1018
1065
|
if (!event.origin.includes("settlr.dev") && !event.origin.includes("localhost")) {
|
|
1019
1066
|
return;
|
|
@@ -1037,7 +1084,7 @@ function PaymentModal({
|
|
|
1037
1084
|
window.addEventListener("message", handleMessage);
|
|
1038
1085
|
return () => window.removeEventListener("message", handleMessage);
|
|
1039
1086
|
}, [amount, onSuccess, onError, onClose]);
|
|
1040
|
-
|
|
1087
|
+
useEffect2(() => {
|
|
1041
1088
|
const handleEscape = (e) => {
|
|
1042
1089
|
if (e.key === "Escape") onClose?.();
|
|
1043
1090
|
};
|
|
@@ -1074,7 +1121,7 @@ function PaymentModal({
|
|
|
1074
1121
|
] }) });
|
|
1075
1122
|
}
|
|
1076
1123
|
function usePaymentModal(config) {
|
|
1077
|
-
const [modalState, setModalState] =
|
|
1124
|
+
const [modalState, setModalState] = useState2({
|
|
1078
1125
|
isOpen: false,
|
|
1079
1126
|
amount: 0
|
|
1080
1127
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlr/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Settlr SDK - Accept Solana USDC payments with privacy. Email checkout, gasless transactions, FHE-encrypted receipts. Private on-chain, compliant off-chain.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|