@b3dotfun/sdk 0.1.66-alpha.1 → 0.1.66-alpha.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.
Files changed (124) hide show
  1. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.d.ts +50 -0
  2. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.js +30 -0
  3. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +47 -0
  4. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +45 -0
  5. package/dist/cjs/anyspend/react/components/checkout/CartItemRow.d.ts +8 -0
  6. package/dist/cjs/anyspend/react/components/checkout/CartItemRow.js +9 -0
  7. package/dist/cjs/anyspend/react/components/checkout/CartSummary.d.ts +8 -0
  8. package/dist/cjs/anyspend/react/components/checkout/CartSummary.js +9 -0
  9. package/dist/cjs/anyspend/react/components/checkout/CheckoutCartPanel.d.ts +12 -0
  10. package/dist/cjs/anyspend/react/components/checkout/CheckoutCartPanel.js +19 -0
  11. package/dist/cjs/anyspend/react/components/checkout/CheckoutLayout.d.ts +10 -0
  12. package/dist/cjs/anyspend/react/components/checkout/CheckoutLayout.js +25 -0
  13. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +20 -0
  14. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +45 -0
  15. package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.d.ts +10 -0
  16. package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.js +11 -0
  17. package/dist/cjs/anyspend/react/components/checkout/CoinbaseCheckoutPanel.d.ts +16 -0
  18. package/dist/cjs/anyspend/react/components/checkout/CoinbaseCheckoutPanel.js +27 -0
  19. package/dist/cjs/anyspend/react/components/checkout/CryptoCheckoutPanel.d.ts +33 -0
  20. package/dist/cjs/anyspend/react/components/checkout/CryptoCheckoutPanel.js +317 -0
  21. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +16 -0
  22. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +215 -0
  23. package/dist/cjs/anyspend/react/components/checkout/PoweredByBranding.d.ts +8 -0
  24. package/dist/cjs/anyspend/react/components/checkout/PoweredByBranding.js +9 -0
  25. package/dist/cjs/anyspend/react/components/checkout/QRCheckoutPanel.d.ts +17 -0
  26. package/dist/cjs/anyspend/react/components/checkout/QRCheckoutPanel.js +148 -0
  27. package/dist/cjs/anyspend/react/components/index.d.ts +5 -1
  28. package/dist/cjs/anyspend/react/components/index.js +6 -1
  29. package/dist/cjs/anyspend/react/components/types/classes.d.ts +32 -0
  30. package/dist/cjs/global-account/react/components/B3DynamicModal.js +5 -1
  31. package/dist/cjs/global-account/react/components/WalletImage/WalletImage.d.ts +1 -1
  32. package/dist/cjs/global-account/react/components/ui/command.d.ts +7 -7
  33. package/dist/cjs/global-account/react/components/ui/dialog.js +1 -1
  34. package/dist/cjs/global-account/react/hooks/useAuth.d.ts +1 -1
  35. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
  36. package/dist/cjs/global-account/react/hooks/useUser.d.ts +1 -1
  37. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
  38. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +53 -1
  39. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +2 -2
  40. package/dist/cjs/shared/constants/chains/supported.d.ts +3 -3
  41. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.d.ts +50 -0
  42. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.js +27 -0
  43. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +47 -0
  44. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +42 -0
  45. package/dist/esm/anyspend/react/components/checkout/CartItemRow.d.ts +8 -0
  46. package/dist/esm/anyspend/react/components/checkout/CartItemRow.js +6 -0
  47. package/dist/esm/anyspend/react/components/checkout/CartSummary.d.ts +8 -0
  48. package/dist/esm/anyspend/react/components/checkout/CartSummary.js +6 -0
  49. package/dist/esm/anyspend/react/components/checkout/CheckoutCartPanel.d.ts +12 -0
  50. package/dist/esm/anyspend/react/components/checkout/CheckoutCartPanel.js +16 -0
  51. package/dist/esm/anyspend/react/components/checkout/CheckoutLayout.d.ts +10 -0
  52. package/dist/esm/anyspend/react/components/checkout/CheckoutLayout.js +22 -0
  53. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +20 -0
  54. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +42 -0
  55. package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.d.ts +10 -0
  56. package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.js +8 -0
  57. package/dist/esm/anyspend/react/components/checkout/CoinbaseCheckoutPanel.d.ts +16 -0
  58. package/dist/esm/anyspend/react/components/checkout/CoinbaseCheckoutPanel.js +24 -0
  59. package/dist/esm/anyspend/react/components/checkout/CryptoCheckoutPanel.d.ts +33 -0
  60. package/dist/esm/anyspend/react/components/checkout/CryptoCheckoutPanel.js +313 -0
  61. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +16 -0
  62. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +212 -0
  63. package/dist/esm/anyspend/react/components/checkout/PoweredByBranding.d.ts +8 -0
  64. package/dist/esm/anyspend/react/components/checkout/PoweredByBranding.js +6 -0
  65. package/dist/esm/anyspend/react/components/checkout/QRCheckoutPanel.d.ts +17 -0
  66. package/dist/esm/anyspend/react/components/checkout/QRCheckoutPanel.js +145 -0
  67. package/dist/esm/anyspend/react/components/index.d.ts +5 -1
  68. package/dist/esm/anyspend/react/components/index.js +3 -0
  69. package/dist/esm/anyspend/react/components/types/classes.d.ts +32 -0
  70. package/dist/esm/global-account/react/components/B3DynamicModal.js +5 -1
  71. package/dist/esm/global-account/react/components/WalletImage/WalletImage.d.ts +1 -1
  72. package/dist/esm/global-account/react/components/ui/command.d.ts +7 -7
  73. package/dist/esm/global-account/react/components/ui/dialog.js +1 -1
  74. package/dist/esm/global-account/react/hooks/useAuth.d.ts +1 -1
  75. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
  76. package/dist/esm/global-account/react/hooks/useUser.d.ts +1 -1
  77. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
  78. package/dist/esm/global-account/react/stores/useModalStore.d.ts +53 -1
  79. package/dist/esm/shared/constants/chains/b3Chain.d.ts +2 -2
  80. package/dist/esm/shared/constants/chains/supported.d.ts +3 -3
  81. package/dist/styles/index.css +1 -1
  82. package/dist/types/anyspend/react/components/checkout/AnySpendCheckout.d.ts +50 -0
  83. package/dist/types/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +47 -0
  84. package/dist/types/anyspend/react/components/checkout/CartItemRow.d.ts +8 -0
  85. package/dist/types/anyspend/react/components/checkout/CartSummary.d.ts +8 -0
  86. package/dist/types/anyspend/react/components/checkout/CheckoutCartPanel.d.ts +12 -0
  87. package/dist/types/anyspend/react/components/checkout/CheckoutLayout.d.ts +10 -0
  88. package/dist/types/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +20 -0
  89. package/dist/types/anyspend/react/components/checkout/CheckoutSuccess.d.ts +10 -0
  90. package/dist/types/anyspend/react/components/checkout/CoinbaseCheckoutPanel.d.ts +16 -0
  91. package/dist/types/anyspend/react/components/checkout/CryptoCheckoutPanel.d.ts +33 -0
  92. package/dist/types/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +16 -0
  93. package/dist/types/anyspend/react/components/checkout/PoweredByBranding.d.ts +8 -0
  94. package/dist/types/anyspend/react/components/checkout/QRCheckoutPanel.d.ts +17 -0
  95. package/dist/types/anyspend/react/components/index.d.ts +5 -1
  96. package/dist/types/anyspend/react/components/types/classes.d.ts +32 -0
  97. package/dist/types/global-account/react/components/WalletImage/WalletImage.d.ts +1 -1
  98. package/dist/types/global-account/react/components/ui/command.d.ts +7 -7
  99. package/dist/types/global-account/react/hooks/useAuth.d.ts +1 -1
  100. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
  101. package/dist/types/global-account/react/hooks/useUser.d.ts +1 -1
  102. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
  103. package/dist/types/global-account/react/stores/useModalStore.d.ts +53 -1
  104. package/dist/types/shared/constants/chains/b3Chain.d.ts +2 -2
  105. package/dist/types/shared/constants/chains/supported.d.ts +3 -3
  106. package/package.json +1 -1
  107. package/src/anyspend/react/components/checkout/AnySpendCheckout.tsx +127 -0
  108. package/src/anyspend/react/components/checkout/AnySpendCheckoutTrigger.tsx +166 -0
  109. package/src/anyspend/react/components/checkout/CartItemRow.tsx +43 -0
  110. package/src/anyspend/react/components/checkout/CartSummary.tsx +23 -0
  111. package/src/anyspend/react/components/checkout/CheckoutCartPanel.tsx +60 -0
  112. package/src/anyspend/react/components/checkout/CheckoutLayout.tsx +72 -0
  113. package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +320 -0
  114. package/src/anyspend/react/components/checkout/CheckoutSuccess.tsx +91 -0
  115. package/src/anyspend/react/components/checkout/CoinbaseCheckoutPanel.tsx +90 -0
  116. package/src/anyspend/react/components/checkout/CryptoCheckoutPanel.tsx +643 -0
  117. package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +519 -0
  118. package/src/anyspend/react/components/checkout/PoweredByBranding.tsx +32 -0
  119. package/src/anyspend/react/components/checkout/QRCheckoutPanel.tsx +320 -0
  120. package/src/anyspend/react/components/index.ts +7 -0
  121. package/src/anyspend/react/components/types/classes.ts +48 -0
  122. package/src/global-account/react/components/B3DynamicModal.tsx +5 -0
  123. package/src/global-account/react/components/ui/dialog.tsx +1 -1
  124. package/src/global-account/react/stores/useModalStore.ts +52 -1
