pagseguro-oficial 2.0.8 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -4
  3. data/README.md +15 -16
  4. data/examples/abandoned_transactions.rb +1 -1
  5. data/examples/transaction_by_notification_code.rb +55 -1
  6. data/examples/transaction_by_reference.rb +24 -0
  7. data/examples/transactions_by_date.rb +7 -1
  8. data/lib/pagseguro/creditor_fee.rb +23 -0
  9. data/lib/pagseguro/document.rb +11 -0
  10. data/lib/pagseguro/installment.rb +1 -1
  11. data/lib/pagseguro/payment_release.rb +21 -0
  12. data/lib/pagseguro/payment_releases.rb +25 -0
  13. data/lib/pagseguro/payment_request/response.rb +6 -1
  14. data/lib/pagseguro/payment_request.rb +4 -3
  15. data/lib/pagseguro/payment_status.rb +2 -0
  16. data/lib/pagseguro/request.rb +9 -7
  17. data/lib/pagseguro/sender.rb +8 -0
  18. data/lib/pagseguro/transaction/search/search_abandoned.rb +19 -0
  19. data/lib/pagseguro/transaction/search/search_by_date.rb +15 -0
  20. data/lib/pagseguro/transaction/search/search_by_reference.rb +12 -0
  21. data/lib/pagseguro/{report.rb → transaction/search.rb} +8 -11
  22. data/lib/pagseguro/transaction/serializer.rb +39 -4
  23. data/lib/pagseguro/transaction.rb +40 -9
  24. data/lib/pagseguro/version.rb +1 -1
  25. data/lib/pagseguro.rb +16 -7
  26. data/spec/fixtures/transactions/success.xml +24 -2
  27. data/spec/pagseguro/creditor_fee_spec.rb +10 -0
  28. data/spec/pagseguro/document_spec.rb +6 -0
  29. data/spec/pagseguro/installment_spec.rb +3 -2
  30. data/spec/pagseguro/pagseguro_spec.rb +4 -4
  31. data/spec/pagseguro/payment_release_spec.rb +9 -0
  32. data/spec/pagseguro/payment_releases_spec.rb +34 -0
  33. data/spec/pagseguro/payment_request_spec.rb +1 -1
  34. data/spec/pagseguro/payment_status_spec.rb +2 -0
  35. data/spec/pagseguro/request_spec.rb +7 -7
  36. data/spec/pagseguro/sender_spec.rb +1 -0
  37. data/spec/pagseguro/transaction/serializer_spec.rb +16 -1
  38. data/spec/pagseguro/transaction_spec.rb +29 -20
  39. metadata +20 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e774d4d23c27502385d14f5e9bc90ada28317325
4
- data.tar.gz: 6000c710d322c4faae2c4d95d0b3a03c34045d2e
3
+ metadata.gz: 970a3da0c4b529d8b515308272485707678b7328
4
+ data.tar.gz: f90deafb204fbc64dcd6d1bee51b30fc781a704a
5
5
  SHA512:
6
- metadata.gz: fd59c649d168459fb7864fb2a30c34a3ef381c3355c7ff4455058f20b37905447a7f5095bc1e17e775d2d5f340a15a27cc21c3052d853f57dad85c004a01f80f
7
- data.tar.gz: ef3e534a97d8e8486f44099d80f82f76c2f14c05303aee1a2ffe3456df4f8cfb0025ede3b50ce68aa7128e564004950dfd41821326a1dfb10ad34dc5cea01a19
6
+ metadata.gz: 1b9d0a5be5c4fb8bb7ab30d8847273ec821a99b40a11169b257c1f34dafe1d5d0832d3d4f9fa4d2346907850b58b8a776491ba32f83f82e50fd4f58dfc3ae4d7
7
+ data.tar.gz: 14ccedf76ac30be67909c144fda0d7dbd97e5042db8f8245d676b97d98c77f84c59732ceb4ab35fb3e9bca39e754a7bc3542b5c2780dff49e4132d64d12d0065
data/CHANGELOG.md CHANGED
@@ -1,13 +1,23 @@
1
- ## Next release - 2.0.8
1
+ ## Next release - 2.2.0
2
+
3
+ - Checkout transparente
4
+
5
+ ## Stable
6
+
7
+ 2.1.0
8
+
9
+ - Utilização da versão 3 da api de notificações e consultas (OBS.: o serviço de consulta a transações abandonadas ainda utiliza a versão 2)
10
+ - O serviço de parcelas (installment) usará fixamente a versão 2 da api
11
+ - Correção de um bug que concatenava o status da transação com o status de um pagamento
12
+
13
+ 2.0.8
2
14
 
