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 
00058     public function __get( $sName )
00059     {
00060         //due to compatibility with templates
00061         if ( $sName == 'oxpayments__oxdesc' ) {
00062             if ( $this->_oPayment === null ) {
00063                 $this->_oPayment = oxNew( 'oxpayment' );
00064                 $this->_oPayment->load( $this->oxuserpayments__oxpaymentsid->value );
00065             }
00066             return $this->_oPayment->oxpayments__oxdesc;
00067         }
00068 
00069         if ( $sName == 'aDynValues' ) {
00070             if ( $this->_aDynValues === null ) {
00071                 $this->_aDynValues = $this->getDynValues();
00072             }
00073             return $this->_aDynValues;
00074         }
00075 
00076         return parent::__get( $sName );
00077     }
00078 
00082     public function __construct()
00083     {
00084         parent::__construct();
00085         $this->init( 'oxuserpayments' );
00086         $this->_sPaymentKey = oxUtils::getInstance()->strRot13( $this->_sPaymentKey );
00087         $this->setStoreCreditCardInfo( $this->getConfig()->getConfigParam( 'blStoreCreditCardInfo' ) );
00088     }
00089 
00095     public function getPaymentKey()
00096     {
00097         return $this->_sPaymentKey;
00098     }
00099 
00107     public function load( $sOxId )
00108     {
00109         $sSelect = 'select oxid, oxuserid, oxpaymentsid, DECODE( oxvalue, "'.$this->getPaymentKey().'" ) as oxvalue
00110                     from oxuserpayments where oxid = '. oxDb::getDb()->quote( $sOxId );
00111 
00112         return $this->assignRecord( $sSelect );
00113     }
00114 
00115 
00121     protected function _insert()
00122     {
00123         // we do not store credit card information
00124         // check and in case skip it
00125         if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00126             return true;
00127         }
00128 
00129         //encode sensitive data
00130         if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00131             $oDb = oxDb::getDb();
00132             $sEncodedValue = $oDb->getOne( "select encode( " . $oDb->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )", false, false);
00133             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00134         }
00135 
00136         $blRet = parent::_insert();
00137 
00138         //restore, as encoding was needed only for saving
00139         if ( $sEncodedValue ) {
00140             $this->oxuserpayments__oxvalue->setValue($sValue);
00141         }
00142 
00143         return $blRet;
00144     }
00145 
00151     protected function _update()
00152     {
00153         $oDb = oxDb::getDb();
00154 
00155         //encode sensitive data
00156         if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00157             $sEncodedValue = $oDb->getOne( "select encode( " . $oDb->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )", false, false);
00158             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00159         }
00160 
00161         $blRet = parent::_update();
00162 
00163         //restore, as encoding was needed only for saving
00164         if ( $sEncodedValue ) {
00165             $this->oxuserpayments__oxvalue->setValue($sValue);
00166         }
00167 
00168         return $blRet;
00169     }
00170 
00178     public function setStoreCreditCardInfo( $blStoreCreditCardInfo )
00179     {
00180         $this->_blStoreCreditCardInfo = $blStoreCreditCardInfo;
00181     }
00182 
00188     public function getStoreCreditCardInfo()
00189     {
00190         return $this->_blStoreCreditCardInfo;
00191     }
00192 
00201     public function getPaymentByPaymentType( $oUser = null, $sPaymentType = null )
00202     {
00203         $blGet = false;
00204         if ( $oUser && $sPaymentType != null ) {
00205             $oDb = oxDb::getDb();
00206             $sQ  = 'select oxpaymentid from oxorder where oxpaymenttype=' . $oDb->quote( $sPaymentType ) . ' and
00207                     oxuserid=' . $oDb->quote( $oUser->getId() ).' order by oxorderdate desc';
00208             if ( ( $sOxId = $oDb->getOne( $sQ ) ) ) {
00209                 $blGet = $this->load( $sOxId );
00210             }
00211         }
00212 
00213         return $blGet;
00214     }
00215 
00221     public function getDynValues()
00222     {
00223         if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00224             return null;
00225         }
00226 
00227         if ( !$this->_aDynValues ) {
00228 
00229             $sRawDynValue = null;
00230             if ( is_object($this->oxuserpayments__oxvalue) ) {
00231                 $sRawDynValue = $this->oxuserpayments__oxvalue->getRawValue();
00232             }
00233 
00234             $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $sRawDynValue );
00235         }
00236         return $this->_aDynValues;
00237     }
00238 
00246     public function setDynValues( $aDynValues )
00247     {
00248         $this->_aDynValues = $aDynValues;
00249     }
00250 
00251 }