@@ -0,0 +1,519 @@
1
+ "use client";
2
+
3
+ import { useAnyspendCreateOnrampOrder, useGeoOnrampOptions, useStripeClientSecret } from "@b3dotfun/sdk/anyspend/react";
4
+ import { cn } from "@b3dotfun/sdk/shared/utils/cn";
5
+ import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
6
+ import { getStripePromise } from "@b3dotfun/sdk/shared/utils/payment.utils";
7
+ import { TextShimmer, useB3Config, useTokenData } from "@b3dotfun/sdk/global-account/react";
8
+ import { AddressElement, Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
9
+ import type { PaymentIntentResult, StripePaymentElementOptions } from "@stripe/stripe-js";
10
+ import { Loader2, Lock } from "lucide-react";
11
+ import { AnimatePresence, motion } from "motion/react";
12
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
13
+ import type { AnySpendCheckoutClasses } from "./AnySpendCheckout";
14
+
15
+ interface FiatCheckoutPanelProps {
16
+ recipientAddress: string;
17
+ destinationTokenAddress: string;
18
+ destinationTokenChainId: number;
19
+ totalAmount: string;
20
+ themeColor?: string;
21
+ onSuccess?: (result: { txHash?: string; orderId?: string }) => void;
22
+ onError?: (error: Error) => void;
23
+ classes?: AnySpendCheckoutClasses;
24
+ }
25
+
26
+ export function FiatCheckoutPanel({
27
+ recipientAddress,
28
+ destinationTokenAddress,
29
+ destinationTokenChainId,
30
+ totalAmount,
31
+ themeColor,
32
+ onSuccess,
33
+ onError,
34
+ classes,
35
+ }: FiatCheckoutPanelProps) {
36
+ const { data: tokenData } = useTokenData(destinationTokenChainId, destinationTokenAddress);
37
+ const { theme, stripePublishableKey } = useB3Config();
38
+
39
+ const formattedAmount = useMemo(() => {
40
+ const decimals = tokenData?.decimals || 18;
41
+ return formatTokenAmount(BigInt(totalAmount), decimals);
42
+ }, [totalAmount, tokenData]);
43
+
44
+ const {
45
+ geoData,
46
+ stripeOnrampSupport,
47
+ stripeWeb2Support,
48
+ isLoading: isLoadingGeo,
49
+ } = useGeoOnrampOptions(formattedAmount);
50
+
51
+ // Order state
52
+ const [orderId, setOrderId] = useState<string | null>(null);
53
+ const [stripePaymentIntentId, setStripePaymentIntentId] = useState<string | null>(null);
54
+ const [orderError, setOrderError] = useState<string | null>(null);
55
+ const orderCreatedRef = useRef(false);
56
+
57
+ const { createOrder, isCreatingOrder } = useAnyspendCreateOnrampOrder({
58
+ onSuccess: (data: any) => {
59
+ const id = data?.data?.id;
60
+ const intentId = data?.data?.stripePaymentIntentId;
61
+ if (id && intentId) {
62
+ setOrderId(id);
63
+ setStripePaymentIntentId(intentId);
64
+ } else {
65
+ setOrderError("Failed to initialize payment. Please try again.");
66
+ }
67
+ },
68
+ onError: (error: Error) => {
69
+ setOrderError(error.message || "Failed to create payment order.");
70
+ onError?.(error);
71
+ },
72
+ });
73
+
74
+ // Auto-create onramp order when Stripe Web2 is supported and all data is ready
75
+ useEffect(() => {
76
+ if (
77
+ !isLoadingGeo &&
78
+ stripeWeb2Support?.isSupport &&
79
+ !orderCreatedRef.current &&
80
+ !orderId &&
81
+ !isCreatingOrder &&
82
+ !orderError &&
83
+ tokenData &&
84
+ recipientAddress
85
+ ) {
86
+ orderCreatedRef.current = true;
87
+
88
+ const dstToken = {
89
+ address: destinationTokenAddress,
90
+ chainId: destinationTokenChainId,
91
+ decimals: tokenData.decimals || 18,
92
+ symbol: tokenData.symbol || "",
93
+ name: tokenData.name || "",
94
+ metadata: {
95
+ logoURI: tokenData.logoURI || "",
96
+ },
97
+ };
98
+
99
+ createOrder({
100
+ recipientAddress,
101
+ orderType: "swap",
102
+ dstChain: destinationTokenChainId,
103
+ dstToken,
104
+ srcFiatAmount: formattedAmount,
105
+ onramp: {
106
+ vendor: "stripe-web2",
107
+ paymentMethod: "",
108
+ country: geoData?.country || "US",
109
+ redirectUrl: window.location.origin,
110
+ },
111
+ expectedDstAmount: totalAmount,
112
+ });
113
+ }
114
+ }, [
115
+ isLoadingGeo,
116
+ stripeWeb2Support,
117
+ orderId,
118
+ isCreatingOrder,
119
+ orderError,
120
+ tokenData,
121
+ recipientAddress,
122
+ destinationTokenAddress,
123
+ destinationTokenChainId,
124
+ formattedAmount,
125
+ totalAmount,
126
+ geoData,
127
+ createOrder,
128
+ ]);
129
+
130
+ // Loading geo/stripe support check
131
+ if (isLoadingGeo) {
132
+ return (
133
+ <motion.div
134
+ initial={{ opacity: 0 }}
135
+ animate={{ opacity: 1 }}
136
+ transition={{ duration: 0.2, ease: "easeOut" }}
137
+ className={cn("anyspend-fiat-loading flex flex-col items-center gap-3 py-6", classes?.fiatPanel)}
138
+ >
139
+ <Loader2 className="h-5 w-5 animate-spin text-gray-400" />
140
+ <TextShimmer duration={1.5} className="text-sm">
141
+ Loading payment form...
142
+ </TextShimmer>
143
+ </motion.div>
144
+ );
145
+ }
146
+
147
+ const hasStripeWeb2 = stripeWeb2Support && stripeWeb2Support.isSupport;
148
+ const hasStripeRedirect = !!stripeOnrampSupport;
149
+
150
+ // Not available in region
151
+ if (!hasStripeWeb2 && !hasStripeRedirect) {
152
+ return (
153
+ <motion.div
154
+ initial={{ opacity: 0, y: 8 }}
155
+ animate={{ opacity: 1, y: 0 }}
156
+ transition={{ duration: 0.25, ease: "easeOut" }}
157
+ className={cn("anyspend-fiat-unavailable py-4 text-center", classes?.fiatPanel)}
158
+ >
159
+ <p className="text-sm text-gray-500 dark:text-gray-400">
160
+ Card payments are not available in your region for this amount.
161
+ </p>
162
+ </motion.div>
163
+ );
164
+ }
165
+
166
+ // Order creation error - show with retry
167
+ if (orderError) {
168
+ return (
169
+ <motion.div
170
+ initial={{ opacity: 0, y: 8 }}
171
+ animate={{ opacity: 1, y: 0 }}
172
+ transition={{ duration: 0.25, ease: "easeOut" }}
173
+ className={cn("anyspend-fiat-error flex flex-col items-center gap-3 py-4", classes?.fiatPanel)}
174
+ >
175
+ <p className="text-sm text-red-500">{orderError}</p>
176
+ <button
177
+ onClick={() => {
178
+ setOrderError(null);
179
+ orderCreatedRef.current = false;
180
+ }}
181
+ className="anyspend-fiat-retry text-sm font-medium text-blue-600 hover:text-blue-700 dark:text-blue-400"
182
+ >
183
+ Try again
184
+ </button>
185
+ </motion.div>
186
+ );
187
+ }
188
+
189
+ // Creating order / waiting for PaymentIntent
190
+ if (hasStripeWeb2 && (isCreatingOrder || !stripePaymentIntentId)) {
191
+ return (
192
+ <motion.div
193
+ initial={{ opacity: 0 }}
194
+ animate={{ opacity: 1 }}
195
+ transition={{ duration: 0.2, ease: "easeOut" }}
196
+ className={cn("anyspend-fiat-initializing flex flex-col items-center gap-3 py-6", classes?.fiatPanel)}
197
+ >
198
+ <Loader2 className="h-5 w-5 animate-spin text-gray-400" />
199
+ <TextShimmer duration={1.5} className="text-sm">
200
+ Initializing secure payment...
201
+ </TextShimmer>
202
+ </motion.div>
203
+ );
204
+ }
205
+
206
+ // Stripe Web2 embedded form
207
+ if (hasStripeWeb2 && stripePaymentIntentId && orderId) {
208
+ return (
209
+ <motion.div
210
+ initial={{ opacity: 0, y: 10 }}
211
+ animate={{ opacity: 1, y: 0 }}
212
+ transition={{ duration: 0.3, ease: "easeOut" }}
213
+ className={cn("anyspend-fiat-stripe", classes?.fiatPanel)}
214
+ >
215
+ <StripeCheckout
216
+ stripePaymentIntentId={stripePaymentIntentId}
217
+ stripePublishableKey={stripePublishableKey}
218
+ theme={theme}
219
+ themeColor={themeColor}
220
+ orderId={orderId}
221
+ onSuccess={onSuccess}
222
+ onError={onError}
223
+ classes={classes}
224
+ />
225
+ </motion.div>
226
+ );
227
+ }
228
+
229
+ // Fallback: Stripe redirect flow (only if web2 not available but redirect is)
230
+ return (
231
+ <div className={cn("anyspend-fiat-redirect flex flex-col gap-3 py-2", classes?.fiatPanel)}>
232
+ <p className="text-sm text-gray-600 dark:text-gray-400">
233
+ You'll be redirected to Stripe to complete your payment securely.
234
+ </p>
235
+ <button
236
+ className={cn(
237
+ "anyspend-fiat-redirect-btn flex w-full items-center justify-center gap-2 rounded-xl px-4 py-3.5 text-sm font-semibold text-white transition-all active:scale-[0.98]",
238
+ "bg-blue-600 hover:bg-blue-700",
239
+ )}
240
+ style={themeColor ? { backgroundColor: themeColor } : undefined}
241
+ >
242
+ <Lock className="h-3.5 w-3.5" />
243
+ Pay with Card
244
+ </button>
245
+ <p className="anyspend-fiat-secured flex items-center justify-center gap-1 text-xs text-gray-400">
246
+ <Lock className="h-3 w-3" />
247
+ Secured by Stripe
248
+ </p>
249
+ </div>
250
+ );
251
+ }
252
+
253
+ // -------------------------------------------------------------------
254
+ // Stripe Elements wrapper - fetches client secret, renders Elements
255
+ // -------------------------------------------------------------------
256
+
257
+ interface StripeCheckoutProps {
258
+ stripePaymentIntentId: string;
259
+ stripePublishableKey?: string | null;
260
+ theme?: string;
261
+ themeColor?: string;
262
+ orderId: string;
263
+ onSuccess?: (result: { txHash?: string; orderId?: string }) => void;
264
+ onError?: (error: Error) => void;
265
+ classes?: AnySpendCheckoutClasses;
266
+ }
267
+
268
+ function StripeCheckout({
269
+ stripePaymentIntentId,
270
+ stripePublishableKey,
271
+ theme,
272
+ themeColor,
273
+ orderId,
274
+ onSuccess,
275
+ onError,
276
+ classes,
277
+ }: StripeCheckoutProps) {
278
+ const { clientSecret, isLoadingStripeClientSecret, stripeClientSecretError } =
279
+ useStripeClientSecret(stripePaymentIntentId);
280
+
281
+ if (isLoadingStripeClientSecret) {
282
+ return (
283
+ <motion.div
284
+ initial={{ opacity: 0 }}
285
+ animate={{ opacity: 1 }}
286
+ transition={{ duration: 0.2, ease: "easeOut" }}
287
+ className="anyspend-stripe-loading flex flex-col items-center gap-3 py-6"
288
+ >
289
+ <Loader2 className="h-5 w-5 animate-spin text-gray-400" />
290
+ <TextShimmer duration={1.5} className="text-sm">
291
+ Loading payment form...
292
+ </TextShimmer>
293
+ </motion.div>
294
+ );
295
+ }
296
+
297
+ if (stripeClientSecretError || !clientSecret) {
298
+ return (
299
+ <motion.div
300
+ initial={{ opacity: 0, y: 8 }}
301
+ animate={{ opacity: 1, y: 0 }}
302
+ transition={{ duration: 0.25, ease: "easeOut" }}
303
+ className="anyspend-stripe-error py-4 text-center"
304
+ >
305
+ <p className="text-sm text-red-500">
306
+ {stripeClientSecretError?.message || "Failed to load payment form. Please try again."}
307
+ </p>
308
+ </motion.div>
309
+ );
310
+ }
311
+
312
+ return (
313
+ <Elements
314
+ stripe={getStripePromise(stripePublishableKey)}
315
+ options={{
316
+ clientSecret,
317
+ appearance: {
318
+ theme: theme === "light" ? "stripe" : "night",
319
+ variables: {
320
+ borderRadius: "8px",
321
+ },
322
+ },
323
+ }}
324
+ >
325
+ <StripeCheckoutForm
326
+ themeColor={themeColor}
327
+ orderId={orderId}
328
+ onSuccess={onSuccess}
329
+ onError={onError}
330
+ classes={classes}
331
+ />
332
+ </Elements>
333
+ );
334
+ }
335
+
336
+ // -------------------------------------------------------------------
337
+ // Inner form component (inside Elements context)
338
+ // -------------------------------------------------------------------
339
+
340
+ interface StripeCheckoutFormProps {
341
+ themeColor?: string;
342
+ orderId: string;
343
+ onSuccess?: (result: { txHash?: string; orderId?: string }) => void;
344
+ onError?: (error: Error) => void;
345
+ classes?: AnySpendCheckoutClasses;
346
+ }
347
+
348
+ function StripeCheckoutForm({ themeColor, orderId, onSuccess, onError, classes }: StripeCheckoutFormProps) {
349
+ const stripe = useStripe();
350
+ const elements = useElements();
351
+
352
+ const [loading, setLoading] = useState(false);
353
+ const [message, setMessage] = useState<string | null>(null);
354
+ const [stripeReady, setStripeReady] = useState(false);
355
+ const [showAddressElement, setShowAddressElement] = useState(false);
356
+
357
+ useEffect(() => {
358
+ if (stripe && elements) {
359
+ setStripeReady(true);
360
+ }
361
+ }, [stripe, elements]);
362
+
363
+ const handlePaymentElementChange = useCallback((event: any) => {
364
+ setShowAddressElement(event.value?.type === "card");
365
+ }, []);
366
+
367
+ const handleSubmit = async (e: React.FormEvent) => {
368
+ e.preventDefault();
369
+
370
+ if (!stripe || !elements) {
371
+ setMessage("Payment system is not ready. Please wait.");
372
+ return;
373
+ }
374
+
375
+ setLoading(true);
376
+ setMessage(null);
377
+
378
+ try {
379
+ const result = (await stripe.confirmPayment({
380
+ elements,
381
+ redirect: "if_required",
382
+ })) as PaymentIntentResult;
383
+
384
+ if (result.error) {
385
+ setMessage(result.error.message || "Payment failed. Please try again.");
386
+ return;
387
+ }
388
+
389
+ // Payment succeeded
390
+ onSuccess?.({ orderId, txHash: undefined });
391
+ } catch (error: any) {
392
+ const errorMessage = error?.message || "Payment failed. Please try again.";
393
+ setMessage(errorMessage);
394
+ onError?.(error instanceof Error ? error : new Error(errorMessage));
395
+ } finally {
396
+ setLoading(false);
397
+ }
398
+ };
399
+
400
+ const stripeElementOptions: StripePaymentElementOptions = {
401
+ layout: "tabs" as const,
402
+ fields: {
403
+ billingDetails: "auto" as const,
404
+ },
405
+ wallets: {
406
+ applePay: "auto" as const,
407
+ googlePay: "auto" as const,
408
+ },
409
+ };
410
+
411
+ if (!stripeReady) {
412
+ return (
413
+ <motion.div
414
+ initial={{ opacity: 0 }}
415
+ animate={{ opacity: 1 }}
416
+ transition={{ duration: 0.2, ease: "easeOut" }}
417
+ className="anyspend-stripe-loading flex flex-col items-center gap-3 py-6"
418
+ >
419
+ <Loader2 className="h-5 w-5 animate-spin text-gray-400" />
420
+ <TextShimmer duration={1.5} className="text-sm">
421
+ Loading payment form...
422
+ </TextShimmer>
423
+ </motion.div>
424
+ );
425
+ }
426
+
427
+ return (
428
+ <motion.form
429
+ initial={{ opacity: 0, y: 10 }}
430
+ animate={{ opacity: 1, y: 0 }}
431
+ transition={{ duration: 0.3, ease: "easeOut" }}
432
+ onSubmit={handleSubmit}
433
+ className="anyspend-stripe-form flex flex-col gap-4"
434
+ >
435
+ <div className="anyspend-stripe-payment-element">
436
+ <PaymentElement onChange={handlePaymentElementChange} options={stripeElementOptions} />
437
+ </div>
438
+
439
+ <AnimatePresence initial={false}>
440
+ {showAddressElement && (
441
+ <motion.div
442
+ key="address-element"
443
+ initial={{ height: 0, opacity: 0 }}
444
+ animate={{ height: "auto", opacity: 1 }}
445
+ exit={{ height: 0, opacity: 0 }}
446
+ transition={{ duration: 0.25, ease: "easeOut" }}
447
+ style={{ overflow: "hidden" }}
448
+ className="anyspend-stripe-address-element"
449
+ >
450
+ <AddressElement
451
+ options={{
452
+ mode: "billing",
453
+ fields: {
454
+ phone: "always",
455
+ },
456
+ display: {
457
+ name: "split",
458
+ },
459
+ validation: {
460
+ phone: {
461
+ required: "always",
462
+ },
463
+ },
464
+ }}
465
+ />
466
+ </motion.div>
467
+ )}
468
+ </AnimatePresence>
469
+
470
+ {/* Error message */}
471
+ <AnimatePresence initial={false}>
472
+ {message && (
473
+ <motion.div
474
+ key="stripe-error"
475
+ initial={{ opacity: 0, height: 0 }}
476
+ animate={{ opacity: 1, height: "auto" }}
477
+ exit={{ opacity: 0, height: 0 }}
478
+ transition={{ duration: 0.2, ease: "easeOut" }}
479
+ style={{ overflow: "hidden" }}
480
+ className="anyspend-stripe-error rounded-lg border border-red-200 bg-red-50 px-3 py-2 dark:border-red-800 dark:bg-red-900/20"
481
+ >
482
+ <p className="text-sm text-red-600 dark:text-red-400">{message}</p>
483
+ </motion.div>
484
+ )}
485
+ </AnimatePresence>
486
+
487
+ {/* Submit button */}
488
+ <button
489
+ type="submit"
490
+ disabled={!stripe || !elements || loading}
491
+ className={cn(
492
+ "anyspend-stripe-submit flex w-full items-center justify-center gap-2 rounded-xl px-4 py-3.5 text-sm font-semibold text-white transition-all",
493
+ !stripe || !elements || loading
494
+ ? "cursor-not-allowed bg-gray-300 dark:bg-gray-600"
495
+ : "bg-blue-600 hover:bg-blue-700 active:scale-[0.98]",
496
+ classes?.payButton,
497
+ )}
498
+ style={themeColor && !loading ? { backgroundColor: themeColor } : undefined}
499
+ >
500
+ {loading ? (
501
+ <>
502
+ <Loader2 className="h-4 w-4 animate-spin" />
503
+ Processing...
504
+ </>
505
+ ) : (
506
+ <>
507
+ <Lock className="h-3.5 w-3.5" />
508
+ Complete Payment
509
+ </>
510
+ )}
511
+ </button>
512
+
513
+ <p className="anyspend-fiat-secured flex items-center justify-center gap-1 text-xs text-gray-400">
514
+ <Lock className="h-3 w-3" />
515
+ Secured by Stripe
516
+ </p>
517
+ </motion.form>
518
+ );
519
+ }
@@ -0,0 +1,32 @@
1
+ "use client";
2
+
3
+ import { cn } from "@b3dotfun/sdk/shared/utils/cn";
4
+ import type { AnySpendCheckoutClasses } from "./AnySpendCheckout";
5
+
6
+ interface PoweredByBrandingProps {
7
+ organizationName?: string;
8
+ organizationLogo?: string;
9
+ classes?: AnySpendCheckoutClasses;
10
+ }
11
+
12
+ export function PoweredByBranding({ organizationName, organizationLogo, classes }: PoweredByBrandingProps) {
13
+ return (
14
+ <div className={cn("flex items-center justify-between pt-4", classes?.poweredBy)}>
15
+ {organizationLogo || organizationName ? (
16
+ <div className="flex items-center gap-2">
17
+ {organizationLogo && (
18
+ <img src={organizationLogo} alt={organizationName || "Organization"} className="h-5 w-5 rounded-full" />
19
+ )}
20
+ {organizationName && (
21
+ <span className="text-xs font-medium text-gray-600 dark:text-gray-400">{organizationName}</span>
22
+ )}
23
+ </div>
24
+ ) : (
25
+ <div />
26
+ )}
27
+ <span className="text-xs text-gray-400 dark:text-gray-500">
28
+ powered by <span className="font-medium text-gray-500 dark:text-gray-400">anyspend</span>
29
+ </span>
30
+ </div>
31
+ );
32
+ }