PageRenderTime 32ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/classes/paypal_checkout.php

https://bitbucket.org/flth/xtcm
PHP | 1456 lines | 1223 code | 0 blank | 233 comment | 172 complexity | ebb07b6ab38649b3391328a00f316083 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. * Project: xt:Commerce - eCommerce Engine
  4. * @version $Id
  5. *
  6. * xt:Commerce - Shopsoftware
  7. * (c) 2003-2007 xt:Commerce (Winger/Zanier), http://www.xt-commerce.com
  8. *
  9. * xt:Commerce ist eine gesch�tzte Handelsmarke und wird vertreten durch die xt:Commerce GmbH (Austria)
  10. * xt:Commerce is a protected trademark and represented by the xt:Commerce GmbH (Austria)
  11. *
  12. * @copyright Copyright 2003-2007 xt:Commerce (Winger/Zanier), www.xt-commerce.com
  13. * @copyright based on Copyright 2002-2003 osCommerce; www.oscommerce.com
  14. * @copyright Porttions Copyright 2003-2007 Zen Cart Development Team
  15. * @copyright Porttions Copyright 2004 DevosC.com
  16. * @license http://www.xt-commerce.com.com/license/2_0.txt GNU Public License V2.0
  17. *
  18. * For questions, help, comments, discussion, etc., please join the
  19. * xt:Commerce Support Forums at www.xt-commerce.com
  20. *
  21. * ab 15.08.2008 Teile vom Hamburger-Internetdienst ge�ndert
  22. * Hamburger-Internetdienst Support Forums at www.forum.hamburger-internetdienst.de
  23. * Stand: 16.05.2010
  24. */
  25. require_once(DIR_FS_INC . 'xtc_write_user_info.inc.php');
  26. define('PROXY_HOST', '127.0.0.1');
  27. define('PROXY_PORT', '808');
  28. define('VERSION', PAYPAL_API_VERSION);
  29. class paypal_checkout {
  30. var $API_UserName,
  31. $API_Password,
  32. $API_Signature,
  33. $API_Endpoint,
  34. $version,
  35. $location_error,
  36. $NOTIFY_URL,
  37. $EXPRESS_CANCEL_URL,
  38. $EXPRESS_RETURN_URL,
  39. $CANCEL_URL,
  40. $RETURN_URL,
  41. $GIROPAY_SUCCESS_URL,
  42. $GIROPAY_CANCEL_URL,
  43. $BANKTXN_PENDING_URL,
  44. $EXPRESS_URL,
  45. $GIROPAY_URL,
  46. $IPN_URL,
  47. $ppAPIec,
  48. $payPalURL;
  49. /*************************************************************/
  50. function paypal_checkout() {
  51. // Stand: 27.03.2010
  52. if(PAYPAL_MODE=='sandbox'){
  53. $this->API_UserName = PAYPAL_API_SANDBOX_USER;
  54. $this->API_Password = PAYPAL_API_SANDBOX_PWD;
  55. $this->API_Signature = PAYPAL_API_SANDBOX_SIGNATURE;
  56. $this->API_Endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
  57. $this->EXPRESS_URL = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=';
  58. $this->GIROPAY_URL = 'https://www.sandbox.paypal.com/webscr?cmd=_complete-express-checkout&token=';
  59. $this->IPN_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
  60. }elseif(PAYPAL_MODE=='live'){
  61. $this->API_UserName = PAYPAL_API_USER;
  62. $this->API_Password = PAYPAL_API_PWD;
  63. $this->API_Signature = PAYPAL_API_SIGNATURE;
  64. $this->API_Endpoint = 'https://api-3t.paypal.com/nvp';
  65. $this->EXPRESS_URL = 'https://www.paypal.com/webscr?cmd=_express-checkout&token=';
  66. $this->GIROPAY_URL = 'https://www.paypal.com/webscr?cmd=_complete-express-checkout&token=';
  67. $this->IPN_URL = 'https://www.paypal.com/cgi-bin/webscr';
  68. }
  69. if(ENABLE_SSL == true){
  70. $this->NOTIFY_URL = HTTPS_SERVER.DIR_WS_CATALOG.'callback/paypal/ipn.php';
  71. $this->EXPRESS_CANCEL_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_SHOPPING_CART.'?XTCsid='.xtc_session_id();
  72. $this->EXPRESS_RETURN_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_PAYPAL_CHECKOUT.'?XTCsid='.xtc_session_id();
  73. $this->PRE_CANCEL_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PAYMENT.'?XTCsid='.xtc_session_id();
  74. $this->CANCEL_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PAYMENT.'?XTCsid='.xtc_session_id().'&error=true&error_message='.PAYPAL_ERROR;
  75. $this->RETURN_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PROCESS.'?XTCsid='.xtc_session_id();
  76. $this->GIROPAY_SUCCESS_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_SUCCESS.'?XTCsid='.xtc_session_id();
  77. $this->GIROPAY_CANCEL_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_SHOPPING_CART.'?XTCsid='.xtc_session_id();
  78. $this->BANKTXN_PENDING_URL = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_SUCCESS.'?XTCsid='.xtc_session_id();
  79. }else{
  80. $this->NOTIFY_URL = HTTP_SERVER.DIR_WS_CATALOG.'callback/paypal/ipn.php';
  81. $this->EXPRESS_CANCEL_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_SHOPPING_CART.'?XTCsid='.xtc_session_id();
  82. $this->EXPRESS_RETURN_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_PAYPAL_CHECKOUT.'?XTCsid='.xtc_session_id();
  83. $this->PRE_CANCEL_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PAYMENT.'?XTCsid='.xtc_session_id();
  84. $this->CANCEL_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PAYMENT.'?XTCsid='.xtc_session_id().'&error=true&error_message='.PAYPAL_ERROR;
  85. $this->RETURN_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PROCESS.'?XTCsid='.xtc_session_id();
  86. $this->GIROPAY_SUCCESS_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_SUCCESS.'?XTCsid='.xtc_session_id();
  87. $this->GIROPAY_CANCEL_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_SHOPPING_CART.'?XTCsid='.xtc_session_id();
  88. $this->BANKTXN_PENDING_URL = HTTP_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_SUCCESS.'?XTCsid='.xtc_session_id();
  89. }
  90. $this->version = VERSION;
  91. $this->USE_PROXY = FALSE;
  92. $this->payPalURL = '';
  93. $this->ppAPIec = $this->buildAPIKey(PAYPAL_API_KEY, 'ec');
  94. if(ENABLE_SSL == true):
  95. $hdrImg='templates/'.CURRENT_TEMPLATE.'/img/'.PAYPAL_API_IMAGE;
  96. if(file_exists(DIR_FS_CATALOG.$hdrImg) AND PAYPAL_API_IMAGE!=''):
  97. $hdrSize = getimagesize(DIR_FS_CATALOG.$hdrImg);
  98. if($hdrSize[0]<=750 AND $hdrSize[1]<=90):
  99. $this->Image = urlencode(HTTPS_SERVER.DIR_WS_CATALOG.$hdrImg);
  100. endif;
  101. endif;
  102. endif;
  103. // BOF - Hetfield - 2009-11-19 - replaced deprecated function ereg with preg_match to be ready for PHP >= 5.3
  104. //if(ereg('^(([a-f]|[A-F]|[0-9]){6})$',PAYPAL_API_CO_BACK))
  105. if(preg_match('/^(([a-f]|[A-F]|[0-9]){6})$/',PAYPAL_API_CO_BACK))
  106. $this->BackColor = PAYPAL_API_CO_BACK;
  107. //if(ereg('^(([a-f]|[A-F]|[0-9]){6})$',PAYPAL_API_CO_BORD))
  108. if(preg_match('/^(([a-f]|[A-F]|[0-9]){6})$/',PAYPAL_API_CO_BORD))
  109. $this->BorderColor = PAYPAL_API_CO_BORD;
  110. // EOF - Hetfield - 2009-11-19 - replaced deprecated function ereg with preg_match to be ready for PHP >= 5.3
  111. }
  112. /*************************************************************/
  113. function build_express_checkout_button(){
  114. // Stand: 01.06.2009
  115. global $PHP_SELF;
  116. if($_SESSION['allow_checkout'] == 'true' AND $_SESSION['cart']->show_total()>0 AND MODULE_PAYMENT_PAYPALEXPRESS_STATUS=='True'):
  117. $unallowed_modules = explode(',', $_SESSION['customers_status']['customers_status_payment_unallowed']);
  118. if(!in_array('paypalexpress', $unallowed_modules)):
  119. include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/paypalexpress.php');
  120. $alt=((defined('MODULE_PAYMENT_PAYPALEXPRESS_ALT_BUTTON'))? MODULE_PAYMENT_PAYPALEXPRESS_ALT_BUTTON :'PayPal');
  121. $source=((strtoupper($_SESSION['language_code'])=='DE')?'epaypal_de.gif':'epaypal_en.gif');
  122. $button .= '<a style="cursor:pointer;" onfocus="if(this.blur) this.blur();" onmouseover="window.status = '."''".'; return true;" href="'.xtc_href_link(basename($PHP_SELF), xtc_get_all_get_params(array('action')).'action=paypal_express_checkout').'"><img src="'.DIR_WS_ICONS.$source.'" alt="'.$alt.'" title="'.$alt.'" /></a>';
  123. return $button;
  124. endif;
  125. endif;
  126. return;
  127. }
  128. /*************************************************************/
  129. function build_express_fehler_button(){
  130. // Stand: 01.06.2009
  131. if(MODULE_PAYMENT_PAYPALEXPRESS_STATUS=='True'){
  132. include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/paypalexpress.php');
  133. $alt=((defined('MODULE_PAYMENT_PAYPALEXPRESS_ALT_BUTTON'))? MODULE_PAYMENT_PAYPALEXPRESS_ALT_BUTTON :'PayPal');
  134. $source=((strtoupper($_SESSION['language_code'])=='DE')?'epaypal_de.gif':'epaypal_en.gif');
  135. $button .= '<a style="cursor:pointer;" onfocus="if(this.blur) this.blur();" onmouseover="window.status = '."''".'; return true;" href="'.$this->EXPRESS_CANCEL_URL.'"><img src="'.DIR_WS_ICONS.$source.'" alt="'.$alt.'" title="'.$alt.'" /></a>';
  136. return $button;
  137. }
  138. return;
  139. }
  140. /*************************************************************/
  141. /******* f�rs express als Zahlbedingung **********************/
  142. /*************************************************************/
  143. function paypal_auth_call(){
  144. // aufruf aus paypal.php NICHT f�r PP Express aus Warenkorb
  145. // Daten aus der Cart - Order noch nicht gespeichert
  146. // 1. Call um die Token ID zu bekommen
  147. // Daten mitgeben, da direkt best�tigung ohne nochmaliges Confirm im Shop
  148. // Stand: 05.01.2010
  149. global $xtPrice,$order;
  150. // Session s�ubern
  151. unset($_SESSION['reshash']);
  152. unset($_SESSION['nvpReqArray']);
  153. require(DIR_WS_CLASSES.'order_total.php');
  154. $order_total_modules = new order_total();
  155. $order_totals = $order_total_modules->process();
  156. $order_tax=0;
  157. $order_discount=0;
  158. $order_fee=0;
  159. $order_gs=0;
  160. $order_shipping=0;
  161. for($i = 0, $n = sizeof($order_totals); $i < $n; $i ++):
  162. switch($order_totals[$i]['code']):
  163. case 'ot_total':
  164. $paymentAmount=$order_totals[$i]['value'];
  165. break;
  166. case 'ot_shipping':
  167. $order_shipping=$order_totals[$i]['value'];
  168. break;
  169. case 'ot_tax':
  170. $order_tax+=$order_totals[$i]['value'];
  171. break;
  172. case 'ot_discount':
  173. $order_discount+=$order_totals[$i]['value'];
  174. break;
  175. case 'ot_coupon':
  176. $order_gs+= ($order_totals[$i]['value'] < 0) ? $order_totals[$i]['value'] : $order_totals[$i]['value'] *(-1);
  177. break;
  178. case 'ot_gv':
  179. $order_gs+= ($order_totals[$i]['value'] < 0) ? $order_totals[$i]['value'] : $order_totals[$i]['value'] *(-1);
  180. break;
  181. /// customers bonus
  182. case 'ot_bonus_fee':
  183. $order_gs+= ($order_totals[$i]['value'] < 0) ? $order_totals[$i]['value'] : $order_totals[$i]['value'] *(-1);
  184. break;
  185. case 'ot_payment':
  186. if($order_totals[$i]['value'] < 0): // Rabatt aus Fremd Modul
  187. $order_discount+=$order_totals[$i]['value'];
  188. else:
  189. $order_fee+=$order_totals[$i]['value'];
  190. endif;
  191. break;
  192. case 'ot_cod_fee':
  193. $order_fee+=$order_totals[$i]['value'];
  194. break;
  195. case 'ot_ps_fee':
  196. $order_fee+=$order_totals[$i]['value'];
  197. break;
  198. case 'ot_loworderfee':
  199. $order_fee+=$order_totals[$i]['value'];
  200. endswitch;
  201. endfor;
  202. // AMT
  203. $paymentAmount = round($paymentAmount, $xtPrice->get_decimal_places($order->info['currency']));
  204. // Summen der Order
  205. $order_tax=round($order_tax, $xtPrice->get_decimal_places($order->info['currency']));
  206. $order_discount=round($order_discount, $xtPrice->get_decimal_places($order->info['currency']));
  207. $order_gs=round($order_gs, $xtPrice->get_decimal_places($order->info['currency']));
  208. $order_fee=round($order_fee, $xtPrice->get_decimal_places($order->info['currency']));
  209. $order_shipping=round($order_shipping, $xtPrice->get_decimal_places($order->info['currency']));
  210. $nvp_products=$this->paypal_get_products($paymentAmount,$order_tax,$order_discount,$order_fee,$order_shipping,$order_gs);
  211. $paymentAmount = urlencode(number_format($paymentAmount, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  212. $currencyCodeType = urlencode($order->info['currency']);
  213. // Payment Type
  214. $paymentType='Sale';
  215. // The returnURL is the location where buyers return when a
  216. // payment has been succesfully authorized.
  217. // The cancelURL is the location buyers are sent to when they hit the
  218. // cancel button during authorization of payment during the PayPal flow
  219. $returnURL =urlencode($this->RETURN_URL);
  220. $cancelURL =urlencode($this->CANCEL_URL);
  221. $gpsucssesURL =urlencode($this->GIROPAY_SUCCESS_URL);
  222. $gpcancelURL =urlencode($this->GIROPAY_CANCEL_URL);
  223. $bankpending =urlencode($this->BANKTXN_PENDING_URL);
  224. // Construct the parameter string that describes the PayPal payment
  225. // the varialbes were set in the web form, and the resulting string
  226. // is stored in $nvpstr
  227. $sh_name = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['firstname'].' '.$order->delivery['lastname']));
  228. $sh_street = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['street_address']));
  229. $sh_street_2 = '';
  230. $sh_city = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['city']));
  231. $sh_zip = urlencode($order->delivery['postcode']);
  232. $sh_state = urlencode($this->state_code($order->delivery['state']));
  233. $sh_countrycode = urlencode($order->delivery['country']['iso_code_2']);
  234. $sh_countryname = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",$order->delivery['country']['title']));
  235. $sh_phonenum = urlencode($order->customer['telephone']);
  236. // String zusammenbauen
  237. $nvpstr="&AMT=".$paymentAmount.
  238. "&CURRENCYCODE=".$currencyCodeType.
  239. "&PAYMENTACTION=".$paymentType.
  240. "&LOCALECODE=".$_SESSION['language_code'].
  241. "&RETURNURL=".$returnURL.
  242. "&CANCELURL=".$cancelURL.
  243. "&GIROPAYSUCCESSURL=".$gpsucssesURL.
  244. "&GIROPAYCANCELURL=".$gpcancelURL.
  245. "&BANKTXNPENDINGURL=".$bankpending.
  246. "&HDRIMG=".$this->Image.
  247. "&HDRBORDERCOLOR=".$this->BorderColor.
  248. "&HDRBACKCOLOR=".$this->BackColor.
  249. "&CUSTOM=".''.
  250. "&SHIPTONAME=".$sh_name.
  251. "&SHIPTOSTREET=".$sh_street.
  252. "&SHIPTOSTREET2=".$sh_street2.
  253. "&SHIPTOCITY=".$sh_city.
  254. "&SHIPTOZIP=".$sh_zip.
  255. "&SHIPTOSTATE=".$sh_state.
  256. "&SHIPTOCOUNTRYCODE=".$sh_countrycode.
  257. "&SHIPTOCOUNTRYNAME=".$sh_countryname.
  258. "&PHONENUM=".$sh_phonenum.
  259. "&ALLOWNOTE=0".
  260. "&ADDROVERRIDE=1";
  261. // Artikel Details mitgeben
  262. $nvpstr.=$nvp_products;
  263. // Senden
  264. $resArray=$this->hash_call("SetExpressCheckout",$nvpstr);
  265. $_SESSION['reshash']= $resArray;
  266. $ack = strtoupper($resArray["ACK"]);
  267. if($ack!="SUCCESS"):
  268. if(PAYPAL_ERROR_DEBUG=='true'):
  269. $this->build_error_message($_SESSION['reshash']);
  270. else:
  271. $_SESSION['reshash']['FORMATED_ERRORS'] = PAYPAL_NOT_AVIABLE;
  272. endif;
  273. xtc_redirect($this->PRE_CANCEL_URL);
  274. endif;
  275. if($ack=="SUCCESS"){
  276. $token = urldecode($resArray["TOKEN"]);
  277. $this->payPalURL = $this->EXPRESS_URL.''.$token;
  278. return $this->payPalURL;
  279. }
  280. }
  281. /*************************************************************/
  282. /******* f�rs express aus dem warenkorb **********************/
  283. /*************************************************************/
  284. function paypal_express_auth_call(){
  285. // aufruf aus cart_actions.php
  286. // 1. Call um die Token ID zu bekommen
  287. // Steuer, Artikel usw bei eingeloggt
  288. // Stand: 05.01.2010
  289. global $xtPrice,$order;
  290. // Session s�ubern
  291. unset($_SESSION['reshash']);
  292. unset($_SESSION['nvpReqArray']);
  293. // Shipping:
  294. if(!isset($_SESSION['sendto'])) {
  295. $_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
  296. } else {
  297. // verify the selected shipping address
  298. $check_address_query = xtc_db_query("select count(*) as total from ".TABLE_ADDRESS_BOOK." where customers_id = '".(int) $_SESSION['customer_id']."' and address_book_id = '".(int) $_SESSION['sendto']."'");
  299. $check_address = xtc_db_fetch_array($check_address_query);
  300. if($check_address['total'] != '1') {
  301. $_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
  302. if(isset($_SESSION['shipping']))
  303. unset($_SESSION['shipping']);
  304. }
  305. }
  306. // Shipping END
  307. require(DIR_WS_CLASSES.'order.php');
  308. $order = new order();
  309. require(DIR_WS_CLASSES.'order_total.php');
  310. $order_total_modules = new order_total();
  311. $order_totals = $order_total_modules->process();
  312. $order_tax=0;
  313. $order_discount=0;
  314. $order_gs=0;
  315. $order_fee=0;
  316. $order_shipping=0;
  317. for($i = 0, $n = sizeof($order_totals); $i < $n; $i ++):
  318. switch($order_totals[$i]['code']):
  319. case 'ot_discount':
  320. $order_discount+=$order_totals[$i]['value'];
  321. break;
  322. case 'ot_coupon':
  323. $order_gs+= ($order_totals[$i]['value'] < 0) ? $order_totals[$i]['value'] : $order_totals[$i]['value'] *(-1);
  324. break;
  325. case 'ot_gv':
  326. $order_gs+= ($order_totals[$i]['value'] < 0) ? $order_totals[$i]['value'] : $order_totals[$i]['value'] *(-1);
  327. break;
  328. /// customers bonus
  329. case 'ot_bonus_fee':
  330. $order_gs+= ($order_totals[$i]['value'] < 0) ? $order_totals[$i]['value'] : $order_totals[$i]['value'] *(-1);
  331. break;
  332. case 'ot_payment':
  333. if($order_totals[$i]['value'] < 0): // Rabatt aus Fremd Modul
  334. $order_discount+=$order_totals[$i]['value'];
  335. else:
  336. $order_fee+=$order_totals[$i]['value'];
  337. endif;
  338. case 'ot_cod_fee':
  339. $order_fee+=$order_totals[$i]['value'];
  340. break;
  341. case 'ot_ps_fee':
  342. $order_fee+=$order_totals[$i]['value'];
  343. break;
  344. case 'ot_loworderfee':
  345. $order_fee+=$order_totals[$i]['value'];
  346. endswitch;
  347. endfor;
  348. // AMT
  349. $paymentAmount=$_SESSION['cart']->show_total()
  350. +$order_discount
  351. +$order_gs
  352. +$order_fee;
  353. if($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1):
  354. $order_tax=$_SESSION['cart']->show_tax(false);
  355. endif;
  356. // Vorl�ufige Versandkosten
  357. if(PAYPAL_EXP_VORL!='' AND PAYPAL_EXP_VERS!=0):
  358. $paymentAmount+=PAYPAL_EXP_VERS;
  359. endif;
  360. // AMT
  361. $paymentAmount = round($paymentAmount, $xtPrice->get_decimal_places($order->info['currency']));
  362. // Summen der Order
  363. $order_tax=round($order_tax, $xtPrice->get_decimal_places($order->info['currency']));
  364. $order_discount=round($order_discount, $xtPrice->get_decimal_places($order->info['currency']));
  365. $order_gs=round($order_gs, $xtPrice->get_decimal_places($order->info['currency']));
  366. $order_fee=round($order_fee, $xtPrice->get_decimal_places($order->info['currency']));
  367. $nvp_products=$this->paypal_get_products($paymentAmount,$order_tax,$order_discount,$order_fee,$order_shipping,$order_gs,True);
  368. $paymentAmount = urlencode(number_format($paymentAmount, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  369. $currencyCodeType = urlencode($order->info['currency']);
  370. // Payment Type
  371. $paymentType='Sale';
  372. $returnURL =urlencode($this->EXPRESS_RETURN_URL);
  373. $cancelURL =urlencode($this->EXPRESS_CANCEL_URL);
  374. $gpsucssesURL =urlencode($this->GIROPAY_SUCCESS_URL);
  375. $gpcancelURL =urlencode($this->EXPRESS_CANCEL_URL);
  376. $bankpending =urlencode($this->BANKTXN_PENDING_URL);
  377. if(isset($_SESSION['sendto']) AND isset($_SESSION['customer_id'])):
  378. // User eingeloggt
  379. $sh_name = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['firstname'].' '.$order->delivery['lastname']));
  380. $sh_street = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['street_address']));
  381. $sh_street_2 = '';
  382. $sh_city = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['city']));
  383. $sh_zip = urlencode($order->delivery['postcode']);
  384. $sh_state = urlencode($this->state_code($order->delivery['state']));
  385. $sh_countrycode = urlencode($order->delivery['country']['iso_code_2']);
  386. $sh_countryname = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",$order->delivery['country']['title']));
  387. $sh_phonenum = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",$order->customer['telephone']));
  388. if($_SESSION['paypal_express_new_customer']!='true')
  389. $address = "&SHIPTONAME=".$sh_name."&SHIPTOSTREET=".$sh_street."&SHIPTOSTREET2=".$sh_street2."&SHIPTOCITY=".$sh_city."&SHIPTOZIP=".$sh_zip."&SHIPTOSTATE=".$sh_state."&SHIPTOCOUNTRYCODE=".$sh_countrycode."&SHIPTOCOUNTRYNAME=".$sh_countryname."&PHONENUM=".$sh_phonenum;
  390. endif;
  391. // String zusammenbauen
  392. $nvpstr="&AMT=".$paymentAmount.
  393. "&CURRENCYCODE=".$currencyCodeType.
  394. "&PAYMENTACTION=".$paymentType.
  395. "&LOCALECODE=".$_SESSION['language_code'].
  396. "&RETURNURL=".$returnURL.
  397. "&CANCELURL=".$cancelURL.
  398. "&GIROPAYSUCCESSURL=".$gpsucssesURL.
  399. "&GIROPAYCANCELURL=".$gpcancelURL.
  400. "&BANKTXNPENDINGURL=".$bankpending.
  401. "&HDRIMG=".$this->Image.
  402. "&HDRBORDERCOLOR=".$this->BorderColor.
  403. "&HDRBACKCOLOR=".$this->BackColor.
  404. "&CUSTOM=".''.
  405. $address.
  406. "&ALLOWNOTE=0".
  407. "&ADDROVERRIDE=0";
  408. // Artikel Details mitgeben
  409. $nvpstr.=$nvp_products;
  410. // Make the call to PayPal to set the Express Checkout token
  411. // If the API call succeded, then redirect the buyer to PayPal
  412. // to begin to authorize payment. If an error occured, show the
  413. // resulting errors
  414. $resArray=$this->hash_call("SetExpressCheckout",$nvpstr);
  415. $_SESSION['reshash']= $resArray;
  416. $ack = strtoupper($resArray["ACK"]);
  417. if($ack=="SUCCESS"){
  418. $token = urldecode($resArray["TOKEN"]);
  419. $this->payPalURL = $this->EXPRESS_URL.''.$token;
  420. return $this->payPalURL;
  421. } else {
  422. if(PAYPAL_ERROR_DEBUG=='true'):
  423. $this->build_error_message($_SESSION['reshash']);
  424. else:
  425. $_SESSION['reshash']['FORMATED_ERRORS'] = PAYPAL_NOT_AVIABLE;
  426. endif;
  427. $this->payPalURL = $this->EXPRESS_CANCEL_URL;
  428. return $this->payPalURL;
  429. }
  430. }
  431. /*************************************************************/
  432. /******* f�r abgelehnte Zahlungen **********************/
  433. /*************************************************************/
  434. function paypal_second_auth_call($insert_id){
  435. // aufruf aus shopping_cart.php
  436. // 1. Call um die Token ID zu bekommen
  437. // Daten aus der Order !
  438. // Stand: 29.04.2009
  439. global $xtPrice,$order;
  440. // Session s�ubern
  441. unset($_SESSION['reshash']);
  442. unset($_SESSION['nvpReqArray']);
  443. require(DIR_WS_CLASSES.'order.php');
  444. $order = new order($insert_id);
  445. // Amt
  446. $paymentAmount = round($order->info['pp_total'], $xtPrice->get_decimal_places($order->info['currency']));
  447. // Summen der Order
  448. $order_tax = round($order->info['pp_tax'], $xtPrice->get_decimal_places($order->info['currency']));
  449. $order_discount = round($order->info['pp_disc'], $xtPrice->get_decimal_places($order->info['currency']));
  450. $order_gs = round($order->info['pp_gs'], $xtPrice->get_decimal_places($order->info['currency']));
  451. $order_fee = round($order->info['pp_fee'], $xtPrice->get_decimal_places($order->info['currency']));
  452. $order_shipping = round($order->info['pp_shipping'], $xtPrice->get_decimal_places($order->info['currency']));
  453. $nvp_products=$this->paypal_get_products($paymentAmount,$order_tax,$order_discount,$order_fee,$order_shipping,$order_gs);
  454. $paymentAmount = urlencode(number_format($paymentAmount, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  455. $currencyCodeType = urlencode($order->info['currency']);
  456. // Payment Type
  457. $paymentType='Sale';
  458. $returnURL =urlencode($this->EXPRESS_CANCEL_URL);
  459. $cancelURL =urlencode($this->EXPRESS_CANCEL_URL);
  460. $gpsucssesURL =urlencode($this->GIROPAY_SUCCESS_URL);
  461. $gpcancelURL =urlencode($this->EXPRESS_CANCEL_URL);
  462. $bankpending =urlencode($this->BANKTXN_PENDING_URL);
  463. $notify_url = urlencode($this->NOTIFY_URL);
  464. $inv_num = urlencode($insert_id);
  465. // Versandadresse
  466. $sh_name = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['firstname'].' '.$order->delivery['lastname']));
  467. $sh_street = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['street_address']));
  468. $sh_street_2 = '';
  469. $sh_city = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['city']));
  470. $sh_state = urlencode($this->state_code($order->delivery['state']));
  471. if(is_array($order->delivery['country'])):
  472. $sh_countrycode = urlencode($order->delivery['country']['iso_code_2']);
  473. $sh_countryname = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",$order->delivery['country']['title']));
  474. else:
  475. $sh_countrycode = urlencode($order->delivery['country_iso_2']);
  476. $sh_countryname = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",$order->delivery['country']));
  477. endif;
  478. $sh_phonenum = urlencode($order->customer['telephone']);
  479. $sh_zip = urlencode($order->delivery['postcode']);
  480. $address = "&SHIPTONAME=".$sh_name."&SHIPTOSTREET=".$sh_street."&SHIPTOSTREET2=".$sh_street2."&SHIPTOCITY=".$sh_city."&SHIPTOZIP=".$sh_zip."&SHIPTOSTATE=".$sh_state."&SHIPTOCOUNTRYCODE=".$sh_countrycode."&SHIPTOCOUNTRYNAME=".$sh_countryname."&PHONENUM=".$sh_phonenum;
  481. // String zusammenbauen
  482. $nvpstr="&AMT=".$paymentAmount.
  483. "&CURRENCYCODE=".$currencyCodeType.
  484. "&PAYMENTACTION=".$paymentType.
  485. "&NOTIFYURL=".$notify_url.
  486. "&INVNUM=".$inv_num.$adress.
  487. "&LOCALECODE=".$_SESSION['language_code'].
  488. "&RETURNURL=".$returnURL.
  489. "&CANCELURL=".$cancelURL.
  490. "&GIROPAYSUCCESSURL=".$gpsucssesURL.
  491. "&GIROPAYCANCELURL=".$gpcancelURL.
  492. "&BANKTXNPENDINGURL=".$bankpending.
  493. "&HDRIMG=".$this->Image.
  494. "&HDRBORDERCOLOR=".$this->BorderColor.
  495. "&HDRBACKCOLOR=".$this->BackColor.
  496. "&CUSTOM=".''.
  497. $address.
  498. "&ALLOWNOTE=0".
  499. "&ADDROVERRIDE=1";
  500. // Artikel Details mitgeben
  501. $nvpstr.=$nvp_products;
  502. // Make the call to PayPal to set the Express Checkout token
  503. // If the API call succeded, then redirect the buyer to PayPal
  504. // to begin to authorize payment. If an error occured, show the
  505. // resulting errors
  506. $resArray=$this->hash_call("SetExpressCheckout",$nvpstr);
  507. $_SESSION['reshash']= $resArray;
  508. $ack = strtoupper($resArray["ACK"]);
  509. if($ack=="SUCCESS"){
  510. $token = urldecode($resArray["TOKEN"]);
  511. $this->payPalURL = $this->EXPRESS_URL.''.$token;
  512. return $this->payPalURL;
  513. } else {
  514. $this->build_error_message($_SESSION['reshash']);
  515. if(PAYPAL_ERROR_DEBUG=='true'):
  516. $_SESSION['reshash']['FORMATED_ERRORS'] = PAYPAL_NOT_AVIABLE;
  517. else:
  518. $this->payPalURL = $this->EXPRESS_CANCEL_URL;
  519. endif;
  520. return $this->payPalURL;
  521. }
  522. }
  523. /*************************************************************/
  524. /******* f�r beide Versionen *********************************/
  525. /*************************************************************/
  526. function complete_ceckout($insert_id, $data=''){
  527. // aufruf aus paypal.php oder paypalexpress.php aus Warenkorb
  528. // 2. Call um die PayPal Aktion abzuschliessen
  529. // Daten aus der Order
  530. // Stand: 29.04.2009
  531. global $xtPrice,$order;
  532. $order = new order($insert_id);
  533. // IP Adresse
  534. if($_SERVER["HTTP_X_FORWARDED_FOR"]) {
  535. $customers_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  536. } else {
  537. $customers_ip = $_SERVER["REMOTE_ADDR"];
  538. }
  539. // Amt
  540. $paymentAmount = round($order->info['pp_total'], $xtPrice->get_decimal_places($order->info['currency']));
  541. // Summen der Order
  542. $order_tax = round($order->info['pp_tax'], $xtPrice->get_decimal_places($order->info['currency']));
  543. $order_discount = round($order->info['pp_disc'], $xtPrice->get_decimal_places($order->info['currency']));
  544. $order_gs = round($order->info['pp_gs'], $xtPrice->get_decimal_places($order->info['currency']));
  545. $order_fee = round($order->info['pp_fee'], $xtPrice->get_decimal_places($order->info['currency']));
  546. $order_shipping = round($order->info['pp_shipping'], $xtPrice->get_decimal_places($order->info['currency']));
  547. $nvp_products=$this->paypal_get_products($paymentAmount,$order_tax,$order_discount,$order_fee,$order_shipping,$order_gs);
  548. $paymentAmount = urlencode(number_format($paymentAmount, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  549. $currencyCodeType = urlencode($order->info['currency']);
  550. $tkn=(($data['token']!='')?$data['token']:$_SESSION['nvpReqArray']['TOKEN']);
  551. $payer=(($data['PayerID']!='')?$data['PayerID']:$payer = $_SESSION['reshash']['PAYERID']);
  552. $token =urlencode($tkn);
  553. $payerID = urlencode($payer);
  554. $paymentType='Sale';
  555. $notify_url = urlencode($this->NOTIFY_URL);
  556. $inv_num = urlencode($insert_id);
  557. $button_source = urlencode($this->ppAPIec);
  558. // Versandadresse
  559. $sh_name = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['firstname'].' '.$order->delivery['lastname']));
  560. $sh_street = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['street_address']));
  561. $sh_street_2 = '';
  562. $sh_city = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8", $order->delivery['city']));
  563. $sh_state = urlencode($this->state_code($order->delivery['state']));
  564. if(is_array($order->delivery['country'])):
  565. $sh_countrycode = urlencode($order->delivery['country']['iso_code_2']);
  566. $sh_countryname = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",$order->delivery['country']['title']));
  567. else:
  568. $sh_countrycode = urlencode($order->delivery['country_iso_2']);
  569. $sh_countryname = urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",$order->delivery['country']));
  570. endif;
  571. $sh_phonenum = urlencode($order->customer['telephone']);
  572. $sh_zip = urlencode($order->delivery['postcode']);
  573. $address = "&SHIPTONAME=".$sh_name."&SHIPTOSTREET=".$sh_street."&SHIPTOSTREET2=".$sh_street2."&SHIPTOCITY=".$sh_city."&SHIPTOZIP=".$sh_zip."&SHIPTOSTATE=".$sh_state."&SHIPTOCOUNTRYCODE=".$sh_countrycode."&SHIPTOCOUNTRYNAME=".$sh_countryname."&PHONENUM=".$sh_phonenum;
  574. // Versand Ende
  575. $nvpstr='&TOKEN='.$token.
  576. '&PAYERID='.$payerID.
  577. '&PAYMENTACTION='.$paymentType.
  578. '&AMT='.$paymentAmount.
  579. '&CURRENCYCODE='.$currencyCodeType.
  580. '&IPADDRESS='.$customers_ip.
  581. '&NOTIFYURL='.$notify_url.
  582. '&INVNUM='.$inv_num.$adress.
  583. '&BUTTONSOURCE='.$button_source.
  584. $address;
  585. // Artikel Details mitgeben
  586. $nvpstr.=$nvp_products;
  587. // Make the call to PayPal to finalize payment
  588. // If an error occured, show the resulting errors
  589. $resArray=$this->hash_call("DoExpressCheckoutPayment",$nvpstr);
  590. $_SESSION['reshash'] = array_merge($_SESSION['reshash'], $resArray) ;
  591. $ack = strtoupper($resArray["ACK"]);
  592. if($ack!="SUCCESS" AND $ack!="SUCCESSWITHWARNING"){
  593. $this->build_error_message($_SESSION['reshash'],'DoEx');
  594. }
  595. }
  596. /*************************************************************/
  597. /******* funktionen nur f�r Warenkorb ************************/
  598. /*************************************************************/
  599. function paypal_get_customer_data(){
  600. // Stand: 29.04.2009
  601. $nvpstr="&TOKEN=".$_SESSION['reshash']['TOKEN'];
  602. // Make the API call and store the results in an array. If the
  603. // call was a success, show the authorization details, and provide
  604. // an action to complete the payment. If failed, show the error
  605. $resArray=$this->hash_call("GetExpressCheckoutDetails",$nvpstr);
  606. $_SESSION['reshash'] = array_merge($_SESSION['reshash'], $resArray) ;
  607. $ack = strtoupper($resArray["ACK"]);
  608. if($ack=="SUCCESS"){
  609. $_SESSION['paypal_express_checkout'] = true;
  610. $_SESSION['paypal_express_payment_modules'] = 'paypalexpress.php';
  611. $this->check_customer();
  612. } else {
  613. $this->build_error_message($_SESSION['reshash']);
  614. $this->payPalURL = $this->EXPRESS_CANCEL_URL;
  615. return $this->payPalURL;
  616. }
  617. }
  618. /*************************************************************/
  619. function check_customer(){
  620. // Stand: 29.04.2009
  621. if(!isset($_SESSION['customer_id'])) {
  622. $check_customer_query = xtc_db_query("select * from ".TABLE_CUSTOMERS." where customers_email_address = '".xtc_db_input($_SESSION['reshash']['EMAIL'])."' and account_type = '0'");
  623. if(!xtc_db_num_rows($check_customer_query)) {
  624. $this->create_account();
  625. }else{
  626. $check_customer = xtc_db_fetch_array($check_customer_query);
  627. $this->login_customer($check_customer);
  628. if(PAYPAL_EXPRESS_ADDRESS_OVERRIDE == 'true' && $_SESSION['pp_allow_address_change']!='true')
  629. $this->create_shipping_address();
  630. }
  631. }else{
  632. if(PAYPAL_EXPRESS_ADDRESS_OVERRIDE == 'true' && $_SESSION['pp_allow_address_change']!='true'){
  633. $check_customer_query = xtc_db_query("select * from ".TABLE_CUSTOMERS." where customers_id = '".xtc_db_input($_SESSION['customer_id'])."' and account_type = '0'");
  634. $check_customer = xtc_db_fetch_array($check_customer_query);
  635. $this->create_shipping_address();
  636. }
  637. }
  638. }
  639. /*************************************************************/
  640. function create_account(){
  641. // Stand: 29.04.2009
  642. $firstname = xtc_db_prepare_input($this->UTF8decode($_SESSION['reshash']['FIRSTNAME']));
  643. $lastname = xtc_db_prepare_input($this->UTF8decode($_SESSION['reshash']['LASTNAME']));
  644. $email_address = xtc_db_prepare_input($_SESSION['reshash']['EMAIL']);
  645. $company = xtc_db_prepare_input($this->UTF8decode($_SESSION['reshash']['BUSINESS']));
  646. $street_address = xtc_db_prepare_input($this->UTF8decode($_SESSION['reshash']['SHIPTOSTREET'] . $_SESSION['reshash']['SHIPTOSTREET_2']));
  647. $postcode = xtc_db_prepare_input($_SESSION['reshash']['SHIPTOZIP']);
  648. $city = xtc_db_prepare_input($this->UTF8decode($_SESSION['reshash']['SHIPTOCITY']));
  649. $state = xtc_db_prepare_input($_SESSION['reshash']['SHIPTOSTATE']);
  650. $telephone = xtc_db_prepare_input($_SESSION['reshash']['PHONENUM']);
  651. $country_query = xtc_db_query("select * from ".TABLE_COUNTRIES." where countries_iso_code_2 = '".xtc_db_input($_SESSION['reshash']['SHIPTOCOUNTRYCODE'])."' ");
  652. $tmp_country = xtc_db_fetch_array($country_query);
  653. $country = xtc_db_prepare_input($tmp_country['countries_id']);
  654. $customers_status = DEFAULT_CUSTOMERS_STATUS_ID;
  655. $sql_data_array = array(
  656. 'customers_status' => $customers_status,
  657. 'customers_firstname' => $firstname,
  658. 'customers_lastname' => $lastname,
  659. 'customers_email_address' => $email_address,
  660. 'customers_telephone' => $telephone,
  661. 'customers_date_added' => 'now()',
  662. 'customers_last_modified' => 'now()');
  663. xtc_db_perform(TABLE_CUSTOMERS, $sql_data_array);
  664. $_SESSION['paypal_express_new_customer'] = 'true';
  665. $_SESSION['customer_id'] = xtc_db_insert_id();
  666. $user_id = xtc_db_insert_id();
  667. xtc_write_user_info($user_id);
  668. $sql_data_array = array(
  669. 'customers_id' => $_SESSION['customer_id'],
  670. 'entry_firstname' => $firstname,
  671. 'entry_lastname' => $lastname,
  672. 'entry_street_address' => $street_address,
  673. 'entry_postcode' => $postcode,
  674. 'entry_city' => $city,
  675. 'entry_country_id' => $country,
  676. 'entry_company' => $company,
  677. 'entry_zone_id' => '0',
  678. 'entry_state' => $state,
  679. 'address_date_added' => 'now()',
  680. 'address_last_modified' => 'now()');
  681. xtc_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
  682. $address_id = xtc_db_insert_id();
  683. $_SESSION['sendto'] = $address_id;
  684. xtc_db_query("update " . TABLE_CUSTOMERS . " set customers_default_address_id = '" . $address_id . "' where customers_id = '" . (int) $_SESSION['customer_id'] . "'");
  685. xtc_db_query("insert into " . TABLE_CUSTOMERS_INFO . " (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('" . (int) $_SESSION['customer_id'] . "', '0', now())");
  686. if(isset($_SESSION['tracking']['refID'])) {
  687. $campaign_check_query_raw = "SELECT *
  688. FROM " . TABLE_CAMPAIGNS . "
  689. WHERE campaigns_refID = '" . $_SESSION[tracking][refID] . "'";
  690. $campaign_check_query = xtc_db_query($campaign_check_query_raw);
  691. if(xtc_db_num_rows($campaign_check_query) > 0) {
  692. $campaign = xtc_db_fetch_array($campaign_check_query);
  693. $refID = $campaign['campaigns_id'];
  694. } else {
  695. $refID = 0;
  696. }
  697. xtc_db_query("update " . TABLE_CUSTOMERS . " set
  698. refferers_id = '" . $refID . "'
  699. where customers_id = '" . (int) $_SESSION['customer_id'] . "'");
  700. $leads = $campaign['campaigns_leads'] + 1;
  701. xtc_db_query("update " . TABLE_CAMPAIGNS . " set
  702. campaigns_leads = '" . $leads . "'
  703. where campaigns_id = '" . $refID . "'");
  704. }
  705. if(ACTIVATE_GIFT_SYSTEM == 'true') {
  706. // GV Code Start
  707. // ICW - CREDIT CLASS CODE BLOCK ADDED ******************************************************* BEGIN
  708. if(NEW_SIGNUP_GIFT_VOUCHER_AMOUNT > 0) {
  709. $coupon_code = create_coupon_code();
  710. $insert_query = xtc_db_query("insert into " . TABLE_COUPONS . " (coupon_code, coupon_type, coupon_amount, date_created) values ('" . $coupon_code . "', 'G', '" . NEW_SIGNUP_GIFT_VOUCHER_AMOUNT . "', now())");
  711. $insert_id = xtc_db_insert_id($insert_query);
  712. $insert_query = xtc_db_query("insert into " . TABLE_COUPON_EMAIL_TRACK . " (coupon_id, customer_id_sent, sent_firstname, emailed_to, date_sent) values ('" . $insert_id . "', '0', 'Admin', '" . $email_address . "', now() )");
  713. $_SESSION['reshash']['SEND_GIFT'] = 'true';
  714. $_SESSION['reshash']['GIFT_AMMOUNT'] = $xtPrice->xtcFormat(NEW_SIGNUP_GIFT_VOUCHER_AMOUNT, true);
  715. $_SESSION['reshash']['GIFT_CODE'] = $coupon_code;
  716. $_SESSION['reshash']['GIFT_LINK'] = xtc_href_link(FILENAME_GV_REDEEM, 'gv_no=' . $coupon_code, 'NONSSL', false);
  717. }
  718. if(NEW_SIGNUP_DISCOUNT_COUPON != '') {
  719. $coupon_code = NEW_SIGNUP_DISCOUNT_COUPON;
  720. $coupon_query = xtc_db_query("select * from " . TABLE_COUPONS . " where coupon_code = '" . $coupon_code . "'");
  721. $coupon = xtc_db_fetch_array($coupon_query);
  722. $coupon_id = $coupon['coupon_id'];
  723. $coupon_desc_query = xtc_db_query("select * from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . $coupon_id . "' and language_id = '" . (int) $_SESSION['language_id'] . "'");
  724. $coupon_desc = xtc_db_fetch_array($coupon_desc_query);
  725. $insert_query = xtc_db_query("insert into " . TABLE_COUPON_EMAIL_TRACK . " (coupon_id, customer_id_sent, sent_firstname, emailed_to, date_sent) values ('" . $coupon_id . "', '0', 'Admin', '" . $email_address . "', now() )");
  726. $_SESSION['reshash']['SEND_COUPON'] = 'true';
  727. $_SESSION['reshash']['COUPON_DESC'] = $coupon_desc['coupon_description'];
  728. $_SESSION['reshash']['COUPON_CODE'] = $coupon['coupon_code'];
  729. }
  730. // ICW - CREDIT CLASS CODE BLOCK ADDED ******************************************************* END
  731. // GV Code End // create templates
  732. }
  733. $_SESSION['ACCOUNT_PASSWORD'] = 'true';
  734. // Login Customer
  735. $check_customer_query = xtc_db_query("select * from ".TABLE_CUSTOMERS." where customers_email_address = '".xtc_db_input($email_address)."' and account_type = '0'");
  736. $check_customer = xtc_db_fetch_array($check_customer_query);
  737. $this->login_customer($check_customer);
  738. if(PAYPAL_EXPRESS_ADDRESS_OVERRIDE == 'true'):
  739. if($firstname.' '.$lastname != $this->UTF8decode($_SESSION['reshash']['SHIPTONAME']))
  740. $this->create_shipping_address();
  741. endif;
  742. }
  743. /*************************************************************/
  744. function login_customer($check_customer){
  745. // Stand: 29.04.2009
  746. global $main,$xtPrice,$econda;
  747. if(SESSION_RECREATE == 'True')
  748. xtc_session_recreate();
  749. $check_country_query = xtc_db_query("select entry_country_id, entry_zone_id from ".TABLE_ADDRESS_BOOK." where customers_id = '".(int) $check_customer['customers_id']."' and address_book_id = '".$check_customer['customers_default_address_id']."'");
  750. $check_country = xtc_db_fetch_array($check_country_query);
  751. $_SESSION['customer_gender'] = $check_customer['customers_gender'];
  752. $_SESSION['customer_first_name'] = $check_customer['customers_firstname'];
  753. $_SESSION['customer_last_name'] = $check_customer['customers_lastname'];
  754. $_SESSION['customer_id'] = $check_customer['customers_id'];
  755. $_SESSION['customer_vat_id'] = $check_customer['customers_vat_id'];
  756. $_SESSION['customer_default_address_id'] = $check_customer['customers_default_address_id'];
  757. $_SESSION['customer_country_id'] = $check_country['entry_country_id'];
  758. $_SESSION['customer_zone_id'] = $check_country['entry_zone_id'];
  759. $_SESSION['customer_email_address'] = $check_customer['customers_email_address'];
  760. $date_now = date('Ymd');
  761. xtc_db_query("update ".TABLE_CUSTOMERS_INFO." SET customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 WHERE customers_info_id = '".(int) $_SESSION['customer_id']."'");
  762. xtc_write_user_info((int) $_SESSION['customer_id']);
  763. // Falls vorher schon mal eingeloggt und was in der Cart war
  764. xtc_db_query("delete from ".TABLE_CUSTOMERS_BASKET." where customers_id = '".(int)$_SESSION['customer_id']."'");
  765. xtc_db_query("delete from ".TABLE_CUSTOMERS_BASKET_ATTRIBUTES." where customers_id = '".(int)$_SESSION['customer_id']."'");
  766. // Warenkorb restoren
  767. $_SESSION['cart']->restore_contents();
  768. if(is_object($econda)) $econda->_loginUser();
  769. // write customers status in session
  770. require(DIR_WS_INCLUDES.'write_customers_status.php');
  771. $xtPrice = new xtcPrice($_SESSION['currency'], $_SESSION['customers_status']['customers_status_id']);
  772. }
  773. /*************************************************************/
  774. function create_shipping_address(){
  775. // Stand: 29.04.2009
  776. $pos = strrpos($_SESSION['reshash']['SHIPTONAME'], ' ');
  777. $lenght = strlen($_SESSION['reshash']['SHIPTONAME']);
  778. $firstname = $this->UTF8decode(substr($_SESSION['reshash']['SHIPTONAME'], 0, $pos));
  779. $lastname = $this->UTF8decode(substr($_SESSION['reshash']['SHIPTONAME'], ($pos+1), $lenght));
  780. $email_address = xtc_db_prepare_input($_SESSION['reshash']['EMAIL']);
  781. $company = xtc_db_prepare_input($_SESSION['reshash']['BUSINESS']);
  782. $street_address = xtc_db_prepare_input($this->UTF8decode($_SESSION['reshash']['SHIPTOSTREET'] . $_SESSION['reshash']['SHIPTOSTREET_2']));
  783. $postcode = xtc_db_prepare_input($_SESSION['reshash']['SHIPTOZIP']);
  784. $city = xtc_db_prepare_input($this->UTF8decode($_SESSION['reshash']['SHIPTOCITY']));
  785. $state = xtc_db_prepare_input($_SESSION['reshash']['SHIPTOSTATE']);
  786. $telephone = xtc_db_prepare_input($_SESSION['reshash']['PHONENUM']);
  787. $country_query = xtc_db_query("select * from ".TABLE_COUNTRIES." where countries_iso_code_2 = '".xtc_db_input($_SESSION['reshash']['SHIPTOCOUNTRYCODE'])."' ");
  788. $tmp_country = xtc_db_fetch_array($country_query);
  789. $country = xtc_db_prepare_input($tmp_country['countries_id']);
  790. $sql_data_array = array(
  791. 'customers_id' => $_SESSION['customer_id'],
  792. 'entry_firstname' => $firstname,
  793. 'entry_lastname' => $lastname,
  794. 'entry_street_address' => $street_address,
  795. 'entry_postcode' => $postcode,
  796. 'entry_city' => $city,
  797. 'entry_country_id' => $country,
  798. 'entry_company' => $company,
  799. 'entry_zone_id' => '0',
  800. 'entry_state' => $state,
  801. 'address_date_added' => 'now()',
  802. 'address_last_modified' => 'now()',
  803. 'address_class' => 'paypal');
  804. $check_address_query = xtc_db_query("select address_book_id from ".TABLE_ADDRESS_BOOK." where customers_id = '".(int) $_SESSION['customer_id']."' and address_class = 'paypal'");
  805. $check_address = xtc_db_fetch_array($check_address_query);
  806. if($check_address['address_book_id']!='') {
  807. xtc_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array, 'update', "address_book_id = '".(int) $check_address['address_book_id']."' and customers_id ='".(int) $_SESSION['customer_id']."'");
  808. $send_to = $check_address['address_book_id'];
  809. }else{
  810. xtc_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
  811. $send_to = xtc_db_insert_id();
  812. }
  813. $_SESSION['sendto'] = $send_to;
  814. }
  815. /*************************************************************/
  816. /******* funktionen f�r beide versionen **********************/
  817. /*************************************************************/
  818. // hash_call: Function to perform the API call to PayPal using API signature
  819. // @methodName is name of API method.
  820. // @nvpStr is nvp string.
  821. // returns an associtive array containing the response from the server.
  822. // 08.01.2009.erg�nzt f�r PHP ohne cURL von Stefan Kl.
  823. // 05.01.2010 Verbose auf 0 da bei einigen Hostern sonst zuviel angezeigt wird
  824. function hash_call($methodName,$nvpStr,$pp_token=''){
  825. // Stand: 05.01.2010
  826. if(function_exists('curl_init')):
  827. $ch = curl_init();
  828. curl_setopt($ch, CURLOPT_URL,$this->API_Endpoint.$pp_token);
  829. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  830. //turning off the server and peer verification(TrustManager Concept).
  831. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  832. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  833. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  834. curl_setopt($ch, CURLOPT_POST, 1);
  835. //if USE_PROXY constant set to TRUE am Anfang dieser Datei, then only proxy will be enabled.
  836. //Set proxy name to PROXY_HOST and port number to PROXY_PORT im Anfang dieser Datei
  837. if($this->USE_PROXY)
  838. curl_setopt($ch, CURLOPT_PROXY, PROXY_HOST.":".PROXY_PORT);
  839. //NVPRequest for submitting to server
  840. $nvpreq="METHOD=".urlencode($methodName)."&VERSION=".urlencode($this->version)."&PWD=".urlencode($this->API_Password)."&USER=".urlencode($this->API_UserName)."&SIGNATURE=".urlencode($this->API_Signature).$nvpStr;
  841. //setting the nvpreq as POST FIELD to curl
  842. curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
  843. //getting response from server
  844. $response = curl_exec($ch);
  845. //convrting NVPResponse to an Associative Array
  846. $nvpResArray=$this->deformatNVP($response);
  847. $nvpReqArray=$this->deformatNVP($nvpreq);
  848. $_SESSION['nvpReqArray']= $nvpReqArray;
  849. /* Mit cURL Fehleranzeige und nicht Versuch mit file_get_contents
  850. if(curl_errno($ch)) {
  851. // moving to display page to display curl errors
  852. $_SESSION['curl_error_no']=curl_errno($ch) ;
  853. $_SESSION['curl_error_msg']=curl_error($ch);
  854. $this->build_error_message($_SESSION['reshash']);
  855. }
  856. */
  857. $curl_fehler=curl_errno($ch);
  858. //closing the curl
  859. curl_close($ch);
  860. //return $nvpResArray;
  861. if(!$curl_fehler)
  862. return $nvpResArray;
  863. //else:
  864. endif;
  865. /// Falls cURL nicht da oder Fehlerhaft
  866. global $API_Endpoint,$version,$API_UserName,$API_Password,$API_Signature,$nvp_Header;
  867. $nvpreq="METHOD=".urlencode($methodName)."&VERSION=".urlencode($this->version)."&PWD=".urlencode($this->API_Password)."&USER=".urlencode($this->API_UserName)."&SIGNATURE=".urlencode($this->API_Signature).$nvpStr;
  868. $request_post = array(
  869. 'http'=>array(
  870. 'method'=>'POST',
  871. 'header'=>"Content-type: application/x-www-form-urlencoded\r\n",
  872. 'content'=>$nvpreq));
  873. $request = stream_context_create($request_post);
  874. $response= file_get_contents($this->API_Endpoint.$pp_token, false, $request);
  875. $nvpResArray=$this->deformatNVP($response);
  876. $nvpReqArray=$this->deformatNVP($nvpreq);
  877. $_SESSION['nvpReqArray']= $nvpReqArray;
  878. return $nvpResArray;
  879. //endif;
  880. }
  881. /*************************************************************/
  882. // This function will take NVPString and convert it to an Associative Array and it will decode the response.
  883. // It is usefull to search for a particular key and displaying arrays.
  884. // @nvpstr is NVPString.
  885. // @nvpArray is Associative Array.
  886. function deformatNVP($nvpstr){
  887. // Stand: 29.04.2009
  888. $intial=0;
  889. $nvpArray = array();
  890. while(strlen($nvpstr)){
  891. //postion of Key
  892. $keypos= strpos($nvpstr,'=');
  893. //position of value
  894. $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
  895. // getting the Key and Value values and storing in a Associative Array
  896. $keyval=substr($nvpstr,$intial,$keypos);
  897. $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
  898. //decoding the respose
  899. $nvpArray[urldecode($keyval)] =urldecode( $valval);
  900. $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
  901. }
  902. return $nvpArray;
  903. }
  904. /*************************************************************/
  905. function build_error_message($resArray='',$Aufruf=''){
  906. // Stand: 29.04.2009
  907. global $messageStack;
  908. if(isset($_SESSION['curl_error_no'])) {
  909. $errorCode= $_SESSION['curl_error_no'] ;
  910. $errorMessage=$_SESSION['curl_error_msg'] ;
  911. $error .= 'Error Number: '. $errorCode . '<br />';
  912. $error .= 'Error Message: '. $errorMessage . '<br />';
  913. } else {
  914. $error .= 'Ack: '. $resArray['ACK'] . '<br />';
  915. $error .= 'Correlation ID: '. $resArray['CORRELATIONID'] . '<br />';
  916. $error .= 'Version:'. $resArray['VERSION'] . '<br />';
  917. $count=0;
  918. $redirect=0;
  919. while(isset($resArray["L_SHORTMESSAGE".$count])) {
  920. $errorCode = $resArray["L_ERRORCODE".$count];
  921. $shortMessage = $resArray["L_SHORTMESSAGE".$count];
  922. $longMessage = $resArray["L_LONGMESSAGE".$count];
  923. if($Aufruf=='DoEx' AND ($errorCode=='10422' OR $errorCode=='10417'))
  924. $redirect=1;
  925. $count=$count+1;
  926. $error .= 'Error Number:'. $errorCode . '<br />';
  927. $error .= 'Error Short Message: '. $shortMessage . '<br />';
  928. $error .= 'Error Long Message: '. $longMessage . '<br />';
  929. }//end while
  930. if($redirect==1)
  931. $_SESSION['reshash']['REDIRECTREQUIRED']="TRUE";
  932. }// end else
  933. $_SESSION['reshash']['FORMATED_ERRORS'] = $error;
  934. }
  935. /*************************************************************/
  936. function paypal_get_products($paymentAmount,$order_tax,$order_discount,$order_fee,$order_shipping,$order_gs,$express_call=False){
  937. // f�r beide PayPal Versionen
  938. // Artikel Details mitgeben
  939. // F�r den Express Call Vermerk f�r den Versand + Vorl�ufige Kosten mitgeben
  940. // Stand: 05.01.2010
  941. global $xtPrice,$order;
  942. $products_sum_amt = 0;
  943. $tmp_products='';
  944. for($i = 0, $n = sizeof($order->products); $i < $n; $i ++) {
  945. $products_price = round($order->products[$i]['price'],$xtPrice->get_decimal_places($order->info['currency']));
  946. $products_sum_amt+=$products_price*$order->products[$i]['qty'];
  947. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr($order->products[$i]['name'],0,127))).
  948. '&L_NUMBER'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr($order->products[$i]['model'],0,127))).
  949. '&L_QTY'.$i.'='.urlencode($order->products[$i]['qty']).
  950. '&L_AMT'.$i.'='.urlencode(number_format($products_price, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  951. }
  952. if($order_discount!=0): // ist ein - Betrag !
  953. $products_sum_amt+=$order_discount;
  954. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr(SUB_TITLE_OT_DISCOUNT,0,127))).
  955. '&L_NUMBER'.$i.'='.
  956. '&L_QTY'.$i.'=1'.
  957. '&L_AMT'.$i.'='.urlencode(number_format($order_discount, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  958. $i++;
  959. endif;
  960. if($order_gs!=0): // ist ein - Betrag !
  961. $products_sum_amt+=$order_gs;
  962. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr(PAYPAL_GS,0,127))).
  963. '&L_NUMBER'.$i.'='.
  964. '&L_QTY'.$i.'=1'.
  965. '&L_AMT'.$i.'='.urlencode(number_format($order_gs, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  966. $i++;
  967. endif;
  968. if($order_fee!=0):
  969. $products_sum_amt+=$order_fee;
  970. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8","Handling")).
  971. '&L_NUMBER'.$i.'='.
  972. '&L_QTY'.$i.'=1'.
  973. '&L_AMT'.$i.'='.urlencode(number_format($order_fee, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  974. $i++;
  975. endif;
  976. if($order_shipping!=0):
  977. $products_sum_amt+=$order_shipping;
  978. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr(SHIPPING_COSTS,0,127))).
  979. '&L_NUMBER'.$i.'='.
  980. '&L_QTY'.$i.'=1'.
  981. '&L_AMT'.$i.'='.urlencode(number_format($order_shipping, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  982. $i++;
  983. endif;
  984. $products_sum_amt = round($products_sum_amt,$xtPrice->get_decimal_places($order->info['currency']));
  985. if($order_tax!=0 AND trim($paymentAmount-$products_sum_amt)>=$order_tax):
  986. $products_sum_amt+=$order_tax;
  987. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr(PAYPAL_TAX,0,127))).
  988. '&L_NUMBER'.$i.'='.
  989. '&L_QTY'.$i.'=1'.
  990. '&L_AMT'.$i.'='.urlencode(number_format($order_tax, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  991. $i++;
  992. endif;
  993. if($express_call AND PAYPAL_EXP_WARN!=''):
  994. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr(PAYPAL_EXP_WARN,0,127))).
  995. '&L_NUMBER'.$i.'='.
  996. '&L_QTY'.$i.'=0'.
  997. '&L_AMT'.$i.'=0';
  998. $i++;
  999. endif;
  1000. if($express_call AND PAYPAL_EXP_VORL!='' AND PAYPAL_EXP_VERS!=0):
  1001. $products_sum_amt+=PAYPAL_EXP_VERS;
  1002. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8",substr(PAYPAL_EXP_VORL,0,127))).
  1003. '&L_NUMBER'.$i.'='.
  1004. '&L_QTY'.$i.'=1'.
  1005. '&L_AMT'.$i.'='.urlencode(number_format(PAYPAL_EXP_VERS, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  1006. $i++;
  1007. endif;
  1008. $products_sum_amt = round($products_sum_amt,$xtPrice->get_decimal_places($order->info['currency']));
  1009. if(trim($paymentAmount)!=trim($products_sum_amt)):
  1010. $order_diff = round($paymentAmount-$products_sum_amt ,$xtPrice->get_decimal_places($order->info['currency']));
  1011. $products_sum_amt+=$order_diff;
  1012. $tmp_products .='&L_NAME'.$i.'='.urlencode($this->mn_iconv($_SESSION['language_charset'], "UTF-8","Differenz")).
  1013. '&L_NUMBER'.$i.'='.
  1014. '&L_QTY'.$i.'=1'.
  1015. '&L_AMT'.$i.'='.urlencode(number_format($order_diff, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  1016. endif;
  1017. $tmp_products.="&ITEMAMT=".urlencode(number_format($products_sum_amt, $xtPrice->get_decimal_places($order->info['currency']), '.', ','));
  1018. // Artikel Details Ende
  1019. return($tmp_products);
  1020. }
  1021. /*************************************************************/
  1022. function write_status_history($o_id) {
  1023. // Stand: 29.04.2009
  1024. if(empty($o_id) ) return false;
  1025. $ack = strtoupper($_SESSION['reshash']["ACK"]);
  1026. if($ack=="SUCCESS" OR $ack=="SUCCESSWITHWARNING"):
  1027. $o_status = PAYPAL_ORDER_STATUS_PENDING_ID;
  1028. else:
  1029. $o_status = PAYPAL_ORDER_STATUS_REJECTED_ID;
  1030. endif;
  1031. // Sieht der Kunde auch ...
  1032. if(!($ack=="SUCCESS" OR $ack=="SUCCESSWITHWARNING") ):
  1033. $crlf = "\n";
  1034. while(list($key, $value) = each($_SESSION['reshash'])) {
  1035. $comment .= $key.'='.$value.$crlf;
  1036. }
  1037. endif;
  1038. $order_history_data = array('orders_id' => $o_id,
  1039. 'orders_status_id' => $o_status,
  1040. 'date_added' => 'now()',
  1041. 'customer_notified' => '0',
  1042. 'comments' => $comment);
  1043. xtc_db_perform(TABLE_ORDERS_STATUS_HISTORY,$order_history_data);
  1044. xtc_db_query("UPDATE " . TABLE_ORDERS . " SET orders_status = '" . $o_status . "', last_modified = now() WHERE orders_id = '" . xtc_db_prepare_input($o_id) . "'");
  1045. return true;
  1046. }
  1047. /*************************************************************/
  1048. function logging_status($o_id) {
  1049. // Stand: 29.04.2009
  1050. $data = array_merge($_SESSION['nvpReqArray'],$_SESSION['reshash']);
  1051. if(!$data['TRANSACTIONID'] OR $data['TRANSACTIONID']=='')
  1052. $data['TRANSACTIONID']='PayPal Fehler!<br>'.date("d.m.Y - H:i:s");
  1053. $data_array = array('xtc_order_id' => $o_id,
  1054. 'txn_type' => $data['TRANSACTIONTYPE'],
  1055. 'reason_code' => $data['REASONCODE'],
  1056. 'payment_type' => $data['PAYMENTTYPE'],
  1057. 'payment_status' => $data['PAYMENTSTATUS'],
  1058. 'pending_reason' => $data['PENDINGREASON'],
  1059. 'invoice' => $data['INVNUM'],
  1060. 'mc_currency' => $data['CURRENCYCODE'],
  1061. 'first_name' => $_SESSION['customer_first_name'],
  1062. 'last_name' => $_SESSION['customer_last_name'],
  1063. 'payer_business_name' => $this->UTF8decode($data['BUSINESS']),
  1064. 'address_name' => $this->UTF8decode($data['SHIPTONAME']),
  1065. 'address_street' => $this->UTF8decode($data['SHIPTOSTREET']),
  1066. 'address_city' => $this->UTF8decode($data['SHIPTOCITY']),
  1067. 'address_state' => $this->UTF8decode($data['SHIPTOSTATE']),
  1068. 'address_zip' => $data['SHIPTOZIP'],
  1069. 'address_country' => $this->UTF8decode($data['SHIPTOCOUNTRYNAME']),
  1070. 'address_status' => $data['ADDRESSSTATUS'],
  1071. 'payer_email' => $data['EMAIL'],
  1072. 'payer_id' => $data['PAYERID'],
  1073. 'payer_status' => $data['PAYERSTATUS'],
  1074. 'payment_date' => $data['TIMESTAMP'],
  1075. 'business' => '',
  1076. 'receiver_email' => '',
  1077. 'receiver_id' => '',
  1078. 'txn_id' => $data['TRANSACTIONID'],
  1079. 'parent_txn_id' => '',
  1080. 'num_cart_items' => '',
  1081. 'mc_gross' => $data['AMT'],
  1082. 'mc_fee' => $data['FEEAMT'],
  1083. 'mc_authorization' => $data['AMT'],
  1084. 'payment_gross' => '',
  1085. 'payment_fee' => '',
  1086. 'settle_amount' => $data['SETTLEAMT'],
  1087. 'settle_currency' => '',
  1088. 'exchange_rate' => $data['EXCHANGERATE'],
  1089. 'notify_version' => $data['VERSION'],
  1090. 'verify_sign' => '',
  1091. 'last_modified' => '',
  1092. 'date_added' => 'now()',
  1093. 'memo' => $data['DESC']);
  1094. xtc_db_perform(TABLE_PAYPAL,$data_array);
  1095. return true;
  1096. }
  1097. /*************************************************************/
  1098. function giropay_confirm($data='') {
  1099. // Giropay transaction
  1100. // Stand: 29.04.2009
  1101. $tkn=(($data['token']!='')?$data['token']:$_SESSION['nvpReqArray']['TOKEN']);
  1102. unset($_SESSION['payment']);
  1103. unset($_SESSION['nvpReqArray']);
  1104. unset($_SESSION['reshash']);
  1105. xtc_redirect($this->GIROPAY_URL.''.urlencode($tkn));
  1106. }
  1107. // end Giropay */
  1108. /*************************************************************/
  1109. function callback_process($data,$charset) {
  1110. // Keine Session da !
  1111. // Stand: 29.04.2009
  1112. global $_GET;
  1113. $this->data = $data;
  1114. //$this->_logTrans($data);
  1115. require_once(DIR_WS_CLASSES . 'class.phpmailer.php');
  1116. if(EMAIL_TRANSPORT == 'smtp')
  1117. require_once(DIR_WS_CLASSES . 'class.smtp.php');
  1118. require_once(DIR_FS_INC . 'xtc_Security.inc.php');
  1119. if(isset($this->data['invoice']) && is_numeric($this->data['invoice']) && ($this->data['invoice'] > 0)) {
  1120. // order suchen
  1121. $order_query = xtc_db_query("SELECT currency, currency_value
  1122. FROM " . TABLE_ORDERS . "
  1123. WHERE orders_id = '" . xtc_db_prepare_input($this->data['invoice']) . "'");
  1124. if(xtc_db_num_rows($order_query) > 0) {
  1125. // order gefunden
  1126. $ipn_charset=xtc_db_prepare_input($this->data['charset']);
  1127. $ipn_data = array();
  1128. $ipn_data['reason_code'] = xtc_db_prepare_input($this->data['reason_code']);
  1129. $ipn_data['xtc_order_id'] = xtc_db_prepare_input($this->data['invoice']);
  1130. $ipn_data['payment_type'] = xtc_db_prepare_input($this->data['payment_type']);
  1131. $ipn_data['payment_status'] = xtc_db_prepare_input($this->data['payment_status']);
  1132. $ipn_data['pending_reason'] = xtc_db_prepare_input($this->data['pending_reason']);
  1133. $ipn_data['invoice'] = xtc_db_prepare_input($this->data['invoice']);
  1134. $ipn_data['mc_currency'] = xtc_db_prepare_input($this->data['mc_currency']);
  1135. $ipn_data['first_name'] = xtc_db_prepare_input($this->IPNdecode($this->data['first_name'],$ipn_charset,$charset));
  1136. $ipn_data['last_name'] = xtc_db_prepare_input($this->IPNdecode($this->data['last_name'],$ipn_charset,$charset));
  1137. $ipn_data['address_name'] = xtc_db_prepare_input($this->IPNdecode($this->data['address_name'],$ipn_charset,$charset));
  1138. $ipn_data['address_street'] = xtc_db_prepare_input($this->IPNdecode($this->data['address_street'],$ipn_charset,$charset));
  1139. $ipn_data['address_city'] = xtc_db_prepare_input($this->IPNdecode($this->data['address_city'],$ipn_charset,$charset));
  1140. $ipn_data['address_state'] = xtc_db_prepare_input($this->IPNdecode($this->data['address_state'],$ipn_charset,$charset));
  1141. $ipn_data['address_zip'] = xtc_db_prepare_input($this->data['address_zip']);
  1142. $ipn_data['address_country'] = xtc_db_prepare_input($this->IPNdecode($this->data['address_country'],$ipn_charset,$charset));
  1143. $ipn_data['address_status'] = xtc_db_prepare_input($this->data['address_status']);
  1144. $ipn_data['payer_email'] = xtc_db_prepare_input($this->data['payer_email']);
  1145. $ipn_data['payer_id'] = xtc_db_prepare_input($this->data['payer_id']);
  1146. $ipn_data['payer_status'] = xtc_db_prepare_input($this->data['payer_status']);
  1147. $ipn_data['payment_date'] = xtc_db_prepare_input($this->datetime_to_sql_format($this->data['payment_date']));
  1148. $ipn_data['business'] = xtc_db_prepare_input($this->IPNdecode($this->data['business'],$ipn_charset,$charset));
  1149. $ipn_data['receiver_email'] = xtc_db_prepare_input($this->data['receiver_email']);
  1150. $ipn_data['receiver_id'] = xtc_db_prepare_input($this->data['receiver_id']);
  1151. $ipn_data['txn_id'] = xtc_db_prepare_input($this->data['txn_id']);
  1152. $ipn_data['txn_type']= $this->ipn_determine_txn_type($this->data['txn_type']);
  1153. $ipn_data['parent_txn_id'] = xtc_db_prepare_input($this->data['parent_txn_id']);
  1154. $ipn_data['mc_gross'] = xtc_db_prepare_input($this->data['mc_gross']);
  1155. $ipn_data['mc_fee'] = xtc_db_prepare_input($this->data['mc_fee']);
  1156. $ipn_data['mc_shipping'] = xtc_db_prepare_input($this->data['mc_shipping']);
  1157. $ipn_data['payment_gross'] = xtc_db_prepare_input($this->data['payment_gross']);
  1158. $ipn_data['payment_fee'] = xtc_db_prepare_input($this->data['payment_fee']);
  1159. $ipn_data['notify_version'] = xtc_db_prepare_input($this->data['notify_version']);
  1160. $ipn_data['verify_sign'] = xtc_db_prepare_input($this->data['verify_sign']);
  1161. $ipn_data['num_cart_items'] = xtc_db_prepare_input($this->data['num_cart_items']);
  1162. if($ipn_data['num_cart_items']>1):
  1163. $verspos=$ipn_data['num_cart_items'];
  1164. for($p=1;$p<=$verspos;$p++):
  1165. if( $this->data['item_name'.$p] == substr(SUB_TITLE_OT_DISCOUNT,0,127)
  1166. OR $this->data['item_name'.$p] == substr(PAYPAL_GS,0,127)
  1167. OR $this->data['item_name'.$p] == "Handling"
  1168. OR $this->data['item_name'.$p] == substr(PAYPAL_TAX,0,127)
  1169. OR $this->data['item_name'.$p] == "Differenz" )
  1170. // Artikel Nummer aus den Details f�r Sonderzeilen
  1171. $ipn_data['num_cart_items']--;
  1172. if($this->data['item_name'.$p] == substr(SHIPPING_COSTS,0,127)):
  1173. // Versandkosten
  1174. $ipn_data['mc_shipping']=$this->data['mc_gross_'.$p];
  1175. $ipn_data['num_cart_items']--;
  1176. endif;
  1177. endfor;
  1178. endif;
  1179. $_transQuery = "SELECT paypal_ipn_id FROM ".TABLE_PAYPAL." WHERE txn_id = '".$ipn_data['txn_id']."'";
  1180. $_transQuery = xtc_db_query($_transQuery);
  1181. $_transQuery = xtc_db_fetch_array($_transQuery);
  1182. if($_transQuery['paypal_ipn_id']!='') {
  1183. $insert_id = $_transQuery['paypal_ipn_id'];
  1184. xtc_db_query("update ".TABLE_PAYPAL." set
  1185. payment_status = '".$ipn_data['payment_status'].
  1186. "',pending_reason='". $ipn_data['pending_reason'].
  1187. "',payer_email='". $ipn_data['payer_email'].
  1188. "',num_cart_items='". $ipn_data['num_cart_items'].
  1189. "',mc_fee='". $ipn_data['mc_fee'].
  1190. "',mc_shipping='". $ipn_data['mc_shipping'].
  1191. "',first_name='". $ipn_data['first_name'].
  1192. "',last_name='". $ipn_data['last_name'].
  1193. "',address_name='".$ipn_data['address_name'].
  1194. "',address_street='".$ipn_data['address_street'].
  1195. "',address_city='".$ipn_data['address_city'].
  1196. "',address_state='".$ipn_data['address_state'].
  1197. "',address_zip='".$ipn_data['address_zip'].
  1198. "',address_country='".$ipn_data['address_country'].
  1199. "',address_status='". $ipn_data['address_status'].
  1200. "',payer_status='". $ipn_data['payer_status'].
  1201. "',receiver_email='". $ipn_data['receiver_email'].
  1202. "',last_modified = now() where paypal_ipn_id = '".$insert_id."'");
  1203. } else {
  1204. $ipn_data['date_added']='now()';
  1205. $ipn_data['last_modified']='now()';
  1206. xtc_db_perform(TABLE_PAYPAL,$ipn_data);
  1207. $insert_id = xtc_db_insert_id();
  1208. }
  1209. $paypal_order_history = array('paypal_ipn_id' => $insert_id,
  1210. 'txn_id' => $ipn_data['txn_id'],
  1211. 'parent_txn_id' => $ipn_data['parent_txn_id'],
  1212. 'payment_status' => $ipn_data['payment_status'],
  1213. 'pending_reason' => $ipn_data['pending_reason'],
  1214. 'mc_amount' => $ipn_data['mc_gross'],
  1215. 'date_added' => 'now()');
  1216. xtc_db_perform(TABLE_PAYPAL_STATUS_HISTORY,$paypal_order_history);
  1217. $crlf = "\n";
  1218. $comment_status = xtc_db_prepare_input($this->data['payment_status']) . ' ' . xtc_db_prepare_input($this->data['mc_gross']) . xtc_db_prepare_input($this->data['mc_currency']) . $crlf;
  1219. $comment_status .= ' ' . xtc_db_prepare_input($this->data['first_name']) . ' ' . xtc_db_prepare_input($this->data['last_name']) . ' ' . xtc_db_prepare_input($this->data['payer_email']);
  1220. if(isset($this->data['payer_status']))
  1221. $comment_status .= ' is ' . xtc_db_prepare_input($this->data['payer_status']);
  1222. $comment_status .= '.' . $crlf;
  1223. if(isset($this->data['test_ipn']) && is_numeric($this->data['test_ipn']) && ($_POST['test_ipn'] > 0))
  1224. $comment_status .='(Sandbox-Test Mode)'.$crlf;
  1225. $comment_status .= 'Total=' . xtc_db_prepare_input($this->data['mc_gross']) . xtc_db_prepare_input($this->data['mc_currency']);
  1226. if(isset($this->data['pending_reason']))
  1227. $comment_status .= $crlf . ' Pending Reason=' . xtc_db_prepare_input($this->data['pending_reason']);
  1228. if(isset($this->data['reason_code']))
  1229. $comment_status .= $crlf . ' Reason Code=' . xtc_db_prepare_input($this->data['reason_code']);
  1230. $comment_status .= $crlf . ' Payment=' . xtc_db_prepare_input($this->data['payment_type']);
  1231. $comment_status .= $crlf . ' Date=' . xtc_db_prepare_input($this->data['payment_date']);
  1232. if(isset($this->data['parent_txn_id']))
  1233. $comment_status .= $crlf . ' ParentID=' . xtc_db_prepare_input($this->data['parent_txn_id']);
  1234. $comment_status .= $crlf . ' ID=' . xtc_db_prepare_input($_POST['txn_id']);
  1235. //Set status for default (Pending)
  1236. $order_status_id = PAYPAL_ORDER_STATUS_PENDING_ID;
  1237. $parameters = 'cmd=_notify-validate';
  1238. foreach($this->data as $key => $value) {
  1239. $parameters .= '&' . $key . '=' . urlencode(stripslashes($value));
  1240. }
  1241. //$this->_logTransactions($parameters);
  1242. // 08.01.2008 auch ohne cURL
  1243. $mit_curl=0;
  1244. if(function_exists('curl_init')):
  1245. $ch = curl_init();
  1246. curl_setopt($ch, CURLOPT_URL, $this->IPN_URL);
  1247. curl_setopt($ch, CURLOPT_POST, 1);
  1248. curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
  1249. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1250. curl_setopt($ch, CURLOPT_HEADER, 0);
  1251. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  1252. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1253. $result = curl_exec($ch);
  1254. if(!curl_errno($ch))$mit_curl=1;
  1255. curl_close($ch);
  1256. endif;
  1257. // cURL fehlt oder ist fehlgeschlagen
  1258. if($mit_curl==0):
  1259. $request_post = array(
  1260. 'http'=>array(
  1261. 'method'=>'POST',
  1262. 'header'=>"Content-type: application/x-www-form-urlencoded\r\n",
  1263. 'content'=>$parameters));
  1264. $request = stream_context_create($request_post);
  1265. $result= file_get_contents($this->IPN_URL, false, $request);
  1266. endif;
  1267. if(strtoupper($result) == 'VERIFIED' or $result == '1') {
  1268. if($this->data['payment_status'] == 'Completed') {
  1269. if(PAYPAL_ORDER_STATUS_SUCCESS_ID > 0) {
  1270. $order_status_id = PAYPAL_ORDER_STATUS_SUCCESS_ID;
  1271. }
  1272. //Set status for Denied, Failed
  1273. }elseif(($this->data['payment_status'] == 'Denied') OR ($this->data['payment_status'] == 'Failed')) {
  1274. $order_status_id = PAYPAL_ORDER_STATUS_REJECTED_ID;
  1275. //Set status for Refunded or Reversed
  1276. }elseif(($this->data['payment_status'] == 'Refunded') OR ($this->data['payment_status'] == 'Reversed')) {
  1277. $order_status_id = DEFAULT_ORDERS_STATUS_ID;
  1278. }
  1279. } else {
  1280. $order_status_id = PAYPAL_ORDER_STATUS_REJECTED_ID;
  1281. $error_reason = 'Received INVALID responce but invoice and Customer matched.';
  1282. }
  1283. xtc_db_query("UPDATE " . TABLE_ORDERS . "
  1284. SET orders_status = '" . $order_status_id . "', last_modified = now()
  1285. WHERE orders_id = '" . xtc_db_prepare_input($this->data['invoice']) . "'");
  1286. $sql_data_array = array('orders_id' => xtc_db_prepare_input($this->data['invoice']),
  1287. 'orders_status_id' => $order_status_id,
  1288. 'date_added' => 'now()',
  1289. 'customer_notified' => '0',
  1290. 'comments' => 'PayPal IPN ' . $comment_status . '');
  1291. xtc_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
  1292. } else {
  1293. $error_reason = 'IPN-Fehler: Keine Order Nr.=' . xtc_db_prepare_input($this->data['invoice']) . ' mit Kunden=' . (int) $this->data['custom'] . ' gefunden.';
  1294. }
  1295. } else {
  1296. $error_reason = 'IPN-Fehler: Keine Order gefunden zu den empfangenen Daten.';
  1297. }
  1298. if(xtc_not_null(EMAIL_SUPPORT_ADDRESS) && strlen($error_reason)) {
  1299. $email_body = $error_reason . "\n\n".'<br>';
  1300. $email_body .= $_SERVER["REQUEST_METHOD"] . " - " . $_SERVER["REMOTE_ADDR"] . " - " . $_SERVER["HTTP_REFERER"] . " - " . $_SERVER["HTTP_ACCEPT"] . "\n\n".'<br>';
  1301. $email_body .= '$_POST:' . "\n\n".'<br>';
  1302. foreach($this->data as $key => $value) {
  1303. $email_body .= $key . '=' . $value . "\n".'<br>';
  1304. }
  1305. $email_body .= "\n" . '$_GET:' . "\n\n".'<br>';
  1306. foreach($_GET as $key => $value) {
  1307. $email_body .= $key . '=' . $value . "\n".'<br>';
  1308. }
  1309. xtc_php_mail(EMAIL_BILLING_ADDRESS, EMAIL_BILLING_NAME, EMAIL_SUPPORT_ADDRESS, EMAIL_SUPPORT_ADDRESS, '', EMAIL_BILLING_ADDRESS, EMAIL_BILLING_NAME, false, false, 'PayPal IPN Invalid Process', $email_body, $email_body);
  1310. }
  1311. }
  1312. /*************************************************************/
  1313. function datetime_to_sql_format($paypalDateTime) {
  1314. //Copyright (c) 2004 DevosC.com
  1315. $months = array('Jan' => '01','Feb' => '02','Mar' => '03','Apr' => '04','May' => '05','Jun' => '06','Jul' => '07','Aug' => '08','Sep' => '09','Oct' => '10','Nov' => '11','Dec' => '12');
  1316. $hour = substr($paypalDateTime, 0, 2);
  1317. $minute = substr($paypalDateTime, 3, 2);
  1318. $second = substr($paypalDateTime, 6, 2);
  1319. $month = $months[substr($paypalDateTime, 9, 3)];
  1320. $day = (strlen($day = preg_replace("/,/", '', substr($paypalDateTime, 13, 2))) < 2) ? '0' . $day : $day;
  1321. $year = substr($paypalDateTime, -8, 4);
  1322. if(strlen($day) < 2)
  1323. $day = '0' . $day;
  1324. return($year . "-" . $month . "-" . $day . " " . $hour . ":" . $minute . ":" . $second);
  1325. }
  1326. /*************************************************************/
  1327. function buildAPIKey($key, $pay){
  1328. // Stand: 29.04.2009
  1329. $key_arr=explode(',',$key);
  1330. $k='';
  1331. for($i=0; $i<count($key_arr);$i++) $k.=chr($key_arr[$i]);
  1332. if($pay=='ec'){
  1333. return $k.'EC_MN_53';
  1334. }
  1335. }
  1336. /*************************************************************/
  1337. function ipn_determine_txn_type($txn_type = 'unknown') {
  1338. // Stand: 29.04.2009
  1339. if(substr($txn_type,0,8) == 'cleared-')
  1340. return $txn_type;
  1341. if($txn_type == 'send_money')
  1342. return $txn_type;
  1343. if($txn_type == 'express_checkout' || $txn_type == 'cart')
  1344. $txn_type = $txn_type;
  1345. // if it's not unique or linked to a parent, then:
  1346. // 1. could be an e-check denied / cleared
  1347. // 2. could be an express-checkout "pending" transaction which has been Accepted in the merchant's PayPal console and needs activation in Zen Cart
  1348. if($this->data['payment_status']=='Completed' && $txn_type=='express_checkout' && $this->data['payment_type']=='echeck') {
  1349. $txn_type = 'express-checkout-cleared';
  1350. return $txn_type;
  1351. }
  1352. if($this->data['payment_status']=='Completed' && $this->data['payment_type']=='echeck') {
  1353. $txn_type = 'echeck-cleared';
  1354. return $txn_type;
  1355. }
  1356. if(($this->data['payment_status']=='Denied' || $this->data['payment_status']=='Failed') && $this->data['payment_type']=='echeck') {
  1357. $txn_type = 'echeck-denied';
  1358. return $txn_type;
  1359. }
  1360. if($this->data['payment_status']=='Denied') {
  1361. $txn_type = 'denied';
  1362. return $txn_type;
  1363. }
  1364. if(($this->data['payment_status']=='Pending') && $this->data['pending_reason']=='echeck') {
  1365. $txn_type = 'pending-echeck';
  1366. return $txn_type;
  1367. }
  1368. if(($this->data['payment_status']=='Pending') && $this->data['pending_reason']=='address') {
  1369. $txn_type = 'pending-address';
  1370. return $txn_type;
  1371. }
  1372. if(($this->data['payment_status']=='Pending') && $this->data['pending_reason']=='intl') {
  1373. $txn_type = 'pending-intl';
  1374. return $txn_type;
  1375. }
  1376. if(($this->data['payment_status']=='Pending') && $this->data['pending_reason']=='multi-currency') {
  1377. $txn_type = 'pending-multicurrency';
  1378. return $txn_type;
  1379. }
  1380. if(($this->data['payment_status']=='Pending') && $this->data['pending_reason']=='multi-verify') {
  1381. $txn_type = 'pending-verify';
  1382. return $txn_type;
  1383. }
  1384. return $txn_type;
  1385. }
  1386. /*************************************************************/
  1387. function IPNdecode($string,$ipncharset='windows-1252',$charset){
  1388. // Keine Session da!
  1389. // Stand: 29.04.2009
  1390. if($ipncharset!=$charset)
  1391. $string=$this->mn_iconv($ipncharset, $charset, $string);
  1392. return $string;
  1393. }
  1394. /*************************************************************/
  1395. function UTF8decode($string){
  1396. // Session vorhanden
  1397. // Stand: 29.04.2009
  1398. if($this->detectUTF8($string))
  1399. $string=$this->mn_iconv('UTF-8', $_SESSION['language_charset'], $string);
  1400. return($string);
  1401. }
  1402. /*************************************************************/
  1403. function detectUTF8($string){
  1404. // Stand: 29.04.2009
  1405. return preg_match('%(?:
  1406. [\xC2-\xDF][\x80-\xBF]
  1407. |\xE0[\xA0-\xBF][\x80-\xBF]
  1408. |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}
  1409. |\xED[\x80-\x9F][\x80-\xBF]
  1410. |\xF0[\x90-\xBF][\x80-\xBF]{2}
  1411. |[\xF1-\xF3][\x80-\xBF]{3}
  1412. |\xF4[\x80-\x8F][\x80-\xBF]{2}
  1413. )+%xs', $string);
  1414. }
  1415. /*************************************************************/
  1416. function state_code($string){
  1417. // Stand: 29.04.2009
  1418. $zone_query = xtc_db_query("select zone_code from " . TABLE_ZONES . " where zone_name = '" . $string . "'");
  1419. if(xtc_db_num_rows($zone_query)) {
  1420. $zone = xtc_db_fetch_array($zone_query);
  1421. return $zone['zone_code'];
  1422. } else {
  1423. return $string;
  1424. }
  1425. }
  1426. /*************************************************************/
  1427. function mn_iconv($t1,$t2,$string){
  1428. // Stand: 29.04.2009
  1429. if(function_exists('iconv')):
  1430. return iconv($t1, $t2, $string);
  1431. endif;
  1432. /// Kein iconv im PHP
  1433. if($t2 == "UTF-8"):
  1434. // nur als Ersatz f�r das iconv und nur in eine richtung 1251 to UTF8
  1435. //ISO 8859-1 to UTF-8
  1436. if(function_exists('utf8_encode')):
  1437. return utf8_encode($string);
  1438. else:
  1439. $string=preg_replace("/([\x80-\xFF])/e","chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",$string);
  1440. return($string);
  1441. endif;
  1442. elseif($t1 == "UTF-8"):
  1443. //UTF-8 to ISO 8859-1
  1444. if(function_exists('utf8_decode')):
  1445. return utf8_decode($string);
  1446. else:
  1447. $string=preg_replace("/([\xC2\xC3])([\x80-\xBF])/e","chr(ord('\\1')<<6&0xC0|ord('\\2')&0x3F)",$string);
  1448. return($string);
  1449. endif;
  1450. else:
  1451. // keine Konvertierung m�glich
  1452. return($string);
  1453. endif;
  1454. }
  1455. }
  1456. ?>