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

/wp-content/plugins/wp-shopping-cart/merchants/GoogleCheckout-XML.php

https://github.com/alx/barceloneta
PHP | 481 lines | 425 code | 35 blank | 21 comment | 87 complexity | 5734d6774e3c0defc17be02f7cb88d87 MD5 | raw file
  1. <?php
  2. require_once('library/googlecart.php');
  3. require_once('library/googleitem.php');
  4. require_once('library/googleshipping.php');
  5. require_once('library/googletax.php');
  6. require_once('library/googleresponse.php');
  7. require_once('library/googlemerchantcalculations.php');
  8. require_once('library/googleresult.php');
  9. require_once('library/googlerequest.php');
  10. $nzshpcrt_gateways[$num]['name'] = 'Google Checkout';
  11. $nzshpcrt_gateways[$num]['internalname'] = 'google';
  12. $nzshpcrt_gateways[$num]['function'] = 'gateway_google';
  13. $nzshpcrt_gateways[$num]['form'] = "form_google";
  14. $nzshpcrt_gateways[$num]['submit_function'] = "submit_google";
  15. $nzshpcrt_gateways[$num]['is_exclusive'] = true;
  16. function gateway_google($seperator, $sessionid)
  17. {
  18. Usecase($seperator, $sessionid);
  19. exit();
  20. }
  21. function Usecase($seperator, $sessionid) {
  22. global $wpdb;
  23. $purchase_log_sql = "SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `sessionid`= ".$sessionid." LIMIT 1";
  24. $purchase_log = $wpdb->get_results($purchase_log_sql,ARRAY_A) ;
  25. $cart_sql = "SELECT * FROM `".$wpdb->prefix."cart_contents` WHERE `purchaseid`='".$purchase_log[0]['id']."'";
  26. $wp_cart = $wpdb->get_results($cart_sql,ARRAY_A) ;
  27. $merchant_id = get_option('google_id');
  28. $merchant_key = get_option('google_key');
  29. $server_type = get_option('google_server_type');
  30. $currency = get_option('google_cur');
  31. $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
  32. $cart->SetContinueShoppingUrl(get_option('product_list_url'));
  33. $cart->SetEditCartUrl(get_option('shopping_cart_url'));
  34. $no=1;
  35. //exit("<pre>".print_r($wp_cart,true)."</pre>");
  36. foreach($wp_cart as $item){
  37. $product_data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id`='".$item['prodid']."' LIMIT 1",ARRAY_A);
  38. $product_data = $product_data[0];
  39. $prohibited = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `product_id`='".$item['prodid']."' AND meta_key='google_prohibited' LIMIT 1",ARRAY_A);
  40. $prohibited_data = $prohibited_data[0];
  41. if (count($prohibited)>0){
  42. $_SESSION['google_prohibited']='1';
  43. } else {
  44. $_SESSION['google_prohibited']='0';
  45. }
  46. $variation_count = count($product_variations);
  47. $variation_sql = "SELECT * FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id`='".$item['id']."'";
  48. $variation_data = $wpdb->get_results($variation_sql,ARRAY_A);
  49. $variation_count = count($variation_data);
  50. $extras_sql = "SELECT * FROM `".$wpdb->prefix."cart_item_extras` WHERE `cart_id`='".$item['id']."'";
  51. $extras_data = $wpdb->get_results($extras_sql,ARRAY_A);
  52. $extras_count = count($extras_data);
  53. $price = nzshpcrt_calculate_tax($item['price'], $_SESSION['selected_country'], $_SESSION['selected_region']);
  54. if ($extras_count>0) {
  55. foreach ($extras_data as $extras_datum) {
  56. $price+=$wpdb->get_var("SELECT `price` FROM `".$wpdb->prefix."extras_values_associations` WHERE `product_id` = '".$item['prodid']."' AND `extras_id` = '".$extras_datum['extra_id']."' LIMIT 1");
  57. }
  58. }
  59. //exit("------->".$price);
  60. $local_currency_shipping = $item['pnp'];
  61. $base_shipping = $purchase_log[0]['base_shipping'];
  62. $total_shipping = $local_currency_shipping+$base_shipping;
  63. $cartitem["$no"] = new GoogleItem($product_data['name'], // Item name
  64. $product_data['description'], // Item description
  65. $item['quantity'], // Quantity
  66. $price); // Unit price
  67. $cart->AddItem($cartitem["$no"]);
  68. $no++;
  69. }
  70. // Add shipping options
  71. $Gfilter = new GoogleShippingFilters();
  72. $Gfilter->SetAllowedCountryArea('ALL');
  73. $google_checkout_shipping=get_option("google_shipping_country");
  74. $google_shipping_country_ids = implode(",",$google_checkout_shipping);
  75. $google_shipping_country = $wpdb->get_var("SELECT isocode FROM ".$wpdb->prefix."currency_list WHERE id IN (".$google_shipping_country_ids.")");
  76. $Gfilter->AddAllowedPostalArea($google_shipping_country);
  77. $ship_1 = new GoogleFlatRateShipping('Flat Rate Shipping', $total_shipping);
  78. $ship_1->AddShippingRestrictions($Gfilter);
  79. $cart->AddShipping($ship_1);
  80. // Add tax rules
  81. if ($_SESSION['selected_country']=='US'){
  82. $tax_rule = new GoogleDefaultTaxRule(0.05);
  83. $state_name = $wpdb->get_var("SELECT name FROM ".$wpdb->prefix."region_tax WHERE id='".$_SESSION['selected_region']."'");
  84. $tax_rule->SetStateAreas(array($state_name));
  85. $cart->AddDefaultTaxRules($tax_rule);
  86. }
  87. $_SESSION['nzshpcrt_cart'] = null;
  88. // Specify <edit-cart-url>
  89. // $cart->SetEditCartUrl("https://www.example.com/cart/");
  90. // Specify "Return to xyz" link
  91. //$cart->SetContinueShoppingUrl("https://www.example.com/goods/");
  92. // Request buyer's phone number
  93. //$cart->SetRequestBuyerPhone(true);
  94. // Display Google Checkout button
  95. echo $cart->CheckoutButtonCode("BIG");
  96. }
  97. function submit_google() {
  98. if($_POST['google_id'] != null) {
  99. update_option('google_id', $_POST['google_id']);
  100. }
  101. if($_POST['google_key'] != null) {
  102. update_option('google_key', $_POST['google_key']);
  103. }
  104. if($_POST['google_cur'] != null) {
  105. update_option('google_cur', $_POST['google_cur']);
  106. }
  107. if($_POST['google_button_size'] != null) {
  108. update_option('google_button_size', $_POST['google_button_size']);
  109. }
  110. if($_POST['google_button_bg'] != null) {
  111. update_option('google_button_bg', $_POST['google_button_bg']);
  112. }
  113. if($_POST['google_server_type'] != null) {
  114. update_option('google_server_type', $_POST['google_server_type']);
  115. }
  116. if($_POST['google_auto_charge'] != null) {
  117. update_option('google_auto_charge', $_POST['google_auto_charge']);
  118. }
  119. return true;
  120. }
  121. function form_google()
  122. {
  123. if (get_option('google_button_size') == '0'){
  124. $button_size1="checked='checked'";
  125. } elseif(get_option('google_button_size') == '1') {
  126. $button_size2="checked='checked'";
  127. } elseif(get_option('google_button_size') == '2') {
  128. $button_size3="checked='checked'";
  129. }
  130. if (get_option('google_server_type') == 'sandbox'){
  131. $google_server_type1="checked='checked'";
  132. } elseif(get_option('google_server_type') == 'production') {
  133. $google_server_type2="checked='checked'";
  134. }
  135. if (get_option('google_auto_charge') == '1'){
  136. $google_auto_charge1="checked='checked'";
  137. } elseif(get_option('google_auto_charge') == '0') {
  138. $google_auto_charge2="checked='checked'";
  139. }
  140. if (get_option('google_button_bg') == 'trans'){
  141. $button_bg1="selected='true'";
  142. } else {
  143. $button_bg2="selected='true'";
  144. }
  145. $output = "
  146. <tr>
  147. <td>
  148. Google Checkout Merchant ID </td>
  149. <td>
  150. <input type='text' size='40' value='".get_option('google_id')."' name='google_id' />
  151. </td>
  152. </tr>
  153. <tr>
  154. <td>
  155. Google Checkout Merchant Key
  156. </td>
  157. <td>
  158. <input type='text' size='40' value='".get_option('google_key')."' name='google_key' />
  159. </td>
  160. </tr>
  161. <tr>
  162. <td>
  163. Turn on auto charging
  164. </td>
  165. <td>
  166. <input $google_auto_charge1 type='radio' name='google_auto_charge' value='1' /> Yes
  167. <input $google_auto_charge2 type='radio' name='google_auto_charge' value='0' /> No
  168. </td>
  169. </tr>
  170. <tr>
  171. <td>
  172. Google Checkout Server Type
  173. </td>
  174. <td>
  175. <input $google_server_type1 type='radio' name='google_server_type' value='sandbox' /> Sandbox (For testing)
  176. <input $google_server_type2 type='radio' name='google_server_type' value='production' /> Production
  177. </td>
  178. </tr>
  179. <tr>
  180. <td>
  181. Select your currency
  182. </td>
  183. <td>
  184. <select name='google_cur'>";
  185. if (get_option('google_cur') == 'USD') {
  186. $output.=
  187. "<option selected value='USD'>USD</option>
  188. <option value='GBP'>GBP</option>";
  189. } else {
  190. $output.=
  191. "<option value='USD'>USD</option>
  192. <option value='GBP' selected>GBP</option>";
  193. }
  194. $output.="</select>
  195. </tr>
  196. <tr>
  197. <td>
  198. Select Shipping Countries for Google Checkout
  199. </td>
  200. <td>
  201. <a href='?page=wp-shopping-cart/gatewayoptions.php&googlecheckoutshipping=1'>Set Shipping countries
  202. </td>
  203. </tr>
  204. <tr>
  205. <td>
  206. Google Checkout Button Styles
  207. </td>
  208. <td><div>Size:
  209. <input $button_size1 type='radio' name='google_button_size' value='0' /> 180&times;46
  210. <input $button_size2 type='radio' name='google_button_size' value='1' /> 168&times;44
  211. <input $button_size3 type='radio' name='google_button_size' value='2' /> 160&times;43
  212. </div>
  213. <div>
  214. Background:
  215. <select name='google_button_bg'>
  216. <option $button_bg1 value='trans'>Transparent</option>
  217. <option $button_bg2 value='white'>White</option>
  218. </div>
  219. </td>
  220. </tr>
  221. <tr>
  222. <td colspan='2'>
  223. Note: Please put this link to your Google API callback url field on your Google checkout account: <strong>".get_option('siteurl')."/index.php</strong>
  224. </td>
  225. </tr>";
  226. return $output;
  227. }
  228. function nzsc_googleResponse() {
  229. global $wpdb, $user_ID;
  230. $merchant_id = get_option('google_id');
  231. $merchant_key = get_option('google_key');
  232. $server_type = get_option('google_server_type');
  233. $currency = get_option('google_cur');
  234. define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'library/googleerror.log');
  235. define('RESPONSE_HANDLER_LOG_FILE', 'library/googlemessage.log');
  236. if (stristr($_SERVER['HTTP_USER_AGENT'],"Google Checkout Notification Agent")) {
  237. $Gresponse = new GoogleResponse($merchant_id, $merchant_key);
  238. $xml_response = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:file_get_contents("php://input");
  239. if (get_magic_quotes_gpc()) {
  240. $xml_response = stripslashes($xml_response);
  241. }
  242. list($root, $data) = $Gresponse->GetParsedXML($xml_response);
  243. $message = "<pre>".print_r($user_marketing_preference,1)."</pre>";
  244. $sessionid = (mt_rand(100,999).time());
  245. if ($root == "new-order-notification") {
  246. $_SESSION['nzshpcrt_cart'] = '';
  247. $cart_items = $data['new-order-notification']['shopping-cart']['items'];
  248. $user_marketing_preference=$data['new-order-notification']['buyer-marketing-preferences']['email-allowed']['VALUE'];
  249. $shipping_name = $data['new-order-notification']['buyer-shipping-address']['contact-name']['VALUE'];
  250. $shipping_name = explode(" ",$shipping_name);
  251. $shipping_firstname = $shipping_name[0];
  252. $shipping_lastname = $shipping_name[count($shipping_name)-1];
  253. $shipping_country = $data['new-order-notification']['buyer-shipping-address']['country-code']['VALUE'];
  254. $shipping_address1 = $data['new-order-notification']['buyer-shipping-address']['address1']['VALUE'];
  255. $shipping_address2 = $data['new-order-notification']['buyer-shipping-address']['address2']['VALUE'];
  256. $shipping_city = $data['new-order-notification']['buyer-shipping-address']['city']['VALUE'];
  257. $shipping_region = $data['new-order-notification']['buyer-shipping-address']['region']['VALUE'];
  258. $billing_name = $data['new-order-notification']['buyer-billing-address']['contact-name']['VALUE'];
  259. $billing_name = explode(" ",$shipping_name);
  260. $billing_firstname = $shipping_name[0];
  261. $billing_lastname = $shipping_name[count($shipping_name)-1];
  262. $billing_region = $data['new-order-notification']['buyer-billing-address']['region']['VALUE'];
  263. $billing_country = $data['new-order-notification']['buyer-billing-address']['country-code']['VALUE'];
  264. $total_price = $data['new-order-notification']['order-total']['VALUE'];
  265. $billing_email = $data['new-order-notification']['buyer-billing-address']['email']['VALUE'];
  266. $billing_phone = $data['new-order-notification']['buyer-billing-address']['phone']['VALUE'];
  267. $billing_address = $data['new-order-notification']['buyer-billing-address']['address1']['VALUE'];
  268. $billing_address .= " ".$data['new-order-notification']['buyer-billing-address']['address2']['VALUE'];
  269. $billing_address .= " ". $data['new-order-notification']['buyer-billing-address']['city']['VALUE'];
  270. $billing_city = $data['new-order-notification']['buyer-billing-address']['city']['VALUE'];
  271. $google_order_number = $data['new-order-notification']['google-order-number']['VALUE'];
  272. $pnp = $data['new-order-notification']['order-adjustment']['shipping']['flat-rate-shipping-adjustment']['shipping-cost']['VALUE'];
  273. //$tax = $data['new-order-notification']['order-adjustment'][];
  274. $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type,$currency);
  275. $result = $Grequest->SendProcessOrder($google_order_number);
  276. $region_number = $wpdb->get_var("SELECT id FROM ".$wpdb->prefix."region_tax` WHERE code ='".$billing_region."'");
  277. $sql = "INSERT INTO `".$wpdb->prefix."purchase_logs` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`base_shipping`,`shipping_region`, `user_ID`, `discount_value`,`gateway`, `google_order_number`, `google_user_marketing_preference`) VALUES ( '".$total_price."', '".$sessionid."', '".time()."', '".$billing_country."', '".$shipping_country."', '".$pnp."','".$region_number."' , '".$user_ID."' , '".$_SESSION['wpsc_discount']."','".get_option('payment_gateway')."','".$google_order_number."','".$user_marketing_preference."')";
  278. // mail('hanzhimeng@gmail.com',"",$sql);
  279. $wpdb->query($sql) ;
  280. $log_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."purchase_logs` WHERE `sessionid` IN('".$sessionid."') LIMIT 1") ;
  281. $sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET firstname='".$shipping_firstname."', lastname='".$shipping_lastname."', email='".$billing_email."', phone='".$billing_phone."' WHERE id='".$log_id."'";
  282. $wpdb->query($sql) ;
  283. if (array_key_exists(0,$cart_items['item'])) {
  284. $cart_items = $cart_items['item'];
  285. }
  286. //logging to submited_form_data
  287. $billing_fname_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='first_name' LIMIT 1") ;
  288. $sql = "INSERT INTO `".$wpdb->prefix."submited_form_data` (log_id, form_id, value) VALUES ('".$log_id."','".$billing_fname_id."','".$billing_firstname."')";
  289. //$wpdb->query($sql) ;
  290. $billing_lname_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='last_name' LIMIT 1") ;
  291. $sql .= ", ('".$log_id."','".$billing_lname_id."','".$billing_lastname."')";
  292. $billing_address_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='address' LIMIT 1") ;
  293. $sql .= ", ('".$log_id."','".$billing_address_id."','".$billing_address."')";
  294. $billing_city_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='city' LIMIT 1") ;
  295. $sql .= ", ('".$log_id."','".$billing_city_id."','".$billing_city."')";
  296. $billing_country_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='country' LIMIT 1") ;
  297. $sql .= ", ('".$log_id."','".$billing_country_id."','".$billing_country."')";
  298. $billing_state_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='state' LIMIT 1") ;
  299. $sql .= ", ('".$log_id."','".$billing_state_id."','".$billing_region."')";
  300. $shipping_fname_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='delivery_first_name' LIMIT 1") ;
  301. $sql .= ", ('".$log_id."','".$shipping_fname_id."','".$shipping_firstname."')";
  302. $shipping_lname_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='delivery_last_name' LIMIT 1") ;
  303. $sql .= ", ('".$log_id."','".$shipping_lname_id."','".$shipping_lastname."')";
  304. $shipping_address_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='delivery_address' LIMIT 1") ;
  305. $sql .= ", ('".$log_id."','".$shipping_address_id."','".$shipping_address1." ".$shipping_address2."')";
  306. $shipping_city_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='delivery_city' LIMIT 1") ;
  307. $sql .= ", ('".$log_id."','".$shipping_city_id."','".$shipping_city."')";
  308. $shipping_state_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='delivery_state' LIMIT 1") ;
  309. $sql .= ", ('".$log_id."','".$shipping_state_id."','".$shipping_region."')";
  310. $shipping_country_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."collect_data_forms` WHERE `type`='delivery_country' LIMIT 1") ;
  311. $sql .= ", ('".$log_id."','".$shipping_country_id."','".$shipping_country."')";
  312. $wpdb->query($sql) ;
  313. //$variations = $cart_item->product_variations;
  314. foreach($cart_items as $cart_item) {
  315. $product_id = $cart_item['merchant-item-id']['VALUE'];
  316. $item_name = $cart_item['item-name']['VALUE'];
  317. $item_desc = $cart_item['item-description']['VALUE'];
  318. $item_unit_price = $cart_item['unit-price']['VALUE'];
  319. $item_quantity = $cart_item['quantity']['VALUE'];
  320. $product_info = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_list` WHERE id='".$product_id."' LIMIT 1", ARRAY_A) ;
  321. $product_info = $product_info[0];
  322. //mail("hanzhimeng@gmail.com","",print_r($product_info,1));
  323. if($product_info['notax'] != 1) {
  324. //$price = nzshpcrt_calculate_tax($item_unit_price, $billing_country, $region_number);
  325. if(get_option('base_country') == $billing_country) {
  326. $country_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."currency_list` WHERE `isocode` IN('".get_option('base_country')."') LIMIT 1",ARRAY_A);
  327. if(($country_data['has_regions'] == 1)) {
  328. if(get_option('base_region') == $region_number) {
  329. $region_data = $wpdb->get_row("SELECT `".$wpdb->prefix."region_tax`.* FROM `".$wpdb->prefix."region_tax` WHERE `".$wpdb->prefix."region_tax`.`country_id` IN('".$country_data['id']."') AND `".$wpdb->prefix."region_tax`.`id` IN('".get_option('base_region')."') ",ARRAY_A) ;
  330. }
  331. $gst = $region_data['tax'];
  332. } else {
  333. $gst = $country_data['tax'];
  334. }
  335. } else {
  336. $gst = 0;
  337. }
  338. } else {
  339. $gst = 0;
  340. }
  341. if ($product_info['no_shipping'] == '0') {
  342. if ($shipping_country == get_option('base_country')) {
  343. $pnp = $product_info['pnp'];
  344. } else {
  345. $pnp = $product_info['international_pnp'];
  346. }
  347. } else {
  348. $pnp=0;
  349. }
  350. $cartsql = "INSERT INTO `".$wpdb->prefix."cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping` ) VALUES ('".$product_id."', '".$log_id."','".$item_unit_price."','".$pnp."', '".$gst."','".$item_quantity."', '".$product_info['donation']."', '".$product_info['no_shipping']."')";
  351. $wpdb->query($cartsql) ;
  352. }
  353. }
  354. if ($root == "order-state-change-notification") {
  355. $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE'];
  356. $google_status=$wpdb->get_var("SELECT google_status FROM ".$wpdb->prefix."purchase_logs WHERE google_order_number='".$google_order_number."'");
  357. $google_status = unserialize($google_status);
  358. if (($google_status[0]!='Partially Charged') && ($google_status[0]!='Partially Refunded')) {
  359. $google_status[0]=$data['order-state-change-notification']['new-financial-order-state']['VALUE'];
  360. $google_status[1]=$data['order-state-change-notification']['new-fulfillment-order-state']['VALUE'];
  361. }
  362. $google_status = serialize($google_status);
  363. $sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET google_status='".$google_status."' WHERE google_order_number='".$google_order_number."'";
  364. $wpdb->query($sql) ;
  365. if (($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == 'CHARGEABLE') && (get_option('google_auto_charge') == '1')) {
  366. $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type,$currency);
  367. $result = $Grequest->SendChargeOrder($google_order_number);
  368. $_SESSION['nzshpcrt_cart'] = '';
  369. unset($_SESSION['coupon_num'], $_SESSION['google_session']);
  370. $sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET processed='2' WHERE google_order_number='".$google_order_number."'";
  371. $wpdb->query($sql) ;
  372. }
  373. }
  374. if ($root == "charge-amount-notification") {
  375. $google_order_number = $data['charge-amount-notification']['google-order-number']['VALUE'];
  376. $google_status=$wpdb->get_var("SELECT google_status FROM ".$wpdb->prefix."purchase_logs WHERE google_order_number='".$google_order_number."'");
  377. $google_status = unserialize($google_status);
  378. $total_charged = $data['charge-amount-notification']['total-charge-amount']['VALUE'];
  379. $google_status['partial_charge_amount'] = $total_charged;
  380. $totalprice=$wpdb->get_var("SELECT totalprice FROM ".$wpdb->prefix."purchase_logs WHERE google_order_number='".$google_order_number."'");
  381. if ($totalprice>$total_charged) {
  382. $google_status[0] = 'Partially Charged';
  383. } else if ($totalprice=$total_charged) {
  384. $google_status[0] = 'CHARGED';
  385. }
  386. $google_status = serialize($google_status);
  387. $sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET google_status='".$google_status."' WHERE google_order_number='".$google_order_number."'";
  388. $wpdb->query($sql) ;
  389. }
  390. if ($root == "refund-amount-notification") {
  391. $google_order_number = $data['refund-amount-notification']['google-order-number']['VALUE'];
  392. $google_status=$wpdb->get_var("SELECT google_status FROM ".$wpdb->prefix."purchase_logs WHERE google_order_number='".$google_order_number."'");
  393. $google_status = unserialize($google_status);
  394. $total_charged = $data['refund-amount-notification']['total-refund-amount']['VALUE'];
  395. $google_status['partial_refund_amount'] = $total_charged;
  396. $totalprice=$wpdb->get_var("SELECT totalprice FROM ".$wpdb->prefix."purchase_logs WHERE google_order_number='".$google_order_number."'");
  397. if ($totalprice>$total_charged) {
  398. $google_status[0] = 'Partially refunded';
  399. } else if ($totalprice=$total_charged) {
  400. $google_status[0] = 'REFUNDED';
  401. }
  402. $google_status = serialize($google_status);
  403. $sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET google_status='".$google_status."' WHERE google_order_number='".$google_order_number."'";
  404. $wpdb->query($sql) ;
  405. }
  406. // <avs-response>Y</avs-response>
  407. // <cvn-response>M</cvn-response>
  408. if ($root == "risk-information-notification") {
  409. $google_order_number = $data['risk-information-notification']['google-order-number']['VALUE'];
  410. $google_status=$wpdb->get_var("SELECT google_status FROM ".$wpdb->prefix."purchase_logs WHERE google_order_number='".$google_order_number."'");
  411. $google_status = unserialize($google_status);
  412. $google_status['cvn']=$data['risk-information-notification']['risk-information']['cvn-response']['VALUE'];
  413. $google_status['avs']=$data['risk-information-notification']['risk-information']['avs-response']['VALUE'];
  414. $google_status['protection']=$data['risk-information-notification']['risk-information']['eligible-for-protection']['VALUE'];
  415. $google_status = serialize($google_status);
  416. $google_status=$wpdb->query("UPDATE ".$wpdb->prefix."purchase_logs SET google_status='".$google_status."' WHERE google_order_number='".$google_order_number."'");
  417. if ($data['risk-information-notification']['risk-information']['cvn-response']['VALUE'] == 'E') {
  418. $google_risk='cvn';
  419. }
  420. if (in_array($data['risk-information-notification']['risk-information']['avs-response']['VALUE'],array('N','U'))) {
  421. if (isset($google_risk)) {
  422. $google_risk = 'cvn+avs';
  423. } else {
  424. $google_risk='avs';
  425. }
  426. }
  427. if (isset($google_risk)) {
  428. $sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET google_risk='".$google_risk."' WHERE google_order_number='".$google_order_number."'";
  429. $wpdb->query($sql);
  430. }
  431. }
  432. if ($root == "order-state-change-notification") {
  433. $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE'];
  434. if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == "CANCELLED_BY_GOOGLE") {
  435. $google_status = $wpdb->get_var("SELECT google_status FROM ".$wpdb->prefix."purchase_logs WHERE google_order_number='".$google_order_number."'");
  436. $google_status = unserialize($google_status);
  437. $google_status[0] = "CANCELLED_BY_GOOGLE";
  438. $wpdb->get_var("UPDATE ".$wpdb->prefix."purchase_logs SET google_status='".serialize($google_status)."' WHERE google_order_number='".$google_order_number."'");
  439. }
  440. }
  441. // mail('hanzhimeng@gmail.com',"",$root . " <pre>". print_r($data,1)."</pre>");
  442. exit();
  443. }
  444. }
  445. add_action('init', 'nzsc_googleResponse');
  446. ?>