pagseguro-oficial 2.0.7 → 2.0.8

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: b0050b2e944dc6682bd9f7df9132100ca1ee4358
4
- data.tar.gz: 2b7d750c8adabea028fad019a1bebe11ecbc42d5
3
+ metadata.gz: e774d4d23c27502385d14f5e9bc90ada28317325
4
+ data.tar.gz: 6000c710d322c4faae2c4d95d0b3a03c34045d2e
5
5
  SHA512:
6
- metadata.gz: df2981bdb81aa06ec264e84ab5e74bc4779327b5e66147734346556a22d490ac0d383f735a5e8acc0e2139d2d7109f3d713881fff0a0c5d4bd467fcd6952a0b8
7
- data.tar.gz: 098b3b8a5dee04b6961f0057c3e8bfe42ebdc5ff5d330ba32951f7990f3cbdea19540567805bd84e7dc84a6deb1a11672a9a9c68fa1c3e62939651bc93f6ca4d
6
+ metadata.gz: fd59c649d168459fb7864fb2a30c34a3ef381c3355c7ff4455058f20b37905447a7f5095bc1e17e775d2d5f340a15a27cc21c3052d853f57dad85c004a01f80f
7
+ data.tar.gz: ef3e534a97d8e8486f44099d80f82f76c2f14c05303aee1a2ffe3456df4f8cfb0025ede3b50ce68aa7128e564004950dfd41821326a1dfb10ad34dc5cea01a19
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Next release - 2.0.8
2
+
3
+ - Consulta de opções de parcelamento
4
+
1
5
  ## Next release - 2.0.7
2
6
 
3
7
  - Suporte para adicionar parâmetros dinamicamente na criação de requisições de pagamentos (isso possibilita a utilização de parâmetros da api que ainda não foram mapeados na gem)
data/README.md CHANGED
@@ -12,6 +12,7 @@ A biblioteca PagSeguro em Ruby é um conjunto de classes de domínio que facilit
12
12
  - Consultar [transações por código]
13
13
  - Consultar [transações por intervalo de datas]
14
14
  - Consultar [transações abandonadas]
15
+ - Consultar opções de parcelamento
15
16
  - Receber [notificações]
16
17
 
17
18
 
@@ -26,7 +27,7 @@ A biblioteca PagSeguro em Ruby é um conjunto de classes de domínio que facilit
26
27
  - Adicione a biblioteca ao seu Gemfile.
27
28
 
28
29
  ```ruby
29
- gem "pagseguro-oficial", git: "git://github.com/pagseguro/ruby.git"
30
+ gem "pagseguro-oficial", "~> 2.0.8"
30
31
  ```
31
32
 
32
33
  - Execute o comando `bundle install`.
@@ -177,6 +178,29 @@ while report.next_page?
177
178
  end
