This commit is contained in:
@@ -4,9 +4,11 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.ReferralRepo;
|
||||
import ru.soune.ReferralService;
|
||||
import ru.soune.nocopy.client.YooKassaClient;
|
||||
import ru.soune.nocopy.dto.payment.PaymentMethodDTO;
|
||||
import ru.soune.nocopy.entity.notification.NotificationType;
|
||||
import ru.soune.nocopy.entity.payment.Payment;
|
||||
import ru.soune.nocopy.entity.payment.PaymentMethod;
|
||||
import ru.soune.nocopy.entity.payment.PaymentOperationType;
|
||||
@@ -19,6 +21,7 @@ import ru.soune.nocopy.exception.PaymentNotFoundException;
|
||||
import ru.soune.nocopy.exception.TariffNotFoundException;
|
||||
import ru.soune.nocopy.exception.UserNotFoundException;
|
||||
import ru.soune.nocopy.repository.*;
|
||||
import ru.soune.nocopy.service.notification.NotificationService;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -46,6 +49,10 @@ public class PaymentService {
|
||||
|
||||
private final YooKassaClient yooKassaClient;
|
||||
|
||||
private final ReferralRepo referralRepo;
|
||||
|
||||
private final NotificationService notificationService;
|
||||
|
||||
@Transactional
|
||||
public Payment createPayment(String email, Long tariffId, String operationType, String paymentUuid) {
|
||||
User user = userRepository.findByEmail(email);
|
||||
@@ -158,15 +165,19 @@ public class PaymentService {
|
||||
savePaymentMethod(payment.getUser(), paymentMethod);
|
||||
|
||||
referralService.onUserAccountRefill(payment.getUser().getId(), intPrice);
|
||||
|
||||
long inviterIdForUser = referralRepo.getInviterIdForUser(payment.getUser().getId());
|
||||
|
||||
notificationService.addNotification(NotificationType.REFERRAL_ACTIVATED, inviterIdForUser);
|
||||
} else if ("payment.canceled".equals(eventType)) {
|
||||
payment.setStatus(PaymentStatus.CANCELED);
|
||||
|
||||
Map<String, Object> cancellationDetails = (Map<String, Object>) object.get("cancellation_details");
|
||||
if (cancellationDetails != null) {
|
||||
String reason = (String) cancellationDetails.get("reason");
|
||||
payment.setCancellationReason(reason);
|
||||
}
|
||||
|
||||
String reason = (String) cancellationDetails.get("reason");
|
||||
payment.setCancellationReason(reason);
|
||||
|
||||
notificationService.addNotification(NotificationType.PAYOUT_RESULT, payment.getUser().getId(), reason);
|
||||
} else if ("payment.waiting_for_capture".equals(eventType)) {
|
||||
payment.setStatus(PaymentStatus.WAITING);
|
||||
payment.setCancellationReason(null);
|
||||
@@ -175,10 +186,11 @@ public class PaymentService {
|
||||
payment.setStatus(PaymentStatus.FAILED);
|
||||
|
||||
Map<String, Object> cancellationDetails = (Map<String, Object>) object.get("cancellation_details");
|
||||
if (cancellationDetails != null) {
|
||||
String reason = (String) cancellationDetails.get("reason");
|
||||
payment.setCancellationReason(reason);
|
||||
}
|
||||
|
||||
String reason = (String) cancellationDetails.get("reason");
|
||||
payment.setCancellationReason(reason);
|
||||
|
||||
notificationService.addNotification(NotificationType.PAYOUT_RESULT, payment.getUser().getId(), reason);
|
||||
}
|
||||
|
||||
paymentRepository.save(payment);
|
||||
|
||||
Reference in New Issue
Block a user