mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-02-11 05:19:14 +00:00
arreglados varios temas además del DL (redsys, etc)
This commit is contained in:
@ -189,9 +189,9 @@ public class RedsysController {
|
||||
try {
|
||||
String idem = "refund-" + paymentId + "-" + amountCents + "-" + UUID.randomUUID();
|
||||
paymentService.refundViaRedsys(paymentId, amountCents, idem);
|
||||
return ResponseEntity.ok("{success:true}");
|
||||
return ResponseEntity.ok("{\"success\":true}");
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.badRequest().body("{success:false, error: '" + e.getMessage() + "'}");
|
||||
return ResponseEntity.badRequest().body("{\"success\":false, \"error\": \"" + e.getMessage() + "\"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,11 +321,33 @@ public class RedsysService {
|
||||
Map<String, Object> decoded = decodeMerchantParametersToMap(dsMerchantParametersResp);
|
||||
|
||||
String dsResponse = String.valueOf(decoded.get("Ds_Response"));
|
||||
if (!"0900".equals(dsResponse)) {
|
||||
if (dsResponse == null) {
|
||||
throw new IllegalStateException("Respuesta Redsys refund sin Ds_Response");
|
||||
}
|
||||
|
||||
int code;
|
||||
try {
|
||||
code = Integer.parseInt(dsResponse);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalStateException("Código Ds_Response no numérico en refund: " + dsResponse, e);
|
||||
}
|
||||
|
||||
// ✅ Consideramos OK: 0–99 (éxito típico) o 900 (0900)
|
||||
boolean ok = (code >= 0 && code <= 99) || code == 900;
|
||||
if (!ok) {
|
||||
throw new IllegalStateException("Devolución rechazada, Ds_Response=" + dsResponse);
|
||||
}
|
||||
|
||||
return String.valueOf(decoded.getOrDefault("Ds_AuthorisationCode", order));
|
||||
// Devolvemos algún identificador razonable para la transacción de refund
|
||||
Object authCodeObj = decoded.get("Ds_AuthorisationCode");
|
||||
String authCode = authCodeObj != null ? String.valueOf(authCodeObj).trim() : null;
|
||||
|
||||
if (authCode == null || authCode.isEmpty()) {
|
||||
// Fallback: usa el Ds_Order original como ID de refund
|
||||
return order;
|
||||
}
|
||||
|
||||
return authCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user