Socializing is Healthy !

Checkout My Portfolio

Dreams | Passion | Code | Love

Automation everywhere! Even for cash-backs?

Automation everywhere! Even for cash-backs?

Wondering for a good cashback offer to pay the bill of my postpaid number, I came across this good offer at PayTM. It may sound cheap at first, but on a scale, this offer stood well for me and most importantly, it was always available. This offer at PayTM promised me a total recharge of Rs. 190 for a payment of Rs. 100. Obviously, there was a trick. But I worked that out too. Let me explain how and what I did.

At the time when I wrote this post, PayTM had a promo code GET5 – which offered me a cashback of Rs. 5 on a recharge of Rs. 10. I know, it sounds so cheap, but it worked good. A user could apply this offer 10 times a day. So if I did a recharge of Rs.100 in total by splitting it into 10 transactions of Rs. 10 each, I got a total cashback of Rs. 50 by the end of the day. Now using this cashback on the next day, I could do 5 more transactions and avail the same offer.

So for a Rs. 100 spent, the calculations were like below :

  1. Rs. 10 * 10 => Cashback of Rs. 5 * 10 = 50
  2. Rs. 10 * 5 => Cashback of Rs.5 * 5 = 25
  3. Rs. 10 * 2 => Cashback of Rs.5 * 2 = 10(Rs. 5 is still left in wallet)
  4. Rs. 10 * 1 => Cashback of Rs.5 * 1 = 5
  5. Rs. 10*1(Using 5 cashback from previous transaction and 5 already in wallet) => Cashback of Rs.5 * 1 = 5

So finally, after spending Rs. 100, I got my number recharged with a total amount of Rs. 190 and I was still left with Rs. 5 in my wallet. But it had a major drawback. It was way more tedious and a lengthy process than it sounds. This is where technology came into the game. Why spend so much time on it? Why not automate it?

I thought of creating a script which could simply do all the above transactions on PayTM for me while I sit back and relax (I’m lazy !). Well I started my research on it and within 3 hours, I got what I desired for – An Automatic PayTM recharging script. Python is my favorite language and it never disappoints. I used a combo of Python along with browser automation using Selenium. I have shared the code for my script as well.

I wrote a piece of code which performs the following steps repeatedly inside a browser window.

  • Opens PayTM website and navigate to recharge section.
  • Enter the mobile number and amount for the transaction.
  • Navigate to the promo code section and apply the promo code.
  • Complete the payment.

So for my bill payments, I just had a little work to do. I just had to load my PayTM wallet with 100 rupees and execute my script. This script expected me to login to PayTM manually though, but this much of hardwork was acceptable 😀

from selenium import webdriver
import time
import random
 
print '------- Program Started -------'
print 'Opening Browser ...'
 
driver = webdriver.Firefox()
driver.get("https://www.paytm.com/recharge")
raw_input("Please login to your paytm account manually and then press enter here.")
loops = int(raw_input("Number of loops for this program = "))
 
print '------------------------------------------'
print ''
 
for i in range(0,loops):
	print 'Initiating Transaction Number : '+str(i+1)
	driver.get("https://www.paytm.com/recharge")
 
	mobile_class = driver.find_element_by_class_name("_3_cL")
	mobile_number = mobile_class.find_element_by_tag_name("input")
	mobile_number.clear()
	mobile_number.send_keys("9999999999") #mobile number.
	print '-- Waiting 20seconds for Paytm to load mobile number details --'
	time.sleep(20)
 
	amount_parent_class = driver.find_element_by_class_name("_1dGv")
	amount_sub_class = amount_parent_class.find_element_by_class_name("_3_cL")
	amount = amount_sub_class.find_element_by_tag_name("input")
	amount.clear()
	amount.send_keys("10")
 
	button_class = driver.find_element_by_class_name("_3BxH")
	button = button_class.find_element_by_tag_name("button")
	button_text = button.text
 
	if button_text.upper() == 'PROCEED TO PAY BILL':
		button.click()
		print '-- Waiting 10seconds before applying promocode --'
		time.sleep(10)
 
		promocode_class = driver.find_element_by_class_name("pjke")
		promocode = promocode_class.find_element_by_tag_name("a")
		promocode.click()
		time.sleep(5)
 
		get5_class = driver.find_element_by_class_name("XQyr")
		get5 = get5_class.find_element_by_tag_name("input")
		get5.clear()
		get5.send_keys("GET5")
		get5_button = get5_class.find_element_by_tag_name("button")
		get5_button.click()
		print 'Promocode applied !'
		print '-- Waiting 5 seconds before initiating payment --'
		time.sleep(5)
 
		payment_class = driver.find_element_by_class_name("_1x8H")
		payment = payment_class.find_element_by_tag_name("button")
		print 'Payment Initiated ...'
		payment.click()
		print 'Payment Completed !'
		if i+1 != loops:
			sleep_time = random.randint(30,60)
			print '-- Waiting '+str(sleep_time)+'seconds before initiating next transaction --'
			#Its good to wait for sometime, otherwise paytm systems might detect abnormality in transactions
			time.sleep(sleep_time)
		else:
			time.sleep(5)
		print '------------------------------------------'
	else:
		print '---- Error ----'
		print 'The checkbox is automatically selected as Y and will not allow to enter promocode'
		continue_loop = raw_input("Do you want to continue to next loop(Y/N) ?")
		if continue_loop!='Y':
			break
 
close_browser = raw_input("Do you want to close browser(Y/N) ?")
if close_browser !='N':
	print 'Browser will close in next 5 seconds ...'
	time.sleep(5)
	print '-- Closing Driver --'
	driver.close()
print '-- Program Completed --'

Note : I created this script in accordance to my postpaid recharge. That is why it contains all the hardcodings. Also I have included time laps in between(like time.sleep(15)) to prevent PayTM systems to detect these transactions as bot transactions.

After this, I was left with only one problem – receiving so many transaction SMSes. I found a solution to this too and this was too simple -ignore them 😛

Happy Automation!

Spread the word :)
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  


Leave a Reply

Your email address will not be published. Required fields are marked *