PageRenderTime 47ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/iclear/iclear_wsdl.php

https://github.com/tisoft/xtcmodified
PHP | 347 lines | 178 code | 31 blank | 138 comment | 35 complexity | ac446bf9c1b907588f58a0822972e4ce MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. // $Id: iclear_wsdl.php,v 1.1 2007/03/18 19:51:15 dis Exp $
  3. /*
  4. iclear payment system - because secure is simply secure
  5. http://www.iclear.de
  6. Copyright (c) 2001 - 2006 iclear
  7. Released under the GNU General Public License
  8. ************************************************************************
  9. Copyright (C) 2005 - 2006 BSE, David Brandt
  10. All rights reserved.
  11. This program is free software licensed under the GNU General Public License (GPL).
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  23. USA
  24. *************************************************************************/
  25. // some installation come with php5 SOAP extension
  26. include(DIR_FS_CATALOG . 'includes/iclear/nusoap.php');
  27. require(DIR_FS_CATALOG . 'includes/iclear/iclear_error.php');
  28. define ('ICLEAR_URI_BASE', 'http://www.iclear.de/');
  29. define ('ICLEAR_URI_ORDER', ICLEAR_URI_BASE . 'ICOrderServices.wsdl');
  30. define ('ICLEAR_URI_USER', ICLEAR_URI_BASE . 'ICUserServices.wsdl');
  31. /**
  32. * The iclearWSDL provides the basic services to access the iclear WSDL payment interface
  33. * It expects values in preformatted manner.
  34. * For specification refer to the iclear WSDL / DMI documentation
  35. *
  36. */
  37. class iclearWSDL extends iclearError {
  38. var $uriUser = ICLEAR_URI_USER;
  39. var $uriOrder = ICLEAR_URI_ORDER;
  40. var $currency = 'EUR'; // default currency is euro
  41. var $language = 'DE'; // default language is german
  42. var $basket;
  43. var $basketID;
  44. var $sessionID = '';
  45. var $requestID = '';
  46. var $wsdlResult = false;
  47. var $wsdlOrder = false;
  48. /**
  49. * constructor
  50. * expects at least the type of the WSDL client, which should be created (user/order)
  51. * in case of order a shopID must be provided
  52. * is in case of user a name and a password is given, a login will be performed
  53. *
  54. * @param [user|order] $type
  55. * @param int $shopID
  56. * @param string $sessionID
  57. * @param string $user
  58. * @param string $pass
  59. * @return iclearWSDL
  60. */
  61. function iclearWSDL($type, $shopID = '', $sessionID = '', $user = '', $pass = '') {
  62. $this->sessionID = $sessionID;
  63. $rc = false;
  64. if($this->client = $this->initWsdlClient($type)) {
  65. $this->type = $type;
  66. $this->shopID = $shopID;
  67. if($this->proxy = $this->client->getProxy()) {
  68. $rc = true;
  69. if($user) {
  70. $rc = $this->connect($user, $pass);
  71. }
  72. }
  73. } else {
  74. $this->addError('iclearWSDL: Unable 2 get proxy!');
  75. }
  76. return $rc;
  77. }
  78. function initWsdlClient($type) {
  79. if($type) {
  80. // check if we're working with nusoap or the PHP extension and setup options
  81. switch($type) {
  82. case 'user':
  83. $this->client = new nusoapclient($this->uriUser, 'wsdl');
  84. break;
  85. case 'order':
  86. $this->client = new nusoapclient($this->uriOrder, 'wsdl');
  87. break;
  88. default:
  89. $this->client = false;
  90. }
  91. } else {
  92. $this->client = false;
  93. }
  94. return $this->client;
  95. }
  96. /**
  97. * Check if a connection error occured
  98. *
  99. * @return string errorMsg
  100. */
  101. function isWsdlError() {
  102. $rc = '';
  103. if(is_object($this->proxy) && ($rc = $this->proxy->getError())) {
  104. $this->addError('nusoap proxy: ' . $rc);
  105. } elseif(is_object($this->proxy) && ($rc = $this->client->getError())) {
  106. $this->addError('nusoap client: ' . $rc);
  107. }
  108. return $rc;
  109. }
  110. /**
  111. * connect a user type session to the iclear interface an retrieve requestID
  112. *
  113. * @param string $user
  114. * @param string $pass
  115. */
  116. function connectWsdl($user, $pass) {
  117. $res = $this->proxy->login($user, $pass, $this->sessionID);
  118. if(!$this->isWsdlError()) {
  119. $this->requestID = $res['requestID'];
  120. }
  121. !$this->getErrorCount();
  122. }
  123. /**
  124. * setter 4 the currency. defaults to EUR
  125. *
  126. * @param string $currency
  127. * @return string
  128. */
  129. function setWsdlCurrency ($currency = 'EUR') {
  130. return $this->currency = $currency;
  131. }
  132. /**
  133. * setter 4 the language. defaults 2 DE
  134. *
  135. * @param string $language
  136. * @return string
  137. */
  138. function setWsdlLanguage ($language = 'DE') {
  139. return $this->language = $language;
  140. }
  141. /**
  142. * set the sessionID which is used during wsdl requests
  143. *
  144. * @param string $sessionID
  145. */
  146. function setWsdlSessionID ($sessionID = '') {
  147. if($sessionID) {
  148. $this->sessionID = $sessionID;
  149. }
  150. }
  151. /**
  152. * load the wsdl basket into object
  153. * WARNING: the basket must be in the correct format or sendOrder / sendOrderS2S request will fail
  154. * sets automatically the basketID
  155. *
  156. * @param array $basket
  157. * @return string basketID
  158. */
  159. function setWsdlBasket(&$basket) {
  160. $this->basketID = 0;
  161. if (!$basket) {
  162. $this->addError('setWsdlOrder: Basket not present!');
  163. } elseif (!sizeof($basket)) {
  164. $this->addError('setWsdlOrder: Basket empty!');
  165. } else {
  166. // here the basket processing goes
  167. $this->basketID = md5(microtime() . $this->sessionID);
  168. }
  169. return $this->basketID;
  170. }
  171. /**
  172. * Get billing address of a (loged in!) user from iclear
  173. *
  174. * @return array
  175. */
  176. function getWsdlBillingAddress() {
  177. if(!$this->requestID) {
  178. $this->addError('getWsdlBillingAddress: No requestID found!');
  179. } else {
  180. $res = $this->proxy->getWsdlAddressList($this->requestID, $this->sessionID);
  181. if(!$this->isError()) {
  182. $address = $res['resultElements']['Address'][0];
  183. }
  184. }
  185. return $address;
  186. }
  187. /**
  188. * Get delivery address of a (loged in!) user from iclear
  189. *
  190. * @return array
  191. */
  192. function getWsdlDeliveryAddress() {
  193. if(!$this->requestID) {
  194. $this->addError('getWsdlDeliveryAddress: No requestID found!');
  195. } else {
  196. $res = $this->proxy->getWsdlAddressList($this->requestID, $this->sessionID);
  197. if(!$this->isError()) {
  198. $address = $res['resultElements']['Address'][1];
  199. }
  200. }
  201. return $address;
  202. }
  203. /**
  204. * Get user addressID from iclear
  205. *
  206. * @param [billing|delivery] $type
  207. * @return int
  208. */
  209. function getWsdlAddressID($type) {
  210. $addressID = 0;
  211. switch($type) {
  212. case 'billing':
  213. if($address = $this->getWsdlBillingAddress()) {
  214. $addressID = $address['addrID'];
  215. }
  216. break;
  217. case 'delivery':
  218. if($address = $this->getWsdlDeliveryAddress()) {
  219. $addressID = $address['addrID'];
  220. }
  221. break;
  222. }
  223. return $addressID;
  224. }
  225. /**
  226. * send a order without user interaction
  227. * for this feature a special agreement with iclear must be present
  228. * and the shop is responsible 4 the authentification / authentication and the data
  229. * integrity of the transported information
  230. * Note: The user must be loged in first!
  231. *
  232. * @param int $userAddrID
  233. * @param string $currency
  234. * @param array $basket
  235. * @return boolean
  236. */
  237. function sendWsdlOrderS2S ($userAddrID, $currency, $basket) {
  238. $rc = false;
  239. if(!$this->shopID) {
  240. $this->addError('sendOrderS2S: No ShopID found!');
  241. } elseif (!$this->requestID) {
  242. $this->addError('sendOrderS2S: No requestID found!');
  243. } else {
  244. $res = $this->proxy->sendOrderS2S($this->requestID, $userAddrID, $this->shopID, md5(time()), $currence, $basket, $this->sessionID);
  245. if(!$this->isError()) {
  246. if((int)$res['status']) {
  247. $this->addError('sendOrderS2S: Error from iclear: ' . $res['statusMessage']);
  248. } else {
  249. $rc = true;
  250. }
  251. }
  252. }
  253. return $rc;
  254. }
  255. /**
  256. * send basket 2 iclear wsdl interface and collects result
  257. *
  258. * @return array wsdlResult
  259. */
  260. function sendWsdlOrder () {
  261. $this->wsdlResult = false;
  262. if(!$this->shopID) {
  263. $this->addError('sendOrder: No ShopID found!');
  264. } elseif (!$this->basket) {
  265. $this->addError('sendOrder: Basket not present!');
  266. } elseif (!sizeof($this->basket)) {
  267. $this->addError('sendOrder: Basket empty!');
  268. } else {
  269. $res = $this->proxy->sendOrder($this->shopID, $this->basketID, $this->currency, $this->basket, $this->sessionID, $this->language);
  270. if(!$this->isWsdlError()) {
  271. if(isset($res['status'])) {
  272. if(!(int)$res['status'] || (int)$res['status'] == 1) {
  273. $this->requestID = $res['requestID'];
  274. // here order ok
  275. $this->wsdlResult =& $res;
  276. } else {
  277. $this->addError('sendOrder: Error from iclear: ' . $res['statusMessage']);
  278. }
  279. }
  280. } else {
  281. $this->addError('SendWsdlOrder: Interface error - ' . $res['detail']['string']);
  282. }
  283. }
  284. return $this->wsdlResult;
  285. } //sendOrder()
  286. /**
  287. * abstract method which is used to store the intermediate basket and orders in
  288. * the iclear table.
  289. * Must be provided by the inheriting class!
  290. * See: iclearCatalog
  291. *
  292. */
  293. function storeWsdlOrder() {
  294. die("Abstract method storeWsdlOrder() of class iclearWSDL called!");
  295. }
  296. /**
  297. * abstract method which is used to load the intermeidiate basket and orders from
  298. * the iclear table.
  299. * Must be provided by the inheriting class!
  300. * See: iclearCatalog
  301. *
  302. */
  303. function loadWsdlOrder() {
  304. die("Abstract method loadWsdlOrder() of class iclearWSDL called!");
  305. }
  306. }// class
  307. ?>