function gateway_google($fromcheckout = false) { global $wpdb, $wpsc_cart, $wpsc_checkout, $current_user, $purchlogs; //exit('<pre>'.print_r($fromcheckout, true).'</pre>'); if (!isset($wpsc_checkout)) { $wpsc_checkout = new wpsc_checkout(); } if (!isset($_SESSION['wpsc_sessionid'])) { $sessionid = mt_rand(100, 999) . time(); $_SESSION['wpsc_sessionid'] = $sessionid; } //exit('<pre>'.print_r($_SESSION,true).'</pre>'); if ($_SESSION['wpsc_delivery_region'] == null && $_SESSION['wpsc_selected_region'] == null) { $_SESSION['wpsc_delivery_region'] = get_option('base_region'); $_SESSION['wpsc_selected_region'] = get_option('base_region'); } $wpsc_cart->get_shipping_option(); $wpsc_cart->get_shipping_quotes(); $wpsc_cart->get_shipping_method(); $wpsc_cart->google_shipping_quotes(); $subtotal = $wpsc_cart->calculate_subtotal(); $base_shipping = $wpsc_cart->calculate_total_shipping(); $tax = $wpsc_cart->calculate_total_tax(); $total = $wpsc_cart->calculate_total_price(); // exit('<pre>'.print_r($wpsc_cart, true).'</pre>'); if ($total > 0) { $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `totalprice` = " . $total . ", `statusno` = '0',`user_ID`=" . (int) $user_ID . ", `date`= UNIX_TIMESTAMP() , `gateway`='google', `billing_country`='" . $wpsc_cart->delivery_country . "', shipping_country='" . $wpsc_cart->selected_country . "', `base_shipping`= '" . $base_shipping . "', shipping_method = '" . $wpsc_cart->selected_shipping_method . "', shipping_option= '" . $wpsc_cart->selected_shipping_option . "', `plugin_version`= '" . WPSC_VERSION . "' , `discount_value` = '" . $wpsc_cart->coupons_amount . "', `discount_data`='" . $wpsc_cart->coupons_name . "' WHERE `sessionid`=" . $_SESSION['wpsc_sessionid'] . ""; // exit($sql); $update = $wpdb->query($sql); $sql = "SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE sessionid=" . $_SESSION['wpsc_sessionid']; $purchase_log_id = $wpdb->get_var($sql); $sql = "DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE purchaseid = " . $purchase_log_id; $wpdb->query($sql); $wpsc_cart->save_to_db($purchase_log_id); if (!$update) { $sql = "INSERT INTO `" . WPSC_TABLE_PURCHASE_LOGS . "` (`totalprice`,`statusno`, `sessionid`, `user_ID`, `date`, `gateway`, `billing_country`,`shipping_country`, `base_shipping`,`shipping_method`, `shipping_option`, `plugin_version`, `discount_value`, `discount_data`) VALUES ('{$total}' ,'0', '" . $_SESSION['wpsc_sessionid'] . "', '" . (int) $user_ID . "', UNIX_TIMESTAMP(), 'google', '{$wpsc_cart->delivery_country}', '{$wpsc_cart->selected_country}', '{$base_shipping}', '" . $wpsc_cart->selected_shipping_method . "', '" . $wpsc_cart->selected_shipping_option . "', '" . WPSC_VERSION . "', '{$wpsc_cart->coupons_amount}','{$wpsc_cart->coupons_name}')"; $wpdb->query($sql); $sql = "SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE sessionid=" . $_SESSION['wpsc_sessionid']; $purchase_log_id = $wpdb->get_var($sql); $wpsc_cart->save_to_db($purchase_log_id); } if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } Usecase($seperator, $_SESSION['wpsc_sessionid'], $fromcheckout); //exit(); } }
function gateway_google($fromcheckout = false) { global $wpdb, $wpsc_cart, $wpsc_checkout, $current_user, $purchlogs; if (!isset($wpsc_checkout)) { $wpsc_checkout = new wpsc_checkout(); } $sessionid = (string) wpsc_get_customer_meta('google_checkout_session_id'); if (empty($sessionid)) { $sessionid = mt_rand(100, 999) . time(); wpsc_update_customer_meta('google_checkout_session_id', $sessionid); } $delivery_region = wpsc_get_customer_meta('shipping_region'); $billing_region = wpsc_get_customer_meta('billing_region'); if (!$billing_region && !$billing_region) { $base_region = get_option('base_region'); wpsc_update_customer_meta('shipping_region', $base_region); wpsc_update_customer_meta('billing_region', $base_region); } $wpsc_cart->get_shipping_option(); $wpsc_cart->get_shipping_quotes(); $wpsc_cart->get_shipping_method(); $wpsc_cart->google_shipping_quotes(); $subtotal = $wpsc_cart->calculate_subtotal(); $base_shipping = $wpsc_cart->calculate_total_shipping(); $tax = $wpsc_cart->calculate_total_tax(); $total = $wpsc_cart->calculate_total_price(); if ($total > 0) { $update = $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'statusno' => 0, 'user_ID' => $user_ID, 'date' => time(), 'gateway' => 'google', 'billing_country' => $wpsc_cart->delivery_country, 'shipping_country' => $wpsc_cart->selected_country, 'base_shipping' => $base_shipping, 'shipping_method' => $wpsc_cart->selected_shipping_method, 'shipping_option' => $wpsc_cart->selected_shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name), array('sessionid' => $sessionid), array('%f', '%d', '%d', '%s', '%s', '%s', '%s', '%f', '%s', '%s', '%s', '%f', '%s'), '%s'); $sql = $wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE sessionid = %s", $sessionid); $purchase_log_id = $wpdb->get_var($sql); if (!empty($purchase_log_id)) { $sql = $wpdb->prepare("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE purchaseid = %d", $purchase_log_id); $wpdb->query($sql); } if (!$update) { $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'statusno' => 0, 'sessionind' => $sessionid, 'user_ID' => $user_ID, 'date' => time(), 'gateway' => 'google', 'billing_country' => $wpsc_cart->delivery_country, 'shipping_country' => $wpsc_cart->selected_country, 'base_shipping' => $base_shipping, 'shipping_method' => $wpsc_cart->selected_shipping_method, 'shipping_option' => $wpsc_cart->selected_shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name), array('%f', '%d', '%s', '%d', '%s', '%s', '%s', '%f', '%s', '%s', '%s', '%s', '%f', '%s'), '%s'); $purchase_log_id = $wpdb->insert_id; } $wpsc_cart->save_to_db($purchase_log_id); if (get_option('permalink_structure') != '') { $separator = "?"; } else { $separator = "&"; } Usecase($separator, $sessionid, $fromcheckout); } }
* * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * 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. */ chdir(".."); // Include all the required files require_once 'library/googlecart.php'; require_once 'library/googleitem.php'; require_once 'library/googleshipping.php'; require_once 'library/googletax.php'; Usecase(); function Usecase() { $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; $currency = "USD"; $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency); $total_count = 1; // Check this URL for more info about the two types of digital Delivery // http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html // Key/URL delivery $item_1 = new GoogleItem("Download Digital Item1", "With S/N", $total_count, 10.99); // Unit price
function gateway_google($seperator, $sessionid) { Usecase($seperator, $sessionid); exit; }