investecOpenAPI

package module
v0.0.0-...-6d9cfae Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 8 Imported by: 0

README

investecOpenAPI

installation

make sure you are in your root of your project folder and you have a go.mod file there if not you just need to create it with

go mod init <project name>
go get -v github.com/t4ke0/investecOpenAPI

Usage

before you start you might need to have the clientID and secret from the API provider. then you are good to proceed.

package main

import (
    ***

	client "github.com/t4ke0/investecOpenAPI"

    ***
)


func main() {
    // testing using sandbox data
	var clientID string = "yAxzQRFX97vOcyQAwluEU6H6ePxMA5eY"
	var secret   string = "4dY0PjEYqoBrZ99r"
	var key      string = "eUF4elFSRlg5N3ZPY3lRQXdsdUVVNkg2ZVB4TUE1ZVk6YVc1MlpYTjBaV010ZW1FdGNHSXRZV05qYjNWdWRITXRjMkZ1WkdKdmVBPT0="
    //

    client.IsDebug = true
    clt := client.NewBankingClient(key, secret, clientID)

    // OAuth to the API
    if err := clt.GetAccessToken(); err != nil {
        log.Fatal(err)
    }

    // Get Accounts.
    accounts, err := clt.GetAccounts()
    if err != nil {
        log.Fatal(err)
    }

    // see the specification of the account type in `api/api.go`
    fmt.Println("Accounts", accounts) 

    // Get Account Balance
    var accountID string = accounts.Data.AccountArr[0].AccountID
    balance, err := clt.GetAccountBalance(accountID)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("balance", balance)

    // Get account transactions
    // you can use fromDate and toData params to filter the transactions.
    // see investecOpenAPI.go file the dates need to have ISO 8601 format.
    transactions, err := clt.GetAccountTransactions(accountID, "", "")
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Println("transactions", transactions)
}

Testing

to Run an example please build example/cmd/main.go

go build example/cmd/main.go
package main

import (
	"encoding/json"
	"fmt"
	"log"

	client "github.com/t4ke0/investecOpenAPI"
	"github.com/t4ke0/investecOpenAPI/api"
)

// sandbox data
var (
	clientID string = "yAxzQRFX97vOcyQAwluEU6H6ePxMA5eY"
	secret   string = "4dY0PjEYqoBrZ99r"
	key      string = "eUF4elFSRlg5N3ZPY3lRQXdsdUVVNkg2ZVB4TUE1ZVk6YVc1MlpYTjBaV010ZW1FdGNHSXRZV05qYjNWdWRITXRjMkZ1WkdKdmVBPT0="
)

func main() {

	// set this to false if you want to test production API
	client.IsDebug = true

	clt := client.NewBankingClient(key, secret, clientID)

	if err := clt.GetAccessToken(); err != nil {
		log.Fatal(err)
	}

	accounts, err := clt.GetAccounts()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("debug accounts %v", accounts)

	// fill in the accountID var with your account id
	var accountID string = accounts.Data.AccountsArr[0].AccountID
	balance, err := clt.GetAccountBalance(accountID)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("debug %v", balance)

	// i'm not using here fromDate or toDate params
	transactions, err := clt.GetAccountTransactions(accountID, "", "")
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("debug transactions %v", transactions)

	beneficiaries, err := clt.GetBeneficiaries()
	if err != nil {
		log.Fatal(err)
	}
	data, _ := json.MarshalIndent(beneficiaries, "", " ")

	fmt.Println(string(data))

	transfermultipleResponse, err := clt.TransferMultiple(accountID, []api.TransferTo{
		api.TransferTo{
			BeneficiaryAccountId: "MTAxOTAwMjQ2MTI2NjA=",
			Amount:               "10.00",
			MyReference:          "Test",
			TheirReference:       "STD Ben Ref",
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	data, _ = json.MarshalIndent(transfermultipleResponse, "", " ")
	fmt.Println(string(data))

	payMultipleResponse, err := clt.PayMultiple(accountID, []api.PaymentMultiple{
		api.PaymentMultiple{
			BeneficiaryAccountId: "MTAxOTAwMjQ2MTI2NjA=",
			Amount:               "10.00",
			MyReference:          "Test",
			TheirReference:       "STD Ben Ref",
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	data, _ = json.MarshalIndent(payMultipleResponse, "", " ")
	fmt.Println(string(data))

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIurl string = "https://openapi.investec.com"
View Source
var IsDebug bool

Functions

This section is empty.

Types

type BankingClient

type BankingClient struct {
	UserCreds   string
	AccessToken string
	// contains filtered or unexported fields
}

func NewBankingClient

func NewBankingClient(key, secret, clientID string) BankingClient

func (*BankingClient) GetAccessToken

func (b *BankingClient) GetAccessToken() error

GetAccessToken

func (BankingClient) GetAccountBalance

func (b BankingClient) GetAccountBalance(accountId string) (api.Balance, error)

GetAccountBalance

func (BankingClient) GetAccountTransactions

func (b BankingClient) GetAccountTransactions(accountID string, fromDate, toDate string) (api.Transactions, error)

GetAccountTransactions gets account transactions you can filter the result using the fromDate and toDate parameters and the dates need to follow ISO 8601 time format

func (BankingClient) GetAccounts

func (b BankingClient) GetAccounts() (api.Accounts, error)

GetAccounts

func (BankingClient) GetBeneficiaries

func (b BankingClient) GetBeneficiaries() (api.Beneficiaries, error)

GetBeneficiaries

func (BankingClient) PayMultiple

func (b BankingClient) PayMultiple(accountID string, payments []api.PaymentMultiple) (api.MultiplePaymentResponse, error)

PayMultiple

func (BankingClient) TransferMultiple

func (b BankingClient) TransferMultiple(accountID string, transfers []api.TransferTo) (api.MultipleTransfersResponse, error)

TransferMultiple

Directories

Path Synopsis
example
cmd command

Jump to

Keyboard shortcuts

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