Business-CCCheck

 view release on metacpan or  search on metacpan

lib/Business/CCCheck.pm  view on Meta::CPAN

  my ($ccn) = @_;
  return '' unless $ccn;

  # no parity check for enRoute
  return 1 if _is_enRoute($ccn);

  return CC_luhn_valid($ccn);
}

sub CC_luhn_valid
{
    my $ccn = shift;
    my @ccn = split('', $ccn);
    my $even = 0;

    $ccn = 0;
    for (my $i=$#ccn; $i >=0; --$i) {
        $ccn[$i] *= 2 if $even;
        $ccn -= 9 if $ccn[$i] > 9;
        $ccn += $ccn[$i];
        $even = ! $even;
    }
    return ($ccn % 10) == 0;
}

=head1 NAME

Business::CCCheck - collection of functions for checking credit card numbers

=head1 SYNOPSIS

  use Business::CCCheck qw(
	@CC_months
	CC_year
	CC_expired
	CC_is_zip
	CC_is_name
	CC_is_addr
	CC_clean
	CC_digits
	CC_oldtype
	CC_parity
	CC_typGeneric
	CC_typDetail
	CC_format
  );

=head1 DESCRIPTION

This module checks the validity of the numbers and dates for a credit card
entry, including the parity of the CC number itself.

=over 2

=item @CC_months

An array of 3 character text months. i.e. Jan, Feb....

=item $scalar = CC_year

Returns the localtime calendar year.

=item $scalar = CC_expired(numeric_month,20xx)

Returns true if card is expired or 
month year has bad fromat else false

=item $scalar = CC_is_zip(zipcode);

Check for valid zip code, returns B<false> or the B<zipcode>.

=item $scalar = CC_is_name(name);

Check for a name string greater than three characters.
Return B<false> if short, otherwise return the B<name>.

=item $scalar = CC_is_addr(address);

Check for a string containing at least 3 words and one endline.
Return B<false> if short, otherwise return the B<address>.

=item $scalar = CC_clean(credit_card_number);

Remove blanks and dashes, verify numeric content. Returns B<false> if
invalid characters are present, otherwise the cleaned credit card number.

=item $scalar = CC_digits(credit_card_number);

Pre-process with CC_clean.  

Returns B<false> if the card number fails the check digit match (except for
enRoute which does not require a check digit) otherwise returns exact text
identifying the card issuer that is one of:

    MasterCard
    VISA
    AmericanExpress
    DinersClub/Carteblanche
    Discover
    enRoute
    JCB

Checks number of digits in card number.

=item $scalar = CC_oldtype($credit_card_number);

Performs the number -> name conversion for CC_digits and checks number of
digits in card number.

returns false if it can not convert.

=item $scalar = CC_parity($credit_card_number);

Performs a credit card number parity check for CC_digits.
This is the same as C<CC_luhn_valid()>, apart from for 'enRoute' cards,
which do not have a check digit. For 'enRoute' cards C<CC_parity()>
always returns true.

=item $scalar = CC_luhn_valid($credit_card_number);

Performs a strict LUHN check on a credit card number,



( run in 0.588 second using v1.01-cache-2.11-cpan-39bf76dae61 )