Skip to content

Commit

Permalink
Upgrading to v0.2
Browse files Browse the repository at this point in the history
Switching to Juspay API to fetch VPA details
  • Loading branch information
LuD1161 committed May 18, 2022
1 parent f864f44 commit 9c4989c
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 57 deletions.
1 change: 0 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ archives:
files:
- data/*
- README.md
- config.yaml.sample
- LICENSE


Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ This tool leverages the openness available with the UPI platform to find :
2. UPI ID and name associated with a gmail account
3. UPI ID and name associated with a vehicle registration number. Leveraging UPI id associated with a FASTag.

**NOTE** : You won't get any results as of now, since razorpay has limited the data that was being sent. Need to find alternative APIs that can help with this. Check [Issue#6](https://github.com/LuD1161/upi-recon-cli/issues/6)

This project is a golang port of [upi-recon](https://github.com/qurbat/upi-recon/) by [@squeal](https://twitter.com/squeal).

# Overview
Expand Down Expand Up @@ -40,7 +38,6 @@ Available Commands:
help Help about any command

Flags:
-c, --config string config file (default "config.yaml")
-h, --help help for upi-recon-cli
-t, --threads int No of threads (default 100)
--timeout int Timeout for requests (default 15)
Expand Down Expand Up @@ -78,20 +75,16 @@ You'd find the following file strucuture inside the extracted folder :
.
├── LICENSE
├── README.md
├── config.yaml.sample
├── data
│   ├── all_suffixes.txt
│   ├── fastag_suffixes.txt
│   ├── gpay_suffixes.txt
│   └── mobile_suffixes.txt
└── upi-recon-cli

1 directory, 8 files
1 directory, 7 files
```
3. Rename the `config.yaml.sample` file to `config.yaml` and add the razorpay live api key into it.
Please [refer to the documentation](https://razorpay.com/docs/payments/dashboard/settings/api-keys/) provided by Razorpay in order to generate valid live API credentials.
<br/>**Note**: Razorpay `test` credentials will not work.
4. That's it. You're ready to go 🎉🚀
3. That's it. You're ready to go 🎉🚀

## Run with Gitpod

Expand Down
2 changes: 1 addition & 1 deletion cmd/checkAll.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var checkAllCmd = &cobra.Command{
log.Error().Msg("Error reading 'data/all_suffixes.txt'")
os.Exit(1)
}
checkUpi(args[0], vpaSuffixes, api_key)
checkUpi(args[0], vpaSuffixes)
} else {
cmd.Help()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/checkFastag.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var checkFastagCmd = &cobra.Command{
os.Exit(1)
}
vpa := fmt.Sprintf("netc.%s", args[0])
checkUpi(vpa, fastTagSuffixes, api_key)
checkUpi(vpa, fastTagSuffixes)
} else {
log.Error().Msgf("❌ Please enter vehicle registration number")
cmd.Help()
Expand Down
2 changes: 1 addition & 1 deletion cmd/checkGpay.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var checkGpayCmd = &cobra.Command{
if strings.HasSuffix(email_id, "@gmail.com") {
vpa_suffix = email_id[:len(email_id)-10]
}
checkUpi(vpa_suffix, gpaySuffixes, api_key)
checkUpi(vpa_suffix, gpaySuffixes)
} else {
log.Error().Msgf("❌ Please enter vehicle registration number")
cmd.Help()
Expand Down
2 changes: 0 additions & 2 deletions cmd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ const banner = `
# Website : https://aseemshrey.in
# YouTube : https://www.youtube.com/c/HackingSimplifiedAS
`

var api_key string
2 changes: 1 addition & 1 deletion cmd/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

type VPAResponse struct {
VPA string `json:"vpa"`
Success bool `json:"success"`
Status string `json:"status"`
CustomerName string `json:"customer_name"`
Error error `json:"error"`
}
32 changes: 2 additions & 30 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -30,12 +29,12 @@ var (
log.Error().Msg("Error reading 'data/mobile_suffixes.txt'")
os.Exit(1)
}
checkUpi(args[0], vpaSuffixes, api_key)
checkUpi(args[0], vpaSuffixes)
} else {
cmd.Help()
}
},
Version: fmt.Sprintf("0.1.2"),
Version: fmt.Sprintf("0.2"),
}
)

Expand All @@ -53,34 +52,7 @@ func init() {
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
fmt.Println(banner)
cobra.OnInitialize(initConfig)
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "config.yaml", "config file")
rootCmd.PersistentFlags().IntVarP(&threads, "threads", "t", 100, "No of threads")
rootCmd.PersistentFlags().IntVarP(&timeout, "timeout", "", 15, "Timeout for requests")
}

func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Search config in home directory with name ".cobra" (without extension).
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.SetConfigType("yaml")
}

viper.AutomaticEnv()

if err := viper.ReadInConfig(); err == nil {
log.Debug().Msgf("Using config file: %s", viper.ConfigFileUsed())
var ok bool
api_key, ok = viper.Get("RAZORPAY_LIVE_API_KEY").(string)
if !ok {
log.Fatal().Msgf("🚨 RAZORPAY_LIVE_API_KEY not set. Please take a look at config.yaml.sample file and check the installation instructions.")
}
} else {
log.Fatal().Msgf("🚨Config file not found.\n✅ Pass in the config file location with -c option or place the config.yaml in this directory itself.")
}
}
17 changes: 8 additions & 9 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ import (
"github.com/rs/zerolog/log"
)

func MakeRequest(vpasChan <-chan string, resultsChan chan<- VPAResponse, api_key string) {
func MakeRequest(vpasChan <-chan string, resultsChan chan<- VPAResponse) {
client := http.Client{Timeout: time.Duration(timeout) * time.Second}
url := fmt.Sprintf("https://api.razorpay.com/v1/payments/validate/account?key_id=%s", api_key)
url := "https://api.juspay.in/upi/verify-vpa"

for vpa := range vpasChan {
result := VPAResponse{
VPA: vpa,
Success: false,
Status: "INVALID",
CustomerName: "",
Error: nil,
}
log.Debug().Msgf("Trying %s", vpa)
payload := strings.NewReader(fmt.Sprintf(`{
"entity": "vpa",
"value": "%s"
"merchant_id":"juspay",
"vpa": "%s"
}`, vpa))
req, err := http.NewRequest("POST", url, payload)
req.Header.Add("Connection", "close")
Expand Down Expand Up @@ -89,7 +88,7 @@ func check_is_a_number(number string) bool {
return re.MatchString(number)
}

func checkUpi(number string, suffixes_array []string, api_key string) {
func checkUpi(number string, suffixes_array []string) {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
Expand All @@ -107,7 +106,7 @@ func checkUpi(number string, suffixes_array []string, api_key string) {
vpasChan := make(chan string, threads)
resultsChan := make(chan VPAResponse)
for i := 0; i < threads; i++ {
go MakeRequest(vpasChan, resultsChan, api_key)
go MakeRequest(vpasChan, resultsChan)
}

go func() {
Expand All @@ -119,7 +118,7 @@ func checkUpi(number string, suffixes_array []string, api_key string) {
found_any := false
for i := 0; i < len(vpas); i++ {
result := <-resultsChan
if result.Error == nil && result.Success == true && result.CustomerName != "" {
if result.Error == nil && result.Status == "VALID" && result.CustomerName != "" {
log.Info().Msgf("✅ Customer Name : %s | VPA : %s", result.CustomerName, result.VPA)
found_any = true
} else {
Expand Down
2 changes: 0 additions & 2 deletions config.yaml.sample

This file was deleted.

0 comments on commit 9c4989c

Please sign in to comment.