# Refunds and Inquiries Endpoints

This reference details the endpoints used for searching transaction history and processing refunds (both referenced and card-present).

## 1. Query Transactions (`/consulta`)

Retrieves the status and details of past operations.

* **URL (Test):** `https://tpvpc-i.redsys.es:27443/TPV_PC/services/rest/tpvpcwss/v1/consulta`  
* **URL (Prod):** `https://tpvpc.redsys.es/TPV_PC/services/rest/tpvpcwss/v1/consulta`  
* **Method:** `POST`

### Request Parameters (`datosOperacion`)

| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| `fechaInicio` | String | Yes | Start date (`YYYY-MM-DD HH:mm:ss` or `YYYY-MM-DD-HH.mm.ss`). |
| `fechaFin` | String | Yes | End date. Max range is 30 days from start date. |
| `pedido` | String | No | Search by system Order ID. |
| `factura` | String | No | Search by your Invoice Reference. |
| `operacion` | String | No | Filter by type: `PAGO`, `PREAUTORIZACION`, `CONFIRMACION`, `DEVOLUCION`. |
| `resultado` | String | No | Filter by result: `AUTORIZADA`, `DENEGADA`. |
| `rts` | String | No | Search by Transaction ID. Overrides all other filters. |
| `pagina` | Int | No | Page number for pagination (starts at 0). |

### Response (resultadoConsulta)

| Field | Type | Description |
| :--- | :--- | :--- |
| `numOperaciones` | Int | Total records found. |
| `totalPaginas` | Int | Total pages available. |
| `operaciones` | Array | List of transaction objects containing `importe`, `estado`, `resultado`, etc. |

## 2. Referenced Refund (`/devolucion`)

Refunds a transaction using its Order ID (pedidoBase) without card interaction.

* **URL (Test):** `https://tpvpc-i.redsys.es:27443/TPV_PC/services/rest/tpvpcwss/v1/devolucion`  
* **URL (Prod):** `https://tpvpc.redsys.es/TPV_PC/services/rest/tpvpcwss/v1/devolucion`  
* **Method:** `POST`

### Request Parameters (`datosOperacion`)

| Field | Type | Required | Max Length | Description |
| :--- | :--- | :--- | :--- | :--- |
| `importe` | Double | Yes | 12 | Amount to refund. |
| `factura` | String | Yes | 250 | Reference for the refund itself. |
| `pedidoBase` | String | Yes | 50 | The `pedido` (Order ID) of the original sale. |

### Response (`resultadoDevolucion`)

Returned only if `resultado.codigo` is `0`.

| Field | Type | Description |
| :---- | :---- | :---- |
| `importe` | String | Amount refunded. |
| `resultado` | String | `Autorizada` or `Denegada`. |
| `estado` | String | `F` (Finalized). |

## 3. Card-Present Refund (`/devolucionTarjeta`)

Initiates a refund requiring the customer to insert their card.

* **URL (Test):** `https://tpvpc-i.redsys.es:27443/TPV_PC/services/rest/tpvpcwss/v1/devolucionTarjeta` 
* **URL (Prod):** `https://tpvpc.redsys.es/TPV_PC/services/rest/tpvpcwss/v1/devolucionTarjeta`  
* **Method:** `POST`

### Request Parameters (`datosOperacion`)

| Field | Type | Required | Max Length | Description |
| :---- | :---- | :---- | :---- | :---- |
| `importe` | Double | Yes | 12 | Amount to refund. |
| `factura` | String | Yes | 250 | Reference for the refund. |
| `pedidoBase` | String | Yes | 50 | The `pedido` (Order ID) of the original sale. |

### Response (`info`)

Synchronous acknowledgment. Final result sent via notification.

| Field | Type | Description |
| :---- | :---- | :---- |
| `resultado.codigo` | String | `0` indicates success. |