catarse_pagarme 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +120 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +35 -0
  7. data/Rakefile +34 -0
  8. data/app/assets/images/catarse_pagarme/.keep +0 -0
  9. data/app/assets/javascripts/catarse_pagarme.js +5 -0
  10. data/app/assets/javascripts/catarse_pagarme/application.js +12 -0
  11. data/app/assets/javascripts/catarse_pagarme/credit_card.js +142 -0
  12. data/app/assets/javascripts/catarse_pagarme/payment_choice.js +22 -0
  13. data/app/assets/javascripts/catarse_pagarme/payment_slip.js +63 -0
  14. data/app/assets/stylesheets/catarse_pagarme/application.css +15 -0
  15. data/app/controllers/catarse_pagarme/application_controller.rb +51 -0
  16. data/app/controllers/catarse_pagarme/credit_card_base_controller.rb +48 -0
  17. data/app/controllers/catarse_pagarme/credit_cards_controller.rb +8 -0
  18. data/app/controllers/catarse_pagarme/notifications_controller.rb +20 -0
  19. data/app/controllers/catarse_pagarme/pagarme_controller.rb +10 -0
  20. data/app/controllers/catarse_pagarme/slip_controller.rb +43 -0
  21. data/app/controllers/catarse_pagarme/subscriptions_controller.rb +27 -0
  22. data/app/helpers/catarse_pagarme/application_helper.rb +23 -0
  23. data/app/models/catarse_pagarme/contribution_concern.rb +9 -0
  24. data/app/models/catarse_pagarme/contribution_delegator.rb +94 -0
  25. data/app/models/catarse_pagarme/credit_card_concern.rb +9 -0
  26. data/app/models/catarse_pagarme/credit_card_delegator.rb +26 -0
  27. data/app/models/catarse_pagarme/credit_card_transaction.rb +11 -0
  28. data/app/models/catarse_pagarme/payment_type.rb +6 -0
  29. data/app/models/catarse_pagarme/save_credit_card_transaction.rb +33 -0
  30. data/app/models/catarse_pagarme/slip_transaction.rb +37 -0
  31. data/app/models/catarse_pagarme/subscription_transaction.rb +21 -0
  32. data/app/models/catarse_pagarme/transaction_base.rb +36 -0
  33. data/app/views/catarse_pagarme/pagarme/review.html.slim +112 -0
  34. data/app/views/layouts/catarse_pagarme/application.html.erb +14 -0
  35. data/bin/rails +12 -0
  36. data/catarse_pagarme.gemspec +26 -0
  37. data/config/initializers/register.rb +5 -0
  38. data/config/routes.rb +15 -0
  39. data/lib/catarse_pagarme.rb +19 -0
  40. data/lib/catarse_pagarme/configuration.rb +16 -0
  41. data/lib/catarse_pagarme/engine.rb +10 -0
  42. data/lib/catarse_pagarme/payment_engine.rb +37 -0
  43. data/lib/catarse_pagarme/version.rb +3 -0
  44. data/lib/tasks/catarse_pagarme_tasks.rake +4 -0
  45. data/spec/controllers/catarse_pagarme/credit_cards_controller_spec.rb +62 -0
  46. data/spec/controllers/catarse_pagarme/notifications_controller_spec.rb +41 -0
  47. data/spec/controllers/catarse_pagarme/pagarme_controller_spec.rb +5 -0
  48. data/spec/controllers/catarse_pagarme/slip_controller_spec.rb +68 -0
  49. data/spec/controllers/catarse_pagarme/subscriptions_controller_spec.rb +95 -0
  50. data/spec/dummy/README.rdoc +28 -0
  51. data/spec/dummy/Rakefile +6 -0
  52. data/spec/dummy/app/assets/images/.keep +0 -0
  53. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  54. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  55. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  56. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  57. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  58. data/spec/dummy/app/mailers/.keep +0 -0
  59. data/spec/dummy/app/models/.keep +0 -0
  60. data/spec/dummy/app/models/bank_account.rb +5 -0
  61. data/spec/dummy/app/models/category.rb +2 -0
  62. data/spec/dummy/app/models/concerns/.keep +0 -0
  63. data/spec/dummy/app/models/contribution.rb +29 -0
  64. data/spec/dummy/app/models/credit_card.rb +3 -0
  65. data/spec/dummy/app/models/payment_engines.rb +2 -0
  66. data/spec/dummy/app/models/payment_notification.rb +3 -0
  67. data/spec/dummy/app/models/project.rb +5 -0
  68. data/spec/dummy/app/models/user.rb +13 -0
  69. data/spec/dummy/app/models/user_total.rb +3 -0
  70. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/spec/dummy/bin/bundle +3 -0
  72. data/spec/dummy/bin/rails +4 -0
  73. data/spec/dummy/bin/rake +4 -0
  74. data/spec/dummy/config.ru +4 -0
  75. data/spec/dummy/config/application.rb +23 -0
  76. data/spec/dummy/config/boot.rb +5 -0
  77. data/spec/dummy/config/database.yml +55 -0
  78. data/spec/dummy/config/environment.rb +5 -0
  79. data/spec/dummy/config/environments/development.rb +37 -0
  80. data/spec/dummy/config/environments/production.rb +82 -0
  81. data/spec/dummy/config/environments/test.rb +39 -0
  82. data/spec/dummy/config/initializers/assets.rb +8 -0
  83. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  84. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  85. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  86. data/spec/dummy/config/initializers/inflections.rb +16 -0
  87. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  88. data/spec/dummy/config/initializers/pagarme.rb +6 -0
  89. data/spec/dummy/config/initializers/session_store.rb +3 -0
  90. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  91. data/spec/dummy/config/locales/en.yml +23 -0
  92. data/spec/dummy/config/routes.rb +3 -0
  93. data/spec/dummy/config/secrets.yml +22 -0
  94. data/spec/dummy/lib/assets/.keep +0 -0
  95. data/spec/dummy/public/404.html +67 -0
  96. data/spec/dummy/public/422.html +67 -0
  97. data/spec/dummy/public/500.html +66 -0
  98. data/spec/dummy/public/favicon.ico +0 -0
  99. data/spec/helpers/catarse_pagarme/application_helper_spec.rb +23 -0
  100. data/spec/models/catarse_pagarme/contribution_delegator_spec.rb +146 -0
  101. data/spec/models/catarse_pagarme/credit_card_transaction_spec.rb +70 -0
  102. data/spec/models/catarse_pagarme/slip_transaction_spec.rb +102 -0
  103. data/spec/spec_helper.rb +36 -0
  104. data/spec/support/factories.rb +70 -0
  105. metadata +280 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8eefd863b2b6d2302f3925cd7b04f5363b64d681
