fix(payment): persist amountPaid on payment confirmation
confirmGuestPayment and confirmPayment set the order status to
PROCESSING but never called order.setAmountPaid(...). As a result
amountPaid always read null even after payment, blocking finance
reconciliation against the Swish payout report.
The frontend test mock (GuestPaymentRedirect.spec.ts) expected
amountPaid: 49 but the real backend returned null.
Changes:
- OrderService: inject app.payment.letter-price (default 49) via
@Value and set order.setAmountPaid(BigDecimal.valueOf(letterPrice))
before save in both confirmGuestPayment and confirmPayment
- OrderServiceTest: assert amountPaid == 49 after both confirm paths
Verified: ./gradlew :backend:test — BUILD SUCCESSFUL
Closes #20
This commit is contained in:
parent
48c2a50c5d
commit
7d6d541354
2 changed files with 10 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package se.bilhalsning.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import se.bilhalsning.entity.Order;
|
||||
import se.bilhalsning.entity.OrderStatus;
|
||||
|
|
@ -8,6 +9,7 @@ import se.bilhalsning.exception.InvalidOrderStateException;
|
|||
import se.bilhalsning.exception.OrderNotFoundException;
|
||||
import se.bilhalsning.repository.OrderRepository;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -18,6 +20,9 @@ public class OrderService {
|
|||
private final OrderRepository orderRepository;
|
||||
private final OrderNotificationService orderNotificationService;
|
||||
|
||||
@Value("${app.payment.letter-price:49}")
|
||||
private int letterPrice = 49;
|
||||
|
||||
public Order createOrder(UUID userId, String plate, String letterText) {
|
||||
Order order = new Order();
|
||||
order.setUserId(userId);
|
||||
|
|
@ -72,6 +77,7 @@ public class OrderService {
|
|||
"Beställningen kan inte ändras i detta tillstånd");
|
||||
}
|
||||
order.setStatus(OrderStatus.PROCESSING);
|
||||
order.setAmountPaid(BigDecimal.valueOf(letterPrice));
|
||||
Order saved = orderRepository.save(order);
|
||||
orderNotificationService.notifyOrderProcessing(saved);
|
||||
return saved;
|
||||
|
|
@ -93,6 +99,7 @@ public class OrderService {
|
|||
public Order confirmPayment(UUID orderId, UUID userId) {
|
||||
Order order = requirePendingOwnedBy(orderId, userId);
|
||||
order.setStatus(OrderStatus.PROCESSING);
|
||||
order.setAmountPaid(BigDecimal.valueOf(letterPrice));
|
||||
Order saved = orderRepository.save(order);
|
||||
orderNotificationService.notifyOrderProcessing(saved);
|
||||
return saved;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import se.bilhalsning.exception.InvalidOrderStateException;
|
|||
import se.bilhalsning.exception.OrderNotFoundException;
|
||||
import se.bilhalsning.repository.OrderRepository;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
|
@ -222,6 +223,7 @@ class OrderServiceTest {
|
|||
Order result = orderService.confirmPayment(orderId, userId);
|
||||
|
||||
assertEquals(OrderStatus.PROCESSING, result.getStatus());
|
||||
assertEquals(new BigDecimal("49"), result.getAmountPaid());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -345,6 +347,7 @@ class OrderServiceTest {
|
|||
Order result = orderService.confirmGuestPayment(token);
|
||||
|
||||
assertEquals(OrderStatus.PROCESSING, result.getStatus());
|
||||
assertEquals(new BigDecimal("49"), result.getAmountPaid());
|
||||
verify(orderNotificationService).notifyOrderProcessing(result);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue