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             $sEncodedValue = oxDb::getDb()->getOne( "select encode( " . oxDb::getDb()->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )" );
00132             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00133         }
00134 
00135         $blRet = parent::_insert();
00136 
00137         //restore, as encoding was needed only for saving
00138         if ( $sEncodedValue ) {
00139             $this->oxuserpayments__oxvalue->setValue($sValue);
00140         }
00141 
00142         return $blRet;
00143     }
00144 
00150     protected function _update()
00151     {
00152         //encode sensitive data
00153         if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00154             $sEncodedValue = oxDb::getDb()->getOne( "select encode( " . oxDb::getDb()->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )" );
00155             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00156         }
00157 
00158         $blRet = parent::_update();
00159 
00160         //restore, as encoding was needed only for saving
00161         if ( $sEncodedValue ) {
00162             $this->oxuserpayments__oxvalue->setValue($sValue);
00163         }
00164 
00165         return $blRet;
00166     }
00167 
00175     public function setStoreCreditCardInfo( $blStoreCreditCardInfo )
00176     {
00177         $this->_blStoreCreditCardInfo = $blStoreCreditCardInfo;
00178     }
00179 
00185     public function getStoreCreditCardInfo()
00186     {
00187         return $this->_blStoreCreditCardInfo;
00188     }
00189 
00198     public function getPaymentByPaymentType( $oUser = null, $sPaymentType = null )
00199     {
00200         $blGet = false;
00201         if ( $oUser && $sPaymentType != null ) {
00202             $sSelect  = 'select oxid from oxuserpayments where oxpaymentsid=' . oxDb::getDb()->quote( $sPaymentType ) . ' and oxuserid="' . $oUser->getId() . '" ';
00203             if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00204                 $blGet = $this->load( $sOxId );
00205             }
00206         }
00207 
00208         return $blGet;
00209     }
00210 
00216     public function getDynValues()
00217     {
00218         if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00219             return null;
00220         }
00221 
00222         if ( !$this->_aDynValues ) {
00223 
00224             $sRawDynValue = null;
00225             if ( is_object($this->oxuserpayments__oxvalue) ) {
00226                 $sRawDynValue = $this->oxuserpayments__oxvalue->getRawValue();
00227             }
00228 
00229             $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $sRawDynValue );
00230         }
00231         return $this->_aDynValues;
00232     }
00233 
00241     public function setDynValues( $aDynValues )
00242     {
00243         $this->_aDynValues = $aDynValues;
00244     }
00245 
00246 }