Skip to content

Commit

Permalink
modifying struct
Browse files Browse the repository at this point in the history
  • Loading branch information
neelesh-patil-4417 committed Dec 22, 2024
1 parent 5caf809 commit 3a253ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 24 additions & 9 deletions packages/i18nify-go/modules/bankcodes/bankcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

type Identifier struct {
SwiftCode string `json:"swift_code"`
RoutingNumber string `json:"routing_number"`
IfscCode string `json:"ifsc_code"`
SwiftCode string `json:"swift_code"`
RoutingNumber []string `json:"routing_number"`
IfscCode string `json:"ifsc_code"`
}

type Branch struct {
Expand Down Expand Up @@ -94,8 +94,10 @@ func IsValidBankIdentifier(countryCode, identifierType, identifierValue string)
return true, nil
}
case IdentifierTypeRoutingNumber:
if strings.EqualFold(branch.Identifiers.RoutingNumber, identifierValue) {
return true, nil
for _, routingNumber := range branch.Identifiers.RoutingNumber {
if strings.EqualFold(routingNumber, identifierValue) {
return true, nil
}
}
case IdentifierTypeIFSC:
if strings.EqualFold(branch.Identifiers.IfscCode, identifierValue) {
Expand Down Expand Up @@ -151,7 +153,7 @@ func GetDefaultBankIdentifiersFromShortCode(countryCode, shortCode string) ([]st
case IdentifierTypeSWIFT:
identifiers = append(identifiers, branch.Identifiers.SwiftCode)
case IdentifierTypeRoutingNumber:
identifiers = append(identifiers, branch.Identifiers.RoutingNumber)
identifiers = append(identifiers, branch.Identifiers.RoutingNumber...)
case IdentifierTypeIFSC:
identifiers = append(identifiers, branch.Identifiers.IfscCode)
default:
Expand Down Expand Up @@ -182,13 +184,26 @@ func GetBankNameFromBankIdentifier(countryCode, identifier string) (string, erro

for _, bank := range bankInfo.Details {
for _, branch := range bank.Branches {
if branch.Identifiers.SwiftCode == identifier ||
branch.Identifiers.RoutingNumber == identifier ||
branch.Identifiers.IfscCode == identifier {
// Check SwiftCode and IfscCode directly
if branch.Identifiers.SwiftCode == identifier || branch.Identifiers.IfscCode == identifier {
return bank.Name, nil
}

// Check if identifier is in RoutingNumber list
for _, routingNumber := range branch.Identifiers.RoutingNumber {
if routingNumber == identifier {
return bank.Name, nil
}
}
}
}

return "", fmt.Errorf("no bank found for identifier '%s' in country %s", identifier, countryCode)
}

func main() {
// fmt.Println(IsValidBankIdentifier("US", "ROUTING_NUMBER", "121135087"))
// fmt.Println(GetBankNameFromShortCode("US", "BUFB"))
fmt.Println(GetDefaultBankIdentifiersFromShortCode("US", "BNNE"))
// fmt.Println(GetBankNameFromBankIdentifier("US", "323371076"))
}
2 changes: 1 addition & 1 deletion packages/i18nify-go/modules/bankcodes/data/US.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"defaults": {
"identifier_type": "SWIFT"
"identifier_type": "ROUTING_NUMBER"
},
"details": [
{
Expand Down

0 comments on commit 3a253ee

Please sign in to comment.