openbank

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

README

go-stone-openbank

A Go library to connect with Stone Open Banking API

How to install

go get github.com/stone-co/go-stone-openbank

Example Usage

package main

import (
	openbank "github.com/stone-co/go-stone-openbank"
	"github.com/stone-co/go-stone-openbank/types"
)

func main() {
	clientID := os.Getenv("STONE_CLIENT_ID")
	privKeyPath := os.Getenv("STONE_PRIVATE_KEY")
	consentURL := os.Getenv("STONE_CONSENT_REDIRECT_URL")

	pemPrivKey := readFileContent(privKeyPath)

	client, err := openbank.NewClient(
		openbank.WithClientID(clientID),
		openbank.SetConsentURL(consentURL),
		openbank.WithPEMPrivateKey(pemPrivKey),
		openbank.UseSandbox(),
	//	openbank.EnableDebug(),
	)
	if err != nil {
		log.Fatal(err)
	}

	err := client.Authenticate()
	if err != nil {
		log.Fatal(err)
	}

	consentLink, err := client.ConsentLink("")
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("consent_link: %s\n", consentLink)

	// returns institutions
	allinstitutions, _, err := client.Institution.List(openbank.AllInstitutions)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(len(allinstitutions), allinstitutions[0])

	// returns institutions participating in the SPI. Useful for PIX operations
	SPIinstitutions, _, err := client.Institution.List(openbank.SPIParticipants)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(len(SPIinstitutions), SPIinstitutions[0])

	// returns institutions participating in the STR. Useful for TED operations
	STRinstitutions, _, err := client.Institution.List(openbank.STRParticipants)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(len(STRinstitutions), STRinstitutions[0])

	// return institution by code or ISPB code
	institution, _, err := client.Institution.Get(SPIinstitutions[0].ISPBCode)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(institution)

	accounts, _, err := client.Account.List()
	if err != nil {
		log.Fatal(err)
	}
	for i := range accounts {
		balance, _, err := client.Account.GetBalance(accounts[i].ID)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("Balance: %+v", balance)
 	}
}

func readFileContent(path string) []byte {
	content, _ := ioutil.ReadFile(path)
	return content
}

see full example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

Types

type AccountService

type AccountService struct {
	// contains filtered or unexported fields
}

AccountService handles communication with Stone Openbank API

func (*AccountService) Get

func (s *AccountService) Get(id string) (*types.Account, *Response, error)

Get account info

func (*AccountService) GetBalance

func (s *AccountService) GetBalance(id string) (*types.Balance, *Response, error)

Get Account Balance

func (*AccountService) GetFees

func (s *AccountService) GetFees(accountID string, feeType string) (*types.Fee, *Response, error)

Get Account Fees of FeeType

func (*AccountService) GetStatement

func (s *AccountService) GetStatement(id string) ([]types.Statement, *Response, error)

Get Account Statement

func (*AccountService) GetStatementEntry

func (s *AccountService) GetStatementEntry(id string) (*types.Statement, *Response, error)

Get Statement Entry

func (*AccountService) List

func (s *AccountService) List() ([]types.Account, *Response, error)

List accounts

func (*AccountService) ListFees

func (s *AccountService) ListFees(accountID string) ([]types.Fee, *Response, error)

List Account Fees

type Client

type Client struct {
	AccountURL *url.URL
	ApiBaseURL *url.URL

	StonePublicKeys types.StonePublicKeys

	ClientID           string
	ConsentRedirectURL string

	Sandbox bool

	UserAgent string

	//Services used for comunicating with API
	Institution    *InstitutionService
	Account        *AccountService
	Transfer       *TransferService
	PaymentInvoice *PaymentInvoiceService
	PIXService     *PIXService
	PaymentLink    *PaymentLinkService
	TopUpsService  *TopUpsService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...ClientOpt) (*Client, error)

func (*Client) AddAccountIdHeader added in v1.1.4

func (c *Client) AddAccountIdHeader(req *http.Request, accountId string) error

AddAccountIdHeader add in request the header used in some pix operations and maybe others

func (*Client) AddIdempotencyHeader added in v1.1.4

func (c *Client) AddIdempotencyHeader(req *http.Request, idempotencyKey string) error

