$uri = "https://branchbusinessadvance.co.ke/payments/callback/confirmation/"
$headers = @{
    "Content-Type" = "application/json"
}
$body = @{
    TransID = "TEST123"
    TransAmount = 100
    BusinessShortCode = "4159523"
    BillRefNumber = "12345678"
    TransTime = "20251111000000"
    MSISDN = "254712345678"
} | ConvertTo-Json

Write-Host "Testing M-Pesa callback URL..." -ForegroundColor Yellow
Write-Host "URL: $uri" -ForegroundColor Cyan
Write-Host "Body: $body" -ForegroundColor Cyan

try {
    $response = Invoke-WebRequest -Uri $uri -Method POST -Headers $headers -Body $body
    Write-Host "`nSuccess!" -ForegroundColor Green
    Write-Host "Status Code: $($response.StatusCode)" -ForegroundColor Green
    Write-Host "Response:" -ForegroundColor Green
    Write-Host $response.Content
} catch {
    Write-Host "`nError!" -ForegroundColor Red
    Write-Host "Error: $_" -ForegroundColor Red
    if ($_.Exception.Response) {
        Write-Host "Status Code: $($_.Exception.Response.StatusCode.value__)" -ForegroundColor Red
    }
}
