00001 <?php
00002
00006 require_once oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "ccval/ccval.php";
00007
00012 class oxInputValidator
00013 {
00019 protected $_aRequiredCCFields = array( 'kktype',
00020 'kknumber',
00021 'kkmonth',
00022 'kkyear',
00023 'kkname',
00024 'kkpruef'
00025 );
00026
00032 protected $_aPossibleCCType = array( 'mcd',
00033 'vis',
00034 'amx',
00035 'dsc',
00036 'dnc',
00037 'jcb',
00038 'swi',
00039 'dlt',
00040 'enr'
00041 );
00042
00048 protected $_aRequiredDCFields = array( 'lsbankname',
00049 'lsblz',
00050 'lsktonr',
00051 'lsktoinhaber'
00052 );
00053
00063 public function validateBasketAmount( $dAmount )
00064 {
00065 $dAmount = str_replace( ',', '.', $dAmount );
00066
00067 if ( !is_numeric( $dAmount ) || $dAmount < 0) {
00068 $oEx = oxNew( 'oxArticleInputException' );
00069 $oEx->setMessage('EXCEPTION_INPUT_INVALIDAMOUNT');
00070 throw $oEx;
00071 }
00072
00073 if ( !oxConfig::getInstance()->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00074 $dAmount = round( ( string ) $dAmount );
00075 }
00076
00077
00078
00079
00080 return $dAmount;
00081 }
00082
00091 public function validatePaymentInputData( $sPaymentId, & $aDynvalue )
00092 {
00093 $blOK = true;
00094
00095 switch( $sPaymentId ) {
00096 case 'oxidcreditcard':
00097
00098 $blOK = false;
00099
00100 foreach ( $this->_aRequiredCCFields as $sFieldName ) {
00101 if ( !isset( $aDynvalue[$sFieldName] ) || !trim( $aDynvalue[$sFieldName] ) ) {
00102 break 2;
00103 }
00104 }
00105
00106 if ( in_array( $aDynvalue['kktype'], $this->_aPossibleCCType ) ) {
00107 $sType = $aDynvalue['kktype'];
00108 } else {
00109 $sType = null;
00110 break;
00111 }
00112
00113 $blResult = ccval( $aDynvalue['kknumber'], $sType, $aDynvalue['kkmonth'].substr( $aDynvalue['kkyear'], 2, 2 ) );
00114 if ( $blResult ) {
00115 $blOK = true;
00116 }
00117
00118 break;
00119
00120 case "oxiddebitnote":
00121
00122 $blOK = false;
00123
00124 foreach ( $this->_aRequiredDCFields as $sFieldName ) {
00125 if ( !isset( $aDynvalue[$sFieldName] ) || !trim( $aDynvalue[$sFieldName] ) ) {
00126 break 2;
00127 }
00128 }
00129
00130
00131 $aDynvalue['lsblz'] = str_replace( ' ', '', $aDynvalue['lsblz'] );
00132 $aDynvalue['lsktonr'] = str_replace( ' ', '', $aDynvalue['lsktonr'] );
00133
00134
00135 if ( strlen( $aDynvalue['lsktonr'] ) < 10 ) {
00136 $sNewNum = str_repeat( '0', 10 - strlen( $aDynvalue['lsktonr'] ) ).$aDynvalue['lsktonr'];
00137 $aDynvalue['lsktonr'] = $sNewNum;
00138 }
00139
00140 if ( preg_match( "/\d{8}/", $aDynvalue['lsblz'] ) && preg_match( "/\d{10}/", $aDynvalue['lsktonr'] ) ) {
00141 $blOK = true;
00142 }
00143 break;
00144 }
00145
00146 return $blOK;
00147 }
00148 }