AddIdempotencyHeader add in request the header used to realize idempotent operations

func (*Client) ApplyOpts

func (c *Client) ApplyOpts(opts ...ClientOpt)

func (*Client) Authenticate

func (c *Client) Authenticate() error
func (c *Client) ConsentLink(sessionID string) (string, error)

func (*Client) DecryptAndValidateWebhook

func (c *Client) DecryptAndValidateWebhook(encryptedJWE string) ([]byte, error)

func (*Client) DecryptJWE

func (c *Client) DecryptJWE(encryptedBody string) ([]byte, error)

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

func (*Client) NewAPIRequest

func (c *Client) NewAPIRequest(method, pathStr string, body interface{}) (*http.Request, error)

NewAPIRequest creates an API request. A relative URL PATH can be provided in pathStr, which will be resolved to the ApiBaseURL of the Client.

type ClientOpt

type ClientOpt func(*Client)

func EnableDebug

func EnableDebug() ClientOpt

func SetAccountURL added in v1.0.5

func SetAccountURL(newAccountUrl string) (ClientOpt, error)

func SetBaseURL added in v1.0.5

func SetBaseURL(newBaseUrl string) (ClientOpt, error)

func SetConsentURL

func SetConsentURL(url string) ClientOpt

func SetUserAgent

func SetUserAgent(ua string) ClientOpt

func UseSandbox

func UseSandbox() ClientOpt

func WithClientID

func WithClientID(key string) ClientOpt

func WithHttpClient

func WithHttpClient(hc http.Client) ClientOpt

func WithPEMPrivateKey

func WithPEMPrivateKey(pk []byte) ClientOpt

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string `json:"message"`

	// RequestID returned from the API, useful to contact support.
	RequestID string `json:"request_id"`

	TransferError TransferError `json:"transfer_error"`
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type InstitutionContext added in v1.1.0

type InstitutionContext string
const (
	AllInstitutions InstitutionContext = "all"
	SPIParticipants InstitutionContext = "spi"
	STRParticipants InstitutionContext = "str"
)

type InstitutionService added in v1.1.0

type InstitutionService struct {
	// contains filtered or unexported fields
}

func (InstitutionService) Get added in v1.1.0

Get institution info

func (InstitutionService) List added in v1.1.0

List institutions

type PIXService added in v1.1.4

type PIXService struct {
	// contains filtered or unexported fields
}

PIXService handles communication with Stone Openbank API

func (*PIXService) ConfirmPedingPayment added in v1.2.0

func (s *PIXService) ConfirmPedingPayment(input types.ConfirmPendingPaymentInput, idempotencyKey, pixID string) (*Response, error)

ConfirmPedingPayment is a service used to confirm a pending payment.

func (*PIXService) CreateDynamicQRCode added in v1.2.0

func (s *PIXService) CreateDynamicQRCode(input types.CreateDynamicQRCodeInput, idempotencyKey string) (*types.PIXInvoiceOutput, *Response, error)

CreateDynamicQRCode make a bar code payment invoice

func (*PIXService) CreatePedingPayment added in v1.2.0

func (s *PIXService) CreatePedingPayment(input types.CreatePedingPaymentInput, idempotencyKey string) (*types.PendingPaymentOutput, *Response, error)

CreatePedingPayment is a service used to create a pending payment.

func (*PIXService) GetEntries added in v1.2.0

func (s *PIXService) GetEntries(accountID string) (*types.AllPixEntries, *Response, error)

GetEntries is a service used to retrieve all Pix entries of a given account.

func (*PIXService) GetOutboundPix added in v1.1.4

func (s *PIXService) GetOutboundPix(id string) (*types.PIXOutBoundOutput, *Response, error)

GetOutboundPix is a service used to retrieve information details from a Pix.

func (*PIXService) GetQRCodeData added in v1.1.4

func (s *PIXService) GetQRCodeData(input types.GetQRCodeInput) (*types.QRCode, *Response, error)

GetQRCodeData is a service used to retrieve information details from a Pix QRCode.

func (*PIXService) ListDynamicQRCodes added in v1.1.4

func (s *PIXService) ListDynamicQRCodes(accountID string) ([]types.QRCodeDynamic, *Response, error)

