PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/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

Large files files are truncated, but you can click here to view the full file

  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. …

Large files files are truncated, but you can click here to view the full file