<?php
// testar_webhook.php - Testar o webhook manualmente

$url = "https://w7master.com.br/emissornota/webhook_receiver.php";

// Simular notificação da Focus
$data = [
    'ref' => 'nota_1781101834518',  // Sua nota de teste
    'status' => 'autorizado',
    'numero' => '9999',
    'codigo_verificacao' => 'TESTE123',
    'url_danfse' => 'https://focusnfe.s3.amazonaws.com/teste.pdf',
    'caminho_xml_nota_fiscal' => 'https://focusnfe.s3.amazonaws.com/teste.xml',
    'data_emissao' => date('Y-m-d H:i:s')
];

echo "=== TESTANDO WEBHOOK ===\n";
echo "URL: $url\n";
echo "Dados: " . json_encode($data) . "\n\n";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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']);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

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

echo "HTTP Code: $httpCode\n";
echo "Resposta: $resposta\n";
if ($curlError) {
    echo "Curl Error: $curlError\n";
}
?>