plaid_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +29 -0
  4. data/app/assets/javascripts/plaid_rails/application.js +13 -0
  5. data/app/assets/javascripts/plaid_rails/link.js +36 -0
  6. data/app/assets/javascripts/plaid_rails.js +1 -0
  7. data/app/assets/stylesheets/plaid_rails/application.css +15 -0
  8. data/app/controllers/plaid_rails/accounts_controller.rb +39 -0
  9. data/app/controllers/plaid_rails/application_controller.rb +4 -0
  10. data/app/controllers/plaid_rails/link_controller.rb +25 -0
  11. data/app/controllers/plaid_rails/webhooks_controller.rb +15 -0
  12. data/app/helpers/plaid_rails/application_helper.rb +4 -0
  13. data/app/models/plaid_rails/account.rb +10 -0
  14. data/app/models/plaid_rails/webhook.rb +14 -0
  15. data/app/services/plaid_rails/create_account_service.rb +30 -0
  16. data/app/views/layouts/plaid_rails/application.html.erb +14 -0
  17. data/app/views/plaid_rails/accounts/create.html.erb +1 -0
  18. data/app/views/plaid_rails/accounts/destroy.html.erb +1 -0
  19. data/app/views/plaid_rails/accounts/index.html.erb +5 -0
  20. data/app/views/plaid_rails/accounts/new.html.erb +17 -0
  21. data/app/views/plaid_rails/link/_auth.html.erb +14 -0
  22. data/app/views/plaid_rails/link/authenticate.html.erb +2 -0
  23. data/app/views/plaid_rails/link/authenticate.js.erb +5 -0
  24. data/config/routes.rb +9 -0
  25. data/db/migrate/20160214150149_create_plaid_rails_webhooks.rb +12 -0
  26. data/db/migrate/20160215155024_create_plaid_rails_accounts.rb +22 -0
  27. data/db/test.sqlite3 +0 -0
  28. data/lib/plaid_rails/engine.rb +21 -0
  29. data/lib/plaid_rails/event.rb +75 -0
  30. data/lib/plaid_rails/version.rb +3 -0
  31. data/lib/plaid_rails.rb +49 -0
  32. data/lib/tasks/plaid_rails_tasks.rake +4 -0
  33. data/spec/controllers/plaid_rails/accounts_controller_spec.rb +45 -0
  34. data/spec/controllers/plaid_rails/application_controller_spec.rb +7 -0
  35. data/spec/controllers/plaid_rails/link_controller_spec.rb +27 -0
  36. data/spec/controllers/plaid_rails/webhooks_controller_spec.rb +18 -0
  37. data/spec/dummy/README.rdoc +28 -0
  38. data/spec/dummy/Rakefile +6 -0
  39. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  40. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  42. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  43. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  44. data/spec/dummy/bin/bundle +3 -0
  45. data/spec/dummy/bin/rails +4 -0
  46. data/spec/dummy/bin/rake +4 -0
  47. data/spec/dummy/config/application.rb +29 -0
  48. data/spec/dummy/config/boot.rb +5 -0
  49. data/spec/dummy/config/database.yml +25 -0
  50. data/spec/dummy/config/environment.rb +5 -0
  51. data/spec/dummy/config/environments/development.rb +37 -0
  52. data/spec/dummy/config/environments/production.rb +78 -0
  53. data/spec/dummy/config/environments/test.rb +39 -0
  54. data/spec/dummy/config/initializers/assets.rb +8 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  57. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  58. data/spec/dummy/config/initializers/inflections.rb +16 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  60. data/spec/dummy/config/initializers/session_store.rb +3 -0
  61. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  62. data/spec/dummy/config/locales/en.yml +23 -0
  63. data/spec/dummy/config/routes.rb +4 -0
  64. data/spec/dummy/config/secrets.yml +22 -0
  65. data/spec/dummy/config.ru +4 -0
  66. data/spec/dummy/db/development.sqlite3 +0 -0
  67. data/spec/dummy/db/schema.rb +46 -0
  68. data/spec/dummy/db/test.sqlite3 +0 -0
  69. data/spec/dummy/log/development.log +31 -0
  70. data/spec/dummy/log/test.log +7051 -0
  71. data/spec/dummy/public/404.html +67 -0
  72. data/spec/dummy/public/422.html +67 -0
  73. data/spec/dummy/public/500.html +66 -0
  74. data/spec/dummy/public/favicon.ico +0 -0
  75. data/spec/factories/account.rb +12 -0
  76. data/spec/factories/webhook.rb +9 -0
  77. data/spec/models/plaid_rails/account_spec.rb +11 -0
  78. data/spec/models/plaid_rails/webhook_spec.rb +18 -0
  79. data/spec/plaid_rails.spec.rb +30 -0
  80. data/spec/services/plaid_rails/create_account_service_spec.rb +23 -0
  81. data/spec/spec_helper.rb +29 -0
  82. metadata +299 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfa957e3247b9dd795200f9e15eb2a775425adf7
