trabajando en devoluciones

This commit is contained in:
2025-11-05 15:09:26 +01:00
parent ed32f773a4
commit a4443763d8
13 changed files with 330 additions and 124 deletions

View File

@ -20,6 +20,8 @@ safekat.api.password=Safekat2024
# Configuración Redsys
redsys.environment=test
redsys.url=https://sis-t.redsys.es:25443/sis/realizarPago
redsys.refund.url=https://sis-t.redsys.es:25443/sis/rest/trataPeticionREST
redsys.urls.ok=http://localhost:8080/pagos/redsys/ok
redsys.urls.ko=http://localhost:8080/pagos/redsys/ko
redsys.urls.notify=https://orological-sacrilegiously-lucille.ngrok-free.dev/pagos/redsys/notify

View File

@ -20,6 +20,8 @@ safekat.api.password=Safekat2024
# Configuración Redsys
redsys.environment=test
redsys.url=https://sis-t.redsys.es:25443/sis/realizarPago
redsys.refund.url=https://sis-t.redsys.es:25443/sis/rest/trataPeticionREST
redsys.urls.ok=https://imprimelibros.jjimenez.eu/pagos/redsys/ok
redsys.urls.ko=https://imprimelibros.jjimenez.eu/pagos/redsys/ko
redsys.urls.notify=https://imprimelibros.jjimenez.eu/pagos/redsys/notify

View File

@ -0,0 +1,15 @@
databaseChangeLog:
- changeSet:
id: 0009-add-composite-unique-txid-type
author: JJO
changes:
# 1⃣ Eliminar el índice único anterior
- dropUniqueConstraint:
constraintName: uq_tx_gateway_txid
tableName: payment_transactions
# 2⃣ Crear índice único compuesto por gateway_transaction_id + type
- addUniqueConstraint:
tableName: payment_transactions
columnNames: gateway_transaction_id, type
constraintName: uq_tx_gateway_txid_type

View File

@ -14,4 +14,6 @@ databaseChangeLog:
- include:
file: db/changelog/changesets/0007-payments-core.yml
- include:
file: db/changelog/changesets/0008-update-cart-status-constraint.yml
file: db/changelog/changesets/0008-update-cart-status-constraint.yml
- include:
file: db/changelog/changesets/0009-add-composite-unique-txid-type.yml

View File

@ -7,6 +7,7 @@ pagos.table.cliente.nombre=Nombre Cliente
pagos.table.redsys.id=Cod. Redsys
pagos.table.pedido.id=Pedido
pagos.table.cantidad=Cantidad
pagos.table.devuelto=Devolución
pagos.table.fecha=Fecha
pagos.table.estado=Estado
pagos.table.acciones=Acciones

View File

