Mage_Payment_Model_Method_Cc Class Reference

Inheritance diagram for Mage_Payment_Model_Method_Cc:

Mage_Payment_Model_Method_Abstract Varien_Object Mage_Paygate_Model_Authorizenet Mage_Paygate_Model_Payflow_Pro Mage_Payment_Model_Method_Ccsave Mage_Paypal_Model_Direct Mage_PaypalUk_Model_Direct

List of all members.

Public Member Functions

 assignData ($data)
 prepareSave ()
 validate ()
 hasVerification ()
 getVerificationRegEx ()
 OtherCcType ($type)
 validateCcNum ($ccNumber)
 validateCcNumOther ($ccNumber)

Protected Member Functions

 _validateExpDate ($expYear, $expMonth)

Protected Attributes

 $_formBlockType = 'payment/form_cc'
 $_infoBlockType = 'payment/info_cc'
 $_canSaveCc = false


Detailed Description

Definition at line 28 of file Cc.php.


Member Function Documentation

_validateExpDate ( expYear,
expMonth 
) [protected]

Definition at line 179 of file Cc.php.

00180     {
00181         $date = Mage::app()->getLocale()->date();
00182         if (!$expYear || !$expMonth || ($date->compareYear($expYear)==1) || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth)==1 )  )) {
00183             return false;
00184         }
00185         return true;
00186     }

assignData ( data  ) 

Assign data to info model instance

Parameters:
mixed $data
Returns:
Mage_Payment_Model_Info

Reimplemented from Mage_Payment_Model_Method_Abstract.

Reimplemented in Mage_PaypalUk_Model_Direct.

Definition at line 40 of file Cc.php.

00041     {
00042         if (!($data instanceof Varien_Object)) {
00043             $data = new Varien_Object($data);
00044         }
00045         $info = $this->getInfoInstance();
00046         $info->setCcType($data->getCcType())
00047             ->setCcOwner($data->getCcOwner())
00048             ->setCcLast4(substr($data->getCcNumber(), -4))
00049             ->setCcNumber($data->getCcNumber())
00050             ->setCcCid($data->getCcCid())
00051             ->setCcExpMonth($data->getCcExpMonth())
00052             ->setCcExpYear($data->getCcExpYear());
00053         return $this;
00054     }

getVerificationRegEx (  ) 

Definition at line 166 of file Cc.php.

00167     {
00168         $verificationExpList = array(
00169             'VI' => '/^[0-9]{3}$/', // Visa
00170             'MC' => '/^[0-9]{3}$/',       // Master Card
00171             'AE' => '/^[0-9]{4}$/',        // American Express
00172             'DI' => '/^[0-9]{3}$/',          // Discovery
00173             'SS' => '/^[0-9]{4}$/',
00174             'OT' => '/^[0-9]{3,4}$/'
00175         );
00176         return $verificationExpList;
00177     }

hasVerification (  ) 

Definition at line 157 of file Cc.php.

00158     {
00159         $configData = $this->getConfigData('useccv');
00160         if(is_null($configData)){
00161             return true;
00162         }
00163         return (bool) $configData;
00164     }

OtherCcType ( type  ) 

Reimplemented in Mage_PaypalUk_Model_Direct.

Definition at line 188 of file Cc.php.

00189     {
00190         return $type=='OT';
00191     }

prepareSave (  ) 

Prepare info instance for save

Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 61 of file Cc.php.

00062     {
00063         $info = $this->getInfoInstance();
00064         if ($this->_canSaveCc) {
00065             $info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
00066         }
00067         //$info->setCcCidEnc($info->encrypt($info->getCcCid()));
00068         $info->setCcNumber(null)
00069             ->setCcCid(null);
00070         return $this;
00071     }

validate (  ) 

Validate payment method information object

Parameters:
Mage_Payment_Model_Info $info
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 79 of file Cc.php.

