sistema de pedidos pendientes de pago hechos

This commit is contained in:
2025-12-23 17:41:05 +01:00
parent d4120bb486
commit b94a099e01
15 changed files with 3895 additions and 868 deletions

View File

@ -231,20 +231,9 @@ public class PaymentController {
})
.add("transfer_id", pago -> {
if (pago.getPayment() != null) {
String responsePayload = pago.getResponsePayload();
Long cartId = null;
if (responsePayload != null && !responsePayload.isBlank()) {
try {
JsonNode node = new ObjectMapper().readTree(responsePayload);
if (node.has("cartId")) {
cartId = node.get("cartId").asLong();
}
} catch (Exception e) {
cartId = null;
}
}
if (cartId != null) {
return "TRANSF-" + cartId;
Long pedido = pago.getPayment().getOrderId();
if (pedido != null) {
return "TRANSF-" + pedido;
}
}
return "";

View File

@ -51,7 +51,7 @@ public class PaymentService {
}
public Payment findFailedPaymentByOrderId(Long orderId) {
return payRepo.findByOrderIdAndStatus(orderId, PaymentStatus.failed)
return payRepo.findFirstByOrderIdAndStatusOrderByIdDesc(orderId, PaymentStatus.failed)
.orElse(null);
}
@ -69,11 +69,17 @@ public class PaymentService {
var node = om.readTree(resp_payload);
Long cartId = null;
Long dirFactId = null;
if (node.has("cartId")) {
cartId = node.get("cartId").asLong();
}
if (node.has("dirFactId")) {
dirFactId = node.get("dirFactId").asLong();
if (node.has("Ds_MerchantData")) {
// format: "Ds_MerchantData": "{"dirFactId":3,"cartId":90}"
String merchantData = node.get("Ds_MerchantData").asText();
merchantData = merchantData.replace(""", "\"");
var mdNode = om.readTree(merchantData);
if (mdNode.has("cartId")) {
cartId = mdNode.get("cartId").asLong();
}
if (mdNode.has("dirFactId")) {
dirFactId = mdNode.get("dirFactId").asLong();
}
}
return Map.of(
"cartId", cartId,

View File

@ -10,5 +10,5 @@ import java.util.Optional;
public interface PaymentRepository extends JpaRepository<Payment, Long> {
Optional<Payment> findByGatewayAndGatewayOrderId(String gateway, String gatewayOrderId);
Optional<Payment> findByOrderIdAndStatus(Long orderId, PaymentStatus status);
Optional<Payment> findFirstByOrderIdAndStatusOrderByIdDesc(Long orderId, PaymentStatus status);
}