oxuserpayment.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxUserPayment extends oxBase
00009 {
00010 
00011     // you can change this if you want more security
00012     // DO NOT !! CHANGE THIS FILE AND STORE CREDIT CARD INFORMATION
00013     // THIS IS MORE THAN LIKELY ILLEGAL !!
00014     // CHECK YOUR CREDIT CARD CONTRACT
00015 
00021     protected $_sPaymentKey = 'fq45QS09_fqyx09239QQ';
00022 
00028     protected $_sClassName = 'oxuserpayment';
00029 
00035     protected $_blStoreCreditCardInfo = null;
00036 
00042     protected $_oPayment = null;
00043 
00049     protected $_aDynValues = null;
00050 
00056     protected $_aSkipSaveFields = array( "oxid" );
00057 
00065     public function __get( $sName )
00066     {
00067         //due to compatibility with templates
00068         if ( $sName == 'oxpayments__oxdesc' ) {
00069             if ( $this->_oPayment === null ) {
00070                 $this->_oPayment = oxNew( 'oxpayment' );
00071                 $this->_oPayment->load( $this->oxuserpayments__oxpaymentsid->value );
00072             }
00073             return $this->_oPayment->oxpayments__oxdesc;
00074         }
00075 
00076         if ( $sName == 'aDynValues' ) {
00077             if ( $this->_aDynValues === null ) {
00078                 $this->_aDynValues = $this->getDynValues();
00079             }
00080             return $this->_aDynValues;
00081         }
00082 
00083         return parent::__get( $sName );
00084     }
00085 
00089     public function __construct()
00090     {
00091         parent::__construct();
00092         $this->init( 'oxuserpayments' );
00093         $this->_sPaymentKey = oxUtils::getInstance()->strRot13( $this->_sPaymentKey );
00094         $this->setStoreCreditCardInfo( $this->getConfig()->getConfigParam( 'blStoreCreditCardInfo' ) );
00095     }
00096 
00102     public function getPaymentKey()
00103     {
00104         return $this->_sPaymentKey;
00105     }
00106 
00114     public function load( $sOxId )
00115     {
00116         $sSelect = 'select oxid, oxuserid, oxpaymentsid, DECODE( oxvalue, "'.$this->getPaymentKey().'" ) as oxvalue
00117                     from oxuserpayments where oxid = '. oxDb::getDb()->quote( $sOxId );
00118 
00119         return $this->assignRecord( $sSelect );
00120     }
00121 
00122 
00128     protected function _insert()
00129     {
00130         // we do not store credit card information
00131         // check and in case skip it
00132         if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00133             return true;
00134         }
00135 
00136         //encode sensitive data
00137         if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00138             $sEncodedValue = oxDb::getDb()->getOne( "select encode( " . oxDb::getDb()->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )" );
00139             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00140         }
00141 
00142         $blRet = parent::_insert();
00143 
00144         //restore, as encoding was needed only for saving
00145         if ( $sEncodedValue ) {
00146             $this->oxuserpayments__oxvalue->setValue( $sValue );
00147         }
00148 
00149         return $blRet;
00150     }
00151 
00157     protected function _update()
00158     {
00159         //encode sensitive data
00160         if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00161             $sEncodedValue = oxDb::getDb()->getOne( "select encode( " . oxDb::getDb()->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )" );
00162             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00163         }
00164 
00165         // replace (not update) existing record
00166         //do not allow derived item update
00167         if ( !$this->allowDerivedUpdate() ) {
00168             return false;
00169         }
00170 
00171 
00172         $oDb = oxDB::getDb();
00173         $sUpdate =  "update {$this->_sCoreTable} set ".$this->_getUpdateFields()
00174                   . " where {$this->_sCoreTable}.oxuserid = " . $oDb->quote( $this->oxuserpayments__oxuserid->value )
00175                   . " and oxpaymentsid = " . $oDb->quote( $this->oxuserpayments__oxpaymentsid->value )
00176                   . " limit 1";
00177 
00178         //trigger event
00179         $this->beforeUpdate();
00180 
00181         $blRet = (bool) $oDb->execute( $sUpdate );
00182         $this->_rebuildCache();
00183 
00184         //restore, as encoding was needed only for saving
00185         if ( $sEncodedValue ) {
00186             $this->oxuserpayments__oxvalue->setValue( $sValue );
00187         }
00188 
00189         return $blRet;
00190     }
00191 
00199     public function exists( $sOXID = null )
00200     {
00201         if ( !$this->oxuserpayments__oxpaymentsid->value || !$this->oxuserpayments__oxuserid->value ) {
00202             return false;
00203         }
00204 
00205         // generating new id..
00206         if ( !$this->getId() ) {
00207             $this->setId();
00208         }
00209 
00210         $oDB = oxDb::getDb( true );
00211         $sSelect  = "select 1 from oxuserpayments where oxuserid = " . $oDB->quote( $this->oxuserpayments__oxuserid->value );
00212         $sSelect .= " and oxpaymentsid = " . $oDB->quote( $this->oxuserpayments__oxpaymentsid->value );
00213 
00214         return ( bool ) $oDB->getOne( $sSelect );
00215     }
00216 
00224     public function delete( $sOXID = null)
00225     {
00226         if ( !$sOXID ) {
00227             $sOXID = $this->getId();
00228 
00229             //do not allow derived deletion
00230             if ( !$this->allowDerivedDelete() ) {
00231                 return false;
00232             }
00233         }
00234 
00235         if ( !$sOXID || !$this->oxuserpayments__oxpaymentsid->value || !$this->oxuserpayments__oxuserid->value  ) {
00236             return false;
00237         }
00238 
00239 
00240         $oDB = oxDb::getDb(true);
00241         $sDelete  = "delete from $this->_sCoreTable where oxuserid = " . $oDB->quote( $this->oxuserpayments__oxuserid->value );
00242         $sSelect .= " and oxpaymentsid = " . $oDB->quote( $this->oxuserpayments__oxpaymentsid->value );
00243 
00244         $rs = $oDB->execute( $sDelete );
00245         if ( $blDelete = ( bool ) $oDB->affected_Rows() ) {
00246             $this->onChange(ACTION_DELETE, $sOXID);
00247         }
00248 
00249         return $blDelete;
00250     }
00251 
00259     public function setStoreCreditCardInfo( $blStoreCreditCardInfo )
00260     {
00261         $this->_blStoreCreditCardInfo = $blStoreCreditCardInfo;
00262     }
00263 
00269     public function getStoreCreditCardInfo()
00270     {
00271         return $this->_blStoreCreditCardInfo;
00272     }
00273 
00282     public function getPaymentByPaymentType( $oUser = null, $sPaymentType = null )
00283     {
00284         $blGet = false;
00285         if ( $oUser && $sPaymentType != null ) {
00286             $sSelect  = 'select oxid from oxuserpayments where oxpaymentsid=' . oxDb::getDb()->quote( $sPaymentType ) . ' and oxuserid="' . $oUser->getId() . '" ';
00287             if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00288                 $blGet = $this->load( $sOxId );
00289             }
00290         }
00291 
00292         return $blGet;
00293     }
00294 
00300     public function getDynValues()
00301     {
00302         if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00303             return null;
00304         }
00305 
00306         if ( !$this->_aDynValues ) {
00307 
00308             $sRawDynValue = null;
00309             if ( is_object($this->oxuserpayments__oxvalue) ) {
00310                 $sRawDynValue = $this->oxuserpayments__oxvalue->getRawValue();
00311             }
00312 
00313             $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $sRawDynValue );
00314         }
00315         return $this->_aDynValues;
00316     }
00317 
00325     public function setDynValues( $aDynValues )
00326     {
00327         $this->_aDynValues = $aDynValues;
00328     }
00329 
00330 }