catarse_moip 3.1.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e99de7a819ac9836c6d658c18e108e37868401d
4
- data.tar.gz: 9ee3cb1b0cc851ccc3ed2be27c7db9a0a0962dc9
3
+ metadata.gz: 0811dcffbaee61f008354134da29c803b69ff685
4
+ data.tar.gz: 62f383c1a7a7f31305d0db05f4863a034f2b6b1f
5
5
  SHA512:
6
- metadata.gz: 1a32faf8498c4036e1d6f3222ff4dbdbc6e5e4e33596d00c0af9110d044e917b8c57b5c0780d00f4db9775d45f84c34f5e180f99b4c46280abfc7cb9058c1dd8
7
- data.tar.gz: b433c5651a8ac3155566ac423d5eeda2fb76135e03679dc341c1f8da41dae86e0da29b6b2dfef0f5cd2f9531d67b1a588975f35f0bd1031c6d82d2490362f522
6
+ metadata.gz: 1ddb507b48e6df49cde0b726d5aa1f6c0931af462cd49da913c4f310ecb246eda0b54fc80997e1ed5445404c161e9c7b1f59d494d56187d47dddc8d220e51bd3
7
+ data.tar.gz: f24434f53c251a7436a092922677d65e47b4c63e7a4f0401749984231770917eb9fdd823a8c24b4bc6a828cbfad52a5d752cd44b0155aa991196585e02fca6f6
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- catarse_moip (3.1.1)
13
+ catarse_moip (3.2.0)
14
14
  enumerate_it
15
15
  httparty
16
16
  libxml-ruby (~> 2.8.0)
@@ -49,7 +49,7 @@ GEM
49
49
  builder (3.2.2)
50
50
  database_cleaner (1.3.0)
51
51
  diff-lcs (1.2.5)
52
- enumerate_it (1.2.4)
52
+ enumerate_it (1.2.6)
53
53
  activesupport (>= 3.0.0)
54
54
  erubis (2.7.0)
55
55
  factory_girl (4.5.0)
@@ -57,7 +57,6 @@ GEM
57
57
  factory_girl_rails (4.5.0)
58
58
  factory_girl (~> 4.5.0)
59
59
  railties (>= 3.0.0)
60
- hike (1.2.3)
61
60
  httparty (0.12.0)
62
61
  json (~> 1.8)
63
62
  multi_xml (>= 0.5.2)
@@ -66,10 +65,9 @@ GEM
66
65
  libxml-ruby (2.8.0)
67
66
  mail (2.6.3)
68
67
  mime-types (>= 1.16, < 3)
69
- mime-types (2.4.3)
68
+ mime-types (2.5)
70
69
  mini_portile (0.6.0)
71
70
  minitest (5.4.2)
72
- multi_json (1.10.1)
73
71
  multi_xml (0.5.5)
74
72
  nokogiri (1.6.3.1)
75
73
  mini_portile (= 0.6.0)
@@ -105,18 +103,14 @@ GEM
105
103
  rspec-core (~> 2.14.0)
106
104
  rspec-expectations (~> 2.14.0)
107
105
  rspec-mocks (~> 2.14.0)
108
- sprockets (2.12.3)
109
- hike (~> 1.2)
110
- multi_json (~> 1.0)
106
+ sprockets (3.0.3)
111
107
  rack (~> 1.0)
112
- tilt (~> 1.1, != 1.3.0)
113
108
  sprockets-rails (2.2.4)
114
109
  actionpack (>= 3.0)
115
110
  activesupport (>= 3.0)
116
111
  sprockets (>= 2.8, < 4.0)
117
112
  thor (0.19.1)
118
113
  thread_safe (0.3.4)
119
- tilt (1.4.1)
120
114
  tzinfo (1.2.2)
121
115
  thread_safe (~> 0.1)
122
116
 
@@ -5,30 +5,9 @@ module CatarseMoip
5
5
  class MoipController < ApplicationController
