openbank

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: GPL-3.0 Imports: 20 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)

	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

	Token string

	//Services used for comunicating with API
	Account        *AccountService
	Transfer       *TransferService
	PaymentInvoice *PaymentInvoiceService
	// contains filtered or unexported fields
}

func NewClient

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

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 PaymentInvoiceService

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

PaymentInvoiceService handlers communication with Stone Openbank API

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 Response

type Response struct {
	*http.Response
}

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