= intval($coupon['max_uses'])) { $max_uses_reached = true; } } if ($expired) { $error_message = 'This coupon has expired.'; } elseif ($max_uses_reached) { $error_message = 'This coupon has reached its maximum usage limit.'; } else { // Check game filter $game_valid = true; if ($coupon['game_filter_type'] === 'specific_games' && !empty($coupon['game_filter_list'])) { $allowed_games = json_decode($coupon['game_filter_list'], true); if (is_array($allowed_games) && count((array)$allowed_games) > 0) { $has_valid_game = false; foreach ((array)$invoices as $inv) { $inv_game_key = isset($inv['game_key']) ? $inv['game_key'] : null; if ($inv_game_key !== null && in_array($inv_game_key, $allowed_games)) { $has_valid_game = true; break; } } if (!$has_valid_game) { $game_valid = false; } } } if (!$game_valid) { $error_message = 'This coupon is not valid for the items in your cart.'; } else { // Apply coupon $applied_coupon = $coupon; $coupon_discount_percent = floatval($coupon['discount_percent']); $_SESSION['cart_coupon_code'] = $coupon_code; $_SESSION['cart_coupon_id'] = $coupon['coupon_id']; $success_message = 'Coupon "' . htmlspecialchars($coupon['name']) . '" applied! You save ' . $coupon_discount_percent . '%'; } } mysqli_free_result($coupon_result); } else { $error_message = 'Invalid coupon code.'; } } } } // Handle coupon removal if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['remove_coupon'])) { unset($_SESSION['cart_coupon_code']); unset($_SESSION['cart_coupon_id']); $applied_coupon = null; $coupon_discount_percent = 0; } // Re-validate coupon from session if present if (empty($applied_coupon) && isset($_SESSION['cart_coupon_code'])) { $coupon_code = $_SESSION['cart_coupon_code']; $safe_code = mysqli_real_escape_string($db, $coupon_code); $coupon_query = "SELECT * FROM {$table_prefix}billing_coupons WHERE code = '$safe_code' AND is_active = 1"; $coupon_result = mysqli_query($db, $coupon_query); if ($coupon_result && mysqli_num_rows($coupon_result) === 1) { $applied_coupon = mysqli_fetch_assoc($coupon_result); $coupon_discount_percent = floatval($applied_coupon['discount_percent']); mysqli_free_result($coupon_result); } else { // Coupon no longer valid, clear from session unset($_SESSION['cart_coupon_code']); unset($_SESSION['cart_coupon_id']); } } // AJAX remove invoice action (hard delete) - returns JSON when remove_invoice_ajax is set if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['remove_invoice_ajax']) && isset($_POST['invoice_id'])) { header('Content-Type: application/json'); $remove_id = intval($_POST['invoice_id']); if ($remove_id <= 0) { echo json_encode(['success' => false, 'error' => 'Invalid invoice id.']); exit; } if (!$db) { echo json_encode(['success' => false, 'error' => 'Database unavailable.']); exit; } // Verify ownership and that invoice is still unpaid/due $check_q = "SELECT invoice_id FROM {$table_prefix}billing_invoices WHERE invoice_id = " . intval($remove_id) . " AND user_id = " . intval($user_id) . " AND (status = 'due' OR status = '') AND (payment_status IS NULL OR payment_status NOT IN ('paid','cancelled','refunded')) LIMIT 1"; $check_r = mysqli_query($db, $check_q); if (!($check_r && mysqli_num_rows($check_r) === 1)) { echo json_encode(['success' => false, 'error' => 'Invoice not found or cannot be removed.']); exit; } // Hard-delete the invoice row $del_q = "DELETE FROM {$table_prefix}billing_invoices WHERE invoice_id = " . intval($remove_id) . " AND user_id = " . intval($user_id) . " AND (status = 'due' OR status = '') AND (payment_status IS NULL OR payment_status NOT IN ('paid','cancelled','refunded')) LIMIT 1"; $ok = mysqli_query($db, $del_q); if ($ok && mysqli_affected_rows($db) > 0) { echo json_encode(['success' => true]); } else { echo json_encode(['success' => false, 'error' => 'Failed to delete invoice.']); } exit; } // Handle non-AJAX remove invoice action (hard delete + redirect) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['remove_invoice']) && isset($_POST['invoice_id'])) { $remove_id = intval($_POST['invoice_id']); if ($remove_id <= 0) { $error_message = 'Invalid invoice id.'; } else { if (!$db) { $error_message = 'Unable to remove item: database unavailable.'; } else { // Verify ownership and that invoice is still unpaid/due $check_q = "SELECT invoice_id FROM {$table_prefix}billing_invoices WHERE invoice_id = " . intval($remove_id) . " AND user_id = " . intval($user_id) . " AND (status = 'due' OR status = '') AND (payment_status IS NULL OR payment_status NOT IN ('paid','cancelled','refunded')) LIMIT 1"; $check_r = mysqli_query($db, $check_q); if ($check_r && mysqli_num_rows($check_r) === 1) { // Hard-delete to remove from cart $del_q = "DELETE FROM {$table_prefix}billing_invoices WHERE invoice_id = " . intval($remove_id) . " AND user_id = " . intval($user_id) . " AND (status = 'due' OR status = '') AND (payment_status IS NULL OR payment_status NOT IN ('paid','cancelled','refunded')) LIMIT 1"; if (mysqli_query($db, $del_q)) { // Reload to avoid form re-submission and refresh invoice list header('Location: /cart.php'); exit; } else { $error_message = 'Failed to remove item from cart.'; } } else { $error_message = 'Invoice not found or cannot be removed.'; } } } } // Calculate discount if ($applied_coupon && $coupon_discount_percent > 0) { $discount_amount = $total_amount * ($coupon_discount_percent / 100); } $final_amount = $total_amount - $discount_amount; // PayPal configuration (from config) $client_id = function_exists('gsp_paypal_get_client_id') ? gsp_paypal_get_client_id() : ($paypal_client_id ?? ''); $sandbox = function_exists('gsp_paypal_is_sandbox') ? gsp_paypal_is_sandbox() : ($paypal_sandbox ?? true); // Prepare PayPal items $paypal_items = []; $paypal_invoice_ids = []; foreach ((array)$invoices as $inv) { $game_display = !empty($inv['game_name']) ? $inv['game_name'] : 'Game Server'; $qty = max(1, intval($inv['qty'])); $paypal_invoice_ids[] = intval($inv['invoice_id']); $lineAmount = (float)($inv['total_due'] ?? $inv['amount'] ?? 0); $paypal_items[] = [ 'name' => $inv['home_name'] . ' (' . $game_display . ')', 'description' => $inv['description'] ?? '', 'quantity' => $qty, 'unit_amount' => [ 'currency_code' => 'USD', 'value' => number_format($lineAmount / $qty, 2, '.', '') ] ]; } $paypal_custom_id = 'cart:' . implode(',', $paypal_invoice_ids); // Get site base URL $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://'; $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $siteBase = $protocol . $host; // (Do not close the shared DB connection here; menu and other includes may use it.) ?> Shopping Cart - Game Server Panel
Database error:

🛒 Shopping Cart

Your cart is empty

Browse our game servers and add them to your cart to get started!

Browse Servers
Game Server Duration Quantity Status Price Action
x $

Coupon Code

Coupon Applied: (% off)
0): ?>
Subtotal: $
Discount (%): -$
Total: $

🎉 Complete Your Free Order

Your coupon covers the full amount. Click below to confirm and automatically provision your server(s).

Checkout with PayPal

Checkout Unavailable: PayPal has not been configured for this site. Please contact the site administrator or try again later. 0 && $db) { $ar = mysqli_query($db, "SELECT users_role FROM {$table_prefix}users WHERE user_id = " . $cart_user_id_check . " LIMIT 1"); if ($ar && ($arow = mysqli_fetch_assoc($ar))) { $cart_is_admin = strtolower($arow['users_role'] ?? '') === 'admin'; } } if ($cart_is_admin): ?>
Admin: configure PayPal credentials in Site Config.

Click the button below to complete your purchase securely through PayPal.

0.00 && !empty($client_id)): ?>