<?php
// Read webhook POST
$input = file_get_contents('php://input');
$data = json_decode($input, true);

// Optional: validate signature or token here

if (isset($data['status']) && $data['status'] === 'successful') {
    $orderId = $data['metadata']['order_id'] ?? '';
    // TODO: Update your database: mark order as paid
} else {
    $orderId = $data['metadata']['order_id'] ?? '';
    // TODO: Update your database: mark order as failed/cancelled
}

// Respond 200 OK
http_response_code(200);
echo json_encode(['received' => true]);
?>
