Files
no-copy/src/main/java/ru/soune/nocopy/controller/PaymentController.java
T

54 lines
2.0 KiB
Java
Raw Normal View History

2026-02-18 16:14:17 +07:00
package ru.soune.nocopy.controller;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
2026-02-19 14:15:59 +07:00
import org.springframework.http.HttpStatus;
2026-02-18 18:42:55 +07:00
import org.springframework.http.ResponseEntity;
2026-02-18 16:14:17 +07:00
import org.springframework.web.bind.annotation.*;
import ru.soune.nocopy.entity.payment.Payment;
2026-02-18 18:42:55 +07:00
import ru.soune.nocopy.exception.TariffNotFoundException;
import ru.soune.nocopy.exception.UserNotFoundException;
2026-02-18 16:14:17 +07:00
import ru.soune.nocopy.service.payment.PaymentService;
import java.util.Map;
@RestController
@RequestMapping("/api/payments")
@RequiredArgsConstructor
@Slf4j
public class PaymentController {
private final PaymentService paymentService;
@PostMapping("/create")
2026-02-19 14:15:59 +07:00
public ResponseEntity<?> createPayment(@RequestParam String email, @RequestParam Long tariffId,
@RequestParam String operationType, @RequestParam String operationUuid) {
2026-02-18 18:42:55 +07:00
try {
Payment payment = paymentService.createPayment(email, tariffId, operationType, operationUuid);
2026-02-19 14:15:59 +07:00
2026-02-18 18:42:55 +07:00
return ResponseEntity.ok(payment);
2026-02-19 14:15:59 +07:00
} catch (TariffNotFoundException e) {
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.body(Map.of("error", "Tariff not found", "message", e.getMessage()));
} catch (UserNotFoundException e) {
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.body(Map.of("error", "User not found", "message", e.getMessage()));
} catch (Exception e) {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Map.of("error", "Internal server error", "message", e.getMessage()));
2026-02-18 18:42:55 +07:00
}
2026-02-18 16:14:17 +07:00
}
@PostMapping("webhook/yookassa")
public void handleYooKassaNotification(@RequestBody Map<String, Object> notification) {
try {
paymentService.handlePaymentNotification(notification);
} catch (Exception e) {
log.error("Error processing payment notification", e);
}
}
}