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
00059 public function __construct()
00060 {
00061 }
00062
00072 public function validateBasketAmount( $dAmount )
00073 {
00074 $dAmount = str_replace( ',', '.', $dAmount );
00075
00076 if ( !is_numeric( $dAmount ) || $dAmount < 0) {
00077 $oEx = oxNew( 'oxArticleInputException' );
00078 $oEx->setMessage('EXCEPTION_INPUT_INVALIDAMOUNT');
00079 throw $oEx;
00080 }
00081
00082 if ( !oxConfig::getInstance()->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00083 $dAmount = round( ( string ) $dAmount );
00084 }
00085
00086
00087
00088
00089 return $dAmount;
00090 }
00091
00100 public function validatePaymentInputData( $sPaymentId, & $aDynvalue )
00101 {
00102 $blOK = true;
00103
00104 switch( $sPaymentId ) {
00105 case 'oxidcreditcard':
00106
00107 $blOK = false;
00108
00109 foreach ( $this->_aRequiredCCFields as $sFieldName ) {
00110 if ( !isset( $aDynvalue[$sFieldName] ) || !trim( $aDynvalue[$sFieldName] ) ) {
00111 break 2;
00112 }
00113 }
00114
00115 if ( in_array( $aDynvalue['kktype'], $this->_aPossibleCCType ) ) {
00116 $sType = $aDynvalue['kktype'];
00117 } else {
00118 $sType = null;
00119 break;
00120 }
00121
00122 $blResult = ccval( $aDynvalue['kknumber'], $sType, $aDynvalue['kkmonth'].substr( $aDynvalue['kkyear'], 2, 2 ) );
00123 if ( $blResult ) {
00124 $blOK = true;
00125 }
00126
00127 break;
00128
00129 case "oxiddebitnote":
00130
00131 $blOK = false;
00132
00133 foreach ( $this->_aRequiredDCFields as $sFieldName ) {
00134 if ( !isset( $aDynvalue[$sFieldName] ) || !trim( $aDynvalue[$sFieldName] ) ) {
00135 break 2;
00136 }
00137 }
00138
00139
00140 $aDynvalue['lsblz'] = str_replace( ' ', '', $aDynvalue['lsblz'] );
00141 $aDynvalue['lsktonr'] = str_replace( ' ', '', $aDynvalue['lsktonr'] );
00142
00143
00144 if ( strlen( $aDynvalue['lsktonr'] ) < 10 ) {
00145 $sNewNum = str_repeat( '0', 10 - strlen( $aDynvalue['lsktonr'] ) ).$aDynvalue['lsktonr'];
00146 $aDynvalue['lsktonr'] = $sNewNum;
00147 }
00148
00149 if ( preg_match( "/^\d{5,8}$/", $aDynvalue['lsblz'] ) && preg_match( "/\d{10}/", $aDynvalue['lsktonr'] ) ) {
00150 $blOK = true;
00151 }
00152 break;
00153 }
00154
00155 return $blOK;
00156 }
00157 }