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 
00068             return $this->_oPayment->oxpayments__oxdesc;
00069         }
00070 
00071         if ($sName == 'aDynValues') {
00072             if ($this->_aDynValues === null) {
00073                 $this->_aDynValues = $this->getDynValues();
00074             }
00075 
00076             return $this->_aDynValues;
00077         }
00078 
00079         return parent::__get($sName);
00080     }
00081 
00085     public function __construct()
00086     {
00087         parent::__construct();
00088         $this->init('oxuserpayments');
00089         $this->_sPaymentKey = oxRegistry::getUtils()->strRot13($this->_sPaymentKey);
00090         $this->setStoreCreditCardInfo($this->getConfig()->getConfigParam('blStoreCreditCardInfo'));
00091     }
00092 
00098     public function getPaymentKey()
00099     {
00100         return $this->_sPaymentKey;
00101     }
00102 
00110     public function load($sOxId)
00111     {
00112         $sSelect = 'select oxid, oxuserid, oxpaymentsid, DECODE( oxvalue, "' . $this->getPaymentKey() . '" ) as oxvalue
00113                     from oxuserpayments where oxid = ' . oxDb::getDb()->quote($sOxId);
00114 
00115         return $this->assignRecord($sSelect);
00116     }
00117 
00118 
00124     protected function _insert()
00125     {
00126         // we do not store credit card information
00127         // check and in case skip it
00128         if (!$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard') {
00129             return true;
00130         }
00131 
00132         //encode sensitive data
00133         if ($sValue = $this->oxuserpayments__oxvalue->value) {
00134             $oDb = oxDb::getDb();
00135             $sEncodedValue = $oDb->getOne("select encode( " . $oDb->quote($sValue) . ", '" . $this->getPaymentKey() . "' )", false, false);
00136             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00137         }
00138 
00139         $blRet = parent::_insert();
00140 
00141         //restore, as encoding was needed only for saving
00142         if ($sEncodedValue) {
00143             $this->oxuserpayments__oxvalue->setValue($sValue);
00144         }
00145 
00146         return $blRet;
00147     }
00148 
00154     protected function _update()
00155     {
00156         $oDb = oxDb::getDb();
00157 
00158         //encode sensitive data
00159         if ($sValue = $this->oxuserpayments__oxvalue->value) {
00160             $sEncodedValue = $oDb->getOne("select encode( " . $oDb->quote($sValue) . ", '" . $this->getPaymentKey() . "' )", false, false);
00161             $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00162         }
00163 
00164         $blRet = parent::_update();
00165 
00166         //restore, as encoding was needed only for saving
00167         if ($sEncodedValue) {
00168             $this->oxuserpayments__oxvalue->setValue($sValue);
00169         }
00170 
00171         return $blRet;
00172     }
00173 
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 
00238         return $this->_aDynValues;
00239     }
00240 
00246     public function setDynValues($aDynValues)
00247     {
00248         $this->_aDynValues = $aDynValues;
00249     }
00250 }