Fix KYC provider routing for users with unresolved country - #2521
Merged
Merged
Conversation
The card flow falls back to Didit whenever it cannot resolve a country or the routing call fails, because Didit is available everywhere. That was safe while the server questioned nothing — and it was not: a Didit session creates a card customer defaulting to Rain, and nothing ever rewrites it. Users in markets Wirex is supposed to win (Thailand, Brazil, Kenya, the US) were landing on Rain for good on the strength of one failed IP lookup. Three changes, matching the server guard that now refuses these: - The card flow sends its country on the Didit session, resolved by the same `resolveRoutingCountry` the routing call uses — so the server can refuse a Wirex market. Both callers must agree or the client is routed to Didit and then refused by it. The onramp and virtual account send none: they run off their own country lists and are not card applications. - CARD_PROVIDER_MISMATCH sends the user to the country screen, exactly as the Sumsub side already does for the mirror case. It re-asks routing on the way through and persists the country picked, so the round trip settles instead of repeating; pushing straight at the Sumsub screen would only bounce off its own COUNTRY_REQUIRED. - With no country resolvable at all, the card flow asks rather than guessing. Only reached when the IP lookup failed too — a country that resolves still goes straight through, so no one gains a step. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xq9bCus4z9sv4FH19v1xgu
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical issue where users with no stored country and undetectable IP geolocation were being incorrectly routed to the Didit (Rain) card provider, even when they should be routed to Wirex. The fix ensures that when country cannot be resolved, users are prompted to select their country before proceeding with card verification.
Key Changes
Export
resolveRoutingCountryfunction: Made the country resolution logic available to the Didit session creation flow so both the client and server can reach the same routing decision.Pass country code to Didit session: Modified
createDiditSessionto accept and send an optionalcountryCodeparameter. This allows the backend to refuse card applications in markets where Wirex is the correct provider, preventing users from being permanently pinned to Rain.Add country selection gate in card flow: Added a check in
useCardStepsthat routes users to the country selection screen when no country can be resolved (neither stored nor detected via IP lookup). This prevents silent fallback to Didit for unresolved users.Handle CARD_PROVIDER_MISMATCH error: Added error handling in
useDiditSessionfor theCARD_PROVIDER_MISMATCHresponse code (400), which occurs when the server refuses a card application because the user's country routes to Wirex. Users are redirected to the country selection screen to re-route correctly.Add test coverage: Comprehensive test suite for
resolveRoutingCountrycovering stored country usage, IP lookup fallback, undefined resolution, and persistence behavior.Notable Implementation Details
https://claude.ai/code/session_01Xq9bCus4z9sv4FH19v1xgu