/** * currency_helpers.php * /app/Helpers/currency_helpers.php * This original/initial version is DEPRECATED */ // Critical Info: /* ************ All previous/existing fees fetching, fees structure, fees application/implementation, fees calculation, as well as all previous/existing fx rates, fx conversion, currency data, currency settings, currency formatting, calculation, etc helpers, methods, functions and classes must now delegate to the NEW currency + fees management suite, which implements records in the following db tables as source of truth for my fintech app/website platform. modular_currency_data, modular_currency_rates, modular_currency_rates_history, modular_currency_settings, modular_fee_internal_names, modular_fee_process_types, modular_fee_structures These NEW currency + fees management suite scripts include: /app/Classes/PaymentModule.php /app/Classes/fxMasterSuite.php /app/Classes/SimpleFileCache.php Fee structures are created and managed by the super_admin with the following script: /app/Legacy/admin/fees-management.php which has been adapted from /app/Legacy/admin/admin_fees_management.php ************ */ /** * ============================================================================ * CURRENCY HELPERS * ============================================================================ */ /** * Get currency symbol from database (with fallback) * * @param string $currencyCode The currency code (e.g., USD, NGN) * @param mysqli|null $db Database connection (optional) * @return string Currency symbol */ function getCurrencySymbol($currencyCode, $db = null) { // Try to use FxCalculator first (most reliable) global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->getCurrencySymbol($currencyCode); } // Try database lookup if ($db) { try { $stmt = $db->prepare("SELECT symbol FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { return $row['symbol']; } } catch (Exception $e) { error_log("Error getting currency symbol: " . $e->getMessage()); } } // Fallback symbols $symbols = [ 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'NGN' => '₦', 'GHS' => 'GH₵', 'KES' => 'KSh', 'ZAR' => 'R', 'CNY' => '¥', 'JPY' => '¥', 'CAD' => 'C$', 'AUD' => 'A$', 'CHF' => 'Fr', 'INR' => '₹', 'BRL' => 'R$', 'MXN' => '$', 'SGD' => 'S$' ]; return $symbols[$currencyCode] ?? '$'; } /** * Format amount with currency symbol * * @param float|int|string $amount The amount to format * @param string $currencyCode The currency code * @param int|null $decimals Number of decimal places (optional, uses currency defaults) * @param mysqli|null $db Database connection (optional) * @return string Formatted amount with currency symbol */ function formatCurrency($amount, $currencyCode, $decimals = null, $db = null) { // Try to use FxCalculator global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->formatAmount($amount, $currencyCode, $decimals); } // Get decimals from database if not provided if ($decimals === null && $db) { try { $stmt = $db->prepare("SELECT decimals FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { $decimals = (int)$row['decimals']; } } catch (Exception $e) { error_log("Error getting decimals: " . $e->getMessage()); } } $decimals = $decimals ?? 2; $symbol = getCurrencySymbol($currencyCode, $db); $formatted = number_format((float)$amount, $decimals); return $symbol . $formatted; } /** * Convert amount between currencies using MasterFxCalculator * * @param float|int|string $amount The amount to convert * @param string $fromCurrency Source currency code * @param string $toCurrency Target currency code * @param mysqli|null $db Database connection (optional) * @return float Converted amount */ function convertCurrency($amount, $fromCurrency, $toCurrency, $db = null) { // If same currency, no conversion needed if ($fromCurrency === $toCurrency) { return (float)$amount; } // Try to use FxCalculator (most reliable) global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $rate = $fxCalculator->getRate($fromCurrency, $toCurrency); return (float)$amount * $rate; } // Fallback: query database directly if ($db) { $baseCurrency = getBaseCurrency($db); try { $stmt = $db->prepare("SELECT external_rates FROM currency_rates WHERE base_currency = ? ORDER BY last_updated DESC LIMIT 1"); $stmt->bind_param('s', $baseCurrency); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); if ($row) { $rates = json_decode($row['external_rates'], true); if (isset($rates[$fromCurrency]) && isset($rates[$toCurrency])) { $inBase = (float)$amount / $rates[$fromCurrency]; return $inBase * $rates[$toCurrency]; } } } catch (Exception $e) { error_log("Error converting currency: " . $e->getMessage()); } } // Ultimate fallback - return original amount error_log("Currency conversion failed, using original amount: $fromCurrency -> $toCurrency"); return (float)$amount; } /** * Get base currency from database * * @param mysqli|null $db Database connection (optional) * @return string Base currency code */ /** * Get base currency from database - SOURCE OF TRUTH: currency_settings table */ function getBaseCurrency($db = null) { static $baseCurrency = null; if ($baseCurrency !== null) { return $baseCurrency; } // Try to use MasterFxCalculator first (it now uses currency_settings) global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $baseCurrency = $fxCalculator->getBaseCurrency(); return $baseCurrency; } // Direct database query if calculator not available if ($db) { try { // PRIMARY SOURCE: currency_settings $result = $db->query("SELECT base_currency FROM currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $baseCurrency = $row['base_currency']; return $baseCurrency; } // FALLBACK: folrun_currency_settings $result = $db->query("SELECT base_currency FROM folrun_currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $baseCurrency = $row['base_currency']; return $baseCurrency; } } catch (Exception $e) { error_log("Error getting base currency: " . $e->getMessage()); } } $baseCurrency = defined('DEFAULT_BASE_CURRENCY') ? DEFAULT_BASE_CURRENCY : 'USD'; return $baseCurrency; } /** * Get fee by key from database */ function getFeeByKey_XXX($feeKey, $db = null) { if ($db === null) { global $db; } try { $stmt = $db->prepare("SELECT fee_value, fee_type FROM folrun_fee_settings WHERE fee_key = ? AND is_active = 1 LIMIT 1"); if ($stmt) { $stmt->bind_param('s', $feeKey); $stmt->execute(); $result = $stmt->get_result(); return $result->fetch_assoc(); } } catch (Exception $e) { error_log("Error getting fee by key: " . $e->getMessage()); } return null; } /** * Get fee by transaction type, wallet type, and user role */ function getFeeByTransactionAndWallet($transactionType, $walletType, $userRole, $db = null) { if ($db === null) { global $db; } try { $sql = "SELECT * FROM folrun_fee_settings WHERE is_active = 1 AND (transaction_type = ? OR transaction_type = 'all') AND (wallet_type = ? OR wallet_type = 'all') AND (user_role = ? OR user_role = 'all') ORDER BY CASE WHEN transaction_type = ? THEN 1 ELSE 2 END, CASE WHEN wallet_type = ? THEN 1 ELSE 2 END, CASE WHEN user_role = ? THEN 1 ELSE 2 END LIMIT 1"; $stmt = $db->prepare($sql); $stmt->bind_param('ssssss', $transactionType, $walletType, $userRole, $transactionType, $walletType, $userRole); $stmt->execute(); $result = $stmt->get_result(); return $result->fetch_assoc(); } catch (Exception $e) { error_log("Error getting fee by transaction and wallet: " . $e->getMessage()); return null; } } /** * Get admin currency from database * * @param mysqli|null $db Database connection (optional) * @return string Admin currency code */ function getAdminCurrency($db = null) { static $adminCurrency = null; if ($adminCurrency !== null) { return $adminCurrency; } global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $adminCurrency = $fxCalculator->getAdminCurrency(); return $adminCurrency; } if ($db) { try { $result = $db->query("SELECT default_admin_currency FROM currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $adminCurrency = $row['default_admin_currency']; return $adminCurrency; } $result = $db->query("SELECT default_admin_currency FROM folrun_currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $adminCurrency = $row['default_admin_currency']; return $adminCurrency; } } catch (Exception $e) { error_log("Error getting admin currency: " . $e->getMessage()); } } $adminCurrency = defined('DEFAULT_ADMIN_CURRENCY') ? DEFAULT_ADMIN_CURRENCY : 'GHS'; return $adminCurrency; } /** * Get all active currencies with rates * * @param mysqli $db Database connection * @return array Array of currencies with their data and rates */ function getAllCurrenciesWithRates($db) { $baseCurrency = getBaseCurrency($db); $currencies = []; try { // Get currency data $result = $db->query("SELECT currency_code, symbol, name, decimals, fallback_rate FROM currency_data WHERE is_active = 1 ORDER BY currency_code"); if ($result) { while ($row = $result->fetch_assoc()) { $currencies[$row['currency_code']] = [ 'name' => $row['name'], 'symbol' => $row['symbol'], 'decimals' => (int)$row['decimals'], 'fallback_rate' => (float)$row['fallback_rate'] ]; } } // Get current rates $stmt = $db->prepare("SELECT external_rates, internal_rates_from, internal_rates_to FROM currency_rates WHERE base_currency = ? ORDER BY last_updated DESC LIMIT 1"); $stmt->bind_param('s', $baseCurrency); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); $externalRates = $row ? json_decode($row['external_rates'], true) : []; $internalFrom = $row ? json_decode($row['internal_rates_from'], true) : []; $internalTo = $row ? json_decode($row['internal_rates_to'], true) : []; foreach ($currencies as $code => &$data) { $data['rate'] = $externalRates[$code] ?? $data['fallback_rate']; $data['rate_from'] = $internalFrom[$code] ?? $data['rate']; $data['rate_to'] = $internalTo[$code] ?? $data['rate']; $data['base_currency'] = $baseCurrency; } } catch (Exception $e) { error_log("Error getting currencies with rates: " . $e->getMessage()); } return $currencies; } /** * Get active currencies list (without rates) * * @param mysqli $db Database connection * @return array Array of active currencies */ function getActiveCurrencies($db): array { $currencies = []; try { $result = $db->query("SELECT currency_code, symbol, name, decimals FROM currency_data WHERE is_active = 1 ORDER BY currency_code"); if ($result) { while ($row = $result->fetch_assoc()) { $currencies[$row['currency_code']] = [ 'symbol' => $row['symbol'], 'name' => $row['name'], 'decimals' => (int)$row['decimals'] ]; } } } catch (Exception $e) { error_log("Error getting active currencies: " . $e->getMessage()); } return $currencies; } /** * ============================================================================ * FEE HELPERS * ============================================================================ */ /** * Get fee structure for a specific transaction * * @param mysqli $db Database connection * @param string $transaction_type Transaction type (deposit, withdrawal, etc.) * @param string $wallet_type Wallet type (funding, earnings, etc.) * @param float|int $amount Transaction amount * @param MasterFxCalculator|null $fxCalculator Optional FX calculator instance * @return array Fee breakdown */ function getTransactionFees($db, $transaction_type, $wallet_type, $amount, $fxCalculator = null) { $fees = [ 'fx_spread' => 0, 'main_fee' => 0, 'total' => 0 ]; try { // Get FX spread - try to use FxCalculator first if ($fxCalculator && $fxCalculator instanceof MasterFxCalculator) { $fees['fx_spread'] = $fxCalculator->getFee('fx_spread_nominal_perc', 0.05); } else { $sql = "SELECT fee_value FROM fee_settings WHERE fee_key = 'fx_spread' AND is_active = 1 LIMIT 1"; $result = $db->query($sql); if ($result && $row = $result->fetch_assoc()) { $fees['fx_spread'] = (float)$row['fee_value'] / 100; } else { $fees['fx_spread'] = 0.05; } } // Get transaction-specific fee $sql = "SELECT * FROM fee_settings WHERE (transaction_type = ? OR transaction_type = 'all') AND (wallet_type = ? OR wallet_type = 'all') AND is_active = 1 ORDER BY CASE WHEN transaction_type = ? THEN 1 WHEN transaction_type = 'all' THEN 3 ELSE 2 END, CASE WHEN wallet_type = ? THEN 1 WHEN wallet_type = 'all' THEN 3 ELSE 2 END LIMIT 1"; $stmt = $db->prepare($sql); $stmt->bind_param('ssss', $transaction_type, $wallet_type, $transaction_type, $wallet_type); $stmt->execute(); $feeSetting = $stmt->get_result()->fetch_assoc(); if ($feeSetting) { if ($feeSetting['fee_type'] === 'flexible') { if ($amount < $feeSetting['threshold_amount']) { $fees['main_fee'] = (float)$feeSetting['fixed_fee_value']; } else { $fees['main_fee'] = $amount * ((float)$feeSetting['percentage_fee_value'] / 100); } } elseif ($feeSetting['fee_type'] === 'percentage') { $fees['main_fee'] = $amount * ((float)$feeSetting['fee_value'] / 100); } elseif ($feeSetting['fee_type'] === 'fixed') { $fees['main_fee'] = (float)$feeSetting['fee_value']; } } else { $fees['main_fee'] = $amount * 0.10; // Default 10% } $fees['total'] = ($amount * $fees['fx_spread']) + $fees['main_fee']; } catch (Exception $e) { error_log("Error getting fees: " . $e->getMessage()); $fees['fx_spread'] = 0.05; $fees['main_fee'] = $amount * 0.10; $fees['total'] = ($amount * 0.05) + ($amount * 0.10); } return $fees; } /** * Get a specific fee by key * * @param mysqli $db Database connection * @param string $feeKey The fee key to retrieve * @param mixed $default Default value if fee not found * @return mixed Fee value or array for flexible fees */ /* function getFeeByKey($db, $feeKey, $default = 0) { try { $sql = "SELECT fee_value, fee_type, threshold_amount, fixed_fee_value, percentage_fee_value FROM fee_settings WHERE fee_key = ? AND is_active = 1 LIMIT 1"; $stmt = $db->prepare($sql); $stmt->bind_param('s', $feeKey); $stmt->execute(); $result = $stmt->get_result(); $fee = $result->fetch_assoc(); if ($fee) { if ($fee['fee_type'] === 'percentage') { return (float)$fee['fee_value'] / 100; } elseif ($fee['fee_type'] === 'fixed') { return (float)$fee['fee_value']; } elseif ($fee['fee_type'] === 'flexible') { return [ 'type' => 'flexible', 'threshold' => (float)$fee['threshold_amount'], 'fixed_fee' => (float)$fee['fixed_fee_value'], 'percentage_fee' => (float)$fee['percentage_fee_value'] ]; } } } catch (Exception $e) { error_log("Error getting fee by key: " . $e->getMessage()); } return $default; } */ /** * Get all active fees * * @param mysqli $db Database connection * @return array Array of all active fees */ function getAllFees($db): array { $fees = []; try { $result = $db->query("SELECT * FROM fee_settings WHERE is_active = 1 ORDER BY sort_order"); if ($result) { while ($row = $result->fetch_assoc()) { $fees[] = $row; } } } catch (Exception $e) { error_log("Error getting all fees: " . $e->getMessage()); } return $fees; } /** * ============================================================================ * USER CURRENCY HELPERS * ============================================================================ */ /** * Get user's effective currency * * @param int $user_id User ID * @param mysqli|null $db Database connection (optional) * @return string User's currency code */ function getUserCurrency($user_id, $db = null) { static $cache = []; if (isset($cache[$user_id])) { return $cache[$user_id]; } // Try to use UserManager if available global $userManager; if (isset($userManager) && $userManager instanceof UserManager) { $user = $userManager->getUser($user_id); if ($user && isset($user['currency_code'])) { $cache[$user_id] = $user['currency_code']; return $cache[$user_id]; } } // Query database directly if ($db) { try { $stmt = $db->prepare("SELECT currency_code FROM users WHERE id = ?"); $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { $cache[$user_id] = $row['currency_code']; return $cache[$user_id]; } } catch (Exception $e) { error_log("Error getting user currency: " . $e->getMessage()); } } // Default fallback return defined('DEFAULT_USER_CURRENCY') ? DEFAULT_USER_CURRENCY : 'NGN'; } /** * Update user's currency * * @param int $user_id User ID * @param string $newCurrency New currency code * @param mysqli $db Database connection * @return bool True on success, false on failure */ function updateUserCurrency($user_id, $newCurrency, $db) { try { $stmt = $db->prepare("UPDATE users SET currency_code = ? WHERE id = ?"); $stmt->bind_param('si', $newCurrency, $user_id); return $stmt->execute(); } catch (Exception $e) { error_log("Error updating user currency: " . $e->getMessage()); return false; } } /** * ============================================================================ * UTILITY FUNCTIONS * ============================================================================ */ /** * Calculate exchange rate impact (for display) * * @param string $fromCurrency Source currency * @param string $toCurrency Target currency * @param float|int $amount Amount to convert * @param mysqli|null $db Database connection (optional) * @return array Exchange rate impact details */ function getExchangeRateImpact($fromCurrency, $toCurrency, $amount, $db = null) { $rate = convertCurrency(1, $fromCurrency, $toCurrency, $db); $result = $amount * $rate; return [ 'rate' => $rate, 'original' => $amount, 'converted' => $result, 'formatted_original' => formatCurrency($amount, $fromCurrency, null, $db), 'formatted_converted' => formatCurrency($result, $toCurrency, null, $db) ]; } /** * Format amount in multiple currencies * * @param float|int $amount Amount to format * @param array $currencies Array of currency codes * @param mysqli|null $db Database connection (optional) * @return array Formatted amounts by currency */ function formatMultiCurrency($amount, $currencies, $db = null) { $result = []; foreach ($currencies as $currency) { $result[$currency] = formatCurrency($amount, $currency, null, $db); } return $result; } /** * Validate currency code * * @param string $currencyCode Currency code to validate * @param mysqli|null $db Database connection (optional) * @return bool True if currency is valid and active */ function isValidCurrency($currencyCode, $db = null) { if ($db) { try { $stmt = $db->prepare("SELECT id FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); return $stmt->get_result()->num_rows > 0; } catch (Exception $e) { error_log("Error validating currency: " . $e->getMessage()); } } $validCurrencies = ['USD', 'EUR', 'GBP', 'NGN', 'GHS', 'KES', 'ZAR', 'CNY']; return in_array(strtoupper($currencyCode), $validCurrencies); } /** * Get currency data for display * * @param string $currencyCode Currency code * @param mysqli|null $db Database connection (optional) * @return array Currency display data */ function getCurrencyDisplayData($currencyCode, $db = null) { global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $data = $fxCalculator->getCurrencyDataFromDb($currencyCode); return [ 'code' => $currencyCode, 'symbol' => $data['symbol'] ?? '$', 'name' => $data['name'] ?? $currencyCode, 'decimals' => $data['decimals'] ?? 2 ]; } if ($db) { try { $stmt = $db->prepare("SELECT symbol, name, decimals FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { return [ 'code' => $currencyCode, 'symbol' => $row['symbol'], 'name' => $row['name'], 'decimals' => (int)$row['decimals'] ]; } } catch (Exception $e) { error_log("Error getting currency display data: " . $e->getMessage()); } } return [ 'code' => $currencyCode, 'symbol' => getCurrencySymbol($currencyCode), 'name' => $currencyCode, 'decimals' => 2 ]; } /** * Get minimum deposit amount for a user based on their role * Returns amount in the system base currency (from database) * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Minimum deposit amount in system base currency (0 = no limit) */ function getMinimumDepositForUser($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 2.00; } // Get user's role $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 2.00; } $role = $user['role']; // Get limits for this role (amounts are in system base currency) $sql = "SELECT min_deposit_base FROM transaction_limits WHERE role = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('s', $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); // Return 0 if no limit found (meaning no minimum) return $limit ? (float)$limit['min_deposit_base'] : 0; } /** * Get maximum deposit amount for a user based on their role * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Maximum deposit amount (0 = no limit) */ function getMaximumDepositForUser($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 0; } $role = $user['role']; $sql = "SELECT max_deposit_base FROM transaction_limits WHERE role = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('s', $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); return $limit ? (float)$limit['max_deposit_base'] : 0; } /** * Get minimum withdrawal amount for a user based on their role * * @param int $user_id User ID * @param string|null $currency Currency to return the amount in * @param mysqli|null $db Database connection * @return float Minimum withdrawal amount */ function getMinimumWithdrawalForUser($user_id, $currency = null, $db = null) { if ($db === null) { global $db; } if (!$db) { return 2.00; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 2.00; } $role = $user['role']; $sql = "SELECT min_withdrawal_base FROM transaction_limits WHERE (role = ? OR role IS NULL) ORDER BY CASE WHEN role = ? THEN 0 ELSE 1 END LIMIT 1"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('ss', $role, $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); $minWithdrawalBase = $limit ? (float)$limit['min_withdrawal_base'] : 2.00; if ($currency !== null) { global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->convert($minWithdrawalBase, 'USD', $currency); } } return $minWithdrawalBase; } /** * Get daily deposit limit for a user based on their role * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Daily deposit limit (0 = no limit) */ function getDailyDepositLimitForUser($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 0; } $role = $user['role']; $sql = "SELECT daily_deposit_limit_base FROM transaction_limits WHERE role = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('s', $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); return $limit ? (float)$limit['daily_deposit_limit_base'] : 0; } /** * Get daily withdrawal limit for a user based on their role * CORRECTED: Uses 'daily_withdrawal_limit_base' column * * @param int $user_id User ID * @param string|null $currency Currency to return the amount in * @param mysqli|null $db Database connection * @return float Daily withdrawal limit (0 = no limit) */ function getDailyWithdrawalLimitForUser($user_id, $currency = null, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 0; } $role = $user['role']; // CORRECTED: Use 'daily_withdrawal_limit_base' column $sql = "SELECT daily_withdrawal_limit_base FROM transaction_limits WHERE (role = ? OR role IS NULL) ORDER BY CASE WHEN role = ? THEN 0 ELSE 1 END LIMIT 1"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('ss', $role, $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); $dailyLimitBase = $limit ? (float)$limit['daily_withdrawal_limit_base'] : 0; if ($currency !== null && $dailyLimitBase > 0) { global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->convert($dailyLimitBase, 'USD', $currency); } } return $dailyLimitBase; } /** * Get formatted minimum deposit string for display * * @param int $user_id User ID * @param string $userCurrency User's currency code * @param mysqli|null $db Database connection * @return string Formatted minimum deposit string */ function getFormattedMinimumDeposit($user_id, $userCurrency, $db = null) { if ($db === null) { global $db; } global $fxCalculator; $minInBase = getMinimumDepositForUser($user_id, null, $db); $minInUserCurrency = $fxCalculator->convert($minInBase, 'USD', $userCurrency); return $fxCalculator->formatAmount($minInUserCurrency, $userCurrency); } /** * Get remaining daily deposit allowance in system base currency * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Remaining daily deposit amount in system base currency */ function getRemainingDailyDepositAllowance($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $dailyLimit = getDailyDepositLimitForUser($user_id, $db); // If no daily limit, return a large number if ($dailyLimit <= 0) { return 99999999.00; } // Get today's total deposits (in system base currency) $sql = "SELECT COALESCE(SUM(gross_amount_base_curr), 0) as today_deposits FROM all_transactions WHERE user_id = ? AND transaction_type = 'credit' AND DATE(date_created) = CURDATE() AND status IN ('pending', 'processing', 'successful')"; $stmt = $db->prepare($sql); if (!$stmt) { return $dailyLimit; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); $todayDeposits = (float)($row['today_deposits'] ?? 0); return max(0, $dailyLimit - $todayDeposits); } Privacy Policy - GigzSocial

