diff --git a/examples/main.go b/examples/main.go new file mode 100644 index 0000000..51103ce --- /dev/null +++ b/examples/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "fmt" + + "github.com/thiagozs/go-pixgen/pix" +) + +func main() { + opts := []pix.Options{ + pix.OptPixKey("28707746806"), + pix.OptDescription("Teste"), + pix.OptMerchantName("Thiago Zilli Sarmento"), + pix.OptMerchantCity("Ararangua"), + pix.OptAmount("1.00"), + pix.OptAditionalInfo("gerado por go-pixgen"), + pix.OptKind(pix.STATIC), + } + + p, err := pix.New(opts...) + if err != nil { + fmt.Println(err.Error()) + return + } + + if err := p.Validates(); err != nil { + fmt.Println(err.Error()) + return + } + + cpy := p.GenPayload() + + fmt.Printf("Copy and Paste: %s\n", cpy) + + // bts, err := p.GenQRCode() + // if err != nil { + // fmt.Println(err.Error()) + // return + // } + + // fmt.Printf("QRCode: %b\n", bts) +} diff --git a/pix/options.go b/pix/options.go index 8bb9b1e..be38f3d 100644 --- a/pix/options.go +++ b/pix/options.go @@ -14,7 +14,7 @@ func (pix PixKind) String() string { type Options func(o *OptionsParams) error type OptionsParams struct { - id string + txId string pixKey string description string amount string @@ -59,9 +59,9 @@ func OptKind(kind PixKind) Options { } } -func OptId(id string) Options { +func OptTxId(id string) Options { return func(o *OptionsParams) error { - o.id = id + o.txId = id return nil } } @@ -103,8 +103,8 @@ func OptAmount(amount string) Options { // ------------- getters -func (o *OptionsParams) GetId() string { - return o.id +func (o *OptionsParams) GetTxId() string { + return o.txId } func (o *OptionsParams) GetPixKey() string { diff --git a/pix/pix.go b/pix/pix.go index 80ddb46..c7e6609 100644 --- a/pix/pix.go +++ b/pix/pix.go @@ -102,8 +102,8 @@ func (p *Pix) generateMAI() string { func (p *Pix) generateAdditionalData() string { txid := "***" - if len(p.params.id) > 0 { - txid = p.params.id + if len(p.params.txId) > 0 { + txid = p.params.txId } return p.getValue(TAG_TXID, txid) }