credit_card_type_detector | credit card type detector
a dart package that detects credit card types based on the current credit card number patterns.
this is a port from braintree’s credit-card-type module
installing
- add dependency to your
pubspec.yaml
get the current version in the ‘installing’ tab on pub.dartlang.org
dependencies:
credit_card_type_detector: ^1.0.2
- import the package
import 'package:credit_card_type_detector/credit_card_type_detector.dart';
usage
import 'package:credit_card_type_detector/credit_card_type_detector.dart';
string visa = "4647 7200 6779 1032";
var type = detectcctype(visa);
assert(type == creditcardtype.visa)
check out the example app in the example directory or the ‘example’ tab on pub.dartlang.org for a more complete example using the bloc pattern
features
no external dependencies
supported cards:
* visa
* mastercard
* american express
* discover
* diners club
* jcb
* union pay
* maestro
* mir
* elo
* hiper/hipercard
pattern detection
each card type has a corresponding list of patterns. see the cardnumpatterns
map.
each pattern is an array of strings that represents a range of numbers or a single number. these numbers correspond to the issuer identification number (iin) for the credit card company.
if the pattern is an array with a single number, the package compares it against the card number. partial matches for card numbers that are shorter than the pattern also match. i.e. given the pattern 123
, then the card numbers 1
, 12
, 123
, 1234
will all match, but 2
, 13
, and 124
will not.
if the pattern is an array of numbers, then the card number is checked to be within the range of those numbers. again, partial matches are accepted. i.e. given the range [100, 123]
, then the card numbers 1
, 10
, 100
, 12
, 120
, 123
will all match, but 2
, 13
, and 124
will not.
the package loops over every card type and everyone of its corresponding patterns.
api
detectcctype(string number)
returns: a
creditcardtype
enum.
i.e. creditcardtype.visa
for any card number that starts with ‘4’.
author
tanner davis (cholojuanito) – creator and repo owner – github profile
Comments are closed.