mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
trabajando en el notify
This commit is contained in:
@ -77,21 +77,34 @@ public class PaymentService {
|
||||
* decodeMerchantParameters
|
||||
*/
|
||||
@Transactional
|
||||
public void handleRedsysNotification(String dsSignature, String dsMerchantParametersB64) throws Exception {
|
||||
RedsysNotification notif = redsysService.validateAndParseNotification(dsSignature, dsMerchantParametersB64);
|
||||
public void handleRedsysNotification(String dsSignature, String dsMerchantParameters) throws Exception {
|
||||
RedsysNotification notif = redsysService.validateAndParseNotification(dsSignature, dsMerchantParameters);
|
||||
|
||||
// Log útil para depurar
|
||||
System.out.println(">> Redsys notify: order=" + notif.order +
|
||||
" amountCents=" + notif.amountCents +
|
||||
" currency=" + notif.currency +
|
||||
" response=" + notif.response);
|
||||
|
||||
Payment p = payRepo.findByGatewayAndGatewayOrderId("redsys", notif.order)
|
||||
.orElseThrow(() -> new IllegalStateException("Payment no encontrado para Ds_Order " + notif.order));
|
||||
|
||||
if (!Objects.equals(p.getCurrency(), notif.currency)) {
|
||||
throw new IllegalStateException("Divisa inesperada");
|
||||
}
|
||||
// 🔹 Opción sencilla: sólo comprobar el importe
|
||||
if (!Objects.equals(p.getAmountTotalCents(), notif.amountCents)) {
|
||||
throw new IllegalStateException("Importe inesperado");
|
||||
throw new IllegalStateException("Importe inesperado: esperado=" +
|
||||
p.getAmountTotalCents() + " recibido=" + notif.amountCents);
|
||||
}
|
||||
|
||||
// Idempotencia sencilla: si ya está capturado o reembolsado, no creamos otra
|
||||
// transacción
|
||||
// Si quieres, puedes hacer un check mínimamente decente de divisa numérica:
|
||||
// (si usas siempre EUR)
|
||||
/*
|
||||
* if (!"978".equals(notif.currency)) {
|
||||
* throw new IllegalStateException("Divisa Redsys inesperada: " +
|
||||
* notif.currency);
|
||||
* }
|
||||
*/
|
||||
|
||||
// Idempotencia simple: si ya está capturado o reembolsado, no hacemos nada
|
||||
if (p.getStatus() == PaymentStatus.CAPTURED
|
||||
|| p.getStatus() == PaymentStatus.PARTIALLY_REFUNDED
|
||||
|| p.getStatus() == PaymentStatus.REFUNDED) {
|
||||
@ -101,9 +114,10 @@ public class PaymentService {
|
||||
PaymentTransaction tx = new PaymentTransaction();
|
||||
tx.setPayment(p);
|
||||
tx.setType(PaymentTransactionType.CAPTURE);
|
||||
tx.setCurrency(p.getCurrency());
|
||||
tx.setCurrency(p.getCurrency()); // "EUR"
|
||||
tx.setAmountCents(notif.amountCents);
|
||||
tx.setStatus(notif.authorized() ? PaymentTransactionStatus.SUCCEEDED
|
||||
tx.setStatus(notif.authorized()
|
||||
? PaymentTransactionStatus.SUCCEEDED
|
||||
: PaymentTransactionStatus.FAILED);
|
||||
|
||||
Object authCode = notif.raw.get("Ds_AuthorisationCode");
|
||||
|
||||
Reference in New Issue
Block a user