6
6
  attr_accessor :contribution
7
7
 
8
- class TransactionStatus < ::EnumerateIt::Base
9
- associate_values(
10
- :authorized => 1,
11
- :started => 2,
12
- :printed_boleto => 3,
13
- :finished => 4,
14
- :canceled => 5,
15
- :process => 6,
16
- :written_back => 7,
17
- :refunded => 9
18
- )
19
- end
20
-
21
8
  skip_before_filter :force_http
22
9
  layout :false
23
10
 
24
- def create_notification
25
- @contribution = PaymentEngines.find_payment key: params[:id_transacao]
26
- process_moip_message if @contribution.payment_method == 'MoIP' || @contribution.payment_method.nil?
27
- return render :nothing => true, :status => 200
28
- rescue Exception => e
29
- return render :text => "#{e.inspect}: #{e.message} recebemos: #{params}", :status => 422
30
- end
31
-
32
11
  def js
33
12
  tries = 0
34
13
  begin
@@ -120,37 +99,5 @@ module CatarseMoip
120
99
  end
121
100
  end
122
101
  end
123
-
124
- def process_moip_message
125
- contribution.with_lock do
126
- first_update_contribution if contribution.payment_method.nil?
127
- payment_notification = PaymentEngines.create_payment_notification contribution_id: contribution.id, extra_data: JSON.parse(params.to_json.force_encoding('iso-8859-1').encode('utf-8'))
128
- payment_id = (contribution.payment_id.gsub(".", "").to_i rescue 0)
129
-
130
- if payment_id <= params[:cod_moip].to_i
131
- contribution.update_attributes payment_id: params[:cod_moip]
132
-
133
- if (params[:valor].to_i/100.0) < contribution.value && params[:valor]
134
- return contribution.invalid! unless contribution.invalid_payment?
135
- end
136
-
137
- case params[:status_pagamento].to_i
138
- when TransactionStatus::PROCESS
139
- payment_notification.deliver_process_notification
140
- when TransactionStatus::AUTHORIZED, TransactionStatus::FINISHED
141
- contribution.confirm! unless contribution.confirmed?
142
- when TransactionStatus::WRITTEN_BACK, TransactionStatus::REFUNDED
143
- contribution.refund! unless contribution.refunded?
144
- when TransactionStatus::CANCELED
145
- unless contribution.canceled?
146
- contribution.cancel!
147
- if contribution.payment_choice.downcase == 'boletobancario'
148
- payment_notification.deliver_slip_canceled_notification
149
- end
150
- end
151
- end
152
- end
153
- end
154
- end
155
102
  end
156
103
  end
