catarse_paypal_express 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -12,21 +12,26 @@ gem "jquery-rails"
12
12
  # your gemspec. These might include edge Rails or gems from your path or
13
13
  # Git. Remember to move these dependencies to your gemspec before releasing
14
14
  # your gem to rubygems.org.
15
-
16
- # To use debugger
17
- # gem 'debugger'
18
- source 'http://rubygems.org'
15
+ source :gemcutter
19
16
  source 'http://gems.github.com'
20
17
 
21
18
  gem 'rails', '3.2.6'
22
19
  gem 'rake', '0.9.2.2'
23
- gem 'catarse_paypal_express', :path => '~/store/code/catarse_paypal_express'
24
20
 
25
- # Database [Putting pg to the end because of a weird bug with Lion, pg and openssl]
21
+ # Database and data related [Putting pg to the end because of a weird bug with Lion, pg and openssl]
26
22
  gem 'pg'
27
23
  gem 'foreigner'
28
24
  gem 'activerecord-postgresql-adapter'
29
25
 
26
+ gem 'catarse_paypal_express', :path => '~/store/code/catarse_paypal_express'
27
+ #gem 'catarse_paypal_express', '~> 0.0.2'
28
+ gem 'catarse_moip', '~> 0.1.1'
29
+ gem 'moip_catarse', '~> 1.0.6', require: 'moip'
30
+
31
+ gem 'maxim-sexy_pg_constraints'
32
+ gem 'dalli'
33
+ gem 'draper'
34
+
30
35
  # Frontend stuff
31
36
  gem 'jquery-rails'
32
37
  gem 'slim'
@@ -43,35 +48,42 @@ gem 'omniauth-yahoo', '~> 0.0.4'
43
48
  gem 'devise', '1.5.3'
44
49
  gem 'cancan'
45
50
 
46
- gem 'rails_autolink', '~> 1.0.7'
47
51
 
48
- # Tools
49
- gem 'mailchimp'
52
+ # Error reporting
50
53
  gem "airbrake"
51
- gem 'feedzirra'
52
- gem 'formtastic'
54
+
55
+ # Email marketing
56
+ #gem 'mailchimp'
57
+ gem 'catarse_mailchimp'
58
+
59
+ # HTML manipulation and formatting
60
+ gem 'formtastic', "~> 2.1.1"
53
61
  gem "auto_html", '= 1.4.2'
62
+ gem 'kaminari'
63
+ gem 'rails_autolink', '~> 1.0.7'
64
+
65
+ # Uploads
66
+ gem 'carrierwave', '= 0.5.8'
67
+ gem 'rmagick'
68
+ gem 'fog'
69
+
70
+ # Other Tools
71
+ gem 'feedzirra'
54
72
  gem 'validation_reflection', git: 'git://github.com/ncri/validation_reflection.git'
55
- gem 'maxim-sexy_pg_constraints'
56
73
  gem 'inherited_resources', '1.3.1'
74
+ gem 'has_scope'
57
75
  gem 'spectator-validates_email', require: 'validates_email'
58
- gem 'has_vimeo_video', '>= 0.0.4'
76
+ gem 'has_vimeo_video', '~> 0.0.5'
59
77
  gem 'wirble'
60
78
  gem "on_the_spot"
61
79
  gem 'weekdays'
62
80
  gem 'brcep'
63
81
  gem "RedCloth"
64
82
  gem 'unicode'
65
- gem 'carrierwave', '= 0.5.8'
66
- gem 'rmagick'
67
- gem 'fog'
68
83
  gem 'enumerate_it'
69
84
  gem 'httparty', '~> 0.6.1'
70
85
  gem "rack-timeout"
71
- gem 'kaminari'
72
86
  gem 'tumblr-api'
73
- gem 'dalli'
74
- gem 'capybara', ">= 1.0.1"
75
87
 
76
88
  # Translations
77
89
  gem 'http_accept_language'
@@ -82,12 +94,8 @@ gem 'routing-filter' #, :git => 'git://github.com/svenfuchs/routing-filter.git'
82
94
  gem 'activeadmin', git: 'git://github.com/gregbell/active_admin.git'
83
95
  gem "meta_search", "1.1.3"
84
96
 
85
- # Payment (moip)
86
- gem 'moip', git: 'https://github.com/danielweinmann/moip-ruby.git', ref: 'db1b879358c623b597dc1c221b53336f9f06db0e'
87
-
88
- # Payment (paypal adaptive)
97
+ # Payment
89
98
  gem 'activemerchant', '1.17.0', require: 'active_merchant'
90
- #gem 'active_paypal_adaptive_payment', '~> 0.3.13'
91
99
  gem 'httpclient', '2.2.5'
