🌟 Community-Powered Repository 🌟

This repository is crafted with ❤️ by our talented community members. It's a space for everyone to use, contribute to, and share. While it aligns with the spirit of our community, please note that this repo is not directly endorsed or supported by Investec. Always exercise caution and discretion when using or contributing to community-driven projects.

InvestecOpenApi Client

Gem Version

A simple client wrapper for the Investec Open API.

Features:

  • Authorize access via OAuth
  • Retrieve accounts
  • Retrieve transactions per account
  • Retrieve balances per account
  • Transfer between accounts

Installation

Add this line to your application's Gemfile:

gem 'investec_open_api'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install investec_open_api

Configuration

To configure the client, create a new file in the root of your directory called .env and place the following:

API_KEY='YOUR API KEY'
CLIENT_ID='YOUR CLIENT ID'
CLIENT_SECRET='YOUR CLIENT SECRET'

Note: you will need to register to get the above credentials. Follow the steps in Enrolment in the documentation. You can also test in sandbox mode (see Running in Sandbox Mode).

Once you have set this up, configure the client using:

InvestecOpenApi.configuration do |config|
    config.api_key       = ENV['API_KEY']
    config.client_id     = ENV['CLIENT_ID']
    config.client_secret = ENV['CLIENT_SECRET']
    config.base_url      = ENV['BASE_URL'] # optional
end

For Rails apps, create a new initializer called investec_open_api.rb in config/initializers:

Usage

To use the wrapper, create an instance of InvestecOpenApi::Client and then authenticate with your credentials:

client = InvestecOpenApi::Client.new
client.authenticate!

Accounts

Calling accounts returns all of the associated accounts:

accounts = client.accounts
 = accounts.first

List transactions for an account

You can list your transactions by passing the account id into the transactions method:

# The dates are optional
client.transactions(.id, { fromDate: "2024-01-01", toDate: "2024-01-31" })

To list pending transactions use the following:

# The dates are optional
client.pending_transactions(.id, { fromDate: "2024-01-01", toDate: "2024-01-31" })

Get Balance for an account

Pass the account_id into the balance method to get the latest account balances:

client.balance(.id)

Inter-account transfers

To transfer between accounts, create a InvestecOpenApi::Models::Transfer object and pass it into the transfer_multiple method:

transfer = InvestecOpenApi::Models::Transfer.new(
  ,
  1000.00, # amount as a Float
  "My reference - of the account transferring from",
  "Their reference - of the account transferring to"
)
client.transfer_multiple(
  .id,
  [ transfer ],
  profile_id # optional
)

Running in Sandbox mode

To run in sandbox mode, use the following configuration:

InvestecOpenApi.configuration do |config|
  config.api_key = "eUF4elFSRlg5N3ZPY3lRQXdsdUVVNkg2ZVB4TUE1ZVk6YVc1MlpYTjBaV010ZW1FdGNHSXRZV05qYjNWdWRITXRjMkZ1WkdKdmVBPT0="
  config.client_id = "yAxzQRFX97vOcyQAwluEU6H6ePxMA5eY"
  config.client_secret = "4dY0PjEYqoBrZ99r"
  config.base_url = "https://openapisandbox.investec.com/"
end

You can now test the API without affecting your actual account.

License

The gem is available as open source under the terms of the MIT License.