# Transactions & statuses

Find an order and check its status server-side.

## Look up an order

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

Example · no finalized transaction
```
{
  "success": true,
  "orderId": "ORDER-DEMO-001",
  "status": "pending",
  "paid": false,
  "url": null
}
```

## Interpret the result

When a transaction exists, the response contains `transaction`, including `id`, `order_id`, `amount`, `currency` and `status`. For this lookup, `paid` is true when the status is `success`.

| Parameter | Description | 
| --- | --- |

| `success` | Payment succeeded. Also verify the reference, amount and currency. | 
| `pending` | Payment not finalized. Do not trigger fulfilment. | 
| `failed` | Attempt failed. | 
| `refunded` | Payment refunded. | 

## Other queries

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

Lookup by ID returns `transaction`. Listing returns `transactions`, limited to the latest 200 entries. The format varies with the query used.
