getCardIssuer method
Implementation
CardIssuer getCardIssuer(String cardNumber) {
cardNumber = cardNumber.replaceAll(' ', '');
var issuerMap = <RegExp, CardIssuer>{
mastercard: CardIssuer.mastercard,
visa: CardIssuer.visa,
amex: CardIssuer.amex,
bCGlobal: CardIssuer.bCGlobal,
carteBlanc: CardIssuer.carteBlanche,
dinersClub: CardIssuer.dinersClub,
discover: CardIssuer.discover,
instaPayment: CardIssuer.instaPayment,
jCB: CardIssuer.jcb,
koreanLocalCard: CardIssuer.koreanLocal,
maestro: CardIssuer.maestro,
solo: CardIssuer.solo,
unionPay: CardIssuer.unionPay,
unknown: CardIssuer.unknown
};
var matchingRegex = <RegExp>[
mastercard,
visa,
amex,
dinersClub,
maestro,
jCB,
discover,
bCGlobal,
carteBlanc,
instaPayment,
solo,
unionPay,
koreanLocalCard,
unknown,
].firstWhere((element) => element.hasMatch(cardNumber));
return issuerMap[matchingRegex]!;
}