# Opzioni sviluppatore

Le opzioni sviluppatore contengono:

- la configurazione del **webhook** su cui JataPay invia le notifiche di evento (pagamento eseguito, dilazione attivata, abbonamento concluso) e il segreto con cui sono firmate;
- la configurazione dell'**autorizzazione con client assertion** (`jwks_uri`), alternativa all'autenticazione con `client_secret`.

La stessa configurazione è modificabile dalla Dashboard nella sezione **[Sviluppatori](https://dashboard.jatapay.it/sviluppatori)**.

## Leggere le opzioni

### Richiesta Http

```bash
GET https://api.jatapay.it/esercente/developer_options
```

:::info
Ruoli autorizzati: `esercente`
:::

**shell**

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

**PHP**

```php
$token = 'IL_TOKEN_DI_ACCESSO';

$url = curl_init("https://api.jatapay.it/esercente/developer_options");
$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/esercente/developer_options", 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/esercente/developer_options', {
  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/esercente/developer_options", 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/esercente/developer_options");

        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/esercente/developer_options"))
                .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 contiene la configurazione attualmente salvata.

```json
{
  "webhook": {
    "enabled": true,
    "url": "https://sandbox.jatapay.it/fake_webhook",
    "webhook_secret": "0d82061536585378f638b3331a0439767a2b3fda8eaa952f7da153c8f2dfbb72"
  },
  "authorization": {
    "enable_client_assertion": true,
    "jwks_uri": "https://e-commerce.example.com/.well-known/jwks.json"
  }
}
```

### Oggetto `webhook`

| Campo | Tipo |  Descrizione |
| -------------- | -------------- |-------------- |
| enabled   | boolean |  Indica se l'invio delle notifiche è attivo   |
| url   | string |  L'URL a cui vengono inviate le notifiche   |
| webhook_secret   | string |  Il segreto con cui è firmata ogni notifica (HMAC-SHA256); vedi [Webhook](/riferimento-api/opzioni-sviluppatore/webhook)   |

### Oggetto `authorization`

| Campo | Tipo |  Descrizione |
| -------------- | -------------- |-------------- |
| enable_client_assertion   | boolean |  Indica se l'autenticazione con client assertion è abilitata   |
| jwks_uri   | string |  L'URL del JWKS con la chiave pubblica usata per validare le client assertion; vedi [Autenticazione](/Autenticazione)   |

### 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"
}
```

## Aggiornare le opzioni

### Richiesta Http

```bash
POST https://api.jatapay.it/esercente/developer_options
```

:::info
Ruoli autorizzati: `esercente`
:::

### Parametri del corpo

| Parametro | Richiesto | Tipo |  Descrizione |
| -------------- | -------------- | -------------- |-------------- |
| webhook   | No |  object  |  Configurazione del webhook (vedi sotto)   |
| authorization   | No |  object  |  Configurazione dell'autorizzazione con client assertion (vedi sotto)   |

### Oggetto `webhook`

| Parametro | Richiesto | Tipo |  Descrizione |
| -------------- | -------------- | -------------- |-------------- |
| url   | Sì |  string  |  URL a cui inviare le notifiche (raggiungibile in HTTPS)   |
| enabled   | No |  boolean  |  Abilita o disabilita l'invio delle notifiche   |

### Oggetto `authorization`

| Parametro | Richiesto | Tipo |  Descrizione |
| -------------- | -------------- | -------------- |-------------- |
| enable_client_assertion   | No |  boolean  |  Abilita l'autenticazione con client assertion (JWT firmato) oltre a `client_secret`   |
| jwks_uri   | No |  string  |  URL del JWKS con la chiave pubblica usata per validare le client assertion   |

**shell**

```bash
curl -X POST "https://api.jatapay.it/esercente/developer_options" \
  -H "Authorization: Bearer IL_TOKEN_DI_ACCESSO" \
  -H "Content-Type: application/json" \
  -d '{
  "webhook": {
    "url": "https://e-commerce.example.com/webhook",
    "enabled": true
  },
  "authorization": {
    "enable_client_assertion": true,
    "jwks_uri": "https://e-commerce.example.com/.well-known/jwks.json"
  }
}'
```

**PHP**

```php
$token = 'IL_TOKEN_DI_ACCESSO';

$body = array(
    'webhook' => array(
        'url' => 'https://e-commerce.example.com/webhook',
        'enabled' => true
    ),
    'authorization' => array(
        'enable_client_assertion' => true,
        'jwks_uri' => 'https://e-commerce.example.com/.well-known/jwks.json'
    )
);

$url = curl_init("https://api.jatapay.it/esercente/developer_options");
$authorization = "Authorization: Bearer ".$token;
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($url, CURLOPT_POSTFIELDS, json_encode($body));
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($url, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen(json_encode($body)),
    $authorization
));

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

**Python**

```python
import requests

token = "IL_TOKEN_DI_ACCESSO"

body = {
    "webhook": {
        "url": "https://e-commerce.example.com/webhook",
        "enabled": True
    },
    "authorization": {
        "enable_client_assertion": True,
        "jwks_uri": "https://e-commerce.example.com/.well-known/jwks.json"
    }
}

headers = {
    "Authorization": "Bearer " + token,
    "Content-Type": "application/json"
}

response = requests.post("https://api.jatapay.it/esercente/developer_options", headers=headers, json=body)

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

**Node.js**

```javascript
const token = 'IL_TOKEN_DI_ACCESSO';

const body = {
  webhook: {
    url: 'https://e-commerce.example.com/webhook',
    enabled: true
  },
  authorization: {
    enable_client_assertion: true,
    jwks_uri: 'https://e-commerce.example.com/.well-known/jwks.json'
  }
};

const response = await fetch('https://api.jatapay.it/esercente/developer_options', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(body)
});

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

**Go**

```go
package main

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

func main() {
	const token = "IL_TOKEN_DI_ACCESSO"
	body := `{
  "webhook": {
    "url": "https://e-commerce.example.com/webhook",
    "enabled": true
  },
  "authorization": {
    "enable_client_assertion": true,
    "jwks_uri": "https://e-commerce.example.com/.well-known/jwks.json"
  }
}`

	req, err := http.NewRequest("POST", "https://api.jatapay.it/esercente/developer_options", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+token)
	req.Header.Set("Content-Type", "application/json")

	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.Text;
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 body = """
            {
              "webhook": {
                "url": "https://e-commerce.example.com/webhook",
                "enabled": true
              },
              "authorization": {
                "enable_client_assertion": true,
                "jwks_uri": "https://e-commerce.example.com/.well-known/jwks.json"
              }
            }
            """;

        var content = new StringContent(body, Encoding.UTF8, "application/json");
        var response = await client.PostAsync("https://api.jatapay.it/esercente/developer_options", content);

        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";

        String body = """
                {
                  "webhook": {
                    "url": "https://e-commerce.example.com/webhook",
                    "enabled": true
                  },
                  "authorization": {
                    "enable_client_assertion": true,
                    "jwks_uri": "https://e-commerce.example.com/.well-known/jwks.json"
                  }
                }
                """;

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.jatapay.it/esercente/developer_options"))
                .header("Authorization", "Bearer " + token)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(body))
                .build();

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

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

### Risposta

La risposta contiene la configurazione salvata.

```json
{
  "webhook": {
    "enabled": true,
    "url": "https://sandbox.jatapay.it/fake_webhook",
    "webhook_secret": "0d82061536585378f638b3331a0439767a2b3fda8eaa952f7da153c8f2dfbb72"
  },
  "authorization": {
    "enable_client_assertion": true,
    "jwks_uri": "https://e-commerce.example.com/.well-known/jwks.json"
  }
}
```

### Oggetto `webhook`

| Campo | Tipo |  Descrizione |
| -------------- | -------------- |-------------- |
| enabled   | boolean |  Indica se l'invio delle notifiche è attivo   |
| url   | string |  L'URL a cui vengono inviate le notifiche   |
| webhook_secret   | string |  Il segreto con cui è firmata ogni notifica (HMAC-SHA256); vedi [Webhook](/riferimento-api/opzioni-sviluppatore/webhook)   |

### Oggetto `authorization`

| Campo | Tipo |  Descrizione |
| -------------- | -------------- |-------------- |
| enable_client_assertion   | boolean |  Indica se l'autenticazione con client assertion è abilitata   |
| jwks_uri   | string |  L'URL del JWKS con la chiave pubblica usata per validare le client assertion; vedi [Autenticazione](/Autenticazione)   |

### 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`.
:::
