OXID eShop CE  4.9.8
 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 
68  return $this->_oPayment->oxpayments__oxdesc;
69  }
70 
71  if ($sName == 'aDynValues') {
72  if ($this->_aDynValues === null) {
73  $this->_aDynValues = $this->getDynValues();
74  }
75 
76  return $this->_aDynValues;
77  }
78 
79  return parent::__get($sName);
80  }
81 
85  public function __construct()
86  {
88  $this->init('oxuserpayments');
89  $this->_sPaymentKey = oxRegistry::getUtils()->strRot13($this->_sPaymentKey);
90  $this->setStoreCreditCardInfo($this->getConfig()->getConfigParam('blStoreCreditCardInfo'));
91  }
92 
98  public function getPaymentKey()
99  {
100  return $this->_sPaymentKey;
101  }
102 
110  public function load($sOxId)
111  {
112  $sSelect = 'select oxid, oxuserid, oxpaymentsid, DECODE( oxvalue, "' . $this->getPaymentKey() . '" ) as oxvalue
113  from oxuserpayments where oxid = ' . oxDb::getDb()->quote($sOxId);
114 
115  return $this->assignRecord($sSelect);
116  }
117 
118 
124  protected function _insert()
125  {
126  // we do not store credit card information
127  // check and in case skip it
128  if (!$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard') {
129  return true;
130  }
131 
132  //encode sensitive data
133  if ($sValue = $this->oxuserpayments__oxvalue->value) {
134  $oDb = oxDb::getDb();
135  $sEncodedValue = $oDb->getOne("select encode( " . $oDb->quote($sValue) . ", '" . $this->getPaymentKey() . "' )", false, false);
136  $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
137  }
138 
139  $blRet = parent::_insert();
140 
141  //restore, as encoding was needed only for saving
142  if ($sEncodedValue) {
143  $this->oxuserpayments__oxvalue->setValue($sValue);
144  }
145 
146  return $blRet;
147  }
148 
154  protected function _update()
155  {
156  $oDb = oxDb::getDb();
157 
158  //encode sensitive data
159  if ($sValue = $this->oxuserpayments__oxvalue->value) {
160  $sEncodedValue = $oDb->getOne("select encode( " . $oDb->quote($sValue) . ", '" . $this->getPaymentKey() . "' )", false, false);
161  $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
162  }
163 
164  $blRet = parent::_update();
165 
166  //restore, as encoding was needed only for saving
167  if ($sEncodedValue) {
168  $this->oxuserpayments__oxvalue->setValue($sValue);
169  }
170 
171  return $blRet;
172  }
173 
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 
238  return $this->_aDynValues;
239  }
240 
246  public function setDynValues($aDynValues)
247  {
248  $this->_aDynValues = $aDynValues;
249  }
250 }