diff --git a/api/cache/donorbox_data.json b/api/cache/donorbox_data.json index 6a861e6..7cf3fb2 100644 --- a/api/cache/donorbox_data.json +++ b/api/cache/donorbox_data.json @@ -1,8 +1,14 @@ { - "total_raised": "35675.25", + "total_raised": "35825.53", "goal_amt": "50000.0", "currency": "eur", - "donations_count": 521, + "donations_count": 533, + "recurring_donors_count": 56, "campaign_name": "Soutenez Index avant le 31 d\u00e9cembre 2025 !", - "updated_at": "2026-02-27T12:51:20+01:00" + "updated_at": "2026-03-06T07:41:46+00:00", + "DEBUG_plans_breakdown": { + "cancelled|monthly": 36, + "active|monthly": 56, + "failed|monthly": 19 + } } \ No newline at end of file diff --git a/api/donorbox-proxy.php b/api/donorbox-proxy.php index 90fdb04..27dd6d7 100644 --- a/api/donorbox-proxy.php +++ b/api/donorbox-proxy.php @@ -128,14 +128,56 @@ if ($campaign === null) { } } +// Compter tous les donateurs réguliers actifs (toutes campagnes confondues) +$recurring_count = 0; +$plans_page = 1; +do { + $plans_url = 'https://donorbox.org/api/v1/plans?per_page=100&page=' . $plans_page; + + $ch_plans = curl_init(); + curl_setopt_array($ch_plans, [ + CURLOPT_URL => $plans_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_USERPWD => DONORBOX_EMAIL . ':' . DONORBOX_API_KEY, + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, + CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'User-Agent: Index-NGO-Website'], + CURLOPT_TIMEOUT => 10, + CURLOPT_SSL_VERIFYPEER => true + ]); + + $plans_response = curl_exec($ch_plans); + $plans_http_code = curl_getinfo($ch_plans, CURLINFO_HTTP_CODE); + curl_close($ch_plans); + + if ($plans_response === false || $plans_http_code !== 200) { + break; + } + + $plans = json_decode($plans_response, true); + if (!is_array($plans)) break; + + foreach ($plans as $plan) { + if (isset($plan['status']) && $plan['status'] === 'active') { + $recurring_count++; + } + $status = $plan['status'] ?? 'unknown'; + $type = $plan['type'] ?? 'unknown'; + $plans_detail[$status . '|' . $type] = ($plans_detail[$status . '|' . $type] ?? 0) + 1; + } + + $plans_page++; +} while (count($plans) === 100); + // Extraire uniquement les données nécessaires $filteredData = [ 'total_raised' => $campaign['total_raised'] ?? 0, 'goal_amt' => $campaign['goal_amt'] ?? 50000, 'currency' => $campaign['currency'] ?? 'EUR', 'donations_count' => $campaign['donations_count'] ?? 0, + 'recurring_donors_count' => $recurring_count, 'campaign_name' => $campaign['name'] ?? 'Unknown', - 'updated_at' => date('c') + 'updated_at' => date('c'), + 'plans_detail' => $plans_detail ?? [] ]; $jsonResponse = json_encode($filteredData, JSON_PRETTY_PRINT); diff --git a/assets/js/donorbox-gauge.js b/assets/js/donorbox-gauge.js index a410517..3401c41 100644 --- a/assets/js/donorbox-gauge.js +++ b/assets/js/donorbox-gauge.js @@ -2,17 +2,8 @@ const DONORBOX_CONFIG = { proxyUrl: '/api/donorbox-proxy.php', }; -function formatCurrency(amount) { - const rounded = Math.round(amount * 100) / 100; - const hasDecimals = rounded % 1 !== 0; - - const formatted = rounded.toLocaleString('fr-FR', { - minimumFractionDigits: 0, - maximumFractionDigits: hasDecimals ? 2 : 0, - }); - - return formatted.replace(/[\s\u00A0\u202F]/g, '\u202F') + '\u202F€'; -} +const RECURRING_DONORS_OFFSET = 98; +const GOAL_SUPPORTERS = 500; async function fetchDonorboxData() { try { @@ -41,9 +32,9 @@ async function fetchDonorboxData() { } function updateGaugeDisplay(campaignData) { - const collected = campaignData.total_raised || 0; - const goal = campaignData.goal_amt || 50000; - const percentage = Math.min((collected / goal) * 100, 100); + const recurringCount = campaignData.recurring_donors_count || 0; + const totalSupport = recurringCount + RECURRING_DONORS_OFFSET; + const percentage = Math.min((totalSupport / GOAL_SUPPORTERS) * 100, 100); const gaugeElement = document.getElementById('gauge'); if (gaugeElement) { @@ -53,27 +44,16 @@ function updateGaugeDisplay(campaignData) { ); } - const collectedElement = document.querySelector( + const countElement = document.querySelector( '#gauge--infos__donateurs .value' ); - if (collectedElement) { - collectedElement.textContent = formatCurrency(collected); - } - - const goalElement = document.querySelector('#gauge--infos__objectif .value'); - if (goalElement) { - goalElement.textContent = formatCurrency(goal); - } - - const donorsCount = campaignData.donations_count || 0; - const donorsElement = document.querySelector('#gauge--infos__donors .value'); - if (donorsElement) { - donorsElement.textContent = donorsCount; + if (countElement) { + countElement.textContent = totalSupport; } console.log('Gauge updated:', { - collected: formatCurrency(collected), - goal: formatCurrency(goal), + recurringDonors: recurringCount, + totalSupport, percentage: `${percentage.toFixed(1)}%`, }); } diff --git a/en/index.html b/en/index.html index 6f59cab..49f4f54 100644 --- a/en/index.html +++ b/en/index.html @@ -96,21 +96,17 @@
Raised
-0€
-Donors
+Regular supporters
0
Goal
- +500
- Support us in 2026
+ Goal: 500 supporters
in 2026
Collectés
-0€
-Donateur·ices
+Soutiens réguliers
0
Objectif
- +500
- Soutenez-nous
en 2026
+ Objectif 500 soutiens
en 2026