@settlr/sdk 0.6.1 → 0.6.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/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +41 -2
- package/dist/index.mjs +57 -12
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -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
|
@@ -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
|
@@ -203,6 +203,8 @@ var Settlr = class {
|
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* Validate API key with Settlr backend
|
|
206
|
+
* This is called automatically by SettlrProvider, but can also be called manually.
|
|
207
|
+
* Fetches merchant wallet address if not provided in config.
|
|
206
208
|
*/
|
|
207
209
|
async validateApiKey() {
|
|
208
210
|
if (this.validated) return;
|
|
@@ -230,6 +232,7 @@ var Settlr = class {
|
|
|
230
232
|
this.tier = data.tier;
|
|
231
233
|
if (data.merchantWallet && !this.merchantWallet) {
|
|
232
234
|
this.merchantWallet = new import_web32.PublicKey(data.merchantWallet);
|
|
235
|
+
this.merchantWalletFromValidation = data.merchantWallet;
|
|
233
236
|
this.config.merchant.walletAddress = data.merchantWallet;
|
|
234
237
|
}
|
|
235
238
|
if (data.merchantName && !this.config.merchant.name) {
|
|
@@ -601,27 +604,54 @@ function SettlrProvider({
|
|
|
601
604
|
config,
|
|
602
605
|
authenticated = false
|
|
603
606
|
}) {
|
|
607
|
+
const [ready, setReady] = (0, import_react.useState)(false);
|
|
608
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
604
609
|
const settlr = (0, import_react.useMemo)(() => {
|
|
605
610
|
return new Settlr({
|
|
606
611
|
...config,
|
|
607
612
|
rpcEndpoint: config.rpcEndpoint ?? "https://api.devnet.solana.com"
|
|
608
613
|
});
|
|
609
614
|
}, [config]);
|
|
615
|
+
(0, import_react.useEffect)(() => {
|
|
616
|
+
let cancelled = false;
|
|
617
|
+
settlr.validateApiKey().then(() => {
|
|
618
|
+
if (!cancelled) {
|
|
619
|
+
setReady(true);
|
|
620
|
+
setError(null);
|
|
621
|
+
}
|
|
622
|
+
}).catch((err) => {
|
|
623
|
+
if (!cancelled) {
|
|
624
|
+
console.error("[Settlr] API key validation failed:", err);
|
|
625
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
626
|
+
if (config.apiKey?.startsWith("sk_test_")) {
|
|
627
|
+
setReady(true);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
return () => {
|
|
632
|
+
cancelled = true;
|
|
633
|
+
};
|
|
634
|
+
}, [settlr, config.apiKey]);
|
|
610
635
|
const value = (0, import_react.useMemo)(
|
|
611
636
|
() => ({
|
|
612
637
|
settlr,
|
|
613
638
|
authenticated,
|
|
639
|
+
ready,
|
|
640
|
+
error,
|
|
614
641
|
createPayment: (options) => {
|
|
615
642
|
return settlr.createPayment(options);
|
|
616
643
|
},
|
|
617
644
|
getCheckoutUrl: (options) => {
|
|
645
|
+
if (!ready) {
|
|
646
|
+
console.warn("[Settlr] SDK not ready yet. Ensure API key is valid.");
|
|
647
|
+
}
|
|
618
648
|
return settlr.getCheckoutUrl(options);
|
|
619
649
|
},
|
|
620
650
|
getBalance: () => {
|
|
621
651
|
return settlr.getMerchantBalance();
|
|
622
652
|
}
|
|
623
653
|
}),
|
|
624
|
-
[settlr, authenticated]
|
|
654
|
+
[settlr, authenticated, ready, error]
|
|
625
655
|
);
|
|
626
656
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SettlrContext.Provider, { value, children });
|
|
627
657
|
}
|
|
@@ -701,11 +731,18 @@ function BuyButton({
|
|
|
701
731
|
variant = "primary",
|
|
702
732
|
size = "md"
|
|
703
733
|
}) {
|
|
704
|
-
const { getCheckoutUrl, createPayment } = useSettlr();
|
|
734
|
+
const { getCheckoutUrl, createPayment, ready, error: sdkError } = useSettlr();
|
|
705
735
|
const [loading, setLoading] = (0, import_react2.useState)(false);
|
|
706
736
|
const [status, setStatus] = (0, import_react2.useState)("idle");
|
|
707
737
|
const handleClick = (0, import_react2.useCallback)(async () => {
|
|
708
738
|
if (disabled || loading) return;
|
|
739
|
+
if (!ready) {
|
|
740
|
+
const notReadyError = new Error(
|
|
741
|
+
sdkError?.message || "Settlr SDK not ready. Please check your API key configuration."
|
|
742
|
+
);
|
|
743
|
+
onError?.(notReadyError);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
709
746
|
setLoading(true);
|
|
710
747
|
setStatus("processing");
|
|
711
748
|
onProcessing?.();
|
|
@@ -729,6 +766,8 @@ function BuyButton({
|
|
|
729
766
|
orderId,
|
|
730
767
|
disabled,
|
|
731
768
|
loading,
|
|
769
|
+
ready,
|
|
770
|
+
sdkError,
|
|
732
771
|
successUrl,
|
|
733
772
|
cancelUrl,
|
|
734
773
|
getCheckoutUrl,
|
package/dist/index.mjs
CHANGED
|
@@ -139,6 +139,8 @@ var Settlr = class {
|
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* Validate API key with Settlr backend
|
|
142
|
+
* This is called automatically by SettlrProvider, but can also be called manually.
|
|
143
|
+
* Fetches merchant wallet address if not provided in config.
|
|
142
144
|
*/
|
|
143
145
|
async validateApiKey() {
|
|
144
146
|
if (this.validated) return;
|
|
@@ -166,6 +168,7 @@ var Settlr = class {
|
|
|
166
168
|
this.tier = data.tier;
|
|
167
169
|
if (data.merchantWallet && !this.merchantWallet) {
|
|
168
170
|
this.merchantWallet = new PublicKey2(data.merchantWallet);
|
|
171
|
+
this.merchantWalletFromValidation = data.merchantWallet;
|
|
169
172
|
this.config.merchant.walletAddress = data.merchantWallet;
|
|
170
173
|
}
|
|
171
174
|
if (data.merchantName && !this.config.merchant.name) {
|
|
@@ -529,7 +532,13 @@ var Settlr = class {
|
|
|
529
532
|
};
|
|
530
533
|
|
|
531
534
|
// src/react.tsx
|
|
532
|
-
import {
|
|
535
|
+
import {
|
|
536
|
+
createContext,
|
|
537
|
+
useContext,
|
|
538
|
+
useMemo,
|
|
539
|
+
useEffect,
|
|
540
|
+
useState
|
|
541
|
+
} from "react";
|
|
533
542
|
import { jsx } from "react/jsx-runtime";
|
|
534
543
|
var SettlrContext = createContext(null);
|
|
535
544
|
function SettlrProvider({
|
|
@@ -537,27 +546,54 @@ function SettlrProvider({
|
|
|
537
546
|
config,
|
|
538
547
|
authenticated = false
|
|
539
548
|
}) {
|
|
549
|
+
const [ready, setReady] = useState(false);
|
|
550
|
+
const [error, setError] = useState(null);
|
|
540
551
|
const settlr = useMemo(() => {
|
|
541
552
|
return new Settlr({
|
|
542
553
|
...config,
|
|
543
554
|
rpcEndpoint: config.rpcEndpoint ?? "https://api.devnet.solana.com"
|
|
544
555
|
});
|
|
545
556
|
}, [config]);
|
|
557
|
+
useEffect(() => {
|
|
558
|
+
let cancelled = false;
|
|
559
|
+
settlr.validateApiKey().then(() => {
|
|
560
|
+
if (!cancelled) {
|
|
561
|
+
setReady(true);
|
|
562
|
+
setError(null);
|
|
563
|
+
}
|
|
564
|
+
}).catch((err) => {
|
|
565
|
+
if (!cancelled) {
|
|
566
|
+
console.error("[Settlr] API key validation failed:", err);
|
|
567
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
568
|
+
if (config.apiKey?.startsWith("sk_test_")) {
|
|
569
|
+
setReady(true);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
return () => {
|
|
574
|
+
cancelled = true;
|
|
575
|
+
};
|
|
576
|
+
}, [settlr, config.apiKey]);
|
|
546
577
|
const value = useMemo(
|
|
547
578
|
() => ({
|
|
548
579
|
settlr,
|
|
549
580
|
authenticated,
|
|
581
|
+
ready,
|
|
582
|
+
error,
|
|
550
583
|
createPayment: (options) => {
|
|
551
584
|
return settlr.createPayment(options);
|
|
552
585
|
},
|
|
553
586
|
getCheckoutUrl: (options) => {
|
|
587
|
+
if (!ready) {
|
|
588
|
+
console.warn("[Settlr] SDK not ready yet. Ensure API key is valid.");
|
|
589
|
+
}
|
|
554
590
|
return settlr.getCheckoutUrl(options);
|
|
555
591
|
},
|
|
556
592
|
getBalance: () => {
|
|
557
593
|
return settlr.getMerchantBalance();
|
|
558
594
|
}
|
|
559
595
|
}),
|
|
560
|
-
[settlr, authenticated]
|
|
596
|
+
[settlr, authenticated, ready, error]
|
|
561
597
|
);
|
|
562
598
|
return /* @__PURE__ */ jsx(SettlrContext.Provider, { value, children });
|
|
563
599
|
}
|
|
@@ -571,9 +607,9 @@ function useSettlr() {
|
|
|
571
607
|
|
|
572
608
|
// src/components.tsx
|
|
573
609
|
import {
|
|
574
|
-
useState,
|
|
610
|
+
useState as useState2,
|
|
575
611
|
useCallback,
|
|
576
|
-
useEffect
|
|
612
|
+
useEffect as useEffect2
|
|
577
613
|
} from "react";
|
|
578
614
|
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
579
615
|
var defaultStyles = {
|
|
@@ -641,11 +677,18 @@ function BuyButton({
|
|
|
641
677
|
variant = "primary",
|
|
642
678
|
size = "md"
|
|
643
679
|
}) {
|
|
644
|
-
const { getCheckoutUrl, createPayment } = useSettlr();
|
|
645
|
-
const [loading, setLoading] =
|
|
646
|
-
const [status, setStatus] =
|
|
680
|
+
const { getCheckoutUrl, createPayment, ready, error: sdkError } = useSettlr();
|
|
681
|
+
const [loading, setLoading] = useState2(false);
|
|
682
|
+
const [status, setStatus] = useState2("idle");
|
|
647
683
|
const handleClick = useCallback(async () => {
|
|
648
684
|
if (disabled || loading) return;
|
|
685
|
+
if (!ready) {
|
|
686
|
+
const notReadyError = new Error(
|
|
687
|
+
sdkError?.message || "Settlr SDK not ready. Please check your API key configuration."
|
|
688
|
+
);
|
|
689
|
+
onError?.(notReadyError);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
649
692
|
setLoading(true);
|
|
650
693
|
setStatus("processing");
|
|
651
694
|
onProcessing?.();
|
|
@@ -669,6 +712,8 @@ function BuyButton({
|
|
|
669
712
|
orderId,
|
|
670
713
|
disabled,
|
|
671
714
|
loading,
|
|
715
|
+
ready,
|
|
716
|
+
sdkError,
|
|
672
717
|
successUrl,
|
|
673
718
|
cancelUrl,
|
|
674
719
|
getCheckoutUrl,
|
|
@@ -820,7 +865,7 @@ function CheckoutWidget({
|
|
|
820
865
|
showBranding = true
|
|
821
866
|
}) {
|
|
822
867
|
const { getCheckoutUrl } = useSettlr();
|
|
823
|
-
const [status, setStatus] =
|
|
868
|
+
const [status, setStatus] = useState2("idle");
|
|
824
869
|
const containerStyle = {
|
|
825
870
|
...widgetStyles.container,
|
|
826
871
|
...theme === "dark" ? widgetStyles.containerDark : widgetStyles.containerLight,
|
|
@@ -1003,7 +1048,7 @@ function PaymentModal({
|
|
|
1003
1048
|
onError,
|
|
1004
1049
|
checkoutUrl = "https://settlr.dev/checkout"
|
|
1005
1050
|
}) {
|
|
1006
|
-
const [loading, setLoading] =
|
|
1051
|
+
const [loading, setLoading] = useState2(true);
|
|
1007
1052
|
const params = new URLSearchParams({
|
|
1008
1053
|
amount: amount.toString(),
|
|
1009
1054
|
merchant: merchantName,
|
|
@@ -1013,7 +1058,7 @@ function PaymentModal({
|
|
|
1013
1058
|
if (memo) params.set("memo", memo);
|
|
1014
1059
|
if (orderId) params.set("orderId", orderId);
|
|
1015
1060
|
const iframeSrc = `${checkoutUrl}?${params.toString()}`;
|
|
1016
|
-
|
|
1061
|
+
useEffect2(() => {
|
|
1017
1062
|
const handleMessage = (event) => {
|
|
1018
1063
|
if (!event.origin.includes("settlr.dev") && !event.origin.includes("localhost")) {
|
|
1019
1064
|
return;
|
|
@@ -1037,7 +1082,7 @@ function PaymentModal({
|
|
|
1037
1082
|
window.addEventListener("message", handleMessage);
|
|
1038
1083
|
return () => window.removeEventListener("message", handleMessage);
|
|
1039
1084
|
}, [amount, onSuccess, onError, onClose]);
|
|
1040
|
-
|
|
1085
|
+
useEffect2(() => {
|
|
1041
1086
|
const handleEscape = (e) => {
|
|
1042
1087
|
if (e.key === "Escape") onClose?.();
|
|
1043
1088
|
};
|
|
@@ -1074,7 +1119,7 @@ function PaymentModal({
|
|
|
1074
1119
|
] }) });
|
|
1075
1120
|
}
|
|
1076
1121
|
function usePaymentModal(config) {
|
|
1077
|
-
const [modalState, setModalState] =
|
|
1122
|
+
const [modalState, setModalState] = useState2({
|
|
1078
1123
|
isOpen: false,
|
|
1079
1124
|
amount: 0
|
|
1080
1125
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlr/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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",
|