github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/itau/validations.go (about) 1 package itau 2 3 import ( 4 "github.com/mundipagg/boleto-api/models" 5 "github.com/mundipagg/boleto-api/validations" 6 ) 7 8 func itauValidateAccount(b interface{}) error { 9 switch t := b.(type) { 10 case *models.BoletoRequest: 11 err := t.Agreement.IsAccountValid(7) 12 if err != nil { 13 return err 14 } 15 return nil 16 default: 17 return validations.InvalidType(t) 18 } 19 } 20 21 func itauValidateAgency(b interface{}) error { 22 switch t := b.(type) { 23 case *models.BoletoRequest: 24 err := t.Agreement.IsAgencyValid() 25 if err != nil { 26 return models.NewErrorResponse("MP400", err.Error()) 27 } 28 return nil 29 default: 30 return validations.InvalidType(t) 31 } 32 } 33 34 func itauBoletoTypeValidate(b interface{}) error { 35 bt := itauBoletoTypes() 36 37 switch t := b.(type) { 38 39 case *models.BoletoRequest: 40 if len(t.Title.BoletoType) > 0 && bt[t.Title.BoletoType] == "" { 41 return models.NewErrorResponse("MP400", "espécie de boleto informada não existente") 42 } 43 return nil 44 default: 45 return validations.InvalidType(t) 46 } 47 }