Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle Cartes Bancaires test cards in retrievePossibleBrands #8258

Merged
merged 13 commits into from Apr 15, 2024

Conversation

amk-stripe
Copy link
Contributor

@amk-stripe amk-stripe commented Apr 10, 2024

Summary

Return correct possible brands for Cartes Bancaires test cards in retrievePossibleBrands API

Motivation

Our API used to incorrectly return only Visa or only Mastercard for the two Cartes Bancaires multi-brand test cards, seen in our docs here

Testing

  • Added tests
  • Modified tests
  • Manually verified

Changelog

  • [FIXED]8259 Fixed an issue with retrievePossibleBrands returning incorrect brands for Cartes Bancaires test cards.

@amk-stripe amk-stripe requested review from a team as code owners April 10, 2024 22:43
@amk-stripe amk-stripe enabled auto-merge (squash) April 10, 2024 22:45
Copy link
Contributor

github-actions bot commented Apr 10, 2024

Diffuse output:

OLD: paymentsheet-example-release-master.apk (signature: V1, V2)
NEW: paymentsheet-example-release-pr.apk (signature: V1, V2)

          │           compressed           │          uncompressed          
          ├───────────┬───────────┬────────┼───────────┬───────────┬────────
 APK      │ old       │ new       │ diff   │ old       │ new       │ diff   
──────────┼───────────┼───────────┼────────┼───────────┼───────────┼────────
      dex │   3.9 MiB │   3.9 MiB │ -231 B │   8.5 MiB │   8.5 MiB │ +148 B 
     arsc │   2.2 MiB │   2.2 MiB │    0 B │   2.2 MiB │   2.2 MiB │    0 B 
 manifest │     5 KiB │     5 KiB │    0 B │  24.9 KiB │  24.9 KiB │    0 B 
      res │ 911.1 KiB │ 911.1 KiB │    0 B │   1.4 MiB │   1.4 MiB │    0 B 
   native │   2.6 MiB │   2.6 MiB │    0 B │     6 MiB │     6 MiB │    0 B 
    asset │     3 MiB │     3 MiB │    0 B │     3 MiB │     3 MiB │    0 B 
    other │   204 KiB │   204 KiB │   +9 B │ 444.8 KiB │ 444.8 KiB │    0 B 
──────────┼───────────┼───────────┼────────┼───────────┼───────────┼────────
    total │  12.8 MiB │  12.8 MiB │ -222 B │  21.7 MiB │  21.7 MiB │ +148 B 

 DEX     │ old   │ new   │ diff       
─────────┼───────┼───────┼────────────
   files │     1 │     1 │  0         
 strings │ 42605 │ 42605 │  0 (+1 -1) 
   types │ 14495 │ 14495 │  0 (+0 -0) 
 classes │ 12223 │ 12223 │  0 (+0 -0) 
 methods │ 60396 │ 60396 │  0 (+0 -0) 
  fields │ 40086 │ 40087 │ +1 (+1 -0) 

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  242 │  242 │  0   
 entries │ 6030 │ 6030 │  0
APK
    compressed     │    uncompressed    │                        
──────────┬────────┼───────────┬────────┤                        
 size     │ diff   │ size      │ diff   │ path                   
──────────┼────────┼───────────┼────────┼────────────────────────
  3.9 MiB │ -231 B │   8.5 MiB │ +148 B │ ∆ classes.dex          
   62 KiB │   +9 B │ 139.7 KiB │    0 B │ ∆ META-INF/CERT.SF     
  1.2 KiB │   -2 B │   1.2 KiB │    0 B │ ∆ META-INF/CERT.RSA    
 53.1 KiB │   +2 B │ 139.6 KiB │    0 B │ ∆ META-INF/MANIFEST.MF 
──────────┼────────┼───────────┼────────┼────────────────────────
    4 MiB │ -222 B │   8.8 MiB │ +148 B │ (total)
DEX
STRINGS:

   old   │ new   │ diff      
  ───────┼───────┼───────────
   42605 │ 42605 │ 0 (+1 -1) 
  
  + ~~R8{backend:dex,compilation-mode:release,has-checksums:false,min-api:21,pg-map-id:a0cfda6,r8-mode:full,version:8.3.37}
  
  - ~~R8{backend:dex,compilation-mode:release,has-checksums:false,min-api:21,pg-map-id:3c16195,r8-mode:full,version:8.3.37}
  

FIELDS:

   old   │ new   │ diff       
  ───────┼───────┼────────────
   40086 │ 40087 │ +1 (+1 -0) 
  
  + I4.v j: ArrayList

@sfriedman-stripe
Copy link
Collaborator

:sonic: 👏🏻

Comment on lines 179 to 202
private val CARTES_BANCAIRES_ACCOUNT_RANGES = setOf(
BinRange(
low = "2221000000000000",
high = "2720000000000000"
),
BinRange(
low = "4000000000000000",
high = "4999999999999999"
),
BinRange(
low = "5000000000000000",
high = "5900000000000000"
),
BinRange(
low = "6700000000000000",
high = "6799999999999999"
)
).map {
AccountRange(
binRange = it,
panLength = 16,
brandInfo = AccountRange.BrandInfo.CartesBancaires
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these bin ranges impact other cards besides the test cards? Is there any reason why we can't hardcode the test numbers rather than these ranges? In production the card metadata service determines what card brands to vend to the client, rather than have the client determine this. I'm concerned these bin ranges could have unintended consequences.

https://github.com/stripe/stripe-ios/blob/ac4a8468/StripePayments/StripePayments/Source/Helpers/STPCardValidator.swift#L444

https://github.com/stripe/stripe-android/blob/5e021d15/payments-core/src/main/java/com/stripe/android/cards/CbcTestCardDelegate.kt#L10

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do see failing tests relating to CBC and BIN in the bitrise run, I think we should hardcode these card numbers rather than have the test cards influence client side bin ranges.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can hardcode the test numbers. That seems good so that we can de-risk getting this fixed and to ensure we don't introduce any unintended behavior.

The BIN ranges that I added here match the regex that we use for CBC. This API and CBC don't actually use the same code path for determining possible brands. Created a jira to unify the two code paths because it seems less than ideal that this API would have different behavior than our implementation of CBC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated PR to just add the test numbers and no other ranges

@@ -43,17 +43,6 @@ class CardAccountRangeService(
return
}

val testAccountRanges = if (isCbcEligible()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used to ensure that the test cards were handled properly in this service. Now the test cards are part of the static card ranges (queried below), so we don't need this special handling.

panLength = 16,
brandInfo = AccountRange.BrandInfo.Visa,
)
fun `If CBC is disabled and only one brand matches, return the matched brand as soon as there is input`() =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test depends on there being only one card that matches the input. Now that the Cartes Bancaires test card also matches a "4" prefix, I needed to change the digit and card brand being used for this test

samer-stripe
samer-stripe previously approved these changes Apr 12, 2024
samer-stripe
samer-stripe previously approved these changes Apr 12, 2024
@amk-stripe amk-stripe merged commit d6b0e23 into master Apr 15, 2024
15 checks passed
@amk-stripe amk-stripe deleted the test-cards-in-retrieve-possible-brands branch April 15, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants