razorpay / ifsc

:bank: IFSC Codes Repository
https://ifsc.razorpay.com
MIT License
341 stars 138 forks source link

Missing lookup ranges support #62

Closed nihalgonsalves closed 6 years ago

nihalgonsalves commented 6 years ago

@captn3m0 When I added the Rubygem (https://github.com/razorpay/ifsc/pull/31), you said that the "lookup ranges" method should be removed as it is no longer supported (https://github.com/razorpay/ifsc/pull/31#issuecomment-317964916)

We've had problems validating IFSC codes in production and investigating it lead me to the JSON file, which still includes 219 instances of range tuples (\[\d*,\d*\]) and thus it seems that the validation errors are due to missing range support in the Elixir package and Rubygem.

Are these invalid branches, or should range validation be added? The API, PHP package, and NPM package all validate ranges correctly at the moment.

e.g. this Allahabad bank code that falls within the [212820,212826] range in the IFSC.json file

# via offline validation
iex> Razorpay.IFSC.validate("ALLA0212822")
{:error, :invalid_branch_code}

# via online API lookup
iex> Razorpay.IFSC.get("ALLA0212822") 
{:ok,
 %Razorpay.IFSC{
   address: "VILLAGE & POST- RAMRAJ, NEAR STATE BANK OF INDIA, DISTRICT- MUZAFFARNAGAR-251320",
   bank: "Allahabad Bank",
   bank_code: "ALLA",
   branch: "RAMRAJ",
   city: "RAM RAJ",
   contact: "",
   district: "MUZAFFARNAGAR",
   ifsc: "ALLA0212822",
   rtgs: nil,
   state: "UTTAR PRADESH"
 }}
$ curl https://ifsc.razorpay.com/ALLA0212822
{"CITY":"RAM RAJ","ADDRESS":"VILLAGE & POST- RAMRAJ, NEAR STATE BANK OF INDIA, DISTRICT- MUZAFFARNAGAR-251320","DISTRICT":"MUZAFFARNAGAR","BRANCH":"RAMRAJ","CONTACT":"","STATE":"UTTAR PRADESH","BANK":"Allahabad Bank","BANKCODE":"ALLA","IFSC":"ALLA0212822"}

Also, the sole range test in validator_asserts.json does not really test a range:

"testValidateInsideRange": {
  "DLXB0000097": true
},

That IFSC code is actually stored plainly like this:

"DLXB":[..., 98, 97, 96, ...]

Which leads me to believe - is the scraper script the problem instead, as it isn't resolving all the ranges correctly to plain arrays?

captn3m0 commented 6 years ago

Will take a look. The code that generates this is at https://github.com/razorpay/ifsc/blob/70080e3c44b6a76d8b2caca4c9a3bd154add9d22/scraper/scripts/methods.rb#L287-L307

captn3m0 commented 6 years ago

I'm wondering if the script is exporting the wrong IFSC.json file :man_facepalming:

captn3m0 commented 6 years ago

Running the generate scripts locally to debug this. Should have a fix + new release out by tomorrow.

Thanks for the report :+1:

captn3m0 commented 6 years ago

Closed with https://github.com/razorpay/ifsc/releases/1.1.0

Still have to push the NPM/Ruby/Hex packages.

captn3m0 commented 6 years ago

@nihalgonsalves Was about to publish 1.1.0 to hex.pm. Can you confirm the following output please? I was confused by the IFSC.json file showing up twice (priv and src):

mix hex.publish
Compiling 3 files (.ex)
Generated ifsc app
Building ifsc 1.1.0
  Dependencies:
    poison ~> 3.1 (app: poison)
    httpoison ~> 0.13 (app: httpoison)
    memoize ~> 1.2 (app: memoize)
  App: ifsc
  Name: ifsc
  Files:
    src/elixir/config/config.exs
    src/elixir/lib/mix
    src/elixir/lib/mix/tasks
    src/elixir/lib/mix/tasks/copy_json.ex
    src/elixir/lib/razorpay
    src/elixir/lib/razorpay/ifsc
    src/elixir/lib/razorpay/ifsc.ex
    src/elixir/lib/razorpay/ifsc/data.ex
    src/elixir/README.md
    tests/elixir/ifsc_acceptance_test.exs
    tests/elixir/ifsc_test.exs
    tests/elixir/test_helper.exs
    tests/validator_asserts.json
    priv/ifsc-data
    priv/ifsc-data/IFSC.json
    priv/ifsc-data/banknames.json
    priv/ifsc-data/sublet.json
    src/IFSC.json
    src/banknames.json
    src/sublet.json
    CONTRIBUTING.md
    README.md
    mix.exs
  Description: A simple package by @razorpay to help you validate your IFSC codes. IFSC codes are bank codes within India
  Version: 1.1.0
  Build tools: mix
  Licenses: MIT
  Maintainers: Nihal Gonsalves <nihal@gonsalves.com>, Abhay Rana <contact@razorpay.com>
  Links: 
    GitHub: https://github.com/razorpay/ifsc
    Website: https://ifsc.razorpay.com/
  Elixir: ~> 1.5
Before publishing, please read the Code of Conduct: https://hex.pm/policies/codeofconduct

Publishing package to public repository hexpm.
Proceed? [Yn] 
nihalgonsalves commented 6 years ago

Should be fine, just double check that the json files are the same. The hex.publish alias should've copied the latest version to priv.

captn3m0 commented 6 years ago

Published: https://hex.pm/packages/ifsc/1.1.0