-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from mucahitkambur/master
Implement detect credit card type mechanism
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |