• Stars
    star
    225
  • Rank 177,187 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 11 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby bindings for Plaid

plaid-ruby Circle CI Gem Version

The official Ruby bindings for the Plaid API. It's generated from our OpenAPI schema.

Installation

Add this line to your application's Gemfile:

gem 'plaid'

And then execute:

$ bundle

Or install it yourself as:

$ gem install plaid

The gem supports Ruby 3.0.0+ only.

Versioning

Versions > 14 are generated from our OpenAPI schema. For previous non-generated versions, check out 13.2.0.

Each major version of plaid-ruby targets a specific version of the Plaid API:

API version plaid-ruby release
2020-09-14 (latest) 12.x.x and higher
2019-05-29 11.x.x, 10.x.x, 9.x.x, 8.x.x, 7.x.x
2018-05-22 6.x.x
2017-03-08 5.x.x

For information about what has changed between versions and how to update your integration, head to the version changelog.

The plaid-ruby client library is typically updated on a monthly basis. The canonical source for the latest version number is the client library changelog.

Usage

This gem wraps the Plaid API, which is fully described in the documentation and in the plaid-openapi spec.

Creating a Plaid client

Create an instance of the client using the client_id and secret from your Plaid dashboard along with your environment of choice:

require 'plaid'

configuration = Plaid::Configuration.new
configuration.server_index = Plaid::Configuration::Environment["sandbox"]
configuration.api_key["PLAID-CLIENT-ID"] = "***"
configuration.api_key["PLAID-SECRET"] = "***"

api_client = Plaid::ApiClient.new(
  configuration
)

client = Plaid::PlaidApi.new(api_client)

The server_index field is the environment which the client will be running in. Your choices for the server_index field include:

  • Plaid::Configuration::Environment["sandbox"] allows you to do your initial integrations tests against preloaded data without being billed or making expensive API calls. More information about using the API sandbox can be found on the API Sandbox documentation.
  • Plaid::Configuration::Environment["development"] allows you to test against both real and test accounts without being billed. More information about Plaid test accounts can be found in our API documentation.
  • Plaid::Configuration::Environment["production"] is the production environment where you can launch your production ready application and be charged for your Plaid usage.

Tuning Faraday

The gem uses Faraday to wrap HTTPS connections, which allows you to tune certain params:

configuration = Plaid::Configuration.new
api_client = Plaid::ApiClient.new(
  configuration
)
api_client.connection.options[:timeout] = 60*20 # 20 minutes

To use custom middleware, reinitialize the Faraday::Connection object:

configuration = Plaid::Configuration.new
api_client = Plaid::ApiClient.new(configuration)
api_client.create_connection do |builder|
  builder.use Faraday::Response::Logger
end

Data type differences from API and from previous versions

Dates

Dates and datetimes in requests, which are represented as strings in the API and in previous client library versions, are represented in this version of the Ruby client library as Ruby Date or DateTime objects.

Time zone information is required for request fields that accept datetimes. Failing to include time zone information (or passing in a string, instead of a Date or DateTime object) will result in an error. See the following examples for guidance on Date and DateTime usage.

If the API reference documentation for a field specifies format: date, any of following are acceptable:

require 'date'

# Not an exhaustive list of possible options
a = Date.new(2022, 5, 5)
b = Date.new(2022, 5, 5).to_date
c = Date.parse('2022-05-05')
d = Date.parse('2022-05-05').to_date
e = Date.today

If the API reference documentation for a field specifies format: date-time, either of the following are acceptable:

require 'time'

# Not an exhaustive list of possible options
a = Time.parse("2022-05-06T22:35:49Z").to_datetime
b = Date.parse("2022-05-06T22:35:49Z").to_datetime

Examples

Create a new link_token

# Grab the client_user_id by searching for the current user in your database
user = User.find_by!(email: '***')
client_user_id = user.id

# Create the link_token with all of your configurations
link_token_create_request = Plaid::LinkTokenCreateRequest.new({
  :user => { :client_user_id => client_user_id.to_s },
  :client_name => 'My app',
  :products => %w[auth transactions],
  :country_codes => ['US'],
  :language => 'en'
})

link_token_response = client.link_token_create(
  link_token_create_request
)

# Pass the result to your client-side app to initialize Link
#  and retrieve a public_token
link_token = link_token_response.link_token

Exchanging a Link public_token for a Plaid access_token

If you have a Link public token, use this function to get an access_token: client.item_public_token_exchange(request)