Privacy Policy

Last updated: June 10, 2026

1. Information We Collect

We collect information you provide directly to us, such as when you create an account, make transactions, or contact support. This may include:

  • Name, email address, and contact information
  • Identity documents for KYC verification
  • Bank account details for withdrawals
  • Transaction history and wallet balances
  • Device information and IP addresses

2. How We Use Your Information

We use the information we collect to:

  • Provide, maintain, and improve our services
  • Process transactions and verify identity
  • Communicate with you about your account
  • Detect and prevent fraud
  • Comply with legal obligations

3. Information Sharing

We do not sell your personal information. We may share information:

  • With service providers who assist in operating our platform
  • To comply with legal requirements
  • To protect the rights and safety of our users
  • With your consent

4. Data Security

We implement appropriate technical and organizational measures to protect your personal information. However, no method of transmission over the Internet is 100% secure.

5. Data Retention

We retain your information for as long as your account is active or as needed to provide services. We may retain certain information as required by law or for legitimate business purposes.

6. Your Rights

Depending on your location, you may have the right to:

  • Access and receive a copy of your data
  • Correct inaccurate data
  • Delete your data
  • Object to data processing
  • Data portability

To exercise these rights, contact us at privacy@gigzsocial.com.

7. Cookies

We use cookies to enhance your experience. You can set your browser to refuse cookies, but this may limit functionality.

8. Children's Privacy

Our services are not directed to individuals under 18. We do not knowingly collect information from children.

9. International Data Transfers

Your information may be transferred to and processed in countries other than your own. We take appropriate safeguards to protect your data.

10. Changes to Privacy Policy

We may update this policy from time to time. We will notify you of material changes by email or through the Platform.

11. Contact Us

For privacy-related inquiries, contact:

Email: privacy@gigzsocial.com