# Transactions & statuts

Retrouvez une commande et contrôlez son statut côté serveur.

## Rechercher une commande

GET`/transactions.php?order_id=ORDER-DEMO-001`

Terminal
```
curl "https://circus-pay.com/api/transactions.php?order_id=ORDER-DEMO-001" \
  -H "Authorization: Bearer $CIRCUSPAY_SECRET_KEY"
```

JavaScript
```
const response = await fetch("https://circus-pay.com/api/transactions.php?order_id=ORDER-DEMO-001", {
  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/transactions.php?order_id=ORDER-DEMO-001");
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/transactions.php?order_id=ORDER-DEMO-001",
    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)
```

Exemple · aucune transaction finalisée
```
{
  "success": true,
  "orderId": "ORDER-DEMO-001",
  "status": "pending",
  "paid": false,
  "url": null
}
```

## Interpréter le résultat

Quand une transaction existe, la réponse contient `transaction` avec notamment `id`, `order_id`, `amount`, `currency` et `status`. Pour cette recherche, `paid` est vrai si le statut est `success`.

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

| `success` | Paiement réussi. Vérifiez également la référence, le montant et la devise. | 
| `pending` | Paiement non finalisé. Ne déclenchez pas la livraison. | 
| `failed` | Tentative échouée. | 
| `refunded` | Paiement remboursé. | 

## Autres lectures

Endpoints
```
GET /transactions.php?id=123
GET /transactions.php
```

La lecture par ID renvoie `transaction`. La liste renvoie `transactions`, limitée aux 200 entrées les plus récentes. Le format varie selon la recherche utilisée.
