<?php
/**
 * Test POST request to verify-payment endpoint
 */
require_once 'config/database.php';
require_once 'config/uddoktapay.php';

echo "Testing POST request to /verify-payment endpoint...\n\n";

$base_url = 'https://ashof.paymently.io/api';
$endpoint = '/verify-payment';
$url = rtrim($base_url, '/') . '/' . ltrim($endpoint, '/');

echo "URL: " . $url . "\n";

// Test data
$test_data = [
    'invoice_id' => 'INV-TEST-12345'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Accept: application/json'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($test_data));

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

curl_close($ch);

echo "HTTP Code: " . $httpCode . "\n";
echo "Content-Type: " . ($contentType ?: 'None') . "\n";
echo "Error: " . ($error ?: 'None') . "\n";
echo "Response: " . substr($response, 0, 500) . "\n";

if ($response) {
    $decoded = json_decode($response, true);
    if ($decoded) {
        echo "Decoded Response:\n";
        echo json_encode($decoded, JSON_PRETTY_PRINT) . "\n";
    } else {
        echo "Failed to decode JSON response\n";
    }
}

echo "\nTest complete.\n";
?>