fix(headless): validate cobadged cards via BIN cache (iOS↔Android parity)#1722
Open
OnurVar wants to merge 2 commits into
Open
fix(headless): validate cobadged cards via BIN cache (iOS↔Android parity)#1722OnurVar wants to merge 2 commits into
OnurVar wants to merge 2 commits into
Conversation
Contributor
|
Appetize link: https://appetize.io/app/7gx3iwdub7hcorvykrwwys2ohu |
8332f03 to
a5d41ff
Compare
a5d41ff to
e8154d7
Compare
…ity) - `validateRawData(_:)` now reads from `CardValidationService.cachedMetadata` so cobadged cards (e.g. BIN 5017…, CB+MC) aren't rejected on the local-IIN guess (Maestro) when the merchant's allowed list contains the actual networks. - Validator mirrors Android `CardNumberValidator`: the unsupported-card-type check only fires for BIN-derived metadata (REMOTE / LOCAL_FALLBACK), and uses "any detected network is allowed" rather than "the resolved network is in the allowed list". - Drop the redundant allowed-list guard in `makeRequestBodyWithRawData` (validation runs before submit; Android doesn't repeat it either). - BIN cache now keyed consistently by 8-char BIN via `binKey(for:)`, with `cachedMetadata(forCardNumber:)` exposed on the protocol. - Debug App: preserve the user's tap when `didReceiveCardMetadata` re-fires (submit-time re-validation), and only treat a selectable list with >1 items as interactive. - Tests cover BIN-cache lookup, `.local` source skip, REMOTE rejection, and cache-key consistency.
e8154d7 to
830eae3
Compare
henry-cooper-primer
approved these changes
May 11, 2026
| allowedCardNetworks: [CardNetwork] = [CardNetwork].allowedCardNetworks, | ||
| apiClient: PrimerAPIClientBINDataProtocol = PrimerAPIClient(), | ||
| debouncer: Debouncer = .init(delay: 0.35)) { | ||
| private func binKey(for cardNumber: String) -> String { |
Contributor
There was a problem hiding this comment.
below internal and functions below inits
|
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.



Description
Fixes the headless cobadge case where a card whose local IIN guess is not in the merchant's allowed list (e.g. BIN `5017…` is locally classified as Maestro, but the BIN response says CB + MC) is rejected at validation, leaving the pay button disabled forever.
Root cause: `PrimerRawCardDataTokenizationBuilder.validateRawData(_:)` ran on every keystroke with `cardNetworksMetadata: nil` and fell back to `CardNetwork(cardNumber:)`. The SDK already had the authoritative BIN response cached in `CardValidationService.metadataCacheBacking`, but the validator never consulted it.
Fix: validator now consults the BIN cache, and the allowed-list check is now expressed the same way Android does it. iOS and Android headless validators are now behaviourally aligned.
What changed
iOS ↔ Android parity
The EFTPOS filter is a deliberate iOS-specific behaviour (covered by an existing test, out of scope here). Everything else is now in lockstep with Android `CardNumberValidator.kt`.
Manual Testing
Verified end-to-end in the Debug App against the sandbox client session with `orderedAllowedCardNetworks=[CB, VISA, MASTERCARD]`. Cases below come from the test matrix in `specs/TEST-CASES.md`:
Contributor Checklist
Reviewer Checklist
Before Merging
Other Stuff