catarse_stripe 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +122 -0
- data/Gemfile.lock +98 -0
- data/MIT-LICENSE +20 -0
- data/README.md +67 -0
- data/Rakefile +36 -0
- data/app/assets/images/catarse_stripe/.gitkeep +0 -0
- data/app/assets/javascripts/.DS_Store +0 -0
- data/app/assets/javascripts/catarse_stripe/.DS_Store +0 -0
- data/app/assets/javascripts/catarse_stripe/stripe_form.js +17 -0
- data/app/assets/javascripts/catarse_stripe/user_document.js +95 -0
- data/app/assets/javascripts/catarse_stripe.js +6 -0
- data/app/controllers/catarse_stripe/payment/stripe_controller.rb +149 -0
- data/app/views/catarse_stripe/payment/stripe/review.html.slim +14 -0
- data/catarse_stripe.gemspec +25 -0
- data/config/initializers/active_merchant.rb +2 -0
- data/config/initializers/register.rb +1 -0
- data/config/locales/en.yml +14 -0
- data/config/routes.rb +10 -0
- data/lib/catarse_stripe/engine.rb +5 -0
- data/lib/catarse_stripe/processors/stripe.rb +27 -0
- data/lib/catarse_stripe/processors.rb +5 -0
- data/lib/catarse_stripe/version.rb +3 -0
- data/lib/catarse_stripe.rb +4 -0
- data/lib/tasks/catarse_stripe_tasks.rake +4 -0
- data/script/rails +8 -0
- data/spec/controllers/catarse_paypal_express/payment/paypal_express_controller_spec.rb +224 -0
- data/spec/fixtures/ipn_data.txt +1 -0
- data/spec/lib/processors/paypal_spec.rb +28 -0
- data/spec/spec_helper.rb +81 -0
- data/test/.DS_Store +0 -0
- metadata +161 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in catarse_paypal_express.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
source :gemcutter
|
8
|
+
source 'http://gems.github.com'
|
9
|
+
|
10
|
+
gem 'rails', '3.2.11'
|
11
|
+
|
12
|
+
gem 'sidekiq', '= 2.4.0'
|
13
|
+
gem 'sinatra', require: false
|
14
|
+
gem 'foreman'
|
15
|
+
gem 'best_in_place'
|
16
|
+
|
17
|
+
gem 'state_machine', require: 'state_machine/core'
|
18
|
+
|
19
|
+
# Database and data related
|
20
|
+
gem 'pg'
|
21
|
+
gem 'pg_search'
|
22
|
+
gem 'postgres-copy'
|
23
|
+
gem 'schema_plus'
|
24
|
+
|
25
|
+
gem 'catarse_paypal_express', git: 'git://github.com/devton/catarse_paypal_express.git'
|
26
|
+
#gem 'catarse_paypal_express', path: '../catarse_paypal_express'
|
27
|
+
gem 'catarse_moip', git: 'git://github.com/devton/catarse_moip.git'
|
28
|
+
#gem 'catarse_moip', path: '../catarse_moip'
|
29
|
+
gem 'moip', git: 'git://github.com/moiplabs/moip-ruby.git'
|
30
|
+
|
31
|
+
gem 'draper'
|
32
|
+
|
33
|
+
# Frontend stuff
|
34
|
+
gem 'slim'
|
35
|
+
gem 'slim-rails'
|
36
|
+
gem 'initjs'
|
37
|
+
|
38
|
+
# Authentication and Authorization
|
39
|
+
gem 'omniauth', "~> 1.1.0"
|
40
|
+
gem 'omniauth-openid', '~> 1.0.1'
|
41
|
+
gem 'omniauth-twitter', '~> 0.0.12'
|
42
|
+
gem 'omniauth-facebook', '~> 1.2.0'
|
43
|
+
gem 'omniauth-github', '~> 1.0.1'
|
44
|
+
gem 'omniauth-linkedin', '~> 0.0.6'
|
45
|
+
gem 'omniauth-yahoo', '~> 0.0.4'
|
46
|
+
gem 'devise', '1.5.3'
|
47
|
+
gem 'cancan', git: 'git://github.com/ryanb/cancan.git', branch: '2.0', ref: 'f1cebde51a87be149b4970a3287826bb63c0ac0b'
|
48
|
+
|
49
|
+
|
50
|
+
# Error reporting
|
51
|
+
gem "airbrake"
|
52
|
+
|
53
|
+
# Email marketing
|
54
|
+
#gem 'mailchimp'
|
55
|
+
gem 'catarse_mailchimp', git: 'git://github.com/devton/catarse_mailchimp'
|
56
|
+
|
57
|
+
# HTML manipulation and formatting
|
58
|
+
gem 'formtastic', "~> 2.1.1"
|
59
|
+
gem "auto_html", '= 1.4.2'
|
60
|
+
gem 'kaminari'
|
61
|
+
gem 'rails_autolink', '~> 1.0.7'
|
62
|
+
|
63
|
+
# Uploads
|
64
|
+
gem 'carrierwave', '~> 0.7.0'
|
65
|
+
gem 'rmagick'
|
66
|
+
gem 'fog'
|
67
|
+
|
68
|
+
# Other Tools
|
69
|
+
gem 'feedzirra'
|
70
|
+
gem 'validation_reflection', git: 'git://github.com/ncri/validation_reflection.git'
|
71
|
+
gem 'inherited_resources', '1.3.1'
|
72
|
+
gem 'has_scope'
|
73
|
+
gem 'spectator-validates_email', require: 'validates_email'
|
74
|
+
gem 'has_vimeo_video', '~> 0.0.5'
|
75
|
+
gem 'memoist', '~> 0.2.0'
|
76
|
+
gem 'wirble'
|
77
|
+
gem "on_the_spot"
|
78
|
+
gem 'weekdays'
|
79
|
+
gem 'brcep'
|
80
|
+
gem "RedCloth"
|
81
|
+
gem 'unicode'
|
82
|
+
gem 'enumerate_it'
|
83
|
+
gem 'httparty', '~> 0.6.1'
|
84
|
+
gem "rack-timeout"
|
85
|
+
|
86
|
+
# Translations
|
87
|
+
gem 'http_accept_language'
|
88
|
+
gem 'routing-filter' #, :git => 'git://github.com/svenfuchs/routing-filter.git'
|
89
|
+
|
90
|
+
# Administration
|
91
|
+
gem "meta_search", "1.1.3"
|
92
|
+
|
93
|
+
# Payment
|
94
|
+
gem 'activemerchant', '1.29.3', require: 'active_merchant'
|
95
|
+
gem 'httpclient', '2.2.5'
|
96
|
+
gem 'selenium-webdriver'
|
97
|
+
|
98
|
+
# Server
|
99
|
+
gem 'thin'
|
100
|
+
|
101
|
+
group :assets do
|
102
|
+
gem 'sass-rails', '~> 3.2.5'
|
103
|
+
gem 'coffee-rails', '~> 3.2.2'
|
104
|
+
gem "compass-rails", "~> 1.0.2"
|
105
|
+
gem 'uglifier', '>= 1.0.3'
|
106
|
+
gem 'compass-960-plugin', '~> 0.10.4'
|
107
|
+
end
|
108
|
+
|
109
|
+
group :test, :development do
|
110
|
+
gem 'launchy'
|
111
|
+
gem 'database_cleaner'
|
112
|
+
gem 'rspec-rails', "~> 2.10.0"
|
113
|
+
gem 'mocha', '0.10.4'
|
114
|
+
gem 'shoulda'
|
115
|
+
gem 'factory_girl_rails', '1.7.0'
|
116
|
+
gem 'capybara', ">= 1.0.1"
|
117
|
+
end
|
118
|
+
|
119
|
+
group :development do
|
120
|
+
gem 'mailcatcher'
|
121
|
+
end
|
122
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
catarse_stripe (0.0.1)
|
5
|
+
rails (~> 3.2.11)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (3.2.11)
|
11
|
+
actionpack (= 3.2.11)
|
12
|
+
mail (~> 2.4.4)
|
13
|
+
actionpack (3.2.11)
|
14
|
+
activemodel (= 3.2.11)
|
15
|
+
activesupport (= 3.2.11)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.0)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.2.1)
|
23
|
+
activemodel (3.2.11)
|
24
|
+
activesupport (= 3.2.11)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.11)
|
27
|
+
activemodel (= 3.2.11)
|
28
|
+
activesupport (= 3.2.11)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.11)
|
32
|
+
activemodel (= 3.2.11)
|
33
|
+
activesupport (= 3.2.11)
|
34
|
+
activesupport (3.2.11)
|
35
|
+
i18n (~> 0.6)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (3.0.2)
|
38
|
+
builder (3.0.4)
|
39
|
+
erubis (2.7.0)
|
40
|
+
hike (1.2.1)
|
41
|
+
i18n (0.6.1)
|
42
|
+
journey (1.0.4)
|
43
|
+
jquery-rails (2.2.1)
|
44
|
+
railties (>= 3.0, < 5.0)
|
45
|
+
thor (>= 0.14, < 2.0)
|
46
|
+
json (1.7.6)
|
47
|
+
mail (2.4.4)
|
48
|
+
i18n (>= 0.4.0)
|
49
|
+
mime-types (~> 1.16)
|
50
|
+
treetop (~> 1.4.8)
|
51
|
+
mime-types (1.21)
|
52
|
+
multi_json (1.5.0)
|
53
|
+
polyglot (0.3.3)
|
54
|
+
rack (1.4.5)
|
55
|
+
rack-cache (1.2)
|
56
|
+
rack (>= 0.4)
|
57
|
+
rack-ssl (1.3.3)
|
58
|
+
rack
|
59
|
+
rack-test (0.6.2)
|
60
|
+
rack (>= 1.0)
|
61
|
+
rails (3.2.11)
|
62
|
+
actionmailer (= 3.2.11)
|
63
|
+
actionpack (= 3.2.11)
|
64
|
+
activerecord (= 3.2.11)
|
65
|
+
activeresource (= 3.2.11)
|
66
|
+
activesupport (= 3.2.11)
|
67
|
+
bundler (~> 1.0)
|
68
|
+
railties (= 3.2.11)
|
69
|
+
railties (3.2.11)
|
70
|
+
actionpack (= 3.2.11)
|
71
|
+
activesupport (= 3.2.11)
|
72
|
+
rack-ssl (~> 1.3.2)
|
73
|
+
rake (>= 0.8.7)
|
74
|
+
rdoc (~> 3.4)
|
75
|
+
thor (>= 0.14.6, < 2.0)
|
76
|
+
rake (10.0.3)
|
77
|
+
rdoc (3.12.1)
|
78
|
+
json (~> 1.4)
|
79
|
+
sprockets (2.2.2)
|
80
|
+
hike (~> 1.2)
|
81
|
+
multi_json (~> 1.0)
|
82
|
+
rack (~> 1.0)
|
83
|
+
tilt (~> 1.1, != 1.3.0)
|
84
|
+
sqlite3 (1.3.7)
|
85
|
+
thor (0.17.0)
|
86
|
+
tilt (1.3.3)
|
87
|
+
treetop (1.4.12)
|
88
|
+
polyglot
|
89
|
+
polyglot (>= 0.3.1)
|
90
|
+
tzinfo (0.3.35)
|
91
|
+
|
92
|
+
PLATFORMS
|
93
|
+
ruby
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
catarse_stripe!
|
97
|
+
jquery-rails
|
98
|
+
sqlite3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Lvxn0va
|
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,67 @@
|
|
1
|
+
## The stripe_controller is a work in progress and things will be changing very rapidly. BEWARE!
|
2
|
+
|
3
|
+
# CatarseStripe
|
4
|
+
|
5
|
+
Catarse Stripe integration with [Catarse](http://github.com/danielweinmann/catarse) crowdfunding platform
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this lines to your Catarse application's Gemfile:
|
10
|
+
|
11
|
+
gem 'catarse_stripe'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Configure the routes for your Catarse application. Add the following lines in the routes file (config/routes.rb):
|
20
|
+
|
21
|
+
mount CatarseStripe::Engine => "/", :as => "catarse_stripe"
|
22
|
+
|
23
|
+
### Configurations
|
24
|
+
|
25
|
+
Create this configurations into Catarse database:
|
26
|
+
|
27
|
+
stripe_api_key, stripe_secret_key and stripe_test (boolean)
|
28
|
+
|
29
|
+
In Rails console, run this:
|
30
|
+
|
31
|
+
Configuration.create!(name: "stripe_api_key", value: "API_KEY")
|
32
|
+
Configuration.create!(name: "stripe_secret_key", value: "SECRET_KEY")
|
33
|
+
Configuration.create!(name: "stripe_test", value: "TRUE/FALSE")
|
34
|
+
|
35
|
+
NOTE: Be sure to add the correct keys from the API section of your Stripe account settings. Stripe_Test: TRUE = Using Stripe Test Server/Sandbox Mode / FALSE = Using Stripe live server.
|
36
|
+
|
37
|
+
## Development environment setup
|
38
|
+
|
39
|
+
Clone the repository:
|
40
|
+
|
41
|
+
$ git clone git://github.com/lvxn0va/catarse_stripe.git
|
42
|
+
|
43
|
+
Add the catarse code into test/dummy:
|
44
|
+
|
45
|
+
$ git submodule init
|
46
|
+
$ git submodule update
|
47
|
+
|
48
|
+
And then execute:
|
49
|
+
|
50
|
+
$ bundle
|
51
|
+
|
52
|
+
## Troubleshooting in development environment
|
53
|
+
|
54
|
+
Remove the admin folder from test/dummy application to prevent a weird active admin bug:
|
55
|
+
|
56
|
+
$ rm -rf test/dummy/app/admin
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create new Pull Request
|
65
|
+
|
66
|
+
|
67
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'CatarseStripe'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
Bundler::GemHelper.install_tasks
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
|
28
|
+
Rake::TestTask.new(:test) do |t|
|
29
|
+
t.libs << 'lib'
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task :default => :test
|
File without changes
|
Binary file
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
CATARSE.StripeForm = CATARSE.UserDocument.extend({
|
2
|
+
el: '#catarse_stripe_form',
|
3
|
+
|
4
|
+
events: {
|
5
|
+
'click input[type=submit]': 'onSubmitToStripe',
|
6
|
+
'keyup #user_document' : 'onUserDocumentKeyup'
|
7
|
+
},
|
8
|
+
|
9
|
+
initialize: function() {
|
10
|
+
this.loader = $('.loader');
|
11
|
+
},
|
12
|
+
|
13
|
+
onSubmitToStripe: function(e) {
|
14
|
+
$(e.currentTarget).hide();
|
15
|
+
this.loader.show();
|
16
|
+
}
|
17
|
+
});
|
@@ -0,0 +1,95 @@
|
|
1
|
+
CATARSE.UserDocument = Backbone.View.extend({
|
2
|
+
onUserDocumentKeyup: function(e){
|
3
|
+
var backerId = $('input#backer_id').val();
|
4
|
+
var projectId = $('input#project_id').val();
|
5
|
+
|
6
|
+
var $documentField = $(e.currentTarget);
|
7
|
+
|
8
|
+
var documentNumber = $documentField.val();
|
9
|
+
var resultCpf = this.validateCpf(documentNumber);
|
10
|
+
var resultCnpj = this.validateCnpj(documentNumber);
|
11
|
+
if(documentNumber.replace(/[.\-\_ ]/g, '').length > 10) {
|
12
|
+
if(resultCpf || resultCnpj) {
|
13
|
+
$documentField.addClass('ok').removeClass('error');
|
14
|
+
//$documentField.attr('disabled', true);
|
15
|
+
|
16
|
+
$.post('/projects/' + projectId + '/backers/' + backerId + '/update_info', {
|
17
|
+
backer: { payer_document: documentNumber }
|
18
|
+
});
|
19
|
+
|
20
|
+
} else {
|
21
|
+
$documentField.addClass('error').removeClass('ok');
|
22
|
+
}
|
23
|
+
}
|
24
|
+
},
|
25
|
+
|
26
|
+
validateCpf: function(cpfString){
|
27
|
+
var product = 0, i, digit;
|
28
|
+
cpfString = cpfString.replace(/[.\-\_ ]/g, '');
|
29
|
+
var aux = Math.floor(parseFloat(cpfString) / 100);
|
30
|
+
var cpf = aux * 100;
|
31
|
+
var quotient;
|
32
|
+
|
33
|
+
for(i=0; i<=8; i++){
|
34
|
+
product += (aux % 10) * (i+2);
|
35
|
+
aux = Math.floor(aux / 10);
|
36
|
+
}
|
37
|
+
digit = product % 11 < 2 ? 0 : 11 - (product % 11);
|
38
|
+
cpf += (digit * 10);
|
39
|
+
product = 0;
|
40
|
+
aux = Math.floor(cpf / 10);
|
41
|
+
for(i=0; i<=9; i++){
|
42
|
+
product += (aux % 10) * (i+2);
|
43
|
+
aux = Math.floor(aux / 10);
|
44
|
+
}
|
45
|
+
digit = product % 11 < 2 ? 0 : 11 - (product % 11);
|
46
|
+
cpf += digit;
|
47
|
+
return parseFloat(cpfString) === cpf;
|
48
|
+
},
|
49
|
+
|
50
|
+
validateCnpj: function(cnpj) {
|
51
|
+
var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
|
52
|
+
digitos_iguais = 1;
|
53
|
+
if (cnpj.length < 14 && cnpj.length < 15)
|
54
|
+
return false;
|
55
|
+
for (i = 0; i < cnpj.length - 1; i++)
|
56
|
+
if (cnpj.charAt(i) != cnpj.charAt(i + 1))
|
57
|
+
{
|
58
|
+
digitos_iguais = 0;
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
if (!digitos_iguais)
|
62
|
+
{
|
63
|
+
tamanho = cnpj.length - 2
|
64
|
+
numeros = cnpj.substring(0,tamanho);
|
65
|
+
digitos = cnpj.substring(tamanho);
|
66
|
+
soma = 0;
|
67
|
+
pos = tamanho - 7;
|
68
|
+
for (i = tamanho; i >= 1; i--)
|
69
|
+
{
|
70
|
+
soma += numeros.charAt(tamanho - i) * pos--;
|
71
|
+
if (pos < 2)
|
72
|
+
pos = 9;
|
73
|
+
}
|
74
|
+
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
75
|
+
if (resultado != digitos.charAt(0))
|
76
|
+
return false;
|
77
|
+
tamanho = tamanho + 1;
|
78
|
+
numeros = cnpj.substring(0,tamanho);
|
79
|
+
soma = 0;
|
80
|
+
pos = tamanho - 7;
|
81
|
+
for (i = tamanho; i >= 1; i--)
|
82
|
+
{
|
83
|
+
soma += numeros.charAt(tamanho - i) * pos--;
|
84
|
+
if (pos < 2)
|
85
|
+
pos = 9;
|
86
|
+
}
|
87
|
+
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
88
|
+
if (resultado != digitos.charAt(1))
|
89
|
+
return false;
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
else
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
});
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'catarse_stripe/processors'
|
2
|
+
|
3
|
+
module CatarseStripe::Payment
|
4
|
+
class StripeController < ApplicationController
|
5
|
+
|
6
|
+
skip_before_filter :verify_authenticity_token, :only => [:notifications]
|
7
|
+
skip_before_filter :detect_locale, :only => [:notifications]
|
8
|
+
skip_before_filter :set_locale, :only => [:notifications]
|
9
|
+
skip_before_filter :force_http
|
10
|
+
|
11
|
+
before_filter :setup_gateway
|
12
|
+
|
13
|
+
SCOPE = "projects.backers.checkout"
|
14
|
+
|
15
|
+
layout :false
|
16
|
+
|
17
|
+
def review
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def ipn
|
22
|
+
backer = Backer.where(:payment_id => params['txn_id']).first
|
23
|
+
if backer
|
24
|
+
notification = backer.payment_notifications.new({
|
25
|
+
extra_data: JSON.parse(params.to_json.force_encoding(params['charset']).encode('utf-8'))
|
26
|
+
})
|
27
|
+
notification.save!
|
28
|
+
backer.update_attributes({
|
29
|
+
:payment_service_fee => params['mc_fee'],
|
30
|
+
:payer_email => params['payer_email']
|
31
|
+
})
|
32
|
+
end
|
33
|
+
return render status: 200, nothing: true
|
34
|
+
rescue Exception => e
|
35
|
+
::Airbrake.notify({ :error_class => "Stripe Notification Error", :error_message => "Stripe Notification Error: #{e.inspect}", :parameters => params}) rescue nil
|
36
|
+
return render status: 200, nothing: true
|
37
|
+
end
|
38
|
+
|
39
|
+
def notifications
|
40
|
+
backer = Backer.find params[:id]
|
41
|
+
response = @@gateway.details_for(backer.payment_token)
|
42
|
+
if response.params['transaction_id'] == params['txn_id']
|
43
|
+
build_notification(backer, response.params)
|
44
|
+
render status: 200, nothing: true
|
45
|
+
else
|
46
|
+
render status: 404, nothing: true
|
47
|
+
end
|
48
|
+
rescue Exception => e
|
49
|
+
::Airbrake.notify({ :error_class => "Stripe Notification Error", :error_message => "Stripe Notification Error: #{e.inspect}", :parameters => params}) rescue nil
|
50
|
+
render status: 404, nothing: true
|
51
|
+
end
|
52
|
+
|
53
|
+
def pay
|
54
|
+
backer = current_user.backs.find params[:id]
|
55
|
+
begin
|
56
|
+
|
57
|
+
customer = Stripe::Customer.create(
|
58
|
+
:email => backer.email
|
59
|
+
:card => params[:stripeToken]
|
60
|
+
)
|
61
|
+
|
62
|
+
response = @@gateway.purchase(
|
63
|
+
:customer => customer.id
|
64
|
+
:amount => backer.price_in_cents,
|
65
|
+
:currency => 'usd',
|
66
|
+
:description => t('stripe_description', scope: SCOPE, :project_name => backer.project.name, :value => backer.display_value)
|
67
|
+
|
68
|
+
{
|
69
|
+
ip: request.remote_ip,
|
70
|
+
return_url: payment_success_stripe_url(id: backer.id),
|
71
|
+
cancel_return_url: payment_cancel_stripe_url(id: backer.id),
|
72
|
+
notify_url: payment_notifications_stripe_url(id: backer.id)
|
73
|
+
}
|
74
|
+
)
|
75
|
+
|
76
|
+
backer.update_attribute :payment_method, 'Stripe'
|
77
|
+
backer.update_attribute :payment_token, response.id
|
78
|
+
|
79
|
+
build_notification(backer, response.params)
|
80
|
+
|
81
|
+
redirect_to payment_success_stripe_url(id: backer.id)
|
82
|
+
rescue Exception => e
|
83
|
+
::Airbrake.notify({ :error_class => "Paypal Error", :error_message => "Paypal Error: #{e.inspect}", :parameters => params}) rescue nil
|
84
|
+
Rails.logger.info "-----> #{e.inspect}"
|
85
|
+
stripe_flash_error
|
86
|
+
return redirect_to main_app.new_project_backer_path(backer.project)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def success
|
91
|
+
backer = current_user.backs.find params[:id]
|
92
|
+
begin
|
93
|
+
@@gateway.purchase(backer.price_in_cents, {
|
94
|
+
ip: request.remote_ip,
|
95
|
+
token: backer.payment_token,
|
96
|
+
payer_id: params[:PayerID]
|
97
|
+
})
|
98
|
+
|
99
|
+
# we must get the deatils after the purchase in order to get the transaction_id
|
100
|
+
details = @@gateway.details_for(backer.payment_token)
|
101
|
+
|
102
|
+
build_notification(backer, details.params)
|
103
|
+
|
104
|
+
if details.params['transaction_id']
|
105
|
+
backer.update_attribute :payment_id, details.params['transaction_id']
|
106
|
+
end
|
107
|
+
paypal_flash_success
|
108
|
+
redirect_to main_app.thank_you_project_backer_path(project_id: backer.project.id, id: backer.id)
|
109
|
+
rescue Exception => e
|
110
|
+
::Airbrake.notify({ :error_class => "Stripe Error", :error_message => "Stripe Error: #{e.message}", :parameters => params}) rescue nil
|
111
|
+
Rails.logger.info "-----> #{e.inspect}"
|
112
|
+
paypal_flash_error
|
113
|
+
return redirect_to main_app.new_project_backer_path(backer.project)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def cancel
|
118
|
+
backer = current_user.backs.find params[:id]
|
119
|
+
flash[:failure] = t('stripe_cancel', scope: SCOPE)
|
120
|
+
redirect_to main_app.new_project_backer_path(backer.project)
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def build_notification(backer, data)
|
126
|
+
processor = CatarseStripe::Processors::Stripe.new
|
127
|
+
processor.process!(backer, data)
|
128
|
+
end
|
129
|
+
|
130
|
+
def stripe_flash_error
|
131
|
+
flash[:failure] = t('stripe_error', scope: SCOPE)
|
132
|
+
end
|
133
|
+
|
134
|
+
def stripe_flash_success
|
135
|
+
flash[:success] = t('success', scope: SCOPE)
|
136
|
+
end
|
137
|
+
|
138
|
+
def setup_gateway
|
139
|
+
if ::Configuration[:stripe_api_key]# and ::Configuration[:stripe_secret_key]
|
140
|
+
@@gateway ||= ActiveMerchant::Billing::StripeGateway.new({
|
141
|
+
:login => ::Configuration[:stripe_api_key]
|
142
|
+
#:login => ::Configuration[:stripe_secret_key]
|
143
|
+
})
|
144
|
+
else
|
145
|
+
puts "[Stripe] API key is required to make requests to Stripe"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
= javascript_include_tag 'catarse_stripe'
|
2
|
+
|
3
|
+
h3= t('projects.backers.review.international.section_title')
|
4
|
+
|
5
|
+
#catarse_stripe_form
|
6
|
+
= form_tag payment_pay_stripe_path(params[:id]) do
|
7
|
+
.clearfix
|
8
|
+
script.stripe-button data-amount="(backer.price_in_cents)" data-description="t('stripe_description', scope: SCOPE, :project_name => backer.project.name, :value => backer.display_value)" data-key=(::Configuration[:stripe_api_key])src="https://checkout.stripe.com/v2/checkout.js"
|
9
|
+
.bootstrap-twitter
|
10
|
+
= label_tag 'user_document', t('projects.backers.review.international.user_document_label')
|
11
|
+
.clearfix
|
12
|
+
= text_field_tag 'user_document', nil, { autocomplete: 'off' }
|
13
|
+
.loader.hide= image_tag 'loading.gif'
|
14
|
+
= submit_tag t('projects.backers.review.international.button'), :class => 'btn btn-primary btn-large'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "catarse_stripe/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "catarse_stripe"
|
9
|
+
s.version = CatarseStripe::VERSION
|
10
|
+
s.authors = ["Luxn0va"]
|
11
|
+
s.email = ["lvx.n0va@gmail.com"]
|
12
|
+
s.homepage = "http://github.com/lvxn0va/catarse_stripe"
|
13
|
+
s.summary = "Stripe Payments Integration with Catarse."
|
14
|
+
s.description = "Stripe Payments Integration with Catarse crowdfunding platform."
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($\)
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
s.add_dependency "rails", "~> 3.2.11"
|
20
|
+
s.add_dependency "activemerchant", ">= 1.17.0"
|
21
|
+
|
22
|
+
s.add_development_dependency "rspec-rails"
|
23
|
+
s.add_development_dependency "factory_girl_rails"
|
24
|
+
s.add_development_dependency "database_cleaner"
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
PaymentEngines.register({name: 'stripe', review_path: ->(backer){ CatarseStripe::Engine.routes.url_helpers.payment_review_stripe_path(backer) }, locale: 'en'})
|
@@ -0,0 +1,14 @@
|
|
1
|
+
en:
|
2
|
+
projects:
|
3
|
+
backers:
|
4
|
+
review:
|
5
|
+
stripe: 'Stripe'
|
6
|
+
international:
|
7
|
+
section_title: 'You will be directed to the Stripe site to complete payment.'
|
8
|
+
user_document_label: 'CPF / CNPJ (only for Brazilians)'
|
9
|
+
button: 'Redirect to Payment By Stripe'
|
10
|
+
checkout:
|
11
|
+
stripe_cancel: "Your Stripe payment was canceled. Please try again."
|
12
|
+
stripe_description: "Back project %{project_name} with %{value} (USD)"
|
13
|
+
stripe_error: "Ooops. There was an error while sending your payment to Stripe. Please try again."
|
14
|
+
success: "Your back was successfully made. Thanks a lot!"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
CatarseStripe::Engine.routes.draw
|
2
|
+
namespace :payment do
|
3
|
+
get '/stripe/:id/review' => 'stripe#review', :as => 'review_stripe'
|
4
|
+
post '/stripe/notifications' => 'stripe#ipn', :as => 'ipn_stripe'
|
5
|
+
match '/stripe/:id/notifications' => 'stripe#notifications', :as => 'notifications_stripe'
|
6
|
+
match '/stripe/:id/pay' => 'stripe#pay', :as => 'pay_stripe'
|
7
|
+
match '/stripe/:id/success' => 'stripe#success', :as => 'success_stripe'
|
8
|
+
match '/stripe/:id/cancel' => 'stripe#cancel', :as => 'cancel_stripe'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CatarseStripe
|
2
|
+
module Processors
|
3
|
+
class Stripe
|
4
|
+
|
5
|
+
def process!(backer, data)
|
6
|
+
status = data["checkout_status"] || "pending"
|
7
|
+
|
8
|
+
notification = backer.payment_notifications.new({
|
9
|
+
extra_data: data
|
10
|
+
})
|
11
|
+
|
12
|
+
notification.save!
|
13
|
+
|
14
|
+
backer.confirm! if success_payment?(status)
|
15
|
+
rescue Exception => e
|
16
|
+
::Airbrake.notify({ :error_class => "Stripe Processor Error", :error_message => "Stripe Processor Error: #{e.inspect}", :parameters => data}) rescue nil
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def success_payment?(status)
|
22
|
+
status == 'PaymentActionCompleted'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/catarse_stripe/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe CatarsePaypalExpress::Payment::PaypalExpressController do
|
6
|
+
before do
|
7
|
+
Configuration.create!(name: "paypal_username", value: "usertest_api1.teste.com")
|
8
|
+
Configuration.create!(name: "paypal_password", value: "HVN4PQBGZMHKFVGW")
|
9
|
+
Configuration.create!(name: "paypal_signature", value: "AeL-u-Ox.N6Jennvu1G3BcdiTJxQAWdQcjdpLTB9ZaP0-Xuf-U0EQtnS")
|
10
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return({})
|
11
|
+
Airbrake.stub(:notify).and_return({})
|
12
|
+
end
|
13
|
+
|
14
|
+
subject{ response }
|
15
|
+
|
16
|
+
let(:current_user) { Factory(:user) }
|
17
|
+
|
18
|
+
describe "POST ipn" do
|
19
|
+
let(:ipn_data){ {"mc_gross"=>"50.00", "protection_eligibility"=>"Eligible", "address_status"=>"unconfirmed", "payer_id"=>"S7Q8X88KMGX5S", "tax"=>"0.00", "address_street"=>"Rua Tatui, 40 ap 81\r\nJardins", "payment_date"=>"09:03:01 Nov 05, 2012 PST", "payment_status"=>"Completed", "charset"=>"windows-1252", "address_zip"=>"01409-010", "first_name"=>"Paula", "mc_fee"=>"3.30", "address_country_code"=>"BR", "address_name"=>"Paula Rizzo", "notify_version"=>"3.7", "custom"=>"", "payer_status"=>"verified", "address_country"=>"Brazil", "address_city"=>"Sao Paulo", "quantity"=>"1", "verify_sign"=>"ALBe4QrXe2sJhpq1rIN8JxSbK4RZA.Kfc5JlI9Jk4N1VQVTH5hPYOi2S", "payer_email"=>"paula.rizzo@gmail.com", "txn_id"=>"3R811766V4891372K", "payment_type"=>"instant", "last_name"=>"Rizzo", "address_state"=>"SP", "receiver_email"=>"financeiro@catarse.me", "payment_fee"=>"", "receiver_id"=>"BVUB4EVC7YCWL", "txn_type"=>"express_checkout", "item_name"=>"Back project", "mc_currency"=>"BRL", "item_number"=>"", "residence_country"=>"BR", "handling_amount"=>"0.00", "transaction_subject"=>"Back project", "payment_gross"=>"", "shipping"=>"0.00", "ipn_track_id"=>"5865649c8c27"} }
|
20
|
+
let(:backer){ Factory(:backer, :payment_id => ipn_data['txn_id'] ) }
|
21
|
+
before do
|
22
|
+
backer
|
23
|
+
post :ipn, ipn_data.merge({ use_route: 'catarse_paypal_express' })
|
24
|
+
backer.reload
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should update backer's payment_service_fee" do
|
28
|
+
backer.payment_service_fee.to_f.should == ipn_data['mc_fee'].to_f
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should update backer's payer_email" do
|
32
|
+
backer.payer_email.should == ipn_data['payer_email']
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should create PaymentNotification for the backer" do
|
36
|
+
backer.payment_notifications.first.extra_data['txn_id'].should == ipn_data['txn_id']
|
37
|
+
end
|
38
|
+
|
39
|
+
its(:status){ should == 200 }
|
40
|
+
|
41
|
+
end
|
42
|
+
describe "POST notification" do
|
43
|
+
context 'when receive a notification' do
|
44
|
+
it 'and not found the backer, should return 404' do
|
45
|
+
post :notifications, { id: 1, use_route: 'catarse_paypal_express'}
|
46
|
+
response.status.should eq(404)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'and the transaction ID not match, should return 404' do
|
50
|
+
backer = Factory(:backer, payment_id: '1234')
|
51
|
+
post :notifications, { id: backer.id, txn_id: 123, use_route: 'catarse_paypal_express' }
|
52
|
+
response.status.should eq(404)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should create a payment_notification' do
|
56
|
+
success_payment_response = mock()
|
57
|
+
success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234', "checkout_status" => "PaymentActionCompleted" })
|
58
|
+
success_payment_response.stubs(:success?).returns(true)
|
59
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return(success_payment_response)
|
60
|
+
|
61
|
+
backer = Factory(:backer, payment_id: '1234')
|
62
|
+
backer.payment_notifications.should be_empty
|
63
|
+
|
64
|
+
post :notifications, { id: backer.id, txn_id: 1234 , use_route: 'catarse_paypal_express' }
|
65
|
+
backer.reload
|
66
|
+
|
67
|
+
backer.payment_notifications.should_not be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'and the transaction ID match, should update the payment status if successful' do
|
71
|
+
success_payment_response = mock()
|
72
|
+
success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234', "checkout_status" => "PaymentActionCompleted" })
|
73
|
+
success_payment_response.stubs(:success?).returns(true)
|
74
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return(success_payment_response)
|
75
|
+
backer = Factory(:backer, payment_id: '1234', confirmed: false)
|
76
|
+
|
77
|
+
post :notifications, { id: backer.id, txn_id: 1234, use_route: 'catarse_paypal_express' }
|
78
|
+
|
79
|
+
backer.reload
|
80
|
+
response.status.should eq(200)
|
81
|
+
backer.confirmed.should be_true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "GET pay" do
|
87
|
+
context 'setup purchase' do
|
88
|
+
context 'when have some failures' do
|
89
|
+
it 'user not logged in, should redirect' do
|
90
|
+
pending 'problems with external application routes'
|
91
|
+
#get :pay, {locale: 'en', use_route: 'catarse_paypal_express' }
|
92
|
+
#response.status.should eq(302)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'backer not belongs to current_user should 404' do
|
96
|
+
backer = Factory(:backer)
|
97
|
+
session[:user_id] = current_user.id
|
98
|
+
|
99
|
+
lambda {
|
100
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
|
101
|
+
}.should raise_exception ActiveRecord::RecordNotFound
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'raise a exepction because invalid data and should be redirect and set the flash message' do
|
105
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:setup_purchase).and_raise(StandardError)
|
106
|
+
session[:user_id] = current_user.id
|
107
|
+
backer = Factory(:backer, user: current_user)
|
108
|
+
|
109
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
|
110
|
+
flash[:failure].should == I18n.t('paypal_error', scope: CatarsePaypalExpress::Payment::PaypalExpressController::SCOPE)
|
111
|
+
response.should be_redirect
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'when successul' do
|
116
|
+
before do
|
117
|
+
success_response = mock()
|
118
|
+
success_response.stub(:token).and_return('ABCD')
|
119
|
+
success_response.stub(:params).and_return({ 'correlation_id' => '123' })
|
120
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:setup_purchase).and_return(success_response)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should create a payment_notification' do
|
124
|
+
session[:user_id] = current_user.id
|
125
|
+
backer = Factory(:backer, user: current_user)
|
126
|
+
|
127
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
|
128
|
+
backer.reload
|
129
|
+
|
130
|
+
backer.payment_notifications.should_not be_empty
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'payment method and token should be persisted ' do
|
134
|
+
session[:user_id] = current_user.id
|
135
|
+
backer = Factory(:backer, user: current_user)
|
136
|
+
|
137
|
+
get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
|
138
|
+
backer.reload
|
139
|
+
|
140
|
+
backer.payment_method.should == 'PayPal'
|
141
|
+
backer.payment_token.should == 'ABCD'
|
142
|
+
|
143
|
+
# The correlation id should not be stored in payment_id, which is only for transaction_id
|
144
|
+
backer.payment_id.should be_nil
|
145
|
+
|
146
|
+
response.should be_redirect
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "GET cancel" do
|
153
|
+
context 'when cancel the paypal purchase' do
|
154
|
+
it 'should show for user the flash message' do
|
155
|
+
session[:user_id] = current_user.id
|
156
|
+
backer = Factory(:backer, user: current_user, payment_token: 'TOKEN')
|
157
|
+
|
158
|
+
get :cancel, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
|
159
|
+
flash[:failure].should == I18n.t('paypal_cancel', scope: CatarsePaypalExpress::Payment::PaypalExpressController::SCOPE)
|
160
|
+
response.should be_redirect
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "GET success" do
|
166
|
+
let(:success_details){ {'transaction_id' => nil, "checkout_status" => "PaymentActionCompleted"} }
|
167
|
+
let(:fake_success_details) do
|
168
|
+
fake_success_details = mock()
|
169
|
+
fake_success_details.stub(:params).and_return(success_details)
|
170
|
+
fake_success_details
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'paypal returning to success route' do
|
174
|
+
|
175
|
+
context 'when paypal purchase is ok' do
|
176
|
+
before(:each) do
|
177
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for) do
|
178
|
+
# If we call the details_for before purchase the transaction_id will not be present
|
179
|
+
success_details.delete('transaction_id') unless success_details['transaction_id'] == '12345'
|
180
|
+
fake_success_details
|
181
|
+
end
|
182
|
+
fake_success_purchase = mock()
|
183
|
+
fake_success_purchase.stub(:success?).and_return(true)
|
184
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:purchase) do
|
185
|
+
# only after the purchase command the transactio_id is set in the details_for
|
186
|
+
success_details['transaction_id'] = '12345' if success_details.include?('transaction_id')
|
187
|
+
fake_success_purchase
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'should update the backer and redirect to thank_you' do
|
192
|
+
session[:user_id] = current_user.id
|
193
|
+
backer = Factory(:backer, user: current_user, payment_token: 'TOKEN')
|
194
|
+
backer.payment_notifications.should be_empty
|
195
|
+
|
196
|
+
get :success, { id: backer.id, PayerID: '123', locale: 'en', use_route: 'catarse_paypal_express' }
|
197
|
+
backer.reload
|
198
|
+
|
199
|
+
backer.payment_notifications.should_not be_empty
|
200
|
+
backer.confirmed.should be_true
|
201
|
+
backer.payment_id.should == '12345'
|
202
|
+
response.should redirect_to("/projects/#{backer.project.id}/backers/#{backer.id}/thank_you")
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when paypal purchase raise a error' do
|
207
|
+
before do
|
208
|
+
ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:purchase).and_raise(StandardError)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should be redirect and show a flash message' do
|
212
|
+
session[:user_id] = current_user.id
|
213
|
+
backer = Factory(:backer, user: current_user)
|
214
|
+
|
215
|
+
get :success, { id: backer.id, PayerID: '123', locale: 'en', use_route: 'catarse_paypal_express' }
|
216
|
+
|
217
|
+
flash[:failure].should == I18n.t('paypal_error', scope: CatarsePaypalExpress::Payment::PaypalExpressController::SCOPE)
|
218
|
+
response.should be_redirect
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
mc_gross=50.00&protection_eligibility=Eligible&address_status=unconfirmed&payer_id=ETKAQNKYZ22XS&tax=0.00&address_street=Avd. de Orovilla 44 , 2D&payment_date=12:07:09 Nov 14, 2012 PST&payment_status=Completed&charset=windows-1252&address_zip=28041&first_name=Miguel Angel&mc_fee=3.80&address_country_code=ES&address_name=Miguel Angel Arcaya Martinez¬ify_version=3.7&custom=&payer_status=verified&address_country=Spain&address_city=Madrid&quantity=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31ASi9V8udCT42l3i7sjZoqAu65cr5&payer_email=choquete@hotmail.com&txn_id=96822&payment_type=instant&last_name=Arcaya Martinez&address_state=Madrid&receiver_email=financeiro@catarse.me&payment_fee=&receiver_id=BVUB4EVC7YCWL&txn_type=express_checkout&item_name=Apoio para o projeto V Plen�ria Nacional de Economia Solid�ria no valor de R$ 50&mc_currency=BRL&item_number=&residence_country=ES&handling_amount=0.00&transaction_subject=Apoio para o projeto V Plen�ria Nacional de Economia Solid�ria no valor de R$ 50&payment_gross=&shipping=0.00&ipn_track_id=b3d9a2e5c34d6
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePaypalExpress::Processors::Paypal do
|
4
|
+
context "process paypal details_for response" do
|
5
|
+
let(:backer) { Factory(:backer, confirmed: false) }
|
6
|
+
|
7
|
+
it "should create a new payment_notifications for backer" do
|
8
|
+
backer.payment_notifications.should be_empty
|
9
|
+
subject.process!(backer, paypal_details_response)
|
10
|
+
backer.payment_notifications.should_not be_empty
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should fill extra_data with all response data" do
|
14
|
+
subject.process!(backer, paypal_details_response)
|
15
|
+
backer.payment_notifications.first.extra_data.should == paypal_details_response
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should confirm backer when checkout status is completed" do
|
19
|
+
subject.process!(backer, paypal_details_response)
|
20
|
+
backer.confirmed.should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not confirm when checkout status is not completed" do
|
24
|
+
subject.process!(backer, paypal_details_response.merge!({"checkout_status" => "just_another_status"}) )
|
25
|
+
backer.confirmed.should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../../test/dummy/config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
#require 'fakeweb'
|
7
|
+
|
8
|
+
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
9
|
+
|
10
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
11
|
+
# in spec/support/ and its subdirectories.
|
12
|
+
Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each {|f| require f }
|
13
|
+
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
# ## Mock Framework
|
17
|
+
#
|
18
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
19
|
+
#
|
20
|
+
# config.mock_with :mocha
|
21
|
+
# config.mock_with :flexmock
|
22
|
+
# config.mock_with :rr
|
23
|
+
|
24
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
25
|
+
config.fixture_path = "#{ENGINE_RAILS_ROOT}/spec/fixtures"
|
26
|
+
|
27
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
28
|
+
# examples within a transaction, remove the following line or assign false
|
29
|
+
# instead of true.
|
30
|
+
config.use_transactional_fixtures = true
|
31
|
+
|
32
|
+
# If true, the base class of anonymous controllers will be inferred
|
33
|
+
# automatically. This will be the default behavior in future versions of
|
34
|
+
# rspec-rails.
|
35
|
+
config.infer_base_class_for_anonymous_controllers = false
|
36
|
+
|
37
|
+
# Include Engine routes (needed for Controller specs)
|
38
|
+
config.include CatarsePaypalExpress::Engine.routes.url_helpers
|
39
|
+
|
40
|
+
# Include Catarse routes
|
41
|
+
config.include Catarse::Application.routes.url_helpers
|
42
|
+
|
43
|
+
config.include Devise::TestHelpers, :type => :controller
|
44
|
+
|
45
|
+
config.include Factory::Syntax::Methods
|
46
|
+
|
47
|
+
config.before(:each) do
|
48
|
+
CatarseMailchimp::API.stubs(:subscribe)
|
49
|
+
CatarseMailchimp::API.stubs(:unsubscribe)
|
50
|
+
end
|
51
|
+
|
52
|
+
config.before(:suite) do
|
53
|
+
DatabaseCleaner.strategy = :transaction
|
54
|
+
DatabaseCleaner.clean_with :truncation
|
55
|
+
end
|
56
|
+
|
57
|
+
config.before(:each) do
|
58
|
+
Project.any_instance.stub(:store_image_url).and_return('http://www.store_image_url.com')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
RoutingFilter.active = false # Because this issue: https://github.com/svenfuchs/routing-filter/issues/36
|
63
|
+
|
64
|
+
def fixture_file(filename)
|
65
|
+
return nil if filename.nil?
|
66
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
67
|
+
File.read(file_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
def paypal_setup_purchase_success_response
|
71
|
+
{ "timestamp"=>"2012-07-23T00:24:21Z", "ack"=>"Success", "correlation_id"=>"dcb8596be51cd", "version"=>"62.0", "build"=>"3332236",
|
72
|
+
"token"=>"EC-49X25168KR2556548", "Timestamp"=>"2012-07-23T00:24:21Z", "Ack"=>"Success", "CorrelationID"=>"dcb8596be51cd",
|
73
|
+
"Version"=>"62.0", "Build"=>"3332236", "Token"=>"EC-49X25168KR2556548" }
|
74
|
+
end
|
75
|
+
|
76
|
+
def paypal_details_response
|
77
|
+
{
|
78
|
+
"transaction_id" => "1234",
|
79
|
+
"checkout_status" => "PaymentActionCompleted"
|
80
|
+
}
|
81
|
+
end
|
data/test/.DS_Store
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: catarse_stripe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luxn0va
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.11
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.11
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activemerchant
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.17.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.17.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec-rails
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: factory_girl_rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: database_cleaner
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Stripe Payments Integration with Catarse crowdfunding platform.
|
95
|
+
email:
|
96
|
+
- lvx.n0va@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- app/assets/images/catarse_stripe/.gitkeep
|
108
|
+
- app/assets/javascripts/.DS_Store
|
109
|
+
- app/assets/javascripts/catarse_stripe.js
|
110
|
+
- app/assets/javascripts/catarse_stripe/.DS_Store
|
111
|
+
- app/assets/javascripts/catarse_stripe/stripe_form.js
|
112
|
+
- app/assets/javascripts/catarse_stripe/user_document.js
|
113
|
+
- app/controllers/catarse_stripe/payment/stripe_controller.rb
|
114
|
+
- app/views/catarse_stripe/payment/stripe/review.html.slim
|
115
|
+
- catarse_stripe.gemspec
|
116
|
+
- config/initializers/active_merchant.rb
|
117
|
+
- config/initializers/register.rb
|
118
|
+
- config/locales/en.yml
|
119
|
+
- config/routes.rb
|
120
|
+
- lib/catarse_stripe.rb
|
121
|
+
- lib/catarse_stripe/engine.rb
|
122
|
+
- lib/catarse_stripe/processors.rb
|
123
|
+
- lib/catarse_stripe/processors/stripe.rb
|
124
|
+
- lib/catarse_stripe/version.rb
|
125
|
+
- lib/tasks/catarse_stripe_tasks.rake
|
126
|
+
- script/rails
|
127
|
+
- spec/controllers/catarse_paypal_express/payment/paypal_express_controller_spec.rb
|
128
|
+
- spec/fixtures/ipn_data.txt
|
129
|
+
- spec/lib/processors/paypal_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- test/.DS_Store
|
132
|
+
homepage: http://github.com/lvxn0va/catarse_stripe
|
133
|
+
licenses: []
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.8.24
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: Stripe Payments Integration with Catarse.
|
156
|
+
test_files:
|
157
|
+
- spec/controllers/catarse_paypal_express/payment/paypal_express_controller_spec.rb
|
158
|
+
- spec/fixtures/ipn_data.txt
|
159
|
+
- spec/lib/processors/paypal_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
161
|
+
- test/.DS_Store
|