= 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($allowed_games) > 0) { $has_valid_game = false; foreach ($invoices as $inv) { if (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']); } } // 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 $sandbox = true; $client_id = 'AfvY_C2zA_hTHxHq7TIhtOeub4xBdySYrt_Hjj3d_WYQwjWI9NfOAVOTeResx2rgZ_nP5tOoxQSAHw8c'; // Prepare PayPal items $paypal_items = []; foreach ($invoices as $inv) { $game_display = !empty($inv['game_name']) ? $inv['game_name'] : 'Game Server'; $qty = max(1, intval($inv['qty'])); $paypal_items[] = [ 'name' => $inv['home_name'] . ' (' . $game_display . ')', 'description' => $inv['description'] ?? '', 'quantity' => $qty, 'unit_amount' => [ 'currency_code' => 'USD', 'value' => number_format(floatval($inv['amount']) / $qty, 2, '.', '') ] ]; } // Get site base URL $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://'; $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $siteBase = $protocol . $host; // Close database connection mysqli_close($db); ?> Shopping Cart - Game Server Panel

🛒 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
x $

Coupon Code

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

Checkout with PayPal

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