punto_pagos_rails 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ require "rails_helper"
2
+
3
+ describe PaymentsController do
4
+ describe "#notification" do
5
+ let!(:transaction) { create(:transaction) }
6
+
7
+ before do
8
+ expect(PuntoPagosRails::TransactionService).to(
9
+ receive(:complete).and_return(true))
10
+ end
11
+
12
+ it "renders json response" do
13
+ get :notification, token: transaction.token
14
+ expect(response.status).to eq(200)
15
+ end
16
+ end
17
+ end
@@ -7,7 +7,7 @@ RSpec.describe TransactionService do
7
7
  let(:service) { TransactionService.new(ticket) }
8
8
  let(:request) { double }
9
9
  let(:response) { double }
10
- let(:token) { 'XXXXX' }
10
+ let(:token) { "XXXXX" }
11
11
  let(:payment_process_url) { double }
12
12
  let(:notification) { double }
13
13
  let(:status) { double }
@@ -59,8 +59,8 @@ RSpec.describe TransactionService do
59
59
  end
60
60
 
61
61
  it "fails with repeated token" do
62
- Transaction.create(token: 'REPEATED_TOKEN')
63
- allow(response).to receive(:get_token).and_return('REPEATED_TOKEN')
62
+ Transaction.create(token: "REPEATED_TOKEN")
63
+ allow(response).to receive(:get_token).and_return("REPEATED_TOKEN")
64
64
  expect(service.create).to eq(false)
65
65
  end
66
66
  end
@@ -99,54 +99,79 @@ RSpec.describe TransactionService do
99
99
  end
100
100
 
101
101
  describe "#notificate" do
102
- before do
103
- allow(PuntoPagos::Notification).to receive(:new).and_return(notification)
104
- allow(notification).to receive(:valid?).with({}, {}).and_return(true)
105
- allow(PuntoPagosRails::Transaction).to receive(:find_by_token).and_return(transaction)
106
- end
102
+ let(:params) { { token: transaction.token } }
103
+ before { allow(PuntoPagos::Notification).to receive(:new).and_return(notification) }
107
104
 
108
- it "creates a notification" do
109
- TransactionService.notificate({}, {})
110
- expect(PuntoPagos::Notification).to have_received(:new)
111
- end
105
+ context "with valid notification" do
106
+ before { allow(notification).to receive(:valid?).with({}, params).and_return(true) }
112
107
 
113
- context "when the notification is valid" do
114
- it "the notification is completed" do
115
- TransactionService.notificate({}, {})
116
- expect(transaction.reload.state).to eq('completed')
108
+ it "completes transaction" do
109
+ expect(TransactionService.notificate(params, {})).to eq(
110
+ respuesta: "99", token: transaction.token)
111
+ expect(transaction.reload.state).to eq("completed")
117
112
  end
118
- end
119
113
 
120
- context "when the notification is invalid" do
121
- before do
122
- allow(notification).to receive(:valid?).with({}, {}).and_return(false)
123
- TransactionService.notificate({}, {})
114
+ context "when notification is completed" do
115
+ before { transaction.update_column(:state, "completed") }
116
+
117
+ it "does not change status" do
118
+ TransactionService.notificate(params, {})
119
+ expect(transaction.reload.state).to eq("completed")
120
+ end
124
121
  end
125
122
 
126
- it "the notification is rejected" do
127
- expect(transaction.reload.state).to eq('rejected')
123
+ context "when notification is rejected" do
124
+ before { transaction.update_column(:state, "rejected") }
125
+
126
+ it "does not change status" do
127
+ TransactionService.notificate(params, {})
128
+ expect(transaction.reload.state).to eq("rejected")
129
+ end
128
130
  end
129
131
  end
130
132
 
131
- context "when the notification is completed" do
133
+ context "with invalid notification" do
132
134
  before do
133
- transaction.update_column :state, 'completed'
135
+ params[:error] = "error!"
136
+ allow(notification).to receive(:valid?).with({}, params).and_return(false)
134
137
  end
135
138
 