92
100
  gem 'selenium-webdriver', '~> 2.25.0'
93
101
  gem 'bourbon'
@@ -112,14 +120,12 @@ group :test, :development do
112
120
  gem 'rspec-rails', "~> 2.10.0"
113
121
  gem 'rcov', '= 0.9.11'
114
122
  gem 'mocha', '0.10.4'
123
+ gem 'shoulda'
124
+ gem 'factory_girl_rails', '1.7.0'
125
+ gem 'capybara', ">= 1.0.1"
115
126
  end
116
127
 
117
128
  group :development do
118
129
  gem 'mailcatcher'
119
130
  gem 'ruby-debug19'
120
131
  end
121
-
122
- group :test do
123
- gem 'shoulda'
124
- gem 'factory_girl_rails', '1.7.0'
125
- end
data/Gemfile.lock CHANGED
@@ -21,20 +21,10 @@ GIT
21
21
  specs:
22
22
  validation_reflection (1.0.0)
23
23
 
24
- GIT
25
- remote: https://github.com/danielweinmann/moip-ruby.git
26
- revision: db1b879358c623b597dc1c221b53336f9f06db0e
27
- ref: db1b879358c623b597dc1c221b53336f9f06db0e
28
- specs:
29
- moip (1.0.2)
30
- activesupport (>= 2.3.2)
31
- httparty (~> 0.6.1)
32
- nokogiri (~> 1.4.3)
33
-
34
24
  PATH
35
25
  remote: .
36
26
  specs:
37
- catarse_paypal_express (0.0.1)
27
+ catarse_paypal_express (0.0.2)
38
28
  activemerchant (~> 1.17.0)
39
29
  rails (~> 3.2.6)
40
30
 
@@ -111,6 +101,12 @@ GEM
111
101
  xpath (~> 0.1.4)
112
102
  carrierwave (0.5.8)
113
103
  activesupport (~> 3.0)
104
+ catarse_mailchimp (0.0.1)
105
+ mailchimp
106
+ supermodel
107
+ catarse_moip (0.1.1)
108
+ moip_catarse (~> 1.0.6)
109
+ rails (~> 3.2.6)
114
110
  childprocess (0.3.5)
115
111
  ffi (~> 1.0, >= 1.0.6)
116
112
  chunky_png (1.2.6)
@@ -140,6 +136,9 @@ GEM
140
136
  orm_adapter (~> 0.0.3)
141
137
  warden (~> 1.1)
142
138
  diff-lcs (1.1.3)
139
+ draper (0.17.0)
140
+ actionpack (~> 3.2)
141
+ activesupport (~> 3.2)
143
142
  enumerate_it (0.7.16)
144
143
  activesupport (>= 3.0.0)
145
144
  erubis (2.7.0)
@@ -179,8 +178,8 @@ GEM
179
178
  foreigner (1.2.0)
180
179
  activerecord (>= 3.0.0)
181
180
  formatador (0.2.3)
182
- formtastic (2.2.1)
183
- actionpack (>= 3.0)
181
+ formtastic (2.1.1)
182
+ actionpack (~> 3.0)
184
183
  fssm (0.2.9)
185
184
  haml (3.1.6)
186
185
  has_scope (0.5.1)
@@ -243,6 +242,10 @@ GEM
243
242
  mime-types (1.19)
244
243
  mocha (0.10.4)
245
244
  metaclass (~> 0.0.1)
245
+ moip_catarse (1.0.6)
246
+ activesupport (>= 2.3.2)
247
+ httparty (~> 0.6.1)
248
+ nokogiri (~> 1.4.2)
246
249
  multi_json (1.3.6)
247
250
  multipart-post (1.1.5)
248
251
  net-scp (1.0.4)
@@ -461,6 +464,8 @@ DEPENDENCIES
461
464
  cancan
462
465
  capybara (>= 1.0.1)
463
466
  carrierwave (= 0.5.8)
467
+ catarse_mailchimp
468
+ catarse_moip (~> 0.1.1)
464
469
  catarse_paypal_express!
465
470
  coffee-rails (~> 3.2.2)
466
471
  compass-960-plugin (~> 0.10.4)
@@ -468,13 +473,15 @@ DEPENDENCIES
468
473
  dalli
469
474
  database_cleaner
470
475
  devise (= 1.5.3)
476
+ draper
471
477
  enumerate_it
472
478
  factory_girl_rails (= 1.7.0)
473
479
  feedzirra
474
480
  fog
475
481
  foreigner
476
- formtastic
477
- has_vimeo_video (>= 0.0.4)
482
+ formtastic (~> 2.1.1)
483
+ has_scope
484
+ has_vimeo_video (~> 0.0.5)
478
485
  http_accept_language
