trabajando en la tabla de transferencias

This commit is contained in:
2025-11-05 21:46:54 +01:00
parent a4443763d8
commit c11c34011e
14 changed files with 800 additions and 433 deletions

View File

@ -198,18 +198,7 @@ public class PaymentService {
}
if (authorized) {
// GENERAR PEDIDO A PARTIR DEL CARRITO
Cart cart = this.cartService.findById(notif.cartId);
if (cart != null) {
// Bloqueamos el carrito
this.cartService.lockCartById(cart.getId());
// order ID es generado dentro de createOrderFromCart donde se marcan los
// presupuestos como no editables
// Long orderId =
// this.cartService.pedidoService.createOrderFromCart(cart.getId(), p.getId());
// p.setOrderId(orderId);
}
processOrder(notif.cartId);
}
payRepo.save(p);
@ -230,7 +219,7 @@ public class PaymentService {
}
}
// ---- refundViaRedsys
// ---- refundViaRedsys
// ----
@Transactional
public void refundViaRedsys(Long paymentId, long amountCents, String idempotencyKey) {
@ -295,7 +284,6 @@ public class PaymentService {
payRepo.save(p);
}
@Transactional
public Payment createBankTransferPayment(Long cartId, long amountCents, String currency) {
Payment p = new Payment();
@ -304,6 +292,10 @@ public class PaymentService {
Cart cart = this.cartService.findById(cartId);
if (cart != null && cart.getUserId() != null) {
p.setUserId(cart.getUserId());
// En el orderId de la transferencia pendiente guardamos el ID del carrito
p.setOrderId(cartId);
// Se bloquea el carrito para evitar modificaciones mientras se procesa el pago
this.cartService.lockCartById(cartId);
}
p.setCurrency(currency);
@ -321,7 +313,7 @@ public class PaymentService {
tx.setCurrency(currency);
// tx.setProcessedAt(null); // la dejas nula hasta que se confirme
txRepo.save(tx);
return p;
}
@ -360,6 +352,11 @@ public class PaymentService {
p.setCapturedAt(LocalDateTime.now());
p.setStatus(PaymentStatus.captured);
payRepo.save(p);
// 4) Procesar el pedido asociado al carrito (si existe)
if (p.getOrderId() != null) {
processOrder(p.getOrderId());
}
}
private boolean isRedsysAuthorized(RedsysService.RedsysNotification notif) {
@ -376,4 +373,20 @@ public class PaymentService {
return code >= 0 && code <= 99;
}
private Boolean processOrder(Long cartId) {
// GENERAR PEDIDO A PARTIR DEL CARRITO
Cart cart = this.cartService.findById(cartId);
if (cart != null) {
// Bloqueamos el carrito
this.cartService.lockCartById(cart.getId());
// order ID es generado dentro de createOrderFromCart donde se marcan los
// presupuestos como no editables
// Long orderId =
// this.cartService.pedidoService.createOrderFromCart(cart.getId(), p.getId());
// p.setOrderId(orderId);
}
return true;
}
}