136
- it "should not be rejectable" do
137
- TransactionService.notificate({}, {})
138
- expect(transaction.reload.state).to_not eq('rejected')
139
+ it "rejects the transaction" do
140
+ expect(TransactionService.notificate(params, {})).to eq(
141
+ respuesta: "00", error: params[:error], token: transaction.token)
142
+ expect(transaction.reload.state).to eq("rejected")
143
+ expect(transaction.error).to eq(params[:error])
144
+ end
145
+ end
146
+ end
147
+
148
+ describe "#complete" do
149
+ let(:params) { { token: transaction.token } }
150
+ before do
151
+ allow(PuntoPagos::Status).to receive(:new).and_return(status)
152
+ allow(status).to receive(:check).with(
153
+ transaction.token, transaction.id.to_s, transaction.amount_to_s).and_return(true)
154
+ end
155
+
156
+ context "with valid status" do
157
+ before { allow(status).to receive(:valid?).and_return(true) }
158
+
159
+ it "completes transaction" do
160
+ expect(TransactionService.complete(params)).to be_truthy
161
+ expect(transaction.reload.state).to eq("completed")
139
162
  end
140
163
  end
141
164
 
142
- context "when the notification is rejected" do
165
+ context "with invalid status" do
143
166
  before do
144
- transaction.update_column :state, 'rejected'
167
+ allow(status).to receive(:valid?).and_return(false)
168
+ allow(status).to receive(:error).and_return("error")
145
169
  end
146
170
 
147
- it "should not be completable" do
148
- TransactionService.notificate({}, {})
149
- expect(transaction.reload.state).to_not eq('completed')
171
+ it "completes transaction" do
172
+ expect(TransactionService.complete(params)).to be_truthy
173
+ expect(transaction.reload.state).to eq("rejected")
174
+ expect(transaction.error).to eq("error")
150
175
  end
151
176
  end
152
177
  end
@@ -0,0 +1 @@
1
+ "%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
@@ -0,0 +1,2 @@
1
+ "%�b
2
+ �秐��@�o� Ep��� Ext���)T
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punto_pagos_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Segovia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-08 00:00:00.000000000 Z
11
+ date: 2016-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -188,11 +188,14 @@ files:
188
188
  - spec/dummy/app/assets/stylesheets/application.css
189
189
  - spec/dummy/app/controllers/application_controller.rb
190
190
  - spec/dummy/app/controllers/home_controller.rb
191
+ - spec/dummy/app/controllers/payments_controller.rb
191
192
  - spec/dummy/app/controllers/transactions_controller.rb
192
193
  - spec/dummy/app/helpers/application_helper.rb
193
194
  - spec/dummy/app/models/ticket.rb
194
195
  - spec/dummy/app/views/home/index.html.erb
195
196
  - spec/dummy/app/views/layouts/application.html.erb
197
+ - spec/dummy/app/views/payments/error.html.erb
198
+ - spec/dummy/app/views/payments/success.html.erb
196
199
  - spec/dummy/app/views/transactions/error.html.erb
197
200
  - spec/dummy/app/views/transactions/success.html.erb
198
201
  - spec/dummy/bin/bundle
@@ -229,6 +232,7 @@ files:
229
232
  - spec/dummy/public/422.html
230
233
  - spec/dummy/public/500.html
231
234
  - spec/dummy/public/favicon.ico
235
+ - spec/dummy/spec/controllers/payments_controller_spec.rb
232
236
  - spec/dummy/spec/controllers/transactions_controller_spec.rb
233
237
  - spec/dummy/spec/lib/punto_pagos_rails/transaction_service_spec.rb
234
238
  - spec/dummy/spec/models/punto_pagos_rails/transaction_spec.rb
@@ -295,6 +299,7 @@ files:
295
299
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/AP/AP0_3b5N2aJWVyyANhjLMP7qdpczG_C1lo6AtzELoyU.cache
296
300
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/EN/EN1sgFDBtOLV_nTM5QCygjXFjJjrCwASL91R_jbxJqo.cache
297
301
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/EN/eNStu73G536x1iNq9tePGM6hv5Xa6-5ZsXtfJuiDtfE.cache
302
+ - spec/dummy/tmp/cache/assets/sprockets/v3.0/Ey/EyWfRmUYoL59k_CqjDAePaOgc1OCqcTmsjJpanercg4.cache
298
303
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/Fi/FiuTIVrQEp_PZDI6AFR7KQkoUtnCXkFVKyr2aSzCINI.cache
299
304
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/HG/HGWuC1XP4qTav8SMCTMvqubfgC1g-BXJH6zXci4WaI8.cache
300
305
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/HT/HT55sL83KvJ-NRz9pru5aQzroueKzMMnMEah6E7MAvY.cache
@@ -334,6 +339,7 @@ files:
334
339
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/uJ/uJSI3kUSsbjut4Cwj7WrhGwwnEB1vCd3Pe2fbI5SU4k.cache
335
340
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/un/un4CV9-W0TLVlFJFc3m-r9KEyxaymOlHKKpGpPOn37s.cache
336
341
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/w_/w_v89Lo_bpb8aAsrFe9y5cBhNobVJ6MwvJqav7plorY.cache
342
+ - spec/dummy/tmp/cache/assets/sprockets/v3.0/wt/wt38OlyCBzCYjWbwhzKkVlJAD3_tIepF8hxEzJkiXB4.cache
337
343
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/xU/xU8kTXBeW6eLfp_eNY6xEEideoQNSHIMC9yQ-P1OPO8.cache
338
344
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/y8/y8u-QuBe2neNMwhZPDIz3ZE5FqNjBEux-ttpcsU9Qxc.cache
339
345
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/yh/yhC-Cty2J5UucXyvUWMfhQRgloZBt67FS7bSQpo7MMk.cache
@@ -371,11 +377,14 @@ test_files:
371
377
  - spec/dummy/app/assets/stylesheets/application.css