479
486
  httparty (~> 0.6.1)
480
487
  httpclient (= 2.2.5)
@@ -483,11 +490,10 @@ DEPENDENCIES
483
490
  kaminari
484
491
  launchy
485
492
  mailcatcher
486
- mailchimp
487
493
  maxim-sexy_pg_constraints
488
494
  meta_search (= 1.1.3)
489
495
  mocha (= 0.10.4)
490
- moip!
496
+ moip_catarse (~> 1.0.6)
491
497
  omniauth (~> 1.1.0)
492
498
  omniauth-facebook (~> 1.2.0)
493
499
  omniauth-github (~> 1.0.1)
@@ -1,3 +1,5 @@
1
+ require 'catarse_paypal_express/processors'
2
+
1
3
  module CatarsePaypalExpress::Payment
2
4
  class PaypalExpressController < ApplicationController
3
5
  skip_before_filter :verify_authenticity_token, :only => [:notifications]
@@ -8,11 +10,12 @@ module CatarsePaypalExpress::Payment
8
10
 
9
11
  SCOPE = "projects.backers.checkout"
10
12
 
13
+
11
14
  def notifications
12
15
  backer = Backer.find params[:id]
13
16
  response = @@gateway.details_for(backer.payment_token)
14
17
  if response.params['transaction_id'] == params['txn_id']
15
- backer.confirm! if response.success?
18
+ build_notification(backer, response.params)
16
19
  render status: 200, nothing: true
17
20
  else
18
21
  render status: 404, nothing: true
@@ -36,6 +39,8 @@ module CatarsePaypalExpress::Payment
36
39
  backer.update_attribute :payment_method, 'PayPal'
37
40
  backer.update_attribute :payment_token, response.token
38
41
 
42
+ build_notification(backer, response.params)
43
+
39
44
  if response.params['correlation_id']
40
45
  backer.update_attribute :payment_id, response.params['correlation_id']
41
46
  end
@@ -59,9 +64,7 @@ module CatarsePaypalExpress::Payment
59
64
  payer_id: details.payer_id
60
65
  })
61
66
 
62
- if response.success?
63
- backer.confirm!
64
- end
67
+ build_notification(backer, details.params)
65
68
 
66
69
  if details.params['transaction_id']
67
70
  backer.update_attribute :payment_id, details.params['transaction_id']
@@ -88,6 +91,11 @@ module CatarsePaypalExpress::Payment
88
91
 
89
92
  private
90
93
 
94
+ def build_notification(backer, data)
95
+ processor = CatarsePaypalExpress::Processors::Paypal.new
96
+ processor.process!(backer, data)
97
+ end
98
+
91
99
  def paypal_flash_error
92
100
  flash[:failure] = t('paypal_error', scope: SCOPE)
93
101
  end
@@ -0,0 +1,5 @@
1
+ require 'catarse_paypal_express/processors/paypal'
2
+ module CatarsePaypalExpress
3
+ module Processors
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module CatarsePaypalExpress
2
+ module Processors
3
+ class Paypal
4
+
5
+ def process!(backer, data)
6
+ status = data["checkout_status"] || "pending"
7
+
8
+ notification = backer.payment_notifications.new({
9
+ status: status,
10
+ extra_data: data
11
+ })
12
+
13
+ notification.save!
14
+
15
+ backer.confirm! if success_payment?(status)
16
+ end
17
+
18
+ protected
19
+
20
+ def success_payment?(status)
21
+ status == 'PaymentActionCompleted'
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module CatarsePaypalExpress
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -23,9 +23,24 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
23
23
  response.status.should eq(404)
24
24
  end
25
25
 
26
+ it 'should create a payment_notification' do
27
+ success_payment_response = mock()
28
+ success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234', "checkout_status" => "PaymentActionCompleted" })
29
+ success_payment_response.stubs(:success?).returns(true)
30
+ ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return(success_payment_response)
31
+
32
+ backer = Factory(:backer, payment_id: '1234')
33
+ backer.payment_notifications.should be_empty
34
+
35
+ post :notifications, { id: backer.id, txn_id: 1234 , use_route: 'catarse_paypal_express' }
36
+ backer.reload
37
+
38
+ backer.payment_notifications.should_not be_empty
39
+ end
40
+
26
41
  it 'and the transaction ID match, should update the payment status if successful' do
27
42
  success_payment_response = mock()
28
- success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234' })
43
+ success_payment_response.stubs(:params).returns({ 'transaction_id' => '1234', "checkout_status" => "PaymentActionCompleted" })
29
44
  success_payment_response.stubs(:success?).returns(true)
30
45
  ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return(success_payment_response)
