money_mover 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +17 -0
  5. data/Gemfile.lock +80 -0
  6. data/lib/money_mover/dwolla/account_client.rb +9 -0
  7. data/lib/money_mover/dwolla/account_token.rb +24 -0
  8. data/lib/money_mover/dwolla/api_connection.rb +18 -0
  9. data/lib/money_mover/dwolla/api_server_response.rb +31 -0
  10. data/lib/money_mover/dwolla/application_client.rb +9 -0
  11. data/lib/money_mover/dwolla/application_token.rb +25 -0
  12. data/lib/money_mover/dwolla/client.rb +24 -0
  13. data/lib/money_mover/dwolla/config.rb +33 -0
  14. data/lib/money_mover/dwolla/environment_urls.rb +35 -0
  15. data/lib/money_mover/dwolla/error_handler.rb +30 -0
  16. data/lib/money_mover/dwolla/models/account_funding_source.rb +28 -0
  17. data/lib/money_mover/dwolla/models/api_resource.rb +70 -0
  18. data/lib/money_mover/dwolla/models/customer.rb +53 -0
  19. data/lib/money_mover/dwolla/models/document.rb +22 -0
  20. data/lib/money_mover/dwolla/models/funding_source.rb +30 -0
  21. data/lib/money_mover/dwolla/models/micro_deposit_initiation.rb +19 -0
  22. data/lib/money_mover/dwolla/models/micro_deposit_verification.rb +31 -0
  23. data/lib/money_mover/dwolla/models/receive_only_business_customer.rb +27 -0
  24. data/lib/money_mover/dwolla/models/receive_only_customer.rb +19 -0
  25. data/lib/money_mover/dwolla/models/root_account.rb +27 -0
  26. data/lib/money_mover/dwolla/models/transfer.rb +33 -0
  27. data/lib/money_mover/dwolla/models/unverified_business_customer.rb +43 -0
  28. data/lib/money_mover/dwolla/models/unverified_customer.rb +27 -0
  29. data/lib/money_mover/dwolla/models/verified_business_customer.rb +53 -0
  30. data/lib/money_mover/dwolla/models/webhook_subscription.rb +36 -0
  31. data/lib/money_mover/dwolla/token.rb +26 -0
  32. data/lib/money_mover/dwolla.rb +44 -0
  33. data/lib/money_mover/standalone_errors.rb +12 -0
  34. data/lib/money_mover/version.rb +3 -0
  35. data/lib/money_mover.rb +15 -0
  36. data/money_mover.gemspec +27 -0
  37. data/spec/integration/money_mover/dwolla/customers/create_spec.rb +75 -0
  38. data/spec/integration/money_mover/dwolla/customers/find_spec.rb +71 -0
  39. data/spec/integration/money_mover/dwolla/customers/funding-sources/create_spec.rb +40 -0
  40. data/spec/integration/money_mover/dwolla/documents/create_spec.rb +62 -0
  41. data/spec/integration/money_mover/dwolla/funding-sources/micro-deposits/initiation_spec.rb +52 -0
  42. data/spec/integration/money_mover/dwolla/funding-sources/micro-deposits/verification_spec.rb +77 -0
  43. data/spec/integration/money_mover/dwolla/transfers/create_spec.rb +80 -0
  44. data/spec/lib/money_mover/dwolla/client_spec.rb +101 -0
  45. data/spec/lib/money_mover/dwolla/config_spec.rb +20 -0
  46. data/spec/lib/money_mover/dwolla/error_handler_spec.rb +78 -0
  47. data/spec/lib/money_mover/dwolla/funding_source_spec.rb +94 -0
  48. data/spec/lib/money_mover/dwolla/microdeposits_initiation_spec.rb +36 -0
  49. data/spec/lib/money_mover/dwolla/root_account_spec.rb +86 -0
  50. data/spec/lib/money_mover/dwolla/token_spec.rb +101 -0
  51. data/spec/lib/money_mover/dwolla/transfer_spec.rb +94 -0
  52. data/spec/lib/money_mover/dwolla/webhook_subscription_spec.rb +199 -0
  53. data/spec/spec_helper.rb +121 -0
  54. data/spec/support/dwolla_helper.rb +330 -0
  55. data/spec/support/fixtures/sample.jpg +0 -0
  56. metadata +196 -0
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe MoneyMover::Dwolla::Transfer do
4
+ let(:funding_source_token) { 'funding_source_token' }
5
+ let(:destination_source_token) { 'destination_source_token' }
6
+ let(:amount) { '12.45' }
7
+ let(:metadata) { { ach_tranfer_id: 123 } }
8
+
9
+ let(:dwolla_errors) { [ ['key1', 'error1'], ['key2', 'error2'] ] }
10
+ let(:dwolla_response) { double 'dwolla response', success?: transfer_success?, resource_location: resource_location, resource_id: resource_id, errors: dwolla_errors }
11
+ let(:api_url) { 'https:://api/url' }
12
+ let(:dwolla_client) { double 'dwolla client', post: dwolla_response, api_url: api_url}
13
+
14
+ let(:resource_location) { double 'resource location' }
15
+ let(:resource_id) { double 'resource id' }
16
+
17
+ let(:transfer_success?) { true }
18
+
19
+ let(:attrs) {{
20
+ sender_funding_source_token: funding_source_token,
21
+ destination_funding_source_token: destination_source_token,
22
+ transfer_amount: amount,
23
+ metadata: metadata
24
+ }}
25
+
26
+ subject { described_class.new(attrs) }
27
+
28
+ before do
29
+ allow(MoneyMover::Dwolla::AccountClient).to receive(:new) { dwolla_client }
30
+ end
31
+
32
+ it { should validate_presence_of(:sender_funding_source_token) }
33
+ it { should validate_presence_of(:destination_funding_source_token) }
34
+ it { should validate_presence_of(:transfer_amount) }
35
+
36
+ describe '#save' do
37
+ let(:transfer_success?) { true }
38
+
39
+ let(:transfer_params) {
40
+ {
41
+ _links: {
42
+ destination: {
43
+ href: "#{api_url}/funding-sources/#{destination_source_token}"
44
+ },
45
+ source: {
46
+ href: "#{api_url}/funding-sources/#{funding_source_token}"
47
+ }
48
+ },
49
+ amount: {
50
+ value: amount.to_s,
51
+ currency: "USD"
52
+ },
53
+ metadata: metadata
54
+ }
55
+ }
56
+
57
+ context 'success' do
58
+ it 'returns true and sets resource_location and id' do
59
+ expect(dwolla_client).to receive(:post).with("/transfers", transfer_params)
60
+
61
+ expect(subject.save).to eq(true)
62
+
63
+ expect(subject.errors).to be_empty
64
+ expect(subject.resource_location).to eq(resource_location)
65
+ expect(subject.id).to eq(resource_id)
66
+ end
67
+ end
68
+
69
+ context 'validations fail' do
70
+ let(:funding_source_token) { nil }
71
+ let(:destination_source_token) { nil }
72
+ let(:amount) { nil }
73
+
74
+ it 'does not attempt to create transfer and returns false with errors' do
75
+ expect(dwolla_client).to_not receive(:post)
76
+
77
+ expect(subject.save).to eq(false)
78
+ expect(subject.errors.full_messages).to eq(["Sender funding source token can't be blank", "Destination funding source token can't be blank", "Transfer amount can't be blank"])
79
+ end
80
+ end
81
+
82
+ context 'dwolla error' do
83
+ let(:transfer_success?) { false }
84
+
85
+ it 'returns false and has errors' do
86
+ expect(dwolla_client).to receive(:post).with("/transfers", transfer_params)
87
+
88
+ expect(subject.save).to eq(false)
89
+ expect(subject.errors[:key1]).to eq(['error1'])
90
+ expect(subject.errors[:key2]).to eq(['error2'])
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,199 @@
1
+ require 'spec_helper'
2
+
3
+ describe MoneyMover::Dwolla::WebhookSubscription do
4
+ let(:dwolla_client) { double 'dwolla client' }
5
+ let(:response_body) { nil }
6
+
7
+ before do
8
+ allow(MoneyMover::Dwolla::ApplicationClient).to receive(:new) { dwolla_client }
9
+ end
10
+
11
+ describe '.all' do
12
+ let(:id1) { 'tokenizedid1' }
13
+ let(:id2) { 'tokenizedid2' }
14
+ let(:response_body) { { _embedded: { :'webhook-subscriptions' => [ sub1, sub2 ] } } }
15
+ let(:sub1) { { id: 'sub1', url: 'url1' } }
16
+ let(:sub2) { { id: 'sub2', url: 'url2' } }
17
+
18
+ let(:dwolla_response) { double 'dwolla response', body: response_body }
19
+
20
+ subject { described_class }
21
+
22
+ before do
23
+ allow(dwolla_client).to receive(:get).with('/webhook-subscriptions') { dwolla_response }
24
+ end
25
+
26
+ it 'returns expected ids' do
27
+ subscriptions = subject.all
28
+
29
+ expect(subscriptions.length).to eq(2)
30
+ expect(subscriptions[0].id).to eq(sub1[:id])
31
+ expect(subscriptions[0].url).to eq(sub1[:url])
32
+ expect(subscriptions[1].id).to eq(sub2[:id])
33
+ expect(subscriptions[1].url).to eq(sub2[:url])
34
+ end
35
+ end
36
+
37
+ describe '#save' do
38
+ let(:callback_url) { double 'callback url' }
39
+ let(:webhook_secret_key) { double 'webhook secret key' }
40
+
41
+ let(:resource_location) { double 'resource location' }
42
+ let(:resource_id) { double 'resource id' }
43
+ let(:response_errors) { [] }
44
+ let(:dwolla_response) { double 'dwolla response', success?: save_success?, errors: response_errors, resource_location: resource_location, resource_id: resource_id }
45
+
46
+ subject { described_class.new(url: callback_url, secret: webhook_secret_key) }
47
+
48
+ before do
49
+ allow(dwolla_client).to receive(:post).with('/webhook-subscriptions', { url: callback_url, secret: webhook_secret_key }) { dwolla_response }
50
+ end
51
+
52
+ context 'success' do
53
+ let(:save_success?) { true }
54
+
55
+ it 'sets resource properties and returns true' do
56
+ expect(subject.save).to eq(true)
57
+ expect(subject.id).to eq(resource_id)
58
+ expect(subject.resource_location).to eq(resource_location)
59
+ end
60
+ end
61
+
62
+ context 'failure' do
63
+ let(:save_success?) { false }
64
+ let(:response_errors) { [ [:base, 'Error1'], [:base, 'Error2'] ] }
65
+
66
+ it 'returns false and has errors' do
67
+ expect(subject.save).to eq(false)
68
+ expect(subject.errors[:base]).to eq(['Error1', 'Error2'])
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#destroy' do
74
+ let(:subscription_id) { 'dwollatokenid' }
75
+ let(:response_errors) { [] }
76
+ let(:dwolla_response) { double 'dwolla response', success?: delete_success?, errors: response_errors }
77
+
78
+ subject { described_class.new(id: subscription_id) }
79
+
80
+ before do
81
+ allow(dwolla_client).to receive(:delete).with("/webhook-subscriptions/#{subscription_id}") { dwolla_response }
82
+ end
83
+
84
+ context 'success' do
85
+ let(:delete_success?) { true }
86
+
87
+ it 'returns true' do
88
+ expect(subject.destroy).to eq(true)
89
+ end
90
+ end
91
+
92
+ context 'failure' do
93
+ let(:delete_success?) { false }
94
+ let(:response_errors) { [ [:base, 'Error1'], [:base, 'Error2'] ] }
95
+
96
+ it 'returns false and has errors' do
97
+ expect(subject.destroy).to eq(false)
98
+ expect(subject.errors[:base]).to eq(['Error1', 'Error2'])
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # INTEGRATION BLACK BOX TEST - making sure that application token is used instead of account token
105
+ describe MoneyMover::Dwolla::WebhookSubscription do
106
+ describe '.all' do
107
+ let(:id1) { 'tokenizedid1' }
108
+ let(:id2) { 'tokenizedid2' }
109
+ let(:webhooks_response) { { _embedded: { :'webhook-subscriptions' => [ sub1, sub2 ] } } }
110
+ let(:sub1) { { id: 'sub1', url: 'url1' } }
111
+ let(:sub2) { { id: 'sub2', url: 'url2' } }
112
+
113
+ let(:dwolla_response) { double 'dwolla response', body: response_body }
114
+
115
+ subject { described_class }
116
+
117
+ before do
118
+ dwolla_helper.stub_get_token_request
119
+ dwolla_helper.stub_get_webhook_subscriptions_request(webhooks_response)
120
+ end
121
+
122
+ it 'returns expected ids' do
123
+ subscriptions = subject.all
124
+
125
+ expect(subscriptions.length).to eq(2)
126
+ expect(subscriptions[0].id).to eq(sub1[:id])
127
+ expect(subscriptions[0].url).to eq(sub1[:url])
128
+ expect(subscriptions[1].id).to eq(sub2[:id])
129
+ expect(subscriptions[1].url).to eq(sub2[:url])
130
+ end
131
+ end
132
+
133
+ describe '#save' do
134
+ let(:callback_url) { "https://callbackurl.com" }
135
+ let(:webhook_secret_key) { "some-secret-key" }
136
+
137
+ let(:create_params) {{
138
+ url: callback_url,
139
+ secret: webhook_secret_key
140
+ }}
141
+
142
+ let(:webhook_token) { 'some-webhook-subscription-token' }
143
+ let(:webhook_location) { dwolla_helper.webhook_subscription_url(webhook_token) }
144
+
145
+ subject { described_class.new(url: callback_url, secret: webhook_secret_key) }
146
+
147
+ before do
148
+ dwolla_helper.stub_get_token_request
149
+ dwolla_helper.stub_create_webhook_subscription_request(create_params, create_response)
150
+ end
151
+
152
+ context 'success' do
153
+ let(:create_response) { dwolla_helper.create_webhook_success_response(webhook_token) }
154
+
155
+ it 'sets resource properties and returns true' do
156
+ expect(subject.save).to eq(true)
157
+ expect(subject.id).to eq(webhook_token)
158
+ expect(subject.resource_location).to eq(webhook_location)
159
+ end
160
+ end
161
+
162
+ context 'failure' do
163
+ let(:create_response) { dwolla_helper.error_response({ message: 'some error' }) }
164
+
165
+ it 'returns false and has errors' do
166
+ expect(subject.save).to eq(false)
167
+ expect(subject.errors[:base]).to eq(['some error'])
168
+ end
169
+ end
170
+ end
171
+
172
+ describe '#destroy' do
173
+ let(:subscription_id) { 'some-subscription-id' }
174
+
175
+ subject { described_class.new(id: subscription_id) }
176
+
177
+ before do
178
+ dwolla_helper.stub_get_token_request
179
+ dwolla_helper.stub_delete_webhook_subscription_request(subscription_id, delete_response)
180
+ end
181
+
182
+ context 'success' do
183
+ let(:delete_response) { dwolla_helper.resource_deleted_response }
184
+
185
+ it 'returns true' do
186
+ expect(subject.destroy).to eq(true)
187
+ end
188
+ end
189
+
190
+ context 'failure' do
191
+ let(:delete_response) { dwolla_helper.error_response({ message: 'some error' }) }
192
+
193
+ it 'returns false and has errors' do
194
+ expect(subject.destroy).to eq(false)
195
+ expect(subject.errors[:base]).to eq(['some error'])
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,121 @@
1
+ require 'shoulda-matchers'
2
+ require 'webmock/rspec'
3
+ require 'rack/test'
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+
23
+ require_relative '../lib/money_mover'
24
+
25
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
26
+
27
+ RSpec.configure do |config|
28
+ # rspec-expectations config goes here. You can use an alternate
29
+ # assertion/expectation library such as wrong or the stdlib/minitest
30
+ # assertions if you prefer.
31
+ config.expect_with :rspec do |expectations|
32
+ # This option will default to `true` in RSpec 4. It makes the `description`
33
+ # and `failure_message` of custom matchers include text for helper methods
34
+ # defined using `chain`, e.g.:
35
+ # be_bigger_than(2).and_smaller_than(4).description
36
+ # # => "be bigger than 2 and smaller than 4"
37
+ # ...rather than:
38
+ # # => "be bigger than 2"
39
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
40
+ end
41
+
42
+ config.include(Shoulda::Matchers::ActiveModel)
43
+
44
+ # rspec-mocks config goes here. You can use an alternate test double
45
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
46
+ config.mock_with :rspec do |mocks|
47
+ # Prevents you from mocking or stubbing a method that does not exist on
48
+ # a real object. This is generally recommended, and will default to
49
+ # `true` in RSpec 4.
50
+ mocks.verify_partial_doubles = true
51
+ end
52
+
53
+ config.before do
54
+ MoneyMover::Dwolla.config_provider = TestConfigProvider.new
55
+ end
56
+
57
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
58
+ # have no way to turn it off -- the option exists only for backwards
59
+ # compatibility in RSpec 3). It causes shared context metadata to be
60
+ # inherited by the metadata hash of host groups and examples, rather than
61
+ # triggering implicit auto-inclusion in groups with matching metadata.
62
+ config.shared_context_metadata_behavior = :apply_to_host_groups
63
+
64
+ # The settings below are suggested to provide a good initial experience
65
+ # with RSpec, but feel free to customize to your heart's content.
66
+ =begin
67
+ # This allows you to limit a spec run to individual examples or groups
68
+ # you care about by tagging them with `:focus` metadata. When nothing
69
+ # is tagged with `:focus`, all examples get run. RSpec also provides
70
+ # aliases for `it`, `describe`, and `context` that include `:focus`
71
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
72
+ config.filter_run_when_matching :focus
73
+
74
+ # Allows RSpec to persist some state between runs in order to support
75
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
76
+ # you configure your source control system to ignore this file.
77
+ config.example_status_persistence_file_path = "spec/examples.txt"
78
+
79
+ # Limits the available syntax to the non-monkey patched syntax that is
80
+ # recommended. For more details, see:
81
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
82
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
83
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
84
+ config.disable_monkey_patching!
85
+
86
+ # This setting enables warnings. It's recommended, but in some cases may
87
+ # be too noisy due to issues in dependencies.
88
+ config.warnings = true
89
+
90
+ # Many RSpec users commonly either run the entire suite or an individual
91
+ # file, and it's useful to allow more verbose output when running an
92
+ # individual spec file.
93
+ if config.files_to_run.one?
94
+ # Use the documentation formatter for detailed output,
95
+ # unless a formatter has already been configured
96
+ # (e.g. via a command-line flag).
97
+ config.default_formatter = 'doc'
98
+ end
99
+
100
+ # Print the 10 slowest examples and example groups at the
101
+ # end of the spec run, to help surface which specs are running
102
+ # particularly slow.
103
+ config.profile_examples = 10
104
+
105
+ # Run specs in random order to surface order dependencies. If you find an
106
+ # order dependency and want to debug it, you can fix the order by providing
107
+ # the seed, which is printed after each run.
108
+ # --seed 1234
109
+ config.order = :random
110
+
111
+ # Seed global randomization in this process using the `--seed` CLI option.
112
+ # Setting this allows you to use `--seed` to deterministically reproduce
113
+ # test failures related to randomization by passing the same `--seed` value
114
+ # as the one that triggered the failure.
115
+ Kernel.srand config.seed
116
+ =end
117
+ end
118
+
119
+ def dwolla_helper
120
+ @dwolla_helper ||= DwollaHelper.new
121
+ end