From fdf8a99674978f11e5975ebcf7a6f6feb6a742c5 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Sat, 20 Jun 2026 11:55:01 -0700 Subject: [PATCH 1/2] fix(billing): allow changing Stripe Express country by creating new account Stripe locks the country on Express accounts after creation, so users who first onboarded with the wrong country (often defaulted to US) could never change it. We now store the locked country and create a new Express account when the user selects a different country. Backend: - Add stripe_account_country column to users and User struct. - Update SetUserStripeAccount to accept and persist country. - On onboard, create a new Stripe account if requested country differs from the locked country. - Return stripe_account_country from the status endpoint. Frontend: - Pre-select the locked country in billing/earnings pages. - Show the locked country and let users pick a different one to create a new account. Tests cover both country passthrough and country-change account creation. --- console-ui/src/app/billing/BillingContent.tsx | 56 +++++++---- .../providers/earnings/EarningsContent.tsx | 92 +++++++++++++++++-- console-ui/src/lib/api.ts | 1 + coordinator/api/stripe_payouts.go | 37 +++++--- coordinator/api/stripe_payouts_test.go | 74 +++++++++++++-- coordinator/billing/stripe_connect.go | 4 + coordinator/store/interface.go | 5 +- coordinator/store/memory.go | 7 +- coordinator/store/postgres.go | 28 ++++-- coordinator/store/postgres_test.go | 22 ++++- 10 files changed, 264 insertions(+), 62 deletions(-) diff --git a/console-ui/src/app/billing/BillingContent.tsx b/console-ui/src/app/billing/BillingContent.tsx index 1287983280..af7d82e0de 100644 --- a/console-ui/src/app/billing/BillingContent.tsx +++ b/console-ui/src/app/billing/BillingContent.tsx @@ -31,7 +31,6 @@ import { CreditCard, Building2, Zap, - AlertCircle, ArrowDownToLine, } from "lucide-react"; import { UsageChart } from "@/components/UsageChart"; @@ -91,6 +90,15 @@ export default function BillingContent() { const [withdrawLoading, setWithdrawLoading] = useState(false); const [selectedStripeCountry, setSelectedStripeCountry] = useState(""); + // Once a Stripe Express account exists, its country is locked. Pre-select + // that country so the user sees what will actually be used, and so a + // deliberate change triggers backend creation of a new account. + useEffect(() => { + if (stripeStatus?.stripe_account_country) { + setSelectedStripeCountry(stripeStatus.stripe_account_country); + } + }, [stripeStatus?.stripe_account_country]); + const loadData = useCallback(async () => { setLoading(true); try { @@ -669,24 +677,36 @@ function StripePayoutsCard({ ) : ( <> -

- - {restricted - ? "Stripe needs more information to enable payouts on your account." - : rejected - ? "Stripe has disabled payouts on this account. Contact support." - : "Finish linking your account on Stripe to enable withdrawals."} +

+ Your Stripe account is locked to{" "} + + {STRIPE_CONNECT_COUNTRIES.find((c) => c.code === status?.stripe_account_country)?.name || status?.stripe_account_country || "your selected country"} + + . If you need a different country, select it below and we will create a new account.

- {!rejected && ( - - )} + + + )} diff --git a/console-ui/src/app/providers/earnings/EarningsContent.tsx b/console-ui/src/app/providers/earnings/EarningsContent.tsx index df4b4f5d08..3054fec96d 100644 --- a/console-ui/src/app/providers/earnings/EarningsContent.tsx +++ b/console-ui/src/app/providers/earnings/EarningsContent.tsx @@ -21,7 +21,6 @@ import { LogIn, ArrowDownToLine, Check, - AlertCircle, Building2, CreditCard, Clock, @@ -102,6 +101,15 @@ export default function EarningsContent() { const [withdrawMethod, setWithdrawMethod] = useState<"standard" | "instant">("standard"); const [withdrawLoading, setWithdrawLoading] = useState(false); const [selectedCountry, setSelectedCountry] = useState(""); + + // Once a Stripe Express account exists, its country is locked. Pre-select + // that country so the user sees what will actually be used, and so a + // deliberate change triggers backend creation of a new account. + useEffect(() => { + if (stripeStatus?.stripe_account_country) { + setSelectedCountry(stripeStatus.stripe_account_country); + } + }, [stripeStatus?.stripe_account_country]); const [countryDropdownOpen, setCountryDropdownOpen] = useState(false); const [countryFilter, setCountryFilter] = useState(""); const countryDropdownRef = useRef(null); @@ -484,19 +492,83 @@ export default function EarningsContent() { ) : ( <> -

- - {restricted - ? "Stripe needs more information to enable payouts on your account." - : rejected - ? "Stripe has disabled payouts on this account. Contact support." - : "Finish linking your account on Stripe to enable withdrawals."} +

+ Your Stripe account is locked to{" "} + + {STRIPE_CONNECT_COUNTRIES.find(c => c.code === stripeStatus?.stripe_account_country)?.name || stripeStatus?.stripe_account_country || "your selected country"} + + . If you need a different country, select it below and we will create a new account.

+ +
+ + + {countryDropdownOpen && ( +
+
+
+ + setCountryFilter(e.target.value)} + placeholder="Search countries..." + autoFocus + className="w-full bg-bg-primary border border-border-dim rounded-lg pl-9 pr-3 py-2 text-sm text-text-primary placeholder:text-text-tertiary outline-none focus:border-teal" + /> +
+
+
+ {STRIPE_CONNECT_COUNTRIES + .filter(c => { + const q = countryFilter.toLowerCase(); + return !q || c.name.toLowerCase().includes(q) || c.code.toLowerCase().includes(q); + }) + .map(c => ( + + )) + } +
+
+ )} +
{!rejected && ( - )} + )} diff --git a/coordinator/api/stripe_payouts.go b/coordinator/api/stripe_payouts.go index 61d8250070..36069c060f 100644 --- a/coordinator/api/stripe_payouts.go +++ b/coordinator/api/stripe_payouts.go @@ -122,7 +122,7 @@ func (s *Server) handleStripeOnboard(w http.ResponseWriter, r *http.Request) { // changed later. stripeAcctID := user.StripeAccountID countryChanged := stripeAcctID != "" && requestedCountry != "" && - user.StripeAccountCountry != "" && requestedCountry != user.StripeAccountCountry + (user.StripeAccountCountry == "" || requestedCountry != user.StripeAccountCountry) if stripeAcctID == "" || countryChanged { country := requestedCountry diff --git a/coordinator/api/stripe_payouts_test.go b/coordinator/api/stripe_payouts_test.go index 2247c550b9..ba8c83787a 100644 --- a/coordinator/api/stripe_payouts_test.go +++ b/coordinator/api/stripe_payouts_test.go @@ -283,6 +283,33 @@ func TestStripeOnboardCreatesNewAccountWhenCountryChanges(t *testing.T) { } } +func TestStripeOnboardCreatesNewAccountWhenExistingCountryUnknown(t *testing.T) { + srv, st := stripePayoutsTestServer(t, true, nil) + user := seedUser(t, st, "acct-country-unknown-1", "carol@example.com") + + // Simulates users created before stripe_account_country existed. If they + // explicitly select a country, don't reuse the unknown-country account. + _ = st.SetUserStripeAccount(user.AccountID, "acct_old_unknown", "pending", "", "", "", false) + user, _ = st.GetUserByAccountID(user.AccountID) + + req := httptest.NewRequest(http.MethodPost, "/v1/billing/stripe/onboard", + strings.NewReader(`{"country":"GB"}`)) + req = withPrivyUser(req, user) + w := httptest.NewRecorder() + srv.handleStripeOnboard(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("got %d: %s", w.Code, w.Body.String()) + } + refreshed, _ := st.GetUserByAccountID(user.AccountID) + if refreshed.StripeAccountID == "acct_old_unknown" { + t.Fatal("expected a new Stripe account for explicit country selection") + } + if refreshed.StripeAccountCountry != "GB" { + t.Errorf("StripeAccountCountry = %q, want GB", refreshed.StripeAccountCountry) + } +} + // --- Status --- func TestStripeStatusReportsCurrentState(t *testing.T) {