ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilEPaySettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
34  private $db;
35 
36  private $settings;
37  private $settings_id;
38 
39  private $server_host;
40  private $server_path;
41  private $vendor;
42  private $auth_token;
43  private $page_style;
45  private $ssl;
47 
48  static private $instance = null;
49 
56  static public function getInstance()
57  {
58  if (!self::$instance)
59  {
60  self::$instance = new ilEPaySettings();
61  }
62 
63  return self::$instance;
64  }
65 
70  private function __construct()
71  {
72  $this->getSettings();
73  }
74 
75 
80  public function validateEPayData($amount, $orderid, $transactionid, $md5Key)
81  {
82  $this->getSettings();
83  $password = $this->getAuthToken();
84  $strForValidate = "";
85  $strForValidate = $amount . $orderid . $transactionid . $password;
86  if (md5($strForValidate) == $md5Key) {
87  return true;
88  }
89  else {
90  return false;
91  }
92  }
93 
99  public function generatekeyForEpay($cur, $amount, $orderid)
100  {
101  $this->getSettings();
102  $password = $this->getAuthToken();
103  return md5($cur . $amount . $orderid . $password);
104  }
105 
106 
112  private function getSettings()
113  {
114  global $ilDB;
115  $this->fetchSettingsId();
116 
117  $res = $ilDB->queryf('
118  SELECT epay FROM payment_settings WHERE settings_id = %s',
119  array('integer'), array($this->getSettingsId()));
120 
121  $result = $res->fetchRow(DB_FETCHMODE_OBJECT);
122 
123  $data = array();
124  if (is_object($result))
125  {
126  if ($result->epay != "") $data = unserialize($result->epay);
127  else $data = array();
128  }
129 
130  $this->setAll($data);
131  }
132 
138  private function fetchSettingsId()
139  {
140  global $ilDB;
141 
142  $res = $ilDB->query('SELECT * FROM payment_settings');
143 
144  $result = $res->fetchRow(DB_FETCHMODE_OBJECT);
145 
146  $this->setSettingsId($result->settings_id);
147  }
148 
149  public function setSettingsId($a_settings_id = 0)
150  {
151  $this->settings_id = $a_settings_id;
152  }
153 
154  public function getSettingsId()
155  {
156  return $this->settings_id;
157  }
158 
159  public function setServerHost($a_server_host)
160  {
161  $this->server_host = $a_server_host;
162  }
163 
164  private function getServerHost()
165  {
166  return $this->server_host;
167  }
168 
169  public function setServerPath($a_server_path)
170  {
171  $this->server_path = $a_server_path;
172  }
173 
174  private function getServerPath()
175  {
176  return $this->server_path;
177  }
178 
179  public function setMerchantNumber($a_merchant_number)
180  {
181  $this->merchant_number = (int) $a_merchant_number;
182  }
183 
184  private function getMerchantNumber()
185  {
186  return $this->merchant_number;
187  }
188 
189  public function setAuthToken($a_auth_token)
190  {
191  $this->auth_token = $a_auth_token;
192  }
193 
194  private function getAuthToken()
195  {
196  return $this->auth_token;
197  }
198 
199 
200  public function setAuthEmail($a_auth_email)
201  {
202  $this->auth_email = $a_auth_email;
203  }
204 
205  private function getAuthEmail()
206  {
207  return $this->auth_email;
208  }
209 
210  public function setInstantCapture($a_instant_capture)
211  {
212  if ((!$a_instant_capture == 1) || (!$a_instant_capture== '1')) $a_instant_capture=0; else $a_instant_capture=1;
213  $this->instant_capture = $a_instant_capture;
214  }
215 
216  private function getInstantCapture()
217  {
218  return $this->instant_capture;
219  }
220 
221 
228  public function getAll()
229  {
230  $values = array(
231  "server_host" => $this->getServerHost(),
232  "server_path" => $this->getServerPath(),
233  "merchant_number" => (int) $this->getMerchantNumber(),
234  "auth_token" => $this->getAuthToken(),
235  "auth_email" => $this->getAuthEmail(),
236  "instant_capture" => $this->getInstantCapture()
237  );
238  return $values;
239  }
240 
244  public function setAll($a)
245  {
246  if (isset($a['server_host'])) $this->setServerHost($a['server_host']);
247  if (isset($a['server_path'])) $this->setServerPath($a['server_path']);
248  if (isset($a['merchant_number'])) $this->setMerchantNumber($a['merchant_number']);
249  if (isset($a['auth_token'])) $this->setAuthToken($a['auth_token']);
250  if (isset($a['auth_email'])) $this->setAuthEmail($a['auth_email']);
251  if (isset($a['instant_capture'])) $this->setInstantCapture($a['instant_capture']);
252  }
253 
257  public function valid()
258  {
259  $r = true;
260  $a = $this->getAll();
261  if ( ($a['server_host'] == '') || ($a['server_path'] == '') ) $r = false;
262  if ( (int) $a['merchant_number'] <= 0 ) $r = false;
263  if ( ((int) $a['instant_capture'] != 0 ) && ((int) $a['instant_capture'] != 1)) $r = false;
264  return $r;
265  }
266 
267 
268 
274  function clearAll()
275  {
276  $statement = $this->db->manipulateF('
277  UPDATE payment_settings
278  SET epay = %s
279  WHERE settings_id = %s',
280  array('text', 'integer'),
281  array('NULL', $this->getSettingsId()));
282 
283 
284  $this->settings = array();
285  }
286 
292  public function save()
293  {
294  global $ilDB;
295  $values = $this->getAll();
296 
297  if ($this->getSettingsId())
298  {
299  $statement = $ilDB->manipulateF('
300  UPDATE payment_settings
301  SET epay = %s
302  WHERE settings_id = %s',
303  array('text', 'integer'),
304  array(serialize($values), $this->getSettingsId()));
305 
306  }
307  else
308  {
309  $next_id = $ilDB->nextId('payment_settings');
310  $statement = $ilDB->manipulateF('
311  INSERT INTO payment_settings
312  ( settings_id,
313  epay)
314  VALUES (%s, %s)',
315  array('integer','text'), array($next_id, serialize($values)));
316 
317  $this->setSettingsId($next_id);
318  }
319  }
320 }
321 ?>