Skip to content

libercapital/pix-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installing

Use go get to retrieve the SDK to add it to your GOPATH workspace, or project's Go module dependencies.

go get github.com/libercapital/pix-sdk-go

Examples

package main

import (
	"log"
	"time"

	pixsdk "github.com/libercapital/pix-sdk-go"
	"github.com/libercapital/pix-sdk-go/services/pix"
)

func main() {
	var pixService = pixsdk.NewService(pixsdk.Config{
		AuthURL:      "https://api.pix.com.br/oauth/token",
		BaseURL:      "https://api.pix.com.br/v2",
		ClientId:     "client-id",
		ClientSecret: "client-secret",
		//Certificate: use 	tls.LoadX509KeyPair() for load certificate if you need,
	})

	// Find Pix by EndToEndId

	px, err := pixService.FindPix("E879247924E724")
	if err != nil {
		log.Fatal(err.Error())
	}

	log.Printf("E2E: %s, TxId: %s, Data: %s, Valor: %s\n", px.E2EId, px.TxId, px.Time.Format(time.RFC3339), px.Value)

	// List Pix by between date
	listPix, err := pixService.ListPix(pix.ListPix{
		pix.StartDate(time.Now().AddDate(0, 0, -1)),
		pix.EndDate(time.Now()),
	})
	if err != nil {
		log.Fatal(err.Error())
	}
	for _, px := range listPix.Pix {
		log.Printf("E2E: %s, TxId: %s, Data: %s, Valor: %s\n", px.E2EId, px.TxId, px.Time.Format(time.RFC3339), px.Value)
	}
}