- Inscription sans redirection HelloAsso (acte volontaire séparé) - Génération automatique d'identifiant AlpID (prenom.code mnémotechnique) - Profil en tuiles : identité, compte, mot de passe, OTP, adhésion, adresse, connexions - Double authentification : activation/suppression OTP via Keycloak - Page d'accueil contextuelle (bienvenue si connecté, CTA adhésion si non adhérent) - Historique des connexions avec statistiques et graphiques Chart.js - Géocodage Nominatim + lien OpenStreetMap pour l'adresse - HelloAsso : checkout intent, validation paiement, mise à jour Dolibarr Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../inc/config.php';
|
|
require_once __DIR__ . '/../inc/auth.php';
|
|
require_once __DIR__ . '/../inc/helloasso.php';
|
|
require_once __DIR__ . '/../inc/keycloak.php';
|
|
require_once __DIR__ . '/../inc/dolibarr.php';
|
|
|
|
session_start_safe();
|
|
|
|
$checkout_id = $_GET['checkoutIntentId'] ?? '';
|
|
$kc_uid = $_GET['uid'] ?? '';
|
|
|
|
if (!$checkout_id || !$kc_uid) {
|
|
set_flash('error', 'Retour de paiement invalide.');
|
|
header('Location: /register.php');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$checkout = ha_get_checkout($checkout_id);
|
|
$order = $checkout['order'] ?? null;
|
|
$payments = $order['payments'] ?? [];
|
|
$paid = false;
|
|
$amount = 0;
|
|
|
|
foreach ($payments as $p) {
|
|
if (($p['state'] ?? '') === 'Authorized') {
|
|
$paid = true;
|
|
$amount = (int)(($p['amount'] ?? HA_AMOUNT) / 100); // centimes → euros
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$paid) {
|
|
set_flash('error', 'Paiement non confirmé. Veuillez réessayer ou contacter un administrateur.');
|
|
header('Location: /helloasso/renew.php');
|
|
exit;
|
|
}
|
|
|
|
// 1. Keycloak : ajouter au groupe adherents (idempotent)
|
|
kc_add_to_group($kc_uid, ADHERENT_GROUP);
|
|
|
|
// 2. Dolibarr : créer la cotisation (+1 an)
|
|
$kc_user = _kc_get_user($kc_uid);
|
|
$email = $kc_user['email'] ?? '';
|
|
$membership = $email ? doli_get_membership($email) : null;
|
|
|
|
if ($membership) {
|
|
doli_add_subscription($membership['id'], $membership['date_fin_ts'], $amount ?: HA_AMOUNT / 100);
|
|
}
|
|
|
|
// 3. TODO : Nextcloud — URL et credentials à configurer
|
|
// nc_add_to_group($email, 'adherents');
|
|
|
|
set_flash('success', 'Paiement confirmé ! Votre adhésion est activée.');
|
|
$next = current_user() ? '/dashboard.php' : '/auth/login.php';
|
|
header('Location: ' . $next);
|
|
exit;
|
|
|
|
} catch (Exception $e) {
|
|
set_flash('error', 'Erreur lors de la validation : ' . $e->getMessage());
|
|
header('Location: /helloasso/renew.php');
|
|
exit;
|
|
}
|
|
|
|
function _kc_get_user(string $uid): array {
|
|
$resp = _kc_request('GET', "/users/$uid");
|
|
return $resp['status'] === 200 ? json_decode($resp['body'], true) ?? [] : [];
|
|
}
|