Class: PlaidRails::CreateAccountService

Inherits:
Object
  • Object
show all
Defined in:
app/services/plaid_rails/create_account_service.rb

Class Method Summary collapse

Class Method Details

.call(account_params) ⇒ Object

creates a new plaid_rails_account for each account the user has selected



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/plaid_rails/create_account_service.rb', line 5

def self.call()
  ["account_ids"].each  do |id|
    # set Plaid::User
    user = Plaid.set_user(["access_token"],['auth'])
    #find the account by account_id 
     = user.accounts.find{|a| a.id==id}
    PlaidRails::Account.create!(
      access_token: ["access_token"], 
      token: ["token"],
      plaid_type: ["type"],
      name: .name,
      bank_name: .meta["name"],
      number: .meta["number"],
      owner_id: ["owner_id"],
      owner_type: ["owner_type"],
      available_balance: .available_balance,
      current_balance: .current_balance,
      plaid_id: id
    ) unless PlaidRails::Account.exists?(plaid_id: id)
  end
  
  PlaidRails::Account.where(owner_id: ["owner_id"], 
    owner_type: ["owner_type"])
end