00080     {
00081         /*
00082         * calling parent validate function
00083         */
00084         parent::validate();
00085 
00086         $info = $this->getInfoInstance();
00087         $errorMsg = false;
00088         $availableTypes = explode(',',$this->getConfigData('cctypes'));
00089 
00090         $ccNumber = $info->getCcNumber();
00091 
00092         // remove credit card number delimiters such as "-" and space
00093         $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
00094         $info->setCcNumber($ccNumber);
00095 
00096         $ccType = '';
00097 
00098         if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
00099             $errorCode = 'ccsave_expiration,ccsave_expiration_yr';
00100             $errorMsg = $this->_getHelper()->__('Incorrect credit card expiration date');
00101         }
00102 
00103         if (in_array($info->getCcType(), $availableTypes)){
00104             if ($this->validateCcNum($ccNumber)
00105                 // Other credit card type number validation
00106                 || ($this->OtherCcType($info->getCcType()) && $this->validateCcNumOther($ccNumber))) {
00107 
00108                 $ccType = 'OT';
00109                 $ccTypeRegExpList = array(
00110                     'VI' => '/^4[0-9]{12}([0-9]{3})?$/', // Visa
00111                     'MC' => '/^5[1-5][0-9]{14}$/',       // Master Card
00112                     'AE' => '/^3[47][0-9]{13}$/',        // American Express
00113                     'DI' => '/^6011[0-9]{12}$/',          // Discovery
00114                     'SS' => '/^((6759[0-9]{12})|(49[013][1356][0-9]{13})|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/'
00115                 );
00116 
00117                 foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
00118                     if (preg_match($ccTypeRegExp, $ccNumber)) {
00119                         $ccType = $ccTypeMatch;
00120                         break;
00121                     }
00122                 }
00123 
00124                 if (!$this->OtherCcType($info->getCcType()) && $ccType!=$info->getCcType()) {
00125                     $errorCode = 'ccsave_cc_type,ccsave_cc_number';
00126                     $errorMsg = $this->_getHelper()->__('Credit card number mismatch with credit card type');
00127                 }
00128             }
00129             else {
00130                 $errorCode = 'ccsave_cc_number';
00131                 $errorMsg = $this->_getHelper()->__('Invalid Credit Card Number');
00132             }
00133 
00134         }
00135         else {
00136             $errorCode = 'ccsave_cc_type';
00137             $errorMsg = $this->_getHelper()->__('Credit card type is not allowed for this payment method');
00138         }
00139 
00140                                 //validate credit card verification number
00141         if ($errorMsg === false && $this->hasVerification()) {
00142             $verifcationRegEx = $this->getVerificationRegEx();
00143             $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
00144             if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
00145                 $errorMsg = $this->_getHelper()->__('Please enter a valid credit card verification number.');
00146             }
00147         }                   
00148 
00149         if($errorMsg){
00150             Mage::throwException($errorMsg);
00151             //throw Mage::exception('Mage_Payment', $errorMsg, $errorCode);
00152         }
00153 
00154         return $this;
00155     }

validateCcNum ( ccNumber  ) 

Validate credit card number

Parameters:
string $cc_number
Returns:
bool

Double every second digit

Add digits of 2-digit numbers together

If the total has no remainder it's OK

Definition at line 199 of file Cc.php.

00200     {
00201         $cardNumber = strrev($ccNumber);
00202         $numSum = 0;
00203 
00204         for ($i=0; $i<strlen($cardNumber); $i++) {
00205             $currentNum = substr($cardNumber, $i, 1);
00206 
00207             /**
00208              * Double every second digit
00209              */
00210             if ($i % 2 == 1) {
00211                 $currentNum *= 2;
00212             }
00213 
00214             /**
00215              * Add digits of 2-digit numbers together
00216              */
00217             if ($currentNum > 9) {
00218                 $firstNum = $currentNum % 10;
00219                 $secondNum = ($currentNum - $firstNum) / 10;
00220                 $currentNum = $firstNum + $secondNum;
00221             }
00222 
00223             $numSum += $currentNum;
00224         }
00225 
00226         /**
00227          * If the total has no remainder it's OK
00228          */
00229         return ($numSum % 10 == 0);
00230     }

validateCcNumOther ( ccNumber  ) 

Other credit cart type number validation

Parameters:
string $ccNumber
Returns:
boolean

Definition at line 238 of file Cc.php.

00239     {
00240         return preg_match('/^\\d+$/', $ccNumber);
00241     }


Member Data Documentation

$_canSaveCc = false [protected]

$_formBlockType = 'payment/form_cc' [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Reimplemented in Mage_Payment_Model_Method_Ccsave, and Mage_PaypalUk_Model_Direct.

Definition at line 30 of file Cc.php.

$_infoBlockType = 'payment/info_cc' [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Reimplemented in Mage_Payment_Model_Method_Ccsave, and Mage_PaypalUk_Model_Direct.

Definition at line 31 of file Cc.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:32 2009 for Magento by  doxygen 1.5.8