php/examples/quickstart.php
Stefan Schmidt-Egermann 5c9669a688
feat: initial php content (v0.1.0)
- Composer-Package, PSR-4-Autoload
- Client mit Sync, Async (mit Polling), Webhook, Verify, Download
- PHP 8.1+ mit readonly-Properties
- Webhook-Signatur-Verifikation (hash_equals)
- PHPUnit-Tests
2026-04-25 12:26:06 +02:00

63 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
/**
* hightrusted CAPTURE — PHP Quickstart
*
* Voraussetzung:
* composer require hightrusted/capture
*
* API-Key holen:
* https://capture.hightrusted.net/dashboard/api-keys
*/
require __DIR__.'/../vendor/autoload.php';
use Hightrusted\Capture\Client;
use Hightrusted\Capture\RateLimitedException;
$client = new Client(['api_key' => getenv('HIGHTRUSTED_API_KEY')]);
// ──────────────────────────────────────────────────────────────────
// 1. Synchrone Capture
// ──────────────────────────────────────────────────────────────────
echo "→ Erstelle Capture (synchron)...\n";
$capture = $client->capture([
'url' => 'https://example.com',
'reference' => 'quickstart-demo',
'viewport' => ['width' => 1920, 'height' => 1080],
]);
echo " ID: {$capture['id']}\n";
echo " Status: {$capture['status']}\n";
echo " Verify-URL: {$capture['verify_url']}\n";
echo " Zeitstempel: {$capture['timestamp']['issued_at']}\n";
// ──────────────────────────────────────────────────────────────────
// 2. Verifikation (kostenlos)
// ──────────────────────────────────────────────────────────────────
echo "\n→ Verifiziere die Capture...\n";
$result = $client->verify(source: $capture['id']);
echo " Gültig: ".($result['valid'] ? 'true' : 'false')."\n";
// ──────────────────────────────────────────────────────────────────
// 3. PDF herunterladen
// ──────────────────────────────────────────────────────────────────
echo "\n→ Lade PDF herunter...\n";
$path = $client->downloadPdf(
$capture['id'],
'./capture_'.substr($capture['id'], 0, 8).'.pdf',
);
echo " Gespeichert: {$path}\n";
// ──────────────────────────────────────────────────────────────────
// 4. Quota
// ──────────────────────────────────────────────────────────────────
echo "\n→ Quota-Status...\n";
try {
$usage = $client->usage();
echo " Plan: {$usage['plan']}\n";
echo " Verbraucht: {$usage['used_calls']}/{$usage['included_calls']}\n";
} catch (RateLimitedException $e) {
echo " Rate-limited, retry in {$e->retryAfterSeconds}s\n";
}