<?php
$payload = '{"event":"charge.success","data":{"reference":"loan_lr_3_123","amount":5000}}';
$secret = 'PAYSTACK_SECRET_KEY_PLACEHOLDER';
$sig = hash_hmac('sha512', $payload, $secret);
$url = 'http://localhost:8000/payment/webhook/paystack';

$ch = curl_init($url);
if (!$ch) {
    echo "Failed to initialize curl\n";
    exit(1);
}

curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'X-Paystack-Signature: ' . $sig,
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);
$error = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "HTTP_CODE={$httpCode}\n";
if ($error) {
    echo "ERROR={$error}\n";
}
echo "RESPONSE={$response}\n";
