PageRenderTime 25ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-shopping-cart/merchants/paypal_multiple.php

http://cartonbank.googlecode.com/
PHP | 272 lines | 203 code | 26 blank | 43 comment | 17 complexity | 5c98a07dbde1e345162b26a582489fff MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  1. <?php
  2. $nzshpcrt_gateways[$num]['name'] = 'Paypal';
  3. $nzshpcrt_gateways[$num]['internalname'] = 'paypal_multiple';
  4. $nzshpcrt_gateways[$num]['function'] = 'gateway_paypal_multiple';
  5. $nzshpcrt_gateways[$num]['form'] = "form_paypal_multiple";
  6. $nzshpcrt_gateways[$num]['submit_function'] = "submit_paypal_multiple";
  7. function gateway_paypal_multiple($seperator, $sessionid)
  8. {
  9. global $wpdb;
  10. $purchase_log_sql = "SELECT * FROM `wp_purchase_logs` WHERE `sessionid`= ".$sessionid." LIMIT 1";
  11. $purchase_log = $wpdb->get_results($purchase_log_sql,ARRAY_A) ;
  12. $cart_sql = "SELECT * FROM `wp_cart_contents` WHERE `purchaseid`='".$purchase_log[0]['id']."'";
  13. $cart = $wpdb->get_results($cart_sql,ARRAY_A) ;
  14. $transact_url = get_option('transact_url');
  15. //$transact_url = "http://cartoonbank.ru/?page_id=32";
  16. // paypal connection variables
  17. // ales $data['business'] = get_option('paypal_multiple_business');
  18. $data['business'] = "igor.aleshin@gmail.com"; // ales
  19. $data['return'] = $transact_url.$seperator."sessionid=".$sessionid."&gateway=paypal";
  20. $data['cancel_return'] = $transact_url;
  21. $data['notify_url'] = $transact_url;
  22. $data['rm'] = '2';
  23. //$data['image'] = 'src=\"http://www.paypal.com/en_US/i/btn/x-click-but01.gif\" name=\"submit\" alt=\"Make payments with PayPal - its fast, free and secure!\"'; // ales
  24. // look up the currency codes and local price
  25. $currency_code = $wpdb->get_results("SELECT `code` FROM `wp_currency_list` WHERE `id`='".get_option(currency_type)."' LIMIT 1",ARRAY_A);
  26. $local_currency_code = $currency_code[0]['code'];
  27. //ales $paypal_currency_code = get_option('paypal_curcode');
  28. $paypal_currency_code = "USD";
  29. // Stupid paypal only accepts payments in one of 5 currencies. Convert from the currency of the users shopping cart to the curency which the user has specified in their paypal preferences.
  30. $curr=new CURRENCYCONVERTER();
  31. $data['currency_code'] = $paypal_currency_code;
  32. $data['Ic'] = 'US';
  33. $data['bn'] = 'toolkit-php';
  34. $data['no_shipping'] = '1';
  35. $data['no_note'] = '1';
  36. switch($paypal_currency_code)
  37. {
  38. case "JPY":
  39. $decimal_places = 0;
  40. break;
  41. case "HUF":
  42. $decimal_places = 0;
  43. break;
  44. default:
  45. $decimal_places = 2;
  46. }
  47. $i = 1;
  48. foreach($cart as $item)
  49. {
  50. $product_data = $wpdb->get_results("SELECT * FROM `wp_product_list` WHERE `id`='".$item['prodid']."' LIMIT 1",ARRAY_A);
  51. $product_data = $product_data[0];
  52. //exit("<pre>" . print_r($item,true) ."</pre>");
  53. $variation_count = count($product_variations);
  54. $variation_sql = "SELECT * FROM `wp_cart_item_variations` WHERE `cart_id`='".$item['id']."'";
  55. $variation_data = $wpdb->get_results($variation_sql,ARRAY_A);
  56. //exit("<pre>" . print_r($variation_data,true) ."</pre>");
  57. $variation_count = count($variation_data);
  58. if($variation_count >= 1)
  59. {
  60. $variation_list = " (";
  61. $j = 0;
  62. foreach($variation_data as $variation)
  63. {
  64. if($j > 0)
  65. {
  66. $variation_list .= ", ";
  67. }
  68. $value_id = $variation['venue_id'];
  69. $value_data = $wpdb->get_results("SELECT * FROM `wp_variation_values` WHERE `id`='".$value_id."' LIMIT 1",ARRAY_A);
  70. $variation_list .= $value_data[0]['name'];
  71. $j++;
  72. }
  73. $variation_list .= ")";
  74. }
  75. else
  76. {
  77. $variation_list = '';
  78. }
  79. if($product_data['special']==1)
  80. {
  81. $price_modifier = $product_data['special_price'];
  82. }
  83. else
  84. {
  85. $price_modifier = 0;
  86. }
  87. $local_currency_productprice = ($product_data['price'] - $price_modifier) * get_option('gst_rate');
  88. $local_currency_shipping = nzshpcrt_determine_item_shipping($item['prodid'], $item['quantity'], $_SESSION['selected_country']);
  89. if($paypal_currency_code != $local_currency_code)
  90. {
  91. $paypal_currency_productprice = $curr->convert($local_currency_productprice,$paypal_currency_code,$local_currency_code);
  92. $paypal_currency_shipping = $curr->convert($local_currency_shipping,$paypal_currency_code,$local_currency_code);
  93. //exit("bad");
  94. }
  95. else
  96. {
  97. $paypal_currency_productprice = $local_currency_productprice;
  98. $paypal_currency_shipping = $local_currency_shipping;
  99. //exit("good");
  100. }
  101. $data['item_name_'.$i] = $product_data['name'].$variation_list;
  102. // ales $data['amount_'.$i] = number_format(sprintf("%01.2f", $paypal_currency_productprice),$decimal_places,'.','');
  103. $data['amount_'.$i] = '10'; // ales
  104. $data['quantity_'.$i] = $item['quantity'];
  105. $data['item_number_'.$i] = $product_data['id'];
  106. //exit($paypal_currency_shipping);
  107. $data['shipping_'.$i] = number_format($paypal_currency_shipping,$decimal_places,'.','');
  108. $data['handling_'.$i] = '';
  109. $i++;
  110. }
  111. $data['tax'] = '';
  112. $base_shipping = nzshpcrt_determine_base_shipping(0, $_SESSION['selected_country']);
  113. if($base_shipping > 0)
  114. {
  115. $data['item_name_'.$i] = "Shipping";
  116. $data['amount_'.$i] = number_format(0,$decimal_places,'.','');
  117. $data['quantity_'.$i] = 1;
  118. $data['item_number_'.$i] = 0;
  119. $data['shipping_'.$i] = number_format($base_shipping,$decimal_places,'.','');
  120. $data['handling_'.$i] = '';
  121. }
  122. $data['custom'] = '';
  123. $data['invoice'] = $sessionid;
  124. // User details
  125. /*
  126. $data['first_name'] = $_POST['firstname'];
  127. $data['last_name'] = $_POST['lastname'];
  128. */
  129. $address_data = $wpdb->get_results("SELECT `id`,`type` FROM `wp_collect_data_forms` WHERE `type` IN ('address','delivery_address') AND `active` = '1'",ARRAY_A);
  130. foreach((array)$address_data as $address)
  131. {
  132. $data['address1'] = $_POST['collected_data'][$address['id']];
  133. if($address['type'] == 'delivery_address')
  134. {
  135. break;
  136. }
  137. }
  138. $city_data = $wpdb->get_results("SELECT `id`,`type` FROM `wp_collect_data_forms` WHERE `type` IN ('city','delivery_city') AND `active` = '1'",ARRAY_A);
  139. foreach((array)$city_data as $city)
  140. {
  141. $data['city'] = $_POST['collected_data'][$city['id']];
  142. if($city['type'] == 'delivery_city')
  143. {
  144. break;
  145. }
  146. }
  147. $country_data = $wpdb->get_results("SELECT `id`,`type` FROM `wp_collect_data_forms` WHERE `type` IN ('country','delivery_country') AND `active` = '1'",ARRAY_A);
  148. foreach((array)$country_data as $country)
  149. {
  150. $data['country'] = $_POST['collected_data'][$country['id']];
  151. if($address['type'] == 'delivery_country')
  152. {
  153. break;
  154. }
  155. }
  156. //$data['country'] = $_POST['address'];
  157. // Change suggested by waxfeet@gmail.com, if email to be sent is not there, dont send an email address
  158. if($_POST['collected_data'][get_option('email_form_field')] != null)
  159. {
  160. $data['email'] = $_POST['collected_data'][get_option('email_form_field')];
  161. }
  162. $data['upload'] = '1';
  163. $data['cmd'] = "_ext-enter";
  164. $data['redirect_cmd'] = "_cart";
  165. $datacount = count($data);
  166. $num = 0;
  167. foreach($data as $key=>$value)
  168. {
  169. $amp = '&';
  170. $num++;
  171. if($num == $datacount)
  172. {
  173. $amp = '';
  174. }
  175. $output .= $key.'='.urlencode($value).$amp;
  176. }
  177. //exit("<pre>" . print_r($_POST,true) ."</pre>");
  178. //exit("<pre>" . print_r($_SESSION,true) ."</pre>");
  179. //exit("<pre>" . print_r($data,true) ."</pre>");
  180. header("Location: ".get_option('paypal_multiple_url')."?".$output);
  181. exit();
  182. }
  183. function submit_paypal_multiple()
  184. {
  185. update_option('paypal_multiple_business', $_POST['paypal_multiple_business']);
  186. update_option('paypal_multiple_url', $_POST['paypal_multiple_url']);
  187. update_option('paypal_curcode', $_POST['paypal_curcode']);
  188. return true;
  189. }
  190. function form_paypal_multiple()
  191. {
  192. $select_currency[get_option('paypal_curcode')] = "selected='true'";
  193. $output = "
  194. <tr>
  195. <td>
  196. PayPal Username
  197. </td>
  198. <td>
  199. <input type='text' size='40' value='".get_option('paypal_multiple_business')."' name='paypal_multiple_business' />
  200. </td>
  201. </tr>
  202. <tr>
  203. <td>
  204. PayPal Url
  205. </td>
  206. <td>
  207. <input type='text' size='40' value='".get_option('paypal_multiple_url')."' name='paypal_multiple_url' />
  208. </td>
  209. </tr>
  210. <tr>
  211. <td>
  212. </td>
  213. <td>
  214. <strong>Note:</strong>The URL to use for the paypal gateway is: https://www.paypal.com/cgi-bin/webscr
  215. </td>
  216. </tr>
  217. <tr>
  218. <td>
  219. PayPal Accepted Currency (e.g. USD, AUD)
  220. </td>
  221. <td>";
  222. /*
  223. $output .= " <select name='paypal_curcode'>
  224. <option ".$select_currency['USD']." value='USD'>U.S. Dollar</option>
  225. <option ".$select_currency['CAD']." value='CAD'>Canadian Dollar</option>
  226. <option ".$select_currency['AUD']." value='AUD'>Australian Dollar</option>
  227. <option ".$select_currency['EUR']." value='EUR'>Euro</option>
  228. <option ".$select_currency['GBP']." value='GBP'>Pound Sterling</option>
  229. <option ".$select_currency['JPY']." value='JPY'>Yen</option>
  230. <option ".$select_currency['NZD']." value='NZD'>New Zealand Dollar</option>
  231. <option ".$select_currency['CHF']." value='CHF'>Swiss Franc</option>
  232. <option ".$select_currency['HKD']." value='HKD'>Hong Kong Dollar</option>
  233. <option ".$select_currency['SGD']." value='SGD'>Singapore Dollar</option>
  234. <option ".$select_currency['SEK']." value='SEK'>Swedish Krona</option>
  235. <option ".$select_currency['HUF']." value='HUF'>Hungarian Forint</option>
  236. <option ".$select_currency['DKK']." value='DKK'>Danish Krone</option>
  237. <option ".$select_currency['PLN']." value='PLN'>Polish Zloty</option>
  238. <option ".$select_currency['NOK']." value='NOK'>Norwegian Krone</option>
  239. <option ".$select_currency['CZK']." value='CZK'>Czech Koruna</option>
  240. </select>";
  241. */
  242. $output .= " </td>
  243. </tr>";
  244. return $output;
  245. }
  246. ?>