@@ -0,0 +1,73 @@
1
+ require 'enumerate_it'
2
+ require 'moip_transparente'
3
+
4
+ module CatarseMoip
5
+ class NotificationsController < ApplicationController
6
+ attr_accessor :payment
7
+
8
+ class TransactionStatus < ::EnumerateIt::Base
9
+ associate_values(
10
+ :authorized => 1,
11
+ :started => 2,
12
+ :printed_boleto => 3,
13
+ :finished => 4,
14
+ :canceled => 5,
15
+ :process => 6,
16
+ :written_back => 7,
17
+ :refunded => 9
18
+ )
19
+ end
20
+
21
+ skip_before_filter :force_http
22
+ layout :false
23
+
24
+ def create
25
+ process_moip_message
26
+ return render :nothing => true, :status => 200
27
+ rescue Exception => e
28
+ return render :text => "#{e.inspect}: #{e.message} recebemos: #{params}", :status => 422
29
+ end
30
+
31
+ def payment
32
+ @payment ||= PaymentEngines.find_payment key: params[:id_transacao]
33
+ end
34
+
35
+ def process_moip_message
36
+ payment.with_lock do
37
+ payment_notification = payment.payment_notifications.create({
38
+ contribution: payment.contribution,
39
+ extra_data: JSON.parse(
40
+ params.to_json.force_encoding('iso-8859-1').encode('utf-8'))
41
+ })
42
+
43
+ payment_id = (payment.gateway_id.gsub(".", "").to_i rescue 0)
44
+
45
+ if payment_id <= params[:cod_moip].to_i
46
+ payment.update_attributes payment_id: params[:cod_moip]
47
+
48
+ if (params[:valor].to_i/100.0) < payment.value && params[:valor]
49
+ #return payment.invalid! unless payment.invalid_payment?
50
+ return
51
+ end
52
+
53
+ case params[:status_pagamento].to_i
54
+ when TransactionStatus::PROCESS
55
+ payment_notification.deliver_process_notification
56
+ when TransactionStatus::AUTHORIZED, TransactionStatus::FINISHED
57
+ payment.pay! unless payment.paid?
58
+ when TransactionStatus::WRITTEN_BACK, TransactionStatus::REFUNDED
59
+ payment.refund! unless payment.refunded?
60
+ when TransactionStatus::CANCELED
61
+ unless payment.refused?
62
+ payment.refuse!
63
+ if payment.slip_payment?
64
+ payment_notification.deliver_slip_canceled_notification
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -5,15 +5,15 @@ module CatarseMoip
5
5
 
6
6
  base_uri ::MOIP_V2_ENDPOINT
7
7
 
8
- attr_accessor :contribution, :refund_options
8
+ attr_accessor :payment, :refund_options
9
9
 
10
- def self.start(contribution)
11
- _instance = new(contribution)
10
+ def self.start(payment)
11
+ _instance = new(payment)
12
12
  _instance.refund
13
13
  end
14
14
 
15
- def initialize(contribution)
16
- self.contribution = contribution
15
+ def initialize(payment)
16
+ self.payment = payment
17
17
  self.refund_options = define_refund_options
18
18
  end
19
19
 
@@ -66,7 +66,7 @@ module CatarseMoip
66
66
  end
67
67
 
68
68
  def bank_account
69
- self.contribution.user.bank_account
69
+ self.payment.user.bank_account
70
70
  end
71
71
 
72
72
  def bank_account_document_type
@@ -83,14 +83,14 @@ module CatarseMoip
83
83
 
84
84
  def amount_to_refund
85
85
  if already_expired_refund_deadline?
86
- ((self.contribution.value - self.contribution.payment_service_fee.to_f) * 100).to_i
86
+ ((self.payment.value - self.payment.gateway_fee.to_f) * 100).to_i
87
87
  else
88
- self.contribution.price_in_cents
88
+ (self.payment.value * 100).round
89
89
  end
90
90
  end
91
91
 
92
92
  def refund_method
93
- if already_expired_refund_deadline? || !self.contribution.is_credit_card?
93
+ if already_expired_refund_deadline? || !self.payment.is_credit_card?
94
94
  'BANK_ACCOUNT'
95
95
  else
96
96
  'CREDIT_CARD'
@@ -98,7 +98,7 @@ module CatarseMoip
98
98
  end
99
99
 
100
100
  def already_expired_refund_deadline?
101
- self.contribution.confirmed_at < 170.days.ago
101
+ self.payment.paid_at < 170.days.ago
102
102
  end
103
103
 
104
104
  def basic_auth_params
@@ -114,7 +114,7 @@ module CatarseMoip
114
114
  end
115
115
 
116
116
  def parsed_payment_id
117
- contribution.payment_id.gsub('.', '')
117
+ payment.gateway_id.gsub('.', '')
118
118
  end
119
119
  end
120
120
  end
@@ -1,7 +1,7 @@
1
1
  CatarseMoip::Engine.routes.draw do
2
2
  resources :moip, only: [], path: 'payment/moip' do
3
3
  collection do
4
- post 'notifications' => "moip#create_notification"
4
+ post 'notifications' => "notifications#create"
5
5
  get 'js'
