github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/bradescoShopFacil/validations.go (about) 1 package bradescoShopFacil 2 3 import ( 4 "github.com/mundipagg/boleto-api/models" 5 "github.com/mundipagg/boleto-api/validations" 6 "strings" 7 ) 8 9 func bradescoShopFacilValidateAgency(b interface{}) error { 10 switch t := b.(type) { 11 case *models.BoletoRequest: 12 err := t.Agreement.IsAgencyValid() 13 if err != nil { 14 return models.NewErrorResponse("MP400", err.Error()) 15 } 16 return nil 17 default: 18 return validations.InvalidType(t) 19 } 20 } 21 22 func bradescoShopFacilValidateAccount(b interface{}) error { 23 switch t := b.(type) { 24 case *models.BoletoRequest: 25 if t.Agreement.Account == "" { 26 return models.NewErrorResponse("MP400", "a conta deve ser preenchida") 27 } 28 return nil 29 default: 30 return validations.InvalidType(t) 31 } 32 } 33 34 func bradescoShopFacilValidateWallet(b interface{}) error { 35 switch t := b.(type) { 36 case *models.BoletoRequest: 37 if t.Agreement.Wallet != 25 && t.Agreement.Wallet != 26 { 38 return models.NewErrorResponse("MP400", "a carteira deve ser 25 ou 26 para o BradescoShopFacil") 39 } 40 return nil 41 default: 42 return validations.InvalidType(t) 43 } 44 } 45 46 func bradescoShopFacilValidateAuth(b interface{}) error { 47 switch t := b.(type) { 48 case *models.BoletoRequest: 49 usr := strings.TrimSpace(t.Authentication.Username) 50 pwd := strings.TrimSpace(t.Authentication.Password) 51 if usr == "" || pwd == "" { 52 return models.NewErrorResponse("MP400", "o nome de usuário e senha devem ser preenchidos") 53 } 54 return nil 55 default: 56 return validations.InvalidType(t) 57 } 58 } 59 60 func bradescoShopFacilValidateAgreement(b interface{}) error { 61 switch t := b.(type) { 62 case *models.BoletoRequest: 63 if t.Agreement.AgreementNumber == 0 { 64 return models.NewErrorResponse("MP400", "o código do contrato deve ser preenchido") 65 } 66 return nil 67 default: 68 return validations.InvalidType(t) 69 } 70 } 71 72 func bradescoShopFacilBoletoTypeValidate(b interface{}) error { 73 bt := bradescoShopFacilBoletoTypes() 74 75 switch t := b.(type) { 76 77 case *models.BoletoRequest: 78 if len(t.Title.BoletoType) > 0 && bt[t.Title.BoletoType] == "" { 79 return models.NewErrorResponse("MP400", "espécie de boleto informada não existente") 80 } 81 return nil 82 default: 83 return validations.InvalidType(t) 84 } 85 }