3
15
  - Consulta de opções de parcelamento
4
16
 
5
- ## Next release - 2.0.7
17
+ 2.0.7
6
18
 
7
19
  - 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)
8
20
 
9
- ## Stable
10
-
11
21
  2.0.6
12
22
 
13
23
  - Adicionando environment sandbox, entre outras melhorias
data/README.md CHANGED
@@ -8,12 +8,11 @@
8
8
 
9
9
  A biblioteca PagSeguro em Ruby é um conjunto de classes de domínio que facilitam, para o desenvolvedor Ruby, a utilização das funcionalidades que o PagSeguro oferece na forma de APIs. Com a biblioteca instalada e configurada, você pode facilmente integrar funcionalidades como:
10
10
 
11
- - Criar [requisições de pagamentos]
12
- - Consultar [transações por código]
13
- - Consultar [transações por intervalo de datas]
14
- - Consultar [transações abandonadas]
15
- - Consultar opções de parcelamento
16
- - Receber [notificações]
11
+ - Criar [requisições de pagamentos] \(este serviço utiliza a versão **V2** da API\)
12
+ - Consultar [transações por código] \(este serviço utiliza a versão **V3** da API\)
13
+ - Consultar [transações por intervalo de datas] \(este serviço utiliza a versão **V3** da API)
14
+ - Consultar [transações abandonadas] \(este serviço utiliza a versão **V2** da API\)
15
+ - Receber [notificações] \(este serviço utiliza a versão **V3** da API\)
17
16
 
18
17
 
19
18
  ## Requisitos
@@ -27,7 +26,7 @@ A biblioteca PagSeguro em Ruby é um conjunto de classes de domínio que facilit
27
26
  - Adicione a biblioteca ao seu Gemfile.
28
27
 
29
28
  ```ruby
30
- gem "pagseguro-oficial", "~> 2.0.8"
29
+ gem "pagseguro-oficial", "~> 2.1.0"
31
30
  ```
32
31
 
33
32
  - Execute o comando `bundle install`.
@@ -45,7 +44,7 @@ end
45
44
 
