pagseguro-oficial 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +54 -2
- data/examples/{authorization.rb → authorization/authorization.rb} +1 -1
- data/examples/{authorization_by_code.rb → authorization/authorization_by_code.rb} +1 -1
- data/examples/{authorization_by_notification_code.rb → authorization/authorization_by_notification_code.rb} +1 -1
- data/examples/refund.rb +25 -0
- data/examples/{abandoned_transactions.rb → transaction/abandoned_transactions.rb} +1 -1
- data/examples/{boleto_transaction_request.rb → transaction/boleto_transaction_request.rb} +1 -1
- data/examples/{credit_card_transaction_request.rb → transaction/credit_card_transaction_request.rb} +1 -1
- data/examples/{invalid_transaction_by_notification_code.rb → transaction/invalid_transaction_by_notification_code.rb} +1 -1
- data/examples/{online_debit_transaction.rb → transaction/online_debit_transaction.rb} +1 -1
- data/examples/{transaction_by_code.rb → transaction/transaction_by_code.rb} +1 -1
- data/examples/{transaction_by_notification_code.rb → transaction/transaction_by_notification_code.rb} +1 -1
- data/examples/{transaction_by_reference.rb → transaction/transaction_by_reference.rb} +1 -1
- data/examples/transaction/transaction_cancellation.rb +19 -0
- data/examples/transaction/transaction_status_history.rb +22 -0
- data/examples/{transactions_by_date.rb → transaction/transactions_by_date.rb} +1 -1
- data/lib/pagseguro/installment.rb +14 -0
- data/lib/pagseguro/payment_request/serializer.rb +48 -55
- data/lib/pagseguro/refund/request_serializer.rb +24 -0
- data/lib/pagseguro/refund/response.rb +33 -0
- data/lib/pagseguro/refund/response_serializer.rb +17 -0
- data/lib/pagseguro/refund/serializer.rb +24 -0
- data/lib/pagseguro/refund.rb +44 -0
- data/lib/pagseguro/transaction/collection.rb +20 -0
- data/lib/pagseguro/transaction/response.rb +37 -4
- data/lib/pagseguro/transaction/search.rb +1 -1
- data/lib/pagseguro/transaction/serializer.rb +14 -3
- data/lib/pagseguro/transaction/status_collection.rb +20 -0
- data/lib/pagseguro/transaction.rb +34 -14
- data/lib/pagseguro/transaction_cancellation/request_serializer.rb +18 -0
- data/lib/pagseguro/transaction_cancellation/response.rb +32 -0
- data/lib/pagseguro/transaction_cancellation/response_serializer.rb +17 -0
- data/lib/pagseguro/transaction_cancellation/serializer.rb +18 -0
- data/lib/pagseguro/transaction_cancellation.rb +40 -0
- data/lib/pagseguro/transaction_status.rb +14 -0
- data/lib/pagseguro/version.rb +1 -1
- data/lib/pagseguro.rb +13 -0
- data/spec/fixtures/refund/success.xml +2 -0
- data/spec/fixtures/transaction_cancellation/success.xml +2 -0
- data/spec/fixtures/transactions/status_history.xml +12 -0
- data/spec/pagseguro/refund/request_serializer_spec.rb +15 -0
- data/spec/pagseguro/refund/response_serializer_spec.rb +12 -0
- data/spec/pagseguro/refund/response_spec.rb +39 -0
- data/spec/pagseguro/refund/serializer_spec.rb +15 -0
- data/spec/pagseguro/refund_spec.rb +63 -0
- data/spec/pagseguro/request_spec.rb +0 -4
- data/spec/pagseguro/transaction/collection_spec.rb +43 -0
- data/spec/pagseguro/transaction/response_spec.rb +96 -0
- data/spec/pagseguro/transaction/search/search_abandoned_spec.rb +41 -28
- data/spec/pagseguro/transaction/search/search_by_date_spec.rb +20 -18
- data/spec/pagseguro/transaction/search/search_by_reference_spec.rb +13 -18
- data/spec/pagseguro/transaction/search_spec.rb +1 -6
- data/spec/pagseguro/transaction/serializer_spec.rb +11 -0
- data/spec/pagseguro/transaction/status_collection_spec.rb +43 -0
- data/spec/pagseguro/transaction_cancellation/request_serializer_spec.rb +13 -0
- data/spec/pagseguro/transaction_cancellation/response_serializer_spec.rb +9 -0
- data/spec/pagseguro/transaction_cancellation/response_spec.rb +42 -0
- data/spec/pagseguro/transaction_cancellation/serializer_spec.rb +13 -0
- data/spec/pagseguro/transaction_cancellation_spec.rb +58 -0
- data/spec/pagseguro/transaction_spec.rb +159 -13
- data/spec/pagseguro/transaction_status_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +64 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88901e2177d4f7a176e193f4fb6f21b62b7120f2
|
4
|
+
data.tar.gz: b025c4d828d375096fb7ee9defcca8c725c75e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6ae8a2ce4062e2c4108b39e32cfade79e2c973c2552cbc11d12f3a390c6a4a29442859525c95571757890f8c4d223099b1bc49e5ea51abe418218d12d5eac2
|
7
|
+
data.tar.gz: 356306e366dc20adc141362c205f051e48c7e0067dc67bb367b6d72a60993517a16976fbec1b83d2349685ec3ffae7ee9f305f9b8ba082edc3ee751d34f41296
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,8 @@ A biblioteca PagSeguro em Ruby é um conjunto de classes de domínio que facilit
|
|
12
12
|
- Consultar [transações por intervalo de datas] \(este serviço utiliza a versão **V3** da API)
|
13
13
|
- Consultar [transações abandonadas] \(este serviço utiliza a versão **V2** da API\)
|
14
14
|
- Receber [notificações] \(este serviço utiliza a versão **V3** da API\)
|
15
|
-
|
15
|
+
- Enviar estorno de transações \(este serviço utiliza a versão **V2** da API\)
|
16
|
+
- Cancelar transações \(este serviço utiliza a versão **V2** da API\)
|
16
17
|
|
17
18
|
## Requisitos
|
18
19
|
|
@@ -25,7 +26,7 @@ A biblioteca PagSeguro em Ruby é um conjunto de classes de domínio que facilit
|
|
25
26
|
- Adicione a biblioteca ao seu Gemfile.
|
26
27
|
|
27
28
|
```ruby
|
28
|
-
gem "pagseguro-oficial", "~> 2.
|
29
|
+
gem "pagseguro-oficial", "~> 2.4.0"
|
29
30
|
```
|
30
31
|
|
31
32
|
- Execute o comando `bundle install`.
|
@@ -178,6 +179,21 @@ while report.next_page?
|
|
178
179
|
end
|
179
180
|
```
|
180
181
|
|
182
|
+
### Histórico de status de transações
|
183
|
+
|
184
|
+
É possível consultar o histórico de mudanças de status em transações
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
response = PagSeguro::Transaction.find_status_history("transaction_code")
|
188
|
+
|
189
|
+
response.each do |status|
|
190
|
+
puts "STATUS:"
|
191
|
+
puts " code: #{status.code}"
|
192
|
+
puts " date: #{status.date}"
|
193
|
+
puts " notification_code: #{status.notification_code}"
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
181
197
|
### Consultar opções de parcelamento
|
182
198
|
|
183
199
|
Você pode consultar as opções de parcelamento para um determinado valor.
|
@@ -219,6 +235,42 @@ Em seguida, acesse o link para confirmar as autorizações
|
|
219
235
|
response.url
|
220
236
|
```
|
221
237
|
|
238
|
+
### Estorno de Transações
|
239
|
+
|
240
|
+
Você pode estornar pagamentos que as transações estiverem com status: Paga (3), Disponível (4), Em disputa (5).
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
refund = PagSeguro::Refund.new
|
244
|
+
refund.transaction_code = "D5D5BE444148407891E497B421975599"
|
245
|
+
|
246
|
+
response = refund.register
|
247
|
+
|
248
|
+
if response.errors.any?
|
249
|
+
puts response.errors.join("\n")
|
250
|
+
else
|
251
|
+
puts "=> REFUND RESPONSE"
|
252
|
+
puts response.result
|
253
|
+
end
|
254
|
+
```
|
255
|
+
|
256
|
+
### Cancelamento de Transações
|
257
|
+
|
258
|
+
Você pode cancelar transações que estiverem com status: Aguardando pagamento ou Em análise.
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
cancellation = PagSeguro::TransactionCancellation.new
|
262
|
+
cancellation.transaction_code = "AFB8FCF29496401681257C1ECE3A98FF"
|
263
|
+
|
264
|
+
cancellation.register
|
265
|
+
|
266
|
+
if cancellation.errors.any?
|
267
|
+
puts cancellation.errors.join("\n")
|
268
|
+
else
|
269
|
+
puts "=> CANCELLATION RESPONSE"
|
270
|
+
puts cancellation.result
|
271
|
+
end
|
272
|
+
```
|
273
|
+
|
222
274
|
## API
|
223
275
|
|
224
276
|
### PagSeguro::PaymentRequest (utiliza versão V2)
|
data/examples/refund.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "boot"
|
2
|
+
|
3
|
+
# Refund
|
4
|
+
#
|
5
|
+
# You need:
|
6
|
+
# - set your AccountCredentials (EMAIL, TOKEN) in the application config
|
7
|
+
# - set transaction code
|
8
|
+
# - set value (optional)
|
9
|
+
#
|
10
|
+
# P.S: See the boot file example for more details
|
11
|
+
|
12
|
+
refund = PagSeguro::Refund.new
|
13
|
+
refund.transaction_code = "D5D5BE444148407891E497B421975599"
|
14
|
+
|
15
|
+
# Partial refund
|
16
|
+
# refund.value = 400.00
|
17
|
+
|
18
|
+
response = refund.register
|
19
|
+
|
20
|
+
if response.errors.any?
|
21
|
+
puts response.errors.join("\n")
|
22
|
+
else
|
23
|
+
puts "=> REFUND RESPONSE"
|
24
|
+
puts response.result
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "../boot"
|
2
|
+
|
3
|
+
# Transaction cancellation
|
4
|
+
#
|
5
|
+
# You need:
|
6
|
+
# - give TRANSACTION CODE to TransactionCancellation#transaction_code
|
7
|
+
# - set your AccountCredentials (EMAIL, TOKEN) in the application config (P.S.: See the boot file example)
|
8
|
+
|
9
|
+
cancellation = PagSeguro::TransactionCancellation.new
|
10
|
+
cancellation.transaction_code = "AFB8FCF29496401681257C1ECE3A98FF"
|
11
|
+
|
12
|
+
cancellation.register
|
13
|
+
|
14
|
+
if cancellation.errors.any?
|
15
|
+
puts cancellation.errors.join("\n")
|
16
|
+
else
|
17
|
+
puts "=> CANCELLATION RESPONSE"
|
18
|
+
puts cancellation.result
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "../boot"
|
2
|
+
|
3
|
+
# Transaction status history
|
4
|
+
#
|
5
|
+
# You need to set your credentials in the application config
|
6
|
+
#
|
7
|
+
# P.S: See the boot file example for more details
|
8
|
+
|
9
|
+
response = PagSeguro::Transaction.find_status_history("transaction_code")
|
10
|
+
|
11
|
+
puts response.inspect
|
12
|
+
|
13
|
+
if response.errors.any?
|
14
|
+
puts response.errors.join("\n")
|
15
|
+
else
|
16
|
+
response.each do |status|
|
17
|
+
puts "STATUS:"
|
18
|
+
puts " code: #{status.code}"
|
19
|
+
puts " date: #{status.date}"
|
20
|
+
puts " notification_code: #{status.notification_code}"
|
21
|
+
end
|
22
|
+
end
|
@@ -39,5 +39,19 @@ module PagSeguro
|
|
39
39
|
def self.api_version
|
40
40
|
'v2'
|
41
41
|
end
|
42
|
+
|
43
|
+
def self.load_from_response(response)
|
44
|
+
if response.success? and response.xml?
|
45
|
+
Nokogiri::XML(response.body).css("installments > installment").map do |node|
|
46
|
+
load_from_xml(node)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
Response.new Errors.new(response)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.load_from_xml(xml)
|
54
|
+
new Serializer.new(xml).serialize
|
55
|
+
end
|
42
56
|
end
|
43
57
|
end
|
@@ -9,87 +9,80 @@ module PagSeguro
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def to_params
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
params.delete_if {|key, value| value.nil? }
|
31
|
-
|
32
|
-
params
|
12
|
+
{}.tap do |data|
|
13
|
+
data[:receiverEmail] = PagSeguro.receiver_email
|
14
|
+
data[:currency] = payment_request.currency
|
15
|
+
data[:reference] = payment_request.reference
|
16
|
+
data[:extraAmount] = to_amount(payment_request.extra_amount)
|
17
|
+
data[:redirectURL] = payment_request.redirect_url
|
18
|
+
data[:notificationURL] = payment_request.notification_url
|
19
|
+
data[:abandonURL] = payment_request.abandon_url
|
20
|
+
data[:maxUses] = payment_request.max_uses
|
21
|
+
data[:maxAge] = payment_request.max_age
|
22
|
+
payment_request.items.each_with_index do |item, index|
|
23
|
+
serialize_item(data, item, index.succ)
|
24
|
+
end
|
25
|
+
|
26
|
+
serialize_sender(data, payment_request.sender)
|
27
|
+
serialize_shipping(data, payment_request.shipping)
|
28
|
+
serialize_extra_params(data, payment_request.extra_params)
|
29
|
+
end.delete_if { |_, value| value.nil? }
|
33
30
|
end
|
34
31
|
|
35
32
|
private
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
params["itemAmount#{index}"] = to_amount(item.amount)
|
44
|
-
params["itemQuantity#{index}"] = item.quantity
|
45
|
-
params["itemShippingCost#{index}"] = to_amount(item.shipping_cost)
|
46
|
-
params["itemWeight#{index}"] = item.weight if item.weight
|
33
|
+
def serialize_item(data, item, index)
|
34
|
+
data["itemId#{index}"] = item.id
|
35
|
+
data["itemDescription#{index}"] = item.description
|
36
|
+
data["itemAmount#{index}"] = to_amount(item.amount)
|
37
|
+
data["itemQuantity#{index}"] = item.quantity
|
38
|
+
data["itemShippingCost#{index}"] = to_amount(item.shipping_cost)
|
39
|
+
data["itemWeight#{index}"] = item.weight if item.weight
|
47
40
|
end
|
48
41
|
|
49
|
-
def serialize_sender(sender)
|
42
|
+
def serialize_sender(data, sender)
|
50
43
|
return unless sender
|
51
44
|
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
data[:senderEmail] = sender.email
|
46
|
+
data[:senderName] = sender.name
|
47
|
+
data[:senderCPF] = sender.cpf
|
55
48
|
|
56
|
-
serialize_phone(sender.phone)
|
49
|
+
serialize_phone(data, sender.phone)
|
57
50
|
end
|
58
51
|
|
59
|
-
def serialize_phone(phone)
|
52
|
+
def serialize_phone(data, phone)
|
60
53
|
return unless phone
|
61
54
|
|
62
|
-
|
63
|
-
|
55
|
+
data[:senderAreaCode] = phone.area_code
|
56
|
+
data[:senderPhone] = phone.number
|
64
57
|
end
|
65
58
|
|
66
|
-
def serialize_shipping(shipping)
|
59
|
+
def serialize_shipping(data, shipping)
|
67
60
|
return unless shipping
|
68
61
|
|
69
|
-
|
70
|
-
|
62
|
+
data[:shippingType] = shipping.type_id
|
63
|
+
data[:shippingCost] = to_amount(shipping.cost)
|
71
64
|
|
72
|
-
serialize_address(shipping.address)
|
65
|
+
serialize_address(data, shipping.address)
|
73
66
|
end
|
74
67
|
|
75
|
-
def serialize_address(address)
|
68
|
+
def serialize_address(data, address)
|
76
69
|
return unless address
|
77
70
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
71
|
+
data[:shippingAddressCountry] = address.country
|
72
|
+
data[:shippingAddressState] = address.state
|
73
|
+
data[:shippingAddressCity] = address.city
|
74
|
+
data[:shippingAddressPostalCode] = address.postal_code
|
75
|
+
data[:shippingAddressDistrict] = address.district
|
76
|
+
data[:shippingAddressStreet] = address.street
|
77
|
+
data[:shippingAddressNumber] = address.number
|
78
|
+
data[:shippingAddressComplement] = address.complement
|
86
79
|
end
|
87
80
|
|
88
|
-
def serialize_extra_params(extra_params)
|
81
|
+
def serialize_extra_params(data, extra_params)
|
89
82
|
return unless extra_params
|
90
83
|
|
91
84
|
extra_params.each do |extra_param|
|
92
|
-
|
85
|
+
data[extra_param.keys.first] = extra_param.values.first
|
93
86
|
end
|
94
87
|
end
|
95
88
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Refund
|
3
|
+
class RequestSerializer
|
4
|
+
# The refund that will be serialized.
|
5
|
+
attr_reader :refund
|
6
|
+
|
7
|
+
def initialize(refund)
|
8
|
+
@refund = refund
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_params
|
12
|
+
{}.tap do |data|
|
13
|
+
data[:transactionCode] = refund.transaction_code
|
14
|
+
data[:refundValue] = to_amount(refund.value)
|
15
|
+
end.delete_if { |_, value| value.nil? }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def to_amount(amount)
|
20
|
+
"%.2f" % BigDecimal(amount.to_s).round(2).to_s("F") if amount
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Refund
|
3
|
+
class Response
|
4
|
+
def initialize(response, refund)
|
5
|
+
@response = response
|
6
|
+
@refund = refund
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialize
|
10
|
+
if success?
|
11
|
+
xml = Nokogiri::XML(response.body)
|
12
|
+
serialize = ResponseSerializer.new(xml).serialize
|
13
|
+
refund.update_attributes(serialize)
|
14
|
+
else
|
15
|
+
refund.errors.add(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
refund
|
19
|
+
end
|
20
|
+
|
21
|
+
def success?
|
22
|
+
response.success? && response.xml?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
# The request response.
|
27
|
+
attr_reader :response
|
28
|
+
|
29
|
+
# The refund object to return
|
30
|
+
attr_reader :refund
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Refund
|
3
|
+
class Serializer
|
4
|
+
# The refund that will be serialized.
|
5
|
+
attr_reader :refund
|
6
|
+
|
7
|
+
def initialize(refund)
|
8
|
+
@refund = refund
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_params
|
12
|
+
{}.tap do |data|
|
13
|
+
data[:transactionCode] = refund.transaction_code
|
14
|
+
data[:refundValue] = to_amount(refund.value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def to_amount(amount)
|
20
|
+
"%.2f" % BigDecimal(amount.to_s).round(2).to_s("F") if amount
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Refund
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
|
5
|
+
# Set the transaction code.
|
6
|
+
# The transaction status must be: Paga (3), Disponível (4), Em disputa (5)
|
7
|
+
attr_accessor :transaction_code
|
8
|
+
|
9
|
+
# Set the refund value.
|
10
|
+
# Greater than 0.00 and less or equal than transaction value.
|
11
|
+
# If not informed, PagSeguro will assume the total transaction value.
|
12
|
+
attr_accessor :value
|
13
|
+
|
14
|
+
# Result from request.
|
15
|
+
attr_accessor :result
|
16
|
+
|
17
|
+
# PagSeguro::Errors object.
|
18
|
+
attr_reader :errors
|
19
|
+
|
20
|
+
# Calls the PagSeguro webservice and register the refund.
|
21
|
+
# Return PagSeguro::Refund.
|
22
|
+
def register
|
23
|
+
response_request = Request.post("transactions/refunds", api_version, params)
|
24
|
+
Response.new(response_request, self).serialize
|
25
|
+
end
|
26
|
+
|
27
|
+
def errors
|
28
|
+
@errors ||= Errors.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def update_attributes(attrs)
|
32
|
+
attrs.map { |name, value| send("#{name}=", value) }
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def api_version
|
37
|
+
"v2"
|
38
|
+
end
|
39
|
+
|
40
|
+
def params
|
41
|
+
RequestSerializer.new(self).to_params
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Transaction
|
3
|
+
class Collection
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def_delegators :@transactions, :each, :empty?, :any?
|
7
|
+
|
8
|
+
def transactions=(objects)
|
9
|
+
@transactions = objects
|
10
|
+
end
|
11
|
+
|
12
|
+
def errors
|
13
|
+
@errors ||= Errors.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# PagSeguro::TransactionStatus instances.
|
17
|
+
attr_reader :transactions
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,11 +1,44 @@
|
|
1
1
|
module PagSeguro
|
2
2
|
class Transaction
|
3
3
|
class Response
|
4
|
-
|
5
|
-
|
4
|
+
def initialize(response, object)
|
5
|
+
@response = response
|
6
|
+
@object = object
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialize
|
10
|
+
if success?
|
11
|
+
object.update_attributes(Serializer.new(xml).serialize)
|
12
|
+
else
|
13
|
+
object.errors.add response
|
14
|
+
end
|
15
|
+
|
16
|
+
object
|
17
|
+
end
|
18
|
+
|
19
|
+
def serialize_statuses
|
20
|
+
if success?
|
21
|
+
object.statuses = Serializer.new(xml).serialize_status_history
|
22
|
+
else
|
23
|
+
object.errors.add(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
object
|
27
|
+
end
|
28
|
+
|
29
|
+
def success?
|
30
|
+
response.success? && response.xml?
|
31
|
+
end
|
32
|
+
|
33
|
+
# The http response.
|
34
|
+
attr_reader :response
|
35
|
+
|
36
|
+
# Set the that will receive errors or updates
|
37
|
+
attr_reader :object
|
6
38
|
|
7
|
-
|
8
|
-
|
39
|
+
private
|
40
|
+
def xml
|
41
|
+
Nokogiri::XML(response.body)
|
9
42
|
end
|
10
43
|
end
|
11
44
|
end
|
@@ -27,7 +27,7 @@ module PagSeguro
|
|
27
27
|
# call. Remember that this will perform an additional HTTP request.
|
28
28
|
def transactions
|
29
29
|
xml do |xml|
|
30
|
-
xml.css("transactionSearchResult transaction").map do |node|
|
30
|
+
xml.css("transactionSearchResult > transactions > transaction").map do |node|
|
31
31
|
Transaction.load_from_xml(node)
|
32
32
|
end
|
33
33
|
end
|