ListQRCodeDynamic list the dynamic qrcodes of an account

func (*PIXService) ListKeys added in v1.1.4

func (s *PIXService) ListKeys(accountID string) ([]types.PIXKey, *Response, error)

ListKeys list the PIX keys of an account

type PaymentInvoiceService

type PaymentInvoiceService struct {
	// contains filtered or unexported fields
}

PaymentInvoiceService handlers communication with Stone Openbank API

func (*PaymentInvoiceService) Cancel added in v1.1.4

func (s *PaymentInvoiceService) Cancel(paymentInvoiceID string) (*Response, error)

func (*PaymentInvoiceService) Get

func (s *PaymentInvoiceService) Get(paymentInvoiceID string) (types.PaymentInvoice, *Response, error)

Get return a PaymentInvoice

func (*PaymentInvoiceService) List

func (s *PaymentInvoiceService) List(accountID string) ([]types.PaymentInvoice, *Response, error)

List returns a list of PaymentInvoices

func (*PaymentInvoiceService) PaymentInvoice

func (s *PaymentInvoiceService) PaymentInvoice(input types.PaymentInvoiceInput, idempotencyKey string) (*types.PaymentInvoice, *Response, error)

PaymentInvoice make a bar code payment invoice

type PaymentLinkService added in v1.1.4

type PaymentLinkService struct {
	// contains filtered or unexported fields
}

func (*PaymentLinkService) Cancel added in v1.1.4

func (*PaymentLinkService) Create added in v1.1.4

func (*PaymentLinkService) Get added in v1.1.4

func (s *PaymentLinkService) Get(accountID, orderID string) (types.PaymentLink, *Response, error)

type Response

type Response struct {
	*http.Response
}

type TopUpsService added in v1.1.4

type TopUpsService struct {
	// contains filtered or unexported fields
}

TopUpsService handles communication with Stone Openbank API

func (*TopUpsService) GetValuesFromGameProvider added in v1.1.4

func (s *TopUpsService) GetValuesFromGameProvider(id int) (*types.Products, *Response, error)

GetValuesFromGameProvider list all values from a game provider

func (*TopUpsService) ListGameProviders added in v1.1.4

func (s *TopUpsService) ListGameProviders() (*types.Providers, *Response, error)

ListGameProviders list all game providers

type TransferError added in v1.0.2

type TransferError struct {
	Type             string `json:"type,omitempty"`
	ValidationErrors []struct {
		Error string   `json:"error,omitempty"`
		Path  []string `json:"path,omitempty"`
	} `json:"validation_errors,omitempty"`
	Reason []struct {
		Error string   `json:"error,omitempty"`
		Path  []string `json:"path,omitempty"`
	} `json:"reason,omitempty"`
}

type TransferService

type TransferService struct {
	// contains filtered or unexported fields
}

TransferService handles communication with Stone Openbank API

func (*TransferService) CancelExternal

func (s *TransferService) CancelExternal(transferID string) (*Response, error)

CancelExternal cancels a scheduled external transference

func (*TransferService) CancelInternal

func (s *TransferService) CancelInternal(transferID string) (*Response, error)

CancelInternal cancels a scheduled internal transference

func (*TransferService) DryRunTransfer

func (s *TransferService) DryRunTransfer(input types.TransferInput, idempotencyKey string) (*types.Transfer, *Response, error)

DryRunTransfer simulate an Internal or External Transfer

func (*TransferService) GetExternal

func (s *TransferService) GetExternal(transferID string) (*types.Transfer, *Response, error)

GetExternal returns an external transfer

func (*TransferService) GetInternal

func (s *TransferService) GetInternal(transferID string) (*types.Transfer, *Response, error)

GetInternal returns an internal transfer

func (*TransferService) ListExternal

func (s *TransferService) ListExternal(accountID string) ([]types.Transfer, *Response, error)

ListExternal returns a list of external_transfers

func (*TransferService) ListInternal

func (s *TransferService) ListInternal(accountID string) ([]types.Transfer, *Response, error)

ListInternal returns a list of internal_transfers

func (*TransferService) Transfer

func (s *TransferService) Transfer(input types.TransferInput, idempotencyKey string) (*types.Transfer, *Response, error)

Transfer makes Internal or External Transfer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL