github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/validations/payee_guarantor.go (about) 1 package validations 2 3 import ( 4 "github.com/mundipagg/boleto-api/models" 5 ) 6 7 //ValidatePayeeGuarantorName Verifica se o nome do lojista é existe 8 func ValidatePayeeGuarantorName(b interface{}) error { 9 switch t := b.(type) { 10 case *models.BoletoRequest: 11 if t.HasPayeeGuarantor() { 12 if !t.PayeeGuarantor.HasName() { 13 return models.NewErrorResponse("MPPayeeGuarantorNameType", "Nome do sacador avalista está vazio") 14 } 15 } 16 return nil 17 default: 18 return InvalidType(t) 19 } 20 } 21 22 //ValidatePayeeGuarantorDocumentNumber Verifica se o número do documento do lojista é válido 23 func ValidatePayeeGuarantorDocumentNumber(b interface{}) error { 24 switch t := b.(type) { 25 case *models.BoletoRequest: 26 if t.HasPayeeGuarantor() { 27 if t.PayeeGuarantor.Document.IsCPF() { 28 return t.PayeeGuarantor.Document.ValidateCPF() 29 } 30 if t.PayeeGuarantor.Document.IsCNPJ() { 31 return t.PayeeGuarantor.Document.ValidateCNPJ() 32 } 33 return models.NewErrorResponse("MPPayeeGuarantorDocumentType", "Tipo de Documento inválido") 34 } 35 return nil 36 default: 37 return InvalidType(t) 38 } 39 }