catarse_paypal_express 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07eed4533c5542caa215045ca70b7f41d716d322
4
+ data.tar.gz: 019bca2925c07d4c5bfcc43934b099d926f5d81e
5
+ SHA512:
6
+ metadata.gz: 18032dd6c34667a2b1ce5b5375cf7033e1c7926ee88f3be84b0933b88a7ba9c0750231b8b1d9903581cc19c042c55f742f318a37c6f6e6cc3bf9b7479f0bac36
7
+ data.tar.gz: a41ae452e1c547953a9316cc7f2d7742e5e637cb20ecfb0c4dc6ba988805baa1485e79acd2e2fe1eae474833d6f01abce5d304222501d0df2ee8b209f1412845
@@ -8,19 +8,6 @@ class CatarsePaypalExpress::PaypalExpressController < ApplicationController
8
8
  def review
9
9
  end
10
10
 
11
- def refund
12
- refund_request = gateway.refund(nil, contribution.payment_id)
13
-
14
-
15
- if refund_request.success?
16
- flash[:notice] = I18n.t('projects.contributions.refund.success')
17
- else
18
- flash[:alert] = refund_request.try(:message) || I18n.t('projects.contributions.refund.error')
19
- end
20
-
21
- redirect_to main_app.admin_contributions_path
22
- end
23
-
24
11
  def ipn
25
12
  if contribution && notification.acknowledge && (contribution.payment_method == 'PayPal' || contribution.payment_method.nil?)
26
13
  process_paypal_message params
@@ -115,15 +102,7 @@ class CatarsePaypalExpress::PaypalExpressController < ApplicationController
115
102
  end
116
103
 
117
104
  def gateway
118
- if PaymentEngines.configuration[:paypal_username] and PaymentEngines.configuration[:paypal_password] and PaymentEngines.configuration[:paypal_signature]
119
- @gateway ||= ActiveMerchant::Billing::PaypalExpressGateway.new({
120
- login: PaymentEngines.configuration[:paypal_username],
121
- password: PaymentEngines.configuration[:paypal_password],
122
- signature: PaymentEngines.configuration[:paypal_signature]
123
- })
124
- else
125
- puts "[PayPal] An API Certificate or API Signature is required to make requests to PayPal"
126
- end
105
+ @gateway ||= CatarsePaypalExpress::Gateway.instance
127
106
  end
128
107
 
129
108
  protected
@@ -4,8 +4,9 @@ begin
4
4
  review_path: ->(contribution) {
5
5
  CatarsePaypalExpress::Engine.routes.url_helpers.review_paypal_express_path(contribution)
6
6
  },
7
- refund_path: ->(contribution) {
8
- CatarsePaypalExpress::Engine.routes.url_helpers.refund_paypal_express_path(contribution)
7
+ can_do_refund?: true,
8
+ direct_refund: ->(contribution) {
9
+ CatarsePaypalExpress::ContributionActions.new(contribution).refund
9
10
  },
10
11
  locale: 'en'
11
12
  })
data/config/routes.rb CHANGED
@@ -5,7 +5,6 @@ CatarsePaypalExpress::Engine.routes.draw do
5
5
  end
6
6
 
7
7
  member do
8
- post :refund
9
8
  get :review
10
9
  post :pay
11
10
  get :success
@@ -1,5 +1,7 @@
1
1
  require 'active_merchant'
2
2
  require "catarse_paypal_express/engine"
3
+ require "catarse_paypal_express/gateway"
4
+ require "catarse_paypal_express/contribution_actions"
3
5
 
4
6
  module CatarsePaypalExpress
5
7
  end
@@ -0,0 +1,20 @@
1
+ module CatarsePaypalExpress
2
+ class ContributionActions
3
+
4
+ def initialize contribution
5
+ @contribution = contribution
6
+ end
7
+
8
+ def refund
9
+ refund_request = gateway.refund(nil, @contribution.payment_id)
10
+ refund_request.success?
11
+ end
12
+
13
+ private
14
+
15
+ def gateway
16
+ @gateway ||= CatarsePaypalExpress::Gateway.instance
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ module CatarsePaypalExpress
2
+ class Gateway
3
+ include ActiveMerchant::Billing::Integrations
4
+
5
+ def initialize configuration = PaymentEngines.configuration
6
+ @configuration = configuration
7
+ end
8
+
9
+ def self.instance
10
+ new.setup_gateway
11
+ rescue Exception => e
12
+ puts e.message
13
+ end
14
+
15
+ def setup_gateway
16
+ check_default_configurations!
17
+ ActiveMerchant::Billing::PaypalExpressGateway.new({
18
+ login: @configuration[:paypal_username],
19
+ password: @configuration[:paypal_password],
20
+ signature: @configuration[:paypal_signature]
21
+ })
22
+ end
23
+
24
+ private
25
+
26
+ def check_default_configurations!
27
+ %i(paypal_username paypal_password paypal_signature).each do |key|
28
+ raise pending_configuration_message unless @configuration[key].present?
29
+ end
30
+ end
31
+
32
+ def pending_configuration_message
33
+ "[PayPal] An API Certificate or API Signature is required to make requests to PayPal"
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module CatarsePaypalExpress
2
- VERSION = "2.2.0"
2
+ VERSION = "2.2.1"
3
3
  end
