<?php
$content = file_get_contents('fees/verify_bank_transactions.php');

// Find both occurrences of the SMS helper path
$pos1 = strpos($content, '$smsHelperPath = __DIR__ . \'/../includes/sms_helper.php\';');
$pos2 = strpos($content, '$smsHelperPath = __DIR__ . \'/../includes/sms_helper.php\';', $pos1 + 1);

if ($pos2 !== false) {
    // Find the end of the second (duplicate) section
    $sectionStart = $pos2;
    
    // Find the corresponding closing braces and catch block
    // The duplicate section ends with a catch block
    $catchPos = strpos($content, '            } catch (Throwable $e) {', $sectionStart);
    if ($catchPos !== false) {
        // Find the end of this catch block (two closing braces)
        $brace1 = strpos($content, '            }', $catchPos);
        if ($brace1 !== false) {
            $brace2 = strpos($content, '            }', $brace1 + 1);
            if ($brace2 !== false) {
                // The section goes from $sectionStart to $brace2 + 1 (to include the final })
                $sectionLength = $brace2 + 1 - $sectionStart;
                $duplicateSection = substr($content, $sectionStart, $sectionLength);
                
                echo "Found duplicate section of length: " . strlen($duplicateSection) . "\n";
                
                // Remove the duplicate section
                $newContent = substr_replace($content, '', $sectionStart, $sectionLength);
                file_put_contents('fees/verify_bank_transactions.php', $newContent);
                
                echo "Duplicate section removed successfully.\n";
            } else {
                echo "Could not find the end of the duplicate section.\n";
            }
        } else {
            echo "Could not find the end of the duplicate section.\n";
        }
    } else {
        echo "Could not find the catch block for the duplicate section.\n";
    }
} else {
    echo "No duplicate section found.\n";
}
?>