<?php
// paystack_webhook.php - For automatic payment confirmation
require_once '../connection.php';

// Get Paystack signature
$signature = $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] ?? '';
$payload = file_get_contents('php://input');

// Verify signature
if ($signature !== hash_hmac('sha512', $payload, $paystack_config['secret_key'])) {
    http_response_code(401);
    exit();
}

$event = json_decode($payload, true);

if ($event['event'] === 'charge.success') {
    $reference = $event['data']['reference'];
    $amount = $event['data']['amount'] / 100;
    
    // Process the subscription (similar to verify_payment.php)
    // ... (same logic as verify_payment.php)
}

http_response_code(200);
?>