@@ -41,21 +41,6 @@ describe CatarsePaypalExpress::PaypalExpressController do
41
41
  payment_method: 'PayPal'
42
42
  }) }
43
43
 
44
- describe "POST refund" do
45
- before do
46
- success_refund = double
47
- success_refund.stub(:success?).and_return(true)
48
-
49
- main_app.should_receive(:admin_contributions_path).and_return('admin_contributions_path')
50
-
51
- gateway.should_receive(:refund).with(nil, contribution.payment_id).and_return(success_refund)
52
-
53
- post :refund, id: contribution.id, use_route: 'catarse_paypal_express'
54
- end
55
-
56
- it { should redirect_to('admin_contributions_path') }
57
- end
58
-
59
44
  describe "GET review" do
60
45
  before do
61
46
  get :review, id: contribution.id, use_route: 'catarse_paypal_express'
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe CatarsePaypalExpress::ContributionActions do
4
+ let(:contribution_actions) { CatarsePaypalExpress::ContributionActions.new(contribution) }
5
+ let(:gateway) { double('gateway') }
6
+ let(:contribution) {
7
+ double(:contribution, {id: 1, payment_id: '123a'})
8
+ }
9
+ let(:refund_return) { double }
10
+
11
+ before do
12
+ CatarsePaypalExpress::Gateway.stub(:instance).and_return(gateway)
13
+ end
14
+
15
+ describe '#refund' do
16
+ subject do
17
+ contribution_actions.refund
18
+ end
19
+
20
+ before do
21
+ contribution_actions.should_receive(:gateway).and_call_original
22
+ gateway.should_receive(:refund).with(nil, contribution.payment_id).and_return(refund_return)
23
+ end
24
+
25
+ context "success refund" do
26
+ before do
27
+ refund_return.stub(:success?).and_return(true)
28
+ end
29
+
30
+ it { should be_true }
31
+ end
32
+
33
+ context "failed refund" do
34
+ before do
35
+ refund_return.stub(:success?).and_return(false)
36
+ end
37
+
38
+ it { should be_false }
39
+ end
40
+ end
41
+ end
@@ -9,6 +9,7 @@
9
9
  # Choose the win32 build.
10
10
  # Install PostgreSQL and put its /bin directory on your path.
11
11
  development:
12
+ host: localhost
12
13
  adapter: postgresql
13
14
  encoding: utf-8
14
15
  database: catarse_development
@@ -35,6 +36,7 @@ development:
35
36
  # re-generated from your development database when you run "rake".
36
37
  # Do not set this db to the same as development or production.
37
38
  test: &test
39
+ host: localhost
38
40
  adapter: postgresql
39
41
  encoding: utf-8
40
42
  database: catarse_test
@@ -43,6 +45,7 @@ test: &test
43
45
 
44
46
 
45
47
  production:
48
+ host: localhost
46
49
  adapter: postgresql
47
50
  encoding: utf-8
48
51
  database: catarse_production
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_paypal_express
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
5
- prerelease:
4
+ version: 2.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Antônio Roberto Silva
@@ -11,102 +10,90 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2014-01-23 00:00:00.000000000 Z
13
+ date: 2014-03-13 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rails
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ~>
19
+ - - "~>"
22
20
  - !ruby/object:Gem::Version
23
21
  version: '4.0'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
- - - ~>
26
+ - - "~>"
30
27
  - !ruby/object:Gem::Version
31
28
  version: '4.0'
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: activemerchant
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ! '>='
33
+ - - ">="
38
34
  - !ruby/object:Gem::Version
39
35
  version: 1.34.0
40
36
  type: :runtime
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ! '>='
40
+ - - ">="
46
41
  - !ruby/object:Gem::Version
47
42
  version: 1.34.0
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: slim-rails
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
- - - ! '>='
47
+ - - ">="
54
48
  - !ruby/object:Gem::Version
