├── .gitignore ├── README.md ├── examples ├── auth.js └── history.js ├── lib ├── auth.js └── history.js ├── package-lock.json ├── package.json └── paytm.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test.js 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Paytm's internal API for Node.js 2 | Reverse engineered paytm's api wrapper written in Node.js 3 | 4 |
5 | 6 | # Instructions 7 | 8 | ## Installation 9 | Install using npm 10 | ```sh 11 | $ npm install node-paytm-api 12 | ``` 13 | 14 | ## Usage 15 | 16 | ### With Number and Password 17 | You can simply require/import and use the Wrapper. 18 | 19 | Example. 20 | ```js 21 | const Paytm = require('node-paytm-api') 22 | const paytm = new Paytm({ number: '+919876543210', password: 'MyPassword' }) 23 | ``` 24 | - after creating class instance you will be recieving OTP on your provided number. 25 | - Then you can verify OTP using `verifyOtp`. The function will return Promise and you can have accessToken when resolved. 26 | 27 | ```js 28 | const accessToken = await paytm.verifyOtp('1234') 29 | ``` 30 | - Note: AccessToken will be stored in class variable. Its only to use it later on. 31 | 32 | -

Once you login! You can use the account methods.

33 | 34 | ### With Access Token 35 | You can use accessToken to initialize class instance too. 36 | 37 | Example: 38 | ```js 39 | const paytm = new Paytm({ accessToken: '' }) 40 | ``` 41 | 42 | ## Using Methods 43 | | Method | Usage | Arguments | Return value | 44 | | -------------- | --------------| ------------ | ------------ | 45 | | getAccessToken | get accessToken when
successfully authenticated | None | `accessToken(String)` | 46 | | getWalletHistory | retrieve wallet history of
user. | (`offset`: optional, `limit`: optional)
`offset` - value to skip for front
`limit` - Retreival results for max at a time | `object -> array of transaction history`
(based on offset and limit) 47 | 48 | 49 | ## Code Example 50 | -

Checkout code example here

