Skip to content

Commit

Permalink
Merge pull request #245 from razorpay/go-src
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo committed Aug 12, 2021
2 parents 290f869 + eb2d809 commit 4b36689
Show file tree
Hide file tree
Showing 19 changed files with 3,944 additions and 25 deletions.
54 changes: 30 additions & 24 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
version: 2
updates:
- package-ecosystem: bundler
directory: "/"
schedule:
interval: daily
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: bundler
directory: "/scraper"
schedule:
interval: daily
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: mix
directory: "/"
schedule:
interval: daily
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: bundler
directory: "/"
schedule:
interval: weekly
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: bundler
directory: "/scraper"
schedule:
interval: weekly
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: composer
directory: "/"
schedule:
interval: weekly
time: "04:00"
timezone: Asia/Calcutta
- package-ecosystem: gomod
directory: "/"
schedule:
interval: weekly
time: "04:00"
timezone: Asia/Calcutta
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ jobs:
bundler-cache: true
- run: bundle install
- run: bundle exec rake
go:
strategy:
matrix:
go: ["^1.16.7", "^1.15.15"]
name: Go
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
bundler-cache: true
- run: make go-test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ InstalledFiles

# One-off scripts
*.php

# IDE files
.idea/*

# Temp files
.*~
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go-test:
go test -tags=unit -timeout 2m -coverprofile=coverage.cov -v ./...

generate-constants:
go run ./src/go/generator/main.go
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ The minimum [PHP version supported is 7.2](https://endoflife.date/php).

`$ npm install ifsc`

## Go

`$ go get -u github.com/razorpay/ifsc`

To use the go pkg, the import path should be:

```go
import "github.com/razorpay/ifsc/src/go"
```

## Support Matrix

Only the latest version of each SDK is considered.
Expand All @@ -91,10 +101,11 @@ Only the latest version of each SDK is considered.
| PHP ||| ✅ (✅) ||
| Ruby ||| ✅ (✅) ||
| Node.js ||| ❎ (❎) ||
| Go ||| ✅ (✅) ||

## API Documentation

This repository also hosts the source code for 3 modules: PHP/Node.js/Ruby as of now.
This repository also hosts the source code for 5 modules: PHP/Node.js/Ruby/Go as of now.
The API is documented below:

### PHP
Expand Down Expand Up @@ -277,6 +288,72 @@ Razorpay::IFSC::IFSC.find '...'
code = Razorpay::IFSC::IFSC.new '...'; code.get
```

### Go

```go
package main

import (
ifsc "github.com/razorpay/ifsc/src/go"
)

// todo: change funcs not required to lower case.

func main() {

ifsc.Validate("KKBK0000261") // Returns true
ifsc.Validate("BOTM0XEEMRA") // Returns false

ifsc.ValidateBankCode("PUNB") // Returns true
ifsc.ValidateBankCode("ABCD") // Returns false

ifsc.GetBankName("PUNB") // Returns "Punjab National Bank", nil
ifsc.GetBankName("ABCD") // Returns "", errors.New(invalid bank code)
ifsc.GetBankName(ifsc.HDFC) // Returns "HDFC Bank", nil


ifsc.GetBankDetails("PUNB")
// or
ifsc.GetBankDetails(ifsc.PUNB)

/* Returns
(*ifsc.Bank){
Name : "Punjab National Bank",
BankCode : "024",
Code : "PUNB",
Type : "PSB",
IFSC : "PUNB0244200",
MICR : "110024001",
IIN : "508568",
APBS : true,
AchCredit : true,
AchDebit : true,
NachDebit : true,
Upi : true
}), nil
*/

ifsc.LookUP("KKBK0000261")

/*
Returns
(*ifsc.IFSCResponse)({
Bank : "Kotak Mahindra Bank",
Branch : "GURGAON",
Address : "JMD REGENT SQUARE,MEHRAULI GURGAON ROAD,OPPOSITE BRISTOL HOTEL,",
Contact : "4131000",
City : "GURGAON",
District : "GURGAON",
State : "HARYANA",
IFSC : "KKBK0000261",
BankCode : "KKBK"
}), nil
*/
}

```

>>>>>>> 5ff434d (update readme & make bank code constants.)
### Code Notes

Both the packages ship with a 300kb JSON file, that
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/razorpay/ifsc

go 1.15

require github.com/stretchr/testify v1.7.0
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
47 changes: 47 additions & 0 deletions src/go/bank.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ifsc

import (
"fmt"
"log"
)

type Bank struct {
Name string `json:"name"`
BankCode string `json:"bank_code"`
Code string `json:"code"`
Type string `json:"type"`
IFSC string `json:"ifsc"`
MICR string `json:"micr"`
IIN string `json:"iin"`
APBS bool `json:"apbs"`
AchCredit bool `json:"ach_credit"`
AchDebit bool `json:"ach_debit"`
NachDebit bool `json:"nach_debit"`
Upi bool `json:"upi",omitempty`
}

var bankData map[string]Bank

func LoadBankData() {
if bankData == nil {
if err := LoadFile("banks.json", &bankData, ""); err != nil {
log.Panic(fmt.Sprintf("there is some error in banknames.json file: %v", err))
}
}
}

func GetBankDetails(bankCode string) *Bank {
data, ok := bankData[bankCode]
if !ok {
return nil
}
var err error
data.Name, err = GetBankName(bankCode)
if err != nil {
return nil
}
if data.MICR != "" {
data.BankCode = data.MICR[3:6]
}
return &data
}
47 changes: 47 additions & 0 deletions src/go/bank_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ifsc

import (
"testing"
// TODO: change
"github.com/stretchr/testify/assert"
)

func Test_BankGetDetails(t *testing.T) {
assert := assert.New(t)
result := GetBankDetails("FINO")
assert.Equal(getFINOfixture(), *result)
result = GetBankDetails("PUNB")
assert.Equal(getPUNBFixture(), *result)
}
func getPUNBFixture() Bank {
return Bank{
Name: "Punjab National Bank",
BankCode: "024",
Code: "PUNB",
Type: "PSB",
IFSC: "PUNB0244200",
MICR: "110024001",
IIN: "508568",
APBS: true,
AchCredit: true,
AchDebit: true,
NachDebit: true,
Upi: true,
}
}
func getFINOfixture() Bank {
return Bank{
Name: "Fino Payments Bank",
BankCode: "",
Code: "FINO",
Type: "PB",
IFSC: "FINO0000001",
MICR: "",
IIN: "608001",
APBS: true,
AchCredit: true,
AchDebit: false,
NachDebit: false,
Upi: true,
}
}
Loading

0 comments on commit 4b36689

Please sign in to comment.