diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e0291d44b9..a4c2098406d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ### PaymentSheet * [DEPRECATED][5061](https://github.com/stripe/stripe-android/pull/5061) Add Deprecated annotation to old primaryButtonColor api. -* [FIXED][5068](https://github.com/stripe/stripe-android/pull/5068) Fix missing theming for add lpm button and notes text +* [FIXED][5068](https://github.com/stripe/stripe-android/pull/5068) Fix missing theming for add lpm button and notes text. +* [ADDED][5069](https://github.com/stripe/stripe-android/pull/5069) Add card brand icons to card details form. ### Payments * [FIXED][5079](https://github.com/stripe/stripe-android/pull/5079) Add 3ds2 url to list of completion URLs so callbacks work correctly. diff --git a/payments-core/src/test/java/com/stripe/android/model/CardBrandTest.kt b/payments-core/src/test/java/com/stripe/android/model/CardBrandTest.kt index 4c4a1184273..16eb78fe31a 100644 --- a/payments-core/src/test/java/com/stripe/android/model/CardBrandTest.kt +++ b/payments-core/src/test/java/com/stripe/android/model/CardBrandTest.kt @@ -189,10 +189,9 @@ class CardBrandTest { CardBrand.Discover, CardBrand.JCB, CardBrand.DinersClub, - CardBrand.UnionPay, - CardBrand.Unknown + CardBrand.UnionPay ), - CardBrand.values() + CardBrand.orderedBrands.toTypedArray() ) } } diff --git a/payments-model/src/main/java/com/stripe/android/model/CardBrand.kt b/payments-model/src/main/java/com/stripe/android/model/CardBrand.kt index 74910390f1c..75accacc681 100644 --- a/payments-model/src/main/java/com/stripe/android/model/CardBrand.kt +++ b/payments-model/src/main/java/com/stripe/android/model/CardBrand.kt @@ -44,6 +44,11 @@ enum class CardBrand( * By default, a [CardBrand] does not have variants. */ private val variantMaxLength: Map = emptyMap(), + + /** + * The rendering order in the card details cell + */ + private val renderingOrder: Int ) { Visa( "visa", @@ -53,6 +58,7 @@ enum class CardBrand( partialPatterns = mapOf( 1 to Pattern.compile("^4$") ), + renderingOrder = 1 ), MasterCard( @@ -66,7 +72,8 @@ enum class CardBrand( partialPatterns = mapOf( 1 to Pattern.compile("^2|5|6$"), 2 to Pattern.compile("^(22|23|24|25|26|27|50|51|52|53|54|55|56|57|58|59|67)$") - ) + ), + renderingOrder = 2 ), AmericanExpress( @@ -79,7 +86,8 @@ enum class CardBrand( pattern = Pattern.compile("^(34|37)[0-9]*$"), partialPatterns = mapOf( 1 to Pattern.compile("^3$") - ) + ), + renderingOrder = 3 ), Discover( @@ -90,6 +98,7 @@ enum class CardBrand( partialPatterns = mapOf( 1 to Pattern.compile("^6$") ), + renderingOrder = 4 ), /** @@ -106,7 +115,8 @@ enum class CardBrand( 1 to Pattern.compile("^3$"), 2 to Pattern.compile("^(35)$"), 3 to Pattern.compile("^(35[2-8])$") - ) + ), + renderingOrder = 5 ), /** @@ -126,7 +136,8 @@ enum class CardBrand( ), variantMaxLength = mapOf( Pattern.compile("^(36)[0-9]*$") to 14 - ) + ), + renderingOrder = 6 ), UnionPay( @@ -136,7 +147,8 @@ enum class CardBrand( pattern = Pattern.compile("^(62|81)[0-9]*$"), partialPatterns = mapOf( 1 to Pattern.compile("^6|8$"), - ) + ), + renderingOrder = 7 ), Unknown( @@ -144,7 +156,8 @@ enum class CardBrand( "Unknown", R.drawable.stripe_ic_unknown, cvcLength = setOf(3, 4), - partialPatterns = emptyMap() + partialPatterns = emptyMap(), + renderingOrder = -1 ); val maxCvcLength: Int @@ -238,6 +251,11 @@ enum class CardBrand( return values().firstOrNull { it.code.equals(code, ignoreCase = true) } ?: Unknown } + val orderedBrands = values() + .toList() + .filter { it.renderingOrder > 0 } + .sortedBy { it.renderingOrder } + private const val CVC_COMMON_LENGTH: Int = 3 } }