dev add context for notifcations
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-05-13 13:39:02 +07:00
parent 0546f6acd5
commit 48c14d475d
10 changed files with 154 additions and 21 deletions
@@ -1,5 +1,7 @@
package ru.soune.nocopy.service.payment;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -13,6 +15,7 @@ import ru.soune.nocopy.entity.payment.Payment;
import ru.soune.nocopy.entity.payment.PaymentMethod;
import ru.soune.nocopy.entity.payment.PaymentOperationType;
import ru.soune.nocopy.entity.payment.PaymentStatus;
import ru.soune.nocopy.entity.search.GlobalSearchTask;
import ru.soune.nocopy.entity.tarif.Tariff;
import ru.soune.nocopy.entity.tarif.TariffInfo;
import ru.soune.nocopy.entity.tarif.TariffStatus;
@@ -25,6 +28,7 @@ import ru.soune.nocopy.service.notification.NotificationService;
import ru.soune.nocopy.service.tariff.TariffInfoService;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -166,9 +170,7 @@ public class PaymentService {
referralService.onUserAccountRefill(payment.getUser().getId(), intPrice);
// long inviterIdForUser = referralRepo.getInviterIdForUser(payment.getUser().getId());
// notificationService.addNotification(NotificationType.REFERRAL_ACTIVATED, inviterIdForUser);
addSearchPaymentNotification(payment, payment.getUser().getId(), null);
} else if ("payment.canceled".equals(eventType)) {
payment.setStatus(PaymentStatus.CANCELED);
@@ -177,7 +179,7 @@ public class PaymentService {
String reason = (String) cancellationDetails.get("reason");
payment.setCancellationReason(reason);
notificationService.addNotification(NotificationType.PAYMENT_RESULT, payment.getUser().getId(), reason);
addSearchPaymentNotification(payment, payment.getUser().getId(), reason);
} else if ("payment.waiting_for_capture".equals(eventType)) {
payment.setStatus(PaymentStatus.WAITING);
payment.setCancellationReason(null);
@@ -190,12 +192,23 @@ public class PaymentService {
String reason = (String) cancellationDetails.get("reason");
payment.setCancellationReason(reason);
notificationService.addNotification(NotificationType.PAYMENT_RESULT, payment.getUser().getId(), reason);
addSearchPaymentNotification(payment, payment.getUser().getId(), reason);
}
paymentRepository.save(payment);
}
private void addSearchPaymentNotification(Payment payment, Long userId, String reason) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode context = mapper.createObjectNode();
context.put("status", payment.getStatus().name());
context.put("reason", reason);
context.put("amount", payment.getAmount());
notificationService.addNotification(NotificationType.PAYMENT_RESULT, userId, context);
}
public List<Payment> userPayments(String email) {
User user = userRepository.findByEmail(email);