catarse_moip 1.0.1 → 1.0.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6298a7c73bdeb0c8eecca41f5082c44ff5c4215
|
4
|
+
data.tar.gz: 1c0b9f4b451fcef195c4db776e13217840dc220a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 638beedc099e89fbc18a4e0c3237cec1ba6ca8ac039413d2b658680c2b0ab83c8fc6b3283b32a73dfc4102a9dce9a0737b926b008566f091566f0de48ab22c5d
|
7
|
+
data.tar.gz: 974327feb4232b0537c41fb94574e9d38df88c59f5218acec4c2c746d5213b125ce7fbb6b831b6cc3bcf024c19280517f791072dab03336c13398fc176d97981
|
data/Gemfile.lock
CHANGED
@@ -22,7 +22,7 @@ module CatarseMoip
|
|
22
22
|
|
23
23
|
def create_notification
|
24
24
|
@backer = PaymentEngines.find_payment key: params[:id_transacao]
|
25
|
-
process_moip_message
|
25
|
+
process_moip_message
|
26
26
|
return render :nothing => true, :status => 200
|
27
27
|
rescue Exception => e
|
28
28
|
return render :text => "#{e.inspect}: #{e.message} recebemos: #{params}", :status => 422
|
@@ -46,7 +46,7 @@ module CatarseMoip
|
|
46
46
|
|
47
47
|
def moip_response
|
48
48
|
@backer = PaymentEngines.find_payment id: params[:id], user_id: current_user.id
|
49
|
-
|
49
|
+
first_update_backer params[:response] unless params[:response]['StatusPagamento'] == 'Falha'
|
50
50
|
render nothing: true, status: 200
|
51
51
|
end
|
52
52
|
|
@@ -88,37 +88,36 @@ module CatarseMoip
|
|
88
88
|
render json: { get_token_response: response, moip: @moip, widget_tag: @moip.widget_tag('checkoutSuccessful', 'checkoutFailure'), javascript_tag: @moip.javascript_tag }
|
89
89
|
end
|
90
90
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
params = params.first unless params.respond_to?(:key)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
if params
|
91
|
+
def first_update_backer
|
92
|
+
response = ::MoIP.query(backer.payment_token)
|
93
|
+
if response && response["Autorizacao"]
|
94
|
+
params = response["Autorizacao"]["Pagamento"]
|
95
|
+
params = params.first unless params.respond_to?(:key)
|
101
96
|
backer.update_attributes({
|
102
97
|
:payment_id => params["CodigoMoIP"],
|
103
98
|
:payment_choice => params["FormaPagamento"],
|
104
99
|
:payment_service_fee => params["TaxaMoIP"]
|
105
|
-
})
|
100
|
+
}) if params
|
106
101
|
end
|
107
102
|
end
|
108
103
|
|
109
|
-
def process_moip_message
|
104
|
+
def process_moip_message
|
110
105
|
PaymentEngines.create_payment_notification backer_id: backer.id, extra_data: JSON.parse(params.to_json.force_encoding('iso-8859-1').encode('utf-8'))
|
106
|
+
|
111
107
|
backer.with_lock do
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
108
|
+
if backer.payment_id.gsub(".", "").to_i < params[:cod_moip].to_i
|
109
|
+
backer.update_attributes payment_id: params[:cod_moip]
|
110
|
+
|
111
|
+
case params[:status_pagamento].to_i
|
112
|
+
when TransactionStatus::AUTHORIZED
|
113
|
+
backer.confirm! unless backer.confirmed?
|
114
|
+
when TransactionStatus::WRITTEN_BACK, TransactionStatus::REFUNDED
|
115
|
+
backer.refund! unless backer.refunded?
|
116
|
+
when TransactionStatus::CANCELED
|
117
|
+
backer.cancel! unless backer.canceled?
|
118
|
+
else
|
119
|
+
backer.waiting! if backer.pending?
|
120
|
+
end
|
122
121
|
end
|
123
122
|
end
|
124
123
|
end
|
data/lib/catarse_moip/version.rb
CHANGED
@@ -6,13 +6,13 @@ describe CatarseMoip::MoipController do
|
|
6
6
|
|
7
7
|
let(:get_token_response){{:status=>:fail, :code=>"171", :message=>"TelefoneFixo do endereço deverá ser enviado obrigatorio", :id=>"201210192052439150000024698931"}}
|
8
8
|
let(:backer){ double('backer', {
|
9
|
-
id: 1,
|
10
|
-
key: 'backer key',
|
11
|
-
payment_id: 'payment id',
|
12
|
-
project: project,
|
13
|
-
pending?: false,
|
14
|
-
value: 10,
|
15
|
-
user: user,
|
9
|
+
id: 1,
|
10
|
+
key: 'backer key',
|
11
|
+
payment_id: 'payment id',
|
12
|
+
project: project,
|
13
|
+
pending?: false,
|
14
|
+
value: 10,
|
15
|
+
user: user,
|
16
16
|
payer_name: 'foo',
|
17
17
|
payer_email: 'foo@bar.com',
|
18
18
|
address_street: 'test',
|
@@ -22,7 +22,13 @@ describe CatarseMoip::MoipController do
|
|
22
22
|
address_city: '123',
|
23
23
|
address_state: '123',
|
24
24
|
address_zip_code: '123',
|
25
|
-
address_phone_number: '123'
|
25
|
+
address_phone_number: '123',
|
26
|
+
confirmed?: true,
|
27
|
+
confirm!: true,
|
28
|
+
canceled?: true,
|
29
|
+
cancel!: true,
|
30
|
+
refunded?: true,
|
31
|
+
refund!: true
|
26
32
|
}) }
|
27
33
|
|
28
34
|
let(:user){ double('user', id: 1) }
|
@@ -53,8 +59,39 @@ describe CatarseMoip::MoipController do
|
|
53
59
|
|
54
60
|
context "when we seach for an existing backer" do
|
55
61
|
before do
|
62
|
+
controller.stub(:params).and_return({:id_transacao =>backer.key, :controller => "catarse_moip/moip", :action => "create_notification"})
|
56
63
|
PaymentEngines.should_receive(:find_payment).with(key: backer.key).and_return(backer)
|
57
|
-
controller.should_receive(:process_moip_message)
|
64
|
+
controller.should_receive(:process_moip_message)
|
65
|
+
post :create_notification, {:id_transacao => backer.key, :use_route => 'catarse_moip'}
|
66
|
+
end
|
67
|
+
|
68
|
+
its(:body){ should == ' ' }
|
69
|
+
its(:status){ should == 200 }
|
70
|
+
it("should assign backer"){ assigns(:backer).should == backer }
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when receive ordered notification for backer" do
|
74
|
+
before do
|
75
|
+
controller.stub(:params).and_return({:cod_moip => 125, :id_transacao =>backer.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
|
76
|
+
backer.stub(:payment_id).and_return('123')
|
77
|
+
|
78
|
+
controller.should_receive(:process_moip_message).and_call_original
|
79
|
+
backer.should_receive(:update_attributes).with(payment_id: 125)
|
80
|
+
post :create_notification, {:id_transacao => backer.key, :use_route => 'catarse_moip'}
|
81
|
+
end
|
82
|
+
|
83
|
+
its(:body){ should == ' ' }
|
84
|
+
its(:status){ should == 200 }
|
85
|
+
it("should assign backer"){ assigns(:backer).should == backer }
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when receive a unordered notification for backer" do
|
89
|
+
before do
|
90
|
+
controller.stub(:params).and_return({:cod_moip => 122, :id_transacao =>backer.key, :controller => "catarse_moip/moip", :action => "create_notification", :status_pagamento => 5})
|
91
|
+
backer.stub(:payment_id).and_return('123')
|
92
|
+
|
93
|
+
controller.should_receive(:process_moip_message).and_call_original
|
94
|
+
backer.should_not_receive(:update_attributes).with(payment_id: 122)
|
58
95
|
post :create_notification, {:id_transacao => backer.key, :use_route => 'catarse_moip'}
|
59
96
|
end
|
60
97
|
|
@@ -69,7 +106,7 @@ describe CatarseMoip::MoipController do
|
|
69
106
|
|
70
107
|
context "when the content of get_javascript_url raises an error" do
|
71
108
|
before do
|
72
|
-
controller.should_receive(:open).at_least(3).times.and_raise('error')
|
109
|
+
controller.should_receive(:open).at_least(3).times.and_raise('error')
|
73
110
|
->{
|
74
111
|
get :js, locale: :pt, use_route: 'catarse_moip'
|
75
112
|
}.should raise_error('error')
|
@@ -79,7 +116,7 @@ describe CatarseMoip::MoipController do
|
|
79
116
|
|
80
117
|
context "when the content of get_javascript_url is read without errors" do
|
81
118
|
before do
|
82
|
-
controller.should_receive(:open).and_return(file)
|
119
|
+
controller.should_receive(:open).and_return(file)
|
83
120
|
file.should_receive(:set_encoding).and_return(file)
|
84
121
|
file.should_receive(:read).and_return(file)
|
85
122
|
file.should_receive(:encode).and_return('js content')
|
@@ -93,7 +130,7 @@ describe CatarseMoip::MoipController do
|
|
93
130
|
describe "POST moip_response" do
|
94
131
|
let(:processor){ double('moip processor') }
|
95
132
|
before do
|
96
|
-
controller.should_receive(:
|
133
|
+
controller.should_receive(:first_update_backer)
|
97
134
|
post :moip_response, id: backer.id, response: {StatusPagamento: 'Sucesso'}, use_route: 'catarse_moip'
|
98
135
|
end
|
99
136
|
|
@@ -109,32 +146,19 @@ describe CatarseMoip::MoipController do
|
|
109
146
|
its(:body){ should == "{\"get_token_response\":{\"status\":\"fail\",\"code\":\"171\",\"message\":\"TelefoneFixo do endereço deverá ser enviado obrigatorio\",\"id\":\"201210192052439150000024698931\"},\"moip\":\"{}\",\"widget_tag\":\"<div id='MoipWidget'\\n data-token=''\\n callback-method-success='checkoutSuccessful' \\n callback-method-error='checkoutFailure'>\\n </div>\",\"javascript_tag\":\"<script type='text/javascript' src='https://www.moip.com.br/transparente/MoipWidget-v2.js' charset='ISO-8859-1'></script>\"}" }
|
110
147
|
end
|
111
148
|
|
112
|
-
describe "#
|
149
|
+
describe "#first_update_backer" do
|
113
150
|
before do
|
114
151
|
controller.stub(:backer).and_return(backer)
|
115
152
|
backer.stub(:payment_token).and_return('token')
|
116
153
|
end
|
117
154
|
|
118
|
-
context "with parameters containing CodigoMoIP and TaxaMoIP" do
|
119
|
-
let(:payment){ {"Status" => "Autorizado","Codigo" => "0","CodigoRetorno" => "0","TaxaMoIP" => "1.54","StatusPagamento" => "Sucesso","CodigoMoIP" => "18093844","Mensagem" => "Requisição processada com sucesso","TotalPago" => "25.00","url" => "https => //www.moip.com.br/Instrucao.do?token=R2W0N123E005F2A911V6O2I0Y3S7M4J853H0S0F0T0D044T8F4H4E9G0I3W8"} }
|
120
|
-
before do
|
121
|
-
MoIP.should_not_receive(:query)
|
122
|
-
backer.should_receive(:update_attributes).with({
|
123
|
-
payment_id: payment["CodigoMoIP"],
|
124
|
-
payment_choice: payment["FormaPagamento"],
|
125
|
-
payment_service_fee: payment["TaxaMoIP"]
|
126
|
-
})
|
127
|
-
end
|
128
|
-
it("should call update attributes but not call MoIP.query"){ controller.update_backer payment }
|
129
|
-
end
|
130
|
-
|
131
155
|
context "with no response from moip" do
|
132
156
|
let(:moip_query_response) { nil }
|
133
157
|
before do
|
134
158
|
MoIP.should_receive(:query).with(backer.payment_token).and_return(moip_query_response)
|
135
159
|
backer.should_not_receive(:update_attributes)
|
136
160
|
end
|
137
|
-
it("should never call update attributes"){ controller.
|
161
|
+
it("should never call update attributes"){ controller.first_update_backer }
|
138
162
|
end
|
139
163
|
|
140
164
|
context "with an incomplete transaction" do
|
@@ -145,7 +169,7 @@ describe CatarseMoip::MoipController do
|
|
145
169
|
MoIP.should_receive(:query).with(backer.payment_token).and_return(moip_query_response)
|
146
170
|
backer.should_not_receive(:update_attributes)
|
147
171
|
end
|
148
|
-
it("should never call update attributes"){ controller.
|
172
|
+
it("should never call update attributes"){ controller.first_update_backer }
|
149
173
|
end
|
150
174
|
|
151
175
|
context "with a real data set that works for some cases" do
|
@@ -161,7 +185,7 @@ describe CatarseMoip::MoipController do
|
|
161
185
|
payment_service_fee: payment["TaxaMoIP"]
|
162
186
|
})
|
163
187
|
end
|
164
|
-
it("should call update attributes"){ controller.
|
188
|
+
it("should call update attributes"){ controller.first_update_backer }
|
165
189
|
end
|
166
190
|
end
|
167
191
|
|
@@ -173,57 +197,41 @@ describe CatarseMoip::MoipController do
|
|
173
197
|
controller.stub(:update_backer)
|
174
198
|
end
|
175
199
|
|
176
|
-
context "when we already have the payment_id in backers table" do
|
177
|
-
before do
|
178
|
-
backer.stub(:payment_id).and_return('test')
|
179
|
-
controller.should_not_receive(:update_backer)
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'should never call update_backer' do
|
183
|
-
controller.process_moip_message post_moip_params.merge!({:id_transacao => backer.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::AUTHORIZED})
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context "when we still do not have the payment_id in backers table" do
|
188
|
-
before do
|
189
|
-
backer.stub(:payment_id).and_return(nil)
|
190
|
-
controller.should_receive(:update_backer)
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'should call update_backer on the processor' do
|
194
|
-
controller.process_moip_message post_moip_params.merge!({:id_transacao => backer.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::AUTHORIZED})
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
200
|
context "when there is a written back request and backer is not refunded" do
|
199
201
|
before do
|
202
|
+
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao => backer.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::WRITTEN_BACK}))
|
200
203
|
backer.stub(:refunded?).and_return(false)
|
201
204
|
backer.should_receive(:refund!)
|
205
|
+
backer.should_receive(:update_attributes)
|
202
206
|
end
|
203
207
|
|
204
208
|
it 'should call refund!' do
|
205
|
-
controller.process_moip_message
|
209
|
+
controller.process_moip_message
|
206
210
|
end
|
207
211
|
end
|
208
212
|
|
209
213
|
context "when there is an authorized request" do
|
210
214
|
before do
|
215
|
+
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao => backer.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::AUTHORIZED}))
|
211
216
|
backer.should_receive(:confirm!)
|
217
|
+
backer.should_receive(:update_attributes)
|
212
218
|
end
|
213
219
|
|
214
220
|
it 'should call confirm!' do
|
215
|
-
controller.process_moip_message
|
221
|
+
controller.process_moip_message
|
216
222
|
end
|
217
223
|
end
|
218
224
|
|
219
225
|
context "when there is a refund request" do
|
220
226
|
before do
|
227
|
+
controller.stub(:params).and_return(post_moip_params.merge!({:id_transacao => backer.key, :status_pagamento => CatarseMoip::MoipController::TransactionStatus::REFUNDED}))
|
221
228
|
backer.stub(:refunded?).and_return(false)
|
222
229
|
backer.should_receive(:refund!)
|
230
|
+
backer.should_receive(:update_attributes)
|
223
231
|
end
|
224
232
|
|
225
233
|
it 'should mark refunded to true' do
|
226
|
-
controller.process_moip_message
|
234
|
+
controller.process_moip_message
|
227
235
|
end
|
228
236
|
end
|
229
237
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2013-
|
13
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
185
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.0.
|
186
|
+
rubygems_version: 2.0.3
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
189
|
summary: MoIP integration with Catarse
|