178
179
  ```
179
180
 
181
+ ### Consultar opções de parcelamento
182
+
183
+ Você pode consultar as opções de parcelamento para um determinado valor.
184
+
185
+ ```ruby
186
+ installments = PagSeguro::Installment.find("100.00")
187
+
188
+ puts "=> INSTALLMENTS"
189
+ puts
190
+ installments.each do |installment|
191
+ puts installment.inspect
192
+ end
193
+
194
+ visa_installments = PagSeguro::Installment.find("100.00", "visa")
195
+
196
+ puts
197
+ puts "=> VISA INSTALLMENTS"
198
+ puts
199
+ visa_installments.each do |installment|
200
+ puts installment.inspect
201
+ end
202
+ ```
203
+
180
204
  ## API
181
205
 
182
206
  ### PagSeguro::PaymentRequest
@@ -0,0 +1,19 @@
1
+ require_relative "boot"
2
+
3
+ installments = PagSeguro::Installment.find("100.00")
4
+
5
+ puts "=> INSTALLMENTS"
6
+ puts
7
+ installments.each do |installment|
8
+ puts installment.inspect
9
+ end
10
+
11
+
12
+ visa_installments = PagSeguro::Installment.find("100.00", "visa")
13
+
14
+ puts
15
+ puts "=> VISA INSTALLMENTS"
16
+ puts
17
+ visa_installments.each do |installment|
18
+ puts installment.inspect
19
+ end
data/lib/pagseguro.rb CHANGED
@@ -15,6 +15,9 @@ require "pagseguro/extensions/ensure_type"
15
15
  require "pagseguro/address"
16
16
  require "pagseguro/shipping"
17
17
  require "pagseguro/phone"
18
+ require "pagseguro/installment"
19
+ require "pagseguro/installment/response"
20
+ require "pagseguro/installment/serializer"
18
21
  require "pagseguro/item"
19
22
  require "pagseguro/items"
20
23
  require "pagseguro/payment_method"
@@ -0,0 +1,46 @@
1
+ module PagSeguro
2
+ class Installment
3
+ include Extensions::MassAssignment
4
+
5
+ # Set the credit card brand.
6
+ attr_accessor :card_brand
7
+
8
+ # Set the installments quantity.
9
+ attr_accessor :quantity
10
+
11
+ # Set the amount.
12
+ # Must fit the patern: \\d+.\\d{2} (e.g. "12.00")
13
+ attr_accessor :amount
14
+
15
+ # Set total amount.
16
+ attr_accessor :total_amount
17
+
18
+ # Set interest free.
19
+ attr_accessor :interest_free
20
+
21
+ # Find installment options by a given amount
22
+ # Optional. Credit card brand
23
+ # Return an Array of PagSeguro::Installment instances
24
+ def self.find(amount, card_brand = nil)
25
+ string = "installments?amount=#{amount}"
26
+ string += "&cardBrand=#{card_brand}" if card_brand
27
+ load_from_response Request.get(string)
28
+ end
29
+
30
+ # Serialize the HTTP response into data.
31
+ def self.load_from_response(response) # :nodoc:
32
+ if response.success? and response.xml?
33
+ Nokogiri::XML(response.body).css("installments > installment").map do |node|
34
+ load_from_xml(node)
35
+ end
36
+ else
37
+ Response.new Errors.new(response)
38
+ end
39
+ end
40
+
41
+ # Serialize the XML object.
42
+ def self.load_from_xml(xml) # :nodoc:
43
+ new Serializer.new(xml).serialize
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,12 @@
1
+ module PagSeguro
2
+ class Installment
3
+ class Response
4
+ # Set the response errors.
5
+ attr_reader :errors
6
+
7
+ def initialize(errors = Errors.new)
8
+ @errors = errors
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ module PagSeguro
2
+ class Installment
3
+ class Serializer
4
+ # The installment that will be serialized
5
+ attr_reader :xml
6
+
7
+ def initialize(xml)
8
+ @xml = xml
9
+ end
10
+
11
+ def serialize
12
+ {}.tap do |data|
13
+ data[:card_brand] = xml.css("cardBrand").text
14
+ data[:quantity] = xml.css("quantity").text
15
+ data[:amount] = xml.css("amount").text
16
+ data[:total_amount] = xml.css("totalAmount").text
17
+ data[:interest_free] = xml.css("interestFree").text
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module PagSeguro
2
- VERSION = "2.0.7"
2
+ VERSION = "2.0.8"
3
3
  end
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <installments>
3
+ <installment>
4
+ <cardBrand>visa</cardBrand>
5
+ <quantity>1</quantity>
6
+ <amount>500.00</amount>
7
+ <totalAmount>500.00</totalAmount>
8
+ <interestFree>true</interestFree>
9
+ </installment>
10
+ <installment>
11
+ <cardBrand>visa</cardBrand>
12
+ <quantity>2</quantity>
13
+ <amount>261.28</amount>
14
+ <totalAmount>522.55</totalAmount>
15
+ <interestFree>false</interestFree>
16
+ </installment>
17
+ <installment>
18
+ <cardBrand>visa</cardBrand>
19
+ <quantity>3</quantity>
20
+ <amount>176.73</amount>
21
+ <totalAmount>530.20</totalAmount>
22
+ <interestFree>false</interestFree>
23
+ </installment>
24
+ </installments>
@@ -4,4 +4,4 @@
4
4
  <code>11024</code>
5
5
  <message>Items invalid quantity.</message>
6
6
  </error>
7
- </errors>
7
+ </errors>
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Installment::Serializer do
4
+ context "when there are installments" do
5
+ let(:source) { File.read("./spec/fixtures/installment/success.xml") }
6
+ let(:xml) { Nokogiri::XML(source) }
7
+ subject(:data) do
8
+ xml.css("installments > installment").map do |xml|
9
+ described_class.new(xml).serialize
10
+ end
11
+ end
12
+
13
+ it { expect(data.size).to eq(3) }
14
+
15
+ it { expect(data[0]).to include(card_brand: "visa") }
16
+ it { expect(data[0]).to include(quantity: "1") }
17
+ it { expect(data[0]).to include(amount: "500.00") }
18
+ it { expect(data[0]).to include(total_amount: "500.00") }
19
+ it { expect(data[0]).to include(interest_free: "true") }
20
+
21
+ it { expect(data[1]).to include(card_brand: "visa") }
22
+ it { expect(data[1]).to include(quantity: "2") }
23
+ it { expect(data[1]).to include(amount: "261.28") }
24
+ it { expect(data[1]).to include(total_amount: "522.55") }
25
+ it { expect(data[1]).to include(interest_free: "false") }
26
+
27
+ it { expect(data[2]).to include(card_brand: "visa") }
28
+ it { expect(data[2]).to include(quantity: "3") }
29
+ it { expect(data[2]).to include(amount: "176.73") }
30
+ it { expect(data[2]).to include(total_amount: "530.20") }
31
+ it { expect(data[2]).to include(interest_free: "false") }
32
+ end
33
+ end
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Installment do
4
+ it_assigns_attribute :card_brand
5
+ it_assigns_attribute :quantity
6
+ it_assigns_attribute :amount
7
+ it_assigns_attribute :total_amount
8
+ it_assigns_attribute :interest_free
9
+
10
+ describe ".find" do
11
+ context "when request succeeds" do
12
+ let(:request) { double("request") }
13
+
14
+ it "finds installments by the given amount" do
15
+ expect(PagSeguro::Request).to receive(:get)
16
+ .with("installments?amount=100.00")
17
+ .and_return(request)
18
+ expect(PagSeguro::Installment).to receive(:load_from_response)
19
+ .with(request)
20
+
21
+ PagSeguro::Installment.find("100.00")
22
+ end
23
+
24
+ it "find installments by amount and credit card brand" do
25
+ expect(PagSeguro::Request).to receive(:get)
26
+ .with("installments?amount=100.00&cardBrand=visa")
27
+ .and_return(request)
28
+ expect(PagSeguro::Installment).to receive(:load_from_response)
29
+ .with(request)
30
+
31
+ PagSeguro::Installment.find("100.00", :visa)
32
+ end
33
+ end
34
+
35
+ context "when request fails" do
36
+ it "returns response with errors" do
37
+ body = %[<?xml version="1.0"?><errors><error><code>1234</code>
38
+ <message>Sample error</message></error></errors>]
39
+ FakeWeb.register_uri :get, %r[.+], status: [400, "Bad Request"],
40
+ body: body, content_type: "text/xml"
41
+ response = PagSeguro::Installment.find("invalid")
42
+
43
+ expect(response).to be_a(PagSeguro::Installment::Response)
44
+ expect(response.errors).to include("Sample error")
45
+ end
46
+ end
47
+ end
48
+
49
+ describe ".load_from_response" do
50
+ context "when response succeeds" do
51
+ let(:response_body) { double(:response_body) }
52
+ let(:response) do
53
+ double(:response, success?: true, xml?: true, body: response_body)
54
+ end
55
+ let(:xml) { double(:xml) }
56
+ let(:node) { double(:node) }
57
+ let(:installments_nodes) { [node] }
58
+
59
+ it "loads response" do
60
+ expect(Nokogiri).to receive(:XML).with(response_body).and_return(xml)
61
+ expect(xml).to receive(:css).with("installments > installment")
62
+ .and_return(installments_nodes)
63
+ expect(PagSeguro::Installment).to receive(:load_from_xml).with(node)
64
+
65
+ PagSeguro::Installment.load_from_response(response)
66
+ end
67
+ end
68
+
69
+ context "when response fails" do
70
+ let(:response) { double(:response, success?: false) }
71
+ let(:error) { double(:error) }
72
+
73
+ it "returns response with errors" do
74
+ expect(PagSeguro::Errors).to receive(:new).with(response)
75
+ .and_return(error)
76
+ expect(PagSeguro::Installment::Response).to receive(:new).with(error)
77
+
78
+ PagSeguro::Installment.load_from_response(response)
79
+ end
80
+ end
81
+ end
82
+
83
+ describe ".load_from_xml" do
84
+ let(:xml) { double(:xml) }
85
+ let(:serializer) { double(:serializer) }
86
+ let(:data) { double(:data) }
87
+
88
+ it "serializes the xml" do
89
+ expect(PagSeguro::Installment::Serializer).to receive(:new).with(xml)
90
+ .and_return(serializer)
91
+ expect(serializer).to receive(:serialize).and_return(data)
92
+ expect(PagSeguro::Installment).to receive(:new).with(data)
93
+
94
+ PagSeguro::Installment.load_from_xml(xml)
95
+ end
96
+ end
97
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro-oficial
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aitch
@@ -181,6 +181,7 @@ files:
181
181
  - Rakefile
182
182
  - examples/abandoned_transactions.rb
183
183
  - examples/boot.rb
184
+ - examples/installment.rb
184
185
  - examples/invalid_transaction_by_notification_code.rb
185
186
  - examples/payment_request.rb
186
187
  - examples/transaction_by_notification_code.rb
@@ -193,6 +194,9 @@ files:
193
194
  - lib/pagseguro/exceptions.rb
194
195
  - lib/pagseguro/extensions/ensure_type.rb
195
196
  - lib/pagseguro/extensions/mass_assignment.rb
197
+ - lib/pagseguro/installment.rb
198
+ - lib/pagseguro/installment/response.rb
199
+ - lib/pagseguro/installment/serializer.rb
196
200
  - lib/pagseguro/item.rb
197
201
  - lib/pagseguro/items.rb
198
202
  - lib/pagseguro/notification.rb
@@ -213,6 +217,7 @@ files:
213
217
  - locales/pt-BR.yml
214
218
  - pagseguro-oficial.gemspec
215
219
  - spec/fixtures/by_date/success.xml
220
+ - spec/fixtures/installment/success.xml
216
221
  - spec/fixtures/invalid_code.xml
217
222
  - spec/fixtures/payment_request/failure.xml
218
223
  - spec/fixtures/payment_request/success.xml
@@ -221,6 +226,8 @@ files:
221
226
  - spec/pagseguro/address_spec.rb
222
227
  - spec/pagseguro/config_spec.rb
223
228
  - spec/pagseguro/errors_spec.rb
229
+ - spec/pagseguro/installment/serializer_spec.rb
230
+ - spec/pagseguro/installment_spec.rb
224
231
  - spec/pagseguro/item_spec.rb
225
232
  - spec/pagseguro/items_spec.rb
226
233
  - spec/pagseguro/notification_spec.rb
@@ -266,6 +273,7 @@ specification_version: 4
266
273
  summary: Biblioteca oficial de integração PagSeguro em Ruby
267
274
  test_files:
268
275
  - spec/fixtures/by_date/success.xml
276
+ - spec/fixtures/installment/success.xml
269
277
  - spec/fixtures/invalid_code.xml
270
278
  - spec/fixtures/payment_request/failure.xml
271
279
  - spec/fixtures/payment_request/success.xml
@@ -274,6 +282,8 @@ test_files:
274
282
  - spec/pagseguro/address_spec.rb
275
283
  - spec/pagseguro/config_spec.rb
276
284
  - spec/pagseguro/errors_spec.rb
285
+ - spec/pagseguro/installment/serializer_spec.rb
286
+ - spec/pagseguro/installment_spec.rb
277
287
  - spec/pagseguro/item_spec.rb
278
288
  - spec/pagseguro/items_spec.rb
279
289
  - spec/pagseguro/notification_spec.rb