function RequestToken() { $this->request_token_xml = $this->GetTokenRequestXML(); //create GRequest object + post xml (googlecart.php line: 962) require_once 'library/googlerequest.php'; $GRequest = new GoogleRequest($this->merchant_id, $this->merchant_key); /*---------------------------------------------------------------------------------------------------*/ $GRequest->SetCertificatePath("/etc/ssl/certs/ca-certificates.crt"); $this->token_response_xml = $GRequest->SendReq($this->server_url, $GRequest->GetAuthenticationHeaders(), $this->request_token_xml); //Check response code if ($this->token_response_xml[0] == "200") { require_once 'xml-processing/gc_XmlParser.php'; $GXmlParser = new gc_XmlParser($this->token_response_xml[1]); $data = $GXmlParser->GetData(); $this->continue_token = $data['notification-data-token-response']['continue-token']['VALUE']; return $this->continue_token; } else { return false; } }
function nzsc_googleResponse() { global $wpdb, $user_ID; $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'library/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'library/googlemessage.log'); if (stristr($_SERVER['HTTP_USER_AGENT'], "Google Checkout Notification Agent")) { $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } list($root, $data) = $Gresponse->GetParsedXML($xml_response); $message = "<pre>" . print_r($user_marketing_preference, 1) . "</pre>"; $sessionid = mt_rand(100, 999) . time(); if ($root == "new-order-notification") { $_SESSION['nzshpcrt_cart'] = ''; $cart_items = $data['new-order-notification']['shopping-cart']['items']; $user_marketing_preference = $data['new-order-notification']['buyer-marketing-preferences']['email-allowed']['VALUE']; $shipping_name = $data['new-order-notification']['buyer-shipping-address']['contact-name']['VALUE']; $shipping_name = explode(" ", $shipping_name); $shipping_firstname = $shipping_name[0]; $shipping_lastname = $shipping_name[count($shipping_name) - 1]; $shipping_country = $data['new-order-notification']['buyer-shipping-address']['country-code']['VALUE']; $shipping_address1 = $data['new-order-notification']['buyer-shipping-address']['address1']['VALUE']; $shipping_address2 = $data['new-order-notification']['buyer-shipping-address']['address2']['VALUE']; $shipping_city = $data['new-order-notification']['buyer-shipping-address']['city']['VALUE']; $shipping_region = $data['new-order-notification']['buyer-shipping-address']['region']['VALUE']; $billing_name = $data['new-order-notification']['buyer-billing-address']['contact-name']['VALUE']; $billing_name = explode(" ", $shipping_name); $billing_firstname = $shipping_name[0]; $billing_lastname = $shipping_name[count($shipping_name) - 1]; $billing_region = $data['new-order-notification']['buyer-billing-address']['region']['VALUE']; $billing_country = $data['new-order-notification']['buyer-billing-address']['country-code']['VALUE']; $total_price = $data['new-order-notification']['order-total']['VALUE']; $billing_email = $data['new-order-notification']['buyer-billing-address']['email']['VALUE']; $billing_phone = $data['new-order-notification']['buyer-billing-address']['phone']['VALUE']; $billing_address = $data['new-order-notification']['buyer-billing-address']['address1']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['address2']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $billing_city = $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $google_order_number = $data['new-order-notification']['google-order-number']['VALUE']; $pnp = $data['new-order-notification']['order-adjustment']['shipping']['flat-rate-shipping-adjustment']['shipping-cost']['VALUE']; $affiliate_id = $data['new-order-notification']['shopping-cart']['merchant-private-data']; $affiliate_id = explode('=', $affiliate_id); if ($affiliate_id[0] == 'affiliate_id') { if ($affiliate_id[1] == '') { $affiliate_id = null; } else { $affiliate_id = $affiliate_id[1]; } } $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendProcessOrder($google_order_number); $region_number = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSC_TABLE_REGION_TAX . "` WHERE code = %s", $billing_region)); $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total_price, 'sessionid' => $sessionid, 'date' => time(), 'billing_country' => $billing_country, 'shipping_country' => $shipping_country, 'base_shipping' => $pnp, 'shipping_region' => $region_number, 'user_ID' => $user_ID, 'discount_value' => $_SESSION['wpsc_discount'], 'gateway' => get_option('payment_gateway'), 'google_order_number' => $google_order_number, 'google_user_marketing_preference' => $user_marketing_preference, 'affiliate_id' => $affiliate_id), array('%f', '%s', '%s', '%s', '%s', '%f', '%s', '%d', '%f', '%s', '%s', '%s', '%s')); $log_id = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN(%s) LIMIT 1", $sessionid)); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('firstname' => $shipping_firstname, 'lastname' => $shipping_lastname, 'email' => $billing_email, 'phone' => $billing_phone), array('id' => $log_id), '%s', '%d'); if (array_key_exists(0, $cart_items['item'])) { $cart_items = $cart_items['item']; } //logging to submited_form_data $billing_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='first_name' LIMIT 1"); $sql = "INSERT INTO `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` (log_id, form_id, value) VALUES ('" . $log_id . "','" . $billing_fname_id . "','" . esc_sql($billing_firstname) . "')"; $billing_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_lname_id . "','" . esc_sql($billing_lastname) . "')"; $billing_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_address_id . "','" . esc_sql($billing_address) . "')"; $billing_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_city_id . "','" . esc_sql($billing_city) . "')"; $billing_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_country_id . "','" . esc_sql($billing_country) . "')"; $billing_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_state_id . "','" . esc_sql($billing_region) . "')"; $shipping_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_first_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_fname_id . "','" . esc_sql($shipping_firstname) . "')"; $shipping_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_lname_id . "','" . esc_sql($shipping_lastname) . "')"; $shipping_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_address_id . "','" . esc_sql($shipping_address1) . " " . esc_sql($shipping_address2) . "')"; $shipping_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_city_id . "','" . esc_sql($shipping_city) . "')"; $shipping_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_state_id . "','" . esc_sql($shipping_region) . "')"; $shipping_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_country_id . "','" . esc_sql($shipping_country) . "')"; $wpdb->query($sql); foreach ($cart_items as $cart_item) { $product_id = $cart_item['merchant-item-id']['VALUE']; $item_name = $cart_item['item-name']['VALUE']; $item_desc = $cart_item['item-description']['VALUE']; $item_unit_price = $cart_item['unit-price']['VALUE']; $item_quantity = $cart_item['quantity']['VALUE']; $product_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $wpdb->posts . "` WHERE id= %d LIMIT 1", $product_id), ARRAY_A); $product_info = $product_info[0]; if ($product_info['notax'] != 1) { if (get_option('base_country') == $billing_country) { $country_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode` IN(%s) LIMIT 1", get_option('base_country')), ARRAY_A); if ($country_data['has_regions'] == 1) { if (get_option('base_region') == $region_number) { $region_data = $wpdb->get_row($wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `" . WPSC_TABLE_REGION_TAX . "`.`country_id` IN(%d) AND `" . WPSC_TABLE_REGION_TAX . "`.`id` IN(%d)", $country_data['id'], get_option('base_region')), ARRAY_A); } $gst = $region_data['tax']; } else { $gst = $country_data['tax']; } } else { $gst = 0; } } else { $gst = 0; } if ($product_info['no_shipping'] == '0') { if ($shipping_country == get_option('base_country')) { $pnp = $product_info['pnp']; } else { $pnp = $product_info['international_pnp']; } } else { $pnp = 0; } $wpdb->insert(WPSC_TABLE_CART_CONTENTS, array('prodid' => $product_id, 'purchaseid' => $log_id, 'price' => $item_unit_price, 'pnp' => $pnp, 'gst' => $gst, 'quantity' => $item_quantity, 'donation' => $product_info['donation'], 'no_shipping' => $product_info['no_shipping']), array('%d', '%d', '%s', '%f', '%f', '%d', '%s', '%s')); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); if ($google_status[0] != 'Partially Charged' && $google_status[0] != 'Partially Refunded') { $google_status[0] = $data['order-state-change-notification']['new-financial-order-state']['VALUE']; $google_status[1] = $data['order-state-change-notification']['new-fulfillment-order-state']['VALUE']; } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == 'CHARGEABLE' && get_option('google_auto_charge') == '1') { $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendChargeOrder($google_order_number); $_SESSION['nzshpcrt_cart'] = ''; unset($_SESSION['coupon_num'], $_SESSION['google_session']); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('processed' => '3'), array('google_order_number' => $google_order_number)); } } if ($root == "charge-amount-notification") { $google_order_number = $data['charge-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $total_charged = $data['charge-amount-notification']['total-charge-amount']['VALUE']; $google_status['partial_charge_amount'] = $total_charged; $totalprice = $wpdb->get_var($wpdb->prepare("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); if ($totalprice > $total_charged) { $google_status[0] = 'Partially Charged'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'CHARGED'; } } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); } if ($root == "refund-amount-notification") { $google_order_number = $data['refund-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number= %s", $google_order_number)); $google_status = unserialize($google_status); $total_charged = $data['refund-amount-notification']['total-refund-amount']['VALUE']; $google_status['partial_refund_amount'] = $total_charged; $totalprice = $wpdb->get_var($wpdb->prepare("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); if ($totalprice > $total_charged) { $google_status[0] = 'Partially refunded'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'REFUNDED'; } } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); } if ($root == "risk-information-notification") { $google_order_number = $data['risk-information-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $google_status['cvn'] = $data['risk-information-notification']['risk-information']['cvn-response']['VALUE']; $google_status['avs'] = $data['risk-information-notification']['risk-information']['avs-response']['VALUE']; $google_status['protection'] = $data['risk-information-notification']['risk-information']['eligible-for-protection']['VALUE']; $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); if ($data['risk-information-notification']['risk-information']['cvn-response']['VALUE'] == 'E') { $google_risk = 'cvn'; } if (in_array($data['risk-information-notification']['risk-information']['avs-response']['VALUE'], array('N', 'U'))) { if (isset($google_risk)) { $google_risk = 'cvn+avs'; } else { $google_risk = 'avs'; } } if (isset($google_risk)) { $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_risk' => $google_risk), array('google_order_number' => $google_order_number)); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == "CANCELLED_BY_GOOGLE") { $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $google_status[0] = "CANCELLED_BY_GOOGLE"; $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => serialize($google_status)), array('google_order_number' => $google_order_number)); } } exit; } }
function nzshpcrt_submit_ajax() { global $wpdb, $user_level, $wp_rewrite; get_currentuserinfo(); if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } $cartt = $_SESSION['nzshpcrt_cart']; $cartt1 = $cartt[0]->product_id; // if is an AJAX request, cruddy code, could be done better but getting approval would be impossible if ($_POST['ajax'] == "true" || $_GET['ajax'] == "true") { if ($_POST['changetax'] == "true") { if (isset($_POST['billing_region'])) { $billing_region = $_POST['billing_region']; } else { $billing_region = $_SESSION['selected_region']; } $billing_country = $_POST['billing_country']; foreach ($cartt as $cart_item) { $product_id = $cart_item->product_id; $quantity = $cart_item->quantity; //echo("<pre>".print_r($cart_item->product_variations,true)."</pre>"); $product = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id` = '{$product_id}' LIMIT 1", ARRAY_A); if ($product['donation'] == 1) { $price = $quantity * $cart_item->donation_price; } else { $price = $quantity * calculate_product_price($product_id, $cart_item->product_variations); if ($product['notax'] != 1) { $tax += nzshpcrt_calculate_tax($price, $billing_country, $billing_region) - $price; } $all_donations = false; } if ($_SESSION['delivery_country'] != null) { $total_shipping += nzshpcrt_determine_item_shipping($product['id'], $quantity, $_SESSION['delivery_country']); } } echo $tax . ":" . $price . ":" . $total_shipping; exit; } if ($_POST['submittogoogle']) { $newvalue = $_POST['value']; $amount = $_POST['amount']; $reason = $_POST['reason']; $comment = $_POST['comment']; $message = $_POST['message']; $amount = number_format($amount, 2, '.', ''); $log_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "purchase_logs` WHERE `id` = '" . $_POST['id'] . "' LIMIT 1", ARRAY_A); if ($newvalue == 2 && function_exists('wpsc_member_activate_subscriptions')) { wpsc_member_activate_subscriptions($_POST['id']); } $google_status = unserialize($log_data['google_status']); switch ($newvalue) { case "Charge": if ($google_status[0] != 'CANCELLED_BY_GOOGLE') { if ($amount == '') { $google_status['0'] = 'Partially Charged'; } else { $google_status['0'] = 'CHARGED'; $google_status['partial_charge_amount'] = $amount; } } break; case "Cancel": if ($google_status[0] != 'CANCELLED_BY_GOOGLE') { $google_status[0] = 'CANCELLED'; } if ($google_status[1] != 'DELIVERED') { $google_status[1] = 'WILL_NOT_DELIVER'; } break; case "Refund": if ($amount == '') { $google_status['0'] = 'Partially Refund'; } else { $google_status['0'] = 'REFUND'; $google_status['partial_refund_amount'] = $amount; } break; case "Ship": if ($google_status[1] != 'WILL_NOT_DELIVER') { $google_status[1] = 'DELIVERED'; } break; case "Archive": $google_status[1] = 'ARCHIVED'; break; } $google_status_sql = "UPDATE `" . $wpdb->prefix . "purchase_logs` SET google_status='" . serialize($google_status) . "' WHERE `id` = '" . $_POST['id'] . "' LIMIT 1"; $wpdb->query($google_status_sql); $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $google_order_number = $wpdb->get_var("SELECT google_order_number FROM `" . $wpdb->prefix . "purchase_logs` WHERE `id` = '" . $_POST['id'] . "' LIMIT 1"); switch ($newvalue) { case 'Charge': $Grequest->SendChargeOrder($google_order_number, $amount); break; case 'Ship': $Grequest->SendDeliverOrder($google_order_number); break; case 'Archive': $Grequest->SendArchiveOrder($google_order_number); break; case 'Refund': $Grequest->SendRefundOrder($google_order_number, $amount, $reason); break; case 'Cancel': $Grequest->SendCancelOrder($google_order_number, $reason, $comment); break; case 'Send Message': $Grequest->SendBuyerMessage($google_order_number, $message); break; } $newvalue++; $update_sql = "UPDATE `" . $wpdb->prefix . "purchase_logs` SET `processed` = '" . $newvalue . "' WHERE `id` = '" . $_POST['id'] . "' LIMIT 1"; //$wpdb->query($update_sql); exit; } ////changes for usps if ($_POST['uspsswitch']) { foreach ($_SESSION['uspsQuote'] as $quotes) { $total = $_POST['total']; if ($quotes[$_POST['key']] != '') { echo nzshpcrt_currency_display($total + $quotes[$_POST['key']], 1); echo "<input type='hidden' value='" . $total . "' id='shopping_cart_total_price'>"; $_SESSION['usps_shipping'] = $quotes[$_POST['key']]; } } exit; } //changes for usps ends if ($_GET['user'] == "true" && is_numeric($_POST['prodid'])) { $memberstatus = get_product_meta($_POST['prodid'], 'is_membership', true); if ($memberstatus[0] == '1' && $_SESSION['nzshopcrt_cart'] != NULL) { } else { $sql = "SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id`='" . $_POST['prodid'] . "' LIMIT 1"; $item_data = $wpdb->get_results($sql, ARRAY_A); $item_quantity = 0; if ($_SESSION['nzshpcrt_cart'] != null) { foreach ($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) { if ($memberstatus[0] != '1' && $_SESSION['nzshpcrt_cart'] != NULL) { if ($cart_item->product_id == $_POST['prodid']) { if ($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $_POST['variation'] && $_SESSION['nzshpcrt_cart'][$cart_key]->extras === $_POST['extras']) { $item_quantity += $_SESSION['nzshpcrt_cart'][$cart_key]->quantity; $item_variations = $_SESSION['nzshpcrt_cart'][$cart_key]->product_variations; } } } } } $item_stock = null; $variation_count = count($_POST['variation']); if ($variation_count >= 1 && $variation_count <= 2) { foreach ($_POST['variation'] as $variation_id) { if (is_numeric($variation_id)) { $variation_ids[] = (int) $variation_id; } } if (count($variation_ids) == 2) { $variation_stock_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "variation_priceandstock` WHERE `product_id` = '" . $_POST['prodid'] . "' AND (`variation_id_1` = '" . $variation_ids[0] . "' AND `variation_id_2` = '" . $variation_ids[1] . "') OR (`variation_id_1` = '" . $variation_ids[1] . "' AND `variation_id_2` = '" . $variation_ids[0] . "') LIMIT 1", ARRAY_A); $item_stock = $variation_stock_data['stock']; } else { if (count($variation_ids) == 1) { $variation_stock_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "variation_priceandstock` WHERE `product_id` = '" . $_POST['prodid'] . "' AND (`variation_id_1` = '" . $variation_ids[0] . "' AND `variation_id_2` = '0') LIMIT 1", ARRAY_A); $item_stock = $variation_stock_data['stock']; } } } if ($item_stock === null) { $item_stock = $item_data[0]['quantity']; } if ($item_data[0]['quantity_limited'] == 1 && $item_stock > 0 && $item_stock > $item_quantity || $item_data[0]['quantity_limited'] == 0) { $cartcount = count($_SESSION['nzshpcrt_cart']); if (is_array($_POST['variation'])) { $variations = $_POST['variation']; } else { $variations = null; } if (is_array($_POST['extras'])) { $extras = $_POST['extras']; } else { $extras = null; } $updated_quantity = false; if ($_SESSION['nzshpcrt_cart'] != null) { foreach ($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) { if (!($memberstatus[0] == '1') && count($_SESSION['nzshpcrt_cart']) > 0) { if ((int) $cart_item->product_id === (int) $_POST['prodid']) { // force both to integer before testing for identicality if ($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $extras && $_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $variations && (int) $_SESSION['nzshpcrt_cart'][$cart_key]->donation_price == (int) $_POST['donation_price']) { if (is_numeric($_POST['quantity'])) { $_SESSION['nzshpcrt_cart'][$cart_key]->quantity += (int) $_POST['quantity']; } else { $_SESSION['nzshpcrt_cart'][$cart_key]->quantity++; } $updated_quantity = true; } } } } } if ($item_data[0]['donation'] == 1) { $donation = $_POST['donation_price']; } else { $donation = false; } if (!($memberstatus[0] == '1' && count($_SESSION['nzshpcrt_cart']) > 0)) { $status = get_product_meta($cartt1, 'is_membership', true); if ($status[0] == '1') { exit; } if ($updated_quantity === false) { if (is_numeric($_POST['quantity'])) { if ($_POST['quantity'] > 0) { $new_cart_item = new cart_item($_POST['prodid'], $variations, $_POST['quantity'], $donation, $extras); } } else { //echo "correct"; $new_cart_item = new cart_item($_POST['prodid'], $variations, 1, $donation, $extras); } $_SESSION['nzshpcrt_cart'][] = $new_cart_item; } } } else { $quantity_limit = true; } $cart = $_SESSION['nzshpcrt_cart']; if ($memberstatus[0] == '1' && count($cart) > 1) { } else { $status = get_product_meta($cartt1, 'is_membership', true); if ($status[0] == '1') { exit('st'); } echo "if(document.getElementById('shoppingcartcontents') != null)\n\t\t\t\t\t {\n\t\t\t\t\t document.getElementById('shoppingcartcontents').innerHTML = \"" . str_replace(array("\n", "\r"), "", addslashes(nzshpcrt_shopping_basket_internals($cart, $quantity_limit))) . "\";\n\t\t\t\t\t }\n\t\t\t\t\t"; if ($_POST['prodid'] != null && get_option('fancy_notifications') == 1) { echo "if(document.getElementById('fancy_notification_content') != null)\n\t\t\t\t\t {\n\t\t\t\t\t document.getElementById('fancy_notification_content').innerHTML = \"" . str_replace(array("\n", "\r"), "", addslashes(fancy_notification_content($_POST['prodid'], $quantity_limit))) . "\";\n\t\t\t\t\t jQuery('#loading_animation').css('display', 'none');\n\t\t\t\t\t jQuery('#fancy_notification_content').css('display', 'block'); \n\t\t\t\t\t }\n\t\t\t\t\t"; } if ($_SESSION['slider_state'] == 0) { echo 'jQuery("#sliding_cart").css({ display: "none"});' . "\n\r"; } else { echo 'jQuery("#sliding_cart").css({ display: "block"});' . "\n\r"; } } } exit; } else { if ($_POST['user'] == "true" && $_POST['emptycart'] == "true") { //exit("/* \n\r ".get_option('shopping_cart_url')." \n\r ".print_r($_POST,true)." \n\r */"); $_SESSION['nzshpcrt_cart'] = ''; $_SESSION['nzshpcrt_cart'] = array(); echo "if(document.getElementById('shoppingcartcontents') != null) { \n\t\t\tdocument.getElementById('shoppingcartcontents').innerHTML = \"" . str_replace(array("\n", "\r"), "", addslashes(nzshpcrt_shopping_basket_internals($cart))) . "\";\n\t\t\t}\n\r"; if ($_POST['current_page'] == get_option('shopping_cart_url')) { echo "window.location = '" . get_option('shopping_cart_url') . "';\n\r"; // if we are on the checkout page, redirect back to it to clear the non-ajax cart too } exit; } } if ($_POST['store_list'] == "true") { $map_data['address'] = $_POST['addr']; $map_data['city'] = $_POST['city']; $map_data['country'] = 'US'; $map_data['zipcode'] = ''; $map_data['radius'] = '50000'; $map_data['state'] = ''; $map_data['submit'] = 'Find Store'; $stores = getdistance($map_data); $i = 0; while ($rows = mysql_fetch_array($stores)) { //echo "<pre>".print_r($rows,1)."</pre>"; if ($i == 0) { $closest_store = $rows[5]; } $i++; $store_list[$i] = $rows[5]; } foreach ($store_list as $store) { $output .= "<option value='{$store}'>{$store}</option>"; } echo $output; exit; } if ($_POST['admin'] == "true") { if (is_numeric($_POST['prodid'])) { /* fill product form */ echo nzshpcrt_getproductform($_POST['prodid']); exit; } else { if (is_numeric($_POST['catid'])) { /* fill category form */ echo nzshpcrt_getcategoryform($_POST['catid']); exit; } else { if (is_numeric($_POST['brandid'])) { /* fill brand form */ echo nzshpcrt_getbrandsform($_POST['brandid']); exit; } else { if (is_numeric($_POST['variation_id'])) { echo nzshpcrt_getvariationform($_POST['variation_id']); exit; } } } } if ($_POST['hide_ecom_dashboard'] == 'true') { require_once ABSPATH . WPINC . '/rss.php'; $rss = fetch_rss('http://www.instinct.co.nz/feed/'); $rss->items = array_slice($rss->items, 0, 5); $rss_hash = sha1(serialize($rss->items)); update_option('wpsc_ecom_news_hash', $rss_hash); exit(1); } if ($_POST['remove_meta'] == 'true' && is_numeric($_POST['meta_id'])) { $meta_id = (int) $_POST['meta_id']; $selected_meta = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}wpsc_productmeta` WHERE `id` IN('{$meta_id}') ", ARRAY_A); if ($selected_meta != null) { if ($wpdb->query("DELETE FROM `{$wpdb->prefix}wpsc_productmeta` WHERE `id` IN('{$meta_id}') LIMIT 1")) { echo $meta_id; exit; } } echo 0; exit; } exit; } if (is_numeric($_POST['currencyid'])) { $currency_data = $wpdb->get_results("SELECT `symbol`,`symbol_html`,`code` FROM `" . $wpdb->prefix . "currency_list` WHERE `id`='" . $_POST['currencyid'] . "' LIMIT 1", ARRAY_A); $price_out = null; if ($currency_data[0]['symbol'] != '') { $currency_sign = $currency_data[0]['symbol_html']; } else { $currency_sign = $currency_data[0]['code']; } echo $currency_sign; exit; } //echo "--==->"; if ($_POST['buynow'] == "true") { $id = $_REQUEST['product_id']; $price = $_REQUEST['price']; $downloads = get_option('max_downloads'); $product_sql = "SELECT * FROM " . $wpdb->prefix . "product_list WHERE id = " . $id . " LIMIT 1"; $product_info = $wpdb->get_results($product_sql, ARRAY_A); $product_info = $product_info[0]; $sessionid = mt_rand(100, 999) . time(); $sql = "INSERT INTO `" . $wpdb->prefix . "purchase_logs` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`shipping_region`, `user_ID`, `discount_value` ) VALUES ( '" . $price . "', '" . $sessionid . "', '" . time() . "', 'BuyNow', 'BuyNow', 'BuyNow' , NULL , 0)"; $wpdb->query($sql); $log_id = $wpdb->get_var("SELECT `id` FROM `" . $wpdb->prefix . "purchase_logs` WHERE `sessionid` IN('" . $sessionid . "') LIMIT 1"); $cartsql = "INSERT INTO `" . $wpdb->prefix . "cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping` ) VALUES ('" . $id . "', '" . $log_id . "','" . $price . "','0', '0','1', '" . $donation . "', '1')"; $wpdb->query($cartsql); $wpdb->query("INSERT INTO `" . $wpdb->prefix . "download_status` ( `fileid` , `purchid` , `downloads` , `active` , `datetime` ) VALUES ( '" . $product_info['file'] . "', '" . $log_id . "', '{$downloads}', '0', NOW( ));"); exit; } if ($_POST['changeorder'] == "true" && is_numeric($_POST['category_id'])) { $category_id = (int) $_POST['category_id']; $hash = $_POST['sort1']; $order = 1; foreach ($hash as $id) { $wpdb->query("UPDATE `" . $wpdb->prefix . "product_order` SET `order`={$order} WHERE `product_id`=" . (int) $id . " AND `category_id`=" . (int) $category_id . " LIMIT 1"); $order++; } exit(" "); } /* rate item */ if ($_POST['rate_item'] == "true" && is_numeric($_POST['product_id']) && is_numeric($_POST['rating'])) { $nowtime = time(); $prodid = $_POST['product_id']; $ip_number = $_SERVER['REMOTE_ADDR']; $rating = $_POST['rating']; $cookie_data = explode(",", $_COOKIE['voting_cookie'][$prodid]); if (is_numeric($cookie_data[0]) && $cookie_data[0] > 0) { $vote_id = $cookie_data[0]; $wpdb->query("UPDATE `" . $wpdb->prefix . "product_rating` SET `rated` = '" . $rating . "' WHERE `id` ='" . $vote_id . "' LIMIT 1 ;"); } else { $insert_sql = "INSERT INTO `" . $wpdb->prefix . "product_rating` ( `ipnum` , `productid` , `rated`, `time`) VALUES ( '" . $ip_number . "', '" . $prodid . "', '" . $rating . "', '" . $nowtime . "');"; $wpdb->query($insert_sql); $data = $wpdb->get_results("SELECT `id`,`rated` FROM `" . $wpdb->prefix . "product_rating` WHERE `ipnum`='" . $ip_number . "' AND `productid` = '" . $prodid . "' AND `rated` = '" . $rating . "' AND `time` = '" . $nowtime . "' ORDER BY `id` DESC LIMIT 1", ARRAY_A); $vote_id = $data[0]['id']; setcookie("voting_cookie[{$prodid}]", $vote_id . "," . $rating, time() + 60 * 60 * 24 * 360); } $output[1] = $prodid; $output[2] = $rating; echo $output[1] . "," . $output[2]; exit; } //written by allen if ($_REQUEST['save_tracking_id'] == "true") { $id = $_POST['id']; $value = $_POST['value']; $update_sql = "UPDATE " . $wpdb->prefix . "purchase_logs SET track_id = '" . $value . "' WHERE id={$id}"; $wpdb->query($update_sql); exit; } if ($_POST['get_rating_count'] == "true" && is_numeric($_POST['product_id'])) { $prodid = $_POST['product_id']; $data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "product_rating` WHERE `productid` = '" . $prodid . "'", ARRAY_A); echo $data[0]['count'] . "," . $prodid; exit; } /// Pointless AJAX call is pointless // if(isset($_POST['changeperpage'])) { // $item_per_page = $_POST['changeperpage']; // echo $item_per_page; // exit(); // } if ($_POST['remove_variation_value'] == "true" && is_numeric($_POST['variation_value_id'])) { $wpdb->query("DELETE FROM `" . $wpdb->prefix . "variation_values_associations` WHERE `value_id` = '" . $_POST['variation_value_id'] . "'"); $wpdb->query("DELETE FROM `" . $wpdb->prefix . "variation_values` WHERE `id` = '" . $_POST['variation_value_id'] . "' LIMIT 1"); exit; } if ($_POST['get_updated_price'] == "true" && is_numeric($_POST['product_id'])) { $notax = $wpdb->get_var("SELECT `notax` FROM `" . $wpdb->prefix . "product_list` WHERE `id` IN('" . $_POST['product_id'] . "') LIMIT 1"); foreach ((array) $_POST['variation'] as $variation) { if (is_numeric($variation)) { $variations[] = $variation; } } foreach ((array) $_POST['extra'] as $extra) { if (is_numeric($extra)) { $extras[] = $extra; } } $pm = $_POST['pm']; echo "product_id=" . $_POST['product_id'] . ";\n"; echo "price=\"" . nzshpcrt_currency_display(calculate_product_price($_POST['product_id'], $variations, 'stay', $extras), $notax) . "\";\n"; //exit(print_r($extras,1)); exit; } if ($_REQUEST['log_state'] == "true" && is_numeric($_POST['id']) && is_numeric($_POST['value'])) { $newvalue = $_POST['value']; if ($_REQUEST['suspend'] == 'true') { if ($_REQUEST['value'] == 1) { wpsc_member_dedeactivate_subscriptions($_POST['id']); } else { wpsc_member_deactivate_subscriptions($_POST['id']); } exit; } else { $log_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "purchase_logs` WHERE `id` = '" . $_POST['id'] . "' LIMIT 1", ARRAY_A); if ($newvalue == 2 && function_exists('wpsc_member_activate_subscriptions')) { wpsc_member_activate_subscriptions($_POST['id']); } $update_sql = "UPDATE `" . $wpdb->prefix . "purchase_logs` SET `processed` = '" . $newvalue . "' WHERE `id` = '" . $_POST['id'] . "' LIMIT 1"; $wpdb->query($update_sql); //echo("/*"); if ($newvalue > $log_data['processed'] && $log_data['processed'] < 2) { transaction_results($log_data['sessionid'], false); } //echo("*/"); $stage_sql = "SELECT * FROM `" . $wpdb->prefix . "purchase_statuses` WHERE `id`='" . $newvalue . "' AND `active`='1' LIMIT 1"; $stage_data = $wpdb->get_row($stage_sql, ARRAY_A); echo "document.getElementById(\"form_group_" . $_POST['id'] . "_text\").innerHTML = '" . $stage_data['name'] . "';\n"; echo "document.getElementById(\"form_group_" . $_POST['id'] . "_text\").style.color = '#" . $stage_data['colour'] . "';\n"; $year = date("Y"); $month = date("m"); $start_timestamp = mktime(0, 0, 0, $month, 1, $year); $end_timestamp = mktime(0, 0, 0, $month + 1, 0, $year); echo "document.getElementById(\"log_total_month\").innerHTML = '" . addslashes(nzshpcrt_currency_display(admin_display_total_price($start_timestamp, $end_timestamp), 1)) . "';\n"; echo "document.getElementById(\"log_total_absolute\").innerHTML = '" . addslashes(nzshpcrt_currency_display(admin_display_total_price(), 1)) . "';\n"; exit; } } if ($_POST['list_variation_values'] == "true" && is_numeric($_POST['new_variation_id'])) { $variation_processor = new nzshpcrt_variations(); echo "variation_value_id = \"" . $_POST['new_variation_id'] . "\";\n"; echo "variation_value_html = \"" . $variation_processor->display_variation_values($_POST['prefix'], $_POST['new_variation_id']) . "\";\n"; $variations_selected = array_values(array_unique(array_merge((array) $_POST['new_variation_id'], (array) $_POST['variation_id']))); echo "variation_subvalue_html = \"" . str_replace("\n\r", '\\n\\r', $variation_processor->variations_add_grid_view((array) $variations_selected)) . "\";\n"; //echo "/*\n\r".print_r(array_values(array_unique(array_merge((array)$_POST['new_variation_id'], $_POST['variation_id']))),true)."\n\r*/"; exit; } if ($_POST['redisplay_variation_values'] == "true") { $variation_processor = new nzshpcrt_variations(); $variations_selected = array_values(array_unique(array_merge((array) $_POST['new_variation_id'], (array) $_POST['variation_id']))); foreach ($variations_selected as $variation_id) { // cast everything to integer to make sure nothing nasty gets in. $variation_list[] = (int) $variation_id; } echo $variation_processor->variations_add_grid_view((array) $variation_list); //echo "/*\n\r".print_r(array_values(array_unique($_POST['variation_id'])),true)."\n\r*/"; exit; } if ($_POST['edit_variation_value_list'] == 'true' && is_numeric($_POST['variation_id']) && is_numeric($_POST['product_id'])) { $variation_id = (int) $_POST['variation_id']; $product_id = (int) $_POST['product_id']; $variations_processor = new nzshpcrt_variations(); $variation_values = $variations_processor->falsepost_variation_values($variation_id); if (is_array($variation_values)) { //echo(print_r($variation_values,true)); $check_variation_added = $wpdb->get_var("SELECT `id` FROM `" . $wpdb->prefix . "variation_associations` WHERE `type` IN ('product') AND `associated_id` IN ('{$product_id}') AND `variation_id` IN ('{$variation_id}') LIMIT 1"); if ($check_variation_added == null) { $variations_processor->add_to_existing_product($product_id, $variation_values); } echo $variations_processor->display_attached_variations($product_id); echo $variations_processor->variations_grid_view($product_id); } else { echo "false"; } exit; } if ($_POST['remove_form_field'] == "true" && is_numeric($_POST['form_id'])) { //exit(print_r($user,true)); if (current_user_can('level_7')) { $wpdb->query("UPDATE `" . $wpdb->prefix . "collect_data_forms` SET `active` = '0' WHERE `id` ='" . $_POST['form_id'] . "' LIMIT 1 ;"); exit(' '); } } /* * function for handling the checkout billing address */ if (preg_match("/[a-zA-Z]{2,4}/", $_POST['billing_country'])) { if ($_SESSION['selected_country'] == $_POST['billing_country']) { $do_not_refresh_regions = true; } else { $do_not_refresh_regions = false; $_SESSION['selected_country'] = $_POST['billing_country']; } if (is_numeric($_POST['form_id'])) { $form_id = $_POST['form_id']; $html_form_id = "region_country_form_{$form_id}"; } else { $html_form_id = 'region_country_form'; } if (is_numeric($_POST['billing_region'])) { $_SESSION['selected_region'] = $_POST['billing_region']; } $cart =& $_SESSION['nzshpcrt_cart']; if ($memberstatus[0] == '1' && count($cart) > 0) { echo "\n\t\t\t"; } else { if ($status[0] == '1') { exit; } echo "if(document.getElementById('shoppingcartcontents') != null)\n\t\t\t\t\t {\n\t\t\t\t\t document.getElementById('shoppingcartcontents').innerHTML = \"" . str_replace(array("\n", "\r"), "", addslashes(nzshpcrt_shopping_basket_internals($cart, $quantity_limit))) . "\";\n\t\t\t\t\t }\n\t\t\t\t\t"; if ($do_not_refresh_regions == false) { $region_list = $wpdb->get_results("SELECT `" . $wpdb->prefix . "region_tax`.* FROM `" . $wpdb->prefix . "region_tax`, `" . $wpdb->prefix . "currency_list` WHERE `" . $wpdb->prefix . "currency_list`.`isocode` IN('" . $_POST['billing_country'] . "') AND `" . $wpdb->prefix . "currency_list`.`id` = `" . $wpdb->prefix . "region_tax`.`country_id`", ARRAY_A); if ($region_list != null) { $output .= "<select name='collected_data[" . $form_id . "][1]' class='current_region' onchange='set_billing_country(\\\"{$html_form_id}\\\", \\\"{$form_id}\\\");'>"; //$output .= "<option value=''>None</option>"; foreach ($region_list as $region) { if ($_SESSION['selected_region'] == $region['id']) { $selected = "selected='true'"; } else { $selected = ""; } $output .= "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>"; } $output .= "</select>"; echo "if(document.getElementById('region_select_{$form_id}') != null)\n\t\t {\n\t\t document.getElementById('region_select_{$form_id}').innerHTML = \"" . $output . "\";\n\t\t }\n\t\t"; } else { echo "if(document.getElementById('region_select_{$form_id}') != null)\n\t\t {\n\t\t document.getElementById('region_select_{$form_id}').innerHTML = \"\";\n\t\t }\n\t\t"; } } } exit; } if ($_POST['get_country_tax'] == "true" && preg_match("/[a-zA-Z]{2,4}/", $_POST['country_id'])) { $country_id = $_POST['country_id']; $region_list = $wpdb->get_results("SELECT `" . $wpdb->prefix . "region_tax`.* FROM `" . $wpdb->prefix . "region_tax`, `" . $wpdb->prefix . "currency_list` WHERE `" . $wpdb->prefix . "currency_list`.`isocode` IN('" . $country_id . "') AND `" . $wpdb->prefix . "currency_list`.`id` = `" . $wpdb->prefix . "region_tax`.`country_id`", ARRAY_A); if ($region_list != null) { echo "<select name='base_region'>\n\r"; foreach ($region_list as $region) { if (get_option('base_region') == $region['id']) { $selected = "selected='true'"; } else { $selected = ""; } echo "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>\n\r"; } echo "</select>\n\r"; } else { echo " "; } exit; } /* fill product form */ if ($_POST['set_slider'] == "true" && is_numeric($_POST['state'])) { $_SESSION['slider_state'] = $_POST['state']; exit; } /* fill category form */ if ($_GET['action'] == "register") { $siteurl = get_option('siteurl'); require_once ABSPATH . WPINC . '/registration-functions.php'; if ($_POST['action'] == 'register' && get_settings('users_can_register')) { //exit("fail for testing purposes"); $user_login = sanitize_user($_POST['user_login']); $user_email = $_POST['user_email']; $errors = array(); if ($user_login == '') { exit($errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.')); } /* checking e-mail address */ if ($user_email == '') { exit(__('<strong>ERROR</strong>: Please type your e-mail address.')); } else { if (!is_email($user_email)) { exit(__('<strong>ERROR</strong>: The email address isn’t correct.')); $user_email = ''; } } if (!validate_username($user_login)) { $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.'); $user_login = ''; } if (username_exists($user_login)) { exit(__('<strong>ERROR</strong>: This username is already registered, please choose another one.')); } /* checking the email isn't already used by another user */ $email_exists = $wpdb->get_row("SELECT user_email FROM {$wpdb->users} WHERE user_email = '{$user_email}'"); if ($email_exists) { die(__('<strong>ERROR</strong>: This email address is already registered, please supply another.')); } if (0 == count($errors)) { $password = substr(md5(uniqid(microtime())), 0, 7); //xit('there?'); $user_id = wp_create_user($user_login, $password, $user_email); if (!$user_id) { exit(sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email'))); } else { wp_new_user_notification($user_id, $password); ?> <div id="login"> <h2><?php _e('Registration Complete'); ?> </h2> <p><?php printf(__('Username: %s'), "<strong>" . wp_specialchars($user_login) . "</strong>"); ?> <br /> <?php printf(__('Password: %s'), '<strong>' . __('emailed to you') . '</strong>'); ?> <br /> <?php printf(__('E-mail: %s'), "<strong>" . wp_specialchars($user_email) . "</strong>"); ?> </p> </div> <?php } } } else { // onsubmit='submit_register_form(this);return false;' echo "<div id='login'>\n <h2>Register for this blog</h2>\n <form id='registerform' action='index.php?ajax=true&action=register' onsubmit='submit_register_form(this);return false;' method='post'>\n <p><input type='hidden' value='register' name='action'/>\n <label for='user_login'>Username:</label><br/> <input type='text' value='' maxlength='20' size='20' id='user_login' name='user_login'/><br/></p>\n <p><label for='user_email'>E-mail:</label><br/> <input type='text' value='' maxlength='100' size='25' id='user_email' name='user_email'/></p>\n <p>A password will be emailed to you.</p>\n <p class='submit'><input type='submit' name='submit_form' id='submit' value='Register »'/><img id='register_loading_img' src='" . WPSC_URL . "/images/loading.gif' alt='' title=''></p>\n \n </form>\n </div>"; } exit; } } /* * AJAX stuff stops here, I would put an exit here, but it may screw up other plugins //exit(); */ }
* <send_mail>); * Send archive order: $Grequest->SendArchiveOrder($data[$root] * ['google-order-number']['VALUE']); * */ switch ($root) { case "new-order-notification": break; case "risk-information-notification": break; case "charge-amount-notification": break; case "authorization-amount-notification": $google_order_number = $data[$root]['google-order-number']['VALUE']; $tracking_data = array("Z12345" => "UPS", "Y12345" => "Fedex"); $GChargeRequest = new GoogleRequest($merchant_id, $merchant_key, $server_type); $GChargeRequest->SendChargeAndShipOrder($google_order_number, $tracking_data); break; case "refund-amount-notification": break; case "chargeback-amount-notification": break; case "order-numbers": break; case "invalid-order-numbers": break; case "order-state-cahnge-notification": break; default: break; }
public function external_hook($hook) { switch ($hook) { case 'notification': if (!isset($_REQUEST['serial-number']) || !$_REQUEST['serial-number']) { send_error('Google API not setup correctly. Please ensure API callback URL is set correctly as per instructions'); exit; } chdir(dirname(__FILE__)); //'includes/plugin_paymethod_google/'); require_once 'library/googleresponse.php'; //require_once('library/googlemerchantcalculations.php'); require_once 'library/googleresult.php'; require_once 'library/googlerequest.php'; require_once 'library/googlenotification.php'; require_once 'library/googlenotificationhistory.php'; define('RESPONSE_HANDLER_ERROR_LOG_FILE', _UCM_FOLDER . '/temp/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', _UCM_FOLDER . '/temp/googlemessage.log'); $server_type = self::is_sandbox() ? "sandbox" : ''; //$currency = module_config::get_currency($currency_id); //$Gresponse = new GoogleResponse(self::get_merchant_id(), self::get_merchant_key()); $Grequest = new GoogleRequest(self::get_merchant_id(), self::get_merchant_key(), $server_type); $GNotificationHistory = new GoogleNotificationHistoryRequest(self::get_merchant_id(), self::get_merchant_key(), $server_type); $response = $GNotificationHistory->SendNotificationHistoryRequest($_REQUEST['serial-number']); $xml_response_status = $response[0]; $xml_response = $response[1]; $response = new SimpleXMLElement($xml_response); $root = $response->getName(); // debugging //send_error('xml2: '.$root.var_export($response,true)); //$Gresponse->SetMerchantAuthentication(self::get_merchant_id(), self::get_merchant_key()); //$Gresponse->SendAck(); $google_order_number = (string) $response->{'google-order-number'}; if ($google_order_number) { $invoice_payment_data = get_single('invoice_payment', 'other_id', $google_order_number); } else { $invoice_payment_data = false; send_error('Google payment API failure, no Google Order Number located'); } if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) { self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Recorded an API hit: ' . $root); } switch ($root) { case "new-order-notification": // an order has been placed. // dont really need to do anything. // we grab the merchant private data from this bit // it contains the private id etc.. if ($google_order_number && $response->{'shopping-cart'}->{'merchant-private-data'}) { $private_data = (array) $response->{'shopping-cart'}->{'merchant-private-data'}; $invoice_id = (int) $private_data['invoice_id']; $invoice_payment_id = (int) $private_data['invoice_payment_id']; if ($invoice_id > 0 && $invoice_payment_id > 0) { self::add_payment_data($invoice_payment_id, 'log', 'Found Google Order Number: ' . $google_order_number); $sql = "UPDATE `" . _DB_PREFIX . "invoice_payment` SET `other_id` = '" . mysql_real_escape_string($google_order_number) . "' WHERE invoice_id = '{$invoice_id}' AND invoice_payment_id = '{$invoice_payment_id}'"; query($sql); } } break; case "order-state-change-notification": $new_financial_state = (string) $response->{'new-financial-order-state'}; if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) { self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Recorded an order status change to: ' . $new_financial_state); } switch ($new_financial_state) { case 'REVIEWING': break; case 'CHARGEABLE': if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) { self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Charging customers credit card. '); } // process and charge the order: $Grequest->SendProcessOrder($google_order_number); $Grequest->SendChargeOrder($google_order_number, ''); break; case 'CHARGING': break; case 'CHARGED': break; case 'PAYMENT_DECLINED': break; case 'CANCELLED': break; case 'CANCELLED_BY_GOOGLE': //$Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'], // "Sorry, your order is cancelled by Google", true); break; default: break; } break; case "charge-amount-notification": // payment has been made! // update the order. $Grequest->SendArchiveOrder($google_order_number); if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) { self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Received a payment of ' . $response->{'latest-charge-amount'} . ' and assigning it to this invoice.'); update_insert("invoice_payment_id", $invoice_payment_data['invoice_payment_id'], "invoice_payment", array('date_paid' => date('Y-m-d'))); } break; case "chargeback-amount-notification": break; case "refund-amount-notification": break; case "risk-information-notification": break; default: //$Gresponse->SendBadRequestStatus("Invalid or not supported Message"); break; } break; } }
require_once 'library/googleresponse.php'; require_once 'library/googlemerchantcalculations.php'; require_once 'library/googleresult.php'; require_once 'library/googlerequest.php'; define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log'); $merchant_id = "369263219659530"; // Your Merchant ID $merchant_key = "9mumsrr2wMyNuFaZRB91rg"; // Your Merchant Key $server_type = "sandbox"; // change this to go live $currency = 'USD'; // set to GBP if in the UK $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); //serial-number //Setup the log file $Gresponse->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL); $Grequest->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL); //How to grab the serial number!!!! $serial = $_POST["serial-number"]; $Gresponse->log->LogResponse("serial:" . $serial); if ($serial != null) { $Grequest->SendNotificationRequest($serial); $Gresponse->SendAck($serial); return; } // Retrieve the XML sent in the HTTP POST request to the ResponseHandler $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); if (get_magic_quotes_gpc()) {
/** * Send a <notification-history-request> request to Google Checkout * * info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Notification_History_API.html} * * @param string $sn serial number * @param string $npt next page token * @param array $orders array of string google order numbers * @param array $nt array of string notification types * @param array $st array of tracking data where tracking code => carrier * @param string @st string of start time in format YYYY-MM-DD[T]HH:MM:SS[Timezone] ie * 2010-05-01T05:00:00Z * @param string @et string of end time in format YYYY-MM-DD[T]HH:MM:SS[Timezone] ie * 2010-05-02T05:00:00Z * @param string $cp path to SSL certificates for peer validation */ function SendNotificationHistoryRequest($sn = null, $npt = null, $orders = array(), $nt = array(), $st = null, $et = null, $cp = null) { $postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; $postargs .= "<notification-history-request xmlns=\"" . $this->schema_url . "\">"; if (isset($sn)) { $postargs .= "<serial-number>" . $sn . "</serial-number>"; } elseif (isset($npt)) { $postargs .= "<next-page-token>" . $npt . "</next-page-token>"; } else { if (isset($orders) && count($orders) > 0) { $postargs .= "<order-numbers>"; foreach ($orders as $order) { $postargs .= "<google-order-number>" . $order . "</google-order-number>"; } $postargs .= "</order-numbers>"; } if (isset($nt) && count($nt) > 0) { $postargs .= "<notification-types>"; foreach ($nt as $notification_type) { $postargs .= "<notification-type>" . $notification_type . "</notification-type"; } $postargs .= "</notification-types>"; } if (isset($st) && isset($et)) { $postargs .= "<start-time>" . $st . "</start-time>"; $postargs .= "<end-time>" . $et . "</end-time>"; } } $postargs .= "</notification-history-request>"; $Grequest = new GoogleRequest($this->merchant_id, $this->merchant_key, $this->server_type); $GRequest->SetCertificatePath($cp); return $Grequest->SendReq($Grequest->GetReportUrl(), $Grequest->GetAuthenticationHeaders(), $postargs); }
while (!feof($fp)) { $line = trim(fgets($fp)); if ($line && !ereg("^{$comment}", $line)) { $pieces = explode("=", $line); $option = trim($pieces[0]); $value = trim($pieces[1]); $config_values[$option] = $value; } } fclose($fp); //print_r($config_values); $merchant_id = $config_values['CONFIG_MERCHANT_ID']; $merchant_key = $config_values['CONFIG_MERCHANT_KEY']; $server_type = $config_values['CONFIG_SERVER_TYPE']; $currency = $config_values['CONFIG_CURRENCY']; $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = ""; } if (isset($_POST['email'])) { $email = $_POST['email']; } else { $email = ""; } //Reload orders of an specific user depending on who is logged in if ($action == "reloadOrders") { if (isset($_POST['userid'])) { $userid = $_POST['userid']; } else {
/** * Submit a server-to-server request. * Creates a GoogleRequest object (defined in googlerequest.php) and sends * it to the Google Checkout server. * * more info: * {@link http://code.google.com/apis/checkout/developer/index.html#alternate_technique} * * @return array with the returned http status code (200 if OK) in index 0 * and the redirect url returned by the server in index 1 */ function CheckoutServer2Server($proxy = array(), $certPath = '') { ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '.'); require_once 'library/googlerequest.php'; $GRequest = new GoogleRequest($this->merchant_id, $this->merchant_key, $this->server_url == "https://checkout.google.com/" ? "Production" : "sandbox", $this->currency); $GRequest->SetProxy($proxy); $GRequest->SetCertificatePath($certPath); return $GRequest->SendServer2ServerCart($this->GetXML()); }
*/ /* This example demostrats line item shipping */ chdir(".."); require_once 'library/googleresponse.php'; require_once 'library/googlemerchantcalculations.php'; require_once 'library/googleresult.php'; require_once 'library/googlerequest.php'; define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log'); $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; // change this to go live $currency = 'USD'; // set to GBP if in the UK $certificate_path = ""; // set your SSL CA cert path $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $GRequest->SetCertificatePath($certificate_path); $item1 = new GoogleShipItem('SKU_1'); $item1->AddTrackingData('USPS', '123123adjsh123'); $item2 = new GoogleShipItem('SKU_2'); $item2->AddTrackingData('USPS', '123123adjsh123'); $item2->AddTrackingData('fedex', 'adajs549p80789163'); $items = array($item1, $item2, new GoogleShipItem('SKU_3', array(array('carrier' => 'DHL', 'tracking-number' => 'akjshdj12323'), array('carrier' => 'USPS', 'tracking-number' => 'aasd4a4sd465a3'))), new GoogleShipItem('SKU_4', array(array('carrier' => 'UPS', 'tracking-number' => '09876543231')))); $Grequest->SendShipItems('123456789', $items); $Grequest->SendCancelItems('123456789', array($item1, $item2), "reason", "comment"); $Grequest->SendReturnItems('123456789', $items);
/** * Submit a server-to-server request. * Creates a GoogleRequest object (defined in googlerequest.php) and sends * it to the Google Checkout server. * * more info: * {@link http://code.google.com/apis/checkout/developer/index.html#alternate_technique} * * @return array with the returned http status code (200 if OK) in index 0 * and the redirect url returned by the server in index 1 */ function CheckoutServer2Server($proxy = array(), $certPath = '') { require_once dirname(__FILE__) . '/library/googlerequest.php'; $GRequest = new GoogleRequest($this->merchant_id, $this->merchant_key, $this->server_url == "https://checkout.google.com/" ? "Production" : "sandbox", $this->currency); $GRequest->SetProxy($proxy); $GRequest->SetCertificatePath($certPath); return $GRequest->SendServer2ServerCart($this->GetXML()); }
while (!feof($fp)) { $line = trim(fgets($fp)); if ($line && !ereg("^{$comment}", $line)) { $pieces = explode("=", $line); $option = trim($pieces[0]); $value = trim($pieces[1]); $config_values[$option] = $value; } } fclose($fp); $merchant_id = $config_values['CONFIG_MERCHANT_ID']; $merchant_key = $config_values['CONFIG_MERCHANT_KEY']; $server_type = $config_values['CONFIG_SERVER_TYPE']; $currency = $config_values['CONFIG_CURRENCY']; $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); //serial-number //Setup the log file $Gresponse->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL); $Grequest->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL); //How to grab the serial number!!!! /* $serial = $_POST["serial-number"]; $Gresponse->log->LogResponse("serial:" . $serial); if ($serial != null) { $Grequest->SendNotificationRequest($serial); $Gresponse->SendAck($serial); return; } */ // Retrieve the XML sent in the HTTP POST request to the ResponseHandler $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
function nzsc_googleResponse() { global $wpdb, $user_ID; $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'library/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'library/googlemessage.log'); if (stristr($_SERVER['HTTP_USER_AGENT'], "Google Checkout Notification Agent")) { $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } list($root, $data) = $Gresponse->GetParsedXML($xml_response); $message = "<pre>" . print_r($user_marketing_preference, 1) . "</pre>"; $sessionid = mt_rand(100, 999) . time(); if ($root == "new-order-notification") { $_SESSION['nzshpcrt_cart'] = ''; $cart_items = $data['new-order-notification']['shopping-cart']['items']; $user_marketing_preference = $data['new-order-notification']['buyer-marketing-preferences']['email-allowed']['VALUE']; $shipping_name = $data['new-order-notification']['buyer-shipping-address']['contact-name']['VALUE']; $shipping_name = explode(" ", $shipping_name); $shipping_firstname = $shipping_name[0]; $shipping_lastname = $shipping_name[count($shipping_name) - 1]; $shipping_country = $data['new-order-notification']['buyer-shipping-address']['country-code']['VALUE']; $shipping_address1 = $data['new-order-notification']['buyer-shipping-address']['address1']['VALUE']; $shipping_address2 = $data['new-order-notification']['buyer-shipping-address']['address2']['VALUE']; $shipping_city = $data['new-order-notification']['buyer-shipping-address']['city']['VALUE']; $shipping_region = $data['new-order-notification']['buyer-shipping-address']['region']['VALUE']; $billing_name = $data['new-order-notification']['buyer-billing-address']['contact-name']['VALUE']; $billing_name = explode(" ", $shipping_name); $billing_firstname = $shipping_name[0]; $billing_lastname = $shipping_name[count($shipping_name) - 1]; $billing_region = $data['new-order-notification']['buyer-billing-address']['region']['VALUE']; $billing_country = $data['new-order-notification']['buyer-billing-address']['country-code']['VALUE']; $total_price = $data['new-order-notification']['order-total']['VALUE']; $billing_email = $data['new-order-notification']['buyer-billing-address']['email']['VALUE']; $billing_phone = $data['new-order-notification']['buyer-billing-address']['phone']['VALUE']; $billing_address = $data['new-order-notification']['buyer-billing-address']['address1']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['address2']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $billing_city = $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $google_order_number = $data['new-order-notification']['google-order-number']['VALUE']; $pnp = $data['new-order-notification']['order-adjustment']['shipping']['flat-rate-shipping-adjustment']['shipping-cost']['VALUE']; $affiliate_id = $data['new-order-notification']['shopping-cart']['merchant-private-data']; $affiliate_id = explode('=', $affiliate_id); if ($affiliate_id[0] == 'affiliate_id') { if ($affiliate_id[1] == '') { $affiliate_id = null; } else { $affiliate_id = $affiliate_id[1]; } } //$tax = $data['new-order-notification']['order-adjustment'][]; $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendProcessOrder($google_order_number); $region_number = $wpdb->get_var("SELECT id FROM " . WPSC_TABLE_REGION_TAX . "` WHERE code ='" . $billing_region . "'"); $sql = "INSERT INTO `" . WPSC_TABLE_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`, `affiliate_id`) 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 . "', '" . $affiliate_id . "')"; // mail('*****@*****.**',"",$sql); $wpdb->query($sql); $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('" . $sessionid . "') LIMIT 1"); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET firstname='" . $shipping_firstname . "', lastname='" . $shipping_lastname . "', email='" . $billing_email . "', phone='" . $billing_phone . "' WHERE id='" . $log_id . "'"; $wpdb->query($sql); if (array_key_exists(0, $cart_items['item'])) { $cart_items = $cart_items['item']; } //logging to submited_form_data $billing_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='first_name' LIMIT 1"); $sql = "INSERT INTO `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` (log_id, form_id, value) VALUES ('" . $log_id . "','" . $billing_fname_id . "','" . $billing_firstname . "')"; //$wpdb->query($sql) ; $billing_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_lname_id . "','" . $billing_lastname . "')"; $billing_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_address_id . "','" . $billing_address . "')"; $billing_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_city_id . "','" . $billing_city . "')"; $billing_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_country_id . "','" . $billing_country . "')"; $billing_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_state_id . "','" . $billing_region . "')"; $shipping_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_first_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_fname_id . "','" . $shipping_firstname . "')"; $shipping_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_lname_id . "','" . $shipping_lastname . "')"; $shipping_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_address_id . "','" . $shipping_address1 . " " . $shipping_address2 . "')"; $shipping_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_city_id . "','" . $shipping_city . "')"; $shipping_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_state_id . "','" . $shipping_region . "')"; $shipping_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_country_id . "','" . $shipping_country . "')"; $wpdb->query($sql); //$variations = $cart_item->product_variations; foreach ($cart_items as $cart_item) { $product_id = $cart_item['merchant-item-id']['VALUE']; $item_name = $cart_item['item-name']['VALUE']; $item_desc = $cart_item['item-description']['VALUE']; $item_unit_price = $cart_item['unit-price']['VALUE']; $item_quantity = $cart_item['quantity']['VALUE']; $product_info = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE id='" . $product_id . "' LIMIT 1", ARRAY_A); $product_info = $product_info[0]; //mail("*****@*****.**","",print_r($product_info,1)); if ($product_info['notax'] != 1) { //$price = nzshpcrt_calculate_tax($item_unit_price, $billing_country, $region_number); if (get_option('base_country') == $billing_country) { $country_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode` IN('" . get_option('base_country') . "') LIMIT 1", ARRAY_A); if ($country_data['has_regions'] == 1) { if (get_option('base_region') == $region_number) { $region_data = $wpdb->get_row("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `" . WPSC_TABLE_REGION_TAX . "`.`country_id` IN('" . $country_data['id'] . "') AND `" . WPSC_TABLE_REGION_TAX . "`.`id` IN('" . get_option('base_region') . "') ", ARRAY_A); } $gst = $region_data['tax']; } else { $gst = $country_data['tax']; } } else { $gst = 0; } } else { $gst = 0; } if ($product_info['no_shipping'] == '0') { if ($shipping_country == get_option('base_country')) { $pnp = $product_info['pnp']; } else { $pnp = $product_info['international_pnp']; } } else { $pnp = 0; } $cartsql = "INSERT INTO `" . WPSC_TABLE_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'] . "')"; $wpdb->query($cartsql); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); if ($google_status[0] != 'Partially Charged' && $google_status[0] != 'Partially Refunded') { $google_status[0] = $data['order-state-change-notification']['new-financial-order-state']['VALUE']; $google_status[1] = $data['order-state-change-notification']['new-fulfillment-order-state']['VALUE']; } $google_status = serialize($google_status); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == 'CHARGEABLE' && get_option('google_auto_charge') == '1') { $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendChargeOrder($google_order_number); $_SESSION['nzshpcrt_cart'] = ''; unset($_SESSION['coupon_num'], $_SESSION['google_session']); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET processed='2' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } } if ($root == "charge-amount-notification") { $google_order_number = $data['charge-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $total_charged = $data['charge-amount-notification']['total-charge-amount']['VALUE']; $google_status['partial_charge_amount'] = $total_charged; $totalprice = $wpdb->get_var("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); if ($totalprice > $total_charged) { $google_status[0] = 'Partially Charged'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'CHARGED'; } } $google_status = serialize($google_status); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } if ($root == "refund-amount-notification") { $google_order_number = $data['refund-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $total_charged = $data['refund-amount-notification']['total-refund-amount']['VALUE']; $google_status['partial_refund_amount'] = $total_charged; $totalprice = $wpdb->get_var("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); if ($totalprice > $total_charged) { $google_status[0] = 'Partially refunded'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'REFUNDED'; } } $google_status = serialize($google_status); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } // <avs-response>Y</avs-response> // <cvn-response>M</cvn-response> if ($root == "risk-information-notification") { $google_order_number = $data['risk-information-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $google_status['cvn'] = $data['risk-information-notification']['risk-information']['cvn-response']['VALUE']; $google_status['avs'] = $data['risk-information-notification']['risk-information']['avs-response']['VALUE']; $google_status['protection'] = $data['risk-information-notification']['risk-information']['eligible-for-protection']['VALUE']; $google_status = serialize($google_status); $google_status = $wpdb->query("UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"); if ($data['risk-information-notification']['risk-information']['cvn-response']['VALUE'] == 'E') { $google_risk = 'cvn'; } if (in_array($data['risk-information-notification']['risk-information']['avs-response']['VALUE'], array('N', 'U'))) { if (isset($google_risk)) { $google_risk = 'cvn+avs'; } else { $google_risk = 'avs'; } } if (isset($google_risk)) { $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_risk='" . $google_risk . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == "CANCELLED_BY_GOOGLE") { $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $google_status[0] = "CANCELLED_BY_GOOGLE"; $wpdb->get_var("UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET google_status='" . serialize($google_status) . "' WHERE google_order_number='" . $google_order_number . "'"); } } // mail('*****@*****.**',"",$root . " <pre>". print_r($data,1)."</pre>"); exit; } }
/** * Process an <order-state-change-notification>. */ function process_order_state_change_notification($google_response, $google_checkout) { list($root, $gc_data) = $google_response->GetParsedXML(); $new_financial_state = $gc_data[$root]['new-financial-order-state']['VALUE']; $new_fulfillment_state = $gc_data[$root]['new-fulfillment-order-state']['VALUE']; $previous_financial_state = $gc_data[$root]['previous-financial-order-state']['VALUE']; $previous_fulfillment_state = $gc_data[$root]['previous-fulfillment-order-state']['VALUE']; $google_order_number = $gc_data[$root]['google-order-number']['VALUE']; $google_order = tep_db_fetch_array(tep_db_query("select orders_id from " . $google_checkout->table_order . " where google_order_number = '" . gc_make_sql_string($google_order_number) . "'")); // Handle change in financial state. $do_financial_state_update = false; if ($previous_financial_state != $new_financial_state) { switch ($new_financial_state) { case 'REVIEWING': break; case 'CHARGEABLE': $do_financial_state_update = true; $orders_status_id = GC_STATE_NEW; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_READY_CHARGE; $customer_notified = 0; break; case 'CHARGING': break; case 'CHARGED': $do_financial_state_update = true; $orders_status_id = GC_STATE_PROCESSING; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state; $customer_notified = 0; break; case 'PAYMENT-DECLINED': $do_financial_state_update = true; $orders_status_id = GC_STATE_NEW; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . GOOGLECHECKOUT_STATE_STRING_PAYMENT_DECLINED; $customer_notified = 1; break; case 'CANCELLED': $do_financial_state_update = true; $orders_status_id = GC_STATE_CANCELED; $customer_notified = 1; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED; break; case 'CANCELLED_BY_GOOGLE': $do_financial_state_update = true; $orders_status_id = GC_STATE_CANCELED; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED_BY_GOOG; $customer_notified = 1; break; default: break; } } // Change financial state in table if required. if ($do_financial_state_update) { $sql_data_array = array('orders_id' => $google_order['orders_id'], 'orders_status_id' => $orders_status_id, 'date_added' => 'now()', 'customer_notified' => $customer_notified, 'comments' => $comments); tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . $orders_status_id . "' where orders_id = '" . gc_make_sql_integer($google_order['orders_id']) . "'"); } // Handle change in fulfillment state. $do_fulfillment_state_update = false; if ($previous_fulfillment_state != $new_fulfillment_state) { switch ($new_fulfillment_state) { case 'NEW': break; case 'PROCESSING': $google_request = new GoogleRequest($google_checkout->merchantid, $google_checkout->merchantkey, sandbox_or_prod(), DEFAULT_CURRENCY); $google_request->SetLogFiles(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG); $google_answer = tep_db_fetch_array(tep_db_query("SELECT go.google_order_number, go.order_amount, o.customers_email_address, gc.buyer_id, o.customers_id\n FROM " . $google_checkout->table_order . " go\n inner join " . TABLE_ORDERS . " o on go.orders_id = o.orders_id\n inner join " . $google_checkout->table_name . " gc on gc.customers_id = o.customers_id\n WHERE go.orders_id = '" . (int) $google_order['orders_id'] . "'\n group by o.customers_id order by o.orders_id desc")); $first_order = tep_db_fetch_array(tep_db_query("SELECT customers_id, count(*) cant_orders\n FROM " . TABLE_ORDERS . "\n WHERE customers_id = '" . $google_answer['customers_id'] . "'\n group by customers_id")); // If this is the first time the buyer has used Google Checkout in the site, // send them their email and password(for the store). if ($first_order['cant_orders'] == 1) { list($http_status_code, ) = $google_request->sendBuyerMessage($google_answer['google_order_number'], sprintf(GOOGLECHECKOUT_NEW_CREDENTIALS_MESSAGE, STORE_NAME, $google_answer['customers_email_address'], $google_answer['buyer_id']), "true", 2); $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_fulfillment_state . "\n"; if ($http_status_code == 200) { $comments .= GOOGLECHECKOUT_SUCCESS_SEND_NEW_USER_CREDENTIALS . "\n"; $customer_notified = '1'; } else { $comments .= "\n" . GOOGLECHECKOUT_ERR_SEND_NEW_USER_CREDENTIALS . "\n"; $customer_notified = '0'; } $comments .= "Messsage:\n" . sprintf(GOOGLECHECKOUT_NEW_CREDENTIALS_MESSAGE, STORE_NAME, $google_answer['customers_email_address'], $google_answer['buyer_id']); $do_fulfillment_state_update = true; $orders_status_id = GC_STATE_PROCESSING; } // Send the internal order number to Google. $google_request->SendMerchantOrderNumber($google_answer['google_order_number'], $google_order['orders_id'], 2); break; case 'DELIVERED': $check_status = tep_db_fetch_array(tep_db_query("select orders_status from " . TABLE_ORDERS . "\n where orders_id = '" . $google_order['orders_id'] . "'")); switch ($check_status['orders_status']) { case GC_STATE_REFUNDED: $orders_status_id = GC_STATE_SHIPPED_REFUNDED; break; case GC_STATE_PROCESSING: default: $orders_status_id = GC_STATE_SHIPPED; break; } $do_fulfillment_state_update = true; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_fulfillment_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_DELIVERED . "\n"; $customer_notified = 1; break; case 'WILL_NOT_DELIVER': $do_fulfillment_state_update = false; $orders_status_id = GC_STATE_CANCELED; $customer_notified = 1; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_fulfillment_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED; break; default: break; } } // Change fulfillment state in table if required. if ($do_fulfillment_state_update) { $sql_data_array = array('orders_id' => $google_order['orders_id'], 'orders_status_id' => $orders_status_id, 'date_added' => 'now()', 'customer_notified' => $customer_notified, 'comments' => $comments); tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . $orders_status_id . "' WHERE orders_id = '" . gc_make_sql_integer($google_order['orders_id']) . "'"); } $google_response->SendAck(); }
/** * @param string $message * @param array $params * * @return bool|object */ public function cancelSubscription(&$message = '', $params = array()) { $orderNo = CRM_Utils_Array::value('subscriptionId', $params); $merchant_id = $this->_paymentProcessor['user_name']; $merchant_key = $this->_paymentProcessor['password']; $server_type = $this->_mode == 'test' ? 'sandbox' : ''; $googleRequest = new GoogleRequest($merchant_id, $merchant_key, $server_type); $result = $googleRequest->SendCancelItems($orderNo, array(), 'Cancelled by admin', ''); $message = "{$result[0]}: {$result[1]}"; if ($result[0] != 200) { return self::error($result[0], $result[1]); } return TRUE; }
function nzshpcrt_submit_ajax() { global $wpdb, $user_level, $wp_rewrite; get_currentuserinfo(); if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } $cartt = $_SESSION['nzshpcrt_cart']; $cartt1 = $cartt[0]->product_id; // if is an AJAX request, cruddy code, could be done better but getting approval would be impossible if ($_POST['ajax'] == "true" || $_GET['ajax'] == "true") { if ($_POST['metabox'] == 'true') { $output .= "<div class='meta_box'>"; if (get_option('multi_add') == '1') { $output .= TXT_WPSC_QUANTITY . ": <input type='text' name='quantity[]' size='3'><br>"; } if (get_option('time_requested') == '1') { $output .= TXT_WPSC_DATE_REQUESTED . ": <input type='text' class='time_requested' name='time_requested[]' size='10'><br>"; } if (get_option('commenting') == '1') { $output .= TXT_WPSC_COMMENT . ":<br><textarea type='text' name='comment[]'></textarea><br>"; } $output .= TXT_WPSC_LABEL . ":<br><textarea type='text' name='label[]'></textarea><br>"; $output .= "</div>"; exit($output); } if ($_POST['submittogoogle']) { $newvalue = $_POST['value']; $amount = $_POST['amount']; $reason = $_POST['reason']; $comment = $_POST['comment']; $message = $_POST['message']; $amount = number_format($amount, 2, '.', ''); $log_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id` = '" . $_POST['id'] . "' LIMIT 1", ARRAY_A); if ($newvalue == 2 && function_exists('wpsc_member_activate_subscriptions')) { wpsc_member_activate_subscriptions($_POST['id']); } $google_status = unserialize($log_data['google_status']); switch ($newvalue) { case "Charge": if ($google_status[0] != 'CANCELLED_BY_GOOGLE') { if ($amount == '') { $google_status['0'] = 'Partially Charged'; } else { $google_status['0'] = 'CHARGED'; $google_status['partial_charge_amount'] = $amount; } } break; case "Cancel": if ($google_status[0] != 'CANCELLED_BY_GOOGLE') { $google_status[0] = 'CANCELLED'; } if ($google_status[1] != 'DELIVERED') { $google_status[1] = 'WILL_NOT_DELIVER'; } break; case "Refund": if ($amount == '') { $google_status['0'] = 'Partially Refund'; } else { $google_status['0'] = 'REFUND'; $google_status['partial_refund_amount'] = $amount; } break; case "Ship": if ($google_status[1] != 'WILL_NOT_DELIVER') { $google_status[1] = 'DELIVERED'; } break; case "Archive": $google_status[1] = 'ARCHIVED'; break; } $google_status_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . serialize($google_status) . "' WHERE `id` = '" . $_POST['id'] . "' LIMIT 1"; $wpdb->query($google_status_sql); $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $google_order_number = $wpdb->get_var("SELECT google_order_number FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id` = '" . $_POST['id'] . "' LIMIT 1"); switch ($newvalue) { case 'Charge': $Grequest->SendChargeOrder($google_order_number, $amount); break; case 'Ship': $Grequest->SendDeliverOrder($google_order_number); break; case 'Archive': $Grequest->SendArchiveOrder($google_order_number); break; case 'Refund': $Grequest->SendRefundOrder($google_order_number, $amount, $reason); break; case 'Cancel': $Grequest->SendCancelOrder($google_order_number, $reason, $comment); break; case 'Send Message': $Grequest->SendBuyerMessage($google_order_number, $message); break; } $newvalue++; $update_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '" . $newvalue . "' WHERE `id` = '" . $_POST['id'] . "' LIMIT 1"; //$wpdb->query($update_sql); exit; } /* if(($_GET['user'] == "true") && is_numeric($_POST['prodid'])) { if(function_exists('wpsc_members_init')) { $memberstatus = get_product_meta($_POST['prodid'],'is_membership',true); } if(($memberstatus=='1') && ($_SESSION['nzshopcrt_cart']!=NULL)){ } else{ $sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='".$_POST['prodid']."' LIMIT 1"; $item_data = $wpdb->get_results($sql,ARRAY_A); if ($_POST['quantity']!='') { $add_quantity = $_POST['quantity']; } $item_quantity = 0; if($_SESSION['nzshpcrt_cart'] != null) { foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) { if (($memberstatus[0]!='1')&&($_SESSION['nzshpcrt_cart']!=NULL)){ if($cart_item->product_id == $_POST['prodid']) { if(($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $_POST['variation'])&&($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $_POST['extras'])) { $item_quantity += $_SESSION['nzshpcrt_cart'][$cart_key]->quantity; $item_variations = $_SESSION['nzshpcrt_cart'][$cart_key]->product_variations; } } } } } $item_stock = null; $variation_count = count($_POST['variation']); if($variation_count >= 1) { foreach($_POST['variation'] as $value_id) { if(is_numeric($value_id)) { $value_ids[] = (int)$value_id; } } if(count($value_ids) > 0) { $variation_ids = $wpdb->get_col("SELECT `variation_id` FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id` IN ('".implode("','",$value_ids)."')"); asort($variation_ids); $all_variation_ids = implode(",", $variation_ids); $priceandstock_id = $wpdb->get_var("SELECT `priceandstock_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` WHERE `product_id` = '".(int)$_POST['prodid']."' AND `value_id` IN ( '".implode("', '",$value_ids )."' ) AND `all_variation_ids` IN('$all_variation_ids') GROUP BY `priceandstock_id` HAVING COUNT( `priceandstock_id` ) = '".count($value_ids)."' LIMIT 1"); $variation_stock_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` = '{$priceandstock_id}' LIMIT 1", ARRAY_A); $item_stock = $variation_stock_data['stock']; } } if($item_stock === null) { $item_stock = $item_data[0]['quantity']; } if((($item_data[0]['quantity_limited'] == 1) && ($item_stock > 0) && ($item_stock > $item_quantity)) || ($item_data[0]['quantity_limited'] == 0)) { $cartcount = count($_SESSION['nzshpcrt_cart']); if(is_array($_POST['variation'])) { $variations = $_POST['variation']; } else { $variations = null; } //if(is_array($_POST['extras'])) { $extras = $_POST['extras']; } else { $extras = null; } $updated_quantity = false; if($_SESSION['nzshpcrt_cart'] != null) { foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) { if ((!($memberstatus[0]=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))) { if((int)$cart_item->product_id === (int)$_POST['prodid']) { // force both to integer before testing for identicality if(($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $extras)&&($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $variations) && ((int)$_SESSION['nzshpcrt_cart'][$cart_key]->donation_price == (int)$_POST['donation_price'])) { if ($_POST['quantity'] != ''){ if(is_array($_POST['quantity'])) { foreach ((array)$_POST['quantity'] as $qty) { $_SESSION['nzshpcrt_cart'][$cart_key]->quantity += (int)$qty; } } else { $_SESSION['nzshpcrt_cart'][$cart_key]->quantity += (int)$_POST['quantity']; } } else { $_SESSION['nzshpcrt_cart'][$cart_key]->quantity++; } $_SESSION['nzshpcrt_cart'][$cart_key]->comment = $_POST['comment']; foreach((array)$_POST['label'] as $key => $label) { if ($label != '') { if (array_key_exists($label, $_SESSION['nzshpcrt_cart'][$cart_key]->meta)) { $_SESSION['nzshpcrt_cart'][$cart_key]->meta[$label]+=(int)$_POST['quantity'][$key]; $_SESSION['nzshpcrt_cart'][$cart_key]->time_requested[$label] = $_POST['time_requested'][$key]; } else { $_SESSION['nzshpcrt_cart'][$cart_key]->meta[$label] = $_POST['quantity'][$key]; $_SESSION['nzshpcrt_cart'][$cart_key]->time_requested[$label] = $_POST['time_requested'][$key]; } } } $updated_quantity = true; } } } } } if($item_data[0]['donation'] == 1) { $donation = $_POST['donation_price']; } else { $donation = false; } if(!(($memberstatus=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))){ $status = get_product_meta($cartt1, 'is_membership', true); if (function_exists('wpsc_members_init') && ( $status=='1')){ exit(); } $parameters = array(); if($updated_quantity === false) { $parameters['variation_values'] = $variations; $parameters['provided_price'] = $donation; $parameters['meta']=null; if($_POST['quantity'] != '') { $total_qty = 0; foreach ($_POST['quantity'] as $key=>$qty) { $total_qty+=$qty; $label[$_POST['label'][$key]] = $qty; $time_requested[$_POST['label'][$key]] = $_POST['time_requested'][$key]; } $parameters['quantity'] = $total_qty; //$new_cart_item = new wpsc_cart_item($_POST['prodid'],$variations,$total_qty, $donation,$_POST['comment'],$time_requested,$label); } else { $parameters['quantity'] = 1; } //mail('*****@*****.**', 'stuff', print_r($parameters,true)); $new_cart_item = new wpsc_cart_item($_POST['prodid'],$parameters); $_SESSION['nzshpcrt_cart'][] = $new_cart_item; } } } else { $quantity_limit = true; } $cart = $_SESSION['nzshpcrt_cart']; if (($memberstatus[0]=='1')&&(count($cart)>1)) { } else { $status = get_product_meta($cartt1, 'is_membership', true); if (function_exists('wpsc_members_init') && ( $status=='1')){ exit('st'); } //require_once(WPSC_FILE_PATH."/shopping_cart_functions.php"); echo "if(document.getElementById('shoppingcartcontents') != null) { document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(nzshpcrt_shopping_basket_internals($cart,$quantity_limit))). "\"; } "; if($_SESSION['slider_state'] == 0) { //echo 'jQuery("#sliding_cart").css({ display: "none"});'."\n\r"; } else { //echo 'jQuery("#sliding_cart").css({ display: "block"});'."\n\r"; } } } exit(); } else if(($_POST['user'] == "true") && ($_POST['emptycart'] == "true")) { $_SESSION['nzshpcrt_cart'] = ''; $_SESSION['nzshpcrt_cart'] = Array(); echo "if(document.getElementById('shoppingcartcontents') != null) { document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "", addslashes(nzshpcrt_shopping_basket_internals($cart))). "\"; }\n\r"; if($_POST['current_page'] == get_option('shopping_cart_url')) { echo "window.location = '".get_option('shopping_cart_url')."';\n\r"; // if we are on the checkout page, redirect back to it to clear the non-ajax cart too } exit(); }*/ if ($_POST['store_list'] == "true") { $map_data['address'] = $_POST['addr']; $map_data['city'] = $_POST['city']; $map_data['country'] = 'US'; $map_data['zipcode'] = ''; $map_data['radius'] = '50000'; $map_data['state'] = ''; $map_data['submit'] = 'Find Store'; $stores = getdistance($map_data); $i = 0; while ($rows = mysql_fetch_array($stores)) { //echo "<pre>".print_r($rows,1)."</pre>"; if ($i == 0) { $closest_store = $rows[5]; } $i++; $store_list[$i] = $rows[5]; } foreach ($store_list as $store) { $output .= "<option value='{$store}'>{$store}</option>"; } echo $output; exit; } if (is_numeric($_POST['currencyid'])) { $currency_data = $wpdb->get_results("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . $_POST['currencyid'] . "' LIMIT 1", ARRAY_A); $price_out = null; if ($currency_data[0]['symbol'] != '') { $currency_sign = $currency_data[0]['symbol_html']; } else { $currency_sign = $currency_data[0]['code']; } echo $currency_sign; exit; } if ($_POST['buynow'] == "true") { if (is_numeric($_REQUEST['product_id']) && is_numeric($_REQUEST['price'])) { $id = $wpdb->escape((int) $_REQUEST['product_id']); $price = $wpdb->escape((double) $_REQUEST['price']); $downloads = get_option('max_downloads'); $product_info = $wpdb->get_row("SELECT * FROM " . WPSC_TABLE_PRODUCT_LIST . " WHERE id = " . $id . " LIMIT 1", ARRAY_A); if (count($product_info) > 0) { $sessionid = mt_rand(100, 999) . time(); $sql = "INSERT INTO `" . WPSC_TABLE_PURCHASE_LOGS . "` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`shipping_region`, `user_ID`, `discount_value` ) VALUES ( '" . $price . "', '" . $sessionid . "', '" . time() . "', 'BuyNow', 'BuyNow', 'BuyNow' , NULL , 0)"; $wpdb->query($sql); $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('" . $sessionid . "') LIMIT 1"); $cartsql = "INSERT INTO `" . WPSC_TABLE_CART_CONTENTS . "` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping` ) VALUES ('" . $id . "', '" . $log_id . "','" . $price . "','0', '0','1', '" . $donation . "', '1')"; $wpdb->query($cartsql); $wpdb->query("INSERT INTO `" . WPSC_TABLE_DOWNLOAD_STATUS . "` ( `fileid` , `purchid` , `downloads` , `active` , `datetime` ) VALUES ( '" . $product_info['file'] . "', '" . $log_id . "', '{$downloads}', '0', NOW( ));"); } } exit; } /* rate item */ if ($_POST['rate_item'] == "true" && is_numeric($_POST['product_id']) && is_numeric($_POST['rating'])) { $nowtime = time(); $prodid = $_POST['product_id']; $ip_number = $_SERVER['REMOTE_ADDR']; $rating = $_POST['rating']; $cookie_data = explode(",", $_COOKIE['voting_cookie'][$prodid]); if (is_numeric($cookie_data[0]) && $cookie_data[0] > 0) { $vote_id = $cookie_data[0]; $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_RATING . "` SET `rated` = '" . $rating . "' WHERE `id` ='" . $vote_id . "' LIMIT 1 ;"); } else { $insert_sql = "INSERT INTO `" . WPSC_TABLE_PRODUCT_RATING . "` ( `ipnum` , `productid` , `rated`, `time`) VALUES ( '" . $ip_number . "', '" . $prodid . "', '" . $rating . "', '" . $nowtime . "');"; $wpdb->query($insert_sql); $data = $wpdb->get_results("SELECT `id`,`rated` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `ipnum`='" . $ip_number . "' AND `productid` = '" . $prodid . "' AND `rated` = '" . $rating . "' AND `time` = '" . $nowtime . "' ORDER BY `id` DESC LIMIT 1", ARRAY_A); $vote_id = $data[0]['id']; setcookie("voting_cookie[{$prodid}]", $vote_id . "," . $rating, time() + 60 * 60 * 24 * 360); } $output[1] = $prodid; $output[2] = $rating; echo $output[1] . "," . $output[2]; exit; } //written by allen if ($_REQUEST['save_tracking_id'] == "true") { $id = $_POST['id']; $value = $_POST['value']; $update_sql = "UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET track_id = '" . $value . "' WHERE id={$id}"; $wpdb->query($update_sql); exit; } if ($_POST['get_updated_price'] == "true" && is_numeric($_POST['product_id'])) { $notax = $wpdb->get_var("SELECT `notax` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` IN('" . $_POST['product_id'] . "') LIMIT 1"); foreach ((array) $_POST['variation'] as $variation) { if (is_numeric($variation)) { $variations[] = (int) $variation; } } $pm = $_POST['pm']; echo "product_id=" . (int) $_POST['product_id'] . ";\n"; echo "price=\"" . nzshpcrt_currency_display(calculate_product_price((int) $_POST['product_id'], $variations, 'stay', $extras), $notax, true) . "\";\n"; echo "numeric_price=\"" . number_format(calculate_product_price((int) $_POST['product_id'], $variations, 'stay', $extras), 2) . "\";\n"; //exit(print_r($extras,1)); exit(" "); } // if(($_POST['redisplay_variation_values'] == "true")) { // $variation_processor = new nzshpcrt_variations(); // $variations_selected = array_values(array_unique(array_merge((array)$_POST['new_variation_id'], (array)$_POST['variation_id']))); // foreach($variations_selected as $variation_id) { // // cast everything to integer to make sure nothing nasty gets in. // $variation_list[] = (int)$variation_id; // } // echo $variation_processor->variations_add_grid_view((array)$variation_list); // //echo "/*\n\r".print_r(array_values(array_unique($_POST['variation_id'])),true)."\n\r*/"; // exit(); // } // /* * function for handling the checkout billing address */ if (preg_match("/[a-zA-Z]{2,4}/", $_POST['billing_country'])) { if ($_SESSION['selected_country'] == $_POST['billing_country']) { $do_not_refresh_regions = true; } else { $do_not_refresh_regions = false; $_SESSION['selected_country'] = $_POST['billing_country']; } if (is_numeric($_POST['form_id'])) { $form_id = $_POST['form_id']; $html_form_id = "region_country_form_{$form_id}"; } else { $html_form_id = 'region_country_form'; } if (is_numeric($_POST['billing_region'])) { $_SESSION['selected_region'] = $_POST['billing_region']; } $cart =& $_SESSION['nzshpcrt_cart']; if ($memberstatus[0] == '1' && count($cart) > 0) { echo "\n\r"; } else { if ($status[0] == '1') { exit; } echo "if(document.getElementById('shoppingcartcontents') != null)\n\t\t\t\t\t {\n\t\t\t\t\t document.getElementById('shoppingcartcontents').innerHTML = \"" . str_replace(array("\n", "\r"), "", addslashes(nzshpcrt_shopping_basket_internals($cart, $quantity_limit))) . "\";\n\t\t\t\t\t }\n\r"; if ($do_not_refresh_regions == false) { $region_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . $_POST['billing_country'] . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", ARRAY_A); if ($region_list != null) { $output .= "<select name='collected_data[" . $form_id . "][1]' class='current_region' onchange='set_billing_country(\\\"{$html_form_id}\\\", \\\"{$form_id}\\\");'>"; //$output .= "<option value=''>None</option>"; foreach ($region_list as $region) { if ($_SESSION['selected_region'] == $region['id']) { $selected = "selected='true'"; } else { $selected = ""; } $output .= "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>"; } $output .= "</select>"; echo "if(document.getElementById('region_select_{$form_id}') != null)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdocument.getElementById('region_select_{$form_id}').innerHTML = \"" . $output . "\";\n\t\t\t\t\t\t\t}\n\r"; } else { echo "if(document.getElementById('region_select_{$form_id}') != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tdocument.getElementById('region_select_{$form_id}').innerHTML = \"\";\n\t\t\t\t\t\t}\n\r"; } } } if ($_POST['changetax'] == "true") { if (isset($_POST['billing_region'])) { $billing_region = $_POST['billing_region']; } else { $billing_region = $_SESSION['selected_region']; } $billing_country = $_POST['billing_country']; $price = 0; $tax = 0; foreach ((array) $cart as $cart_item) { $product_id = $cart_item->product_id; $quantity = $cart_item->quantity; //echo("<pre>".print_r($cart_item->product_variations,true)."</pre>"); $product = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` = '{$product_id}' LIMIT 1", ARRAY_A); if ($product['donation'] == 1) { $price += $quantity * $cart_item->donation_price; } else { $product_price = $quantity * calculate_product_price($product_id, $cart_item->product_variations); if ($product['notax'] != 1) { $tax += nzshpcrt_calculate_tax($product_price, $billing_country, $billing_region) - $product_price; } $price += $product_price; $all_donations = false; } if ($_SESSION['delivery_country'] != null) { $total_shipping += nzshpcrt_determine_item_shipping($product['id'], $quantity, $_SESSION['delivery_country']); } } $total_shipping += nzshpcrt_determine_base_shipping(0, $_SESSION['delivery_country']); $total = number_format($tax + $price + $total_shipping, 2); if ($tax > 0) { echo "jQuery(\"tr.total_tax td\").show();\n\r"; } else { echo "jQuery(\"tr.total_tax td\").hide();\n\r"; } $tax = number_format($tax, 2); echo "jQuery('#checkout_tax').html(\"<span class='pricedisplay'>\${$tax}</span>\");\n\r"; echo "jQuery('#checkout_total').html(\"<span class='pricedisplay'>\${$total}</span><input id='shopping_cart_total_price' type='hidden' value='\${$total}'>\");\n\r"; } exit; } if ($_POST['get_country_tax'] == "true" && preg_match("/[a-zA-Z]{2,4}/", $_POST['country_id'])) { $country_id = $_POST['country_id']; $region_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . $country_id . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", ARRAY_A); if ($region_list != null) { echo "<select name='base_region'>\n\r"; foreach ($region_list as $region) { if (get_option('base_region') == $region['id']) { $selected = "selected='true'"; } else { $selected = ""; } echo "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>\n\r"; } echo "</select>\n\r"; } else { echo " "; } exit; } /* fill product form */ if ($_POST['set_slider'] == "true" && is_numeric($_POST['state'])) { $_SESSION['slider_state'] = $_POST['state']; exit; } /* fill category form */ if ($_GET['action'] == "register") { $siteurl = get_option('siteurl'); require_once ABSPATH . WPINC . '/registration-functions.php'; if ($_POST['action'] == 'register' && get_settings('users_can_register')) { //exit("fail for testing purposes"); $user_login = sanitize_user($_POST['user_login']); $user_email = $_POST['user_email']; $errors = array(); if ($user_login == '') { exit($errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.')); } /* checking e-mail address */ if ($user_email == '') { exit(__('<strong>ERROR</strong>: Please type your e-mail address.')); } else { if (!is_email($user_email)) { exit(__('<strong>ERROR</strong>: The email address isn’t correct.')); $user_email = ''; } } if (!validate_username($user_login)) { $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.'); $user_login = ''; } if (username_exists($user_login)) { exit(__('<strong>ERROR</strong>: This username is already registered, please choose another one.')); } /* checking the email isn't already used by another user */ $email_exists = $wpdb->get_row("SELECT user_email FROM {$wpdb->users} WHERE user_email = '{$user_email}'"); if ($email_exists) { die(__('<strong>ERROR</strong>: This email address is already registered, please supply another.')); } if (0 == count($errors)) { $password = substr(md5(uniqid(microtime())), 0, 7); //xit('there?'); $user_id = wp_create_user($user_login, $password, $user_email); if (!$user_id) { exit(sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email'))); } else { wp_new_user_notification($user_id, $password); ?> <div id="login"> <h2><?php _e('Registration Complete'); ?> </h2> <p><?php printf(__('Username: %s'), "<strong>" . wp_specialchars($user_login) . "</strong>"); ?> <br /> <?php printf(__('Password: %s'), '<strong>' . __('emailed to you') . '</strong>'); ?> <br /> <?php printf(__('E-mail: %s'), "<strong>" . wp_specialchars($user_email) . "</strong>"); ?> </p> </div> <?php } } } else { // onsubmit='submit_register_form(this);return false;' echo "<div id='login'>\n <h2>Register for this blog</h2>\n <form id='registerform' action='index.php?ajax=true&action=register' onsubmit='submit_register_form(this);return false;' method='post'>\n <p><input type='hidden' value='register' name='action'/>\n <label for='user_login'>Username:</label><br/> <input type='text' value='' maxlength='20' size='20' id='user_login' name='user_login'/><br/></p>\n <p><label for='user_email'>E-mail:</label><br/> <input type='text' value='' maxlength='100' size='25' id='user_email' name='user_email'/></p>\n <p>A password will be emailed to you.</p>\n <p class='submit'><input type='submit' name='submit_form' id='submit' value='" . TXT_WPSC_REGISTER . " »'/><img id='register_loading_img' src='" . WPSC_URL . "/images/loading.gif' alt='' title=''></p>\n\n \n </form>\n </div>"; } exit; } } /* * AJAX stuff stops here, I would put an exit here, but it may screw up other plugins //exit(); */ }
function google_checkout_state_change($check_status, $status, $oID, $cust_notify, $notify_comments) { global $db, $messageStack, $orders_statuses; define('API_CALLBACK_ERROR_LOG', DIR_FS_CATALOG . "/googlecheckout/logs/response_error.log"); define('API_CALLBACK_MESSAGE_LOG', DIR_FS_CATALOG . "/googlecheckout/logs/response_message.log"); include_once DIR_FS_CATALOG . '/includes/modules/payment/googlecheckout.php'; include_once DIR_FS_CATALOG . '/googlecheckout/library/googlerequest.php'; require_once DIR_FS_CATALOG . '/googlecheckout/library/configuration/google_configuration.php'; require_once DIR_FS_CATALOG . '/googlecheckout/library/configuration/google_configuration_keys.php'; $config = new GoogleConfigurationKeys(); $googlecheckout = new googlecheckout(); $google_request = new GoogleRequest($googlecheckout->merchantid, $googlecheckout->merchantkey, MODULE_PAYMENT_GOOGLECHECKOUT_MODE == 'https://sandbox.google.com/checkout/' ? "sandbox" : "production", DEFAULT_CURRENCY); $google_request->SetLogFiles(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG); $google_answer = tep_db_fetch_array(tep_db_query("SELECT go.google_order_number, go.order_amount, o.customers_email_address, gc.buyer_id, o.customers_id\n FROM " . $googlecheckout->table_order . " go \n inner join " . TABLE_ORDERS . " o on go.orders_id = o.orders_id\n inner join " . $googlecheckout->table_name . " gc on gc.customers_id = o.customers_id\n WHERE go.orders_id = '" . (int) $oID . "'\n group by o.customers_id order by o.orders_id desc")); $google_order = $google_answer['google_order_number']; $amount = $google_answer['order_amount']; // If status update is from Google New -> Google Processing on the Admin UI // this invokes the processing-order and charge-order commands // 1->Google New, 2-> Google Processing if ($check_status['orders_status'] == GC_STATE_NEW && $status == GC_STATE_PROCESSING && $google_order != '') { list($curl_status, ) = $google_request->SendChargeOrder($google_order, $amount); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_CHARGE_ORDER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_CHARGE_ORDER, 'success'); } list($curl_status, ) = $google_request->SendProcessOrder($google_order); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_PROCESS_ORDER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_PROCESS_ORDER, 'success'); } } else { if (($check_status['orders_status'] == GC_STATE_PROCESSING || $check_status['orders_status'] == GC_STATE_REFUNDED) && ($status == GC_STATE_SHIPPED || $status == GC_STATE_SHIPPED_REFUNDED) && $google_order != '') { $carrier = $tracking_no = ""; // Add tracking Data if (isset($_POST['carrier_select']) && $_POST['carrier_select'] != 'select' && isset($_POST['tracking_number']) && !empty($_POST['tracking_number'])) { $carrier = $_POST['carrier_select']; $tracking_no = $_POST['tracking_number']; $comments = GOOGLECHECKOUT_STATE_STRING_TRACKING . "\n" . GOOGLECHECKOUT_STATE_STRING_TRACKING_CARRIER . $_POST['carrier_select'] . "\n" . GOOGLECHECKOUT_STATE_STRING_TRACKING_NUMBER . $_POST['tracking_number'] . ""; tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . "\n (orders_id, orders_status_id, date_added, customer_notified, comments)\n values ('" . (int) $oID . "',\n '" . tep_db_input($check_status['orders_status'] == GC_STATE_REFUNDED ? GC_STATE_SHIPPED_REFUNDED : GC_STATE_SHIPPED) . "',\n now(),\n '" . tep_db_input($cust_notify) . "',\n '" . tep_db_input($comments) . "')"); } list($curl_status, ) = $google_request->SendDeliverOrder($google_order, $carrier, $tracking_no, $cust_notify == 1 ? "true" : "false"); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_DELIVER_ORDER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_DELIVER_ORDER, 'success'); } list($curl_status, ) = $google_request->SendArchiveOrder($google_order); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_ARCHIVE_ORDER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_ARCHIVE_ORDER, 'success'); } } else { if ($check_status['orders_status'] != GC_STATE_CANCELED && $status == GC_STATE_CANCELED && $google_order != '') { if ($check_status['orders_status'] != GC_STATE_NEW) { list($curl_status, ) = $google_request->SendRefundOrder($google_order, 0, GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_REFUND_ORDER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_REFUND_ORDER, 'success'); } } else { // Tell google witch is the OSC's internal order Number list($curl_status, ) = $google_request->SendMerchantOrderNumber($google_order, $oID); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_MERCHANT_ORDER_NUMBER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_MERCHANT_ORDER_NUMBER, 'success'); } } // Is the order is not archive, I do it if ($check_status['orders_status'] != GC_STATE_SHIPPED && $check_status['orders_status'] != GC_STATE_SHIPPED_REFUNDED) { list($curl_status, ) = $google_request->SendArchiveOrder($google_order); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_ARCHIVE_ORDER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_ARCHIVE_ORDER, 'success'); } } // Cancel the order list($curl_status, ) = $google_request->SendCancelOrder($google_order, GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED, $notify_comments); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_CANCEL_ORDER, 'error'); } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_CANCEL_ORDER, 'success'); } } else { if ($google_order != '' && $check_status['orders_status'] != $status) { $statuses = array(); foreach ($orders_statuses as $status_array) { $statuses[$status_array['id']] = $status_array['text']; } $messageStack->add_session(sprintf(GOOGLECHECKOUT_ERR_INVALID_STATE_TRANSITION, $statuses[$check_status['orders_status']], $statuses[$status], $statuses[$check_status['orders_status']]), 'error'); } } } } // Send Buyer's message if ($cust_notify == 1 && isset($notify_comments) && !empty($notify_comments)) { $cust_notify_ok = '0'; $use_cart_messaging = gc_get_configuration_value($config->useCartMessaging()) == 'True'; if (!(strlen(htmlentities(strip_tags($notify_comments))) > GOOGLE_MESSAGE_LENGTH && $use_cart_messaging)) { list($curl_status, ) = $google_request->sendBuyerMessage($google_order, $notify_comments, "true"); if ($curl_status != 200) { $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_MESSAGE_ORDER, 'error'); $cust_notify_ok = '0'; } else { $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_MESSAGE_ORDER, 'success'); $cust_notify_ok = '1'; } if (strlen(htmlentities(strip_tags($notify_comments))) > GOOGLE_MESSAGE_LENGTH) { $messageStack->add_session(sprintf(GOOGLECHECKOUT_WARNING_CHUNK_MESSAGE, GOOGLE_MESSAGE_LENGTH), 'warning'); } } // Cust notified return $cust_notify_ok; } // Cust notified return '0'; }
include_once "classes/DiamondPurchasedHistory.php"; include_once "classes/User.php"; include_once "classes/InAppHttpRequest.php"; include_once "properties/constants.php"; define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'logs/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'logs/googlemessage.log'); $merchant_id = MERCHANT_ID; // Your Merchant ID $merchant_key = MERCHANT_KEY; // Your Merchant Key $server_type = CHECKOUT_SERVER_TYPE; // change this to go live $currency = CHECKOUT_CURRENCY; // set to GBP if in the UK $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); //Setup the log file $Gresponse->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL); // Retrieve the XML sent in the HTTP POST request to the ResponseHandler $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } list($root, $data) = $Gresponse->GetParsedXML($xml_response); $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key); $status = $Gresponse->HttpAuthentication(); if (!$status) { die('authentication failed'); } switch ($root) { case "new-order-notification":
function process_order_state_change_notification($Gresponse, $googlepayment) { global $db; list($root, $data) = $Gresponse->GetParsedXML(); $new_financial_state = $data[$root]['new-financial-order-state']['VALUE']; $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE']; $previous_financial_state = $data[$root]['previous-financial-order-state']['VALUE']; $previous_fulfillment_order = $data[$root]['previous-fulfillment-order-state']['VALUE']; $google_order_number = $data[$root]['google-order-number']['VALUE']; $google_order = $db->Execute("SELECT orders_id from " . "" . $googlepayment->table_order . " where google_order_number = " . "'" . makeSqlString($google_order_number) . "'"); $update = false; if ($previous_financial_state != $new_financial_state) { switch ($new_financial_state) { case 'REVIEWING': break; case 'CHARGEABLE': $update = true; $orders_status_id = GC_STATE_NEW; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_READY_CHARGE; $customer_notified = 0; break; case 'CHARGING': break; case 'CHARGED': $update = true; $orders_status_id = GC_STATE_PROCESSING; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state; $customer_notified = 0; break; case 'PAYMENT-DECLINED': $update = true; $orders_status_id = GC_STATE_NEW; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . GOOGLECHECKOUT_STATE_STRING_PAYMENT_DECLINED; $customer_notified = 1; break; case 'CANCELLED': $update = true; $orders_status_id = GC_STATE_CANCELED; $customer_notified = 1; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED; break; case 'CANCELLED_BY_GOOGLE': $update = true; $orders_status_id = GC_STATE_CANCELED; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_financial_state . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED_BY_GOOG; $customer_notified = 1; break; default: break; } } if ($update) { $sql_data_array = array('orders_id' => $google_order->fields['orders_id'], 'orders_status_id' => $orders_status_id, 'date_added' => 'now()', 'customer_notified' => $customer_notified, 'comments' => $comments); zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); $db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status = " . "'" . $orders_status_id . "' WHERE orders_id = " . "'" . makeSqlInteger($google_order->fields['orders_id']) . "'"); } $update = false; if ($previous_fulfillment_order != $new_fulfillment_order) { switch ($new_fulfillment_order) { case 'NEW': break; case 'PROCESSING': $Gresponse->SendAck(false); $Grequest = new GoogleRequest($googlepayment->merchantid, $googlepayment->merchantkey, MODULE_PAYMENT_GOOGLECHECKOUT_MODE == 'https://sandbox.google.com/checkout/' ? "sandbox" : "production", DEFAULT_CURRENCY); $Grequest->SetLogFiles(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG); $google_answer = $db->Execute("SELECT go.google_order_number, go.order_amount, o.customers_email_address, gc.buyer_id, o.customers_id\n FROM " . $googlepayment->table_order . " go \n inner join " . TABLE_ORDERS . " o on go.orders_id = o.orders_id\n inner join " . $googlepayment->table_name . " gc on gc.customers_id = o.customers_id\n WHERE go.orders_id = '" . (int) $google_order->fields['orders_id'] . "'\n group by o.customers_id order by o.orders_id desc"); $first_order = $db->Execute("SELECT customers_id, count(*) cant_orders\n FROM " . TABLE_ORDERS . " \n WHERE customers_id = '" . $google_answer->fields['customers_id'] . "'\n group by customers_id"); // Send buyers email and password if new user and first buy with GC in the site if ($first_order->fields['cant_orders'] == 1) { list($status, ) = $Grequest->sendBuyerMessage($google_answer->fields['google_order_number'], sprintf(GOOGLECHECKOUT_NEW_CREDENTIALS_MESSAGE, STORE_NAME, $google_answer->fields['customers_email_address'], $google_answer->fields['buyer_id']), "true", 2); $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_fulfillment_order . "\n"; if ($status != 200) { $comments .= "\n" . GOOGLECHECKOUT_ERR_SEND_NEW_USER_CREDENTIALS . "\n"; $customer_notified = '0'; } else { $comments .= GOOGLECHECKOUT_SUCCESS_SEND_NEW_USER_CREDENTIALS . "\n"; $customer_notified = '1'; } $comments .= "Messsage:\n" . sprintf(GOOGLECHECKOUT_NEW_CREDENTIALS_MESSAGE, STORE_NAME, $google_answer->fields['customers_email_address'], $google_answer->fields['buyer_id']); $update = true; $orders_status_id = GC_STATE_PROCESSING; } // Tell google witch is the Zencart's internal order Number $Grequest->SendMerchantOrderNumber($google_answer->fields['google_order_number'], $google_order->fields['orders_id'], 2); break; case 'DELIVERED': $check_status = $db->Execute("select orders_status, shipping_module_code from " . TABLE_ORDERS . "\n where orders_id = '" . $google_order->fields['orders_id'] . "'"); if ($check_status->fields['shipping_module_code'] == 'FreeGCDigital') { $orders_status_id = GC_STATE_DIGITAL_PROCESSED; } else { switch ($check_status->fields['orders_status']) { case GC_STATE_REFUNDED: $orders_status_id = GC_STATE_SHIPPED_REFUNDED; break; case GC_STATE_PROCESSING: default: $orders_status_id = GC_STATE_SHIPPED; break; } } $update = true; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_fulfillment_order . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_DELIVERED . "\n"; $customer_notified = 1; break; case 'WILL_NOT_DELIVER': $update = false; $orders_status_id = GC_STATE_CANCELED; $customer_notified = 1; $comments = GOOGLECHECKOUT_STATE_STRING_TIME . $data[$root]['timestamp']['VALUE'] . "\n" . GOOGLECHECKOUT_STATE_STRING_NEW_STATE . $new_fulfillment_order . "\n" . GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED; break; default: break; } } if ($update) { $sql_data_array = array('orders_id' => $google_order->fields['orders_id'], 'orders_status_id' => $orders_status_id, 'date_added' => 'now()', 'customer_notified' => $customer_notified, 'comments' => $comments); // print_r($sql_data_array); zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); $db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status = " . "'" . $orders_status_id . "' WHERE orders_id = " . "'" . makeSqlInteger($google_order->fields['orders_id']) . "'"); } $Gresponse->SendAck(); }
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This is an example for Merchant handled subscriptions. This code will generate a * recurrence request. */ chdir(".."); require_once 'library/googlerequest.php'; require_once 'library/googleitem.php'; define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log'); $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; // change this to go live $currency = 'USD'; // set to GBP if in the UK $certificate_path = ""; // set your SSL certificate path $google_order_id = ""; // set your SSL CA cert path $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $GRequest->SetCertificatePath($certificate_path); $item1 = new GoogleItem("recurring item", "recurring item fee", 1, 30.0); $item1->SetCurrency($currency); $items = array($item1); $Grequest->SendRecurrenceRequest($google_order_id, $items);
public function preparePayment() { if ($this->testmode == true) { $environment = 'sandbox'; } else { $environment = 'production'; } $Gcart = new GoogleCart($this->arr_settings['account'], $this->arr_settings['secret'], $environment, $this->arr_order['currency']); $Gcart->SetContinueShoppingUrl($this->url_return_success); $Gitem = new GoogleItem($this->arr_order['id'], "Your Purchase (Order reference #" . $this->arr_order['id'] . ")", 1, $this->arr_order['total']); $Gcart->AddItem($Gitem); $Gcart->SetMerchantPrivateData(new MerchantPrivateData(array('shopguid' => $this->arr_settings['shopguid'], 'orderguid' => $this->arr_order['guid'], 'ip-address' => $this->arr_settings['ip']))); $GcartXML = $Gcart->GetXML(); $Grequest = new GoogleRequest($Gcart->merchant_id, $Gcart->merchant_key, $environment, $Gcart->currency); list($status, $this->url_integration) = $Grequest->SendServer2ServerCart($GcartXML, false); if ($this->url_integration == "") { echo "An error occurred while sending the basket to google. Check the google checkout 'Integration console'."; die; } }