Credit Card Type Detector in Flutter

You are currently viewing Credit Card Type Detector in Flutter
Credit Card Type Detector

Credit Card Type Detector in Flutter

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

Credit Card Type Detector
Credit Card Type Detector

Installing

  1. Add dependency to your pubspec.yaml
    1. Get the current version in the ‘Installing’ tab on pub.dartlang.org
dependencies:
    credit_card_type_detector: ^1.0.2

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

See also  Simple Card View with List View Builder using Flutter

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 1121231234 will all match, but 213, and 124 will not.

See also  Custom Time Interval Picker in Flutter

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 11010012120123 will all match, but 213, and 124 will not.

See also  Flutter vs React Native - What to choose in 2022?

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’.

Related Repos

Credit

This is developed by cholojuanito
Download this project from the below link.
https://github.com/cholojuanito/credit_card_type_detector/archive/refs/heads/master.zip
You can visit original source page from the below link:
https://github.com/cholojuanito/credit_card_type_detector

Spread the love

Leave a Reply