Skip to content

Commit

Permalink
Change for optional value amount
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagozs committed Jan 28, 2022
1 parent 8038294 commit 53e9e37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 1 addition & 4 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import (

func main() {
opts := []pix.Options{
pix.OptPixKey("28707746806"),
pix.OptDescription("Teste"),
pix.OptPixKey("11999821234"),
pix.OptMerchantName("Thiago Zilli Sarmento"),
pix.OptMerchantCity("Ararangua"),
pix.OptAmount("1.00"),
pix.OptAditionalInfo("gerado por go-pixgen"),
pix.OptKind(pix.STATIC),
}

Expand Down
19 changes: 12 additions & 7 deletions pix/pix.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,33 @@ func (p *Pix) GenPayload() string {
p.getValue(TAG_INIT_METHOD, "11"),
p.getValue(TAG_MAI, p.generateMAI()),
p.getValue(TAG_MCC, "0000"),
p.getValue(TAG_TRANSACTION_CURRENCY, "986"),
p.getValue(TAG_TRANSACTION_AMOUNT, p.params.amount),
p.getValue(TAG_COUNTRY_CODE, "BR"),
p.getValue(TAG_TRANSACTION_CURRENCY, "986")}
if len(p.params.amount) > 0 {
tags = append(tags, p.getValue(TAG_TRANSACTION_AMOUNT, p.params.amount))
}
tags = append(tags, p.getValue(TAG_COUNTRY_CODE, "BR"),
p.getValue(TAG_MERCHANT_NAME, p.params.merchant.name),
p.getValue(TAG_MERCHANT_CITY, p.params.merchant.city),
p.getValue(TAG_ADDITIONAL_DATA, p.generateAdditionalData()),
p.getValue(TAG_CRC, "0000"),
}
)
case DYNAMIC:
tags = []string{
p.getValue(TAG_INIT, "01"),
p.getValue(TAG_INIT_METHOD, "11"),
p.getValue(TAG_MAI, p.generateMAI()),
p.getValue(TAG_MCC, "0000"),
p.getValue(TAG_TRANSACTION_CURRENCY, "986"),
p.getValue(TAG_TRANSACTION_AMOUNT, p.params.amount),
p.getValue(TAG_COUNTRY_CODE, "BR"),
}
if len(p.params.amount) > 0 {
tags = append(tags, p.getValue(TAG_TRANSACTION_AMOUNT, p.params.amount))
}
tags = append(tags, p.getValue(TAG_COUNTRY_CODE, "BR"),
p.getValue(TAG_MERCHANT_NAME, p.params.merchant.name),
p.getValue(TAG_MERCHANT_CITY, p.params.merchant.city),
p.getValue(TAG_ADDITIONAL_DATA, p.generateAdditionalData()),
p.getValue(TAG_CRC, "0000"),
}
)
}

payload := strings.Join(tags, "")
Expand Down

0 comments on commit 53e9e37

Please sign in to comment.