A class which encapsulates the authenticated user for all Plaid products.
- A
- B
- C
- D
- E
- F
- I
- L
- M
- N
- R
- T
- U
[R] | access_token | The access token for authenticated user. |
[R] | accounts | The Array of Account instances providing accounts information for the user. |
[R] | initial_transactions | The Array of Transactions provided by initial call to ::create. If the :login_only option of ::create is set to false, the initial 30-day transactional data are returned during the API call. This attribute contains them. |
[R] | mfa | The MFA data (Hash or Array of Hash) or nil, if no MFA required. E.g. [{ question: “What was the name of your first pet?” }] or [{ mask: 't..t@plaid.com', type: 'email' }, { mask: 'xxx-xxx-5309', type: 'phone' }] or { message: 'Code sent to xxx-xxx-5309' } |
[R] | mfa_type | The Symbol MFA type to be used (or nil, if no MFA required). E.g. :questions, :list, or :device. |
[R] | processor_token | The processor token for a given account and authenticated user. |
[R] | product | The current product. Provides a context for update and delete calls. See Plaid::PRODUCTS. |
[R] | stripe_bank_account_token | The String stripe bank account token. This field is set when you use ::exchange_token to convert Link public_token into an access token suitable for Plaid API. |
Create (add) a user.
- product
-
The Symbol product name you are adding the user to, one of Plaid::PRODUCTS (e.g. :info, :connect, etc.).
- institution
-
The String/Symbol financial institution type that you want to access (e.g. :wells).
- username
-
The String username associated with the financial institution.
- password
-
The String password associated with the financial institution.
- pin
-
The String PIN number associated with the financial institution (default: nil).
- options
-
the Hash options (default: {}):
- :list
-
The Boolean flag which would request the available send methods if the institution requires code-based MFA credential (default: false).
- :webhook
-
The String webhook URL. Used with :connect, :income, and :risk products (default: nil).
- :pending
-
The Boolean flag requesting to return pending transactions. Used with :connect product (default: false).
- :login_only
-
The Boolean option valid for initial authentication only. If set to false, the initial request will return transaction data based on the start_date and end_date.
- :start_date
-
The start Date from which to return transactions (default: 30 days ago).
- :end_date
-
The end Date to which transactions will be collected (default: today).
- client
-
The Plaid::Client instance used to connect to the API (default is to use global Plaid client - Plaid.client).
Returns
Returns a Plaid::User instance.
Source: show
# File lib/plaid/user.rb, line 86 def self.create(product, institution, username, password, pin: nil, options: nil, client: nil) check_product product payload = { username: username, password: password, type: institution.to_s } payload[:pin] = pin if pin payload[:options] = MultiJson.dump(options) if options conn = Connector.new(product, auth: true, client: client) resp = conn.post(payload) new product, response: resp, mfa: conn.mfa?, client: client end
Exchange a Link public_token for an API access_token.
The account_id parameter is required if you wish to receive a Stripe bank account token.
- public_token
-
The String Link public_token.
- account_id
-
The String account ID.
- product
-
The Symbol product name (default: :connect).
- client
-
The Plaid::Client instance used to connect to the API (default is to use global Plaid client - Plaid.client).
Returns
Returns a new User with access token obtained from Plaid and default product set to product. #stripe_bank_account_token for this user instance will contain the Stripe token.
Source: show
# File lib/plaid/user.rb, line 131 def self.exchange_token(public_token, account_id = nil, product: :connect, client: nil) check_product product payload = { public_token: public_token } payload[:account_id] = account_id if account_id response = Connector.new(:exchange_token, auth: true, client: client) .post(payload) stripe_token = account_id && response['stripe_bank_account_token'] new product, response: response, client: client, stripe_token: stripe_token end
Get User instance in case user access token is known.
No requests are made, but the returned User instance is ready to be used.
- product
-
The Symbol product name you want to use, one of Plaid::PRODUCTS (e.g. :info, :connect, etc.).
- token
-
The String access token for the user.
- client
-
The Plaid::Client instance used to connect to the API (default is to use global Plaid client - Plaid.client).
Returns
Returns a Plaid::User instance.
Source: show
# File lib/plaid/user.rb, line 113 def self.load(product, token, client: nil) new check_product(product), access_token: token, client: client end
Get auth information for the user (routing numbers for accounts).
Not only this method returns the new data, but it updates self.accounts as well.
The method does a POST /auth/get request.
- sync
-
The Boolean flag which, if true, causes auth information to be rerequested from the server. Otherwise cached version is returned, if it exists.
Returns
Returns an Array of Account with numbers baked in.
Source: show
# File lib/plaid/user.rb, line 370 def auth(sync: false) if sync || !@accounts || !@accounts[0] || !@accounts[0].numbers response = Connector.new(:auth, :get, auth: true, client: client) .post(access_token: access_token) update_accounts(response) end accounts end
Get current account balance.
Does a POST /balance request.
Returns
Returns an Array of Plaid::Account.
Source: show
# File lib/plaid/user.rb, line 440 def balance response = Connector.new(:balance, auth: true, client: client) .post(access_token: access_token) update_accounts(response) end
Delete the user.
Makes a delete request and freezes self to prevent further modifications to the object.
Returns
Returns self.
Source: show
# File lib/plaid/user.rb, line 315 def delete Connector.new(product, auth: true, client: client) .delete(access_token: access_token) freeze end
Get the current user tied to another product.
No API request is made, just the current product is changed.
- product
-
The Symbol product you are selecting, one of Plaid::PRODUCTS.
See also #upgrade.
Returns
Returns a new User instance.
Source: show
# File lib/plaid/user.rb, line 354 def for_product(product) User.load product, access_token, client: client end
Get income information for the user.
Does a POST /income/get request.
- sync
-
The Boolean flag which, if true, causes income information to be rerequested from the server. Otherwise cached version is returned, if it exists.
Returns
Returns a Plaid::Income instance.
Source: show
# File lib/plaid/user.rb, line 408 def income(sync: false) if sync || !@income parse_response(Connector.new(:income, :get, auth: true, client: client) .post(access_token: access_token)) end @income end
Get info for the user.
Does a POST /info/get request.
- sync
-
The Boolean flag which, if true, causes information to be rerequested from the server. Otherwise cached version is returned, if it exists.
Returns
Returns a Plaid::Info instance.
Source: show
# File lib/plaid/user.rb, line 390 def info(sync: false) if sync || !@info parse_response(Connector.new(:info, :get, auth: true, client: client) .post(access_token: access_token)) end @info end
Find out if MFA is required based on last request.
After calling e.g. ::create you might need to make an additional authorization step if MFA is required by the financial institution.
Returns
Returns true if this step is needed, a falsey value otherwise.
Source: show
# File lib/plaid/user.rb, line 174 def mfa? @mfa_required end
Submit MFA information.
- info
-
The String with MFA information (default: nil).
- send_method
-
The Hash with code send method information. E.g. { type: 'phone' } or { mask: '123-…-4321' }. Default is first available email.
- options
-
the Hash options (default: {}):
- :list
-
The Boolean flag which would request the available send methods if the institution requires code-based MFA credential (default: false).
- :webhook
-
The String webhook URL. Used with :connect, :income, and :risk products (default: nil).
- :pending
-
The Boolean flag requesting to return pending transactions. Used with :connect product (default: false).
- :login_only
-
The Boolean option valid for initial authentication only. If set to false, the initial request will return transaction data based on the start_date and end_date.
- :start_date
-
The start Date from which to return transactions (default: 30 days ago).
- :end_date
-
The end Date to which transactions will be collected (default: today).
Returns
Returns true if whole MFA process is completed, false otherwise.
Source: show
# File lib/plaid/user.rb, line 204 def mfa_step(info = nil, send_method: nil, options: nil) payload = { access_token: access_token } payload[:mfa] = info if info if options || send_method options = {} unless options options[:send_method] = send_method if send_method payload[:options] = MultiJson.dump(options) end conn = Connector.new(product, :step, auth: true) # Use PATCH if we are in context of User#update. response = if @mfa_patch conn.patch(payload) else conn.post(payload) end @mfa_required = conn.mfa? parse_response(response) end
Get risk data for the user's accounts.
Does a POST /risk/get request.
- sync
-
The Boolean flag which, if true, causes risk information to be rerequested from the server. Otherwise cached version is returned, if it exists.
Returns
Returns an Array of accounts with risk attribute set.
Source: show
# File lib/plaid/user.rb, line 426 def risk(sync: false) if sync || !@accounts || !@accounts[0] || !@accounts[0].risk parse_response(Connector.new(:risk, :get, auth: true, client: client) .post(access_token: access_token)) end @accounts end
Get transactions.
Does a /connect/get call. Updates self.accounts with latest information.
- pending
-
the Boolean flag requesting to return pending transactions.
- account_id
-
the String Account ID (default: nil). If this argument is present, only transactions for given account will be requested.
- start_date
-
The start Date (inclusive).
- end_date
-
The end Date (inclusive).
Returns
Returns an Array of Transaction records.
Source: show
# File lib/plaid/user.rb, line 237 def transactions(pending: false, account_id: nil, start_date: nil, end_date: nil) options = { pending: pending } options[:account] = account_id if account_id options[:gte] = start_date.to_s if start_date options[:lte] = end_date.to_s if end_date response = Connector.new(:connect, :get, auth: true, client: client) .post(access_token: access_token, options: MultiJson.dump(options)) update_accounts(response) build_objects(response['transactions'], Transaction) end
Update user credentials.
Updates the user credentials for the current product. See #for_product.
- username
-
The String username associated with the financial institution.
- password
-
The String password associated with the financial institution.
- pin
-
The String PIN number associated with the financial institution (default: nil).
Returns
Returns self.
Source: show
# File lib/plaid/user.rb, line 264 def update(username, password, pin = nil) payload = { access_token: access_token, username: username, password: password } payload[:pin] = pin if pin conn = Connector.new(product, auth: true, client: client) resp = conn.patch(payload) if conn.mfa? @mfa_required = true end parse_response(resp) # A note for User#mfa_step to send PATCH request too @mfa_patch = true self end
Create or update the webhook for Connect.
Does a PATCH /connect request.
- webhook
-
The String with webhook URL.
Returns
Returns self.
Source: show
# File lib/plaid/user.rb, line 295 def update_webhook(webhook) raise ArgumentError, 'User#update_webhook only supported by Connect!' unless product == :connect payload = { access_token: access_token, options: MultiJson.dump(webhook: webhook) } parse_response(Connector.new(:connect, auth: true, client: client) .patch(payload)) self end
Upgrade the user.
For an existing user that has been added via any of products (:connect, :auth, :income, :info, or :risk), you can upgrade that user to have functionality with other products.
Does a POST /upgrade request.
See also #for_product.
- product
-
The Symbol product name you are upgrading the user to, one of Plaid::PRODUCTS.
Returns
Returns another User record with the same access token, but tied to the new product.
Source: show
# File lib/plaid/user.rb, line 337 def upgrade(product) payload = { access_token: access_token, upgrade_to: product.to_s } response = Connector.new(:upgrade, auth: true, client: client) .post(payload) User.new product, response: response, client: client end
[R] | client | The Plaid::Client instance used to make queries. |
Initialize a User instance.
- product
-
The Symbol product name.
- #access_token
-
The String access token obtained from Plaid.
- response
-
The Hash response body to parse.
- mfa
-
The Boolean flag indicating that response body contains an MFA response.
- stripe_token
-
The String stripe bank account token.
- client
-
The Plaid::Client instance used to connect to the API (default is to use global Plaid client - Plaid.client).
Source: show
# File lib/plaid/user.rb, line 156 def initialize(product, access_token: nil, response: nil, mfa: nil, stripe_token: nil, client: nil) @product = product @client = client @access_token = access_token if access_token @mfa_required = mfa @stripe_bank_account_token = stripe_token @accounts = @initial_transactions = @info = @risk = @income = nil parse_response(response) if response end