oxuserpayment.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class oxUserPayment extends oxBase
00010 {
00011 
00012     // you can change this if you want more security
00013     // DO NOT !! CHANGE THIS FILE AND STORE CREDIT CARD INFORMATION
00014     // THIS IS MORE THAN LIKELY ILLEGAL !!
00015     // CHECK YOUR CREDIT CARD CONTRACT
00016 
00022     protected $_sPaymentKey = 'fq45QS09_fqyx09239QQ';
00023 
00029     protected $_sClassName = 'oxuserpayment';
00030 
00036     protected $_blStoreCreditCardInfo = null;
00037 
00043     protected $_oPayment = null;
00044 
00050     protected $_aDynValues = null;
00051 
00059     public function __get( $sName )
00060     {
00061         //due to compatibility with templates
00062         if ( $sName == 'oxpayments__oxdesc' ) {
00063             if ( $this->_oPayment === null ) {
00064                 $this->_oPayment = oxNew( 'oxpayment' );
00065                 $this->_oPayment->load( $this->oxuserpayments__oxpaymentsid->value );
00066             }
00067             return $this->_oPayment->oxpayments__oxdesc;
00068         }
00069 
00070         if ( $sName == 'aDynValues' ) {
00071             if ( $this->_aDynValues === null ) {
00072                 $this->_aDynValues = $this->getDynValues();
00073             }
00074             return $this->_aDynValues;
00075         }
00076 
00077         return parent::__get( $sName );
00078     }
00079 
00083     public function __construct()
00084     {
00085         parent::__construct();
00086         $this->init( 'oxuserpayments' );
00087         $this->_sPaymentKey = oxRegistry::getUtils()->strRot13( $this->_sPaymentKey );
00088         $this->setStoreCreditCardInfo( $this->getConfig()->getConfigParam( 'blStoreCreditCardInfo' ) );
00089     }
00090 
00096     public function getPaymentKey()
00097     {
00098         return $this->_sPaymentKey;
00099     }
00100 
00108     public function load( $sOxId )
00109     {
00110         $sSelect = 'select oxid, oxuserid, oxpaymentsid, DECODE( oxvalue, "'.$this->getPaymentKey().'" ) as oxvalue
00111                     from oxuserpayments where oxid = '. oxDb::getDb()->quote( $sOxId );
00112 
00113         return $this->assignRecord( $sSelect );
00114     }
00115 
00116 
00122     protected function _insert()
00123     {
00124         // we do not store credit card information
00125         // check and in case skip it
00126         if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00127             return true;
00128         }
00129 
00130         //encode sensitive data
00131         if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00132             $oDb = oxDb::getDb();
00133             $sEncodedValue = $oDb->getOne( "select encode( " . $oDb->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )", false, false);
00134             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00135         }
00136 
00137         $blRet = parent::_insert();
00138 
00139         //restore, as encoding was needed only for saving
00140         if ( $sEncodedValue ) {
00141             $this->oxuserpayments__oxvalue->setValue($sValue);
00142         }
00143 
00144         return $blRet;
00145     }
00146 
00152     protected function _update()
00153     {
00154         $oDb = oxDb::getDb();
00155 
00156         //encode sensitive data
00157         if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00158             $sEncodedValue = $oDb->getOne( "select encode( " . $oDb->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )", false, false);
00159             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00160         }
00161 
00162         $blRet = parent::_update();
00163 
00164         //restore, as encoding was needed only for saving
00165         if ( $sEncodedValue ) {
00166             $this->oxuserpayments__oxvalue->setValue($sValue);
00167         }
00168 
00169         return $blRet;
00170     }
00171 
00179     public function setStoreCreditCardInfo( $blStoreCreditCardInfo )
00180     {
00181         $this->_blStoreCreditCardInfo = $blStoreCreditCardInfo;
00182     }
00183 
00189     public function getStoreCreditCardInfo()
00190     {
00191         return $this->_blStoreCreditCardInfo;
00192     }
00193 
00202     public function getPaymentByPaymentType( $oUser = null, $sPaymentType = null )
00203     {
00204         $blGet = false;
00205         if ( $oUser && $sPaymentType != null ) {
00206             $oDb = oxDb::getDb();
00207             $sQ  = 'select oxpaymentid from oxorder where oxpaymenttype=' . $oDb->quote( $sPaymentType ) . ' and
00208                     oxuserid=' . $oDb->quote( $oUser->getId() ).' order by oxorderdate desc';
00209             if ( ( $sOxId = $oDb->getOne( $sQ ) ) ) {
00210                 $blGet = $this->load( $sOxId );
00211             }
00212         }
00213 
00214         return $blGet;
00215     }
00216 
00222     public function getDynValues()
00223     {
00224         if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00225             return null;
00226         }
00227 
00228         if ( !$this->_aDynValues ) {
00229 
00230             $sRawDynValue = null;
00231             if ( is_object($this->oxuserpayments__oxvalue) ) {
00232                 $sRawDynValue = $this->oxuserpayments__oxvalue->getRawValue();
00233             }
00234 
00235             $this->_aDynValues = oxRegistry::getUtils()->assignValuesFromText( $sRawDynValue );
00236         }
00237         return $this->_aDynValues;
00238     }
00239 
00247     public function setDynValues( $aDynValues )
00248     {
00249         $this->_aDynValues = $aDynValues;
00250     }
00251 
00252 }