55
49
  version: '0'
56
50
  type: :runtime
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
- - - ! '>='
54
+ - - ">="
62
55
  - !ruby/object:Gem::Version
63
56
  version: '0'
64
57
  - !ruby/object:Gem::Dependency
65
58
  name: rspec-rails
66
59
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
- - - ~>
61
+ - - "~>"
70
62
  - !ruby/object:Gem::Version
71
63
  version: 2.14.0
72
64
  type: :development
73
65
  prerelease: false
74
66
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
67
  requirements:
77
- - - ~>
68
+ - - "~>"
78
69
  - !ruby/object:Gem::Version
79
70
  version: 2.14.0
80
71
  - !ruby/object:Gem::Dependency
81
72
  name: factory_girl_rails
82
73
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
74
  requirements:
85
- - - ! '>='
75
+ - - ">="
86
76
  - !ruby/object:Gem::Version
87
77
  version: '0'
88
78
  type: :development
89
79
  prerelease: false
90
80
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
81
  requirements:
93
- - - ! '>='
82
+ - - ">="
94
83
  - !ruby/object:Gem::Version
95
84
  version: '0'
96
85
  - !ruby/object:Gem::Dependency
97
86
  name: database_cleaner
98
87
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
88
  requirements:
101
- - - ! '>='
89
+ - - ">="
102
90
  - !ruby/object:Gem::Version
103
91
  version: '0'
104
92
  type: :development
105
93
  prerelease: false
106
94
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
95
  requirements:
109
- - - ! '>='
96
+ - - ">="
110
97
  - !ruby/object:Gem::Version
111
98
  version: '0'
112
99
  description: PaypalExpress integration with Catarse crowdfunding platform
@@ -118,9 +105,9 @@ executables: []
118
105
  extensions: []
119
106
  extra_rdoc_files: []
120
107
  files:
121
- - .gitignore
122
- - .rspec
123
- - .travis.yml
108
+ - ".gitignore"
109
+ - ".rspec"
110
+ - ".travis.yml"
124
111
  - Gemfile
125
112
  - Gemfile.lock
126
113
  - MIT-LICENSE
@@ -139,12 +126,15 @@ files:
139
126
  - config/locales/pt.yml
140
127
  - config/routes.rb
141
128
  - lib/catarse_paypal_express.rb
129
+ - lib/catarse_paypal_express/contribution_actions.rb
142
130
  - lib/catarse_paypal_express/engine.rb
131
+ - lib/catarse_paypal_express/gateway.rb
143
132
  - lib/catarse_paypal_express/version.rb
144
133
  - lib/tasks/catarse_paypal_express_tasks.rake
145
134
  - script/rails
146
135
  - spec/controllers/catarse_paypal_express/paypal_express_controller_spec.rb
147
136
  - spec/fixtures/ipn_data.txt
137
+ - spec/lib/catarse_paypal_express/contribution_actions_spec.rb
148
138
  - spec/spec_helper.rb
149
139
  - spec/support/payment_engines.rb
150
140
  - test/dummy/README.rdoc
@@ -182,31 +172,31 @@ files:
182
172
  - test/dummy/script/rails
183
173
  homepage: http://github.com/catarse/catarse_paypal_express
184
174
  licenses: []
175
+ metadata: {}
185
176
  post_install_message:
186
177
  rdoc_options: []
187
178
  require_paths:
188
179
  - lib
189
180
  required_ruby_version: !ruby/object:Gem::Requirement
190
- none: false
191
181
  requirements:
192
- - - ! '>='
182
+ - - ">="
193
183
  - !ruby/object:Gem::Version
194
184
  version: '0'
195
185
  required_rubygems_version: !ruby/object:Gem::Requirement
196
- none: false
197
186
  requirements:
198
- - - ! '>='
187
+ - - ">="
199
188
  - !ruby/object:Gem::Version
200
189
  version: '0'
201
190
  requirements: []
202
191
  rubyforge_project:
203
- rubygems_version: 1.8.25
192
+ rubygems_version: 2.2.0
204
193
  signing_key:
205
- specification_version: 3
194
+ specification_version: 4
206
195
  summary: PaypalExpress integration with Catarse
207
196
  test_files:
208
197
  - spec/controllers/catarse_paypal_express/paypal_express_controller_spec.rb
209
198
  - spec/fixtures/ipn_data.txt
199
+ - spec/lib/catarse_paypal_express/contribution_actions_spec.rb
210
200
  - spec/spec_helper.rb
211
201
  - spec/support/payment_engines.rb
212
202
  - test/dummy/README.rdoc