PageRenderTime 76ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/www/shop/engine/Shopware/Plugins/Default/Backend/HeidelActions/payproxy/class.heidelpay.php

https://bitbucket.org/weberlars/sot-shopware
PHP | 1289 lines | 1089 code | 78 blank | 122 comment | 186 complexity | 4acf2a6b3026e0bb1a3c683f5def3910 MD5 | raw file
Possible License(s): AGPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, LGPL-3.0
  1. <?php
  2. class heidelpay
  3. {
  4. /*{{{Variables*/
  5. var $response = '';
  6. var $error = '';
  7. var $httpstatus = '';
  8. #var $live_url = 'https://ctpe.net/frontend/payment.prc';
  9. #var $demo_url = 'https://test.ctpe.net/frontend/payment.prc';
  10. var $live_url = 'https://heidelpay.hpcgw.net/sgw/gtwu';
  11. var $demo_url = 'https://test-heidelpay.hpcgw.net/sgw/gtwu';
  12. #var $xml_demo_url = 'https://test.ctpe.io/payment/ctpe';
  13. #var $xml_live_url = 'https://ctpe.io/payment/ctpe';
  14. var $xml_demo_url = 'https://test-heidelpay.hpcgw.net/TransactionCore/xml';
  15. var $xml_live_url = 'https://heidelpay.hpcgw.net/TransactionCore/xml';
  16. var $allowedCcardCurrencies = array('AED','AFA','ALL','AMD','ANG','AOA','ARS','AUD','AWG','AZM','BAM','BBD','BDT','BGN','BHD','BIF','BMD','BND','BOB','BRL','BSD','BTN','BWP','BYR','BZD','CAD','CDF','CHF','CLP','CNY','COP','CRC','CUP','CVE','CYP','CZK','DJF','DKK','DOP','DZD','EEK','EGP','ERN','ETB','EUR','FJD','FKP','GBP','GEL','GGP','GHC','GIP','GMD','GNF','GTQ','GYD','HKD','HNL','HRK','HTG','HUF','IDR','ILS','IMP','INR','IQD','IRR','ISK','JEP','JMD','JOD','JPY','KES','KGS','KHR','KMF','KPW','KRW','KWD','KYD','KZT','LAK','LBP','LKR','LRD','LSL','LTL','LVL','LYD','MAD','MDL','MGA','MKD','MMK','MNT','MOP','MRO','MTL','MUR','MVR','MWK','MXN','MYR','MZM','NAD','NGN','NIO','NOK','NPR','NZD','OMR','PAB','PEN','PGK','PHP','PKR','PLN','PTS','PYG','QAR','RON','RUB','RWF','SAR','SBD','SCR','SDD','SEK','SGD','SHP','SIT','SKK','SLL','SOS','SPL','SRD','STD','SVC','SYP','SZL','THB','TJS','TMM','TND','TOP','TRL','TRY','TTD','TVD','TWD','TZS','UAH','UGX','USD','UYU','UZS','VEF','VND','VUV','WST','XAF','XAG','XAU','XCD','XDR','XOF','XPD','XPF','XPT','YER','ZAR','ZMK','ZWD');
  17. var $availablePayments = array('CC','DD','DC','VA','OT','IV','PP','UA');
  18. var $pageURL = '';
  19. var $actualPaymethod = 'CC';
  20. var $db;
  21. var $dbhost = '' ; //'localhost';
  22. var $dbname = '' ; //'demoshops_sw4';
  23. var $dbuser = '' ; //'demoshops';
  24. var $dbpass = '' ; //'CKfFSxBDQxanWeBx';
  25. var $dbtable = 's_plugin_heidelpay_requests';
  26. var $table_config = 's_plugin_heidelpay_config';
  27. var $table_rates = 's_plugin_heidelpay_rates';
  28. var $sql = array();
  29. var $reqFields = array(
  30. 'IDENTIFICATION_UNIQUEID',
  31. 'IDENTIFICATION_SHORTID',
  32. 'IDENTIFICATION_TRANSACTIONID',
  33. 'IDENTIFICATION_REFERENCEID',
  34. 'PROCESSING_RESULT',
  35. 'PROCESSING_RETURN_CODE',
  36. 'PROCESSING_CODE',
  37. 'TRANSACTION_SOURCE',
  38. 'TRANSACTION_CHANNEL',
  39. 'TRANSACTION_RESPONSE',
  40. 'TRANSACTION_MODE',
  41. 'CRITERION_RESPONSE_URL',
  42. );
  43. var $duration2days = array(
  44. 'day' => '1',
  45. 'week' => '7',
  46. 'month' => '30',
  47. 'year' => '365',
  48. );
  49. var $baseURL = '';
  50. var $protokoll = 'http://';
  51. var $allKinds = array(
  52. 'abo' => '1',
  53. 'rate' => '2',
  54. 'deposit' => '3',
  55. );
  56. /*}}}*/
  57. function heidelpay()/*{{{*/
  58. {
  59. $configFilepath = dirname(__FILE__).'/../../../../../../../config.php';
  60. $config = include $configFilepath;
  61. if (!is_array($config)) {
  62. print 'Invalid configuration file provided; PHP file does not return array value';
  63. exit();
  64. };
  65. $this->dbhost = $config['db']['host'];
  66. $this->dbuser = $config['db']['username'];
  67. $this->dbpass = $config['db']['password'];
  68. $this->dbname = $config['db']['dbname'];
  69. if ($this->db = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass)){
  70. mysql_select_db($this->dbname, $this->db);
  71. } else {
  72. $this->error = 'MySQL Connection failed.';
  73. }
  74. // load protokoll for shopware config (sUSESSL)
  75. if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') {
  76. $this->protokoll = "https://" ;
  77. } else {
  78. $this->protokoll = "http://" ;
  79. }
  80. $serverHost = $_SERVER['HTTP_HOST'];
  81. // Get default shop
  82. $sql = 'SELECT base_path FROM `s_core_shops`WHERE `default` = 1 LIMIT 1';
  83. $this->sql[__FUNCTION__][] = $sql;
  84. $res = mysql_query($sql, $this->db);
  85. $exists = mysql_num_rows($res)>0;
  86. if (!$exists) {
  87. print 'No Settings Config found for sBASEPATH';
  88. exit();
  89. }
  90. $row = mysql_fetch_assoc($res);
  91. $this->baseURL = $this->protokoll.$serverHost.$row['base_path'];
  92. }/*}}}*/
  93. function saveReq($data, $xml)/*{{{*/
  94. {
  95. // Double Check
  96. if (!empty($data['IDENTIFICATION_UNIQUEID'])){
  97. $sql = 'SELECT `id` FROM `'.$this->dbtable.'`
  98. WHERE `IDENTIFICATION_UNIQUEID`= "'.addslashes($data['IDENTIFICATION_UNIQUEID']).'" ';
  99. $this->sql[__FUNCTION__][] = $sql;
  100. $res = mysql_query($sql, $this->db);
  101. $row = mysql_fetch_assoc($res);
  102. if ($row['id'] > 0) return $row['id'];
  103. }
  104. $sql = 'INSERT INTO `'.$this->dbtable.'` SET ';
  105. foreach($this->reqFields AS $key){
  106. $sql.= '`'.$key.'` = "'.addslashes($data[$key]).'", ';
  107. }
  108. $tmp = explode('.', $data['PROCESSING_CODE']);
  109. $sql.= '`meth` = "'.addslashes($tmp[0]).'", ';
  110. $sql.= '`typ` = "'.addslashes($tmp[1]).'", ';
  111. #$sql.= '`XML` = "'.addslashes($xml).'", '; // Raw Post Data
  112. $sql.= '`created` = NOW() ';
  113. #echo $sql;
  114. $this->sql[__FUNCTION__][] = $sql;
  115. $res = mysql_query($sql, $this->db);
  116. $lastID = mysql_insert_id($this->db);
  117. // Im Fall von CP die PA Zeile als gecaptured markieren
  118. if (!empty($data['IDENTIFICATION_REFERENCEID']) && $tmp[1] == 'CP'){
  119. $sql = 'UPDATE `'.$this->dbtable.'`
  120. SET `CAPTURED` = 1
  121. WHERE `IDENTIFICATION_UNIQUEID` = "'.addslashes($data['IDENTIFICATION_REFERENCEID']).'"';
  122. $this->sql[__FUNCTION__][] = $sql;
  123. mysql_query($sql, $this->db);
  124. }
  125. return $lastID;
  126. }/*}}}*/
  127. function saveRes2Req($uniqueId, $response)/*{{{*/
  128. {
  129. $sql = 'UPDATE `'.$this->dbtable.'` SET ';
  130. $sql.= '`RESPONSE` = "'.addslashes($response).'" ';
  131. $sql.= 'WHERE `IDENTIFICATION_UNIQUEID` = "'.addslashes($uniqueId).'" ';
  132. #echo $sql;
  133. $this->sql[__FUNCTION__][] = $sql;
  134. return mysql_query($sql, $this->db);
  135. }/*}}}*/
  136. function doRequest($url, $data, $xml = NULL)/*{{{*/
  137. {
  138. $strPOST = '';
  139. foreach($data AS $k => $v) {
  140. $strPOST.= $k.'='.$v.'&';
  141. }
  142. if (!empty($xml)) $strPOST = 'load='.urlencode($xml);
  143. #echo '<pre>'.print_r($strPOST, 1).'</pre>';
  144. if (function_exists('curl_init')) {
  145. $ch = curl_init();
  146. curl_setopt($ch, CURLOPT_URL, $url);
  147. curl_setopt($ch, CURLOPT_HEADER, 0);
  148. curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  149. curl_setopt($ch, CURLOPT_TIMEOUT, 8);
  150. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8);
  151. curl_setopt($ch, CURLOPT_POST, 1);
  152. curl_setopt($ch, CURLOPT_POSTFIELDS, $strPOST);
  153. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  154. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  155. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
  156. #curl_setopt($ch, CURLOPT_FOLLLOW_LOCATION,1);
  157. curl_setopt($ch, CURLOPT_USERAGENT, "php ctpepost");
  158. $this->response = curl_exec($ch);
  159. $this->error = curl_error($ch);
  160. $this->httpstatus = curl_getinfo($ch,CURLINFO_HTTP_CODE);
  161. #echo '<pre>'.print_r($this->response, 1).'</pre>';
  162. #echo '<pre>'.print_r($this->error, 1).'</pre>';
  163. #echo '<pre>'.print_r($this->httpstatus, 1).'</pre>';
  164. curl_close($ch);
  165. $res = $this->response;
  166. if (!$this->response && $this->error){
  167. $msg = urlencode('Curl Fehler...');
  168. $res = 'status=FAIL&msg='.$this->error;
  169. }
  170. } else {
  171. $msg = urlencode('Curl Fehler..');
  172. $res = 'status=FAIL&msg='.$msg;
  173. }
  174. return $res;
  175. }/*}}}*/
  176. function parseResult($curlresultURL)/*{{{*/
  177. {
  178. $r_arr=explode("&",$curlresultURL);
  179. foreach($r_arr AS $buf) {
  180. $temp=urldecode($buf);
  181. $temp=split("=",$temp,2);
  182. $postatt=$temp[0];
  183. $postvar=$temp[1];
  184. $returnvalue[$postatt]=$postvar;
  185. }
  186. $processingresult = $returnvalue['PROCESSING.RESULT'];
  187. if (empty($processingresult)) $processingresult = $returnvalue['POST.VALIDATION'];
  188. $redirectURL = $returnvalue['FRONTEND.REDIRECT_URL'];
  189. if (!isset($returnvalue['PROCESSING.RETURN']) && $returnvalue['POST.VALIDATION'] > 0){
  190. $returnvalue['PROCESSING.RETURN'] = 'Errorcode: '.$returnvalue['POST.VALIDATION'];
  191. }
  192. ksort($returnvalue);
  193. return array('result' => $processingresult, 'url' => $redirectURL, 'all' => $returnvalue);
  194. }/*}}}*/
  195. function checkHPCParams($params)/*{{{*/
  196. {
  197. if (empty($params)) return array();
  198. $tmp = array();
  199. foreach($params AS $k => $v){
  200. $k = preg_replace('/_/', '.', $k, 1);
  201. $tmp[$k] = $v;
  202. }
  203. return $tmp;
  204. }/*}}}*/
  205. function doDeposit($amount, $currency, $usage, $depositName, $duration, $payCode, $uniqueId, $loginData)/*{{{*/
  206. {
  207. if ($duration < 1) return false;
  208. if (!in_array($payCode, array('DD', 'DC', 'CC'))) return false;
  209. $transMode = $loginData['TRANSACTION_MODE'];
  210. // Schedule auf Test System mu??? mit CONNECTOR_TEST durchgef???hrt werden.
  211. if ($transMode == 'INTEGRATOR_TEST') $transMode = 'CONNECTOR_TEST';
  212. // Nicht jeder Monat hat mehr als 28 Tage. Daher immer den Letzten Tag des Monats nehmen wenn > 28
  213. $dayOfMonth = date('d');
  214. if ($dayOfMonth > 28) $dayOfMonth = 'L';
  215. $hour = date('H') - 3;
  216. $minute = date('i') - 1;
  217. // zum Testen in 1 Minute
  218. #$hour = date('H') - 2;
  219. #$minute = date('i') + 1;
  220. #$startTime = $res['all']['PROCESSING.TIMESTAMP'];
  221. $startTime = date('Y-m-d ').$hour.':'.date('i').date(':s');
  222. $nextMonth = date('m') + $duration; // Buchung erst zum bestimmten Zeitpunkt
  223. if ($nextMonth > 12) $nextMonth = $nextMonth - 12; // Wenn Dezember, dann ist n???chster Monat 1 und nicht 13
  224. if ($dayOfMonth == 'L') $startTime = date('Y').'-'.$nextMonth.'-'.date('d').' '.$hour.':'.date('i').date(':s'); // Startdatum mu??? bei "L" in Zukunft sein.
  225. $entTime = '';
  226. $endTime = date('Y-m-d H:i:s', mktime($hour,date('i'),date('s'),date('m')+$duration,date('d'),date('Y')));
  227. # Nur in dem einen Monat
  228. $month = $nextMonth;
  229. $xml = '<Request version="1.0">
  230. <Header>
  231. <Security sender="'.$loginData['SECURITY_SENDER'].'"/>
  232. </Header>
  233. <Transaction mode="'.$transMode.'" response="SYNC" channel="'.$loginData['TRANSACTION_CHANNEL'].'">
  234. <User login="'.$loginData['USER_LOGIN'].'" pwd="'.$loginData['USER_PWD'].'"/>
  235. <Identification>
  236. <TransactionID>'.$depositName.'</TransactionID>
  237. </Identification>
  238. <Payment code="'.$payCode.'.SD">
  239. <Presentation>
  240. <Amount>'.$amount.'</Amount>
  241. <Currency>'.$currency.'</Currency>
  242. <Usage>'.$usage.'</Usage>
  243. </Presentation>
  244. </Payment>
  245. <Job name="'.$depositName.'" start="'.$startTime.'" end="'.$endTime.'">
  246. <Action type="DB"/>
  247. <Execution>
  248. <DayOfMonth>'.$dayOfMonth.'</DayOfMonth>
  249. <Month>'.$month.'</Month>
  250. <Minute>'.$minute.'</Minute>
  251. <Hour>'.$hour.'</Hour>
  252. </Execution>
  253. <Notice>
  254. <Callable>ANYTIME</Callable>
  255. </Notice>
  256. <Duration>
  257. <Number>'.$duration.'</Number>
  258. <Unit>MONTH</Unit>
  259. </Duration>
  260. </Job>
  261. <Analysis><Criterion name="sales_cycle">RN</Criterion></Analysis>
  262. <Account registration="'.$uniqueId.'" />
  263. </Transaction>
  264. </Request>';
  265. #echo $xml;
  266. return $xml;
  267. $res = $this->doRequest(array(), $xml);
  268. $res = $this->parseResult($res);
  269. #echo '<pre>'.print_r($res, 1).'</pre>';
  270. return $res;
  271. }/*}}}*/
  272. function doRates($amount, $currency, $usage, $rateName, $freq, $duration, $payCode, $uniqueId, $loginData)/*{{{*/
  273. {
  274. if ($freq < 1) return false;
  275. if (!in_array($payCode, array('DD', 'DC', 'CC'))) return false;
  276. $transMode = $loginData['TRANSACTION_MODE'];
  277. // Schedule auf Test System mu??? mit CONNECTOR_TEST durchgef???hrt werden.
  278. if ($transMode == 'INTEGRATOR_TEST') $transMode = 'CONNECTOR_TEST';
  279. // Nicht jeder Monat hat mehr als 28 Tage. Daher immer den Letzten Tag des Monats nehmen wenn > 28
  280. $dayOfMonth = date('d');
  281. if ($dayOfMonth > 28) $dayOfMonth = 'L';
  282. $hour = date('H') - 3;
  283. $minute = date('i') - 1;
  284. // zum Testen in 1 Minute
  285. #$hour = date('H') - 2;
  286. #$minute = date('i') + 1;
  287. #$startTime = $res['all']['PROCESSING.TIMESTAMP'];
  288. $startTime = date('Y-m-d ').$hour.':'.date('i').date(':s');
  289. $nextMonth = date('m') + 1; // Erste Buchung erst im n???chsten Monat
  290. if ($nextMonth > 12) $nextMonth = $nextMonth - 12; // Wenn Dezember, dann ist n???chster Monat 1 und nicht 13
  291. if ($dayOfMonth == 'L') $startTime = date('Y').'-'.$nextMonth.'-'.date('d').' '.$hour.':'.date('i').date(':s'); // Startdatum mu??? bei "L" in Zukunft sein.
  292. $entTime = '';
  293. $endTime = date('Y-m-d H:i:s', mktime($hour,date('i'),date('s'),date('m')+$duration,date('d'),date('Y')));
  294. # Jeden Monat
  295. $month = '*';
  296. if ($freq == 2){ # Sechsteljährlich
  297. $m = (int)date('m');
  298. $month = $m;
  299. $m+= 2;
  300. if ($m > 12) $m-= 12;
  301. $month.= ','.$m;
  302. $m+= 2;
  303. if ($m > 12) $m-= 12;
  304. $month.= ','.$m;
  305. $m+= 2;
  306. if ($m > 12) $m-= 12;
  307. $month.= ','.$m;
  308. $m+= 2;
  309. if ($m > 12) $m-= 12;
  310. $month.= ','.$m;
  311. $m+= 2;
  312. if ($m > 12) $m-= 12;
  313. $month.= ','.$m;
  314. } else if ($freq == 3){ # Vierteljährlich
  315. $m = (int)date('m');
  316. $month = $m;
  317. $m+= 3;
  318. if ($m > 12) $m-= 12;
  319. $month.= ','.$m;
  320. $m+= 3;
  321. if ($m > 12) $m-= 12;
  322. $month.= ','.$m;
  323. $m+= 3;
  324. if ($m > 12) $m-= 12;
  325. $month.= ','.$m;
  326. } else if ($freq == 4){ # Dritteljährlich
  327. $m = (int)date('m');
  328. $month = $m;
  329. $m+= 4;
  330. if ($m > 12) $m-= 12;
  331. $month.= ','.$m;
  332. $m+= 4;
  333. if ($m > 12) $m-= 12;
  334. $month.= ','.$m;
  335. } else if ($freq == 6){ # Halbjährlich
  336. $m = date('m');
  337. $month = $m;
  338. $m+= 6;
  339. if ($m > 12) $m-= 12;
  340. $month.= ','.$m;
  341. } else if ($freq == 12){ # Jährlich
  342. $m = date('m');
  343. $month = $m;
  344. }
  345. $xml = '<Request version="1.0">
  346. <Header>
  347. <Security sender="'.$loginData['SECURITY_SENDER'].'"/>
  348. </Header>
  349. <Transaction mode="'.$transMode.'" response="SYNC" channel="'.$loginData['TRANSACTION_CHANNEL'].'">
  350. <User login="'.$loginData['USER_LOGIN'].'" pwd="'.$loginData['USER_PWD'].'"/>
  351. <Identification>
  352. <TransactionID>'.$rateName.'</TransactionID>
  353. </Identification>
  354. <Payment code="'.$payCode.'.SD">
  355. <Presentation>
  356. <Amount>'.$amount.'</Amount>
  357. <Currency>'.$currency.'</Currency>
  358. <Usage>'.$usage.'</Usage>
  359. </Presentation>
  360. </Payment>
  361. <Job name="'.$rateName.'" start="'.$startTime.'" end="'.$endTime.'">
  362. <Action type="DB"/>
  363. <Execution>
  364. <DayOfMonth>'.$dayOfMonth.'</DayOfMonth>
  365. <Month>'.$month.'</Month>
  366. <Minute>'.$minute.'</Minute>
  367. <Hour>'.$hour.'</Hour>
  368. </Execution>
  369. <Notice>
  370. <Callable>ANYTIME</Callable>
  371. </Notice>
  372. <Duration>
  373. <Number>'.$duration.'</Number>
  374. <Unit>MONTH</Unit>
  375. </Duration>
  376. </Job>
  377. <Analysis><Criterion name="sales_cycle">RN</Criterion></Analysis>
  378. <Account registration="'.$uniqueId.'" />
  379. </Transaction>
  380. </Request>';
  381. #echo $xml;
  382. return $xml;
  383. $res = $this->doRequest(array(), $xml);
  384. $res = $this->parseResult($res);
  385. #echo '<pre>'.print_r($res, 1).'</pre>';
  386. return $res;
  387. }/*}}}*/
  388. function doSubscription($amount, $currency, $usage, $aboName, $freq, $payCode, $uniqueId, $loginData)/*{{{*/
  389. {
  390. if ($freq < 1) return false;
  391. if (!in_array($payCode, array('DD', 'DC', 'CC'))) return false;
  392. $transMode = $loginData['TRANSACTION_MODE'];
  393. // Schedule auf Test System mu??? mit CONNECTOR_TEST durchgef???hrt werden.
  394. if ($transMode == 'INTEGRATOR_TEST') $transMode = 'CONNECTOR_TEST';
  395. // Nicht jeder Monat hat mehr als 28 Tage. Daher immer den Letzten Tag des Monats nehmen wenn > 28
  396. $dayOfMonth = date('d');
  397. if ($dayOfMonth > 28) $dayOfMonth = 'L';
  398. $hour = date('H') - 3;
  399. $minute = date('i') - 1;
  400. // zum Testen in 1 Minute
  401. #$hour = date('H') - 2;
  402. #$minute = date('i') + 1;
  403. #$startTime = $res['all']['PROCESSING.TIMESTAMP'];
  404. $startTime = date('Y-m-d ').$hour.':'.date('i').date(':s');
  405. $entTime = '';
  406. #$endTime = date('Y-m-d H:i:s', mktime($hour,date('i'),date('s'),date('m'),date('d')+($freq*30),date('Y')));
  407. # Jeden Monat
  408. $month = '*';
  409. if ($freq == 2){ # Sechstelj???hrlich
  410. $m = (int)date('m');
  411. $month = $m;
  412. $m+= 2;
  413. if ($m > 12) $m-= 12;
  414. $month.= ','.$m;
  415. $m+= 2;
  416. if ($m > 12) $m-= 12;
  417. $month.= ','.$m;
  418. $m+= 2;
  419. if ($m > 12) $m-= 12;
  420. $month.= ','.$m;
  421. $m+= 2;
  422. if ($m > 12) $m-= 12;
  423. $month.= ','.$m;
  424. $m+= 2;
  425. if ($m > 12) $m-= 12;
  426. $month.= ','.$m;
  427. } else if ($freq == 3){ # Viertelj???hrlich
  428. $m = (int)date('m');
  429. $month = $m;
  430. $m+= 3;
  431. if ($m > 12) $m-= 12;
  432. $month.= ','.$m;
  433. $m+= 3;
  434. if ($m > 12) $m-= 12;
  435. $month.= ','.$m;
  436. $m+= 3;
  437. if ($m > 12) $m-= 12;
  438. $month.= ','.$m;
  439. } else if ($freq == 4){ # Drittelj???hrlich
  440. $m = (int)date('m');
  441. $month = $m;
  442. $m+= 4;
  443. if ($m > 12) $m-= 12;
  444. $month.= ','.$m;
  445. $m+= 4;
  446. if ($m > 12) $m-= 12;
  447. $month.= ','.$m;
  448. } else if ($freq == 6){ # Halbj???hrlich
  449. $m = date('m');
  450. $month = $m;
  451. $m+= 6;
  452. if ($m > 12) $m-= 12;
  453. $month.= ','.$m;
  454. } else if ($freq == 12){ # J???hrlich
  455. $m = date('m');
  456. $month = $m;
  457. }
  458. $xml = '<Request version="1.0">
  459. <Header>
  460. <Security sender="'.$loginData['SECURITY_SENDER'].'"/>
  461. </Header>
  462. <Transaction mode="'.$transMode.'" response="SYNC" channel="'.$loginData['TRANSACTION_CHANNEL'].'">
  463. <User login="'.$loginData['USER_LOGIN'].'" pwd="'.$loginData['USER_PWD'].'"/>
  464. <Identification>
  465. <TransactionID>'.$aboName.'</TransactionID>
  466. </Identification>
  467. <Payment code="'.$payCode.'.SD">
  468. <Presentation>
  469. <Amount>'.$amount.'</Amount>
  470. <Currency>'.$currency.'</Currency>
  471. <Usage>'.$usage.'</Usage>
  472. </Presentation>
  473. </Payment>
  474. <Job name="'.$aboName.'" start="'.$startTime.'" end="'.$endTime.'">
  475. <Action type="DB"/>
  476. <Execution>
  477. <DayOfMonth>'.$dayOfMonth.'</DayOfMonth>
  478. <Month>'.$month.'</Month>
  479. <Minute>'.$minute.'</Minute>
  480. <Hour>'.$hour.'</Hour>
  481. </Execution>
  482. <Notice>
  483. <Callable>ANYTIME</Callable>
  484. </Notice>
  485. <Duration>
  486. <Number>'.$freq.'</Number>
  487. <Unit>DAY</Unit>
  488. </Duration>
  489. </Job>
  490. <Analysis><Criterion name="sales_cycle">RN</Criterion></Analysis>
  491. <Account registration="'.$uniqueId.'" />
  492. </Transaction>
  493. </Request>';
  494. #echo $xml;
  495. return $xml;
  496. $res = $this->doRequest(array(), $xml);
  497. $res = $this->parseResult($res);
  498. #echo '<pre>'.print_r($res, 1).'</pre>';
  499. return $res;
  500. }/*}}}*/
  501. function getPostFromXML($xml)/*{{{*/
  502. {
  503. $tmp = array();
  504. if (empty($xml)) return array();
  505. foreach($xml AS $k => $v){
  506. $attribs = $v->attributes();
  507. #echo '<pre>'.print_r($attribs, 1).'</pre>';
  508. foreach($attribs AS $ak => $av){
  509. #echo $ak.' -> '.$av.'<br>';
  510. $tmp[strtoupper($k).'_'.strtoupper($ak)] = (string)$av;
  511. }
  512. foreach($v AS $kk => $vv){
  513. $attribs = $vv->attributes();
  514. if (!empty($attribs)){
  515. foreach($attribs AS $ak => $av){
  516. #echo $ak.' -> '.$av.'<br>';
  517. $tmp[strtoupper($kk).'_'.strtoupper($ak)] = (string)$av;
  518. }
  519. }# else {
  520. foreach($vv AS $kkk => $vvv){
  521. $attribs = $vvv->attributes();
  522. if (!empty($attribs)){
  523. foreach($attribs AS $ak => $av){
  524. if ($kk == 'Analysis') continue;
  525. #echo $ak.' -> '.$av.'<br>';
  526. $tmp[strtoupper($kk).'_'.strtoupper($kkk).'_'.strtoupper($ak)] = (string)$av;
  527. }
  528. }# else {
  529. if ($kk == 'Customer'){
  530. foreach($vvv AS $kkkk => $vvvv){
  531. #echo $ak.' -> '.$av.'<br>';
  532. $tmp[strtoupper($kkk).'_'.strtoupper($kkkk)] = (string)$vvvv;
  533. }
  534. } else if ($kk == 'Payment'){
  535. foreach($vvv AS $kkkk => $vvvv){
  536. #echo $ak.' -> '.$av.'<br>';
  537. $tmp[strtoupper($kkk).'_'.strtoupper($kkkk)] = (string)$vvvv;
  538. }
  539. } else if ($kk == 'Analysis'){
  540. $attribs = $vvv->attributes();
  541. if (!empty($attribs)){
  542. #echo (string)$attribs->name;
  543. #echo (string)$vvv;
  544. $tmp[strtoupper($kkk).'_'.strtoupper((string)$attribs->name)] = (string)$vvv;
  545. }
  546. foreach($vvv AS $kkkk => $vvvv){
  547. #echo $kkkk.' -> '.$vvvv.'<br>';
  548. #$tmp[strtoupper($kkkk).'_'.strtoupper((string)$attribs->name)] = (string)$vvvv;
  549. }
  550. } else {
  551. if ($kkk == 'Expiry') continue;
  552. $tmp[strtoupper($kk).'_'.strtoupper($kkk)] = (string)$vvv;
  553. #echo $kkk.' -> '.$vvv.'<br>';
  554. }
  555. #}
  556. }
  557. #}
  558. }
  559. }
  560. return $tmp;
  561. }/*}}}*/
  562. function checkLogin($dat)/*{{{*/
  563. {
  564. $data = array(
  565. 'SECURITY.SENDER' => $dat['SECURITY_SENDER'],
  566. 'USER.LOGIN' => $dat['USER_LOGIN'],
  567. 'USER.PWD' => $dat['USER_PWD'],
  568. 'TRANSACTION.CHANNEL' => $dat['TRANSACTION_CHANNEL'],
  569. 'TRANSACTION.MODE' => $dat['TRANSACTION_MODE'],
  570. 'PAYMENT.CODE' => 'CC.RG',
  571. 'FRONTEND.ENABLED' => 'true',
  572. 'FRONTEND.RESPONSE_URL' => 'http://www.google.de',
  573. );
  574. $url = $this->demo_url;
  575. if ($dat['TRANSATION.MODE'] == 'LIVE') $url = $this->live_url;
  576. // echo '<pre>'.print_r($data, 1).'</pre>';
  577. $res = trim($this->doRequest($url, $data));
  578. parse_str($res, $ret);
  579. // echo '<pre>'.print_r($ret, 1).'</pre>';
  580. return !empty($ret['FRONTEND_REDIRECT_URL']);
  581. }/*}}}*/
  582. function getUniqueId($uniqueId)/*{{{*/
  583. {
  584. if (empty($uniqueId)) return array();
  585. $sql = 'SELECT `SERIAL` FROM `'.$this->dbtable.'` ';
  586. $sql.= 'WHERE `IDENTIFICATION_UNIQUEID` = "'.addslashes($uniqueId).'" ';
  587. #echo $sql;
  588. $this->sql[__FUNCTION__][] = $sql;
  589. $res = mysql_query($sql, $this->db);
  590. if (mysql_errno($this->db) > 0) return array();
  591. if (mysql_num_rows($res) <= 0) return array();
  592. $tmp = mysql_fetch_assoc($res);
  593. if (empty($tmp)) return array();
  594. return unserialize($tmp['SERIAL']);
  595. }/*}}}*/
  596. function getShortId($shortId)/*{{{*/
  597. {
  598. if (empty($shortId)) return array();
  599. $sql = 'SELECT `SERIAL` FROM `'.$this->dbtable.'` ';
  600. $sql.= 'WHERE `IDENTIFICATION_SHORTID` = "'.addslashes($shortId).'" ';
  601. #echo $sql;
  602. $this->sql[__FUNCTION__][] = $sql;
  603. $res = mysql_query($sql, $this->db);
  604. $tmp = array();
  605. while($row = mysql_fetch_assoc($res)){
  606. $tmp[] = unserialize($row['SERIAL']);
  607. }
  608. return $tmp;
  609. }/*}}}*/
  610. function getRefId($refId)/*{{{*/
  611. {
  612. if (empty($refId)) return array();
  613. $sql = 'SELECT `SERIAL` FROM `'.$this->dbtable.'` ';
  614. $sql.= 'WHERE `IDENTIFICATION_REFERENCEID` = "'.addslashes($refId).'" ';
  615. #echo $sql;
  616. $this->sql[__FUNCTION__][] = $sql;
  617. $res = mysql_query($sql, $this->db);
  618. if (mysql_errno($this->db) > 0) return array();
  619. if (mysql_num_rows($res) <= 0) return array();
  620. $tmp = array();
  621. while($row = mysql_fetch_assoc($res)){
  622. $tmp[] = unserialize($row['SERIAL']);
  623. }
  624. return $tmp;
  625. }/*}}}*/
  626. function getOpenPA()/*{{{*/
  627. {
  628. // Wenig perfomant
  629. /*
  630. $sql = 'SELECT a.`SERIAL` FROM `'.$this->dbtable.'` a
  631. LEFT JOIN `'.$this->dbtable.'` b
  632. ON a.`IDENTIFICATION_REFERENCEID` = b.`IDENTIFICATION_UNIQUEID`
  633. AND a.`PROCESSING_CODE` LIKE "%.CP.%"
  634. WHERE a.`PROCESSING_CODE` LIKE "%.PA.%"
  635. AND a.`PROCESSING_RESULT` = "ACK"
  636. AND a.`PROCESSING_CODE` NOT LIKE "OT.%"
  637. ';
  638. */
  639. // besser so
  640. /*
  641. $sql = 'SELECT a.`SERIAL`, b.`id` FROM `'.$this->dbtable.'` a
  642. LEFT JOIN `'.$this->dbtable.'` b
  643. ON b.`IDENTIFICATION_REFERENCEID` = a.`IDENTIFICATION_UNIQUEID`
  644. AND b.`typ` = "CP"
  645. WHERE a.`typ` = "PA"
  646. AND a.`PROCESSING_RESULT` = "ACK"
  647. AND a.`meth` IN ("CC", "DC", "DD", "VA")
  648. ';
  649. */
  650. // viel besser
  651. $sql = 'SELECT `SERIAL` FROM `'.$this->dbtable.'`
  652. WHERE `CAPTURED` = 0
  653. AND `typ` = "PA"
  654. AND `PROCESSING_RESULT` = "ACK"
  655. AND `meth` IN ("CC", "DC", "DD", "VA")
  656. ';
  657. #echo $sql;
  658. $this->sql[__FUNCTION__][] = $sql;
  659. $res = mysql_query($sql, $this->db);
  660. $tmp = array();
  661. if (mysql_num_rows($res) <= 0) return $tmp;
  662. while($row = mysql_fetch_assoc($res)){
  663. if (!empty($row['id'])) continue;
  664. $tmp[] = unserialize($row['SERIAL']);
  665. }
  666. return $tmp;
  667. }/*}}}*/
  668. function doSearch($params)/*{{{*/
  669. {
  670. if (empty($params)) return array();
  671. $sql = 'SELECT `SERIAL` FROM `'.$this->dbtable.'`
  672. WHERE 1=1 ';
  673. foreach($params AS $k => $v){
  674. if (empty($v)) continue;
  675. $sql.= ' AND `'.addslashes($k).'` LIKE "%'.addslashes($v).'%" ';
  676. }
  677. #echo $sql;
  678. $res = mysql_query($sql, $this->db);
  679. if (mysql_num_rows($res) <= 0) return array();
  680. $tmp = array();
  681. while($row = mysql_fetch_assoc($res)){
  682. $tmp[] = unserialize($row['SERIAL']);
  683. }
  684. return $tmp;
  685. }/*}}}*/
  686. function convertXML2SERIAL()/*{{{*/
  687. {
  688. $sql = 'SELECT `id`,`xml` FROM `'.$this->dbtable.'` ';
  689. #echo $sql;
  690. $this->sql[__FUNCTION__][] = $sql;
  691. $res = mysql_query($sql, $this->db);
  692. while($row = mysql_fetch_assoc($res)){
  693. $xml = simplexml_load_string($row['xml']);
  694. $data = $this->getPostFromXML($xml);
  695. $this->saveSERIAL($row['id'], $data);
  696. }
  697. return true;
  698. }/*}}}*/
  699. function convertOpenPA()/*{{{*/
  700. {
  701. $sql = 'SELECT `IDENTIFICATION_REFERENCEID` FROM `'.$this->dbtable.'`
  702. WHERE `typ` = "CP"
  703. AND `PROCESSING_RESULT` = "ACK"
  704. AND `meth` IN ("CC", "DC", "DD", "VA")';
  705. #echo $sql.'<br>';
  706. $this->sql[__FUNCTION__][] = $sql;
  707. $res = mysql_query($sql, $this->db);
  708. while($row = mysql_fetch_assoc($res)){
  709. $sql = 'UPDATE `'.$this->dbtable.'` SET ';
  710. $sql.= '`CAPTURED` = "1" ';
  711. $sql.= 'WHERE `IDENTIFICATION_UNIQUEID` = "'.$row['IDENTIFICATION_REFERENCEID'].'" ';
  712. $sql.= 'AND `typ` = "PA" ';
  713. #echo $sql.'<br>';
  714. mysql_query($sql, $this->db);
  715. }
  716. return true;
  717. }/*}}}*/
  718. function convertProcessingCode()/*{{{*/
  719. {
  720. $sql = 'SELECT `id`,`PROCESSING_CODE` FROM `'.$this->dbtable.'` ';
  721. #echo $sql;
  722. $this->sql[__FUNCTION__][] = $sql;
  723. $res = mysql_query($sql, $this->db);
  724. while($row = mysql_fetch_assoc($res)){
  725. $tmp = explode('.', $row['PROCESSING_CODE']);
  726. $sql = 'UPDATE `'.$this->dbtable.'` SET ';
  727. $sql.= '`meth` = "'.addslashes($tmp[0]).'", ';
  728. $sql.= '`typ` = "'.addslashes($tmp[1]).'" ';
  729. $sql.= 'WHERE `id` = "'.$row['id'].'" ';
  730. mysql_query($sql, $this->db);
  731. }
  732. return true;
  733. }/*}}}*/
  734. function saveSERIAL($id, $data)/*{{{*/
  735. {
  736. $serial = serialize($data);
  737. $sql = 'UPDATE `'.$this->dbtable.'`
  738. SET `SERIAL` = "'.addslashes($serial).'"
  739. WHERE `id` = '.(int)$id;
  740. #echo $sql;
  741. $this->sql[__FUNCTION__][] = $sql;
  742. return mysql_query($sql, $this->db);
  743. }/*}}}*/
  744. function getSenderByChannel($channel)/*{{{*/
  745. {
  746. if (empty($channel)) return false;
  747. $sql = 'SELECT `SECURITY_SENDER` FROM `'.$this->table_config.'` ';
  748. $sql.= 'WHERE `TRANSACTION_CHANNEL` = "'.addslashes($channel).'" ';
  749. #echo $sql;
  750. $this->sql[__FUNCTION__][] = $sql;
  751. $res = mysql_query($sql, $this->db);
  752. if (mysql_errno($this->db) > 0) return false;
  753. if (mysql_num_rows($res) <= 0) return false;
  754. $tmp = mysql_fetch_assoc($res);
  755. #echo '<pre>'.print_r($tmp, 1).'</pre>';
  756. if (empty($tmp)) return array();
  757. return $tmp['SECURITY_SENDER'];
  758. }/*}}}*/
  759. function checkTable($table)/*{{{*/
  760. {
  761. $sql = 'SHOW TABLES LIKE "'.$table.'"';
  762. #echo $sql;
  763. $this->sql[__FUNCTION__][] = $sql;
  764. $res = mysql_query($sql, $this->db);
  765. $exists = mysql_num_rows($res)>0;
  766. if ($exists) $this->setActiveTable($table); // Aktuelle Tabelle w???hlen
  767. return $exists;
  768. }/*}}}*/
  769. function createTable($table)/*{{{*/
  770. {
  771. $sql = 'CREATE TABLE IF NOT EXISTS `'.$table.'` (
  772. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  773. `meth` char(2) NOT NULL,
  774. `typ` char(2) NOT NULL,
  775. `IDENTIFICATION_UNIQUEID` varchar(32) NOT NULL,
  776. `IDENTIFICATION_SHORTID` varchar(14) NOT NULL,
  777. `IDENTIFICATION_TRANSACTIONID` varchar(255) NOT NULL,
  778. `IDENTIFICATION_REFERENCEID` varchar(32) NOT NULL,
  779. `PROCESSING_RESULT` varchar(20) NOT NULL,
  780. `PROCESSING_RETURN_CODE` varchar(11) NOT NULL,
  781. `PROCESSING_CODE` varchar(11) NOT NULL,
  782. `TRANSACTION_SOURCE` varchar(10) NOT NULL,
  783. `TRANSACTION_CHANNEL` varchar(32) NOT NULL,
  784. `TRANSACTION_RESPONSE` varchar(5) NOT NULL,
  785. `TRANSACTION_MODE` varchar(15) NOT NULL,
  786. `CRITERION_RESPONSE_URL` varchar(255) NOT NULL,
  787. `created` datetime NOT NULL,
  788. `SERIAL` mediumtext NOT NULL,
  789. `XML` mediumtext NOT NULL,
  790. `RESPONSE` mediumtext NOT NULL,
  791. `CAPTURED` int(1) NOT NULL,
  792. PRIMARY KEY (`id`),
  793. KEY `typ` (`typ`),
  794. KEY `meth` (`meth`),
  795. KEY `IDENTIFICATION_UNIQUEID` (`IDENTIFICATION_UNIQUEID`),
  796. KEY `IDENTIFICATION_SHORTID` (`IDENTIFICATION_SHORTID`),
  797. KEY `IDENTIFICATION_TRANSACTIONID` (`IDENTIFICATION_TRANSACTIONID`),
  798. KEY `IDENTIFICATION_REFERENCEID` (`IDENTIFICATION_REFERENCEID`)
  799. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
  800. #echo $sql;
  801. $this->sql[__FUNCTION__][] = $sql;
  802. return mysql_query($sql, $this->db);
  803. }/*}}}*/
  804. function setActiveTable($table)/*{{{*/
  805. {
  806. $this->dbtable = $table;
  807. return $table;
  808. }/*}}}*/
  809. function doAction($action, $loginData, $trxData)/*{{{*/
  810. {
  811. $data = array(
  812. 'SECURITY_SENDER' => $loginData['SECURITY_SENDER'],
  813. 'TRANSACTION_MODE' => $loginData['TRANSACTION_MODE'],
  814. 'TRANSACTION_CHANNEL' => $loginData['TRANSACTION_CHANNEL'],
  815. 'USER_LOGIN' => $loginData['USER_LOGIN'],
  816. 'USER_PWD' => $loginData['USER_PWD'],
  817. 'IDENTIFICATION_TRANSACTIONID' => $trxData['txnid'],
  818. 'IDENTIFICATION_REFERENCEID' => $trxData['uniqueid'],
  819. 'PAYMETHOD' => $trxData['paymethod'],
  820. 'AMOUNT' => $trxData['amount'],
  821. 'CURRENCY' => $trxData['currency'],
  822. 'USAGE' => $trxData['usage'],
  823. 'COMMENT' => $trxData['comment'],
  824. 'FRONTEND_LANGUAGE' => $loginData['FRONTEND_LANGUAGE'],
  825. );
  826. if (!empty($trxData['regid'])) $data['REGID'] = $trxData['regid'];
  827. $reqData = $this->getRequestData($action, $data);
  828. #echo '<pre>'.print_r($reqData, 1).'</pre>';
  829. $url = $this->demo_url;
  830. if ($dat['TRANSATION.MODE'] == 'LIVE') $url = $this->live_url;
  831. #echo $url;
  832. $res = $this->doRequest($url, $reqData);
  833. parse_str($res, $output);
  834. #echo '<pre>'.print_r($res, 1).'</pre>';
  835. return $output;
  836. }/*}}}*/
  837. function getRequestData($action, $dat)/*{{{*/
  838. {
  839. $data = array(
  840. 'SECURITY.SENDER' => $dat['SECURITY_SENDER'],
  841. 'TRANSACTION.MODE' => $dat['TRANSACTION_MODE'],
  842. 'TRANSACTION.RESPONSE' => 'SYNC',
  843. 'TRANSACTION.CHANNEL' => $dat['TRANSACTION_CHANNEL'],
  844. 'USER.LOGIN' => $dat['USER_LOGIN'],
  845. 'USER.PWD' => $dat['USER_PWD'],
  846. 'IDENTIFICATION.TRANSACTIONID' => $dat['IDENTIFICATION_TRANSACTIONID'],
  847. 'IDENTIFICATION.REFERENCEID' => $dat['IDENTIFICATION_REFERENCEID'],
  848. 'CRITERION.COMMENT' => $dat['COMMENT'],
  849. 'PRESENTATION.AMOUNT' => $dat['AMOUNT'],
  850. 'PRESENTATION.CURRENCY' => $dat['CURRENCY'],
  851. 'PRESENTATION.USAGE' => $dat['USAGE'],
  852. 'FRONTEND.LANGUAGE' => $dat['FRONTEND_LANGUAGE'],
  853. );
  854. switch($action){
  855. case 'refund':
  856. $data = array_merge($data, array(
  857. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.RF',
  858. ));
  859. break;
  860. case 'rebill':
  861. $data = array_merge($data, array(
  862. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.RB',
  863. ));
  864. break;
  865. case 'capture':
  866. $data = array_merge($data, array(
  867. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.CP',
  868. ));
  869. break;
  870. case 'reservation':
  871. $data = array_merge($data, array(
  872. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.PA',
  873. 'ACCOUNT.REGISTRATION' => $dat['REGID'],
  874. ));
  875. break;
  876. case 'debit':
  877. $data = array_merge($data, array(
  878. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.DB',
  879. 'ACCOUNT.REGISTRATION' => $dat['REGID'],
  880. ));
  881. break;
  882. case 'reversal':
  883. $data = array_merge($data, array(
  884. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.RV',
  885. ));
  886. break;
  887. case 'schedule':
  888. $data = array_merge($data, array(
  889. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.SD',
  890. ));
  891. break;
  892. case 'deschedule':
  893. $data = array_merge($data, array(
  894. 'PAYMENT.CODE' => $dat['PAYMETHOD'].'.DS',
  895. ));
  896. break;
  897. }
  898. return $data;
  899. }/*}}}*/
  900. function getLanguage($lang, $external = false, $extPath = NULL)/*{{{*/
  901. {
  902. if ($external){
  903. if (empty($extPath)){
  904. $this->error = 'Could not load external Language File '.$filename.' from '.$extPath;
  905. return false;
  906. } else {
  907. $extCSV = $this->doRequest($extPath, array());
  908. #echo '<pre>'.print_r($extCSV, 1).'</pre>';
  909. if (empty($extCSV) || $this->httpstatus != 200 || strpos($extCSV, '#')===false){
  910. $this->error = 'External Language File '.$filename.' from '.$extPath.' was empty';
  911. return false;
  912. } else {
  913. $tmp = array();
  914. $data = explode("\n", $extCSV);
  915. #$data = str_getcsv($extCSV, '#');
  916. #echo '<pre>'.print_r($data, 1).'</pre>';
  917. foreach($data AS $k => $v){
  918. $p = explode('#', trim($v));
  919. $tmp[$p[0]] = $p[1];
  920. }
  921. return $tmp;
  922. }
  923. }
  924. }
  925. $filename = dirname(__FILE__).'/lang_'.strtolower($lang).'.csv';
  926. if (!file_exists($filename)){
  927. $this->error = 'Could not find Language File '.$filename;
  928. return false;
  929. }
  930. if (($handle = fopen($filename, "r")) !== FALSE) {
  931. while (($data = fgetcsv($handle, 1000, "#")) !== FALSE) {
  932. #$data = trim($data);
  933. $tmp[$data[0]] = $data[1];
  934. }
  935. fclose($handle);
  936. } else {
  937. $this->error = 'Could not load Language File '.$filename;
  938. return false;
  939. }
  940. return $tmp;
  941. }/*}}}*/
  942. function setSettings($merID, $settings, $channel)/*{{{*/
  943. {
  944. if (empty($merID)) {
  945. $this->error = __FUNCTION__.': No Merchant ID';
  946. return false;
  947. }
  948. if (empty($settings)) {
  949. $this->error = __FUNCTION__.': No Settings to save';
  950. return false;
  951. }
  952. if (empty($channel)) {
  953. $this->error = __FUNCTION__.': No Channel to save';
  954. return false;
  955. }
  956. $sql = 'UPDATE `'.$this->table_config.'` SET ';
  957. foreach($settings AS $k => $v){
  958. $sql.= ' `'.addslashes($k).'` = "'.addslashes($v).'", ';
  959. }
  960. $sql.= '`lastChanged` = NOW() ';
  961. $sql.= 'WHERE `SECURITY_SENDER` = "'.addslashes($merID).'"
  962. AND `TRANSACTION_CHANNEL` = "'.addslashes($channel).'" ';
  963. #echo $sql.'<br>';
  964. $this->sql[__FUNCTION__][] = $sql;
  965. $res = mysql_query($sql, $this->db);
  966. return mysql_errno($this->db)==0;
  967. }/*}}}*/
  968. function newSettings($merID, $channel)/*{{{*/
  969. {
  970. if (empty($merID)) {
  971. $this->error = __FUNCTION__.': No Merchant ID';
  972. return false;
  973. }
  974. if (empty($channel)) {
  975. $this->error = __FUNCTION__.': No Channel to save';
  976. return false;
  977. }
  978. $sql = 'INSERT INTO `'.$this->table_config.'` SET
  979. `created` = NOW(),
  980. `SECURITY_SENDER` = "'.addslashes($merID).'",
  981. `TRANSACTION_CHANNEL` = "'.addslashes($channel).'"
  982. ';
  983. #echo $sql.'<br>';
  984. $this->sql[__FUNCTION__][] = $sql;
  985. $res = mysql_query($sql, $this->db);
  986. return mysql_errno($this->db)==0;
  987. }/*}}}*/
  988. function getSettings($merID)/*{{{*/
  989. {
  990. if (empty($merID)) {
  991. $this->error = __FUNCTION__.': No Merchant ID';
  992. return false;
  993. }
  994. $sql = 'SELECT * FROM `'.$this->table_config.'`
  995. WHERE `SECURITY_SENDER` = "'.addslashes($merID).'"
  996. ';
  997. #echo $sql;
  998. $this->sql[__FUNCTION__][] = $sql;
  999. $res = mysql_query($sql, $this->db);
  1000. $exists = mysql_num_rows($res)>0;
  1001. if (!$exists) {
  1002. $this->error = 'No Settings Config found for '.$merID;
  1003. return false;
  1004. }
  1005. $tmp = array();
  1006. while($row = mysql_fetch_assoc($res)){
  1007. $tmp[$row['TRANSACTION_CHANNEL']] = $row;
  1008. $tmp[$row['TRANSACTION_CHANNEL']]['rates'] = $this->getRatesByOwner($row['id']);
  1009. }
  1010. return $tmp;
  1011. }/*}}}*/
  1012. function setRate($owner, $id, $rate)/*{{{*/
  1013. {
  1014. if (empty($owner)) {
  1015. $this->error = __FUNCTION__.': No Owner ID';
  1016. return false;
  1017. }
  1018. if (empty($id)) {
  1019. $this->error = __FUNCTION__.': No ID';
  1020. return false;
  1021. }
  1022. if (empty($rate)) {
  1023. $this->error = __FUNCTION__.': No rate to save';
  1024. return false;
  1025. }
  1026. $sql = 'UPDATE `'.$this->table_rates.'` SET ';
  1027. foreach($rate AS $k => $v){
  1028. $sql.= ' `'.addslashes($k).'` = "'.addslashes($v).'", ';
  1029. }
  1030. $sql.= '`owner` = '.addslashes($owner).' ';
  1031. $sql.= 'WHERE `owner` = "'.addslashes($owner).'" AND `id` = "'.(int)$id.'" ';
  1032. #echo $sql.'<br>';
  1033. $this->sql[__FUNCTION__][] = $sql;
  1034. $res = mysql_query($sql, $this->db);
  1035. return mysql_errno($this->db)==0;
  1036. }/*}}}*/
  1037. function removeRate($owner, $id)/*{{{*/
  1038. {
  1039. if (empty($owner)) {
  1040. $this->error = __FUNCTION__.': No Owner ID';
  1041. return false;
  1042. }
  1043. if (empty($id)) {
  1044. $this->error = __FUNCTION__.': No ID';
  1045. return false;
  1046. }
  1047. $sql = 'DELETE FROM `'.$this->table_rates.'` ';
  1048. $sql.= 'WHERE `owner` = "'.addslashes($owner).'"
  1049. AND `id` = "'.(int)$id.'" ';
  1050. #echo $sql.'<br>';
  1051. $this->sql[__FUNCTION__][] = $sql;
  1052. $res = mysql_query($sql, $this->db);
  1053. return mysql_errno($this->db)==0;
  1054. }/*}}}*/
  1055. function addRate($owner, $rate)/*{{{*/
  1056. {
  1057. if (empty($owner)) {
  1058. $this->error = __FUNCTION__.': No Owner ID';
  1059. return false;
  1060. }
  1061. if (empty($rate)) {
  1062. $this->error = __FUNCTION__.': No rate to save';
  1063. return false;
  1064. }
  1065. $sql = 'INSERT `'.$this->table_rates.'` SET ';
  1066. foreach($rate AS $k => $v){
  1067. $sql.= ' `'.addslashes($k).'` = "'.addslashes($v).'", ';
  1068. }
  1069. $sql.= '`owner` = '.addslashes($owner).' ';
  1070. #echo $sql.'<br>';
  1071. $this->sql[__FUNCTION__][] = $sql;
  1072. $res = mysql_query($sql, $this->db);
  1073. return mysql_insert_id($this->db)>0;
  1074. }/*}}}*/
  1075. function getRatesByOwner($owner)/*{{{*/
  1076. {
  1077. $sql = 'SELECT * FROM `'.$this->table_rates.'`
  1078. WHERE `owner` = "'.$owner.'"
  1079. ORDER BY `kind`,`sortorder` ASC
  1080. ';
  1081. #echo $sql;
  1082. $this->sql[__FUNCTION__][] = $sql;
  1083. $res = mysql_query($sql, $this->db);
  1084. $tmp = array();
  1085. while($row = mysql_fetch_assoc($res)){
  1086. $tmp[$row['kind']][$row['id']] = $row;
  1087. }
  1088. return $tmp;
  1089. }/*}}}*/
  1090. function getConfig($merID, $channel)/*{{{*/
  1091. {
  1092. $sql = 'SELECT * FROM `'.$this->table_config.'`
  1093. WHERE `SECURITY_SENDER` = "'.addslashes($merID).'"
  1094. AND `TRANSACTION_CHANNEL` = "'.addslashes($channel).'"
  1095. ';
  1096. #echo $sql;
  1097. $this->sql[__FUNCTION__][] = $sql;
  1098. $res = mysql_query($sql, $this->db);
  1099. $exists = mysql_num_rows($res)>0;
  1100. if (!$exists) {
  1101. $sql = 'INSERT INTO `'.$this->table_config.'`
  1102. SET `SECURITY_SENDER` = "'.addslashes($merID).'",
  1103. `TRANSACTION_CHANNEL` = "'.addslashes($channel).'",
  1104. `allowABO` = "0",
  1105. `allowRATE` = "0",
  1106. `created` = NOW()
  1107. ';
  1108. mysql_query($sql, $this->db);
  1109. return $this->getConfig($merID, $channel);
  1110. }
  1111. $row = mysql_fetch_assoc($res);
  1112. return $row;
  1113. }/*}}}*/
  1114. function getRates($merID, $channel, $amount = NULL, $currency = 'EUR')/*{{{*/
  1115. {
  1116. if (empty($merID)) {
  1117. $this->error = __FUNCTION__.': Missing merID!';
  1118. return array();
  1119. }
  1120. if (empty($channel)) {
  1121. $this->error = __FUNCTION__.': Missing channel!';
  1122. return array();
  1123. }
  1124. $config = $this->getConfig($merID, $channel);
  1125. $sql = 'SELECT * FROM `'.$this->table_rates.'`
  1126. WHERE `owner` = "'.$config['id'].'"
  1127. ORDER BY `kind`,`sortorder` ASC
  1128. ';
  1129. #echo $sql;
  1130. $this->sql[__FUNCTION__][] = $sql;
  1131. $res = mysql_query($sql, $this->db);
  1132. $tmp = array();
  1133. while($row = mysql_fetch_assoc($res)){
  1134. $tmp[$row['kind']][$row['id']] = $row;
  1135. if ($amount > 0){
  1136. // Ratenzahlung
  1137. if ($row['kind'] == 'rate'){
  1138. $duraInDays = $this->duration2days[$row['durationtype']] * $row['duration'];
  1139. $freqInDays = $this->duration2days[$row['freqtype']] * $row['freq'];
  1140. $efDuration = floor($duraInDays / $freqInDays) + 1; // Plus 1 wegen der Initrate
  1141. $tmp[$row['kind']][$row['id']]['duraInDays'] = $duraInDays;
  1142. $tmp[$row['kind']][$row['id']]['freqInDays'] = $freqInDays;
  1143. #echo $duraInDays.' duraInDays '.$freqInDays.' freqInDays '.$efDuration.'<br>';
  1144. if ($row['feetype'] == 'percent'){
  1145. $rate_amount = $amount + ($amount / 100) * ($row['fee'] / 100);
  1146. } else {
  1147. $rate_amount = $amount + ($row['fee'] / 100);
  1148. }
  1149. $rate_amount = sprintf('%1.2f', $rate_amount); // Da sonst zu viele Nachkommastellen entstehen k???nnen
  1150. $piece = floor($rate_amount / $efDuration);
  1151. $rest = $piece + ($rate_amount - ($piece * $efDuration));
  1152. #echo $rate_amount.' % '.$efDuration.'='.$piece.' rest: '.$rest.'<br>';
  1153. // Anzahlung
  1154. } else if ($row['kind'] == 'deposit'){
  1155. $duraInDays = $this->duration2days[$row['durationtype']] * $row['duration'];
  1156. $tmp[$row['kind']][$row['id']]['duraInDays'] = $duraInDays;
  1157. $tmp[$row['kind']][$row['id']]['freqInDays'] = 0;
  1158. #echo $duraInDays.' duraInDays '.$freqInDays.' freqInDays '.$efDuration.'<br>';
  1159. if ($row['feetype'] == 'percent'){
  1160. $rest = ($amount / 100) * ($row['fee'] / 100); // Erste Zahlung
  1161. $rest = sprintf('%1.2f', $rest); // Da sonst zu viele Nachkommastellen entstehen k???nnen
  1162. $piece = $amount - $rest; // Zweite Zahlung
  1163. } else {
  1164. $rest = ($row['fee'] / 100); // Erste Zahlung
  1165. $rest = sprintf('%1.2f', $rest); // Da sonst zu viele Nachkommastellen entstehen k???nnen
  1166. $piece = $amount - $rest; // Zweite Zahlung
  1167. }
  1168. $rate_amount = $amount;
  1169. #echo $rate_amount.' % '.$efDuration.'='.$piece.' rest: '.$rest.'<br>';
  1170. // Abozahlung
  1171. } else if ($row['kind'] == 'abo'){
  1172. $freqInDays = $this->duration2days[$row['freqtype']] * $row['freq'];
  1173. $tmp[$row['kind']][$row['id']]['duraInDays'] = 0;
  1174. $tmp[$row['kind']][$row['id']]['freqInDays'] = $freqInDays;
  1175. if ($row['feetype'] == 'percent'){
  1176. $rate_amount = $amount + ($amount / 100) * ($row['fee'] / 100);
  1177. } else {
  1178. $rate_amount = $amount + ($row['fee'] / 100);
  1179. }
  1180. $rate_amount = sprintf('%1.2f', $rate_amount); // Da sonst zu viele Nachkommastellen entstehen k???nnen
  1181. #echo $rate_amount.'<br>';
  1182. }
  1183. $tmp[$row['kind']][$row['id']]['rate_amount'] = $piece;
  1184. $tmp[$row['kind']][$row['id']]['rate_first'] = $rest;
  1185. $tmp[$row['kind']][$row['id']]['currency'] = $currency;
  1186. $tmp[$row['kind']][$row['id']]['amount'] = $amount;
  1187. $tmp[$row['kind']][$row['id']]['newamount'] = $rate_amount;
  1188. }
  1189. }
  1190. return $tmp;
  1191. }/*}}}*/
  1192. }
  1193. function x($text)/*{{{*/
  1194. {
  1195. if (!empty($_SESSION['language_cache'][$text])){
  1196. return $_SESSION['language_cache'][$text];
  1197. }
  1198. if (isset($_SESSION['language_cache'][$text])) return $text; // Da schon Eintrag vorhanden, braucht es nicht neu in die Datei
  1199. $filename = 'lang_'.$_SESSION['actual_language'].'.csv';
  1200. if ($handle = fopen($filename, 'a')) {
  1201. if ($_SESSION['actual_language'] == 'de'){
  1202. $somecontent = $text.'#'."\n";
  1203. } else {
  1204. $somecontent = '#'.$text."\n";
  1205. }
  1206. fwrite($handle, $somecontent);
  1207. fclose($handle);
  1208. }
  1209. return $text;
  1210. }/*}}}*/
  1211. ?>