# Checkout Studio & Designs

Behalten Sie Ihr Design in jedem per API erstellten Link.

## Gespeichertes Design verwenden

Erstellen und aktivieren Sie Ihr Design im Checkout Studio. Kopieren Sie seine Kennung und übergeben Sie sie beim Erstellen des Checkouts als `theme_id`.

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": 2499,
  "currency": "EUR",
  "productName": "Ma commande",
  "orderId": "ORDER-DEMO-001",
  "successUrl": "https://example.com/payment/return",
  "cancelUrl": "https://example.com/payment/cancel",
  "theme_id": "ma-boutique"
}'
```

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": 2499,
  "currency": "EUR",
  "productName": "Ma commande",
  "orderId": "ORDER-DEMO-001",
  "successUrl": "https://example.com/payment/return",
  "cancelUrl": "https://example.com/payment/cancel",
  "theme_id": "ma-boutique"
})
});
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": 2499,
  "currency": "EUR",
  "productName": "Ma commande",
  "orderId": "ORDER-DEMO-001",
  "successUrl": "https://example.com/payment/return",
  "cancelUrl": "https://example.com/payment/cancel",
  "theme_id": "ma-boutique"
}',
]);
$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': 2499, 'currency': 'EUR', 'productName': 'Ma commande', 'orderId': 'ORDER-DEMO-001', 'successUrl': 'https://example.com/payment/return', 'cancelUrl': 'https://example.com/payment/cancel', 'theme_id': 'ma-boutique'},
    timeout=20,
)
response.raise_for_status()
result = response.json()
if not result.get("success"):
    raise RuntimeError(result.get("error", "API request failed"))
print(result)
```

## Design für den Link bewahren

Die API prüft, ob das Design aktiv ist und Ihrem Konto gehört. Seine Konfiguration wird mit dem Link gespeichert. Eine verbindliche Markenkonfiguration Ihres Kontos kann Vorrang haben.

## Format und Fehler

| Parameter | Beschreibung | 
| --- | --- |

| `theme_id` | 1 bis 40 Zeichen: Kleinbuchstaben, Ziffern und Bindestriche. | 
| `invalid_theme_id` | Ungültiges Kennungsformat. | 
| `theme_not_found` | Design fehlt, ist inaktiv oder für dieses Konto nicht zugänglich. | 
| `conflicting_theme_id` | Die übergebenen Parameter theme_id, themeId oder template widersprechen sich. | 
| `theme_unavailable` | Das Design kann nicht geladen oder für den Link gespeichert werden. | 

**Wichtig**

Ohne `theme_id` bleibt das bisherige Verhalten Ihrer Integration erhalten. Der ältere Parameter `template` behält seine Kompatibilitätsbehandlung; für gespeicherte Designs bevorzugen Sie `theme_id`.
