dune-balanced-bankaccount 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +34 -0
- data/app/assets/images/dune/balanced/bankaccount/.gitkip +0 -0
- data/app/assets/javascripts/dune-balanced-bankaccount.js +1 -0
- data/app/assets/javascripts/dune/balanced/bankaccount/.gitkip +0 -0
- data/app/assets/javascripts/dune/balanced/bankaccount/accounts.js.coffee.erb +24 -0
- data/app/assets/javascripts/dune/balanced/bankaccount/flash.js.coffee +16 -0
- data/app/assets/javascripts/dune/balanced/bankaccount/form.js.coffee.erb +90 -0
- data/app/assets/javascripts/dune/balanced/bankaccount/payments.js.coffee.erb +25 -0
- data/app/assets/stylesheets/dune/balanced/bankaccount/.gitkip +0 -0
- data/app/controllers/dune/balanced/bankaccount/accounts_controller.rb +67 -0
- data/app/controllers/dune/balanced/bankaccount/application_controller.rb +4 -0
- data/app/controllers/dune/balanced/bankaccount/confirmations_controller.rb +66 -0
- data/app/controllers/dune/balanced/bankaccount/payments_controller.rb +65 -0
- data/app/controllers/dune/balanced/bankaccount/routing_numbers_controller.rb +10 -0
- data/app/helpers/application_helper.rb +8 -0
- data/app/models/dune/balanced/bankaccount/delayed_payment.rb +18 -0
- data/app/models/dune/balanced/bankaccount/delayed_payment_processing.rb +22 -0
- data/app/models/dune/balanced/bankaccount/payment.rb +69 -0
- data/app/models/dune/balanced/bankaccount/payment_base.rb +44 -0
- data/app/models/dune/balanced/bankaccount/payment_generator.rb +38 -0
- data/app/models/dune/balanced/bankaccount/routing_number.rb +6 -0
- data/app/models/dune/balanced/bankaccount/transaction_additional_fee_calculator.rb +12 -0
- data/app/models/dune/balanced/bankaccount/transaction_fee_calculator_base.rb +34 -0
- data/app/models/dune/balanced/bankaccount/transaction_inclusive_fee_calculator.rb +16 -0
- data/app/models/dune/balanced/bankaccount/verification.rb +34 -0
- data/app/models/dune/balanced/event_registered.rb +13 -0
- data/app/views/dune/balanced/bankaccount/accounts/new.html.slim +96 -0
- data/app/views/dune/balanced/bankaccount/confirmations/new.html.slim +53 -0
- data/app/views/dune/balanced/bankaccount/payments/new.html.slim +97 -0
- data/app/views/notifications_mailer/balanced/bankaccount/bank_account_replaced.en.html.slim +12 -0
- data/app/views/notifications_mailer/balanced/bankaccount/confirm_bank_account.en.html.slim +16 -0
- data/app/views/notifications_mailer/balanced/bankaccount/new_verification_started.en.html.slim +14 -0
- data/app/views/notifications_mailer/subjects/balanced/bankaccount/bank_account_replaced.en.text.slim +1 -0
- data/app/views/notifications_mailer/subjects/balanced/bankaccount/confirm_bank_account.en.text.slim +1 -0
- data/app/views/notifications_mailer/subjects/balanced/bankaccount/new_verification_started.en.text.slim +1 -0
- data/app/workers/dune/balanced/bankaccount/debit_authorized_contributions_worker.rb +26 -0
- data/bin/rails +8 -0
- data/bin/test_suite +19 -0
- data/config/environment.rb +0 -0
- data/config/initializers/event_observers.rb +2 -0
- data/config/initializers/registration.rb +5 -0
- data/config/locales/en.yml +59 -0
- data/config/locales/simple_form.en.yml +21 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20140224220426_create_routing_number.rb +10 -0
- data/db/migrate/20140813180429_use_hrefs_for_balanced_resources.rb +41 -0
- data/dune-balanced-bankaccount.gemspec +29 -0
- data/lib/dune/balanced/bankaccount.rb +11 -0
- data/lib/dune/balanced/bankaccount/engine.rb +14 -0
- data/lib/dune/balanced/bankaccount/interface.rb +28 -0
- data/lib/dune/balanced/bankaccount/version.rb +7 -0
- data/lib/float_extensions.rb +11 -0
- data/lib/tasks/dune/balanced/bankaccount/update_routing_numbers.rake +27 -0
- data/spec/controllers/dune/balanced/bankaccount/accounts_controller_spec.rb +183 -0
- data/spec/controllers/dune/balanced/bankaccount/confirmations_controller_spec.rb +190 -0
- data/spec/controllers/dune/balanced/bankaccount/payments_controller_spec.rb +158 -0
- data/spec/controllers/dune/balanced/bankaccount/routing_numbers_controller_spec.rb +22 -0
- data/spec/factories.rb +47 -0
- data/spec/lib/dune/balanced/bankaccount/interface_spec.rb +37 -0
- data/spec/models/dune/balanced/bankaccount/delayed_payment_processing_spec.rb +38 -0
- data/spec/models/dune/balanced/bankaccount/delayed_payment_spec.rb +66 -0
- data/spec/models/dune/balanced/bankaccount/payment_generator_spec.rb +65 -0
- data/spec/models/dune/balanced/bankaccount/payment_spec.rb +252 -0
- data/spec/models/dune/balanced/bankaccount/routing_number_spec.rb +6 -0
- data/spec/models/dune/balanced/bankaccount/transaction_additional_fee_calculator_spec.rb +53 -0
- data/spec/models/dune/balanced/bankaccount/transaction_inclusive_fee_calculator_spec.rb +34 -0
- data/spec/models/dune/balanced/bankaccount/verification_spec.rb +34 -0
- data/spec/models/dune/balanced/event_registered_spec.rb +51 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/workers/dune/balanced/bankaccount/debit_authorized_contributions_worker_spec.rb +71 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5eac95a0a387376d42c05b3280307c3e3dece15
|
4
|
+
data.tar.gz: 89136bb7e8b120076282dad8210ff6392bd0c841
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3714c6233f15c9fb2e9e533e69580fbab2379ffb0ed2144aae9a86d6a4bc664eca2a7ecfddeaa29226aea9fbea06b2830538b2b326f4a61eb5934e7748fe44d
|
7
|
+
data.tar.gz: 0e260bfd8f9c96ab0bb49ac7c07b75dc08d136026cd83d56e1b3d29f146f66a005df871aee66acf26ea59758579908d70546ec344faaf6921af434dba5427682
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
spec/dummy/db/*.sqlite3
|
19
|
+
spec/dummy/log/
|
20
|
+
.env
|
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemfile_url = File.join(File.dirname(__FILE__), 'spec/dummy/Gemfile')
|
4
|
+
gemfile_content = File.open(gemfile_url, 'rb') { |f| f.read }
|
5
|
+
|
6
|
+
gemspec_gems = %w(
|
7
|
+
dune-balanced-bankaccount'
|
8
|
+
dune-balanced'
|
9
|
+
rspec-rails'
|
10
|
+
spring'
|
11
|
+
)
|
12
|
+
eval_gemfile gemfile_url, (gemfile_content.split("\n").reject do |line|
|
13
|
+
line.empty? || Regexp.union(*gemspec_gems).match(line)
|
14
|
+
end.join("\n"))
|
15
|
+
|
16
|
+
gemspec
|
17
|
+
gem 'dune-balanced', github: 'FromUte/dune-balanced', branch: :master
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Josemar Luedke
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Dune::Balanced::Bankaccount
|
2
|
+
|
3
|
+
## What
|
4
|
+
|
5
|
+
This is an integration between [Balanced](https://www.balancedpayments.com/) and [dune-investissement](https://github.com/FromUte/dune), a crowdfunding platform.
|
6
|
+
|
7
|
+
## How
|
8
|
+
|
9
|
+
Include this gem as dependency of your project, adding the following line in your `Gemfile`.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# Gemfile
|
13
|
+
gem 'dune-balanced-bankaccount'
|
14
|
+
```
|
15
|
+
|
16
|
+
Dune::Balanced::Bankaccount is a Rails Engine, integrating with your (Neighbor.ly Donate) Rails application with very little of effort. To turn the engine on, mount it in an appropriate route:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# config/routes.rb
|
20
|
+
mount Dune::Balanced::Bankaccount::Engine => '/', as: 'dune_balanced_bankaccount'
|
21
|
+
```
|
22
|
+
|
23
|
+
And load our JavaScript:
|
24
|
+
|
25
|
+
```coffeescript
|
26
|
+
//= require dune-balanced-bankaccount
|
27
|
+
```
|
28
|
+
|
29
|
+
And install the engine:
|
30
|
+
|
31
|
+
```console
|
32
|
+
$ bundle exec rake railties:install:migrations db:migrate
|
33
|
+
```
|
34
|
+
|
35
|
+
### Load/Update Routing Numbers in database
|
36
|
+
|
37
|
+
We have a rake task to update the Routing Numbers from [fededirectory.frb.org](http://www.fededirectory.frb.org/fpddir.txt) with the Bank Name.
|
38
|
+
|
39
|
+
From your main app, just run:
|
40
|
+
|
41
|
+
`$ rake dune_balanced_bankaccount:update_routing_numbers`
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
50
|
+
|
51
|
+
### Running specs
|
52
|
+
|
53
|
+
We prize for our test suite and coverage, so it would be great if you could run the specs to ensure that your patch is not breaking the existing codebase.
|
54
|
+
|
55
|
+
`bundle exec rspec`
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
Licensed under the [MIT license](LICENSE.txt).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
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 = 'Dune::Balanced::Bankaccount'
|
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
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree .
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Dune.Dune ?= {}
|
2
|
+
Dune.Dune.Balanced ?= {}
|
3
|
+
Dune.Dune.Balanced.Bankaccount ?= {}
|
4
|
+
Dune.Dune.Balanced.Bankaccount.Accounts ?= {}
|
5
|
+
|
6
|
+
Dune.Dune.Balanced.Bankaccount.Accounts.New =
|
7
|
+
modules: -> [Dune.Dune.Balanced.Bankaccount.Form]
|
8
|
+
init: Backbone.View.extend
|
9
|
+
el: '.dune-balanced-bankaccount-form'
|
10
|
+
|
11
|
+
initialize: ->
|
12
|
+
_.bindAll(this, 'toggleSelected', 'toggleReplaceBank')
|
13
|
+
this.$('input[name="payment[show_bank]"]').bind('change', this.toggleReplaceBank)
|
14
|
+
this.$('input[type=radio]').bind('change', this.toggleSelected)
|
15
|
+
this.toggleSelected()
|
16
|
+
|
17
|
+
toggleSelected: ->
|
18
|
+
this.$('.bank-box').removeClass('selected')
|
19
|
+
this.$('input[type=radio]:checked.show-bank').parents('.bank-box').addClass('selected')
|
20
|
+
|
21
|
+
toggleReplaceBank: (event)->
|
22
|
+
$box = $(event.currentTarget).parents('.bank-box')
|
23
|
+
$('.expandable').addClass('hide')
|
24
|
+
$box.find('.expandable').removeClass('hide')
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Dune.Dune ?= {}
|
2
|
+
Dune.Dune.Balanced ?= {}
|
3
|
+
Dune.Dune.Balanced.Bankaccount ?= {}
|
4
|
+
|
5
|
+
Dune.Dune.Balanced.Bankaccount.Flash =
|
6
|
+
message: (text)->
|
7
|
+
this.remove()
|
8
|
+
alertBox = $('<div>', { 'class': 'alert-box error text-center', 'html':
|
9
|
+
$('<h5>', { 'html': text })
|
10
|
+
} )
|
11
|
+
errorBoxWrapper = $('<div>', { 'class': 'error-box large-12 columns hide', 'html': alertBox}).insertBefore('.dune-balanced-bankaccount-form .submit')
|
12
|
+
errorBoxWrapper.fadeIn(300)
|
13
|
+
|
14
|
+
remove: ->
|
15
|
+
$('.error-box').remove()
|
16
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Dune.Dune ?= {}
|
2
|
+
Dune.Dune.Balanced ?= {}
|
3
|
+
Dune.Dune.Balanced.Bankaccount ?= {}
|
4
|
+
|
5
|
+
Dune.Dune.Balanced.Bankaccount.Form = Backbone.View.extend
|
6
|
+
el: '.dune-balanced-bankaccount-form'
|
7
|
+
|
8
|
+
initialize: ->
|
9
|
+
_.bindAll(this, 'submit', 'submitToBalanced')
|
10
|
+
this.Flash = Dune.Dune.Balanced.Bankaccount.Flash
|
11
|
+
|
12
|
+
$.getScript 'https://js.balancedpayments.com/1.1/balanced.js'
|
13
|
+
|
14
|
+
this.$form = this.$('form')
|
15
|
+
this.$form.bind('submit', this.submit)
|
16
|
+
this.$('#payment_routing_number').bind('blur', this.showBankName)
|
17
|
+
this.$('input[type=radio]').bind('change', this.fixFoundationRadio)
|
18
|
+
|
19
|
+
fixFoundationRadio: =>
|
20
|
+
this.$('.radio.checked').removeClass('checked')
|
21
|
+
this.$('input[type=radio]:checked ~ .radio').addClass('checked')
|
22
|
+
|
23
|
+
submit: (event) ->
|
24
|
+
selectedBank = this.$('[name="payment[use_bank]"]:checked, [name="payment[use_bank]"]:hidden')
|
25
|
+
return if $.inArray(selectedBank.val(), ['new', '']) == -1
|
26
|
+
|
27
|
+
event.preventDefault()
|
28
|
+
|
29
|
+
that = this
|
30
|
+
routing_number_path = $('[data-routing-number-path]').
|
31
|
+
data('routing-number-path').
|
32
|
+
replace('id', this.$('#payment_routing_number').val())
|
33
|
+
|
34
|
+
error_handler = ->
|
35
|
+
that.Flash.message('<%= I18n.t('dune.balanced.bankaccount.payments.new.errors.routing_number') %>')
|
36
|
+
$.rails.enableFormElements($('.dune-balanced-bankaccount-form'))
|
37
|
+
$submit = $('.dune-balanced-bankaccount-form input[type=submit]')
|
38
|
+
$submit.val($submit.data('enable-with'))
|
39
|
+
|
40
|
+
$.getJSON routing_number_path, (response) ->
|
41
|
+
if response.ok
|
42
|
+
that.Flash.remove()
|
43
|
+
that.$('.simple_form.payment').attr('novalidate', '')
|
44
|
+
|
45
|
+
that.submitToBalanced(selectedBank)
|
46
|
+
else
|
47
|
+
error_handler()
|
48
|
+
.error ->
|
49
|
+
error_handler()
|
50
|
+
|
51
|
+
submitToBalanced: (selectedBank) ->
|
52
|
+
$.rails.disableFormElements($('.dune-balanced-bankaccount-form'))
|
53
|
+
bankAccountData =
|
54
|
+
name: this.$('#payment_account_holder_name').val()
|
55
|
+
routing_number: this.$('#payment_routing_number').val()
|
56
|
+
account_number: this.$('#payment_account_number').val()
|
57
|
+
account_type: this.$('input[name="payment[account_type]"]:checked').val()
|
58
|
+
|
59
|
+
this.$('[data-balanced-bank-account-input]').val('')
|
60
|
+
|
61
|
+
balanced_callback_for_201 = (response) ->
|
62
|
+
selectedBank.val(response.bank_accounts[0].href)
|
63
|
+
$('[data-balanced-bankaccount-form] form').submit()
|
64
|
+
|
65
|
+
that = this
|
66
|
+
balanced_callback_for_402 = (response) ->
|
67
|
+
that.Flash.message('<%= I18n.t('dune.balanced.bankaccount.payments.new.errors.bank_error') %>')
|
68
|
+
$.rails.enableFormElements($('.dune-balanced-bankaccount-form'))
|
69
|
+
$submit = $('.dune-balanced-bankaccount-form input[type=submit]')
|
70
|
+
$submit.val($submit.data('enable-with'))
|
71
|
+
|
72
|
+
balanced.bankAccount.create bankAccountData, (response) ->
|
73
|
+
switch response.status_code
|
74
|
+
when 201 then balanced_callback_for_201(response)
|
75
|
+
when 402 then balanced_callback_for_402(response)
|
76
|
+
|
77
|
+
showBankName: (e)=>
|
78
|
+
number = $.trim(this.$('#payment_routing_number').val())
|
79
|
+
unless number.length is 9
|
80
|
+
this.$('#payment_bank_name').val('')
|
81
|
+
return
|
82
|
+
|
83
|
+
$.getJSON $('[data-routing-number-path]').data('routing-number-path').replace('id', number), (response) =>
|
84
|
+
if response.ok
|
85
|
+
this.$('#payment_bank_name').val($.trim(response.bank_name))
|
86
|
+
else
|
87
|
+
this.$('#payment_bank_name').val('')
|
88
|
+
|
89
|
+
|
90
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Dune.Dune ?= {}
|
2
|
+
Dune.Dune.Balanced ?= {}
|
3
|
+
Dune.Dune.Balanced.Bankaccount ?= {}
|
4
|
+
Dune.Dune.Balanced.Bankaccount.Payments ?= {}
|
5
|
+
|
6
|
+
Dune.Dune.Balanced.Bankaccount.Payments.New =
|
7
|
+
modules: -> [Dune.Dune.Balanced.Bankaccount.Form]
|
8
|
+
init: Backbone.View.extend
|
9
|
+
el: '.dune-balanced-bankaccount-form'
|
10
|
+
|
11
|
+
initialize: ->
|
12
|
+
_.bindAll(this, 'toggleSelected', 'toggleReplaceBank')
|
13
|
+
this.$('input[name="payment[use_bank]"]').bind('change', this.toggleReplaceBank)
|
14
|
+
this.$('input[type=radio]').bind('change', this.toggleSelected)
|
15
|
+
this.toggleSelected()
|
16
|
+
|
17
|
+
toggleSelected: ->
|
18
|
+
this.$('.bank-box').removeClass('selected')
|
19
|
+
this.$('input[type=radio]:checked.use-bank').parents('.bank-box').addClass('selected')
|
20
|
+
|
21
|
+
toggleReplaceBank: ->
|
22
|
+
if this.$('#payment_use_bank_new').is(':checked')
|
23
|
+
this.$('.add-new-bankaccount-form').removeClass('hide')
|
24
|
+
else
|
25
|
+
this.$('.add-new-bankaccount-form').addClass('hide')
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Dune::Balanced::Bankaccount
|
2
|
+
class AccountsController < ActionController::Base
|
3
|
+
before_filter :authenticate_user!
|
4
|
+
|
5
|
+
def new
|
6
|
+
@bank_account = customer.bank_accounts.to_a.last
|
7
|
+
render layout: false
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
attach_bank_to_customer
|
12
|
+
|
13
|
+
flash[:success] = t('dune.balanced.bankaccount.accounts.create.success')
|
14
|
+
redirect_to main_app.payments_user_path(current_user)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def attach_bank_to_customer
|
20
|
+
bank_account = Balanced::BankAccount.find(resource_params.fetch(:use_bank))
|
21
|
+
unless customer_bank_accounts.any? { |c| c.href.eql? bank_account.href }
|
22
|
+
Dune::Balanced::Contributor.
|
23
|
+
find_or_create_by(user_id: current_user.id).
|
24
|
+
update_attributes(bank_account_href: bank_account.href)
|
25
|
+
notify_user_about_replacement
|
26
|
+
unstore_all_bank_accounts
|
27
|
+
# Not calling #reload raises Balanced::ConflictError when attaching a
|
28
|
+
# new card after unstoring others.
|
29
|
+
bank_account.associate_to_customer(customer)
|
30
|
+
verify_bank_account(bank_account)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def notify_user_about_replacement
|
35
|
+
Notification.notify('balanced/bankaccount/bank_account_replaced',
|
36
|
+
current_user) if customer_bank_accounts.any?
|
37
|
+
end
|
38
|
+
|
39
|
+
def verify_bank_account(bank_account)
|
40
|
+
bank_account.verify
|
41
|
+
end
|
42
|
+
|
43
|
+
def unstore_all_bank_accounts
|
44
|
+
customer_bank_accounts.each do |bank|
|
45
|
+
bank.unstore
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def customer_bank_accounts
|
50
|
+
@bank_accounts ||= customer.bank_accounts.to_a
|
51
|
+
end
|
52
|
+
|
53
|
+
def resource_params
|
54
|
+
params.require(:payment).
|
55
|
+
permit(:contribution_id,
|
56
|
+
:match_id,
|
57
|
+
:use_bank,
|
58
|
+
:pay_fee,
|
59
|
+
user: {})
|
60
|
+
end
|
61
|
+
|
62
|
+
def customer
|
63
|
+
@customer ||= Dune::Balanced::Customer.new(current_user, params).fetch
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Dune::Balanced::Bankaccount
|
2
|
+
class ConfirmationsController < ApplicationController
|
3
|
+
before_filter :authenticate_user!
|
4
|
+
before_action :check_bank_account_availability, only: :new
|
5
|
+
|
6
|
+
def new
|
7
|
+
@verification = verification
|
8
|
+
@contributions = current_user.contributions.with_state(:waiting_confirmation)
|
9
|
+
render layout: 'application'
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
verification.confirm(params[:confirmation][:amount_1],
|
14
|
+
params[:confirmation][:amount_2])
|
15
|
+
|
16
|
+
flash.notice = t('.messages.success')
|
17
|
+
redirect_to main_app.payments_user_path(current_user)
|
18
|
+
rescue Balanced::BankAccountVerificationFailure
|
19
|
+
# Balanced does not decrease BankAccountVerification#attempts_remaining
|
20
|
+
# after a failure
|
21
|
+
@attempts_remaining = verification.attempts_remaining - 1
|
22
|
+
flash.alert = t('.messages.unable_to_verify')
|
23
|
+
check_for_attempts_remaining
|
24
|
+
redirect_to new_confirmation_path
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def check_for_attempts_remaining
|
29
|
+
if @attempts_remaining.zero?
|
30
|
+
flash.alert = t('.messages.none_attempts_remaining')
|
31
|
+
create_new_verification
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_new_verification
|
36
|
+
bank_account.verify
|
37
|
+
Notification.notify('balanced/bankaccount/new_verification_started',
|
38
|
+
current_user)
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_bank_account_availability
|
42
|
+
if bank_account
|
43
|
+
if verification.try(:verification_status) == 'succeeded'
|
44
|
+
flash.alert = t('.errors.already_confirmed')
|
45
|
+
has_errors = true
|
46
|
+
end
|
47
|
+
else
|
48
|
+
flash.alert = t('.errors.bank_account_not_found')
|
49
|
+
has_errors = true
|
50
|
+
end
|
51
|
+
redirect_to main_app.payments_user_path(current_user) if has_errors
|
52
|
+
end
|
53
|
+
|
54
|
+
def verification
|
55
|
+
@verification ||= bank_account.bank_account_verifications.to_a.first
|
56
|
+
end
|
57
|
+
|
58
|
+
def bank_account
|
59
|
+
@bank_account ||= customer.bank_accounts.to_a.last
|
60
|
+
end
|
61
|
+
|
62
|
+
def customer
|
63
|
+
@customer ||= Dune::Balanced::Customer.new(current_user, params).fetch
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|