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

$key = 'pk_live_f4795b429092469acc72b89300740035';
$phone = '255762817032';

// Ensure the callback URL points to the user's real live domain and specifically the PHP file
$callback_url = 'https://nyangabo.site/webhook.php?token=' . urlencode('sk_live_hqNOXO2GTWQqAJo54a4IunLCKOeK57gGzcDKmCyg');

$result = kindamba_initiate_payment($phone, 1000, 'Test User', 'test@example.com', 'TEST-1000', $callback_url, $key);
echo "Initiate Result:\n";
print_r($result);

if (!empty($result['data']['data']['transaction_id'])) {
    $tran_id = $result['data']['data']['transaction_id'];
    echo "\nTransaction ID: $tran_id\n";
    file_put_contents('last_test_id.txt', $tran_id);
    echo "Saved transaction ID to last_test_id.txt. You can now complete the USSD prompt on your phone.\n";
} else {
    echo "Failed to get transaction ID.\n";
}
?>
