OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxuserpayment.php
Go to the documentation of this file.
1 <?php
2 
9 class oxUserPayment extends oxBase
10 {
11 
12  // you can change this if you want more security
13  // DO NOT !! CHANGE THIS FILE AND STORE CREDIT CARD INFORMATION
14  // THIS IS MORE THAN LIKELY ILLEGAL !!
15  // CHECK YOUR CREDIT CARD CONTRACT
16 
22  protected $_sPaymentKey = 'fq45QS09_fqyx09239QQ';
23 
29  protected $_sClassName = 'oxuserpayment';
30 
36  protected $_blStoreCreditCardInfo = null;
37 
43  protected $_oPayment = null;
44 
50  protected $_aDynValues = null;
51 
59  public function __get( $sName )
60  {
61  //due to compatibility with templates
62  if ( $sName == 'oxpayments__oxdesc' ) {
63  if ( $this->_oPayment === null ) {
64  $this->_oPayment = oxNew( 'oxpayment' );
65  $this->_oPayment->load( $this->oxuserpayments__oxpaymentsid->value );
66  }
67  return $this->_oPayment->oxpayments__oxdesc;
68  }
69 
70  if ( $sName == 'aDynValues' ) {
71  if ( $this->_aDynValues === null ) {
72  $this->_aDynValues = $this->getDynValues();
73  }
74  return $this->_aDynValues;
75  }
76 
77  return parent::__get( $sName );
78  }
79 
83  public function __construct()
84  {
86  $this->init( 'oxuserpayments' );
87  $this->_sPaymentKey = oxRegistry::getUtils()->strRot13( $this->_sPaymentKey );
88  $this->setStoreCreditCardInfo( $this->getConfig()->getConfigParam( 'blStoreCreditCardInfo' ) );
89  }
90 
96  public function getPaymentKey()
97  {
98  return $this->_sPaymentKey;
99  }
100 
108  public function load( $sOxId )
109  {
110  $sSelect = 'select oxid, oxuserid, oxpaymentsid, DECODE( oxvalue, "'.$this->getPaymentKey().'" ) as oxvalue
111  from oxuserpayments where oxid = '. oxDb::getDb()->quote( $sOxId );
112 
113  return $this->assignRecord( $sSelect );
114  }
115 
116 
122  protected function _insert()
123  {
124  // we do not store credit card information
125  // check and in case skip it
126  if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
127  return true;
128  }
129 
130  //encode sensitive data
131  if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
132  $oDb = oxDb::getDb();
133  $sEncodedValue = $oDb->getOne( "select encode( " . $oDb->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )", false, false);
134  $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
135  }
136 
137  $blRet = parent::_insert();
138 
139  //restore, as encoding was needed only for saving
140  if ( $sEncodedValue ) {
141  $this->oxuserpayments__oxvalue->setValue($sValue);
142  }
143 
144  return $blRet;
145  }
146 
152  protected function _update()
153  {
154  $oDb = oxDb::getDb();
155 
156  //encode sensitive data
157  if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
158  $sEncodedValue = $oDb->getOne( "select encode( " . $oDb->quote( $sValue ) . ", '" . $this->getPaymentKey() . "' )", false, false);
159  $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
160  }
161 
162  $blRet = parent::_update();
163 
164  //restore, as encoding was needed only for saving
165  if ( $sEncodedValue ) {
166  $this->oxuserpayments__oxvalue->setValue($sValue);
167  }
168 
169  return $blRet;
170  }
171 
179  public function setStoreCreditCardInfo( $blStoreCreditCardInfo )
180  {
181  $this->_blStoreCreditCardInfo = $blStoreCreditCardInfo;
182  }
183 
189  public function getStoreCreditCardInfo()
190  {
192  }
193 
202  public function getPaymentByPaymentType( $oUser = null, $sPaymentType = null )
203  {
204  $blGet = false;
205  if ( $oUser && $sPaymentType != null ) {
206  $oDb = oxDb::getDb();
207  $sQ = 'select oxpaymentid from oxorder where oxpaymenttype=' . $oDb->quote( $sPaymentType ) . ' and
208  oxuserid=' . $oDb->quote( $oUser->getId() ).' order by oxorderdate desc';
209  if ( ( $sOxId = $oDb->getOne( $sQ ) ) ) {
210  $blGet = $this->load( $sOxId );
211  }
212  }
213 
214  return $blGet;
215  }
216 
222  public function getDynValues()
223  {
224  if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
225  return null;
226  }
227 
228  if ( !$this->_aDynValues ) {
229 
230  $sRawDynValue = null;
231  if ( is_object($this->oxuserpayments__oxvalue) ) {
232  $sRawDynValue = $this->oxuserpayments__oxvalue->getRawValue();
233  }
234 
235  $this->_aDynValues = oxRegistry::getUtils()->assignValuesFromText( $sRawDynValue );
236  }
237  return $this->_aDynValues;
238  }
239 
247  public function setDynValues( $aDynValues )
248  {
249  $this->_aDynValues = $aDynValues;
250  }
251 
252 }