@@ -2,8 +2,11 @@ package ru.soune.nocopy.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.soune.nocopy.entity.payment.Payment;
|
||||
import ru.soune.nocopy.exception.TariffNotFoundException;
|
||||
import ru.soune.nocopy.exception.UserNotFoundException;
|
||||
import ru.soune.nocopy.service.payment.PaymentService;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -17,9 +20,14 @@ public class PaymentController {
|
||||
private final PaymentService paymentService;
|
||||
|
||||
@PostMapping("/create")
|
||||
public Payment createPayment(@RequestParam String email, @RequestParam Long tariffId,
|
||||
@RequestParam String operationType, @RequestParam String operationUuid) {
|
||||
return paymentService.createPayment(email, tariffId, operationType, operationUuid);
|
||||
public ResponseEntity<Payment> createPayment(@RequestParam String email, @RequestParam Long tariffId,
|
||||
@RequestParam String operationType, @RequestParam String operationUuid) {
|
||||
try {
|
||||
Payment payment = paymentService.createPayment(email, tariffId, operationType, operationUuid);
|
||||
return ResponseEntity.ok(payment);
|
||||
} catch (TariffNotFoundException | UserNotFoundException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("webhook/yookassa")
|
||||
|
||||
@@ -11,6 +11,7 @@ import ru.soune.nocopy.entity.tarif.TariffInfo;
|
||||
import ru.soune.nocopy.entity.tarif.TariffStatus;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.PaymentNotFoundException;
|
||||
import ru.soune.nocopy.exception.TariffNotFoundException;
|
||||
import ru.soune.nocopy.exception.UserNotFoundException;
|
||||
import ru.soune.nocopy.repository.PaymentRepository;
|
||||
import ru.soune.nocopy.repository.TariffRepository;
|
||||
@@ -35,7 +36,13 @@ public class PaymentService {
|
||||
@Transactional
|
||||
public Payment createPayment(String email, Long tariffId, String operationType, String paymentUuid) {
|
||||
User user = userRepository.findByEmail(email);
|
||||
Tariff tariff = tariffRepository.findById(tariffId).orElseThrow();
|
||||
|
||||
if (user == null) {
|
||||
throw new UserNotFoundException(email);
|
||||
}
|
||||
|
||||
Tariff tariff = tariffRepository.findById(tariffId).orElseThrow(() ->
|
||||
new TariffNotFoundException("Tariff not found"));
|
||||
|
||||
Payment payment = new Payment();
|
||||
payment.setStatus(PaymentStatus.PENDING);
|
||||
|
||||
Reference in New Issue
Block a user