Repository navigation
fix(billing): allow changing Stripe Express country by creating new account - #427
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This PR adds a single read-only display field ( Trust Boundaries Touched
Threat Analysis
New Attack SurfaceNone. Open Findings ResolvedNone. The 9 unmapped files ( 🔐 Threat model: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c10ce004b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| countryChanged := stripeAcctID != "" && requestedCountry != "" && | ||
| user.StripeAccountCountry != "" && requestedCountry != user.StripeAccountCountry |
There was a problem hiding this comment.
Don't reuse accounts with unknown locked country
For users who already had a stripe_account_id before this migration, the new stripe_account_country column is empty, so selecting a different country never makes countryChanged true because of the user.StripeAccountCountry != "" guard. In that scenario the handler reuses the old Stripe account and returns an onboarding link for the account whose country the user is trying to escape, so existing wrong-country users remain stuck unless the country is backfilled or an unknown stored country is treated as needing replacement/refresh from Stripe.
Useful? React with 👍 / 👎.
| {!rejected && ( | ||
| <button | ||
| onClick={handleStripeOnboard} | ||
| disabled={stripeOnboardLoading} | ||
| className="flex items-center gap-2 px-5 py-2.5 rounded-lg bg-teal border-2 border-ink text-white text-sm font-bold hover:opacity-90 disabled:opacity-50 transition-all" | ||
| disabled={stripeOnboardLoading || !selectedCountry} |
There was a problem hiding this comment.
Allow rejected users to submit a new country
On the Provider Earnings page, rejected Stripe accounts now see the replacement-country picker but the only onboarding button is still hidden by !rejected, so a provider whose account was rejected in the wrong country cannot submit a different country from this surface. Since the backend and Billing page both support creating a fresh account when the selected country changes, this guard leaves rejected providers stuck unless they discover the separate Billing page.
Useful? React with 👍 / 👎.
…ccount 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.
c10ce00 to
26c092d
Compare
ethenotethan
left a comment
There was a problem hiding this comment.
Automated Code Review — Layr-Labs/d-inference#
Verdict: REQUEST_CHANGES
Security — ✅ No issues found
Performance — 1 finding(s) (1 blocking)
- 🟡 [MEDIUM]
coordinator/store/postgres.go:3070-3077— Dynamic SQL construction using fmt.Sprintf in hot path- Suggestion: Pre-build both SQL variants at startup or use conditional parameter binding to avoid string formatting on every call
Type_diligence — 1 finding(s) (1 blocking)
- 🟡 [MEDIUM]
coordinator/store/postgres.go:3056-3077— fmt.Sprintf with dynamic SQL construction using untrusted countryClause- Suggestion: Use parameterized queries or prepared statements instead of string concatenation. Consider using a conditional UPDATE with CASE or separate query paths for country updates.
Additive_complexity — 4 finding(s) (1 blocking)
- 🔵 [INFO]
coordinator/api/stripe_payouts.go:142— SetUserStripeAccount now takes 7 parameters, making it harder to call correctly- Suggestion: Consider using a struct parameter or builder pattern to reduce parameter count and improve readability
- 🟡 [MEDIUM]
coordinator/store/postgres.go:3056-3077— Dynamic SQL construction with conditional country clause adds complexity- Suggestion: Use two separate queries or COALESCE to handle optional country update more simply
- 🔵 [INFO]
console-ui/src/app/providers/earnings/EarningsContent.tsx:495-575— Custom dropdown implementation duplicates standard select functionality- Suggestion: Use a standard select element like in BillingContent.tsx or extract shared dropdown component
- 🔵 [INFO]
coordinator/api/stripe_payouts.go:187-207— Status endpoint conditionally updates database state during read operation- Suggestion: Move the SetUserStripeAccount call to a separate sync/refresh endpoint or background job
6 finding(s) total, 3 blocking. Verdict: REQUEST_CHANGES.
🤖 Automated review by Centaur · DAR-186
| fmt.Sprintf(`UPDATE users SET | ||
| stripe_account_id = $2, | ||
| stripe_account_status = $3, | ||
| stripe_destination_type = $4, | ||
| stripe_destination_last4 = $5, | ||
| stripe_instant_eligible = $6 | ||
| WHERE account_id = $1`, | ||
| accountID, stripeAccountID, status, destinationType, destinationLast4, instantEligible, | ||
| stripe_instant_eligible = $6%s | ||
| WHERE account_id = $1`, countryClause), | ||
| args..., |
There was a problem hiding this comment.
🟡 [MEDIUM] ⚡ Dynamic SQL construction using fmt.Sprintf in hot path
💡 Suggestion: Pre-build both SQL variants at startup or use conditional parameter binding to avoid string formatting on every call
📊 Score: 3×4 = 12 · Category: inefficient_string_formatting
| // stripeAccountCountry is the ISO country the Express account is locked to. | ||
| // Pass an empty string to leave the existing country value unchanged. | ||
| func (s *PostgresStore) SetUserStripeAccount(accountID, stripeAccountID, status, stripeAccountCountry, destinationType, destinationLast4 string, instantEligible bool) error { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
|
|
||
| countryClause := "" | ||
| args := []any{accountID, stripeAccountID, status, destinationType, destinationLast4, instantEligible} | ||
| if stripeAccountCountry != "" { | ||
| countryClause = ", stripe_account_country = $7" | ||
| args = append(args, stripeAccountCountry) | ||
| } | ||
|
|
||
| tag, err := s.pool.Exec(ctx, | ||
| `UPDATE users SET | ||
| fmt.Sprintf(`UPDATE users SET | ||
| stripe_account_id = $2, | ||
| stripe_account_status = $3, | ||
| stripe_destination_type = $4, | ||
| stripe_destination_last4 = $5, | ||
| stripe_instant_eligible = $6 | ||
| WHERE account_id = $1`, | ||
| accountID, stripeAccountID, status, destinationType, destinationLast4, instantEligible, | ||
| stripe_instant_eligible = $6%s | ||
| WHERE account_id = $1`, countryClause), | ||
| args..., |
There was a problem hiding this comment.
🟡 [MEDIUM] 🏷️ fmt.Sprintf with dynamic SQL construction using untrusted countryClause
💡 Suggestion: Use parameterized queries or prepared statements instead of string concatenation. Consider using a conditional UPDATE with CASE or separate query paths for country updates.
📊 Score: 3×4 = 12 · Category: unsafe_type_cast
| } | ||
| stripeAcctID = acct.ID | ||
| if err := s.billing.Store().SetUserStripeAccount(user.AccountID, stripeAcctID, stripeStatusPending, "", "", false); err != nil { | ||
| if err := s.billing.Store().SetUserStripeAccount(user.AccountID, stripeAcctID, stripeStatusPending, country, "", "", false); err != nil { |
There was a problem hiding this comment.
🔵 [INFO] 🧩 SetUserStripeAccount now takes 7 parameters, making it harder to call correctly
💡 Suggestion: Consider using a struct parameter or builder pattern to reduce parameter count and improve readability
📊 Score: 2×3 = 6 · Category: over-configuration
| // stripeAccountCountry is the ISO country the Express account is locked to. | ||
| // Pass an empty string to leave the existing country value unchanged. | ||
| func (s *PostgresStore) SetUserStripeAccount(accountID, stripeAccountID, status, stripeAccountCountry, destinationType, destinationLast4 string, instantEligible bool) error { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
|
|
||
| countryClause := "" | ||
| args := []any{accountID, stripeAccountID, status, destinationType, destinationLast4, instantEligible} | ||
| if stripeAccountCountry != "" { | ||
| countryClause = ", stripe_account_country = $7" | ||
| args = append(args, stripeAccountCountry) | ||
| } | ||
|
|
||
| tag, err := s.pool.Exec(ctx, | ||
| `UPDATE users SET | ||
| fmt.Sprintf(`UPDATE users SET | ||
| stripe_account_id = $2, | ||
| stripe_account_status = $3, | ||
| stripe_destination_type = $4, | ||
| stripe_destination_last4 = $5, | ||
| stripe_instant_eligible = $6 | ||
| WHERE account_id = $1`, | ||
| accountID, stripeAccountID, status, destinationType, destinationLast4, instantEligible, | ||
| stripe_instant_eligible = $6%s | ||
| WHERE account_id = $1`, countryClause), | ||
| args..., |
There was a problem hiding this comment.
🟡 [MEDIUM] 🧩 Dynamic SQL construction with conditional country clause adds complexity
💡 Suggestion: Use two separate queries or COALESCE to handle optional country update more simply
📊 Score: 3×4 = 12 · Category: over-abstraction
| <p className="text-sm text-text-secondary mb-4 leading-relaxed"> | ||
| Your Stripe account is locked to{" "} | ||
| <span className="font-medium text-text-primary"> | ||
| {STRIPE_CONNECT_COUNTRIES.find(c => c.code === stripeStatus?.stripe_account_country)?.name || stripeStatus?.stripe_account_country || "your selected country"} | ||
| </span> | ||
| . If that is not correct, select your country below and we will create a new account. | ||
| </p> | ||
| {!rejected && ( | ||
| <label className="block text-xs font-mono text-text-tertiary uppercase tracking-wider mb-2"> | ||
| Country | ||
| </label> | ||
| <div className="relative mb-4" ref={countryDropdownRef}> | ||
| <button | ||
| onClick={handleStripeOnboard} | ||
| disabled={stripeOnboardLoading} | ||
| className="flex items-center gap-2 px-5 py-2.5 rounded-lg bg-teal border-2 border-ink text-white text-sm font-bold hover:opacity-90 disabled:opacity-50 transition-all" | ||
| type="button" | ||
| onClick={() => { setCountryDropdownOpen(!countryDropdownOpen); setCountryFilter(""); }} | ||
| className="w-full flex items-center justify-between gap-2 bg-bg-primary border border-border-dim rounded-lg px-4 py-3 text-sm text-left transition-colors hover:border-teal/40 focus:outline-none focus:border-teal" | ||
| > | ||
| {stripeOnboardLoading ? <Loader2 size={14} className="animate-spin" /> : <Building2 size={14} />} | ||
| {stripeOnboardLoading ? "Redirecting..." : restricted ? "Provide more info" : "Continue setup"} | ||
| {selectedCountry ? ( | ||
| <span className="flex items-center gap-2 text-text-primary"> | ||
| <span>{STRIPE_CONNECT_COUNTRIES.find(c => c.code === selectedCountry)?.flag}</span> | ||
| <span>{STRIPE_CONNECT_COUNTRIES.find(c => c.code === selectedCountry)?.name}</span> | ||
| </span> | ||
| ) : ( | ||
| <span className="flex items-center gap-2 text-text-tertiary"> | ||
| <Globe size={14} /> | ||
| <span>Select your country</span> | ||
| </span> | ||
| )} | ||
| <ChevronDown size={14} className={`text-text-tertiary transition-transform ${countryDropdownOpen ? "rotate-180" : ""}`} /> | ||
| </button> | ||
| )} | ||
|
|
||
| {countryDropdownOpen && ( | ||
| <div className="absolute z-50 mt-1 w-full bg-bg-white border border-border-dim rounded-xl shadow-lg overflow-hidden"> | ||
| <div className="p-2 border-b border-border-dim"> | ||
| <div className="relative"> | ||
| <Search size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary" /> | ||
| <input | ||
| type="text" | ||
| value={countryFilter} | ||
| onChange={(e) => 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" | ||
| /> | ||
| </div> | ||
| </div> | ||
| <div className="max-h-64 overflow-y-auto"> | ||
| {STRIPE_CONNECT_COUNTRIES | ||
| .filter(c => { | ||
| const q = countryFilter.toLowerCase(); | ||
| return !q || c.name.toLowerCase().includes(q) || c.code.toLowerCase().includes(q); | ||
| }) | ||
| .map(c => ( | ||
| <button | ||
| key={c.code} | ||
| type="button" | ||
| onClick={() => { setSelectedCountry(c.code); setCountryDropdownOpen(false); }} | ||
| className={`w-full flex items-center gap-3 px-4 py-2.5 text-sm text-left transition-colors ${ | ||
| selectedCountry === c.code | ||
| ? "bg-teal/10 text-teal" | ||
| : "text-text-secondary hover:bg-bg-hover" | ||
| }`} | ||
| > | ||
| <span className="text-base">{c.flag}</span> | ||
| <span className="flex-1">{c.name}</span> | ||
| <span className="text-xs font-mono text-text-tertiary">{c.code}</span> | ||
| </button> | ||
| )) | ||
| } | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| <button | ||
| onClick={handleStripeOnboard} | ||
| disabled={stripeOnboardLoading || !selectedCountry} | ||
| className="flex items-center gap-2 px-5 py-2.5 rounded-lg bg-teal border-2 border-ink text-white text-sm font-bold hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed transition-all" | ||
| > | ||
| {stripeOnboardLoading ? <Loader2 size={14} className="animate-spin" /> : <Building2 size={14} />} | ||
| {stripeOnboardLoading ? "Redirecting..." : restricted ? "Provide more info" : "Continue setup"} | ||
| </button> | ||
| </> |
There was a problem hiding this comment.
🔵 [INFO] 🧩 Custom dropdown implementation duplicates standard select functionality
💡 Suggestion: Use a standard select element like in BillingContent.tsx or extract shared dropdown component
📊 Score: 2×3 = 6 · Category: duplicate logic
| @@ -191,7 +204,7 @@ func (s *Server) handleStripeStatus(w http.ResponseWriter, r *http.Request) { | |||
| } else { | |||
| status := stripeStatusForAccount(acct) | |||
| if err := s.billing.Store().SetUserStripeAccount(user.AccountID, user.StripeAccountID, | |||
| status, acct.DestinationType, acct.DestinationLast4, acct.InstantEligible); err != nil { | |||
| status, "", acct.DestinationType, acct.DestinationLast4, acct.InstantEligible); err != nil { | |||
There was a problem hiding this comment.
🔵 [INFO] 🧩 Status endpoint conditionally updates database state during read operation
💡 Suggestion: Move the SetUserStripeAccount call to a separate sync/refresh endpoint or background job
📊 Score: 2×2 = 4 · Category: misplaced responsibility
Port the opt-in typical verifier from ddalcu/mlx-serve PR #427 into the provider. The engine rule lives in mlx-swift-lm (pin moved to 8def451 on fork main); this layer selects it per model and reports it. - `[backend] mtp_acceptance` (optional; nil = not set) and `mtp_acceptance_by_model` in provider.toml, values "exact" / "typical". Precedence: per-model table, then the global key, then exact. An unknown value resolves to exact and is logged, so a typo can never install a lossy rule. The typical threshold is the engine constant 0.2. - MTPAcceptancePolicy (new) parses and resolves; the slot factory passes the result into CBv2MTPConfig(acceptance:). Standalone serving and the start command carry the same keys. Serving reads no environment variable; the benchmark harness alone honours DARKBLOOM_MTP_ACCEPTANCE=exact|typical[:<delta>]. - Slot posture telemetry gains `mtp_acceptance` (Swift, Go and TS allowlists plus the schema doc) so acceptance rates roll up per rule. - Docs: cli-reference rows, inference.md MTP paragraph, design record docs/design/typical-mtp-acceptance.md with its index row, changelog. Greedy requests are unchanged; for a model configured typical, sampled output is not distribution-exact for the target. G4 measurement is pending; no fleet default moves before that table exists. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Port the opt-in typical verifier from ddalcu/mlx-serve PR #427 into the provider. The engine rule lives in mlx-swift-lm (pin moved to 8def451 on fork main); this layer selects it per model and reports it. - `[backend] mtp_acceptance` (optional; nil = not set) and `mtp_acceptance_by_model` in provider.toml, values "exact" / "typical". Precedence: per-model table, then the global key, then exact. An unknown value resolves to exact and is logged, so a typo can never install a lossy rule. The typical threshold is the engine constant 0.2. - MTPAcceptancePolicy (new) parses and resolves; the slot factory passes the result into CBv2MTPConfig(acceptance:). Standalone serving and the start command carry the same keys. Serving reads no environment variable; the benchmark harness alone honours DARKBLOOM_MTP_ACCEPTANCE=exact|typical[:<delta>]. - Slot posture telemetry gains `mtp_acceptance` (Swift, Go and TS allowlists plus the schema doc) so acceptance rates roll up per rule. - Docs: cli-reference rows, inference.md MTP paragraph, design record docs/design/typical-mtp-acceptance.md with its index row, changelog. Greedy requests are unchanged; for a model configured typical, sampled output is not distribution-exact for the target. G4 measurement is pending; no fleet default moves before that table exists. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Port the opt-in typical verifier from ddalcu/mlx-serve PR #427 into the provider. The engine rule lives in mlx-swift-lm (pin moved to 8def451 on fork main); this layer selects it per model and reports it. - `[backend] mtp_acceptance` (optional; nil = not set) and `mtp_acceptance_by_model` in provider.toml, values "exact" / "typical". Precedence: per-model table, then the global key, then exact. An unknown value resolves to exact and is logged, so a typo can never install a lossy rule. The typical threshold is the engine constant 0.2. - MTPAcceptancePolicy (new) parses and resolves; the slot factory passes the result into CBv2MTPConfig(acceptance:). Standalone serving and the start command carry the same keys. Serving reads no environment variable; the benchmark harness alone honours DARKBLOOM_MTP_ACCEPTANCE=exact|typical[:<delta>]. - Slot posture telemetry gains `mtp_acceptance` (Swift, Go and TS allowlists plus the schema doc) so acceptance rates roll up per rule. - Docs: cli-reference rows, inference.md MTP paragraph, design record docs/design/typical-mtp-acceptance.md with its index row, changelog. Greedy requests are unchanged; for a model configured typical, sampled output is not distribution-exact for the target. G4 measurement is pending; no fleet default moves before that table exists. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Add per-model typical MTP draft acceptance for sampled requests Port the opt-in typical verifier from ddalcu/mlx-serve PR #427 into the provider. The engine rule lives in mlx-swift-lm (pin moved to 8def451 on fork main); this layer selects it per model and reports it. - `[backend] mtp_acceptance` (optional; nil = not set) and `mtp_acceptance_by_model` in provider.toml, values "exact" / "typical". Precedence: per-model table, then the global key, then exact. An unknown value resolves to exact and is logged, so a typo can never install a lossy rule. The typical threshold is the engine constant 0.2. - MTPAcceptancePolicy (new) parses and resolves; the slot factory passes the result into CBv2MTPConfig(acceptance:). Standalone serving and the start command carry the same keys. Serving reads no environment variable; the benchmark harness alone honours DARKBLOOM_MTP_ACCEPTANCE=exact|typical[:<delta>]. - Slot posture telemetry gains `mtp_acceptance` (Swift, Go and TS allowlists plus the schema doc) so acceptance rates roll up per rule. - Docs: cli-reference rows, inference.md MTP paragraph, design record docs/design/typical-mtp-acceptance.md with its index row, changelog. Greedy requests are unchanged; for a model configured typical, sampled output is not distribution-exact for the target. G4 measurement is pending; no fleet default moves before that table exists. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * refactor: file the typical MTP acceptance changelog entry under Unreleased The entry sat in the frozen v0.9.9 release-candidate section (cut 2026-09-22) with a stray blank line; move it to the top Unreleased list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(configuration): document DARKBLOOM_MTP_ACCEPTANCE Master's docs-impact map ties ProviderConfig.swift to the configuration reference. Add the benchmark-only acceptance override next to DARKBLOOM_MTP_VERIFICATION_MODE and point serving readers to the [backend] provider.toml keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * bench(mtp): expose sampled acceptance controls and installed rule evidence * docs: record controlled typical MTP throughput measurements * build: pin merged typical acceptance SDK main --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com>
…sting bounds #2149 now reads the tool channel in linear time (e2c60ca) and pins #423 with the nesting bounds. Only the libs/mlx-swift-lm gitlink conflicted. It now pins 3702459f, mlx-swift-lm #427 (vision) with that #423 (cc2be070) merged in. libs/mlx and libs/mlx-swift stay at 72dffa2d and b1c94d29. Co-Authored-By: Claude <noreply@anthropic.com>
…che (replay Layr-Labs#2149) Replays Layr-Labs#2149 onto dev (82175d9) and pins libs/mlx-swift-lm to d625d5bde2bd6f181227e858422f1d072d84c6cc (Layr-Labs/mlx-swift-lm#579, multimodal SDK baseline: Layr-Labs#423, Layr-Labs#427, Layr-Labs#429, Layr-Labs#430, Layr-Labs#432; Layr-Labs#428 omitted) so every commit in the stack compiles cleanly. Drops Layr-Labs#2149's MTPAcceptancePolicy.swift edit (superseded by Layr-Labs#2723 universal exact acceptance on dev), regenerates fixtures/prompt-contract/v1/reasoning_effort_vectors.json (475 -> 504 cases, inserting muse_glimmer at indices 380-408 via scripts/generate-reasoning-effort-vectors.py), and updates CachePromptParityTests and MuseGlimmerPolicyTests for dev parity.
Summary
Why
Stripe Express account country is immutable after account creation. Reusing an existing wrong-country account sent users back to Stripe still seeing USA. With this change, selecting the correct country creates a new connected account while existing internal earnings balances remain unchanged.
Existing Users
Users stuck with a wrong-country Stripe account can select their correct country in Billing or Provider Earnings and continue. The backend creates a new Express account for future withdrawals. Historical withdrawals remain tied to the old account.
Verification
go test ./api/ -run TestStripego test ./store/ -count=1go test ./billing/ -count=1go build ./...golangci-lint runnpm test -- --runnpx eslint src/app/billing/BillingContent.tsx src/app/providers/earnings/EarningsContent.tsx src/lib/api.tsnpm run build