# Dettaglio pagamento

Ritorna i dati del pagamento indicato: tipo, importo, numero della rata, stato, metodo di pagamento, esito dei tentativi e riferimenti a cliente ed esercente.
L'identificativo si ottiene dall'endpoint [Elenco pagamenti](/riferimento-api/pagamenti/elenco-pagamenti).

## Richiesta Http

```bash
GET https://api.jatapay.it/pagamenti/ID_PAGAMENTO
```

## Parametri di percorso

| Parametro | Richiesto | Tipo |  Descrizione |
| -------------- | -------------- | -------------- |-------------- |
| id_pagamento   | Sì |  string  |  Identificativo del pagamento (`_id` restituito dall'elenco)   |

**shell**

```bash
curl -X GET "https://api.jatapay.it/pagamenti/ID_PAGAMENTO" \
  -H "Authorization: Bearer IL_TOKEN_DI_ACCESSO"
```

**PHP**

```php
$token = 'IL_TOKEN_DI_ACCESSO';

$url = curl_init("https://api.jatapay.it/pagamenti/ID_PAGAMENTO");
$authorization = "Authorization: Bearer ".$token;
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($url, CURLOPT_HTTPHEADER, array(
    $authorization
));

$result = curl_exec($url);
curl_close($url);
$api_response = json_decode($result);
```

**Python**

```python
import requests

token = "IL_TOKEN_DI_ACCESSO"

headers = {
    "Authorization": "Bearer " + token
}

response = requests.get("https://api.jatapay.it/pagamenti/ID_PAGAMENTO", headers=headers)

print(response.status_code)
print(response.json())
```

**Node.js**

```javascript
const token = 'IL_TOKEN_DI_ACCESSO';

const response = await fetch('https://api.jatapay.it/pagamenti/ID_PAGAMENTO', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${token}`
  }
});

console.log(response.status, await response.json());
```

**Go**

```go
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	const token = "IL_TOKEN_DI_ACCESSO"

	req, err := http.NewRequest("GET", "https://api.jatapay.it/pagamenti/ID_PAGAMENTO", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+token)

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	data, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(res.StatusCode, string(data))
}
```

**.NET**

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string token = "IL_TOKEN_DI_ACCESSO";

        using var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

        var response = await client.GetAsync("https://api.jatapay.it/pagamenti/ID_PAGAMENTO");

        Console.WriteLine((int)response.StatusCode);
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String token = "IL_TOKEN_DI_ACCESSO";

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.jatapay.it/pagamenti/ID_PAGAMENTO"))
                .header("Authorization", "Bearer " + token)
                .GET()
                .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
                .send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println(response.statusCode());
        System.out.println(response.body());
    }
}
```

## Risposta

La risposta è l'oggetto del pagamento, con lo schema `Pagamento` e tutti i campi del modello dati.

```json
{
  "_id": "6ae07f601d7bc659f6125dcc",
  "tipo": "rata_dilazione",
  "importo": 33333,
  "dilazione": "6ae07f601d7bc659f6125dc0",
  "numero": 12,
  "numero_txt": "12",
  "totale_rate": 12,
  "data_pagamento": "",
  "stato": "unpaid",
  "fee": {},
  "stripe": {},
  "credit_management": {
    "rating": 0
  },
  "payment_method": "card",
  "vendor": "stripe",
  "no_billing": true,
  "client": "JataPay",
  "cliente": "6a218ca738c301f9262b9017",
  "esercente": "6a55ecdfb180394de3e29aa5",
  "note": "",
  "data_fallimento": "",
  "tentativo_pagamento": 0,
  "data_controllo": "2027-09-01T03:00",
  "prossimo_tentativo": "2027-09-01T03:00",
  "base": 33333,
  "data_inserimento": "2026-10-27T10:39"
}
```

## Errori

| Codice | Descrizione |
| -------------- | -------------- |
| 400 | Richiesta non valida, parametri mancanti o non coerenti |
| 401 | Token mancante, scaduto o non valido |
| 403 | Ruolo non abilitato all'operazione |
| 500 | Errore interno del server |

Il corpo della risposta di errore contiene sempre `error_code` (il codice simbolico dell'errore, ad esempio `bad_request`, oppure il codice HTTP corrispondente) e `error_message` con il messaggio descrittivo:

```json
{
  "error_code": "bad_request",
  "error_message": "Messaggio di errore"
}
```

:::warning
La richiesta deve avere l'header `Authorization: Bearer <token>` e, quando è presente un corpo, l'header `Content-Type: application/json`.
:::
