<?php
// criar_webhook.php - Criar webhook na Focus

$token = "T6BuPKa33JP2oXtJUsTanOnl5lf3DeFl";
$ambiente = "homologacao"; // ou "producao"

$baseUrl = $ambiente == 'producao' ? 'https://api.focusnfe.com.br/v2' : 'https://homologacao.focusnfe.com.br/v2';

$data = [
    'cnpj' => '39555689000156', // CNPJ da empresa
    'event' => 'nfsen',
    'url' => 'https://w7master.com.br/emissornota/webhook_receiver.php'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/hooks');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Basic ' . base64_encode($token . ':')
]);

$resposta = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "HTTP Code: " . $httpCode . "\n";
echo "Resposta: " . $resposta . "\n";
?>