An example of the function's usage if you have a public_token in hand:

request = Plaid::ItemPublicTokenExchangeRequest.new
request.public_token = public_token

response = client.item_public_token_exchange(request)
access_token = response.access_token

Deleting an item

request = Plaid::ItemPublicTokenExchangeRequest.new
request.public_token = public_token

response = client.item_public_token_exchange(request)
access_token = response.access_token

# Provide the access_token for the Item you want to remove
item_remove_request = Plaid::ItemRemoveRequest.new
item_remove_request.access_token = access_token

client.item_remove(item_remove_request)

Get paginated transactions (preferred method)

request = Plaid::ItemPublicTokenExchangeRequest.new
request.public_token = public_token

response = client.item_public_token_exchange(request)
access_token = response.access_token

transactions_sync_request = Plaid::TransactionsSyncRequest.new
transactions_sync_request.access_token = access_token

transaction_response = client.transactions_sync(transactions_sync_request)
transactions = transaction_response.added

# the transactions in the response are paginated, so make multiple calls while
# updating the cursor to retrieve all transactions
while transaction_response.has_more
  transactions_sync_request = Plaid::TransactionsSyncRequest.new
  transactions_sync_request.access_token = access_token
  transactions_sync_request.cursor = transaction_response.next_cursor

  transaction_response = client.transactions_sync(transactions_sync_request)
  transactions += transaction_response.added
end

Get paginated transactions (older method)

request = Plaid::ItemPublicTokenExchangeRequest.new
request.public_token = public_token

response = client.item_public_token_exchange(request)
access_token = response.access_token

transactions_get_request = Plaid::TransactionsGetRequest.new
transactions_get_request.access_token = access_token
transactions_get_request.start_date = "2020-01-01"
transactions_get_request.end_date = "2021-01-01"

transaction_response = client.transactions_get(transactions_get_request)
transactions = transaction_response.transactions

# the transactions in the response are paginated, so make multiple calls while
# increasing the offset to retrieve all transactions
while transactions.length < transaction_response.total_transactions
  options_payload = {}
  options_payload[:offset] = transactions.length

  transactions_get_request = Plaid::TransactionsGetRequest.new
  transactions_get_request.access_token = access_token
  transactions_get_request.start_date = "2020-01-01"
  transactions_get_request.end_date = "2021-01-01"
  transactions_get_request.options = options_payload

  transaction_response = client.transactions_get(transactions_get_request)
  transactions += transaction_response.transactions
end

Obtaining Item-related data

If you have an access_token, you can use following code to retreive data:

request = Plaid::ItemPublicTokenExchangeRequest.new
request.public_token = public_token

response = client.item_public_token_exchange(request)
access_token = response.access_token

auth_get_request = Plaid::AuthGetRequest.new
auth_get_request.access_token = access_token

auth_response = client.auth_get(auth_get_request)
auth = auth_response.auth

There are also a number of other methods you can use to retrieve data:

  • client.accounts_get(Plaid::AccountsGetRequest.new({:access_token => access_token, ...})): accounts
  • client.accounts_balance_get(Plaid::AccountsBalanceGetRequest.new({:access_token => access_token, ...})): real-time balances
  • client.auth_get(Plaid::AuthGetRequest.new({:access_token => access_token, ...})): auth
  • client.identity_get(Plaid::IdentityGetRequest.new({:access_token => access_token, ...})): identity
  • client.transactions_get(Plaid::TransactionsGetRequest.new({:access_token => access_token, ...})): transactions
  • client.investments_transactions_get(Plaid::InvestmentsTransactionsGetRequest.new({:access_token => access_token, ...})): investment-account transactions
  • client.investments_holdings_get(Plaid::InvestmentsHoldingsGetRequest.new({:access_token => access_token, ...})): investment-account holdings

All of these methods return appropriate data. More information can be found on the API documentation.

Create a Stripe bank_account_token

Exchange a Plaid Link public_token for an API access_token and a Stripe bank_account_token:

request = Plaid::ItemPublicTokenExchangeRequest.new
request.public_token = public_token

response = client.item_public_token_exchange(request)
access_token = response.access_token

processor_token_create_request = Plaid::ProcessorStripeBankAccountTokenCreateRequest.new
processor_token_create_request.access_token = access_token
processor_token_create_request.account_id = '[Account ID]'

