def getTransactionNumber(cookies: dict, session_id: str) -> str: headers = { 'authority': 'secure.newegg.com', 'accept': 'application/json, text/plain, */*', 'x-sessionid': session_id, 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57', 'content-type': 'application/json', 'origin': 'https://secure.newegg.com', 'sec-fetch-site': 'same-origin', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty', 'referer': 'https://secure.newegg.com/shop/checkout?sessionId=' + session_id, 'accept-language': 'en-US,en;q=0.9' } data = '{"SessionID":"' + session_id + '","Actions":[{"ActionType":"AlterPanelStatus","JsonContent":"{\\"ActionType\\":\\"AlterPanelStatus\\",\\"PanelStatus\\":{\\"ShippingAddress\\":\\"Done\\",\\"DeliveryMethod\\":\\"Done\\",\\"TaxID\\":\\"Done\\",\\"Payment\\":\\"Todo\\"}}"}],"EnableAsyncToken":true}' responseObj = requests.post('https://secure.newegg.com/shop/api/InitOrderReviewApi', headers=headers, cookies=cookies, data=data) if responseObj.status_code != 200: printFail("ERROR GETTING TRANSACTION NUMBER, TRYING AGAIN") return getTransactionNumber(cookies, session_id) else: colors.printInfo("GOT TRANSACTION NUMBER") try: return str(responseObj.json()['PaymentOption']['CreditCardList'][0]['TransactionNumber']) except: colors.printFail("ERROR GETTING TRANSACTION NUMBER, PLEASE RUN THE GENCOOKIE UTILITY!!!") return None
def inStock(s_id: str, price: float) -> bool: url = 'https://www.newegg.com/product/api/ProductRealtime?ItemNumber=' + s_id try: r = requests.get(url) except: colors.printFail('Failed to make request to instock API, trying again...') return inStock(s_id, price) if r.status_code == 200: try: j = r.json() inStock = j['MainItem']['Instock'] acceptPrice = j['MainItem']['FinalPrice'] <= price if inStock and acceptPrice: colors.printSuccess('ITEM IN STOCK FOR GOOD PRICE!!!') elif inStock and not acceptPrice: colors.printFail('Item in stock, price too high...') else: colors.printInfo('Item not in stock...') return inStock and acceptPrice except: colors.printFail('Invalid response, IP block?') return False else: colors.printFail('Unsuccessful request made, IP block?') return False
def getCurrIp() -> str: r = requests.get('https://api.ipify.org?format=json') if r.status_code != 200: colors.printFail('Failed to detect IP address, retrying...') time.sleep(1) return getCurrIp() else: colors.printInfo('detected IP: ' + r.json()['ip']) return r.text
def addToCart(p_id: str, cookies: dict) -> bool: try: add = requests.get('https://secure.newegg.com/Shopping/AddtoCart.aspx?Submit=ADD&ItemList=' + p_id, cookies=cookies) except: colors.printFail("Failed to add to cart, IP block?") time.sleep(2) return addToCart(p_id, cookies) if p_id not in add.url: #fail colors.printFail("Couldn't add to cart, retrying in 1 sec") time.sleep(2) return addToCart(p_id, cookies) else: colors.printInfo("Added to cart") return True
def testCookies() -> bool: cookies = loadCookies() config = configparser.ConfigParser() config.read('config.ini') product_id = config['ALWAYSWORKS']['primaryId'] secondary_product_id = config['ALWAYSWORKS']['secondaryId'] cvv = config['CREDENTIALS']['cvv'] colors.printInfo('Running in always successful mode (no buying)') addToCart(product_id, cookies) transactionComplete = checkout(config, cookies, product_id, secondary_product_id, cvv, True) if not transactionComplete: colors.printFail('Need to update cookies!') else: colors.printSuccess('Cookies working...') return transactionComplete
def main(profile: str) -> None: cookies = loadCookies() transactionComplete = False config = configparser.ConfigParser() config.read('config.ini') product_id = config[profile]['primaryId'] secondary_product_id = config[profile]['secondaryId'] cvv = config['CREDENTIALS']['cvv'] test = False if profile == 'TEST': colors.printInfo('Running in test mode (no buying)') test = True while not transactionComplete: if addToCart(product_id, cookies): transactionComplete = checkout(config, cookies, product_id, secondary_product_id, cvv, test)
def switchVPN(vpn_id: str, username: str, password: str) -> None: formerIP = getCurrIp() colors.printInfo('Swapping IP address...') killVPN() newConfigFile = getConfigFileName(vpn_id) res = os.system('./vpnConnector.sh ' + newConfigFile + ' ' + username + ' ' + password) if res != 0: colors.printFail('Failed to connect to VPN. Trying again...') switchVPN(vpn_id, username, password) else: time.sleep(10) if formerIP == getCurrIp(): colors.printFail('Unsuccessful swap...trying again in 5 seconds') time.sleep(5) switchVPN(vpn_id, username, password) else: colors.printSuccess('Successful swap of IP address...')
def submitCardInfo(transactionNumber: str, cookies: dict, cvv: str, session_id: str, trans_number: str) -> bool: headers = { 'authority': 'secure.newegg.com', 'accept': 'application/json, text/plain, */*', 'x-sessionid': session_id, 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57', 'content-type': 'application/json', 'origin': 'https://secure.newegg.com', 'sec-fetch-site': 'same-origin', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty', 'referer': 'https://secure.newegg.com/shop/checkout?sessionId=' + session_id, 'accept-language': 'en-US,en;q=0.9' } data = '{"SessionID":"' + session_id + '","Actions":[{"ActionType":"ConfirmPayment","JsonContent":"{\\"ActionType\\":\\"ConfirmPayment\\",\\"Cvv2\\":\\"' + cvv + '\\",\\"TransactionNumber\\":' + trans_number + ',\\"PaytermsCode\\":\\"Discover\\"}"}],"EnableAsyncToken":true}' responseObj = requests.post('https://secure.newegg.com/shop/api/InitOrderReviewApi', headers=headers, cookies=cookies, data=data) if responseObj.status_code != 200: colors.printFail("ERROR SUBMITTING CARD INFO, TRYING AGAIN") return submitCardInfo(transactionNumber, cookies, cvv, session_id, trans_number) else: colors.printInfo("CARD INFO SUBMITTED") return True
def genSessionID(cookies: dict, s_id: str) -> str: req_url = 'https://secure.newegg.com/shop/api/CheckoutApi' headers = { 'authority': 'secure.newegg.com', 'accept': 'application/json, text/plain, */*', 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57', 'content-type': 'application/json', 'origin': 'https://secure.newegg.com', 'sec-fetch-site': 'same-origin', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty', 'referer': 'https://secure.newegg.com/shop/cart', 'accept-language': 'en-US,en;q=0.9' } data = genDataString(s_id) requestObj = requests.post(req_url, headers=headers, cookies=cookies, data=data) if requestObj.status_code != 200: colors.printFail("ERROR GENERATING SESSION ID, TRYING AGAIN") return genSessionID(cookies, s_id) else: colors.printInfo("GOT SESSION ID") return requestObj.json()['SessionID']
def checkout(config: dict, cookies: dict, p_id: str, s_id: str, cvv: str, test: bool) -> bool: sessionId = genSessionID(cookies, s_id) url = 'https://secure.newegg.com/shop/checkout?sessionId=' + sessionId transactionNumber = getTransactionNumber(cookies, sessionId) if transactionNumber == None: return False if submitCardInfo(transactionNumber, cookies, cvv, sessionId, transactionNumber): if validateAddress(config, cookies, sessionId, transactionNumber): if not test: if submit_order(cookies, sessionId): colors.printSuccess("Success! Check your inbox") return True else: colors.printInfo('session_id: ' + sessionId) colors.printInfo('transaction_number: ' + transactionNumber) return True else: return checkout(config, cookies, p_id, s_id, cvv) else: colors.printFail("Couldnt check out, retrying") return checkout(config, cookies, p_id, s_id) return True
def submit_order(cookies: dict, s_id: str) -> bool: headers = { 'authority': 'secure.newegg.com', 'accept': 'application/json, text/plain, */*', 'x-sessionid': s_id, 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57', 'content-type': 'application/json', 'origin': 'https://secure.newegg.com', 'sec-fetch-site': 'same-origin', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty', 'referer': 'https://secure.newegg.com/shop/checkout?sessionId=' + s_id, 'accept-language': 'en-US,en;q=0.9' } data = '{"SessionID":"' + s_id + '","IsAcceptNSCCAuth":false,"SubscribeNewsletterFlag":false,"CreactAccount":false,"Password":"","MobileSubscribe":{},"LanguageCode":"en-us","Cvv2":""}' response = requests.post('https://secure.newegg.com/shop/api/PlaceOrderApi', headers=headers, data=data, cookies=cookies) if response.status_code != 200: colors.printFail("FAILED TO PLACE. RETRYING...") return submit_order(cookies, s_id) else: colors.printInfo("ORDER PLACED") return True
def validateAddress(config: dict, cookies: dict, s_id: str, trans_number: str) -> bool: headers = { 'authority': 'secure.newegg.com', 'accept': 'application/json, text/plain, */*', 'x-sessionid': s_id, 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57', 'content-type': 'application/json', 'origin': 'https://secure.newegg.com', 'sec-fetch-site': 'same-origin', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty', 'referer': 'https://secure.newegg.com/shop/checkout?sessionId=' + s_id, 'accept-language': 'en-US,en;q=0.9' } data = getBillingData(config, trans_number) response = requests.post('https://secure.newegg.com/shop/api/ValidateAddress', headers=headers, data=data, cookies=cookies) if response.status_code != 200: colors.printFail("ERROR VALIDATING BILLING ADDRESS, RETRYING...") return validateAddress(config, cookies, s_id) else: colors.printInfo("BILLING ADDRESS VALIDATED") return True
colors.printFail('Item in stock, price too high...') else: colors.printInfo('Item not in stock...') return inStock and acceptPrice except: colors.printFail('Invalid response, IP block?') return False else: colors.printFail('Unsuccessful request made, IP block?') return False profile = '' if len(sys.argv) == 1: profile = 'TEST' colors.printInfo('Running in test mode...') else: profile = sys.argv[1] colors.printFail('CONFIRM YOU WANT TO RUN THE ACTUAL SCRIPT FOR CONFIG: ' + profile) input() config = configparser.ConfigParser() config.read('config.ini') secondary_product_id = config[profile]['secondaryId'] price = float(config[profile]['priceThreshold']) phoneNumber = config['CREDENTIALS']['phoneNumber'] email = config['CREDENTIALS']['email'] emailPassword = config['CREDENTIALS']['emailPassword'] server = config['CREDENTIALS']['server'] bought = False iterationsUntilCookieTest = 90 iterations = 0