@strimz/sdk-react 0.2.8 → 0.3.1
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 +58 -49
- package/dist/index.cjs +91 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +91 -38
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/checkout-error.ts +12 -0
- package/src/checkout-message.ts +30 -0
- package/src/components/StrimzCheckoutEmbed.tsx +25 -19
- package/src/hooks/useStrimzCheckout.ts +36 -22
- package/src/hooks/useStrimzSession.ts +5 -3
- package/src/index.ts +1 -0
|
@@ -36,6 +36,7 @@ export function useStrimzSession(
|
|
|
36
36
|
const [loading, setLoading] = React.useState<boolean>(false)
|
|
37
37
|
const [error, setError] = React.useState<Error | null>(null)
|
|
38
38
|
const cancelledRef = React.useRef(false)
|
|
39
|
+
const sessionRef = React.useRef<PaymentSession | null>(null)
|
|
39
40
|
|
|
40
41
|
const fetchOnce = React.useCallback(async () => {
|
|
41
42
|
if (!sessionId) return
|
|
@@ -45,6 +46,7 @@ export function useStrimzSession(
|
|
|
45
46
|
// The publishable-key client exposes them via `client.checkout.session`.
|
|
46
47
|
const next = await client.checkout.session(sessionId)
|
|
47
48
|
if (!cancelledRef.current) {
|
|
49
|
+
sessionRef.current = next
|
|
48
50
|
setSession(next)
|
|
49
51
|
setError(null)
|
|
50
52
|
}
|
|
@@ -57,12 +59,14 @@ export function useStrimzSession(
|
|
|
57
59
|
|
|
58
60
|
React.useEffect(() => {
|
|
59
61
|
cancelledRef.current = false
|
|
62
|
+
sessionRef.current = null
|
|
60
63
|
if (!sessionId) return
|
|
61
64
|
|
|
62
65
|
void fetchOnce()
|
|
63
66
|
const interval = options.pollIntervalMs ?? 3_000
|
|
64
67
|
const timer = setInterval(() => {
|
|
65
|
-
|
|
68
|
+
const latest = sessionRef.current
|
|
69
|
+
if (latest && TERMINAL_STATES.includes(latest.status)) return
|
|
66
70
|
void fetchOnce()
|
|
67
71
|
}, interval)
|
|
68
72
|
|
|
@@ -70,8 +74,6 @@ export function useStrimzSession(
|
|
|
70
74
|
cancelledRef.current = true
|
|
71
75
|
clearInterval(timer)
|
|
72
76
|
}
|
|
73
|
-
// session is intentionally not in deps. The interval reads the latest via closure.
|
|
74
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
77
|
}, [sessionId, fetchOnce, options.pollIntervalMs])
|
|
76
78
|
|
|
77
79
|
return { session, loading, error, refresh: fetchOnce }
|
package/src/index.ts
CHANGED