stripe_response = client.processor_stripe_bank_account_token_create(processor_token_create_request)
bank_account_token = stripe_response.stripe_bank_account_token

Categories

You can request category information:

categories = client.categories_get             # Array of all known categories

Institutions

Financial institution information is available as shown below where the function arguments represent count and offset:

institutions_get_request = Plaid::InstitutionsGetRequest.new({
  :count => 3,
  :offset => 1,
  :country_codes => ["US"],
})

response = client.institutions_get(institutions_get_request)

Errors

Any methods making API calls will result in an exception raised unless the response code is "200: Success" or "210: MFA Required".

Plaid::ApiError is returned in response to API internal server errors.

Read more about response codes and their meaning in the Plaid documentation.

Response Objects

All API calls return a response object that is accessible only with dot notation (i.e., response.foo.bar) and not with bracket notation. Expected keys for all types of responses are defined, and any attempt to access an unknown key will cause NoMethodError exception.

Contributing

Bug reports are welcome on GitHub at https://github.com/plaid/plaid-ruby. See also contributing guidelines. As the library is auto-generated, pull requests are automatically closed.

License

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

Legacy API

If you're looking for a Ruby client that works with the legacy Plaid API, use the plaid-legacy gem.

More Repositories

1

quickstart

Get up and running with Plaid Link and the API in minutes
TypeScript
537
star
2

plaid-node

Node bindings for Plaid
TypeScript
521
star
3

pattern

An example end-to-end Plaid integration to create items and fetch transaction data
TypeScript
441
star
4

plaid-python

Python bindings for Plaid
Python
426
star
5

plaid-postman

Postman collection for the Plaid API
HTML
315
star
6

react-plaid-link

React bindings for Plaid Link
TypeScript
264
star
7

deprecated-link

This repository is now deprecated. To integrate with Plaid, visit the docs.
261
star
8

plaid-go

go bindings for Plaid
Go
196
star
9

deprecated-async-problem

🔀 Solutions and non-solutions to JavaScript's async problem
JavaScript
186
star
10

react-native-plaid-link-sdk

Plaid Link for React Native
TypeScript
170
star
11

plaid-java

Java bindings for Plaid
Java
129
star
12

plaid-link-ios

Plaid Link iOS SDK
Objective-C
116
star
13

plaid-link-android

Plaid Link Android SDK
Kotlin
100
star
14

tiny-quickstart

A minimal quickstart demonstrating Plaid Link, Balances, and OAuth
JavaScript
77
star
15

plaid-openapi

API version 2020-09-14
74
star
16

support

Plaid Support
66
star
17

plaid-link-examples

Plaid Link Webview, ReactNative examples
Objective-C
60
star
18

pattern-account-funding

Sample code to demonstrate Plaid-powered account funding use cases using the Auth, Identity, and Balance APIs. Includes examples of using Auth partners for end-to-end funds transfers.
TypeScript
44
star
19

envvar

Derive JavaScript values from environment variables
JavaScript
37
star
20

npmserve

fast npm installs for slow clients
Shell
36
star
21

npmserve-server

fast npm installs for slow clients
JavaScript
27
star
22

go-envvar

A go library for managing environment variables. Maps to typed values, supports required and optional vars with defaults.
Go
25
star
23

idv-quickstart

Get up and running with Plaid Identity Verification in minutes
CSS
22
star
24

tutorial-resources

Sample apps and material to go along with Plaid's tutorials
JavaScript
18
star
25

income-sample

Sample app for Income
TypeScript
15
star
26

account-funding-tutorial

TypeScript
13
star
27

sandbox-custom-users

JSON files specifying custom users suitable for testing Plaid integrations on Sandbox
Python
13
star
28

nockingbird

Declarative HTTP mocking (for use with Nock)
CoffeeScript
13
star
29

core-exchange

The Core Exchange spec and generated server code
JavaScript
12
star
30

pattern-transfers

TypeScript
11
star
31

payment-initiation-pattern-app

Payment Initiation demo app for Europe, based on Plaid Pattern
TypeScript
6
star
32

credit-attributes

Attributes that can be calculated using Plaid's credit products
Python
4
star
33

plaid-node-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
JavaScript
4
star
34

assets-attributes

Attributes that can be calculated using a Plaid Asset Report
Python
3
star
35

plaid-java-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
Java
3
star
36

plaid-python-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
Python
3
star
37

plaid-ruby-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
Ruby
2
star
38

.github

1
star
39

plaid-go-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
1
star