['id'=>1,'name'=>'Monthly','price'=>9.99,'duration_days'=>30], 2 => ['id'=>2,'name'=>'3 Months','price'=>24.99,'duration_days'=>90], 3 => ['id'=>3,'name'=>'6 Months','price'=>44.99,'duration_days'=>180], 4 => ['id'=>4,'name'=>'Yearly','price'=>79.99,'duration_days'=>365], ]; if (isset($default_plans[$plan_id])) $plan = $default_plans[$plan_id]; if (!$plan) { header("Location: /pricing"); exit; } } // Calculate discounted price centrally $price_info = calculate_discounted_price($plan["price"], $plan["duration_days"]); $plan_price = $price_info["price"]; $plan_discount = $price_info["discount"]; $currency = sanitize($_GET['currency'] ?? 'BTC'); $amount_crypto = calc_crypto_amount($plan_price, $currency); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_order'])) { $currency = sanitize($_POST['currency'] ?? 'BTC'); $amount_crypto = calc_crypto_amount($plan_price, $currency); $expires = date('Y-m-d H:i:s', time() + (PAYMENT_TIMEOUT * 60)); $wallet = get_wallet($currency); $stmt = $db->prepare("INSERT INTO orders (user_id, plan_id, amount, currency, payment_address, wallet_address, payment_status, expires_at, created_at) VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, datetime('now'))"); if ($stmt->execute([$user_id, $plan['id'], $amount_crypto, $currency, $wallet, $wallet, $expires])) { $order_id = $db->lastInsertId(); header('Location: /subscribe?order=' . $order_id); exit; } $error = __('error_payment'); }