ILIAS  release_4-3 Revision
 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 include_once './Services/Payment/classes/class.ilPaymentSettings.php';
34 
36 {
37  private $db;
38  public $pSettings;
39 
40 // private $settings;
41 // private $settings_id;
42 
43  private $server_host;
44  private $server_path;
45  private $vendor;
46  private $auth_token;
47  private $page_style;
49  private $ssl;
51 
52  static private $instance = null;
53 
60  static public function getInstance()
61  {
62  if (!self::$instance)
63  {
64  self::$instance = new ilEPaySettings();
65  }
66 
67  return self::$instance;
68  }
69 
74  private function __construct()
75  {
76  $this->pSettings = ilPaymentSettings::_getInstance();
77  $this->getSettings();
78  }
79 
80 
85  public function validateEPayData($amount, $orderid, $transactionid, $md5Key)
86  {
87  $this->getSettings();
88  $password = $this->getAuthToken();
89  $strForValidate = "";
90  $strForValidate = $amount . $orderid . $transactionid . $password;
91  if (md5($strForValidate) == $md5Key) {
92  return true;
93  }
94  else {
95  return false;
96  }
97  }
98 
104  public function generatekeyForEpay($cur, $amount, $orderid)
105  {
106  $this->getSettings();
107  $password = $this->getAuthToken();
108  return md5($cur . $amount . $orderid . $password);
109  }
110 
111 
117  private function getSettings()
118  {
119 
120  $result->epay = $this->pSettings->get('epay');
121 
122 // global $ilDB;
123 //
124 // $this->fetchSettingsId();
125 //
126 // $res = $ilDB->queryf('
127 // SELECT epay FROM payment_settings WHERE settings_id = %s',
128 // array('integer'), array($this->getSettingsId()));
129 //
130 // $result = $res->fetchRow(DB_FETCHMODE_OBJECT);
131 
132  $data = array();
133  if (is_object($result))
134  {
135  if ($result->epay != "") $data = unserialize($result->epay);
136  else $data = array();
137  }
138 
139  $this->setAll($data);
140  }
141 
147  private function fetchSettingsId()
148  {
149 // global $ilDB;
150 //
151 // $res = $ilDB->query('SELECT * FROM payment_settings');
152 //
153 // $result = $res->fetchRow(DB_FETCHMODE_OBJECT);
154 //
155 // $this->setSettingsId($result->settings_id);
156  }
157 
158  public function setSettingsId($a_settings_id = 0)
159  {
160 // $this->settings_id = $a_settings_id;
161  }
162 
163  public function getSettingsId()
164  {
165 // return $this->settings_id;
166  }
167 
168  public function setServerHost($a_server_host)
169  {
170  $this->server_host = $a_server_host;
171  }
172 
173  private function getServerHost()
174  {
175  return $this->server_host;
176  }
177 
178  public function setServerPath($a_server_path)
179  {
180  $this->server_path = $a_server_path;
181  }
182 
183  private function getServerPath()
184  {
185  return $this->server_path;
186  }
187 
188  public function setMerchantNumber($a_merchant_number)
189  {
190  $this->merchant_number = (int) $a_merchant_number;
191  }
192 
193  private function getMerchantNumber()
194  {
195  return $this->merchant_number;
196  }
197 
198  public function setAuthToken($a_auth_token)
199  {
200  $this->auth_token = $a_auth_token;
201  }
202 
203  private function getAuthToken()
204  {
205  return $this->auth_token;
206  }
207 
208 
209  public function setAuthEmail($a_auth_email)
210  {
211  $this->auth_email = $a_auth_email;
212  }
213 
214  private function getAuthEmail()
215  {
216  return $this->auth_email;
217  }
218 
219  public function setInstantCapture($a_instant_capture)
220  {
221  if ((!$a_instant_capture == 1) || (!$a_instant_capture== '1')) $a_instant_capture=0; else $a_instant_capture=1;
222  $this->instant_capture = $a_instant_capture;
223  }
224 
225  private function getInstantCapture()
226  {
227  return $this->instant_capture;
228  }
229 
230 
237  public function getAll()
238  {
239  $values = array(
240  "server_host" => $this->getServerHost(),
241  "server_path" => $this->getServerPath(),
242  "merchant_number" => (int) $this->getMerchantNumber(),
243  "auth_token" => $this->getAuthToken(),
244  "auth_email" => $this->getAuthEmail(),
245  "instant_capture" => $this->getInstantCapture()
246  );
247  return $values;
248  }
249 
253  public function setAll($a)
254  {
255  if (isset($a['server_host'])) $this->setServerHost($a['server_host']);
256  if (isset($a['server_path'])) $this->setServerPath($a['server_path']);
257  if (isset($a['merchant_number'])) $this->setMerchantNumber($a['merchant_number']);
258  if (isset($a['auth_token'])) $this->setAuthToken($a['auth_token']);
259  if (isset($a['auth_email'])) $this->setAuthEmail($a['auth_email']);
260  if (isset($a['instant_capture'])) $this->setInstantCapture($a['instant_capture']);
261  }
262 
266  public function valid()
267  {
268  $r = true;
269  $a = $this->getAll();
270  if ( ($a['server_host'] == '') || ($a['server_path'] == '') ) $r = false;
271  if ( (int) $a['merchant_number'] <= 0 ) $r = false;
272  if ( ((int) $a['instant_capture'] != 0 ) && ((int) $a['instant_capture'] != 1)) $r = false;
273  return $r;
274  }
275 
276 
277 
283  function clearAll()
284  {
285  $this->pSettings->set('epay', NULL, 'epay');
286  $this->settings = array();
287 // $statement = $this->db->manipulateF('
288 // UPDATE payment_settings
289 // SET epay = %s
290 // WHERE settings_id = %s',
291 // array('text', 'integer'),
292 // array('NULL', $this->getSettingsId()));
293 //
294 //
295 // $this->settings = array();
296 
297  }
298 
304  public function save()
305  {
306  $values = $this->getAll();
307  $this->pSettings->set('epay', serialize($values), 'epay');
308 
309 // global $ilDB;
310 // if ($this->getSettingsId())
311 // {
312 // $statement = $ilDB->manipulateF('
313 // UPDATE payment_settings
314 // SET epay = %s
315 // WHERE settings_id = %s',
316 // array('text', 'integer'),
317 // array(serialize($values), $this->getSettingsId()));
318 //
319 // }
320 // else
321 // {
322 // $next_id = $ilDB->nextId('payment_settings');
323 // $statement = $ilDB->manipulateF('
324 // INSERT INTO payment_settings
325 // ( settings_id,
326 // epay)
327 // VALUES (%s, %s)',
328 // array('integer','text'), array($next_id, serialize($values)));
329 //
330 // $this->setSettingsId($next_id);
331 // }
332  }
333 }
334 ?>