Skip to content

Commit

Permalink
Merge pull request #10 from mucahitkambur/master
Browse files Browse the repository at this point in the history
Implement detect credit card type mechanism
  • Loading branch information
savepopulation authored Dec 5, 2019
2 parents 850b792 + eb9f8cb commit 419aac1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/src/main/java/com/raqun/oyster/card/CardType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.raqun.oyster.card

enum class CardType {
UNKNOWN,
VISA,
MASTER_CARD,
AMERICAN_EXPRESS,
DINERS_CLUB,
DISCOVER,
JCB,
JCB15
}
24 changes: 24 additions & 0 deletions lib/src/main/java/com/raqun/oyster/card/CardUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.raqun.oyster.card

class CardUtil {

companion object {
fun getType(cardNumber: String): CardType {
val regexMap = mapOf(
TYPE_REGEX_VISA to CardType.VISA,
TYPE_REGEX_MASTER_CARD to CardType.MASTER_CARD,
TYPE_REGEX_AMEX to CardType.AMERICAN_EXPRESS,
TYPE_REGEX_DINERS_CLUB to CardType.DINERS_CLUB,
TYPE_REGEX_DISCOVER to CardType.DISCOVER,
TYPE_REGEX_JCB to CardType.JCB,
TYPE_REGEX_JCB15 to CardType.JCB15
)
for (regex in regexMap) {
if (cardNumber.cleanCardNumber().matches(regex.key.toRegex())) {
return regex.value
}
}
return CardType.UNKNOWN
}
}
}

0 comments on commit 419aac1

Please sign in to comment.