diff --git a/ajax_inscr_gestion.php b/ajax_inscr_gestion.php index 92ef6f2..db51a7c 100644 --- a/ajax_inscr_gestion.php +++ b/ajax_inscr_gestion.php @@ -98,7 +98,7 @@ switch ($strAction) { } $strRefundToken = fxRefundEnsureToken(); - $arrRefundCtx = fxRefundComputeContext($recCommandes, $intEveContext, false); + $arrRefundCtx = fxRefundComputeContext($recCommandes, $intEveContext); // Auteur = promoteur connecte (alimente l'encart "Ajoute par" du formulaire). $strAuteur = trim((string)($_SESSION['com_info']['com_prenom'] ?? '') . ' ' diff --git a/php/inc_settings.php b/php/inc_settings.php index 3c25153..77d50d8 100644 --- a/php/inc_settings.php +++ b/php/inc_settings.php @@ -7,7 +7,7 @@ * Constantes * * **************/ -define('_VERSION_CODE', '4.72.718'); +define('_VERSION_CODE', '4.72.719'); define('_DATE_CODE', '2026-06-30'); //MSIN-4290 define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe'); diff --git a/superadm/ajax_refund.php b/superadm/ajax_refund.php index e646c96..998a8d3 100644 --- a/superadm/ajax_refund.php +++ b/superadm/ajax_refund.php @@ -23,8 +23,8 @@ $response = ['success' => false, 'message' => 'Erreur inconnue']; // ============================================================ // AUTHENTIFICATION : qui appelle cet endpoint ? -// - Super Admin (usa_info) -> bypass total (comportement historique, aucun droit granulaire) -// - Promoteur (com_info) -> soumis a inscriptions_gestion.refund + ownership de l'evenement +// - Super Admin (usa_info) -> plafond par evenement (meme ventilation que promoteur) +// - Promoteur (com_info) -> inscriptions_gestion.refund + plafond par evenement // - Personne -> refus // L'autorisation fine du promoteur (ownership) se fait plus bas, une fois la commande relue en DB. // ============================================================ @@ -75,49 +75,42 @@ try { throw new Exception("Le montant doit être > 0."); } - // --- 2bis) AUTORISATION du promoteur (le Super Admin est en bypass) --- - $recCommandesFull = null; + // --- 2bis) Commande relue en BD + plafond par evenement (Super Admin et promoteur) --- + $sqlOwner = "SELECT * FROM inscriptions_panier_acheteurs" + . " WHERE no_commande = '" . $db->fxEscape($no_commande) . "' LIMIT 1"; + $rowOwner = $db->fxGetRow($sqlOwner); + if (!$rowOwner) { + throw new Exception("Commande introuvable."); + } + + if ((string)$rowOwner['TransactionID'] !== (string)$CAPTURE_ID) { + throw new Exception("Incohérence commande / capture."); + } + + $intEveContext = intval($_POST['refund_eve_context'] ?? 0); + if ($intEveContext <= 0) { + $intEveContext = intval($rowOwner['eve_id']); + } + + if ($intEveContext <= 0 || !fxRefundPanierLinkedToEvent($rowOwner['no_panier'], $intEveContext, intval($rowOwner['eve_id']))) { + throw new Exception("Cette commande n'est pas rattachée à l'événement sélectionné."); + } + if (!$blnIsSuperAdmin) { - // L'evenement de reference est RELU en DB depuis la commande (jamais fourni par le client). require_once $_SERVER["DOCUMENT_ROOT"] . "/php/inc_fx_eve_acces.php"; - - $sqlOwner = "SELECT * FROM inscriptions_panier_acheteurs" - . " WHERE no_commande = '" . $db->fxEscape($no_commande) . "' LIMIT 1"; - $rowOwner = $db->fxGetRow($sqlOwner); - if (!$rowOwner) { - throw new Exception("Commande introuvable."); - } - $recCommandesFull = $rowOwner; - - // Defense : la capture postee doit correspondre a la commande reclamee. - if ((string)$rowOwner['TransactionID'] !== (string)$CAPTURE_ID) { - throw new Exception("Incohérence commande / capture."); - } - - $intEveContext = intval($_POST['refund_eve_context'] ?? 0); - if ($intEveContext <= 0) { - $intEveContext = intval($rowOwner['eve_id']); - } - - if ($intEveContext <= 0 || !fxRefundPanierLinkedToEvent($rowOwner['no_panier'], $intEveContext, intval($rowOwner['eve_id']))) { - throw new Exception("Cette commande n'est pas rattachée à votre événement."); - } - - // inscriptions_gestion.refund sur l'evenement de contexte (fiche), pas seulement le checkout. if (!fxEveAccesHasPermission($intComId, $intEveContext, 'inscriptions_gestion.refund')) { throw new Exception("Accès refusé à cet événement."); } - - $arrRefundCtx = fxRefundComputeContext($rowOwner, $intEveContext, false); - $fltMaxAllowed = (float) ($arrRefundCtx['maxblock'] ?? 0); - if ($fltMaxAllowed <= 0 || $amount > ($fltMaxAllowed + 0.009)) { - throw new Exception("Montant supérieur au plafond remboursable pour votre événement (" . number_format($fltMaxAllowed, 2, '.', '') . " $currencyUI)."); - } - - // Journalisation sur l'evenement de contexte (ventilation inter-evenements). - $eve_id = $intEveContext; } + $arrRefundCtx = fxRefundComputeContext($rowOwner, $intEveContext); + $fltMaxAllowed = (float) ($arrRefundCtx['maxblock'] ?? 0); + if ($fltMaxAllowed <= 0 || $amount > ($fltMaxAllowed + 0.009)) { + throw new Exception("Montant supérieur au plafond remboursable pour cet événement (" . number_format($fltMaxAllowed, 2, '.', '') . " $currencyUI)."); + } + + $eve_id = $intEveContext; + // --- 3) Appel PayPal --- require_once $_SERVER["DOCUMENT_ROOT"] .'/paypal_advanced/PaypalCheckout.class.php'; $paypal = new PayPalCheckout(); // adapte si nécessaire diff --git a/superadm/commandes.php b/superadm/commandes.php index 6644dd8..6ee22ef 100644 --- a/superadm/commandes.php +++ b/superadm/commandes.php @@ -412,7 +412,7 @@ if (!isset($CAPTURE_ID) || !is_string($CAPTURE_ID) || $CAPTURE_ID === '') { } // Contexte de remboursement mutualisé (calculs + détails PayPal) -$refundCtx = fxRefundComputeContext($recCommandes, 0, true); +$refundCtx = fxRefundComputeContext($recCommandes, intval($recCommandes['eve_id'] ?? 0)); $paypaldetails = $refundCtx['paypaldetails']; // Auteur du remboursement (Super Admin connecté) : alimente l'encart "Ajouté par". diff --git a/superadm/php/inc_fx_paypal.php b/superadm/php/inc_fx_paypal.php index 0b1a190..9dc9739 100644 --- a/superadm/php/inc_fx_paypal.php +++ b/superadm/php/inc_fx_paypal.php @@ -1168,8 +1168,7 @@ function fxRefundComputeEventShare(array $recCommandes, int $intEveContext): arr * Calcule le contexte de remboursement d'une commande (capture PayPal). * * @param array $recCommandes Ligne commande (TransactionID, eve_id, no_commande, fra_total...) - * @param int $intEveContext Evenement depuis lequel on rembourse (0 = eve_id commande). Ignore si Super Admin. - * @param bool $blnSuperAdmin true = capture PayPal complete (option A Super Admin). + * @param int $intEveContext Evenement depuis lequel on rembourse (0 = eve_id commande). * @return array { * ok:bool, capture_id:string, currency:string, paypaldetails:array, * max_paypal:float, solde_dispo:float, frais_ms1:float, @@ -1177,7 +1176,7 @@ function fxRefundComputeEventShare(array $recCommandes, int $intEveContext): arr * split_active:bool, event_share:float, sister_share:float, eve_id_context:int * } */ -function fxRefundComputeContext(array $recCommandes, int $intEveContext = 0, bool $blnSuperAdmin = false): array +function fxRefundComputeContext(array $recCommandes, int $intEveContext = 0): array { $out = [ 'ok' => false, @@ -1206,7 +1205,7 @@ function fxRefundComputeContext(array $recCommandes, int $intEveContext = 0, boo require_once $_SERVER['DOCUMENT_ROOT'] . '/paypal_advanced/PaypalCheckout.class.php'; $paypal = new PayPalCheckout(); - $intSoldeEveId = $blnSuperAdmin ? intval($recCommandes['eve_id'] ?? 0) : ($intEveContext > 0 ? $intEveContext : intval($recCommandes['eve_id'] ?? 0)); + $intSoldeEveId = ($intEveContext > 0 ? $intEveContext : intval($recCommandes['eve_id'] ?? 0)); $out['solde_dispo'] = (float) statut_payement($intSoldeEveId); // Details PayPal de la capture + reconciliation locale @@ -1236,15 +1235,6 @@ function fxRefundComputeContext(array $recCommandes, int $intEveContext = 0, boo $out['frais_ms1'] = (float) ($recCommandes['fra_total'] ?? 0); - if ($blnSuperAdmin) { - // Option A — Super Admin : capture PayPal complete (comportement historique). - $out['maxUI'] = $maxPaypal; - $out['maxblock'] = ($maxPaypal < $out['solde_dispo']) ? $maxPaypal : 0.0; - $out['maxproposer'] = max(0.0, $out['maxUI'] - $out['frais_ms1']); - $out['ok'] = true; - return $out; - } - if ($intEveContext <= 0) { $intEveContext = intval($recCommandes['eve_id'] ?? 0); }