Skip to content

Commit

Permalink
Genral fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagozs committed Jan 28, 2022
1 parent b26d8c3 commit 8038294
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
42 changes: 42 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 5 additions & 5 deletions pix/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pix/pix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8038294

Please sign in to comment.