31
46
  backer = Factory(:backer, payment_id: '1234', confirmed: false)
@@ -74,6 +89,17 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
74
89
  ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:setup_purchase).and_return(success_response)
75
90
  end
76
91
 
92
+ it 'should create a payment_notification' do
93
+ session[:user_id] = current_user.id
94
+ backer = Factory(:backer, user: current_user)
95
+
96
+ get :pay, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
97
+ backer.reload
98
+
99
+ backer.payment_notifications.should_not be_empty
100
+ backer.payment_notifications.first.status == 'pending'
101
+ end
102
+
77
103
  it 'payment method, token and id should be persisted ' do
78
104
  session[:user_id] = current_user.id
79
105
  backer = Factory(:backer, user: current_user)
@@ -110,17 +136,19 @@ describe CatarsePaypalExpress::Payment::PaypalExpressController do
110
136
 
111
137
  fake_success_details = mock()
112
138
  fake_success_details.stub(:payer_id).and_return('123')
113
- fake_success_details.stub(:params).and_return({'transaction_id' => '12345'})
139
+ fake_success_details.stub(:params).and_return({'transaction_id' => '12345', "checkout_status" => "PaymentActionCompleted"})
114
140
  ActiveMerchant::Billing::PaypalExpressGateway.any_instance.stub(:details_for).and_return(fake_success_details)
115
141
  end
116
142
 
117
143
  it 'should update the backer and redirect to thank_you' do
118
144
  session[:user_id] = current_user.id
119
145
  backer = Factory(:backer, user: current_user, payment_token: 'TOKEN')
146
+ backer.payment_notifications.should be_empty
120
147
 
121
148
  get :success, { id: backer.id, locale: 'en', use_route: 'catarse_paypal_express' }
122
149
  backer.reload
123
150
 
151
+ backer.payment_notifications.should_not be_empty
124
152
  backer.confirmed.should be_true
125
153
  backer.payment_id.should == '12345'
126
154
  session[:thank_you_id].should == backer.project.id
@@ -0,0 +1,33 @@
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 status based on checkout_status" do
14
+ subject.process!(backer, paypal_details_response)
15
+ backer.payment_notifications.first.status.should == 'PaymentActionCompleted'
16
+ end
17
+
18
+ it "should fill extra_data with all response data" do
19
+ subject.process!(backer, paypal_details_response)
20
+ backer.payment_notifications.first.extra_data.should == paypal_details_response
21
+ end
22
+
23
+ it "should confirm backer when checkout status is completed" do
24
+ subject.process!(backer, paypal_details_response)
25
+ backer.confirmed.should be_true
26
+ end
27
+
28
+ it "should not confirm when checkout status is not completed" do
29
+ subject.process!(backer, paypal_details_response.merge!({"checkout_status" => "just_another_status"}) )
30
+ backer.confirmed.should be_false
31
+ end
32
+ end
33
+ end
data/spec/spec_helper.rb CHANGED
@@ -66,3 +66,10 @@ def paypal_setup_purchase_success_response
66
66
  "token"=>"EC-49X25168KR2556548", "Timestamp"=>"2012-07-23T00:24:21Z", "Ack"=>"Success", "CorrelationID"=>"dcb8596be51cd",
67
67
  "Version"=>"62.0", "Build"=>"3332236", "Token"=>"EC-49X25168KR2556548" }
68
68
  end
69
+
70
+ def paypal_details_response
71
+ {
72
+ "transaction_id" => "1234",
73
+ "checkout_status" => "PaymentActionCompleted"
74
+ }
75
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_paypal_express
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2012-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -112,10 +112,13 @@ files:
112
112
  - config/routes.rb
113
113
  - lib/catarse_paypal_express.rb
114
114
  - lib/catarse_paypal_express/engine.rb
115
+ - lib/catarse_paypal_express/processors.rb
116
+ - lib/catarse_paypal_express/processors/paypal.rb
115
117
  - lib/catarse_paypal_express/version.rb
116
118
  - lib/tasks/catarse_paypal_express_tasks.rake
117
119
  - script/rails
118
120
  - spec/controllers/catarse_paypal_express/payment/paypal_express_controller_spec.rb
121
+ - spec/lib/processors/paypal_spec.rb
119
122
  - spec/spec_helper.rb
120
123
  homepage: http://github.com/devton/catarse_paypal_express
121
124
  licenses: []
@@ -143,4 +146,5 @@ specification_version: 3
143
146
  summary: PaypalExpress integration with Catarse
144
147
  test_files:
145
148
  - spec/controllers/catarse_paypal_express/payment/paypal_express_controller_spec.rb
149
+ - spec/lib/processors/paypal_spec.rb
146
150
  - spec/spec_helper.rb