372
378
  - spec/dummy/app/controllers/application_controller.rb
373
379
  - spec/dummy/app/controllers/home_controller.rb
380
+ - spec/dummy/app/controllers/payments_controller.rb
374
381
  - spec/dummy/app/controllers/transactions_controller.rb
375
382
  - spec/dummy/app/helpers/application_helper.rb
376
383
  - spec/dummy/app/models/ticket.rb
377
384
  - spec/dummy/app/views/home/index.html.erb
378
385
  - spec/dummy/app/views/layouts/application.html.erb
386
+ - spec/dummy/app/views/payments/error.html.erb
387
+ - spec/dummy/app/views/payments/success.html.erb
379
388
  - spec/dummy/app/views/transactions/error.html.erb
380
389
  - spec/dummy/app/views/transactions/success.html.erb
381
390
  - spec/dummy/bin/bundle
@@ -414,6 +423,7 @@ test_files:
414
423
  - spec/dummy/public/favicon.ico
415
424
  - spec/dummy/Rakefile
416
425
  - spec/dummy/README.rdoc
426
+ - spec/dummy/spec/controllers/payments_controller_spec.rb
417
427
  - spec/dummy/spec/controllers/transactions_controller_spec.rb
418
428
  - spec/dummy/spec/lib/punto_pagos_rails/transaction_service_spec.rb
419
429
  - spec/dummy/spec/models/punto_pagos_rails/transaction_spec.rb
@@ -484,6 +494,7 @@ test_files:
484
494
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/EN/EN1sgFDBtOLV_nTM5QCygjXFjJjrCwASL91R_jbxJqo.cache
485
495
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/EN/eNStu73G536x1iNq9tePGM6hv5Xa6-5ZsXtfJuiDtfE.cache
486
496
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/es/esYVHbG7qL7AKN3EPN_UFicQM3c0WTcTjqjDGibdz-Y.cache
497
+ - spec/dummy/tmp/cache/assets/sprockets/v3.0/Ey/EyWfRmUYoL59k_CqjDAePaOgc1OCqcTmsjJpanercg4.cache
487
498
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/Fi/FiuTIVrQEp_PZDI6AFR7KQkoUtnCXkFVKyr2aSzCINI.cache
488
499
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/HG/HGWuC1XP4qTav8SMCTMvqubfgC1g-BXJH6zXci4WaI8.cache
489
500
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/hj/hj8Ir9wcVSy1KYrnWu9bpD24vDhCG3tvt-nKbNxb1Wg.cache
@@ -518,6 +529,7 @@ test_files:
518
529
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/VR/VRC0qpQ2CiJgNEMvtXOvEDluwkaoomyJeAm7Unfrcr0.cache
519
530
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/VY/VYpuh0Ag6L55xqqNJ1mGLQVvGlNNH50DN6HApLtiRSk.cache
520
531
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/w_/w_v89Lo_bpb8aAsrFe9y5cBhNobVJ6MwvJqav7plorY.cache
532
+ - spec/dummy/tmp/cache/assets/sprockets/v3.0/wt/wt38OlyCBzCYjWbwhzKkVlJAD3_tIepF8hxEzJkiXB4.cache
521
533
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/X7/X7YQ6EHE68K2fFs0F2XPWazA8x8qVSZuaaYjKvgRj7w.cache
522
534
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/xU/xU8kTXBeW6eLfp_eNY6xEEideoQNSHIMC9yQ-P1OPO8.cache
523
535
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/y8/y8u-QuBe2neNMwhZPDIz3ZE5FqNjBEux-ttpcsU9Qxc.cache