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

42 lines
1.5 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-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-18 18:42:55 +07:00
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();
}
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);
}
}
}