catarse_paypal_express 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ test/dummy/.sass-cache
8
+ test/dummy/
data/Gemfile ADDED
@@ -0,0 +1,17 @@
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
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
data/Gemfile.lock ADDED
@@ -0,0 +1,126 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ catarse_paypal_express (0.0.1)
5
+ activemerchant (~> 1.17.0)
6
+ rails (~> 3.2.6)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.6)
12
+ actionpack (= 3.2.6)
13
+ mail (~> 2.4.4)
14
+ actionpack (3.2.6)
15
+ activemodel (= 3.2.6)
16
+ activesupport (= 3.2.6)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.1)
20
+ rack (~> 1.4.0)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.1.3)
24
+ activemerchant (1.17.0)
25
+ activesupport (>= 2.3.11)
26
+ braintree (>= 2.0.0)
27
+ builder (>= 2.0.0)
28
+ json (>= 1.5.1)
29
+ activemodel (3.2.6)
30
+ activesupport (= 3.2.6)
31
+ builder (~> 3.0.0)
32
+ activerecord (3.2.6)
33
+ activemodel (= 3.2.6)
34
+ activesupport (= 3.2.6)
35
+ arel (~> 3.0.2)
36
+ tzinfo (~> 0.3.29)
37
+ activeresource (3.2.6)
38
+ activemodel (= 3.2.6)
39
+ activesupport (= 3.2.6)
40
+ activesupport (3.2.6)
41
+ i18n (~> 0.6)
42
+ multi_json (~> 1.0)
43
+ arel (3.0.2)
44
+ braintree (2.16.0)
45
+ builder (>= 2.0.0)
46
+ builder (3.0.0)
47
+ database_cleaner (0.8.0)
48
+ diff-lcs (1.1.3)
49
+ erubis (2.7.0)
50
+ factory_girl (3.5.0)
51
+ activesupport (>= 3.0.0)
52
+ factory_girl_rails (3.5.0)
53
+ factory_girl (~> 3.5.0)
54
+ railties (>= 3.0.0)
55
+ hike (1.2.1)
56
+ i18n (0.6.0)
57
+ journey (1.0.4)
58
+ jquery-rails (2.0.2)
59
+ railties (>= 3.2.0, < 5.0)
60
+ thor (~> 0.14)
61
+ json (1.7.3)
62
+ mail (2.4.4)
63
+ i18n (>= 0.4.0)
64
+ mime-types (~> 1.16)
65
+ treetop (~> 1.4.8)
66
+ mime-types (1.19)
67
+ multi_json (1.3.6)
68
+ polyglot (0.3.3)
69
+ rack (1.4.1)
70
+ rack-cache (1.2)
71
+ rack (>= 0.4)
72
+ rack-ssl (1.3.2)
73
+ rack
74
+ rack-test (0.6.1)
75
+ rack (>= 1.0)
76
+ rails (3.2.6)
77
+ actionmailer (= 3.2.6)
78
+ actionpack (= 3.2.6)
79
+ activerecord (= 3.2.6)
80
+ activeresource (= 3.2.6)
81
+ activesupport (= 3.2.6)
82
+ bundler (~> 1.0)
83
+ railties (= 3.2.6)
84
+ railties (3.2.6)
85
+ actionpack (= 3.2.6)
86
+ activesupport (= 3.2.6)
87
+ rack-ssl (~> 1.3.2)
88
+ rake (>= 0.8.7)
89
+ rdoc (~> 3.4)
90
+ thor (>= 0.14.6, < 2.0)
91
+ rake (0.9.2.2)
92
+ rdoc (3.12)
93
+ json (~> 1.4)
94
+ rspec (2.11.0)
95
+ rspec-core (~> 2.11.0)
96
+ rspec-expectations (~> 2.11.0)
97
+ rspec-mocks (~> 2.11.0)
98
+ rspec-core (2.11.1)
99
+ rspec-expectations (2.11.1)
100
+ diff-lcs (~> 1.1.3)
101
+ rspec-mocks (2.11.1)
102
+ rspec-rails (2.11.0)
103
+ actionpack (>= 3.0)
104
+ activesupport (>= 3.0)
105
+ railties (>= 3.0)
106
+ rspec (~> 2.11.0)
107
+ sprockets (2.1.3)
108
+ hike (~> 1.2)
109
+ rack (~> 1.0)
110
+ tilt (~> 1.1, != 1.3.0)
111
+ thor (0.15.4)
112
+ tilt (1.3.3)
113
+ treetop (1.4.10)
114
+ polyglot
115
+ polyglot (>= 0.3.1)
116
+ tzinfo (0.3.33)
117
+
118
+ PLATFORMS
119
+ ruby
120
+
121
+ DEPENDENCIES
122
+ catarse_paypal_express!
123
+ database_cleaner
124
+ factory_girl_rails
125
+ jquery-rails
126
+ rspec-rails
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Antônio Roberto Silva
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,66 @@
1
+ # CatarsePaypalExpress
2
+
3
+ Catarse paypal express integration with [Catarse](http://github.com/danielweinmann/catarse) crowdfunding platform
4
+
5
+ ## Installation
6
+
7
+ Add this lines to your Catarse application's Gemfile:
8
+
9
+ gem 'catarse_paypal_express'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ Configure the routes for your Catarse application. Add the following lines in the routes file (config/routes.rb):
18
+
19
+ mount CatarsePaypalExpress::Engine => "/", :as => "catarse_paypal_express"
20
+
21
+ ### Configurations
22
+
23
+ Create this configurations into Catarse database:
24
+
25
+ paypal_username, paypal_password and paypal_signature
26
+
27
+ In Rails console, run this:
28
+
29
+ Configuration.create!(name: "paypal_username", value: "USERNAME")
30
+ Configuration.create!(name: "paypal_password", value: "PASSWORD")
31
+ Configuration.create!(name: "paypal_signature", value: "SIGNATURE")
32
+
33
+ ## Development environment setup
34
+
35
+ Clone the repository:
36
+
37
+ $ git clone git://github.com/devton/catarse_paypal_express.git
38
+
39
+ Add the catarse code into test/dummy:
40
+
41
+ $ git submodule add git://github.com/danielweinmann/catarse.git test/dummy
42
+
43
+ Copy the Catarse's gems to Gemfile:
44
+
45
+ $ cat test/dummy/Gemfile >> Gemfile
46
+
47
+ And then execute:
48
+
49
+ $ bundle
50
+
51
+ ## Troubleshooting in development environment
52
+
53
+ Remove the admin folder from test/dummy application to prevent a weird active admin bug:
54
+
55
+ $ rm -rf test/dummy/app/admin
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
64
+
65
+
66
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
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 = 'CatarsePaypalExpress'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
File without changes
@@ -0,0 +1,111 @@
1
+ module CatarsePaypalExpress::Payment
2
+ class PaypalExpressController < ApplicationController
3
+ skip_before_filter :verify_authenticity_token, :only => [:notifications]
4
+ skip_before_filter :detect_locale, :only => [:notifications]
5
+ skip_before_filter :set_locale, :only => [:notifications]
6
+
7
+ before_filter :setup_gateway
8
+
9
+ SCOPE = "projects.backers.checkout"
10
+
11
+ def notifications
12
+ backer = Backer.find params[:id]
13
+ response = @@gateway.details_for(backer.payment_token)
14
+ if response.params['transaction_id'] == params['txn_id']
15
+ backer.confirm! if response.success?
16
+ render status: 200, nothing: true
17
+ else
18
+ render status: 404, nothing: true
19
+ end
20
+ rescue
21
+ render status: 404, nothing: true
22
+ end
23
+
24
+ def pay
25
+ backer = current_user.backs.find params[:id]
26
+ begin
27
+ response = @@gateway.setup_purchase(backer.price_in_cents, {
28
+ ip: request.remote_ip,
29
+ return_url: payment_success_paypal_express_url(id: backer.id),
30
+ cancel_return_url: payment_cancel_paypal_express_url(id: backer.id),
31
+ currency_code: 'BRL',
32
+ description: t('paypal_description', scope: SCOPE, :project_name => backer.project.name, :value => backer.display_value),
33
+ notify_url: payment_notifications_paypal_express_url(id: backer.id)
34
+ })
35
+
36
+ backer.update_attribute :payment_method, 'PayPal'
37
+ backer.update_attribute :payment_token, response.token
38
+
39
+ if response.params['correlation_id']
40
+ backer.update_attribute :payment_id, response.params['correlation_id']
41
+ end
42
+
43
+ redirect_to @@gateway.redirect_url_for(response.token)
44
+ rescue Exception => e
45
+ Airbrake.notify({ :error_class => "Paypal Error", :error_message => "Paypal Error: #{e.inspect}", :parameters => params}) rescue nil
46
+ Rails.logger.info "-----> #{e.inspect}"
47
+ paypal_flash_error
48
+ return redirect_to main_app.new_project_backer_path(backer.project)
49
+ end
50
+ end
51
+
52
+ def success
53
+ backer = current_user.backs.find params[:id]
54
+ begin
55
+ details = @@gateway.details_for(backer.payment_token)
56
+ response = @@gateway.purchase(backer.price_in_cents, {
57
+ ip: request.remote_ip,
58
+ token: backer.payment_token,
59
+ payer_id: details.payer_id
60
+ })
61
+
62
+ if response.success?
63
+ backer.confirm!
64
+ end
65
+
66
+ if details.params['transaction_id']
67
+ backer.update_attribute :payment_id, details.params['transaction_id']
68
+ end
69
+
70
+ session[:thank_you_id] = backer.project.id
71
+ session[:_payment_token] = backer.payment_token
72
+
73
+ paypal_flash_success
74
+ redirect_to main_app.thank_you_path
75
+ rescue Exception => e
76
+ Airbrake.notify({ :error_class => "Paypal Error", :error_message => "Paypal Error: #{e.message}", :parameters => params}) rescue nil
77
+ Rails.logger.info "-----> #{e.inspect}"
78
+ paypal_flash_error
79
+ return redirect_to main_app.new_project_backer_path(backer.project)
80
+ end
81
+ end
82
+
83
+ def cancel
84
+ backer = current_user.backs.find params[:id]
85
+ flash[:failure] = t('paypal_cancel', scope: SCOPE)
86
+ redirect_to main_app.new_project_backer_path(backer.project)
87
+ end
88
+
89
+ private
90
+
91
+ def paypal_flash_error
92
+ flash[:failure] = t('paypal_error', scope: SCOPE)
93
+ end
94
+
95
+ def paypal_flash_success
96
+ flash[:success] = t('success', scope: SCOPE)
97
+ end
98
+
99
+ def setup_gateway
100
+ if ::Configuration[:paypal_username] and ::Configuration[:paypal_password] and ::Configuration[:paypal_signature]
101
+ @@gateway ||= ActiveMerchant::Billing::PaypalExpressGateway.new({
102
+ :login => ::Configuration[:paypal_username],
103
+ :password => ::Configuration[:paypal_password],
104
+ :signature => ::Configuration[:paypal_signature]
105
+ })
106
+ else
107
+ puts "[PayPal] An API Certificate or API Signature is required to make requests to PayPal"
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,26 @@
1
+ #encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ # Maintain your gem's version:
5
+ require "catarse_paypal_express/version"
6
+
7
+ # Describe your gem and declare its dependencies:
8
+ Gem::Specification.new do |s|
9
+ s.name = "catarse_paypal_express"
10
+ s.version = CatarsePaypalExpress::VERSION
11
+ s.authors = ["Antônio Roberto Silva"]
12
+ s.email = ["forevertonny@gmail.com"]
13
+ s.homepage = "http://github.com/devton/catarse_paypal_express"
14
+ s.summary = "PaypalExpress integration with Catarse"
15
+ s.description = "PaypalExpress integration with Catarse crowdfunding platform"
16
+
17
+ s.files = `git ls-files`.split($\)
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+
20
+ s.add_dependency "rails", "~> 3.2.6"
21
+ s.add_dependency "activemerchant", "~> 1.17.0"
22
+
23
+ s.add_development_dependency "rspec-rails"
24
+ s.add_development_dependency "factory_girl_rails"
25
+ s.add_development_dependency "database_cleaner"
26
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ CatarsePaypalExpress::Engine.routes.draw do
2
+ namespace :payment do
3
+ match '/paypal_express/:id/notifications' => 'paypal_express#notifications', :as => 'notifications_paypal_express'
4
+ match '/paypal_express/:id/pay' => 'paypal_express#pay', :as => 'pay_paypal_express'
5
+ match '/paypal_express/:id/success' => 'paypal_express#success', :as => 'success_paypal_express'
6
+ match '/paypal_express/:id/cancel' => 'paypal_express#cancel', :as => 'cancel_paypal_express'
7
+ end
8
+ end
9
+
@@ -0,0 +1,4 @@
1
+ require "catarse_paypal_express/engine"
2
+
3
+ module CatarsePaypalExpress
4
+ end
@@ -0,0 +1,6 @@
1
+ module CatarsePaypalExpress
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace CatarsePaypalExpress
4
+ end
5
+ end
6
+
@@ -0,0 +1,3 @@
1
+ module CatarsePaypalExpress
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :catarse_paypal_express do
3
+ # # Task goes here
4
+ # end
data/script/rails ADDED
@@ -0,0 +1,9 @@
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_paypal_express/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
9
+
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ describe CatarsePaypalExpress::Payment::PaypalExpressController do
4
+ before do
5
+ Configuration.create!(name: "paypal_username", value: "usertest_api1.teste.com")
6
+ Configuration.create!(name: "paypal_password", value: "HVN4PQBGZMHKFVGW")
7
+ Configuration.create!(name: "paypal_signature", value: "AeL-u-Ox.N6Jennvu1G3BcdiTJxQAWdQcjdpLTB9ZaP0-Xuf-U0EQtnS")
8
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return({})
9
+ Airbrake.stub(:notify).and_return({})
10
+ end
11
+
12
+ let(:current_user) { Factory(:user) }
13
+
14
+ context 'when receive a notification' do
15
+ it 'and not found the backer, should return 404' do
16
+ post :notifications, { id: 1, use_route: 'catarse_paypal_express'}
17
+ response.status.should eq(404)
18
+ end
19
+
20
+ it 'and the transaction ID not match, should return 404' do
21
+ backer = Factory(:backer, payment_id: '1234')
22
+ post :notifications, { id: backer.id, txn_id: 123, use_route: 'catarse_paypal_express' }
23
+ response.status.should eq(404)
24
+ end
25
+
26
+ it 'and the transaction ID match, should update the payment status if successful' do
27
+ success_payment_response = mock()
28
+ success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234' })
29
+ success_payment_response.stubs(:success?).returns(true)
30
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return(success_payment_response)
31
+ backer = Factory(:backer, payment_id: '1234', confirmed: false)
32
+
33
+ post :notifications, { id: backer.id, txn_id: 1234, use_route: 'catarse_paypal_express' }
34
+
35
+ backer.reload
36
+ response.status.should eq(200)
37
+ backer.confirmed.should be_true
38
+ end
39
+ end
40
+
41
+ context 'setup purchase' do
42
+ context 'when have some failures' do
43
+ it 'user not logged in, should redirect' do
44
+ pending 'problems with external application routes'
45
+ #get :pay, {locale: 'en', use_route: 'catarse_paypal_express' }
46
+ #response.status.should eq(302)
47
+ end
48
+
49
+ it 'backer not belongs to current_user should 404' do
50
+ backer = Factory(:backer)
51
+ session[:user_id] = current_user.id
52
+
53
+ lambda {
54
+ get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
55
+ }.should raise_exception ActiveRecord::RecordNotFound
56
+ end
57
+
58
+ it 'raise a exepction because invalid data and should be redirect and set the flash message' do
59
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:setup_purchase).and_raise(StandardError)
60
+ session[:user_id] = current_user.id
61
+ backer = Factory(:backer, user: current_user)
62
+
63
+ get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
64
+ flash[:failure].should == I18n.t('paypal_error', scope: CatarsePaypalExpress::Payment::PaypalExpressController::SCOPE)
65
+ response.should be_redirect
66
+ end
67
+ end
68
+
69
+ context 'when successul' do
70
+ before do
71
+ success_response = mock()
72
+ success_response.stub(:token).and_return('ABCD')
73
+ success_response.stub(:params).and_return({ 'correlation_id' => '123' })
74
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:setup_purchase).and_return(success_response)
75
+ end
76
+
77
+ it 'payment method, token and id should be persisted ' do
78
+ session[:user_id] = current_user.id
79
+ backer = Factory(:backer, user: current_user)
80
+
81
+ get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
82
+ backer.reload
83
+
84
+ backer.payment_method.should == 'PayPal'
85
+ backer.payment_token.should == 'ABCD'
86
+ backer.payment_id.should == '123'
87
+
88
+ response.should be_redirect
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'when cancel the paypal purchase' do
94
+ it 'should show for user the flash message' do
95
+ session[:user_id] = current_user.id
96
+ backer = Factory(:backer, user: current_user, payment_token: 'TOKEN')
97
+
98
+ get :cancel, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
99
+ flash[:failure].should == I18n.t('paypal_cancel', scope: CatarsePaypalExpress::Payment::PaypalExpressController::SCOPE)
100
+ response.should be_redirect
101
+ end
102
+ end
103
+
104
+ context 'paypal returning to success route' do
105
+ context 'when paypal purchase is ok' do
106
+ before(:each) do
107
+ fake_success_purchase = mock()
108
+ fake_success_purchase.stub(:success?).and_return(true)
109
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:purchase).and_return(fake_success_purchase)
110
+
111
+ fake_success_details = mock()
112
+ fake_success_details.stub(:payer_id).and_return('123')
113
+ fake_success_details.stub(:params).and_return({'transaction_id' => '12345'})
114
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return(fake_success_details)
115
+ end
116
+
117
+ it 'should update the backer and redirect to thank_you' do
118
+ session[:user_id] = current_user.id
119
+ backer = Factory(:backer, user: current_user, payment_token: 'TOKEN')
120
+
121
+ get :success, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
122
+ backer.reload
123
+
124
+ backer.confirmed.should be_true
125
+ backer.payment_id.should == '12345'
126
+ session[:thank_you_id].should == backer.project.id
127
+ session[:_payment_token].should == backer.payment_token
128
+
129
+ response.should redirect_to('/thank_you')
130
+ end
131
+ end
132
+ context 'when paypal purchase raise a error' do
133
+ before do
134
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:purchase).and_raise(StandardError)
135
+ end
136
+
137
+ it 'should be redirect and show a flash message' do
138
+ session[:user_id] = current_user.id
139
+ backer = Factory(:backer, user: current_user)
140
+
141
+ get :success, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
142
+
143
+ flash[:failure].should == I18n.t('paypal_error', scope: CatarsePaypalExpress::Payment::PaypalExpressController::SCOPE)
144
+ response.should be_redirect
145
+ end
146
+ end
147
+ end
148
+
149
+ end
@@ -0,0 +1,68 @@
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 = false
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
+ config.before(:suite) do
47
+ DatabaseCleaner.strategy = :transaction
48
+ DatabaseCleaner.clean_with :truncation
49
+ end
50
+
51
+ config.before(:each) do
52
+ Project.any_instance.stub(:store_image_url).and_return('http://www.store_image_url.com')
53
+ end
54
+ end
55
+
56
+ RoutingFilter.active = false # Because this issue: https://github.com/svenfuchs/routing-filter/issues/36
57
+
58
+ def fixture_file(filename)
59
+ return nil if filename.nil?
60
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
61
+ File.read(file_path)
62
+ end
63
+
64
+ def paypal_setup_purchase_success_response
65
+ { "timestamp"=>"2012-07-23T00:24:21Z", "ack"=>"Success", "correlation_id"=>"dcb8596be51cd", "version"=>"62.0", "build"=>"3332236",
66
+ "token"=>"EC-49X25168KR2556548", "Timestamp"=>"2012-07-23T00:24:21Z", "Ack"=>"Success", "CorrelationID"=>"dcb8596be51cd",
67
+ "Version"=>"62.0", "Build"=>"3332236", "Token"=>"EC-49X25168KR2556548" }
68
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catarse_paypal_express
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Antônio Roberto Silva
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-24 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.6
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.6
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: PaypalExpress integration with Catarse crowdfunding platform
95
+ email:
96
+ - forevertonny@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/controllers/.gitkeep
108
+ - app/controllers/catarse_paypal_express/payment/paypal_express_controller.rb
109
+ - catarse_paypal_express.gemspec
110
+ - config/routes.rb
111
+ - lib/catarse_paypal_express.rb
112
+ - lib/catarse_paypal_express/engine.rb
113
+ - lib/catarse_paypal_express/version.rb
114
+ - lib/tasks/catarse_paypal_express_tasks.rake
115
+ - script/rails
116
+ - spec/controllers/catarse_paypal_express/payment/paypal_express_controller_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: http://github.com/devton/catarse_paypal_express
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.21
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: PaypalExpress integration with Catarse
142
+ test_files:
143
+ - spec/controllers/catarse_paypal_express/payment/paypal_express_controller_spec.rb
144
+ - spec/spec_helper.rb