# Moyens de paiement

Proposez les moyens compatibles avec votre compte, votre devise et votre checkout.

## Lire la configuration du compte

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 réponse contient `methods`. Pour chaque entrée, consultez notamment `id`, `enabled`, `available`, `currencies` et `unavailableReason`. La disponibilité finale dépend également du parcours de traitement sélectionné.

## Restreindre un checkout

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

**À retenir**

Cette liste restreint les moyens autorisés ; elle ne les active pas. Une liste vide ou composée uniquement de valeurs inconnues n’est pas une manière de désactiver tous les paiements : le code de création ignore alors cette restriction.

## Exemple BLIK uniquement

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)
```

Le compte doit autoriser BLIK et le parcours retenu doit accepter PLN. Pour ajouter la carte, utilisez `["blik", "card"]`.

## Identifiants du catalogue

| Paramètre | Description | 
| --- | --- |

| `card / applepay / googlepay` | Carte et portefeuilles. Compatibilité selon votre configuration et l’appareil du client. | 
| `blik` | PLN | 
| `p24` | PLN, EUR | 
| `ideal / bancontact / eps` | EUR | 
| `twint` | CHF | 
| `multibanco / mb_way / satispay` | EUR | 
| `klarna` | Selon les devises et l’activation du compte. | 
| `sepa` | EUR · virement entrant ; ce n’est pas un prélèvement SEPA. | 
| `ach` | USD · virement entrant. | 
| `crypto` | Disponibilité, actifs et réseaux selon votre compte. | 

## Paiements avec redirection

Laissez le checkout gérer le départ vers la banque ou le prestataire et son retour. Votre boutique reçoit ensuite la confirmation serveur ; elle ne doit pas considérer un paramètre d’URL ou un retour navigateur comme une preuve de succès.
