import React, { useState } from "react"; import { stripeAPI } from "../services/api"; interface StripeConnectOnboardingProps { onComplete: () => void; onCancel: () => void; } const StripeConnectOnboarding: React.FC = ({ onComplete, onCancel, }) => { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [step, setStep] = useState<"start" | "creating" | "redirecting">( "start" ); const createStripeAccount = async () => { setLoading(true); setError(null); setStep("creating"); try { // First, create the Stripe Connected Account const accountResponse = await stripeAPI.createConnectedAccount(); setStep("redirecting"); // Generate onboarding link const refreshUrl = `${window.location.origin}/earnings?refresh=true`; const returnUrl = `${window.location.origin}/earnings?setup=complete`; const linkResponse = await stripeAPI.createAccountLink({ refreshUrl, returnUrl, }); const { url } = linkResponse.data; // Redirect to Stripe onboarding window.location.href = url; } catch (err: any) { setError( err.response?.data?.error || err.message || "Failed to set up earnings" ); setStep("start"); setLoading(false); } }; const handleStartSetup = () => { createStripeAccount(); }; return (
Set Up Earnings
{step === "start" && ( <>

Start Receiving Earnings

Set up your earnings account to automatically receive payments

Secure
Powered by Stripe, trusted by millions
Automatic
Earnings are processed automatically
Direct Deposit
Funds go directly to your bank
What to expect:
  • You'll be redirected to Stripe to verify your identity
  • Provide bank account details for deposits
  • The setup process takes about 5 minutes
  • Start earning immediately after setup
{error && (
{error}
)} )} {step === "creating" && (
Loading...
Creating your earnings account...

Please wait while we set up your account

)} {step === "redirecting" && (
Loading...
Redirecting to Stripe...

You'll be redirected to complete the setup process. This may take a moment.

)}
{step === "start" && ( <> )} {(step === "creating" || step === "redirecting") && (
Please don't close this window...
)}
); }; export default StripeConnectOnboarding;