11package  pix
22
33import  (
4+ 	"errors" 
45	"fmt" 
56	"regexp" 
67	"strings" 
8+ 	"unicode/utf8" 
79
810	"github.com/snksoft/crc" 
11+ 	"github.com/thiagozs/go-pixgen/qrcode" 
912)
1013
1114type  Pix  struct  {
@@ -64,6 +67,8 @@ func (p *Pix) GenPayload() string {
6467
6568	payload  =  p .FindAndReplaceCRC (payload )
6669
70+ 	p .params .SetQRCodeContent (payload )
71+ 
6772	return  payload 
6873}
6974
@@ -77,15 +82,15 @@ func (p *Pix) generateMAI() string {
7782		tags  :=  []string {
7883			p .getValue (TAG_MAI_GUI , BC_GUI ),
7984			p .getValue (TAG_MAI_PIXKEY , p .params .pixKey ),
80- 			p .getValue (TAG_MAI_INFO_ADD , "Gerado por Pix-Utils" ),
81- 			//p.getValue(TAG_MAI_INFO_ADD, p.params.infoAdicional), 
85+ 		}
86+ 		if  len (p .params .aditionalInfo ) >  0  {
87+ 			tags  =  append (tags , p .getValue (TAG_MAI_INFO_ADD , p .params .aditionalInfo ))
8288		}
8389		return  strings .Join (tags , "" )
8490	case  DYNAMIC :
8591		tags  :=  []string {
8692			p .getValue (TAG_MAI_GUI , BC_GUI ),
87- 			p .getValue (TAG_MAI_URL , "https://www.pix.com.br/" ),
88- 			//p.getValue(TAG_MAI_URL, p.params.url), 
93+ 			p .getValue (TAG_MAI_URL , p .params .url ),
8994		}
9095		return  strings .Join (tags , "" )
9196	default :
@@ -111,3 +116,34 @@ func (p *Pix) FindAndReplaceCRC(payload string) string {
111116	payload  =  m .ReplaceAllString (payload , "" )
112117	return  payload  +  p .getCRC16 (payload )
113118}
119+ 
120+ func  (p  * Pix ) Validates () error  {
121+ 	if  p .params .pixKey  ==  ""  {
122+ 		return  errors .New ("pixkey must not be empty" )
123+ 	}
124+ 
125+ 	if  p .params .merchant .name  ==  ""  {
126+ 		return  errors .New ("name must not be empty" )
127+ 	}
128+ 
129+ 	if  p .params .merchant .city  ==  ""  {
130+ 		return  errors .New ("city must not be empty" )
131+ 	}
132+ 
133+ 	if  utf8 .RuneCountInString (p .params .merchant .name ) >  25  {
134+ 		return  errors .New ("name must be at least 25 characters long" )
135+ 	}
136+ 
137+ 	if  utf8 .RuneCountInString (p .params .merchant .city ) >  15  {
138+ 		return  errors .New ("city must be at least 15 characters long" )
139+ 	}
140+ 
141+ 	return  nil 
142+ }
143+ 
144+ func  (p  * Pix ) GenQRCode () ([]byte , error ) {
145+ 	return  qrcode .New (qrcode.QRCodeOptions {
146+ 		Size :    p .params .GetQRCodeSize (),
147+ 		Content : p .params .GetQRCodeContent (),
148+ 	})
149+ }
0 commit comments