oxinputvalidator.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxInputValidator
00008 {
00014     protected $_aRequiredCCFields = array( 'kktype',
00015                                            'kknumber',
00016                                            'kkmonth',
00017                                            'kkyear',
00018                                            'kkname',
00019                                            'kkpruef'
00020                                           );
00021 
00027     protected $_aPossibleCCType = array( 'mcd', // Master Card
00028                                          'vis', // Visa
00029                                          'amx', // American Express
00030                                          'dsc', // Discover
00031                                          'dnc', // Diners Club
00032                                          'jcb', // JCB
00033                                          'swi', // Switch
00034                                          'dlt', // Delta
00035                                          'enr'  // EnRoute
00036                                         );
00037 
00043     protected $_aRequiredDCFields = array( 'lsbankname',
00044                                            'lsblz',
00045                                            'lsktonr',
00046                                            'lsktoinhaber'
00047                                          );
00048 
00054     public function __construct()
00055     {
00056     }
00057 
00067     public function validateBasketAmount( $dAmount )
00068     {
00069         $dAmount = str_replace( ',', '.', $dAmount );
00070 
00071         if ( !is_numeric( $dAmount ) || $dAmount < 0) {
00072             $oEx = oxNew( 'oxArticleInputException' );
00073             $oEx->setMessage('EXCEPTION_INPUT_INVALIDAMOUNT');
00074             throw $oEx;
00075         }
00076 
00077         if ( !oxConfig::getInstance()->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00078             $dAmount = round( ( string ) $dAmount );
00079         }
00080 
00081         //negative amounts are not allowed
00082         //$dAmount = abs($dAmount);
00083 
00084         return $dAmount;
00085     }
00086 
00095     public function validatePaymentInputData( $sPaymentId, & $aDynvalue )
00096     {
00097         $blOK = true;
00098 
00099         switch( $sPaymentId ) {
00100             case 'oxidcreditcard':
00101 
00102                 $blOK = false;
00103 
00104                 foreach ( $this->_aRequiredCCFields as $sFieldName ) {
00105                     if ( !isset( $aDynvalue[$sFieldName] ) || !trim( $aDynvalue[$sFieldName] ) ) {
00106                         break 2;
00107                     }
00108                 }
00109 
00110                 if ( in_array( $aDynvalue['kktype'], $this->_aPossibleCCType ) ) {
00111                     $sType = $aDynvalue['kktype'];
00112                 } else {
00113                     $sType = null;
00114                     break;
00115                 }
00116 
00117                 $oCardValidator = oxNew( "oxccvalidator" );
00118                 $blResult = $oCardValidator->isValidCard( $aDynvalue['kknumber'], $sType, $aDynvalue['kkmonth'].substr( $aDynvalue['kkyear'], 2, 2 ) );
00119                 if ( $blResult ) {
00120                     $blOK = true;
00121                 }
00122 
00123                 break;
00124 
00125             case "oxiddebitnote":
00126 
00127                 $blOK = false;
00128                 $oStr = getStr();
00129 
00130                 foreach ( $this->_aRequiredDCFields as $sFieldName ) {
00131                     if ( !isset( $aDynvalue[$sFieldName] ) || !trim( $aDynvalue[$sFieldName] ) ) {
00132                         break 2;
00133                     }
00134                 }
00135 
00136                 // cleaning up spaces
00137                 $aDynvalue['lsblz']   = str_replace( ' ', '', $aDynvalue['lsblz'] );
00138                 $aDynvalue['lsktonr'] = str_replace( ' ', '', $aDynvalue['lsktonr'] );
00139 
00140                 //if konto number is shorter than 10, add zeros in front of number
00141                 if ( $oStr->strlen( $aDynvalue['lsktonr'] ) < 10 ) {
00142                     $sNewNum = str_repeat( '0', 10 - $oStr->strlen( $aDynvalue['lsktonr'] ) ).$aDynvalue['lsktonr'];
00143                     $aDynvalue['lsktonr'] = $sNewNum;
00144                 }
00145 
00146                 if ( $oStr->preg_match( "/^\d{5,8}$/", $aDynvalue['lsblz'] ) && $oStr->preg_match( "/\d{10}/", $aDynvalue['lsktonr'] ) ) {
00147                     $blOK = true;
00148                 }
00149                 break;
00150         }
00151 
00152         return $blOK;
00153     }
00154 }