Class CCValidator

Description

Credit card validation class

This class implements Mod 10 algorithm to validate a credit card number. It also checks if a credit card number prefix and an exparation date are correct.

Example of usage:

  1.  $ccv new CCValidator(
  2.      'JOHN JOHNSON'CCV_AMERICAN_EXPRESS'378282246310005'32007);
  3.  if ($validCard $ccv->validate()) {
  4.      if ($validCard CCV_RES_ERR_HOLDER{
  5.          echo 'Card holder\'s name is missing or incorrect.<br />';
  6.      }
  7.      if ($validCard CCV_RES_ERR_TYPE{
  8.          echo 'Incorrect credit card type.<br />';
  9.      }
  10.      if ($validCard CCV_RES_ERR_DATE{
  11.          echo 'Incorrect expiration date.<br />';
  12.      }
  13.      if ($validCard CCV_RES_ERR_FORMAT{
  14.          echo 'Incorrect credit card number format.<br />';
  15.      }
  16.      if ($validCard CCV_RES_ERR_NUMBER{
  17.          echo 'Invalid credit card number.<br />';
  18.      }
  19.  else {
  20.      echo 'Credit card information is valid.<br />';
  21.  }



			
Variable Summary
Method Summary
CCValidator CCValidator (string $cardHolder, int $cardType, string $cardNumber, int $cardExpiredMonth, int $cardExpiredYear)
int validate ()
Variables
int $cardExpiredMonth = 0 (line 155)

Credit card expiration month

1-12 or 0 if not set. Read only. Use constructor to set the value.

  • access: public
int $cardExpiredYear = 0 (line 165)

Credit card expiration year

YYYY or 0 if not set. Read only. Use constructor to set the value.

  • access: public
string $cardHolder = '' (line 123)

Credit card holder's name

Read only. Use constructor to set the value.

  • access: public
string $cardNumber = '' (line 145)

Credit card number

Read only. Use constructor to set the value.

  • access: public
int $cardType = -1 (line 135)

Credit card type

CCV_MASTER_CARD - 0, CCV_VISA - 1, CCV_AMERICAN_EXPRESS - 2, CCV_DINERS_CLUB - 3, CCV_DISCOVER - 4, CCV_JCB - 5 or -1 if no card. Read only. Use constructor to set the value.

  • access: public
Methods
Constructor CCValidator (line 181)

Constructor

  • access: public
CCValidator CCValidator (string $cardHolder, int $cardType, string $cardNumber, int $cardExpiredMonth, int $cardExpiredYear)
  • string $cardHolder: Credit card holder's name.
  • int $cardType: Credit card type. CCV_MASTER_CARD - 0, CCV_VISA - 1, CCV_AMERICAN_EXPRESS - 2, CCV_DINERS_CLUB - 3, CCV_DISCOVER - 4, CCV_JCB - 5.
  • string $cardNumber: Credit card number
  • int $cardExpiredMonth: Credit card expiration month. 1-12.
  • int $cardExpiredYear: Credit card expiration year in YYYY format.
validate (line 203)

Validate credit card information

  • return: Validation result as a bitwise combination of following numbers: CCV_RES_VALID - credit card information is valid; CCV_RES_ERR_HOLDER - card holder's name is missing or incorrect; CCV_RES_ERR_TYPE - incorrect credit card type; CCV_RES_ERR_DATE - incorrect expiration date; CCV_RES_ERR_FORMAT - incorrect credit card number format; CCV_RES_ERR_NUMBER - invalid credit card number.
  • access: public
int validate ()

Documentation generated by phpDocumentor