fix(paiement): envoi de l'email de confirmation uniquement si le paiement est remis
This commit is contained in:
@@ -70,6 +70,11 @@ public class PaiementEmailService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Boolean.FALSE.equals(paiement.getRemis())) {
|
||||||
|
log.info("Paiement non remis (remis=false) pour le paiement ID {}. L'e-mail de confirmation ne sera pas envoyé.", paiement.getId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Licence licence = paiement.getLicence();
|
Licence licence = paiement.getLicence();
|
||||||
String recipientEmail = licence.getAdherent() != null ? licence.getAdherent().getEmail() : null;
|
String recipientEmail = licence.getAdherent() != null ? licence.getAdherent().getEmail() : null;
|
||||||
log.info(">>> [PaiementEmailService] Adhérent: {} {}, Email: {}",
|
log.info(">>> [PaiementEmailService] Adhérent: {} {}, Email: {}",
|
||||||
|
|||||||
+19
@@ -170,4 +170,23 @@ class PaiementEmailServiceTest {
|
|||||||
assertTrue(result);
|
assertTrue(result);
|
||||||
verify(mailSenderMock, timeout(2000).times(1)).send(any(MimeMessage.class));
|
verify(mailSenderMock, timeout(2000).times(1)).send(any(MimeMessage.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSendPaiementConfirmation_NonRemis() {
|
||||||
|
Adherent adherent = new Adherent();
|
||||||
|
adherent.setNom("DUPONT");
|
||||||
|
adherent.setPrenom("Jean");
|
||||||
|
adherent.setEmail("jean.dupont@example.com");
|
||||||
|
|
||||||
|
Licence licence = new Licence();
|
||||||
|
licence.setAdherent(adherent);
|
||||||
|
|
||||||
|
Paiement paiement = new Paiement();
|
||||||
|
paiement.setLicence(licence);
|
||||||
|
paiement.setMontant(new BigDecimal("50.00"));
|
||||||
|
paiement.setRemis(false);
|
||||||
|
|
||||||
|
boolean result = paiementEmailService.sendPaiementConfirmation(paiement);
|
||||||
|
assertFalse(result, "Devrait retourner false et ne pas envoyer d'email si remis = false");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ public class PaiementController {
|
|||||||
|
|
||||||
BigDecimal ancienMontant = paiement.getMontant();
|
BigDecimal ancienMontant = paiement.getMontant();
|
||||||
String ancienMode = paiement.getModePaiement().getNom();
|
String ancienMode = paiement.getModePaiement().getNom();
|
||||||
|
Boolean ancienRemis = paiement.getRemis();
|
||||||
|
|
||||||
Licence licence = paiement.getLicence();
|
Licence licence = paiement.getLicence();
|
||||||
|
|
||||||
@@ -154,6 +155,16 @@ public class PaiementController {
|
|||||||
auditLog.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom());
|
auditLog.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom());
|
||||||
auditLog.setDetails("Modification du paiement: montant " + ancienMontant + "€ -> " + montant + "€, mode " + ancienMode + " -> " + mode.getNom() + ", remis -> " + (Boolean.TRUE.equals(remis) ? "Oui" : "Non"));
|
auditLog.setDetails("Modification du paiement: montant " + ancienMontant + "€ -> " + montant + "€, mode " + ancienMode + " -> " + mode.getNom() + ", remis -> " + (Boolean.TRUE.equals(remis) ? "Oui" : "Non"));
|
||||||
auditLogPaiementRepository.save(auditLog);
|
auditLogPaiementRepository.save(auditLog);
|
||||||
|
|
||||||
|
// Si le paiement passe de non remis (ex: Chèque Sport mairie) à remis (Oui), envoyer l'email de confirmation
|
||||||
|
if (Boolean.FALSE.equals(ancienRemis) && Boolean.TRUE.equals(remis)) {
|
||||||
|
try {
|
||||||
|
log.info("Appel de sendPaiementConfirmation depuis updatePaiement (passage de remis=false à remis=true) pour le paiement ID: {}", paiement.getId());
|
||||||
|
paiementEmailService.sendPaiementConfirmation(paiement);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Erreur lors de l'envoi de l'e-mail de confirmation après la remise du paiement ID {}: ", id, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redirect != null && !redirect.isEmpty()) {
|
if (redirect != null && !redirect.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user