Skip to content

Commit

Permalink
Refactor ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswoo-stripe committed May 31, 2022
1 parent 1e2a029 commit 54c9b81
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ class CardBrandTest {
CardBrand.Discover,
CardBrand.JCB,
CardBrand.DinersClub,
CardBrand.UnionPay,
CardBrand.Unknown
CardBrand.UnionPay
),
CardBrand.values()
CardBrand.orderedBrands.toTypedArray()
)
}
}
30 changes: 24 additions & 6 deletions payments-model/src/main/java/com/stripe/android/model/CardBrand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ enum class CardBrand(
* By default, a [CardBrand] does not have variants.
*/
private val variantMaxLength: Map<Pattern, Int> = emptyMap(),

/**
* The rendering order in the card details cell
*/
private val renderingOrder: Int
) {
Visa(
"visa",
Expand All @@ -53,6 +58,7 @@ enum class CardBrand(
partialPatterns = mapOf(
1 to Pattern.compile("^4$")
),
renderingOrder = 1
),

MasterCard(
Expand All @@ -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(
Expand All @@ -79,7 +86,8 @@ enum class CardBrand(
pattern = Pattern.compile("^(34|37)[0-9]*$"),
partialPatterns = mapOf(
1 to Pattern.compile("^3$")
)
),
renderingOrder = 3
),

Discover(
Expand All @@ -90,6 +98,7 @@ enum class CardBrand(
partialPatterns = mapOf(
1 to Pattern.compile("^6$")
),
renderingOrder = 4
),

/**
Expand All @@ -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
),

/**
Expand All @@ -126,7 +136,8 @@ enum class CardBrand(
),
variantMaxLength = mapOf(
Pattern.compile("^(36)[0-9]*$") to 14
)
),
renderingOrder = 6
),

UnionPay(
Expand All @@ -136,15 +147,17 @@ enum class CardBrand(
pattern = Pattern.compile("^(62|81)[0-9]*$"),
partialPatterns = mapOf(
1 to Pattern.compile("^6|8$"),
)
),
renderingOrder = 7
),

Unknown(
"unknown",
"Unknown",
R.drawable.stripe_ic_unknown,
cvcLength = setOf(3, 4),
partialPatterns = emptyMap()
partialPatterns = emptyMap(),
renderingOrder = -1
);

val maxCvcLength: Int
Expand Down Expand Up @@ -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
}
}

0 comments on commit 54c9b81

Please sign in to comment.