MSIN-4417 Update refund context handling in registration management
This commit refines the refund context handling by removing the unnecessary boolean parameter for Super Admin in the `fxRefundComputeContext` function, simplifying the logic. It ensures that refunds are consistently linked to the correct event context across various functions, enhancing authorization checks and calculations. The version code is incremented to 4.72.719 to reflect these changes.
This commit is contained in:
@ -98,7 +98,7 @@ switch ($strAction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$strRefundToken = fxRefundEnsureToken();
|
$strRefundToken = fxRefundEnsureToken();
|
||||||
$arrRefundCtx = fxRefundComputeContext($recCommandes, $intEveContext, false);
|
$arrRefundCtx = fxRefundComputeContext($recCommandes, $intEveContext);
|
||||||
|
|
||||||
// Auteur = promoteur connecte (alimente l'encart "Ajoute par" du formulaire).
|
// Auteur = promoteur connecte (alimente l'encart "Ajoute par" du formulaire).
|
||||||
$strAuteur = trim((string)($_SESSION['com_info']['com_prenom'] ?? '') . ' '
|
$strAuteur = trim((string)($_SESSION['com_info']['com_prenom'] ?? '') . ' '
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
* Constantes *
|
* Constantes *
|
||||||
*
|
*
|
||||||
**************/
|
**************/
|
||||||
define('_VERSION_CODE', '4.72.718');
|
define('_VERSION_CODE', '4.72.719');
|
||||||
define('_DATE_CODE', '2026-06-30');
|
define('_DATE_CODE', '2026-06-30');
|
||||||
//MSIN-4290
|
//MSIN-4290
|
||||||
define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe');
|
define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe');
|
||||||
|
|||||||
@ -23,8 +23,8 @@ $response = ['success' => false, 'message' => 'Erreur inconnue'];
|
|||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// AUTHENTIFICATION : qui appelle cet endpoint ?
|
// AUTHENTIFICATION : qui appelle cet endpoint ?
|
||||||
// - Super Admin (usa_info) -> bypass total (comportement historique, aucun droit granulaire)
|
// - Super Admin (usa_info) -> plafond par evenement (meme ventilation que promoteur)
|
||||||
// - Promoteur (com_info) -> soumis a inscriptions_gestion.refund + ownership de l'evenement
|
// - Promoteur (com_info) -> inscriptions_gestion.refund + plafond par evenement
|
||||||
// - Personne -> refus
|
// - Personne -> refus
|
||||||
// L'autorisation fine du promoteur (ownership) se fait plus bas, une fois la commande relue en DB.
|
// L'autorisation fine du promoteur (ownership) se fait plus bas, une fois la commande relue en DB.
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@ -75,21 +75,14 @@ try {
|
|||||||
throw new Exception("Le montant doit être > 0.");
|
throw new Exception("Le montant doit être > 0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- 2bis) AUTORISATION du promoteur (le Super Admin est en bypass) ---
|
// --- 2bis) Commande relue en BD + plafond par evenement (Super Admin et promoteur) ---
|
||||||
$recCommandesFull = null;
|
|
||||||
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"
|
$sqlOwner = "SELECT * FROM inscriptions_panier_acheteurs"
|
||||||
. " WHERE no_commande = '" . $db->fxEscape($no_commande) . "' LIMIT 1";
|
. " WHERE no_commande = '" . $db->fxEscape($no_commande) . "' LIMIT 1";
|
||||||
$rowOwner = $db->fxGetRow($sqlOwner);
|
$rowOwner = $db->fxGetRow($sqlOwner);
|
||||||
if (!$rowOwner) {
|
if (!$rowOwner) {
|
||||||
throw new Exception("Commande introuvable.");
|
throw new Exception("Commande introuvable.");
|
||||||
}
|
}
|
||||||
$recCommandesFull = $rowOwner;
|
|
||||||
|
|
||||||
// Defense : la capture postee doit correspondre a la commande reclamee.
|
|
||||||
if ((string)$rowOwner['TransactionID'] !== (string)$CAPTURE_ID) {
|
if ((string)$rowOwner['TransactionID'] !== (string)$CAPTURE_ID) {
|
||||||
throw new Exception("Incohérence commande / capture.");
|
throw new Exception("Incohérence commande / capture.");
|
||||||
}
|
}
|
||||||
@ -100,23 +93,23 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($intEveContext <= 0 || !fxRefundPanierLinkedToEvent($rowOwner['no_panier'], $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.");
|
throw new Exception("Cette commande n'est pas rattachée à l'événement sélectionné.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// inscriptions_gestion.refund sur l'evenement de contexte (fiche), pas seulement le checkout.
|
if (!$blnIsSuperAdmin) {
|
||||||
|
require_once $_SERVER["DOCUMENT_ROOT"] . "/php/inc_fx_eve_acces.php";
|
||||||
if (!fxEveAccesHasPermission($intComId, $intEveContext, 'inscriptions_gestion.refund')) {
|
if (!fxEveAccesHasPermission($intComId, $intEveContext, 'inscriptions_gestion.refund')) {
|
||||||
throw new Exception("Accès refusé à cet événement.");
|
throw new Exception("Accès refusé à cet événement.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$arrRefundCtx = fxRefundComputeContext($rowOwner, $intEveContext, false);
|
$arrRefundCtx = fxRefundComputeContext($rowOwner, $intEveContext);
|
||||||
$fltMaxAllowed = (float) ($arrRefundCtx['maxblock'] ?? 0);
|
$fltMaxAllowed = (float) ($arrRefundCtx['maxblock'] ?? 0);
|
||||||
if ($fltMaxAllowed <= 0 || $amount > ($fltMaxAllowed + 0.009)) {
|
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).");
|
throw new Exception("Montant supérieur au plafond remboursable pour cet événement (" . number_format($fltMaxAllowed, 2, '.', '') . " $currencyUI).");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Journalisation sur l'evenement de contexte (ventilation inter-evenements).
|
|
||||||
$eve_id = $intEveContext;
|
$eve_id = $intEveContext;
|
||||||
}
|
|
||||||
|
|
||||||
// --- 3) Appel PayPal ---
|
// --- 3) Appel PayPal ---
|
||||||
require_once $_SERVER["DOCUMENT_ROOT"] .'/paypal_advanced/PaypalCheckout.class.php';
|
require_once $_SERVER["DOCUMENT_ROOT"] .'/paypal_advanced/PaypalCheckout.class.php';
|
||||||
|
|||||||
@ -412,7 +412,7 @@ if (!isset($CAPTURE_ID) || !is_string($CAPTURE_ID) || $CAPTURE_ID === '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Contexte de remboursement mutualisé (calculs + détails PayPal)
|
// Contexte de remboursement mutualisé (calculs + détails PayPal)
|
||||||
$refundCtx = fxRefundComputeContext($recCommandes, 0, true);
|
$refundCtx = fxRefundComputeContext($recCommandes, intval($recCommandes['eve_id'] ?? 0));
|
||||||
$paypaldetails = $refundCtx['paypaldetails'];
|
$paypaldetails = $refundCtx['paypaldetails'];
|
||||||
|
|
||||||
// Auteur du remboursement (Super Admin connecté) : alimente l'encart "Ajouté par".
|
// Auteur du remboursement (Super Admin connecté) : alimente l'encart "Ajouté par".
|
||||||
|
|||||||
@ -1168,8 +1168,7 @@ function fxRefundComputeEventShare(array $recCommandes, int $intEveContext): arr
|
|||||||
* Calcule le contexte de remboursement d'une commande (capture PayPal).
|
* Calcule le contexte de remboursement d'une commande (capture PayPal).
|
||||||
*
|
*
|
||||||
* @param array $recCommandes Ligne commande (TransactionID, eve_id, no_commande, fra_total...)
|
* @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 int $intEveContext Evenement depuis lequel on rembourse (0 = eve_id commande).
|
||||||
* @param bool $blnSuperAdmin true = capture PayPal complete (option A Super Admin).
|
|
||||||
* @return array {
|
* @return array {
|
||||||
* ok:bool, capture_id:string, currency:string, paypaldetails:array,
|
* ok:bool, capture_id:string, currency:string, paypaldetails:array,
|
||||||
* max_paypal:float, solde_dispo:float, frais_ms1:float,
|
* 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
|
* 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 = [
|
$out = [
|
||||||
'ok' => false,
|
'ok' => false,
|
||||||
@ -1206,7 +1205,7 @@ function fxRefundComputeContext(array $recCommandes, int $intEveContext = 0, boo
|
|||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/paypal_advanced/PaypalCheckout.class.php';
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/paypal_advanced/PaypalCheckout.class.php';
|
||||||
$paypal = new PayPalCheckout();
|
$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);
|
$out['solde_dispo'] = (float) statut_payement($intSoldeEveId);
|
||||||
|
|
||||||
// Details PayPal de la capture + reconciliation locale
|
// 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);
|
$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) {
|
if ($intEveContext <= 0) {
|
||||||
$intEveContext = intval($recCommandes['eve_id'] ?? 0);
|
$intEveContext = intval($recCommandes['eve_id'] ?? 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user