51 | 52 | # Credits 53 | - HttpCanary 54 | - Magisk 55 | - Fiddler 56 | - and ofc me :flushed: 57 | -------------------------------------------------------------------------------- /examples/auth.js: -------------------------------------------------------------------------------- 1 | const Paytm = require('./../paytm') 2 | const readline = require('readline') 3 | 4 | // Add your number and Password 5 | const paytm = new Paytm({ number: '+91987654321', password: 'MyPassword' }) 6 | paytm.login().then(() => { 7 | const ques = readline.createInterface({ input: process.stdin, output: process.stdout }) 8 | ques.question('Enter OTP:', async (otp) => { 9 | const accessToken = await paytm.verifyOtp(otp) 10 | console.log("AccessToken", accessToken) 11 | ques.close() 12 | }) 13 | }) 14 | 15 | -------------------------------------------------------------------------------- /examples/history.js: -------------------------------------------------------------------------------- 1 | const Paytm = require('./../paytm') 2 | const readline = require('readline') 3 | 4 | // Add your number and Password 5 | const paytm = new Paytm({ number: '+91987654321', password: 'MyPassword' }) 6 | paytm.login().then(() => { 7 | const ques = readline.createInterface({ input: process.stdin, output: process.stdout }) 8 | ques.question('Enter OTP:', async (otp) => { 9 | await paytm.verifyOtp(otp) 10 | 11 | // only change from auth.js file 12 | const history = await paytm.getWalletHistory() 13 | console.log("Wallet history:", history) 14 | 15 | // get Next list 16 | const nextHistory = await paytm.getWalletHistory(50, 100) // Returns 50-100 result 17 | console.log("Next history", nextHistory) 18 | ques.close() 19 | }) 20 | }) 21 | 22 | -------------------------------------------------------------------------------- /lib/auth.js: -------------------------------------------------------------------------------- 1 | const { default: axios } = require('axios') 2 | 3 | const commonHeaders = { 4 | 'content-type': 'application/json', 5 | 'host': 'accounts.paytm.com', 6 | 'authorization': 'Basic bWFya2V0LWFwcDo5YTA3MTc2Mi1hNDk5LTRiZDktOTE0YS00MzYxZTdjM2Y0YmM=' 7 | } 8 | 9 | const getStateToken = async (number) => { 10 | const res = await axios({ 11 | method: 'POST', 12 | url: 'https://accounts.paytm.com/simple/login/init', 13 | data: { 14 | loginId: number, 15 | flow: 'login' 16 | }, 17 | headers: commonHeaders 18 | }) 19 | console.log('statetoken', res.data) 20 | return res.data.stateToken 21 | 22 | } 23 | 24 | const validatePassword = async (stateToken, password) => { 25 | const res = await axios({ 26 | method: 'POST', 27 | url: "https://accounts.paytm.com/simple/login/validate/password", 28 | headers: commonHeaders, 29 | data: { 30 | password, 31 | stateToken 32 | } 33 | }) 34 | console.log('Validating password') 35 | console.log(res.data) 36 | return res.data.stateToken 37 | } 38 | 39 | const login = async (number, password) => { 40 | return await validatePassword(await getStateToken(number), password) 41 | } 42 | const verifyOtp = async (otp, stateToken) => { 43 | const res = await axios({ 44 | method: 'POST', 45 | url: 'https://accounts.paytm.com/simple/login/validate/otp', 46 | headers: commonHeaders, 47 | data: { 48 | otp, 49 | stateToken 50 | } 51 | }) 52 | console.log("Otp verification", res.data) 53 | return res.data.oauthCode 54 | } 55 | 56 | const getAccessToken = async (oAuthToken) => { 57 | const res = await axios({ 58 | method: 'POST', 59 | url: 'https://accounts.paytm.com/oauth2/token', 60 | data: `code=${oAuthToken}&scope=paytm&grant_type=authorization_code`, 61 | headers: commonHeaders 62 | }) 63 | console.log("Access Token", res.data) 64 | return { accessToken: res.data.access_token, expiresAt: res.data.expires } 65 | } 66 | 67 | module.exports = { 68 | login, 69 | verifyOtp, 70 | getAccessToken 71 | } 72 | -------------------------------------------------------------------------------- /lib/history.js: -------------------------------------------------------------------------------- 1 | const { default: axios } = require('axios') 2 | 3 | const getWalletHistory = async (accessToken, offset, limit) => { 4 | console.log(accessToken) 5 | const res = await axios({ 6 | method: 'POST', 7 | url: 'https://trust.paytm.in/service/wrapper/userTransactionHistory', 8 | data: { 9 | "request": { 10 | "userGuid": "", 11 | "startLimit": offset, 12 | "lastLimit": limit, 13 | "subWalletParams": { 14 | "subWalletType": ["PAYTM WALLET"] 15 | }, 16 | "walletTransactiontype": "ALL" 17 | } 18 | }, 19 | headers: { 20 | ssotoken: accessToken, 21 | 'content-type': 'application/json' 22 | } 23 | }) 24 | console.log('Wallet history', res.data) 25 | return res.data 26 | } 27 | 28 | module.exports = getWalletHistory -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "paytm-api", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "axios": { 8 | "version": "0.20.0", 9 | "resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz", 10 | "integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==", 11 | "requires": { 12 | "follow-redirects": "^1.10.0" 13 | } 14 | }, 15 | "follow-redirects": { 16 | "version": "1.13.0", 17 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", 18 | "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-paytm-api", 3 | "version": "1.0.1", 4 | "description": "Paytm internal API for Node.js", 5 | "main": "paytm.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": ["paytm", "api", "reverse engineered"], 10 | "author": "Swapnil Soni", 11 | "license": "ISC", 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/SwapnilSoni1999/node-paytm-api.git" 15 | }, 16 | "dependencies": { 17 | "axios": "^0.20.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /paytm.js: -------------------------------------------------------------------------------- 1 | const auth = require('./lib/auth') 2 | const walletHistory = require('./lib/history') 3 | 4 | class Paytm { 5 | constructor(payload) { 6 | console.log(payload) 7 | this.access = { 8 | accessToken: null, 9 | expiresAt: null 10 | } 11 | if (payload.accessToken) { 12 | this.access.accessToken = payload.accessToken 13 | } else { 14 | this.number = payload.number 15 | this.password = payload.password 16 | } 17 | } 18 | 19 | async login() { 20 | this.stateToken = await auth.login(this.number, this.password) 21 | return this.stateToken 22 | } 23 | 24 | async verifyOtp(otp) { 25 | this.oauthToken = await auth.verifyOtp(otp, this.stateToken) 26 | this.access = await auth.getAccessToken(this.oauthToken) 27 | return this.access.accessToken 28 | } 29 | 30 | async getAccessToken() { 31 | return this.access.accessToken 32 | } 33 | 34 | async getWalletHistory(offset=0, limit=20) { 35 | return await walletHistory(this.access.accessToken, offset, limit) 36 | } 37 | 38 | } 39 | 40 | module.exports = Paytm --------------------------------------------------------------------------------