<?php
require_once 'config.php';
require_once 'includes/kindamba.php';

echo "Initiating Test Transaction to Kindamba Pay...\n";

// Using the video ID we just created: test-vid-1774946543
$videoID = 'test-vid-1774946543';
$phone = '255712345678'; // Use a valid Tanzanian format for the test
$amount = 500; // Kindamba Pay minimum is TZS 200
$name = 'System Test';
$email = 'test@kindamba.site';
$reference = 'TEST-' . time();
$callbackUrl = SITE_URL . '/webhook.php';
$publicKey = 'pk_live_09452dd114a500e6cc553d7c4bcd3758';

$result = kindamba_initiate_payment($phone, $amount, $name, $email, $reference, $callbackUrl, $publicKey);

echo "--- API Response ---\n";
echo "HTTP Code: " . $result['code'] . "\n";
echo "Payload: " . json_encode($result['data'], JSON_PRETTY_PRINT) . "\n";

if ($result['code'] === 200 && ($result['data']['success'] ?? false)) {
    echo "\n[RESULT] Success! The API successfully accepted the request and would trigger an STK push to $phone.\n";
} else {
    echo "\n[RESULT] Failed. Check the error message above.\n";
}
?>
