Skip to content

Commit

Permalink
Update CardBrand.Mastercard regex (#2467)
Browse files Browse the repository at this point in the history
This better aligns the validation logic of the Android and iOS SDKs [0]

[0] https://github.com/stripe/stripe-ios/blob/master/Stripe/STPBINRange.m#L52
  • Loading branch information
mshafrir-stripe authored May 11, 2020
1 parent c05a89f commit 1588f5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion stripe/src/main/java/com/stripe/android/model/CardBrand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ enum class CardBrand(
"mastercard",
"Mastercard",
R.drawable.stripe_ic_mastercard,
pattern = Pattern.compile("^(2221|2222|2223|2224|2225|2226|2227|2228|2229|223|224|225|226|227|228|229|23|24|25|26|270|271|2720|50|51|52|53|54|55|67)[0-9]*$")
pattern = Pattern.compile("^(2221|2222|2223|2224|2225|2226|2227|2228|2229|222|223|224|225|226|227|228|229|23|24|25|26|270|271|2720|50|51|52|53|54|55|56|57|58|59|67)[0-9]*$"),
partialPatterns = mapOf(
2 to Pattern.compile("^(22|23|24|25|26|27|50|51|52|53|54|55|56|57|58|59|67)$")
)
),

UnionPay(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,10 @@ class CardBrandTest {
assertThat(CardBrand.fromCardNumber("352800"))
.isEqualTo(CardBrand.JCB)
}

@Test
fun fromCardNumber_withMaestroBin_shouldReturnMastercard() {
assertThat(CardBrand.fromCardNumber("561243"))
.isEqualTo(CardBrand.MasterCard)
}
}

0 comments on commit 1588f5b

Please sign in to comment.