NAME

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

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
  );

DESCRIPTION

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

@CC_months

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

$scalar = CC_year

Returns the localtime calendar year.

$scalar = CC_expired(numeric_month,20xx)

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

$scalar = CC_is_zip(zipcode);

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

$scalar = CC_is_name(name);

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

$scalar = CC_is_addr(address);

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

$scalar = CC_clean(credit_card_number);

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

$scalar = CC_digits(credit_card_number);

Pre-process with CC_clean.

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

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

$scalar = CC_parity($credit_card_number);

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

$scalar = CC_luhn_valid($credit_card_number);

Performs a strict LUHN check on a credit card number, and returns true if the number has a valid check digit, false otherwise.

$scalar = CC_typGeneric(credit_card_number);

Returns a text string describing the type of credit card or 'false' if no indentification can be made. Checks if type is in '%enRoute' or '%CCprimary', similar to Card Types below.

Does NOT check the number of digits in the card number.

$scalar = CC_typDetail(credit_card_number);

Returns detailed description of card type as it appears in %CCsecondary, %CCprimary, %enRoute... or 'false' if the card number can not be identified.

$scalar = CC_format(credit_card_number);

Pre-process with CC_clean, CC_digits.

Returns the credit card number as a group of quadruples separated by spaces. The trailing (right hand) group will contain any remaining non-quad number set.

HOW IT WORKS

MOD10 Check Digit calculation

Credit Card Validation - Check Digits

This document outlines procedures and algorithms for Verifying the accuracy and validity of credit card numbers. Most credit card numbers are encoded with a "Check Digit". A check digit is a digit added to a number (either at the end or the beginning) that validates the authenticity of the number. A simple algorithm is applied to the other digits of the number which yields the check digit. By running the algorithm, and comparing the check digit you get from the algorithm with the check digit encoded with the credit card number, you can verify that you have correctly read all of the digits and that they make a valid combination.

Possible uses for this information:

When a user has keyed in a credit card number (or scanned it) 
and you want to validate it before sending it our for debit 
authorization. When issuing cards, say an affinity card, you 
might want to add a check digit using the MOD 10 method. 

LUHN Formula (Mod 10) for Validation of Primary Account Number

The following steps are required to validate the primary account number:

Step 1:

Double the value of alternate digits of the primary account number beginning with the second digit from the right (the first right--hand digit is the check digit.)

Step 2:

Add the individual digits comprising the products obtained in Step 1 to each of the unaffected digits in the original number.

Step 3:

The total obtained in Step 2 must be a number ending in zero (30, 40, 50, etc.) for the account number to be validated.

For example, to validate the primary account number 49927398716:

Step 1:
4 9 9 2 7 3 9 8 7 1 6
 x2  x2  x2  x2  x2 
------------------------------
 18   4   6  16   2
Step 2:
4 +(1+8)+ 9 + (4) + 7 + (6) + 9 +(1+6) + 7 + (2) + 6 
Step 3:
Sum = 70 : Card number is validated 

Note: Card is valid because the 70/10 yields no remainder.

The validation applied (last known date 3/96) is the so called LUHN Formula (Mod 10) for Validation of Primary Account Number Validation criteria are:

      1. number prefix
      2. number of digits
      3. mod10  (for all but enRoute which uses only 1 & 2)

 ... according to the following list of example criteria:

    Card Type		Prefix		 Length  Check-Digit Algoritm

	MC		51 - 55		   16	   mod 10

	VISA		4		 13, 16	   mod 10

	AMX		34, 37		   15	   mod 10

	Diners Club /	300-305, 36, 38	   14	   mod 10
	Carte Blanche

	Discover	6011		   16	   mod 10

	enRoute		2014, 2149	   16	   - any -

	JCB		3		   16	   mod 10
	JCB		2131, 1800	   15	   mod 10

COPYRIGHT AND LICENSE

Copyright 2001 - 2011, Michael Robinton <michael@bizsystems.com>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

AUTHOR

Michael Robinton, <michael@bizsystems.com>