4
+ data.tar.gz: dc85367d062a5f30fb2eb4c2b710b209900b1fd5
5
+ SHA512:
6
+ metadata.gz: b41ba15579bce2ac67921611123e912327e5b761f03136e609b928787db5f16909c8c37b254c59f9db08bb746e040ccdd1e8bc7776e1d3f6c6aca912f2e8119c
7
+ data.tar.gz: 9596b52bf901061ceb373c84c0ac290331270b0d73902369df233c7d4a48e7424edcb7154073b649bc3c158fd70bdbcd4ba1e1818faef8c98531ec8ab4bbfb13
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ test/dummy/.sass-cache
9
+ *.gem
10
+ spec/dummy/log/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,120 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ catarse_pagarme (0.0.1)
5
+ pagarme (~> 1.9.5)
6
+ rails (~> 4.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.1.4)
12
+ actionpack (= 4.1.4)
13
+ actionview (= 4.1.4)
14
+ mail (~> 2.5.4)
15
+ actionpack (4.1.4)
16
+ actionview (= 4.1.4)
17
+ activesupport (= 4.1.4)
18
+ rack (~> 1.5.2)
19
+ rack-test (~> 0.6.2)
20
+ actionview (4.1.4)
21
+ activesupport (= 4.1.4)
22
+ builder (~> 3.1)
23
+ erubis (~> 2.7.0)
24
+ activemodel (4.1.4)
25
+ activesupport (= 4.1.4)
26
+ builder (~> 3.1)
27
+ activerecord (4.1.4)
28
+ activemodel (= 4.1.4)
29
+ activesupport (= 4.1.4)
30
+ arel (~> 5.0.0)
31
+ activesupport (4.1.4)
32
+ i18n (~> 0.6, >= 0.6.9)
33
+ json (~> 1.7, >= 1.7.7)
34
+ minitest (~> 5.1)
35
+ thread_safe (~> 0.1)
36
+ tzinfo (~> 1.1)
37
+ arel (5.0.1.20140414130214)
38
+ builder (3.2.2)
39
+ diff-lcs (1.2.5)
40
+ erubis (2.7.0)
41
+ factory_girl (4.4.0)
42
+ activesupport (>= 3.0.0)
43
+ factory_girl_rails (4.4.1)
44
+ factory_girl (~> 4.4.0)
45
+ railties (>= 3.0.0)
46
+ hike (1.2.3)
47
+ i18n (0.6.11)
48
+ json (1.8.1)
49
+ mail (2.5.4)
50
+ mime-types (~> 1.16)
51
+ treetop (~> 1.4.8)
52
+ mime-types (1.25.1)
53
+ minitest (5.4.0)
54
+ multi_json (1.10.1)
55
+ netrc (0.7.7)
56
+ pagarme (1.9.6)
57
+ multi_json
58
+ rest-client
59
+ pg (0.17.1)
60
+ polyglot (0.3.5)
61
+ rack (1.5.2)
62
+ rack-test (0.6.2)
63
+ rack (>= 1.0)
64
+ rails (4.1.4)
65
+ actionmailer (= 4.1.4)
66
+ actionpack (= 4.1.4)
67
+ actionview (= 4.1.4)
68
+ activemodel (= 4.1.4)
69
+ activerecord (= 4.1.4)
70
+ activesupport (= 4.1.4)
71
+ bundler (>= 1.3.0, < 2.0)
72
+ railties (= 4.1.4)
73
+ sprockets-rails (~> 2.0)
74
+ railties (4.1.4)
75
+ actionpack (= 4.1.4)
76
+ activesupport (= 4.1.4)
77
+ rake (>= 0.8.7)
78
+ thor (>= 0.18.1, < 2.0)
79
+ rake (10.3.2)
80
+ rest-client (1.7.2)
81
+ mime-types (>= 1.16, < 3.0)
82
+ netrc (~> 0.7)
83
+ rspec-core (2.14.8)
84
+ rspec-expectations (2.14.5)
85
+ diff-lcs (>= 1.1.3, < 2.0)
86
+ rspec-mocks (2.14.6)
87
+ rspec-rails (2.14.2)
88
+ actionpack (>= 3.0)
89
+ activemodel (>= 3.0)
90
+ activesupport (>= 3.0)
91
+ railties (>= 3.0)
92
+ rspec-core (~> 2.14.0)
93
+ rspec-expectations (~> 2.14.0)
94
+ rspec-mocks (~> 2.14.0)
95
+ sprockets (2.12.1)
96
+ hike (~> 1.2)
97
+ multi_json (~> 1.0)
98
+ rack (~> 1.0)
99
+ tilt (~> 1.1, != 1.3.0)
100
+ sprockets-rails (2.1.4)
101
+ actionpack (>= 3.0)
102
+ activesupport (>= 3.0)
103
+ sprockets (~> 2.8)
104
+ thor (0.19.1)
105
+ thread_safe (0.3.4)
106
+ tilt (1.4.1)
107
+ treetop (1.4.15)
108
+ polyglot
109
+ polyglot (>= 0.3.1)
110
+ tzinfo (1.2.1)
111
+ thread_safe (~> 0.1)
112
+
113
+ PLATFORMS
114
+ ruby
115
+
116
+ DEPENDENCIES
117
+ catarse_pagarme!
118
+ factory_girl_rails
119
+ pg
120
+ rspec-rails (~> 2.14.0)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 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/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # CatarsePagarme [![Code Climate](https://codeclimate.com/github/catarse/catarse_pagarme/badges/gpa.svg)](https://codeclimate.com/github/catarse/catarse_pagarme)
2
+
3
+ A [Pagar.me](http://pagar.me) payment engine for [Catarse](http://github.com/catarse/catarse)
4
+
5
+ ## Installation
6
+
7
+ For now we are under development, but you can install directly via git on Gemfile
8
+
9
+ ```
10
+ gem 'catarse_pagarme', github: 'catarse/catarse_pagarme'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Configure the routes for your Catarse application. Add the following lines in the routes file (config/routes.rb):
16
+
17
+ ```
18
+ mount CatarsePagarme::Engine => "/", :as => "catarse_moip"
19
+ ```
20
+
21
+ create an (config/initializers/pagarme.rb) and configure with:
22
+
23
+
24
+ ```
25
+ CatarsePagarme.configure do |config|
26
+ config.api_key = "API_KEY"
27
+ config.slip_tax = "Slip payment tax"
28
+ config.credit_card_tax = "Credit card transaction tax don't need to define the 0.39"
29
+ config.interest_rate = "Interest rate for installments"
30
+ end
31
+ ```
32
+
33
+
34
+
35
+ This project rocks and uses MIT-LICENSE.
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 = 'CatarsePagarme'
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 = 'spec/**/*_spec.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
File without changes
@@ -0,0 +1,5 @@
1
+ //= require_tree ./catarse_pagarme
2
+
3
+ $(function(){
4
+ app.createViewGetters();
5
+ });
@@ -0,0 +1,12 @@
1
+ App.addChild('PagarmeForm', {
2
+ el: 'form.pagarme',
3
+
4
+ activate: function() {
5
+ this.message = this.$('.next_step_after_valid_document .alert-danger');
6
+ this.loader = this.$('.loader');
7
+
8
+ this.contributionId = $('input#contribution_id').val();
9
+ this.projectId = $('input#project_id').val();
10
+ }
11
+ });
12
+
@@ -0,0 +1,142 @@
1
+ App.views.PagarmeForm.addChild('PaymentCard', {
2
+ el: '#payment_type_credit_card_section',
3
+
4
+ events: {
5
+ 'keyup input[type="text"]' : 'creditCardInputValidator',
6
+ 'keyup #payment_card_number' : 'onKeyupPaymentCardNumber',
7
+ 'click input#credit_card_submit' : 'onSubmit',
8
+ 'click a.use_another-card': 'showCreditCardForm'
9
+ },
10
+
11
+ activate: function(options){
12
+ var that = this;
13
+ this.pagarmeForm = this.parent;
14
+ this.message = this.$('.alert-danger');
15
+ this.$('input#payment_card_date').mask('99/99');
16
+ },
17
+
18
+ showCreditCardForm: function(e) {
19
+ var that = this;
20
+ e.preventDefault();
21
+
22
+ that.$('ul.my_credit_cards').hide();
23
+ that.$('a.use_another-card ').hide();
24
+ that.$('.type_card_data').show();
25
+ that.$('.save_card').show();
26
+
27
+ $.each(that.$('.my_credit_cards input:radio[name=payment_subscription_card]'), function(i, item) {
28
+ $(item).prop('checked', false);
29
+ });
30
+ },
31
+
32
+ getUrl: function(){
33
+ var that = this;
34
+ var url = '';
35
+
36
+ if(that.$('input#payment_save_card').prop('checked') || that.hasSelectedSomeCard()) {
37
+ url = '/payment/pagarme/'+that.parent.contributionId+'/pay_with_subscription';
38
+ } else {
39
+ url = '/payment/pagarme/'+that.parent.contributionId+'/pay_credit_card';
40
+ }
41
+
42
+ return url;
43
+ },
44
+
45
+ getAjaxType: function() {
46
+ var type = 'POST';
47
+
48
+ if(this.hasSelectedSomeCard()) {
49
+ type = 'PUT'
50
+ }
51
+ return type;
52
+ },
53
+
54
+ selectedCard: function() {
55
+ return this.$('.my_credit_cards input:radio[name=payment_subscription_card]:checked');
56
+ },
57
+
58
+ hasSelectedSomeCard: function() {
59
+ return this.selectedCard().length > 0;
60
+ },
61
+
62
+ getPaymentData: function() {
63
+ var data = {};
64
+
65
+ if(this.hasSelectedSomeCard()) {
66
+ data = {
67
+ subscription_id: this.selectedCard().val(),
68
+ payment_card_installments: this.getInstallments() }
69
+ } else {
70
+ data = {
71
+ payment_card_number: this.$('input#payment_card_number').val(),
72
+ payment_card_name: this.$('input#payment_card_name').val(),
73
+ payment_card_date: this.$('input#payment_card_date').val(),
74
+ payment_card_source: this.$('input#payment_card_source').val(),
75
+ payment_card_installments: this.getInstallments()
76
+ }
77
+ }
78
+
79
+ return data;
80
+ },
81
+
82
+ getInstallments: function() {
83
+ if(this.hasSelectedSomeCard()) {
84
+ return this.$('.my_credit_cards select#payment_card_installments').val();
85
+ } else {
86
+ return this.$('.type_card_data select#payment_card_installments').val();
87
+ }
88
+ },
89
+
90
+ onSubmit: function(e) {
91
+ var that = this;
92
+
93
+ e.preventDefault();
94
+ $(e.currentTarget).hide();
95
+ that.parent.loader.show();
96
+
97
+ $.ajax({
98
+ type: that.getAjaxType(),
99
+ url: that.getUrl(),
100
+ data: that.getPaymentData(),
101
+ success: function(response){
102
+ that.parent.loader.hide();
103
+
104
+ if(response.payment_status == 'failed'){
105
+ that.message.find('p').html(response.message);
106
+ that.message.fadeIn('fast')
107
+
108
+ $(e.currentTarget).show();
109
+ } else {
110
+ var thank_you = $('#project_review').data('thank-you-path');
111
+
112
+ if(thank_you){
113
+ location.href = thank_you;
114
+ } else {
115
+ location.href = '/';
116
+ }
117
+ }
118
+ }
119
+ });
120
+ },
121
+
122
+ onKeyupPaymentCardNumber: function(e){
123
+ this.$('input#payment_card_flag').val(this.getCardFlag($(e.currentTarget).val()))
124
+ },
125
+
126
+ getCardFlag: function(number) {
127
+ var cc = (number + '').replace(/\s/g, ''); //remove space
128
+
129
+ if ((/^(34|37)/).test(cc) && cc.length == 15) {
130
+ return 'AmericanExpress'; //AMEX begins with 34 or 37, and length is 15.
131
+ } else if ((/^(51|52|53|54|55)/).test(cc) && cc.length == 16) {
132
+ return 'Mastercard'; //MasterCard beigins with 51-55, and length is 16.
133
+ } else if ((/^(4)/).test(cc) && (cc.length == 13 || cc.length == 16)) {
134
+ return 'Visa'; //VISA begins with 4, and length is 13 or 16.
135
+ } else if ((/^(300|301|302|303|304|305|36|38)/).test(cc) && cc.length == 14) {
136
+ return 'Diners'; //Diners Club begins with 300-305 or 36 or 38, and length is 14.
137
+ } else if ((/^(38)/).test(cc) && cc.length == 19) {
138
+ return 'Hipercard';
139
+ }
140
+ return 'Desconhecido';
141
+ }
142
+ });
@@ -0,0 +1,22 @@
1
+ App.views.PagarmeForm.addChild('PaymentChoice', {
2
+ el: '.list_payment',
3
+
4
+ events: {
5
+ 'change input[type="radio"]' : 'onListPaymentChange'
6
+ },
7
+
8
+ onListPaymentChange: function(e){
9
+ var that = this.parent;
10
+
11
+ $('.payment_section').fadeOut('fast', function(){
12
+ var currentElementId = $(e.currentTarget).attr('id');
13
+ that.$('#'+currentElementId+'_section').fadeIn('fast');
14
+ });
15
+ },
16
+
17
+ activate: function(){
18
+ var that = this.parent;
19
+
20
+ that.$('input#payment_type_credit_card').click();
21
+ }
22
+ });
@@ -0,0 +1,63 @@
1
+ App.views.PagarmeForm.addChild('PaymentSlip', {
2
+ el: '#payment_type_slip_section',
3
+
4
+ events: {
5
+ 'click input#build_boleto' : 'onBuildBoletoClick',
6
+ 'click .link_content a' : 'onContentClick',
7
+ },
8
+
9
+ activate: function(options){
10
+ this.PagarmeForm = this.parent;
11
+ this.message = this.$('.alert-danger');
12
+ this.$('#user_bank_account_attributes_name').brbanks();
13
+ },
14
+
15
+ onContentClick: function() {
16
+ var thank_you = $('#project_review').data('thank-you-path');
17
+
18
+ if(thank_you){
19
+ location.href = thank_you;
20
+ } else {
21
+ location.href = '/';
22
+ }
23
+ },
24
+
25
+ onBuildBoletoClick: function(e){
26
+ var that = this;
27
+ var parent = this.parent;
28
+
29
+ e.preventDefault();
30
+ $(e.currentTarget).hide();
31
+ that.PagarmeForm.loader.show();
32
+
33
+ var bankAccountAttributes = {
34
+ user: {
35
+ bank_account_attributes: {
36
+ name: that.$('input#user_bank_account_attributes_name').val(),
37
+ agency: that.$('input#user_bank_account_attributes_agency').val(),
38
+ agency_digit: that.$('input#user_bank_account_attributes_agency_digit').val(),
39
+ account: that.$('input#user_bank_account_attributes_account').val(),
40
+ account_digit: that.$('input#user_bank_account_attributes_account_digit').val(),
41
+ owner_name: that.$('input#user_bank_account_attributes_owner_name').val(),
42
+ owner_document: that.$('input#user_bank_account_attributes_owner_document').val()
43
+ }
44
+ }
45
+ };
46
+
47
+ $.post('/payment/pagarme/'+that.PagarmeForm.contributionId+'/pay_slip', bankAccountAttributes).success(function(response){
48
+ parent.loader.hide();
49
+ if(response.payment_status == 'failed'){
50
+ that.message.find('p').html(response.message);
51
+ that.message.fadeIn('fast')
52
+
53
+ $(e.currentTarget).show();
54
+ } else if(response.boleto_url) {
55
+ var link = $('<a target="__blank">'+response.boleto_url+'</a>')
56
+ link.attr('href', response.boleto_url);
57
+ that.$('.link_content').empty().html(link);
58
+ that.$('.payment_section:visible .subtitle').fadeIn('fast');
59
+ }
60
+ });
61
+ }
62
+
63
+ });