46
45
  O token de segurança está disponível em sua [conta do PagSeguro](https://pagseguro.uol.com.br/integracao/token-de-seguranca.jhtml).
47
46
 
48
- ## Pagamentos
47
+ ## Pagamentos (API V2)
49
48
 
50
49
  Para iniciar uma requisição de pagamento, você precisa instanciar a classe `PagSeguro::PaymentRequest`. Isso normalmente será feito em seu controller de checkout.
51
50
 
@@ -100,7 +99,7 @@ class CheckoutController < ApplicationController
100
99
  end
101
100
  ```
102
101
 
103
- ## Notificações
102
+ ## Notificações (API V3)
104
103
 
105
104
  O PagSeguro irá notificar a URL informada no processo de checkout. Isso é feito através do método `PagSeguro::PaymentRequest#notification_url`. Esta URL irá receber o código da notificação e tipo de notificação. Com estas informações, podemos recuperar as informações detalhadas sobre o pagamento.
106
105
 
@@ -122,9 +121,9 @@ class NotificationsController < ApplicationController
122
121
  end
123
122
  ```
124
123
 
125
- ## Consultas
124
+ ## Consultas (API V3)
126
125
 
127
- ### Transações abandonadas
126
+ ### Transações abandonadas (API V2)
128
127
 
129
128
  Para quantificar o número de transações abandonadas, você pode solicitar uma lista com histórico dessas transações.
130
129
 
@@ -203,7 +202,7 @@ end
203
202
 
204
203
  ## API
205
204
 
206
- ### PagSeguro::PaymentRequest
205
+ ### PagSeguro::PaymentRequest (utiliza versão V2)
207
206
 
208
207
  #### Definindo identificador do pedido
209
208
 
@@ -335,10 +334,10 @@ Se seu Pull Request for relacionado a uma versão específica, o Pull Request n
335
334
 
336
335
 
337
336
  [requisições de pagamentos]: https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-pagamentos.html
338
- [notificações]: https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-notificacoes.html
339
- [transações por código]: https://pagseguro.uol.com.br/v2/guia-de-integracao/consulta-de-transacoes-por-codigo.html
340
- [transações por intervalo de datas]: https://pagseguro.uol.com.br/v2/guia-de-integracao/consulta-de-transacoes-por-intervalo-de-datas.html
341
- [transações abandonadas]: https://pagseguro.uol.com.br/v2/guia-de-integracao/consulta-de-transacoes-abandonadas.html
337
+ [notificações]: https://pagseguro.uol.com.br/v3/guia-de-integracao/api-de-notificacoes.html
338
+ [transações por código]: https://pagseguro.uol.com.br/v3/guia-de-integracao/consulta-de-transacoes-por-codigo.html
339
+ [transações por intervalo de datas]: https://pagseguro.uol.com.br/v3/guia-de-integracao/consulta-de-transacoes-por-intervalo-de-datas.html
340
+ [transações abandonadas]: https://pagseguro.uol.com.br/v3/guia-de-integracao/consulta-de-transacoes-abandonadas.html
342
341
  [fórum]: http://forum.pagseguro.uol.com.br/
343
342
  [Ruby]: http://www.ruby-lang.org/pt/
344
343
  [GitHub]: https://github.com/pagseguro/ruby/
@@ -20,7 +20,7 @@ while report.next_page?
20
20
  puts " created at: #{transaction.created_at}"
21
21
  puts " code: #{transaction.code}"
22
22
  puts " type_id: #{transaction.type_id}"
23
- puts " gross amount: #{transaction.gross_amount}"
23
+ puts " gross amount: #{transaction.gross_amount.to_f}"
24
24
  puts
25
25
  end
26
26
  end
@@ -2,4 +2,58 @@ require_relative "boot"
2
2
 
3
3
  transaction = PagSeguro::Transaction.find_by_notification_code("739D69-79C052C05280-55542D9FBB33-4AB2D0")
4
4
 
5
- puts transaction
5
+ puts "=> Transaction"
6
+ puts " code: #{transaction.code}"
7
+ puts " type: #{transaction.type_id}"
8
+ puts " status: #{transaction.status.status}"
9
+ puts " cancellation source: #{transaction.cancellation_source}"
10
+ puts " escrow end date: #{transaction.escrow_end_date}"
11
+ puts " payment method type: #{transaction.payment_method.type}"
12
+ puts " gross amount: #{transaction.gross_amount.to_f}"
13
+ puts " discount amount: #{transaction.discount_amount.to_f}"
14
+ puts " operational fee amount: #{transaction.creditor_fees.operational_fee_amount.to_f}"
15
+ puts " installment fee amount: #{transaction.creditor_fees.installment_fee_amount.to_f}"
16
+ puts " intermediation rate amount: #{transaction.creditor_fees.intermediation_rate_amount.to_f}"
17
+ puts " intermediation fee amount: #{transaction.creditor_fees.intermediation_fee_amount.to_f}"
18
+ puts " commission fee amount: #{transaction.creditor_fees.commission_fee_amount.to_f}"
19
+ puts " commission fee amount: #{transaction.creditor_fees.commission_fee_amount.to_f}"
20
+ puts " efrete: #{transaction.creditor_fees.efrete.to_f}"
21
+ puts " net amount: #{transaction.net_amount.to_f}"
22
+ puts " extra amount: #{transaction.extra_amount.to_f}"
23
+
24
+ puts " => Payments"
25
+ puts " installment count: #{transaction.installments}"
26
+ transaction.payment_releases.each do |release|
27
+ puts " current installment: #{release.installment}"
28
+ puts " total amount: #{release.total_amount.to_f}"
29
+ puts " release amount: #{release.release_amount.to_f}"
30
+ puts " status: #{release.status}"
31
+ puts " release date: #{release.release_date}"
32
+ end
33
+
34
+ puts " => Items"
35
+ puts " items count: #{transaction.items.size}"
36
+ transaction.items.each do |item|
37
+ puts " item id: #{item.id}"
38
+ puts " description: #{item.description}"
39
+ puts " quantity: #{item.quantity}"
40
+ puts " amount: #{item.amount.to_f}"
41
+ puts " weight: #{item.weight}g"
42
+ end
43
+
44
+ puts " => Sender"
45
+ puts " name: #{transaction.sender.name}"
46
+ puts " email: #{transaction.sender.email}"
47
+ puts " phone: (#{transaction.sender.phone.area_code}) #{transaction.sender.phone.number}"
48
+ puts " document: #{transaction.sender.document.type}: #{transaction.sender.document.value}"
49
+
50
+ puts " => Shipping"
51
+ puts " street: #{transaction.shipping.address.street}, #{transaction.shipping.address.number}"
52
+ puts " complement: #{transaction.shipping.address.complement}"
53
+ puts " postal code: #{transaction.shipping.address.postal_code}"
54
+ puts " district: #{transaction.shipping.address.district}"
55
+ puts " city: #{transaction.shipping.address.city}"
56
+ puts " state: #{transaction.shipping.address.state}"
57
+ puts " country: #{transaction.shipping.address.country}"
58
+ puts " type: #{transaction.shipping.type_name}"
59
+ puts " cost: #{transaction.shipping.cost}"
@@ -0,0 +1,24 @@
1
+ require_relative 'boot'
2
+
3
+ transaction = PagSeguro::Transaction.find_by_reference("REF1234")
4
+
5
+ while transaction.next_page?
6
+ transaction.next_page!
7
+ puts "== Page #{transaction.page}"
8
+ abort "=> Errors: #{transaction.errors.join("\n")}" unless transaction.valid?
9
+ puts "Report created on #{transaction.created_at}"
10
+ puts
11
+
12
+ transaction.transactions.each do |transaction|
13
+ puts "=> Transaction"
14
+ puts " created_at: #{transaction.created_at}"
15
+ puts " code: #{transaction.code}"
16
+ puts " cancellation_source: #{transaction.cancellation_source}"
17
+ puts " payment method: #{transaction.payment_method.type}"
18
+ puts " gross amount: #{transaction.gross_amount.to_f}"
19
+ puts " updated at: #{transaction.updated_at}"
20
+ puts " status: #{transaction.status.status}"
21
+ puts
22
+ end
23
+ end
24
+
@@ -15,9 +15,15 @@ while report.next_page?
15
15
  puts " created_at: #{transaction.created_at}"
16
16
  puts " code: #{transaction.code}"
17
17
  puts " cancellation_source: #{transaction.cancellation_source}"
18
+ puts " type: #{transaction.type_id}"
19
+ puts " status: #{transaction.status.status}"
18
20
  puts " payment method: #{transaction.payment_method.type}"
19
- puts " gross amount: #{transaction.gross_amount}"
21
+ puts " gross amount: #{transaction.gross_amount.to_f}"
22
+ puts " discount amount: #{transaction.discount_amount.to_f}"
23
+ puts " net amount: #{transaction.net_amount.to_f}"
24
+ puts " extra amount: #{transaction.extra_amount.to_f}"
20
25
  puts " updated at: #{transaction.updated_at}"
26
+ puts " status: #{transaction.status.status}"
21
27
  puts
22
28
  end
23
29
  end
@@ -0,0 +1,23 @@
1
+ module PagSeguro
2
+ class CreditorFee
3
+ include Extensions::MassAssignment
4
+
5
+ # Set the current transaction intermidiation rate amount
6
+ attr_accessor :intermediation_rate_amount
7
+
8
+ # Set the current transaction intermediation fee amount
9
+ attr_accessor :intermediation_fee_amount
10
+
11
+ # Set the current transaction installment amount
12
+ attr_accessor :installment_fee_amount
13
+
14
+ # Set the current transaction operational fee amount
15
+ attr_accessor :operational_fee_amount
16
+
17
+ # Set the current transaction commission fee amount
18
+ attr_accessor :commission_fee_amount
19
+
20
+ # Set the current transaction freight amount
21
+ attr_accessor :efrete
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module PagSeguro
2
+ class Document
3
+ include Extensions::MassAssignment
4
+
5
+ # the type of the document
6
+ attr_accessor :type
7
+
8
+ # the value of the document
9
+ attr_accessor :value
10
+ end
11
+ end
@@ -24,7 +24,7 @@ module PagSeguro
24
24
  def self.find(amount, card_brand = nil)
25
25
  string = "installments?amount=#{amount}"
26
26
  string += "&cardBrand=#{card_brand}" if card_brand
27
- load_from_response Request.get(string)
27
+ load_from_response Request.get(string, 'v2')
28
28
  end
29
29
 
30
30
  # Serialize the HTTP response into data.
@@ -0,0 +1,21 @@
1
+ module PagSeguro
2
+ class PaymentRelease
3
+ include Extensions::MassAssignment
4
+ include Extensions::EnsureType
5
+
6
+ # Set the number of installments
7
+ attr_accessor :installment
8
+
9
+ # Set the total amount
10
+ attr_accessor :total_amount
11
+
12
+ # Set the total amount of the current release
13
+ attr_accessor :release_amount
14
+
15
+ # Set the status of current release
16
+ attr_accessor :status
17
+
18
+ # Set the release date
19
+ attr_accessor :release_date
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module PagSeguro
2
+ class PaymentReleases
3
+ include Enumerable
4
+ extend Forwardable
5
+ include Extensions::EnsureType
6
+
7
+ def_delegators :@payments, :each, :size
8
+
9
+ def initialize
10
+ @payments = []
11
+ end
12
+
13
+ def <<(payment)
14
+ payment = ensure_type(PaymentRelease, payment)
15
+
16
+ @payments << payment unless @payments.include? payment
17
+ end
18
+
19
+ def include?(payment)
20
+ self.find do |included_payment|
21
+ included_payment.installment == ensure_type(PaymentRelease, payment).installment
22
+ end
23
+ end
24
+ end
25
+ end
@@ -15,7 +15,7 @@ module PagSeguro
15
15
  end
16
16
 
17
17
  def url
18
- PagSeguro.site_url("checkout/payment.html?code=#{code}") if code
18
+ PagSeguro.site_url("#{api_version}/checkout/payment.html?code=#{code}") if code
19
19
  end
20
20
 
21
21
  def code
@@ -25,6 +25,11 @@ module PagSeguro
25
25
  def created_at
26
26
  @created_at ||= Time.parse(response.data.css("checkout > date").text) if success?
27
27
  end
28
+
29
+ # Default PagSeguro API version for payments
30
+ def api_version
31
+ 'v2'
32
+ end
28
33
  end
29
34
  end
30
35
  end
@@ -81,7 +81,7 @@ module PagSeguro
81
81
  email: email,
82
82
  token: token
83
83
  })
84
- Response.new Request.post("checkout", params)
84
+ Response.new Request.post("checkout", api_version, params)
85
85
  end
86
86
 
87
87
  private
@@ -92,8 +92,9 @@ module PagSeguro
92
92
  self.token = PagSeguro.token
93
93
  end
94
94
 
95
- def endpoint
96
- PagSeguro.api_url("checkout")
95
+ # The default PagSeguro API version
96
+ def api_version
97
+ 'v2'
97
98
  end
98
99
  end
99
100
  end
@@ -9,6 +9,8 @@ module PagSeguro
9
9
  "5" => :in_dispute,
10
10
  "6" => :refunded,
11
11
  "7" => :cancelled,
12
+ "8" => :chargeback_charged,
13
+ "9" => :contested
12
14
  }.freeze
13
15
 
14
16
  # The payment status id.
@@ -10,29 +10,31 @@ module PagSeguro
10
10
  # Perform a GET request.
11
11
  #
12
12
  # # +path+: the path that will be requested. Must be something like <tt>"transactions/code/739D69-79C052C05280-55542D9FBB33-CAB2B1"</tt>.
13
+ # # +api_version+: the current PagSeguro API version of the requested service
13
14
  # # +data+: the data that will be sent as query string. Must be a Hash.
14
15
  # # +headers+: any additional header that will be sent through the request.
15
16
  #
16
- def get(path, data = {}, headers = {})
17
- execute :get, path, data, headers
17
+ def get(path, api_version, data = {}, headers = {})
18
+ execute :get, path, api_version, data, headers
18
19
  end
19
20
 
20
21
  # Perform a POST request.
21
22
  #
22
23
  # # +path+: the path that will be requested. Must be something like <tt>"checkout"</tt>.
24
+ # # +api_version+: the current PagSeguro API version of the requested service
23
25
  # # +data+: the data that will be sent as body data. Must be a Hash.
24
26
  # # +headers+: any additional header that will be sent through the request.
25
27
  #
26
- def post(path, data = {}, headers = {})
27
- execute :post, path, data, headers
28
+ def post(path, api_version, data = {}, headers = {})
29
+ execute :post, path, api_version, data, headers
28
30
  end
29
31
 
30
32
  # Perform the specified HTTP request. It will include the API credentials,
31
- # encoding and additional headers.
32
- def execute(request_method, path, data, headers) # :nodoc:
33
+ # api_version, encoding and additional headers.
34
+ def execute(request_method, path, api_version, data, headers) # :nodoc:
33
35
  request.public_send(
34
36
  request_method,
35
- PagSeguro.api_url(path),
37
+ PagSeguro.api_url("#{api_version}/#{path}"),
36
38
  extended_data(data),
37
39
  extended_headers(request_method, headers)
38
40
  )
@@ -6,6 +6,9 @@ module PagSeguro
6
6
  # Get the sender phone.
7
7
  attr_reader :phone
8
8
 
9
+ # Get the sender document
10
+ attr_reader :document
11
+
9
12
  # Set the sender name.
10
13
  attr_accessor :name
11
14
 
@@ -19,5 +22,10 @@ module PagSeguro
19
22
  def phone=(phone)
20
23
  @phone = ensure_type(Phone, phone)
21
24
  end
25
+
26
+ # Set the sender document.
27
+ def document=(document)
28
+ @document = ensure_type(Document, document)
29
+ end
22
30
  end
23
31
  end
@@ -0,0 +1,19 @@
1
+ module PagSeguro
2
+ class SearchAbandoned < PagSeguro::Search
3
+ private
4
+ def perform_request_and_serialize
5
+ @response = Request.get(@path, api_version,
6
+ {
7
+ initialDate: options[:starts_at].xmlschema,
8
+ finalDate: options[:ends_at].xmlschema,
9
+ page: page,
10
+ maxPageResults: options.fetch(:per_page, 50)
11
+ })
12
+ @errors = Errors.new(@response)
13
+ end
14
+
15
+ def api_version
16
+ 'v2'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module PagSeguro
2
+ class SearchByDate < PagSeguro::Search
3
+ private
4
+ def perform_request_and_serialize
5
+ @response = Request.get(@path, api_version,
6
+ {
7
+ initialDate: options[:starts_at].xmlschema,
8
+ finalDate: options[:ends_at].xmlschema,
9
+ page: page,
10
+ maxPageResults: options.fetch(:per_page, 50)
11
+ })
12
+ @errors = Errors.new(@response)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module PagSeguro
2
+ class SearchByReference < PagSeguro::Search
3
+ private
4
+ def perform_request_and_serialize
5
+ @response = Request.get(@path, api_version,
6
+ {
7
+ reference: options[:reference],
8
+ })
9
+ @errors = Errors.new(@response)
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module PagSeguro
2
- class Report
2
+ class Search
3
3
  # Set the report options.
4
4
  #
5
5
  # # +per_page+: the page size.
@@ -14,8 +14,7 @@ module PagSeguro
14
14
  # Return the current page.
15
15
  attr_reader :page
16
16
 
17
- def initialize(item_class, path, options, page = 0)
18
- @item_class = item_class
17
+ def initialize(path, options, page = 0)
19
18
  @path = path
20
19
  @options = options
21
20
  @page = page
@@ -86,14 +85,12 @@ module PagSeguro
86
85
 
87
86
  private
88
87
  def perform_request_and_serialize
89
- @response = Request.get(@path, {
90
- initialDate: options[:starts_at].xmlschema,
91
- finalDate: options[:ends_at].xmlschema,
92
- page: page,
93
- maxPageResults: options.fetch(:per_page, 50)
94
- })
95
-
96
- @errors = Errors.new(@response)
88
+ raise NotImplementedError.new("'.perform_request_and_serialize' must be implemented in specific search class")
89
+ end
90
+
91
+ # The default PagSeguro API version
92
+ def api_version
93
+ 'v3'
97
94
  end
98
95
 
99
96
  def fetched?
@@ -12,6 +12,8 @@ module PagSeguro
12
12
  serialize_general(data)
13
13
  serialize_amounts(data)
14
14
  serialize_dates(data)
15
+ serialize_creditor(data)
16
+ serialize_payments(data)
15
17
  serialize_items(data)
16
18
  serialize_sender(data)
17
19
  serialize_shipping(data) if xml.css("shipping").any?
@@ -19,11 +21,11 @@ module PagSeguro
19
21
  end
20
22
 
21
23
  def serialize_general(data)
22
- data[:code] = xml.css(">code").text
24
+ data[:code] = xml.css("> code").text
23
25
  data[:reference] = xml.css("reference").text
24
- data[:type_id] = xml.css(">type").text
26
+ data[:type_id] = xml.css("> type").text
25
27
  data[:payment_link] = xml.css("paymentLink").text
26
- data[:status] = xml.css("status").text
28
+ data[:status] = xml.css("> status").text
27
29
 
28
30
  cancellation_source = xml.css("cancellationSource")
29
31
  data[:cancellation_source] = cancellation_source.text if cancellation_source.any?
@@ -47,12 +49,37 @@ module PagSeguro
47
49
  def serialize_amounts(data)
48
50
  data[:gross_amount] = BigDecimal(xml.css("grossAmount").text)
49
51
  data[:discount_amount] = BigDecimal(xml.css("discountAmount").text)
50
- data[:fee_amount] = BigDecimal(xml.css("feeAmount").text)
51
52
  data[:net_amount] = BigDecimal(xml.css("netAmount").text)
52
53
  data[:extra_amount] = BigDecimal(xml.css("extraAmount").text)
53
54
  data[:installments] = xml.css("installmentCount").text.to_i
54
55
  end
55
56
 
57
+ def serialize_creditor(data)
58
+ data[:creditor_fees] = {
59
+ intermediation_rate_amount: BigDecimal(xml.css("creditorFees > intermediationRateAmount").text),
60
+ intermediation_fee_amount: BigDecimal(xml.css("creditorFees > intermediationFeeAmount").text),
61
+ installment_fee_amount: BigDecimal(xml.css("creditorFees > installmentFeeAmount").text),
62
+ operational_fee_amount: BigDecimal(xml.css("creditorFees > operationalFeeAmount").text),
63
+ commission_fee_amount: BigDecimal(xml.css("creditorFees > commissionFeeAmount").text),
64
+ efrete: BigDecimal(xml.css("creditorFees > efrete").text)
65
+ }
66
+ end
67
+
68
+ def serialize_payments(data)
69
+ data[:payment_releases] = []
70
+
71
+ xml.css("paymentReleases > paymentRelease").each do |node|
72
+ payment_release = {}
73
+ payment_release[:installment] = node.css("installment").text
74
+ payment_release[:total_amount] = BigDecimal(node.css("totalAmount").text)
75
+ payment_release[:release_amount] = BigDecimal(node.css("releaseAmount").text)
76
+ payment_release[:status] = node.css("status").text
77
+ payment_release[:release_date] = Time.parse(node.css("releaseDate").text)
78
+
79
+ data[:payment_releases] << payment_release
80
+ end
81
+ end
82
+
56
83
  def serialize_items(data)
57
84
  data[:items] = []
58
85
 
@@ -74,9 +101,17 @@ module PagSeguro
74
101
  }
75
102
 
76
103
  serialize_phone(sender)
104
+ serialize_document(sender)
77
105
  data[:sender] = sender
78
106
  end
79
107
 
108
+ def serialize_document(data)
109
+ data[:document] = {
110
+ type: xml.css("sender > documents > document > type").text,
111
+ value: xml.css("sender > documents > document > value").text
112
+ }
113
+ end
114
+
80
115
  def serialize_phone(data)
81
116
  data[:phone] = {
82
117
  area_code: xml.css("sender > phone > areaCode").text,