plaid-legacy 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 033f6f757e2de0376d156aec59eb4d95ea01529e
4
+ data.tar.gz: 47bbaf501af5899ac400372b58179e4ba43ce1ee
5
+ SHA512:
6
+ metadata.gz: 10c2984cecf8ca20d7794ea3abee7ddb9ec7eb974198ba81e01b4d11df61eb8111720b65c79a99b891db9715bb9ff2db553a15f18b0ccba388b92955d541af5e
7
+ data.tar.gz: 3a6199ba74f95ad1dc384893548382320d2d2eaf5cbc1c726e5ea24abee2e35b0b0f65907aa607194eed266ca1fb046a550c980c4e26d362b896bf9cf474fded
@@ -0,0 +1,34 @@
1
+ # 3.0.0. 17-Jan-2017
2
+
3
+ * Add `/institutions/all` and `/institutions/all/search` endpoints, see [UPGRADING.md](UPGRADING.md#upgrading-from-2xx-to-300)
4
+
5
+ # 2.2.0. 03-Nov-2016
6
+
7
+ * Add `Transaction#reference_number` (@ericbirdsall).
8
+ * Fix webhook codes and add risk and income webhooks.
9
+
10
+ # 2.1.0. 19-Oct-2016
11
+
12
+ * Documentation fixes (@ishmael).
13
+ * Fix `Transaction#to_s` behavior (@michel-tricot).
14
+ * PATCH `/:product/step` flow.
15
+ * Use the same client in `User#upgrade` (@betesh).
16
+ * Webhook object (@zshannon).
17
+ * `processor_token` access in `User.exchange_token` (@gylaz).
18
+ * Raise `ServerError` in case server returned an empty response body.
19
+
20
+ # 2.0.0. 24-May-2016
21
+
22
+ * Use `~> 1.0` spec for multi_json dependency.
23
+ * Support `stripe_bank_account_token` in `User.exchange_token`.
24
+
25
+ # 2.0.0.alpha.2. 14-May-2016
26
+
27
+ * Use `:production` instead of `:api` to signify production environment
28
+ in `Plaid::Client#env=`.
29
+ * `User#mfa_step` allows to specify options now (thanks @gcweeks).
30
+ * Implemented `User#update_webhook`.
31
+
32
+ # 2.0.0.alpha. 06-May-2016
33
+
34
+ * Rewrite everything.
@@ -0,0 +1,15 @@
1
+ # Contributing
2
+
3
+ 1. Make one or more atomic commits, and ensure that each commit has a
4
+ descriptive commit message. Commit messages should be line wrapped
5
+ at 72 characters.
6
+
7
+ 2. Make sure that there are tests for the code you wrote.
8
+
9
+ 3. Make sure that you've documented all public methods using [TomDoc](http://tomdoc.org/).
10
+
11
+ 4. Run `rake test`, and address any errors. Preferably, fix commits
12
+ in place using `git rebase` or `git commit --amend` to make the
13
+ changes easier to review.
14
+
15
+ 5. Open a pull request.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in plaid.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Plaid Technologies, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,328 @@
1
+ # plaid-ruby-legacy [![Build Status](https://travis-ci.org/plaid/plaid-ruby-legacy-legacy.svg)](https://travis-ci.org/plaid/plaid-ruby-legacy) [![Gem Version](https://badge.fury.io/rb/plaid-legacy.svg)](http://badge.fury.io/rb/plaid-legacy)
2
+
3
+ Ruby bindings for the Plaid's legacy API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'plaid-legacy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install plaid-legacy
20
+
21
+ The gem supports Ruby 2.x only.
22
+
23
+ ## Usage
24
+
25
+ This gem wraps the Plaid API, which is fully described in the [documentation](http://plaid.com/docs).
26
+
27
+ The RubyDoc for the gem is available [here](http://plaid.github.io/plaid-ruby-legacy).
28
+
29
+ ### Configuring access to Plaid
30
+
31
+ Configure the gem with your client id, secret, and the environment you would like to use.
32
+
33
+ ```ruby
34
+ Plaid.config do |p|
35
+ p.client_id = '<<< Plaid provided client ID >>>'
36
+ p.secret = '<<< Plaid provided secret key >>>'
37
+ p.env = :tartan # or :production
38
+ end
39
+ ```
40
+
41
+ ### Creating a new User
42
+
43
+ ```ruby
44
+ user = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good')
45
+ ```
46
+
47
+ This call will do a `POST /connect`. The response will contain account information and transactions
48
+ for last 30 days, which you can find in `user.accounts` and `user.initial_transactions`, accordingly.
49
+
50
+ If the authentication requires a pin, you can pass it as a named parameter:
51
+
52
+ ```ruby
53
+ user = Plaid::User.create(:income, 'usaa', 'plaid_test', 'plaid_good', pin: '1234')
54
+ ```
55
+
56
+ To add options such as `login_only` or `webhook`, use `options` argument:
57
+
58
+ ```ruby
59
+ user = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good',
60
+ options: { login_only: true, webhook: 'https://example.org/callbacks/plaid')
61
+ ```
62
+
63
+ The first argument for `Plaid::User.create` is always a product you want to add the user to (like,
64
+ `:connect`, `:auth`, `:info`, `:income`, or `:risk`). The user object is bound to the product, and subsequent
65
+ calls like `user.update` or `user.delete` are done for this product (i.e., `PATCH /info` and `DELETE /info`
66
+ for `:info`).
67
+
68
+ ### Instantiating a User with an existing access token
69
+
70
+ If you've already added the user and saved the access token, you should use `User.load`:
71
+
72
+ ```ruby
73
+ user = Plaid::User.load(:risk, 'access_token')
74
+ ```
75
+
76
+ This won't make any API requests by itself, just set the product and the token in the `User` instance.
77
+
78
+ ### Exchanging a Link public token for a Plaid access token
79
+
80
+ If you have a Link public token, use `User.exchange_token`:
81
+
82
+ ```ruby
83
+ user = Plaid::User.exchange_token('public_token') # bound to :connect product
84
+ ```
85
+
86
+ With more options:
87
+
88
+ ```ruby
89
+ user2 = Plaid::User.exchange_token('public_token', 'account_id', product: :auth)
90
+ ```
91
+
92
+ If you want to [move money via Stripe's ACH
93
+ API](https://plaid.com/docs/link/stripe/#step-4-write-server-side-handler), you
94
+ ought to specify the `account_id` param. In this case the returned user
95
+ instance will have the `stripe_bank_account_token` attribute set.
96
+
97
+ ### Upgrading and changing the current product
98
+
99
+ Plaid supports upgrading a user, i.e. adding it to another product:
100
+
101
+ ```ruby
102
+ # Create a user in Connect
103
+ user = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good')
104
+
105
+ # Upgrade this user, attaching it to Auth as well (makes a request to /upgrade).
106
+ auth_user = user.upgrade(:auth)
107
+ ```
108
+
109
+ The `auth_user` will be a different instance of `User`, attached to Auth, but the access token will be the same.
110
+
111
+ Sometimes you know that the user has already been added to another product. To get a `User` instance with
112
+ same access token, but different current product, use `User.for_product`:
113
+
114
+ ```ruby
115
+ # Get a user attached to Connect
116
+ user = Plaid::User.load(:connect, 'access_token')
117
+
118
+ # Makes no requests
119
+ info_user = user.for_product(:info)
120
+ ```
121
+
122
+ Basically it's the same as:
123
+
124
+ ```ruby
125
+ info_user = Plaid::User.load(:info, 'access_token')
126
+ ```
127
+
128
+ ### MFA (Multi-Factor Authorization)
129
+
130
+ If MFA is requested by the financial institution, the `User.create` call would behave
131
+ a bit differently:
132
+
133
+ ```ruby
134
+ user = Plaid::User.create(:auth, 'wells', 'plaid_test', 'plaid_good')
135
+
136
+ user.accounts #=> nil
137
+ user.mfa? #=> true
138
+ user.mfa_type #=> :questions
139
+ user.mfa #=> [{question: "What's the nickname of the person who created Ruby?"}]
140
+ ```
141
+
142
+ In this case you'll have to submit the answer to the question:
143
+
144
+ ```ruby
145
+ user.mfa_step('matz') # This is the correct answer!
146
+
147
+ user.mfa? #=> false
148
+ user.mfa_type #=> nil
149
+ user.mfa #=> nil
150
+ user.accounts #=> [<Plaid::Account ...>, ...]
151
+ ```
152
+
153
+ The code-based MFA workflow is similar. Basically you need to call `user.mfa_step(...)`
154
+ until `user.mfa?` becomes false.
155
+
156
+ ### Obtaining user-related data
157
+
158
+ If you have a live `User` instance, you can use following methods
159
+ (independent of instance's current product):
160
+
161
+ * `user.transactions(...)`. Makes a `/connect/get` request.
162
+ * `user.auth(sync: false)`. Makes an `/auth/get` request.
163
+ * `user.info(sync: false)`. Makes an `/info/get` request.
164
+ * `user.income(sync: false)`. Makes an `/income/get` request.
165
+ * `user.risk(sync: false)`. Makes an `/risk/get` request.
166
+ * `user.balance`. Makes an `/balance` request.
167
+
168
+ All of these methods return appropriate data, but they also update the cached `user.accounts`. That is,
169
+ if you user has access to Auth and Risk products, the following code:
170
+
171
+ ```ruby
172
+ user = User.load(:auth, 'access_token')
173
+ user.auth
174
+ user.risk
175
+ ```
176
+ will result in `user.accounts` having both routing number and risk information for all the accounts. The
177
+ subsequent `user.balance` call will just update the current balance, not touching the routing and risk information.
178
+
179
+ The `sync` flag, if set to true, will result in updating the information from the server even if it has already been
180
+ loaded. Otherwise cached information will be returned:
181
+
182
+ ```ruby
183
+ user = User.load(:auth, 'access_token') # Just set the token
184
+ user.auth # POST /auth/get
185
+ user.auth # No POST, return cached info
186
+ user.auth(sync: true) # POST /auth/get again
187
+ ```
188
+
189
+ Same goes for other methods, except `User#transactions` and `User#balance` which always make requests to the API.
190
+
191
+ ### Categories
192
+
193
+ You can request category information:
194
+
195
+ ```ruby
196
+ cats = Plaid::Category.all # Array of all known categories
197
+ cat = Plaid::Category.get('17001013') # A single category by its ID
198
+ ```
199
+
200
+ ### Institutions
201
+
202
+ Financial institution information is available via `Plaid::Institution`.
203
+
204
+ ```ruby
205
+ insts = Plaid::Institution.all(count: 20, offset: 20) # A page
206
+ inst = Plaid::Institution.get('5301a93ac140de84910000e0') # A single institution by its ID
207
+
208
+ res = Plaid::Institution.search(query: 'c') # Lookup by name
209
+ ```
210
+
211
+ ### Webhooks
212
+
213
+ You can register to receive [Webhooks](https://plaid.com/docs/legacy/api/#webhook) from Plaid when your users have new events. If you do, you'll receive `POST` requests with JSON.
214
+
215
+ E.g. Initial Transaction Webhook:
216
+ ```json
217
+ {
218
+ "message": "Initial transaction pull finished",
219
+ "access_token": "xxxxx",
220
+ "total_transactions": 123,
221
+ "code": 0
222
+ }
223
+ ```
224
+
225
+ You should parse that JSON into a Ruby Hash with String keys (eg. `webhook_hash = JSON.parse(json_string)`). Then, you can convert that Hash into a Ruby object using `Plaid::Webhook`:
226
+
227
+ ```ruby
228
+ webhook = Plaid::Webhook.new(webhook_hash)
229
+
230
+ # Was that the Initial Transaction Webhook?
231
+ webhook.initial_transaction?
232
+ access_token = webhook.access_token
233
+ total_transactions = webhook.total_transactions
234
+
235
+ # Or did Historical Transactions become available?
236
+ webhook.historical_transaction?
237
+ access_token = webhook.access_token
238
+ total_transactions = webhook.total_transactions
239
+
240
+ # Or did Normal Transactions become available?
241
+ webhook.normal_transaction?
242
+ access_token = webhook.access_token
243
+ total_transactions = webhook.total_transactions
244
+
245
+ # Or maybe a transaction was removed?
246
+ webhook.removed_transaction?
247
+ access_token = webhook.access_token
248
+ removed_transactions_ids = webhook.removed_transactions_ids
249
+
250
+ # Or was the User's Webhook Updated?
251
+ webhook.user_webhook_updated?
252
+ access_token = webhook.access_token
253
+
254
+ # Otherwise, was it an error?
255
+ webhook.error_response?
256
+ # Which error?
257
+ error = webhook.error
258
+ ```
259
+
260
+ ### Custom clients
261
+
262
+ It's possible to use several Plaid environments and/or credentials in one app by
263
+ explicit instantiation of `Plaid::Client`:
264
+
265
+ ```ruby
266
+ # Configuring the global client (Plaid.client) which is used by default
267
+ Plaid.config do |p|
268
+ p.client_id = 'client_id_1'
269
+ p.secret = 'secret_1'
270
+ p.env = :tartan
271
+ end
272
+
273
+ # Creating a custom client
274
+ api = Plaid::Client.new(client_id: 'client_id_2', secret: 'secret_2', env: :production)
275
+
276
+ # Tartan user (using default client)
277
+ user1 = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good')
278
+
279
+ # Api user (using api client)
280
+ user2 = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good', client: api)
281
+
282
+ # Lookup an institution in production
283
+ res = Plaid::Institution.search(query: 'c', client: api)
284
+ ```
285
+
286
+ The `client` option can be passed to the following methods:
287
+
288
+ * `User.create`
289
+ * `User.load`
290
+ * `User.exchange_token`
291
+ * `Category.all`
292
+ * `Category.get`
293
+ * `Institution.all`
294
+ * `Institution.get`
295
+ * `Institution.search`
296
+ * `Institution.search_by_id`
297
+
298
+ ### Errors
299
+
300
+ Any methods making API calls will result in an exception raised unless the response code is "200: Success" or
301
+ "201: MFA Required".
302
+
303
+ `Plaid::BadRequestError` is raised when status code is "400: Bad Request".
304
+
305
+ `Plaid::UnauthorizedError` is raised when status code is "401: Unauthorized".
306
+
307
+ `Plaid::RequestFailedError` is raised when status code is "402: Request Failed".
308
+
309
+ `Plaid::NotFoundError` is raised when status code is "404: Cannot be Found".
310
+
311
+ `Plaid::ServerError` is raised when status code is "50X: Server Error".
312
+
313
+ Read more about response codes and their meaning in the
314
+ [Plaid documentation](https://plaid.com/docs/legacy/api/#response-codes).
315
+
316
+ ## Development
317
+
318
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
319
+
320
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
321
+
322
+ ## Contributing
323
+
324
+ Bug reports and pull requests are welcome on GitHub at https://github.com/plaid/plaid-ruby-legacy. See also [contributing guidelines](CONTRIBUTING.md).
325
+
326
+ ## License
327
+
328
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,54 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'sdoc'
3
+ require 'rdoc/task'
4
+ require 'rake/testtask'
5
+ require 'fileutils'
6
+
7
+ RDoc::Task.new do |rdoc|
8
+ rdoc.rdoc_dir = 'doc/rdoc'
9
+ rdoc.generator = 'sdoc'
10
+ rdoc.main = 'README.md'
11
+
12
+ rdoc.rdoc_files.include('README.md', 'LICENSE', 'UPGRADING.md',
13
+ 'CONTRIBUTING.md', 'CHANGELOG.md', 'lib/**/*.rb')
14
+ rdoc.markup = 'tomdoc'
15
+ end
16
+
17
+ Rake::TestTask.new do |t|
18
+ t.libs << 'test'
19
+ t.test_files = FileList['test/test*.rb']
20
+ t.verbose = true
21
+ t.ruby_opts << '-rminitest/pride'
22
+ end
23
+
24
+ desc 'Update the gh-pages branch with doc/rdoc contents'
25
+ task :update_gh_pages do
26
+ tmpdir = Dir::Tmpname.create('plaid_docs') {}
27
+
28
+ desc = `git describe`.chomp
29
+
30
+ sh "git clone --shared . #{tmpdir}"
31
+
32
+ Dir.chdir(tmpdir) do
33
+ sh 'git checkout gh-pages'
34
+ FileUtils.rm_rf Dir.glob("#{tmpdir}/*")
35
+ end
36
+
37
+ FileUtils.cp_r Dir.glob('doc/rdoc/*'), tmpdir
38
+
39
+ Dir.chdir(tmpdir) do
40
+ sh 'git add .'
41
+ sh 'git add --update .'
42
+ sh "git commit --allow-empty -m 'Regenerate docs for #{desc}'"
43
+ sh 'git push'
44
+ end
45
+
46
+ FileUtils.rm_rf tmpdir
47
+ end
48
+
49
+ desc 'Generate rdoc and update gh-pages on GitHub'
50
+ task update_github_docs: %i(rdoc update_gh_pages) do
51
+ sh 'git push origin gh-pages'
52
+ end
53
+
54
+ task default: :test