@ -23,9 +23,10 @@ $(() => {
serverSide: true,
orderCellsTop: true,
pageLength: 50,
lengthMenu: [10, 25, 50, 100, 500],
language: { url: '/assets/libs/datatables/i18n/' + language + '.json' },
responsive: true,
dom: 'lrBtip',
dom: 'lBrtip',
buttons: {
dom: {
button: {
@ -45,16 +46,66 @@ $(() => {
url: '/pagos/datatable/redsys',
method: 'GET',
},
order: [[4, 'asc']], // Ordena por fecha por defecto
order: [[5, 'desc']], // Ordena por fecha por defecto
columns: [
{ data: 'client', name: 'user.fullName', orderable: true },
{ data: 'gateway_order_id', name: 'payments.gateway_order_id', orderable: true },
{ data: 'orderId', name: 'order.id', orderable: true },
{ data: 'amount_cents', name: 'amount_cents', orderable: true },
{ data: 'created_at', name: 'created_at', orderable: true },
{ data: 'actions', name: 'actions' }
{ data: 'client', name: 'client', orderable: true },
{ data: 'gateway_order_id', name: 'payment.gatewayOrderId', orderable: true },
{ data: 'orderId', name: 'payment.orderId', orderable: true },
{ data: 'amount_cents', name: 'amountCents', orderable: true },
{ data: 'amount_cents_refund', name: 'amountCentsRefund', orderable: true },
{ data: 'created_at', name: 'createdAt', orderable: true },
{ data: 'actions', name: 'actions', orderable: false, searchable: false }
],
columnDefs: [{ targets: -1, orderable: false, searchable: false }]
});
})
// Fila de filtros = segunda fila del thead (index 1)
$('#pagos-redsys-datatable thead tr:eq(1) th').each(function (colIdx) {
const input = $(this).find('input');
if (input.length === 0) return; // columnas sin filtro
input.on('keyup change', function () {
const value = this.value;
if (table.column(colIdx).search() !== value) {
table.column(colIdx).search(value).draw();
}
});
});
$(document).on('click', '.btn-refund-payment', function () {
const dsOrderId = $(this).data('dsorderid');
const transactionId = $(this).data('transactionid');
// show swal confirmation with input for amount to refund
Swal.fire({
title: '¿Estás seguro de que deseas devolver este pago?',
text: 'Introduce la cantidad a devolver (en euros):',
input: 'number',
inputAttributes: {
min: 0,
}
}).then((result) => {
if (result.isConfirmed) {
const amountToRefund = parseFloat(result.value);
if (isNaN(amountToRefund) || amountToRefund <= 0) {
Swal.fire('Error', 'Cantidad inválida para la devolución.', 'error');
return;
}
$.ajax({
url: '/pagos/redsys/refund/' + transactionId,
method: 'POST',
data: {
amountCents: amountToRefund*100
}
}).then((response) => {
if (response.success) {
Swal.fire('Éxito', 'Pago devuelto con éxito.', 'success');
table.draw();
} else {
Swal.fire('Error', 'No se pudo procesar la devolución.', 'error');
}
});
}
});
});
});

View File

@ -8,8 +8,6 @@
<th:block layout:fragment="pagecss">
<link th:href="@{/assets/libs/datatables/dataTables.bootstrap5.min.css}" rel="stylesheet" />
</th:block>
<th:block layout:fragment="pagecss">
</th:block>
</head>
<body>
@ -68,6 +66,7 @@
</div>
<div class="tab-pane" id="arrow-transferencias" role="tabpanel">
<div></div>
<!---
<div
th:insert="~{imprimelibros/presupuestos/presupuesto-list-items/tabla-anonimos :: tabla-anonimos}">

View File

@ -6,13 +6,15 @@
<th scope="col" th:text="#{pagos.table.redsys.id}">Cliente</th>
<th scope="col" th:text="#{pagos.table.pedido.id}">Pedido</th>
<th scope="col" th:text="#{pagos.table.cantidad}">Cantidad</th>
<th scope="col" th:text="#{pagos.table.devuelto}">Devolución</th>
<th scope="col" th:text="#{pagos.table.fecha}">Fecha</th>
<th scope="col" th:text="#{pagos.table.acciones}">Acciones</th>
</tr>
<tr>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="user.fullName" /></th>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="user.fullName" /></th>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="payments.gateway_order_id" /></th>
<th><input type="text" class="form-control form-control-sm redsys-filter" /></th>
<th><input type="text" class="form-control form-control-sm redsys-filter" /></th>
<th><input type="text" class="form-control form-control-sm redsys-filter" /></th>
<th></th>
<th></th>
<th></th>
<th></th> <!-- Acciones (sin filtro) -->

View File

@ -17,7 +17,8 @@
<th scope="col" th:text="#{presupuesto.tabla.updated-at}">Actualizado el</th>
<th scope="col" th:text="#{presupuesto.tabla.acciones}">Acciones</th>
</tr>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="id" /></th>
<tr>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="id" /></th>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="titulo" /></th>
</th>
<th>
@ -48,7 +49,8 @@
<option value="colorhq" th:text="#{presupuesto.color-premium}">Color HQ</option>
</select>
</th>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="selectedTirada" /></th>
<th><input type="text" class="form-control form-control-sm presupuesto-filter"
data-col="selectedTirada" /></th>
<th><input type="text" class="form-control form-control-sm presupuesto-filter" data-col="paginas" />
</th>
<th>
@ -68,7 +70,7 @@
</th>
<th></th> <!-- Actualizado el (sin filtro) -->
<th></th> <!-- Acciones (sin filtro) -->
</tr>
</tr>
</thead>
<tbody>
</tbody>