pagseguro-transparente 0.1.1 → 0.1.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: 46c48e033101e088eac0919e399bb95a04191f39
4
- data.tar.gz: 4103d9ed90670ac93d064a2fede0a3fd0607c0ce
3
+ metadata.gz: e047eff0614910990e6b5a617a6642013fc4d532
4
+ data.tar.gz: 58d06eae167cbdc8dc6b98b4361dd0a2025ab905
5
5
  SHA512:
6
- metadata.gz: a17ae59afdb86543e8bc8b7731105f4fa07c00cebaa1720e749c6c6d4dacf062660dd8f48adb578ace232bde70ae77f9d90c7cce1cbc3cb53ccbbb363e4942fd
7
- data.tar.gz: 779c5ad5e9ab57a39610dcd23b1fe0b09d849d03c8df556eb809d01f590bdf2b01fec195a51d6b350aebc08336e9a2bdf128c85c3a5d41a05db33a83ee338d86
6
+ metadata.gz: d0c88537b0ca25fe5f29ed26180c9affbc0c9125255a2b965102e66b01d1e9c2ef3bba0792a956f0036ebe09fbb0a9782742aab33eaea9927db5d4a3a172080a
7
+ data.tar.gz: b286ba420bea57acb1e77ef9047f42165116e35af80f58418bfa06235f81c3b1fd7aaf6b341401e5566f0070310b0b6abc99c7926ec3558ec6c9616b8e43202d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagseguro-transparente (0.1.0)
4
+ pagseguro-transparente (0.1.2)
5
5
  activemodel
6
6
  httparty (~> 0.13)
7
7
  i18n (~> 0.6)
data/lib/pagseguro.rb CHANGED
@@ -26,6 +26,7 @@ require "pagseguro/holder"
26
26
  require "pagseguro/address"
27
27
  require "pagseguro/shipping"
28
28
  require "pagseguro/installment"
29
+ require "pagseguro/refund"
29
30
 
30
31
  I18n.enforce_available_locales = false
31
32
  I18n.load_path += Dir[File.expand_path('../../config/locales/*.yml', __FILE__)]
@@ -66,7 +66,7 @@ module PagSeguro
66
66
  # Calls the PagSeguro web service and register this request for payment.
67
67
  def transaction
68
68
  params = Serializer.new(self).to_params
69
- PagSeguro::Transaction.new post('/transactions', params)
69
+ PagSeguro::Transaction.new post('/transactions', params).parsed_response
70
70
  end
71
71
 
72
72
  def initialize(options = {})
@@ -0,0 +1,30 @@
1
+ module PagSeguro
2
+ class Refund < Request
3
+ attr_accessor :request
4
+
5
+ def initialize(transaction_code)
6
+ @transaction_code = transaction_code
7
+ @request = {}
8
+ end
9
+
10
+ def request
11
+ @request = post("/transactions/refunds", transactionCode: @transaction_code)
12
+
13
+ @request.response.code == '200'
14
+ end
15
+
16
+ def errors
17
+ case @request.response.code
18
+ when '400'
19
+ errors = @request.parsed_response
20
+ [errors['errors']['error']].flatten
21
+ when '200'
22
+ []
23
+ when '403'
24
+ [{'code' => '403', 'message' => 'Forbidden'}]
25
+ else
26
+ [{'code' => @request.response.code.to_s, 'message' => 'Unkown Error'}]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -19,8 +19,7 @@ module PagSeguro
19
19
  def post(path, params = {})
20
20
  options = add_credencials(params)
21
21
 
22
- response = self.class.post(path, options)
23
- response.parsed_response
22
+ self.class.post(path, options)
24
23
  end
25
24
 
26
25
  private
@@ -1,7 +1,7 @@
1
1
  module PagSeguro
2
2
  class Session < Request
3
3
  def create
4
- Response.new post('/sessions')
4
+ Response.new post('/sessions').parsed_response
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module PagSeguro
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -5,8 +5,8 @@ Gem::Specification.new do |spec|
5
5
  spec.required_ruby_version = ">= 1.9.3"
6
6
  spec.name = "pagseguro-transparente"
7
7
  spec.version = PagSeguro::VERSION
8
- spec.authors = ["Cirdes Henrique"]
9
- spec.email = ["cirdes@gmail.com"]
8
+ spec.authors = ["Cirdes Henrique", "Bruno Luigi"]
9
+ spec.email = ["cirdes@gmail.com", "bruno.luigi@gmail.com"]
10
10
  spec.description = "Integração com o novo checkout transparente do Pagseguro."
11
11
  spec.summary = spec.description
12
12
  spec.homepage = "https://github.com/eventick/pagseguro-transparente"
