# Metodi di pagamento

Proponi metodi compatibili con account, valuta e checkout.

## Leggere la configurazione dell’account

GET`/payment-methods.php`

Terminal
```
curl "https://circus-pay.com/api/payment-methods.php" \
  -H "Authorization: Bearer $CIRCUSPAY_SECRET_KEY"
```

JavaScript
```
const response = await fetch("https://circus-pay.com/api/payment-methods.php", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.CIRCUSPAY_SECRET_KEY}`
  }
});
const result = await response.json();
if (!response.ok || !result.success) {
  throw new Error(result.error || "API request failed");
}
console.log(result);
```

PHP
```
<?php
$ch = curl_init("https://circus-pay.com/api/payment-methods.php");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 20,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("CIRCUSPAY_SECRET_KEY"),
    "Content-Type: application/json",
  ],
]);
$raw = curl_exec($ch);
if ($raw === false) { throw new RuntimeException(curl_error($ch)); }
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
if ($status >= 400 || empty($result["success"])) {
  throw new RuntimeException($result["error"] ?? "API request failed");
}
```

Python
```
import os, requests

response = requests.get(
    "https://circus-pay.com/api/payment-methods.php",
    headers={"Authorization": "Bearer " + os.environ["CIRCUSPAY_SECRET_KEY"]},
    timeout=20,
)
response.raise_for_status()
result = response.json()
if not result.get("success"):
    raise RuntimeError(result.get("error", "API request failed"))
print(result)
```

La risposta contiene `methods`. Per ogni voce consulta `id`, `enabled`, `available`, `currencies` e `unavailableReason`. La disponibilità finale dipende anche dal flusso di elaborazione selezionato.

## Limitare un checkout

JSON
```
{
  "paymentMethods": ["card", "blik"]
}
```

**Da ricordare**

L’elenco limita i metodi autorizzati; non li attiva. Un elenco vuoto o con soli valori sconosciuti non disabilita tutti i pagamenti: la creazione ignora questa restrizione.

## Esempio solo BLIK

POST`/checkout/create.php`

Terminal
```
curl "https://circus-pay.com/api/checkout/create.php" \
  -H "Authorization: Bearer $CIRCUSPAY_SECRET_KEY" \
  -H "Content-Type: application/json" \
  --data '{
  "amount": 15000,
  "currency": "PLN",
  "productName": "Commande BLIK",
  "orderId": "BLIK-DEMO-001",
  "paymentMethods": [
    "blik"
  ]
}'
```

JavaScript
```
const response = await fetch("https://circus-pay.com/api/checkout/create.php", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CIRCUSPAY_SECRET_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
  "amount": 15000,
  "currency": "PLN",
  "productName": "Commande BLIK",
  "orderId": "BLIK-DEMO-001",
  "paymentMethods": [
    "blik"
  ]
})
});
const result = await response.json();
if (!response.ok || !result.success) {
  throw new Error(result.error || "API request failed");
}
console.log(result);
```

PHP
```
<?php
$ch = curl_init("https://circus-pay.com/api/checkout/create.php");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 20,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("CIRCUSPAY_SECRET_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => '{
  "amount": 15000,
  "currency": "PLN",
  "productName": "Commande BLIK",
  "orderId": "BLIK-DEMO-001",
  "paymentMethods": [
    "blik"
  ]
}',
]);
$raw = curl_exec($ch);
if ($raw === false) { throw new RuntimeException(curl_error($ch)); }
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
if ($status >= 400 || empty($result["success"])) {
  throw new RuntimeException($result["error"] ?? "API request failed");
}
```

Python
```
import os, requests

response = requests.post(
    "https://circus-pay.com/api/checkout/create.php",
    headers={"Authorization": "Bearer " + os.environ["CIRCUSPAY_SECRET_KEY"]},
    json={'amount': 15000, 'currency': 'PLN', 'productName': 'Commande BLIK', 'orderId': 'BLIK-DEMO-001', 'paymentMethods': ['blik']},
    timeout=20,
)
response.raise_for_status()
result = response.json()
if not result.get("success"):
    raise RuntimeError(result.get("error", "API request failed"))
print(result)
```

L’account deve consentire BLIK e il flusso selezionato deve supportare PLN. Per aggiungere le carte, usa `["blik", "card"]`.

## Identificativi del catalogo

| Parametro | Descrizione | 
| --- | --- |

| `card / applepay / googlepay` | Carte e wallet. Compatibilità secondo configurazione e dispositivo del cliente. | 
| `blik` | PLN | 
| `p24` | PLN, EUR | 
| `ideal / bancontact / eps` | EUR | 
| `twint` | CHF | 
| `multibanco / mb_way / satispay` | EUR | 
| `klarna` | Secondo valute e attivazione dell’account. | 
| `sepa` | EUR · bonifico in entrata; non è un addebito diretto SEPA. | 
| `ach` | USD · bonifico in entrata. | 
| `crypto` | Disponibilità, asset e reti secondo l’account. | 

## Pagamenti con reindirizzamento

Lascia che il checkout gestisca il passaggio alla banca o al fornitore e il ritorno. Il negozio riceve poi la conferma del server; un parametro URL o il ritorno del browser non dimostrano il successo.
