Refactoring

This commit is contained in:
dahoud
2026-01-31 16:54:46 +00:00
parent ce89face73
commit 9dc9ca591c
85 changed files with 2643 additions and 381 deletions

View File

@@ -48,6 +48,8 @@ public class WavePaymentService {
EstablishmentPaymentRepository paymentRepository;
@Inject
UsersRepository usersRepository;
@Inject
EmailService emailService;
@ConfigProperty(name = "wave.api.url", defaultValue = "https://api.wave.com")
String waveApiUrl;
@@ -184,8 +186,32 @@ public class WavePaymentService {
manager.setActive(true);
usersRepository.persist(manager);
LOG.info("Webhook Wave: établissement et manager activés pour " + establishmentId);
try {
emailService.sendPaymentConfirmationEmail(
manager.getEmail(),
manager.getFirstName(),
establishment.getName(),
sub.getAmountXof() != null ? sub.getAmountXof() : 0,
sub.getPlan() != null ? sub.getPlan() : "MONTHLY"
);
} catch (Exception e) {
LOG.warn("Envoi email confirmation paiement échoué: " + e.getMessage());
}
}
}
} else if ("payment.refunded".equals(eventType)) {
sub.setStatus(EstablishmentSubscription.STATUS_CANCELLED);
subscriptionRepository.persist(sub);
if (establishment != null) {
establishment.setIsActive(false);
establishmentRepository.persist(establishment);
Users manager = establishment.getManager();
if (manager != null) {
manager.setActive(false);
usersRepository.persist(manager);
}
LOG.info("Webhook Wave: remboursement traité, établissement désactivé pour " + establishmentId);
}
} else if ("payment.cancelled".equals(eventType) || "payment.expired".equals(eventType)
|| "payment.failed".equals(eventType)) {
sub.setStatus(EstablishmentSubscription.STATUS_CANCELLED);
@@ -199,6 +225,17 @@ public class WavePaymentService {
manager.setActive(false);
usersRepository.persist(manager);
LOG.info("Webhook Wave: établissement et manager suspendus pour " + establishmentId);
if ("payment.failed".equals(eventType)) {
try {
emailService.sendPaymentFailureEmail(
manager.getEmail(),
manager.getFirstName(),
establishment.getName()
);
} catch (Exception e) {
LOG.warn("Envoi email échec paiement échoué: " + e.getMessage());
}
}
}
}
}
@@ -207,8 +244,11 @@ public class WavePaymentService {
paymentRepository.findByWaveSessionId(sessionId).ifPresent(payment -> {
if ("payment.completed".equals(eventType)) {
payment.setStatus(EstablishmentPayment.STATUS_COMPLETED);
} else if ("payment.cancelled".equals(eventType) || "payment.expired".equals(eventType)) {
} else if ("payment.cancelled".equals(eventType) || "payment.expired".equals(eventType)
|| "payment.refunded".equals(eventType)) {
payment.setStatus(EstablishmentPayment.STATUS_CANCELLED);
} else if ("payment.failed".equals(eventType)) {
payment.setStatus(EstablishmentPayment.STATUS_FAILED);
}
paymentRepository.persist(payment);
});