6
6
  end
7
7
  member do
@@ -17,8 +17,8 @@ module CatarseMoip
17
17
  true
18
18
  end
19
19
 
20
- def direct_refund contribution
21
- ::CatarseMoip::V2::Refund.start(contribution)
20
+ def direct_refund payment
21
+ ::CatarseMoip::V2::Refund.start(payment)
22
22
  end
23
23
 
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module CatarseMoip
2
- VERSION = "3.1.1"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -50,166 +50,6 @@ describe CatarseMoip::MoipController do
50
50
  contribution.stub(:with_lock).and_yield
51
51
  end
52
52
 
53
- describe "POST create_notification" do
54
- describe "payment notifications" do
55
-
56
- context "when payment status is processing (6)" do
57
-
58
- let(:payment_notification) do
59
- pn = mock()
60
- pn.stub(:deliver_process_notification).and_return(true)
61
- pn
62
- end
63
-
64
- before do
65
- contribution.stub(:payment_id).and_return('123')
66
- contribution.stub(:update_attributes).and_return(true)
67
-
68
- payment_notification.should_receive(:deliver_process_notification)
69
- end
70
-
71
- it("should satisfy expectations") do
72
- post :create_notification, {:cod_moip => 125, :id_transacao => contribution.key, :use_route => 'catarse_moip', :status_pagamento => 6}
73
- end
74
- end
75
-
76
- context "when payment status is canceled and payment is made with Boleto" do
77
- let(:payment_notification) do
78
- pn = mock()
79
- pn.stub(:deliver_slip_canceled_notification).and_return(true)
80
- pn
81
- end
82
-
83
- context "when contribution is made with Boleto" do
84
- before do
85
- contribution.stub(:payment_choice).and_return('BoletoBancario')
86
- contribution.stub(:payment_id).and_return('123')
87
- contribution.stub(:update_attributes).and_return(true)
88
- end
89
-
90
- context "when is not canceled yet" do
91
- before do
92
- contribution.stub(:canceled?).and_return(false)
93
-
94
- payment_notification.should_receive(:deliver_slip_canceled_notification)
95
- end
96
-
97
- it("should satisfy expectations") do
98
- post :create_notification, {:cod_moip => 125, :id_transacao => contribution.key, :use_route => 'catarse_moip', :status_pagamento => 5}
99
- end
100
- end
101
-
102
- context "when is already canceled" do
103
- before do
104
- payment_notification.should_not_receive(:deliver_slip_canceled_notification)
105
- end
106
-
107
- it("should satisfy expectations") do
108
- post :create_notification, {:cod_moip => 125, :id_transacao => contribution.key, :use_route => 'catarse_moip', :status_pagamento => 5}
109
- end
110
- end
111
- end
112
- end
113
- end
114
-
115
- context "when we search for a non-existant contribution" do
116
- before do
117
- PaymentEngines.should_receive(:find_payment).with(key: "non-existant contribution key").and_raise('error')
118
- post :create_notification, {:id_transacao => "non-existant contribution key", :use_route => 'catarse_moip'}
119
- end
120
-
121
- its(:status){ should == 422 }
122
- its(:body){ should == "#<RuntimeError: error>: error recebemos: {\"id_transacao\"=>\"non-existant contribution key\", \"controller\"=>\"catarse_moip/moip\", \"action\"=>\"create_notification\"}" }
123
- end
124
-
125
- context "when we seach for an existing contribution" do
126
- before do
127
- controller.stub(:params).and_return({:id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification"})
128
- PaymentEngines.should_receive(:find_payment).with(key: contribution.key).and_return(contribution)
129
- controller.should_receive(:process_moip_message)
130
- post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
131
- end
132
-
133
- its(:body){ should == ' ' }
134
- its(:status){ should == 200 }
135
- it("should assign contribution"){ assigns(:contribution).should == contribution }
136
- end
137
-
138
- context "when receive ordered notification for contribution" do
139
- before do
140
- controller.stub(:params).and_return({:cod_moip => 125, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
141
- contribution.stub(:payment_id).and_return('123')
142
-
143
- controller.should_receive(:process_moip_message).and_call_original
144
- contribution.should_receive(:update_attributes).with(payment_id: 125)
145
- post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
146
- end
147
-
148
- its(:body){ should == ' ' }
149
- its(:status){ should == 200 }
150
- it("should assign contribution"){ assigns(:contribution).should == contribution }
151
- end
152
-
153
- context "when we receive a notification with the same payment id but with another status" do
154
- before do
155
- controller.stub(:params).and_return({:cod_moip => 123, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 1})
156
- contribution.stub(:payment_id).and_return('123')
157
-
158
- controller.should_receive(:process_moip_message).and_call_original
159
- contribution.should_receive(:update_attributes).with(payment_id: 123)
160
- post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
161
- end
162
-
163
- its(:body){ should == ' ' }
164
- its(:status){ should == 200 }
165
- it("should assign contribution"){ assigns(:contribution).should == contribution }
166
- end
167
-
168
- context "when receive a unordered notification for contribution" do
169
- before do
170
- controller.stub(:params).and_return({:cod_moip => 122, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
171
- contribution.stub(:payment_id).and_return('123')
172
-
173
- controller.should_receive(:process_moip_message).and_call_original
174
- contribution.should_not_receive(:update_attributes).with(payment_id: 122)
175
- post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
176
- end
177
-
178
- its(:body){ should == ' ' }
179
- its(:status){ should == 200 }
180
- it("should assign contribution"){ assigns(:contribution).should == contribution }
181
- end
182
-
183
- context "when contribution payment_method is PayPal" do
184
- before do
185
- controller.stub(:params).and_return({:cod_moip => 125, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
186
- contribution.stub(:payment_method).and_return('PayPal')
187
-
188
- controller.should_not_receive(:process_moip_message)
189
- post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
190
- end
191
-
192
- its(:body){ should == ' ' }
193
- its(:status){ should == 200 }
194
- it("should assign contribution"){ assigns(:contribution).should == contribution }
195
- end
196
-
197
- context "when contribution payment_id is null" do
198
- before do
199
- controller.stub(:params).and_return({:cod_moip => 122, :id_transacao =>contribution.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
200
- contribution.stub(:payment_id).and_return(nil)
201
-
202
- controller.should_receive(:process_moip_message).and_call_original
203
- contribution.should_receive(:update_attributes).with(payment_id: 122)
204
- post :create_notification, {:id_transacao => contribution.key, :use_route => 'catarse_moip'}
205
- end
206
-
207
- its(:body){ should == ' ' }
208
- its(:status){ should == 200 }
209
- it("should assign contribution"){ assigns(:contribution).should == contribution }
210
- end
211
- end
212
-
213
53
  describe "GET js" do
214
54
  let(:file){ double('js_file') }
215
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_moip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antônio Roberto Silva
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-03-02 00:00:00.000000000 Z
13
+ date: 2015-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -135,6 +135,7 @@ files:
135
135
  - app/assets/javascripts/catarse_moip/payment_slip.js
136
136
  - app/assets/javascripts/catarse_moip/user_document.js
137
137
  - app/controllers/catarse_moip/moip_controller.rb
138
+ - app/controllers/catarse_moip/notifications_controller.rb
138
139
  - app/models/catarse_moip/v2/refund.rb
139
140
  - app/views/catarse_moip/moip/_terms.html.slim
140
141
  - app/views/catarse_moip/moip/review.html.slim
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
216
  version: '0'
216
217
  requirements: []
217
218
  rubyforge_project:
218
- rubygems_version: 2.2.2
219
+ rubygems_version: 2.4.5
219
220
  signing_key:
220
221
  specification_version: 4
221
222
  summary: MoIP integration with Catarse