4
+ data.tar.gz: ccaacbd3394200f6653ff4891584054e4760e4f5
5
+ SHA512:
6
+ metadata.gz: 7c0d5802e0258f8e4115c1d3cb9295610934f2001f04408d7423984606f96b282fe8db52aee8052e84a9cf154348ba0578cb178fd698ae7cd7f4bf758272e11a
7
+ data.tar.gz: 8f2aa09ebfc55dfea10cd084f699293aaa49ed430c76cadd8ee246802cadb8c57fe235b78d8f911c527516f7f2b78e004552e94783c232bb985cbf60f5566bf8
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'PlaidRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
25
+ require 'rspec/core'
26
+ require 'rspec/core/rake_task'
27
+ desc "Run all specs in spec directory (excluding plugin specs)"
28
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
29
+ task :default => :spec
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,36 @@
1
+ var plaidData = $("#plaid-data");
2
+ var linkHandler = Plaid.create({
3
+ env: plaidData.data('env'),
4
+ clientName: plaidData.data('client-name'),
5
+ key: plaidData.data('key'),
6
+ product: 'connect',
7
+ webhook: plaidData.data('webhook'),
8
+ onLoad: function () {
9
+ // The Link module finished loading.
10
+ },
11
+ onSuccess: function (public_token, metadata) {
12
+ // Send the public_token to your app server here.
13
+ // The metadata object contains info about the institution the
14
+ // user selected and the account ID, if selectAccount is enabled.
15
+ $.ajax({
16
+ type: 'POST',
17
+ dataType: 'script',
18
+ url: '/plaid/authenticate',
19
+ data: {
20
+ public_token: public_token,
21
+ name: metadata.institution.name,
22
+ type: metadata.institution.type,
23
+ owner_type: plaidData.data('owner-type'),
24
+ owner_id: plaidData.data('owner-id')
25
+ }
26
+ });
27
+ },
28
+ onExit: function () {
29
+ // The user exited the Link flow.
30
+ }
31
+ });
32
+ // Trigger the authentication view
33
+ $(document).on("click", '#plaidLinkButton', function () {
34
+ linkHandler.open();
35
+ });
36
+
@@ -0,0 +1 @@
1
+ //= require_tree './plaid_rails'
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,39 @@
1
+ require_dependency "plaid_rails/application_controller"
2
+
3
+ module PlaidRails
4
+ class AccountsController < ApplicationController
5
+
6
+ def index
7
+ @accounts =PlaidRails::Account.where(owner_id: account_params[:owner_id])
8
+ end
9
+
10
+ # display list of accounts for authenticated user
11
+ def new
12
+ @user = Plaid.set_user(account_params[:access_token], ['auth'])
13
+ # Retrieve the user's accounts
14
+ @user.get('auth')
15
+ @accounts = @user.accounts
16
+ end
17
+
18
+ #create new bank account and return all the accounts for the owner
19
+ def create
20
+ @accounts = PlaidRails::CreateAccountService.call(account_params)
21
+ end
22
+
23
+ def update
24
+
25
+ end
26
+
27
+ def destroy
28
+ account = PlaidRails::Account.find(params[:id])
29
+ account.destroy
30
+ end
31
+
32
+ private
33
+
34
+ # Never trust parameters from the scary internet, only allow the white list through.
35
+ def account_params
36
+ params.require(:account).permit(:access_token, :type,:name,:owner_id,:owner_type,account_ids:[])
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ module PlaidRails
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,25 @@
1
+ require_dependency "plaid_rails/application_controller"
2
+
3
+ module PlaidRails
4
+ class LinkController < ApplicationController
5
+
6
+ def authenticate
7
+ begin
8
+ @exchange_token = Plaid.exchange_token(link_params[:public_token])
9
+
10
+ @params = link_params
11
+
12
+ rescue => e
13
+ Rails.logger.error "Error: #{e}"
14
+ Rails.logger.error e.backtrace.join("\n")
15
+ render text: e.message, status: 500
16
+ end
17
+ end
18
+
19
+ private
20
+ # Never trust parameters from the scary internet, only allow the white list through.
21
+ def link_params
22
+ params.permit(:public_token, :type,:name,:owner_id,:owner_type)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module PlaidRails
2
+ class WebhooksController < ApplicationController
3
+ skip_before_filter :verify_authenticity_token
4
+
5
+ def create
6
+ @webhook = PlaidRails::Webhook.create!(webhook_params)
7
+ render json: @webhook
8
+ end
9
+
10
+ private
11
+ def webhook_params
12
+ params.require(:webhook).permit(:code, :message, :access_token)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ module PlaidRails
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module PlaidRails
2
+ class Account < ActiveRecord::Base
3
+ belongs_to :owner, polymorphic: true, foreign_key: :owner_id
4
+
5
+ validates :plaid_id, presence: true
6
+ validates :name, presence: true
7
+ validates :access_token, presence: true
8
+ validates :plaid_type, presence: true
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module PlaidRails
2
+ class Webhook < ActiveRecord::Base
3
+
4
+ validates :code, presence: true
5
+ validates :message, presence: true
6
+ validates :access_token, presence: true
7
+ after_save :event
8
+
9
+ private
10
+ def event
11
+ PlaidRails::Event.instrument(self)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ module PlaidRails
2
+ class CreateAccountService
3
+
4
+ # creates a new plaid_rails_account for each account the user has selected
5
+ def self.call(account_params)
6
+ account_params["account_ids"].each do |id|
7
+ # set Plaid::User
8
+ user = Plaid.set_user(account_params["access_token"],['auth'])
9
+ #find the account by account_id
10
+ account = user.accounts.find{|a| a.id==id}
11
+
12
+ PlaidRails::Account.create!(
13
+ access_token: account_params["access_token"],
14
+ plaid_type: account_params["type"],
15
+ name: account.name,
16
+ bank_name: account.meta["name"],
17
+ number: account.meta["number"],
18
+ owner_id: account_params["owner_id"],
19
+ owner_type: account_params["owner_type"],
20
+ available_balance: account.available_balance,
21
+ current_balance: account.current_balance,
22
+ plaid_id: id
23
+ ) unless PlaidRails::Account.exists?(plaid_id: id)
24
+ end
25
+
26
+ PlaidRails::Account.where(owner_id: account_params["owner_id"],
27
+ owner_type: account_params["owner_type"])
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>PlaidRails</title>
5
+ <%= stylesheet_link_tag "plaid_rails/application", media: "all" %>
6
+ <%= javascript_include_tag "plaid_rails/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ <%= render template: "index" %>
@@ -0,0 +1 @@
1
+ account removed
@@ -0,0 +1,5 @@
1
+ <h3>Accounts</h3>
2
+
3
+ <% @accounts.each do |account| %>
4
+ <%=account.name%> <br/>
5
+ <%end%>
@@ -0,0 +1,17 @@
1
+ <h3>Select The Accounts To Link</h3>
2
+
3
+
4
+ <%= form_tag "/plaid/accounts", method: "post", remote: true do %>
5
+ <%= hidden_field_tag "account[access_token]", params["access_token"] %>
6
+ <%= hidden_field_tag "account[name]", params["name"] %>
7
+ <%= hidden_field_tag "account[type]", params["type"] %>
8
+ <%= hidden_field_tag "account[owner_id]", params["owner_id"] %>
9
+ <%= hidden_field_tag "account[owner_type]", params["owner_type"] %>
10
+ <% @accounts.each_with_index do |account,index| %>
11
+ <%= check_box_tag "account[account_ids][]", account.id,nil,{id: "account_account_ids_#{index}"}%>
12
+ <label for="account_account_ids_<%=index%>"> <%= "#{account.meta["name"]} - #{account.meta["number"]}"%></label><br/>
13
+ <%end%>
14
+
15
+ <%= submit_tag "Save", :class=>"button small" %>
16
+ <%= button_tag "Cancel" , :class=>"button small close"%>
17
+ <%end%>
@@ -0,0 +1,14 @@
1
+ <button id="plaidLinkButton" class="small">Link your Bank Account</button>
2
+
3
+
4
+ <div id="plaid-data"
5
+ data-client-name="<%= client_name %>"
6
+ data-env="<%= Rails.env.production? ? "production" : "tartan"%>"
7
+ data-key="<%= PlaidRails.public_key %>"
8
+ data-webhook="<%= PlaidRails.webhook %>"
9
+ data-owner-type="<%= owner.class.name %>"
10
+ data-owner-id="<%= owner.id %>">
11
+ </div>
12
+
13
+ <%=javascript_include_tag "https://cdn.plaid.com/link/stable/link-initialize.js" %>
14
+ <%=javascript_include_tag "plaid_rails/link.js" %>
@@ -0,0 +1,2 @@
1
+ // override this js file with your own in your the own view in
2
+ // app/views/plaid_rails/link/authenticate.html.erb
@@ -0,0 +1,5 @@
1
+ // override this js file with your own in your the own view in
2
+ // app/views/plaid_rails/link/authenticate.js.erb
3
+
4
+ console.log('success')
5
+ alert('success')
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ PlaidRails::Engine.routes.draw do
2
+
3
+ resources :accounts
4
+
5
+ match '/webhooks', to: 'webhooks#create', via: :post
6
+ match '/authenticate', to: "link#authenticate", via: :post
7
+
8
+
9
+ end
@@ -0,0 +1,12 @@
1
+ class CreatePlaidRailsWebhooks < ActiveRecord::Migration
2
+ def change
3
+ create_table :plaid_rails_webhooks do |t|
4
+ t.integer :code
5
+ t.string :message
6
+ t.string :access_token
7
+ t.text :params
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ class CreatePlaidRailsAccounts < ActiveRecord::Migration
2
+ def change
3
+ create_table :plaid_rails_accounts do |t|
4
+ t.string :access_token
5
+ t.string :plaid_type
6
+ t.string :name
7
+ t.string :bank_name
8
+ t.integer :number
9
+ t.string :plaid_id
10
+ t.string :owner_type
11
+ t.integer :owner_id
12
+ t.datetime :last_sync
13
+ t.decimal :current_balance, :precision => 10, :scale => 2
14
+ t.decimal :available_balance, :precision => 10, :scale => 2
15
+ t.string :error
16
+ t.timestamps
17
+ end
18
+ add_index :plaid_rails_accounts, :access_token
19
+ add_index :plaid_rails_accounts, :owner_id
20
+ add_index :plaid_rails_accounts, :plaid_id
21
+ end
22
+ end
data/db/test.sqlite3 ADDED
File without changes
@@ -0,0 +1,21 @@
1
+ module PlaidRails
2
+ class Engine < ::Rails::Engine
3
+
4
+ isolate_namespace PlaidRails
5
+ config.generators do |g|
6
+ g.test_framework :rspec, :fixture => false
7
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
8
+ g.assets false
9
+ g.helper false
10
+ end
11
+
12
+ initializer :append_migrations do |app|
13
+ unless app.root.to_s.match root.to_s
14
+ config.paths["db/migrate"].expanded.each do |expanded_path|
15
+ app.config.paths["db/migrate"] << expanded_path
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ require "active_support/notifications"
2
+
3
+ module PlaidRails
4
+ module Event
5
+ class << self
6
+ attr_accessor :adapter, :backend, :event_retriever, :namespace, :authentication_secret
7
+
8
+ def configure(&block)
9
+ raise ArgumentError, "must provide a block" unless block_given?
10
+ block.arity.zero? ? instance_eval(&block) : yield(self)
11
+ end
12
+ alias :setup :configure
13
+
14
+ def instrument(event)
15
+ name = case event.code
16
+ when 0
17
+ "transactions.initial"
18
+ when 1
19
+ "transactions.new"
20
+ when 2
21
+ "transactions.interval"
22
+ when 3
23
+ "transactions.removed"
24
+ when 4
25
+ "webhook.updated"
26
+ else
27
+ "plaid.error"
28
+ end
29
+ backend.instrument namespace.call(name), event if event
30
+ end
31
+
32
+ def subscribe(name, callable = Proc.new)
33
+ backend.subscribe namespace.to_regexp(name), adapter.call(callable)
34
+ end
35
+
36
+ def all(callable = Proc.new)
37
+ subscribe nil, callable
38
+ end
39
+
40
+ def listening?(name)
41
+ namespaced_name = namespace.call(name)
42
+ backend.notifier.listening?(namespaced_name)
43
+ end
44
+ end
45
+
46
+ class Namespace < Struct.new(:value, :delimiter)
47
+ def call(name = nil)
48
+ "#{value}#{delimiter}#{name}"
49
+ end
50
+
51
+ def to_regexp(name = nil)
52
+ %r{^#{Regexp.escape call(name)}}
53
+ end
54
+ end
55
+
56
+ class NotificationAdapter < Struct.new(:subscriber)
57
+ def self.call(callable)
58
+ new(callable)
59
+ end
60
+
61
+ def call(*args)
62
+ payload = args.last
63
+ subscriber.call(payload)
64
+ end
65
+ end
66
+
67
+ class Error < StandardError; end
68
+ class UnauthorizedError < Error; end
69
+
70
+ self.adapter = NotificationAdapter
71
+ self.backend = ActiveSupport::Notifications
72
+ # self.event_retriever = lambda { |params| PlaidRails::Event.retrieve(params[:webhooks][:access_token]) }
73
+ self.namespace = Namespace.new("plaid_rails", ".")
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module PlaidRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,49 @@
1
+ require "plaid_rails/engine"
2
+ require "plaid_rails/event"
3
+ require "plaid"
4
+
5
+ module PlaidRails
6
+
7
+ class << self
8
+ attr_accessor :customer_id,
9
+ :secret,
10
+ :environment_location,
11
+ :public_key,
12
+ :webhook,
13
+ :long_tail
14
+
15
+
16
+ def configure(&block)
17
+ raise ArgumentError, "must provide a block" unless block_given?
18
+ block.arity.zero? ? instance_eval(&block) : yield(self)
19
+ end
20
+
21
+ def subscribe(name, callable = Proc.new)
22
+ PlaidRails::Event.subscribe(name, callable)
23
+ end
24
+
25
+ def instrument(name, object)
26
+ PlaidRails::Event.backend.instrument( PlaidRails::Event.namespace.call(name), object)
27
+ end
28
+
29
+ def all(callable = Proc.new)
30
+ PlaidRails::Event.all(callable)
31
+ end
32
+
33
+ # class Retriever
34
+ # def self.call(params)
35
+ # #return nil if StripeWebhook.exists?(stripe_id: params[:id])
36
+ # Webhook.create!(params: params)
37
+ # # event = Stripe::Event.retrieve(params[:id], { api_key: Payola.secret_key })
38
+ # #Payola.event_filter.call(event)
39
+ # end
40
+ # end
41
+
42
+ def reset!
43
+ #PlaidRails::Event.event_retriever = Retriever
44
+
45
+ end
46
+ end
47
+
48
+ self.reset!
49
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :plaid_rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ module PlaidRails
4
+ describe AccountsController do
5
+ routes { PlaidRails::Engine.routes }
6
+ let(:account){create(:account)}
7
+ let(:public_token){'test,wells,connected'}
8
+ let(:user){Plaid.set_user('test_wells', ['auth'])}
9
+
10
+ it "get index" do
11
+ get :index, account:{owner_id: 1}
12
+ expect(response).to be_success
13
+ expect(assigns(:accounts)).to eq [account]
14
+
15
+ end
16
+
17
+ it "get new" do
18
+ get :new, account:{access_token: 'test_wells', name:'Wells Fargo', type: 'wells',
19
+ owner_id: "1", owner_type: "User"}
20
+ expect(response).to be_success
21
+ expect(assigns(:accounts)).to_not be_nil
22
+ end
23
+
24
+ it "can create" do
25
+ accounts = user.accounts.map{|a| a.id}
26
+ post :create, account: {access_token: 'test_wells', account_ids: accounts,
27
+ name:'Wells Fargo', type: 'wells', owner_id: "1", owner_type: "User"}
28
+ expect(response).to be_success
29
+ expect(assigns(:accounts).size).to eq 4
30
+ end
31
+
32
+ it "can destroy" do
33
+ delete :destroy, id: account.id
34
+ expect(response).to be_success
35
+ end
36
+
37
+ # it {
38
+ # should permit(:access_token, :type,:name,:owner_id,:owner_type,:account_id).
39
+ # for(:create, params: {access_token: 'test_wells', account_id: '1',
40
+ # name: 'name'})}
41
+ # it {
42
+ # should permit(:token, :type,:name,:owner_id,:owner_type).
43
+ # for(:new, verb: :get, params: {access_token: 'test_wells'})}
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ module Plaid
4
+ describe PlaidRails::ApplicationController do
5
+
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module PlaidRails
4
+ describe LinkController do
5
+ routes { PlaidRails::Engine.routes }
6
+
7
+ it "authenticate with public token" do
8
+ xhr :post, :authenticate, public_token: 'test,wells,connected', name:'Wells Fargo', type: 'wells',
9
+ owner_id: "1", owner_type: "User"
10
+ expect(response).to be_success
11
+ expect(response).to render_template('plaid_rails/link/authenticate')
12
+ end
13
+
14
+ it "can't authenticat with bad public token" do
15
+ xhr :post, :authenticate, public_token: 'badtoken', name:'Wells Fargo', type: 'wells',
16
+ owner_id: "1", owner_type: "User"
17
+ expect(response).to_not be_success
18
+ expect(response.status).to eq 500
19
+ expect(response.body).to eq "unauthorized product"
20
+ end
21
+
22
+ it {
23
+ should permit(:public_token, :type,:name,:owner_id,:owner_type).
24
+ for(:authenticate, verb: :post, format: :js)}
25
+
26
+ end
27
+ end