From 744ff00b9d87d084f3ebec51799449899a23e9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20M=C3=B6rling?= Date: Fri, 15 May 2026 20:29:42 +0200 Subject: [PATCH] feat: add POST /api/payment/{orderId}/pay mock payment endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PaymentController: @RestController at /api/payment, requires authentication (covered by SecurityConfig.anyRequest().authenticated()) - POST /{orderId}/pay: calls orderService.markAsPaid(orderId) which sets status=PAID and amountPaid=49.00, returns updated OrderResponse - No Stripe integration yet — pure mock simulating what a successful Stripe webhook callback would do in Phase 1 - toResponse() mapper reuses the same OrderResponse structure as OrderController for consistent API shape --- .../controller/PaymentController.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 backend/src/main/java/se/bilhalsning/controller/PaymentController.java diff --git a/backend/src/main/java/se/bilhalsning/controller/PaymentController.java b/backend/src/main/java/se/bilhalsning/controller/PaymentController.java new file mode 100644 index 0000000..43200cd --- /dev/null +++ b/backend/src/main/java/se/bilhalsning/controller/PaymentController.java @@ -0,0 +1,38 @@ +package se.bilhalsning.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import se.bilhalsning.dto.OrderResponse; +import se.bilhalsning.entity.Order; +import se.bilhalsning.service.OrderService; + +import java.util.UUID; + +@RestController +@RequestMapping("/api/payment") +@RequiredArgsConstructor +public class PaymentController { + + private final OrderService orderService; + + @PostMapping("/{orderId}/pay") + public ResponseEntity pay(@PathVariable UUID orderId) { + Order order = orderService.markAsPaid(orderId); + return ResponseEntity.ok(toResponse(order)); + } + + private OrderResponse toResponse(Order order) { + return new OrderResponse( + order.getId(), + order.getPlate(), + order.getStatus().getValue(), + order.getTrackingId(), + order.getAmountPaid(), + order.getCreatedAt() + ); + } +}