Class: PlaidRails::LinkController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PlaidRails::LinkController
- Defined in:
- app/controllers/plaid_rails/link_controller.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#update ⇒ Object
updates the access token after changing password with institution.
Instance Method Details
#authenticate ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/plaid_rails/link_controller.rb', line 6 def authenticate begin @exchange_token = Plaid::User.exchange_token(link_params[:public_token]) @params = link_params.merge!(token: link_params[:public_token]) rescue => e Rails.logger.error "Error: #{e}" Rails.logger.error e.backtrace.join("\n") render text: e., status: 500 end end |
#update ⇒ Object
updates the access token after changing password with institution
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/plaid_rails/link_controller.rb', line 20 def update begin exchange_token = Plaid::User.exchange_token(link_params[:public_token]) # find old access_token old_access_token = PlaidRails::Account.find_by(owner_type: link_params[:owner_type], owner_id: link_params[:owner_id],number: link_params[:number]).access_token # find all plaid_accounts with old access_token accounts = PlaidRails::Account.where(owner_type: link_params[:owner_type], owner_id: link_params[:owner_id], access_token: old_access_token) # update found accounts with new token. accounts.update_all(access_token: exchange_token.access_token, transactions_start_date: Date.today) # get all accounts to display back to user. @plaid_accounts = PlaidRails::Account.where(owner_type: link_params[:owner_type], owner_id: link_params[:owner_id]) flash[:success]="You have successfully updated your account(s)" rescue => e Rails.logger.error "Error: #{e}" render text: e., status: 500 end end |