@@ -0,0 +1,102 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Refund do
4
+ let(:transactionCode) { '766B9C-AD4B044B04DA-77742F5FA653-E1AB24' }
5
+
6
+ subject(:refund) { PagSeguro::Refund.new(transactionCode) }
7
+
8
+ it { should respond_to(:request) }
9
+ it { should respond_to(:errors) }
10
+
11
+ before do
12
+ PagSeguro.email = 'mail'
13
+ PagSeguro.token = 'token'
14
+ end
15
+
16
+ describe "#request" do
17
+
18
+ let(:refund) { PagSeguro::Refund.new(transactionCode) }
19
+
20
+ context "successful refund" do
21
+ subject { refund.request }
22
+
23
+ before do
24
+ stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/transactions/refunds").
25
+ with(:body => "email=mail&token=token&transactionCode=766B9C-AD4B044B04DA-77742F5FA653-E1AB24").
26
+ to_return(:status => 200, :body => "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?> <result>OK</result>", :headers => {'Content-Type' => 'application/xml;charset=ISO-8859-1'})
27
+ end
28
+
29
+ it { expect(subject).to be_true }
30
+ end
31
+
32
+ context "unsuccessfull refund" do
33
+ let(:single_error) { "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?><errors><error><code>14006</code><message>insufficient balance to refund transaction.</message></error></errors>" }
34
+ let(:multiple_errors) { "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?><errors><error><code>14006</code><message>insufficient balance to refund transaction.</message></error><error><code>14007</code><message>invalid transaction status to refund.</message></error></errors>" }
35
+ let(:xml_response) { }
36
+
37
+ before do
38
+ stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/transactions/refunds").
39
+ with(:body => "email=mail&token=token&transactionCode=766B9C-AD4B044B04DA-77742F5FA653-E1AB24").
40
+ to_return(:status => 400, :body => xml_response, :headers => {'Content-Type' => 'application/xml;charset=ISO-8859-1'})
41
+ end
42
+
43
+ context "single error" do
44
+ let(:xml_response) { single_error }
45
+
46
+ context "request return" do
47
+ subject { refund.request }
48
+
49
+ it { expect(subject).to be_false }
50
+ end
51
+
52
+ context "error format" do
53
+ before { refund.request }
54
+ subject { refund.errors }
55
+
56
+ it { expect(subject).to eq [ { "code" => "14006", "message" => "insufficient balance to refund transaction."} ] }
57
+ end
58
+ end
59
+
60
+ context "various errors" do
61
+ let(:xml_response) { multiple_errors }
62
+
63
+ context "request return" do
64
+ subject { refund.request }
65
+
66
+ it { expect(subject).to be_false }
67
+ end
68
+
69
+ context "error format" do
70
+ before { refund.request }
71
+ subject { refund.errors }
72
+
73
+ it { expect(refund.errors).to eq [ { "code" => "14006", "message" => "insufficient balance to refund transaction."}, { "code" => "14007", "message" => "invalid transaction status to refund."} ] }
74
+ end
75
+ end
76
+ end
77
+
78
+ context "unexpected response" do
79
+ subject { refund.errors }
80
+
81
+ before do
82
+ stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/transactions/refunds").
83
+ with(:body => "email=mail&token=token&transactionCode=766B9C-AD4B044B04DA-77742F5FA653-E1AB24").
84
+ to_return(:status => status, :body => "")
85
+ end
86
+
87
+ before { refund.request }
88
+
89
+ context '403 Forbbiden' do
90
+ let(:status) { 403 }
91
+
92
+ it { expect(refund.errors).to eq [ { "code" => "403", "message" => "Forbidden"} ] }
93
+ end
94
+
95
+ context '401 Unauthorized' do
96
+ let(:status) { 401 }
97
+
98
+ it { expect(refund.errors).to eq [ { "code" => "401", "message" => "Unkown Error"} ] }
99
+ end
100
+ end
101
+ end
102
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro-transparente
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cirdes Henrique
8
+ - Bruno Luigi
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-07-07 00:00:00.000000000 Z
12
+ date: 2014-07-15 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activemodel
@@ -181,6 +182,7 @@ dependencies:
181
182
  description: Integração com o novo checkout transparente do Pagseguro.
182
183
  email:
183
184
  - cirdes@gmail.com
185
+ - bruno.luigi@gmail.com
184
186
  executables: []
185
187
  extensions: []
186
188
  extra_rdoc_files: []
@@ -209,6 +211,7 @@ files:
209
211
  - lib/pagseguro/payment/serializer.rb
210
212
  - lib/pagseguro/phone.rb
211
213
  - lib/pagseguro/query.rb
214
+ - lib/pagseguro/refund.rb
212
215
  - lib/pagseguro/request.rb
213
216
  - lib/pagseguro/sender.rb
214
217
  - lib/pagseguro/session.rb
@@ -238,6 +241,7 @@ files:
238
241
  - spec/pagseguro/payment_spec.rb
239
242
  - spec/pagseguro/phone_spec.rb
240
243
  - spec/pagseguro/query_spec.rb
244
+ - spec/pagseguro/refund_spec.rb
241
245
  - spec/pagseguro/sender_spec.rb
242
246
  - spec/pagseguro/session/response_spec.rb
243
247
  - spec/pagseguro/session_spec.rb
@@ -290,6 +294,7 @@ test_files:
290
294
  - spec/pagseguro/payment_spec.rb
291
295
  - spec/pagseguro/phone_spec.rb
292
296
  - spec/pagseguro/query_spec.rb
297
+ - spec/pagseguro/refund_spec.rb
293
298
  - spec/pagseguro/sender_spec.rb
294
299
  - spec/pagseguro/session/response_spec.rb
295
300
  - spec/pagseguro/session_spec.rb