pagseguro-oficial 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -1
  3. data/CONTRIBUTING.md +39 -0
  4. data/Dockerfile +20 -0
  5. data/README.md +22 -0
  6. data/docker-compose.yml +5 -0
  7. data/examples/checkout/create_payment_request.rb +1 -1
  8. data/examples/direct/create_transaction_using_boleto.rb +1 -1
  9. data/examples/direct/create_transaction_using_credit_card.rb +1 -1
  10. data/examples/direct/create_transaction_using_online_debit.rb +1 -1
  11. data/examples/preapproval/cancel_preapproval.rb +26 -0
  12. data/examples/preapproval/change_preapproval_payment.rb +50 -0
  13. data/examples/preapproval/change_preapproval_status.rb +29 -0
  14. data/examples/preapproval/charge_preapproval.rb +36 -0
  15. data/examples/preapproval/create_preapproval.rb +68 -0
  16. data/examples/preapproval/create_preapproval_auto.rb +53 -0
  17. data/examples/preapproval/create_preapproval_discount.rb +30 -0
  18. data/examples/preapproval/create_preapproval_manual.rb +58 -0
  19. data/examples/preapproval/create_preapproval_transparent.rb +41 -0
  20. data/examples/preapproval/preapproval_retry.rb +29 -0
  21. data/examples/preapproval/search/search_by_date_interval.rb +45 -0
  22. data/examples/preapproval/search/search_by_days_interval.rb +46 -0
  23. data/examples/preapproval/search/search_by_notification_code.rb +50 -0
  24. data/examples/preapproval/search/search_by_subscription_code.rb +50 -0
  25. data/examples/preapproval/search/search_subscription_payment_orders.rb +53 -0
  26. data/examples/split_payment/create_payment_request.rb +1 -1
  27. data/examples/split_payment/create_transaction_using_boleto.rb +118 -0
  28. data/examples/split_payment/create_transaction_using_credit_card.rb +152 -0
  29. data/lib/pagseguro.rb +33 -1
  30. data/lib/pagseguro/credit_card_transaction_request.rb +1 -1
  31. data/lib/pagseguro/document.rb +8 -0
  32. data/lib/pagseguro/holder.rb +8 -0
  33. data/lib/pagseguro/manual_subscription_charger.rb +59 -0
  34. data/lib/pagseguro/manual_subscription_charger/request_serializer.rb +50 -0
  35. data/lib/pagseguro/manual_subscription_charger/response.rb +36 -0
  36. data/lib/pagseguro/manual_subscription_charger/response_serializer.rb +17 -0
  37. data/lib/pagseguro/payment_request/request_serializer.rb +25 -1
  38. data/lib/pagseguro/receiver.rb +3 -0
  39. data/lib/pagseguro/request.rb +32 -2
  40. data/lib/pagseguro/sender.rb +21 -3
  41. data/lib/pagseguro/subscription.rb +132 -0
  42. data/lib/pagseguro/subscription/request_serializer.rb +129 -0
  43. data/lib/pagseguro/subscription/response.rb +49 -0
  44. data/lib/pagseguro/subscription/response_serializer.rb +62 -0
  45. data/lib/pagseguro/subscription/subscription_search.rb +135 -0
  46. data/lib/pagseguro/subscription_canceller.rb +30 -0
  47. data/lib/pagseguro/subscription_canceller/response.rb +34 -0
  48. data/lib/pagseguro/subscription_change_payment.rb +46 -0
  49. data/lib/pagseguro/subscription_change_payment/request_serializer.rb +80 -0
  50. data/lib/pagseguro/subscription_change_payment/response.rb +26 -0
  51. data/lib/pagseguro/subscription_change_status.rb +50 -0
  52. data/lib/pagseguro/subscription_change_status/request_serializer.rb +28 -0
  53. data/lib/pagseguro/subscription_change_status/response.rb +26 -0
  54. data/lib/pagseguro/subscription_discount.rb +41 -0
  55. data/lib/pagseguro/subscription_discount/request_serializer.rb +34 -0
  56. data/lib/pagseguro/subscription_discount/response.rb +34 -0
  57. data/lib/pagseguro/subscription_payment_method.rb +21 -0
  58. data/lib/pagseguro/subscription_payment_order.rb +57 -0
  59. data/lib/pagseguro/subscription_payment_order/response.rb +37 -0
  60. data/lib/pagseguro/subscription_payment_order/response_serializer.rb +51 -0
  61. data/lib/pagseguro/subscription_plan.rb +69 -0
  62. data/lib/pagseguro/subscription_plan/request_serializer.rb +81 -0
  63. data/lib/pagseguro/subscription_plan/response.rb +36 -0
  64. data/lib/pagseguro/subscription_plan/response_serializer.rb +17 -0
  65. data/lib/pagseguro/subscription_retry.rb +35 -0
  66. data/lib/pagseguro/subscription_retry/response.rb +34 -0
  67. data/lib/pagseguro/subscription_search_payment_orders.rb +131 -0
  68. data/lib/pagseguro/subscription_transaction.rb +29 -0
  69. data/lib/pagseguro/subscription_transactions.rb +5 -0
  70. data/lib/pagseguro/transaction.rb +0 -10
  71. data/lib/pagseguro/transaction/serializer.rb +19 -2
  72. data/lib/pagseguro/transaction_request.rb +26 -1
  73. data/lib/pagseguro/transaction_request/request_serializer.rb +164 -1
  74. data/lib/pagseguro/version.rb +1 -1
  75. data/spec/fixtures/manual_subscription_charger/fail.xml +6 -0
  76. data/spec/fixtures/manual_subscription_charger/success.xml +4 -0
  77. data/spec/fixtures/subscription/fail.xml +6 -0
  78. data/spec/fixtures/subscription/find_success.xml +28 -0
  79. data/spec/fixtures/subscription/search_success.xml +18 -0
  80. data/spec/fixtures/subscription/success.xml +4 -0
  81. data/spec/fixtures/subscription_canceller/fail.xml +6 -0
  82. data/spec/fixtures/subscription_change_payment/fail.xml +7 -0
  83. data/spec/fixtures/subscription_change_status/fail.xml +7 -0
  84. data/spec/fixtures/subscription_discount/fail.xml +6 -0
  85. data/spec/fixtures/subscription_payment_order/success.xml +18 -0
  86. data/spec/fixtures/subscription_plan/fail.xml +6 -0
  87. data/spec/fixtures/subscription_plan/success.xml +4 -0
  88. data/spec/fixtures/subscription_retry/fail.xml +7 -0
  89. data/spec/fixtures/subscription_search_payment_orders/success.xml +43 -0
  90. data/spec/fixtures/transactions/without_status_and_type.xml +71 -0
  91. data/spec/pagseguro/credit_card_transaction_request_spec.rb +1 -1
  92. data/spec/pagseguro/document_spec.rb +15 -0
  93. data/spec/pagseguro/holder_spec.rb +1 -0
  94. data/spec/pagseguro/manual_subscription_charger/request_serializer_spec.rb +79 -0
  95. data/spec/pagseguro/manual_subscription_charger/response_serializer_spec.rb +10 -0
  96. data/spec/pagseguro/manual_subscription_charger/response_spec.rb +65 -0
  97. data/spec/pagseguro/manual_subscription_charger_spec.rb +68 -0
  98. data/spec/pagseguro/payment_request/request_serializer_spec.rb +54 -22
  99. data/spec/pagseguro/receiver_spec.rb +1 -0
  100. data/spec/pagseguro/sender_spec.rb +16 -2
  101. data/spec/pagseguro/subscription/request_serializer_spec.rb +233 -0
  102. data/spec/pagseguro/subscription/response_serializer_spec.rb +46 -0
  103. data/spec/pagseguro/subscription/response_spec.rb +79 -0
  104. data/spec/pagseguro/subscription/subscription_search_spec.rb +154 -0
  105. data/spec/pagseguro/subscription_canceller/response_spec.rb +58 -0
  106. data/spec/pagseguro/subscription_canceller_spec.rb +57 -0
  107. data/spec/pagseguro/subscription_change_payment/request_serializer_spec.rb +150 -0
  108. data/spec/pagseguro/subscription_change_payment/response_spec.rb +41 -0
  109. data/spec/pagseguro/subscription_change_payment_spec.rb +60 -0
  110. data/spec/pagseguro/subscription_change_status/request_serializer_spec.rb +19 -0
  111. data/spec/pagseguro/subscription_change_status/response_spec.rb +41 -0
  112. data/spec/pagseguro/subscription_change_status_spec.rb +53 -0
  113. data/spec/pagseguro/subscription_discount/request_serializer_spec.rb +27 -0
  114. data/spec/pagseguro/subscription_discount/response_spec.rb +58 -0
  115. data/spec/pagseguro/subscription_discount_spec.rb +60 -0
  116. data/spec/pagseguro/subscription_payment_method_spec.rb +10 -0
  117. data/spec/pagseguro/subscription_payment_order/response_serializer_spec.rb +24 -0
  118. data/spec/pagseguro/subscription_payment_order/response_spec.rb +55 -0
  119. data/spec/pagseguro/subscription_payment_order_spec.rb +27 -0
  120. data/spec/pagseguro/subscription_plan/request_serializer_spec.rb +253 -0
  121. data/spec/pagseguro/subscription_plan/response_serializer_spec.rb +10 -0
  122. data/spec/pagseguro/subscription_plan/response_spec.rb +65 -0
  123. data/spec/pagseguro/subscription_plan_spec.rb +118 -0
  124. data/spec/pagseguro/subscription_retry/response_spec.rb +58 -0
  125. data/spec/pagseguro/subscription_retry_spec.rb +62 -0
  126. data/spec/pagseguro/subscription_search_payment_order_spec.rb +129 -0
  127. data/spec/pagseguro/subscription_spec.rb +137 -0
  128. data/spec/pagseguro/subscription_transaction_spec.rb +24 -0
  129. data/spec/pagseguro/subscription_transactions_spec.rb +37 -0
  130. data/spec/pagseguro/transaction/response_spec.rb +0 -42
  131. data/spec/pagseguro/transaction/serializer_spec.rb +5 -6
  132. data/spec/pagseguro/transaction_request/request_serializer_spec.rb +623 -159
  133. data/spec/pagseguro/transaction_request_spec.rb +26 -0
  134. data/spec/pagseguro/transaction_spec.rb +0 -48
  135. data/spec/spec_helper.rb +1 -0
  136. metadata +154 -8
  137. data/examples/checkout/search/search_transaction_status_history.rb +0 -22
  138. data/lib/pagseguro/transaction/status_collection.rb +0 -20
  139. data/spec/fixtures/transactions/status_history.xml +0 -12
  140. data/spec/pagseguro/transaction/status_collection_spec.rb +0 -43
@@ -6,6 +6,9 @@ module PagSeguro
6
6
  # Set receiver's email.
7
7
  attr_accessor :email
8
8
 
9
+ # Set receiver's public_key.
10
+ attr_accessor :public_key
11
+
9
12
  # Get receiver split.
10
13
  attr_reader :split
11
14
 
@@ -18,6 +18,17 @@ module PagSeguro
18
18
  execute :get, path, api_version, data, headers
19
19
  end
20
20
 
21
+ def get_with_auth_on_url(path, api_version, credentials)
22
+ request.public_send(
23
+ :get,
24
+ PagSeguro.api_url("#{api_version}/#{path}?#{credentials_to_params(credentials)}")
25
+ )
26
+ end
27
+
28
+ def get_without_api_version(path, data={}, headers={})
29
+ request.get(path, extended_data(data), headers)
30
+ end
31
+
21
32
  # Perform a POST request.
22
33
  #
23
34
  # # +path+: the path that will be requested. Must be something like <tt>"checkout"</tt>.
@@ -36,12 +47,31 @@ module PagSeguro
36
47
  # # +credentials+: the credentials like ApplicationCredentials or AccountCredentials.
37
48
  # # +data+: the data that will be sent as body data. Must be a XML.
38
49
  #
39
- def post_xml(path, api_version, credentials, data)
50
+ def post_xml(path, api_version, credentials, data = '', options={})
40
51
  credentials_params = credentials_to_params(credentials)
52
+ url_path = [api_version, path].reject(&:nil?).join('/')
41
53
 
42
54
  request.post do
43
- url PagSeguro.api_url("#{api_version}/#{path}?#{credentials_params}")
55
+ url PagSeguro.api_url("#{url_path}?#{credentials_params}")
44
56
  headers "Content-Type" => "application/xml; charset=#{PagSeguro.encoding}"
57
+ headers.merge!(options[:headers]) if options[:headers]
58
+ body data
59
+ end
60
+ end
61
+
62
+ # Perform a PUT request, sending XML data.
63
+ #
64
+ # # +path+: the path that will be requested. Must be something like <tt>"checkout"</tt>.
65
+ # # +credentials+: the credentials like ApplicationCredentials or AccountCredentials.
66
+ # # +data+: the data that will be sent as body data. Must be a XML.
67
+ #
68
+ def put_xml(path, credentials, data)
69
+ full_url = PagSeguro.api_url("#{path}?#{credentials_to_params(credentials)}")
70
+
71
+ request.put do
72
+ url full_url
73
+ headers "Content-Type" => "application/xml; charset=#{PagSeguro.encoding}",
74
+ "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1"
45
75
  body data
46
76
  end
47
77
  end
@@ -9,14 +9,17 @@ module PagSeguro
9
9
  # Get the sender document
10
10
  attr_reader :document
11
11
 
12
+ # Get the sender address
13
+ attr_reader :address
14
+
12
15
  # Set the sender name.
13
16
  attr_accessor :name
14
17
 
15
18
  # Set the sender e-mail.
16
19
  attr_accessor :email
17
20
 
18
- # Set the CPF document.
19
- attr_accessor :cpf
21
+ # Set the sender ip
22
+ attr_accessor :ip
20
23
 
21
24
  # Set sender hash.
22
25
  # It's used to identify the sender.
@@ -27,9 +30,24 @@ module PagSeguro
27
30
  @phone = ensure_type(Phone, phone)
28
31
  end
29
32
 
33
+ def documents
34
+ @documents ||= Documents.new
35
+ end
36
+
37
+ def documents=(_documents=[])
38
+ _documents.each do |document|
39
+ documents << document
40
+ end
41
+ end
42
+
30
43
  # Set the sender document.
31
44
  def document=(document)
32
- @document = ensure_type(Document, document)
45
+ documents << ensure_type(Document, document)
46
+ end
47
+
48
+ # Set the sender address.
49
+ def address=(address)
50
+ @address = ensure_type(Address, address)
33
51
  end
34
52
  end
35
53
  end
@@ -0,0 +1,132 @@
1
+ module PagSeguro
2
+ # It lets you create a subscription without going through PagSeguro screens.
3
+ class Subscription
4
+ include Extensions::MassAssignment
5
+ include Extensions::EnsureType
6
+ include Extensions::Credentiable
7
+
8
+ API_VERSION = :v2
9
+ TEN_DAYS_IN_SECONDS = 864_000
10
+
11
+ # Set the name
12
+ attr_accessor :name
13
+
14
+ # Set the date
15
+ attr_accessor :date
16
+
17
+ # Set the tracker
18
+ attr_accessor :tracker
19
+
20
+ # Set the status
21
+ attr_accessor :status
22
+
23
+ # Set the last event date
24
+ attr_accessor :last_event_date
25
+
26
+ # Set the charge
27
+ attr_accessor :charge
28
+
29
+ # Set the plan
30
+ attr_accessor :plan
31
+
32
+ # Set the reference
33
+ attr_accessor :reference
34
+
35
+ # Get the sender
36
+ attr_reader :sender
37
+
38
+ # Get the payment method
39
+ attr_reader :payment_method
40
+
41
+ # The code of a created to the subscription, must be saved
42
+ attr_accessor :code
43
+
44
+ # Set the sender
45
+ def sender=(sender)
46
+ @sender = ensure_type(Sender, sender)
47
+ end
48
+
49
+ # Set the payment method
50
+ def payment_method=(payment_method)
51
+ @payment_method = ensure_type(SubscriptionPaymentMethod, payment_method)
52
+ end
53
+
54
+ def update_attributes(attrs)
55
+ attrs.each {|name, value| send("#{name}=", value) }
56
+ end
57
+
58
+ def create
59
+ request = Request.post_xml('pre-approvals', nil, credentials, xml_params, extra_options)
60
+ Response.new(request, self).serialize
61
+ self
62
+ end
63
+
64
+ def errors
65
+ @errors ||= Errors.new
66
+ end
67
+
68
+ # Find subscription by notification code
69
+ def self.find_by_notification_code(code, options={})
70
+ load_from_response send_request("pre-approvals/notifications/#{code}", options[:credentials])
71
+ end
72
+
73
+ # Find subscription by subscription code
74
+ def self.find_by_code(code, options={})
75
+ load_from_response send_request("pre-approvals/#{code}", options[:credentials])
76
+ end
77
+
78
+ def self.search_by_days_interval(options={})
79
+ # Default options
80
+ options = {
81
+ interval: 30,
82
+ per_page: 50,
83
+ page: 0
84
+ }.merge(options)
85
+
86
+ SubscriptionSearch.new('pre-approvals/notifications', options)
87
+ end
88
+
89
+ def self.search_by_date_interval(options={})
90
+ # Default options
91
+ options = {
92
+ starts_at: Time.now,
93
+ ends_at: Time.now - TEN_DAYS_IN_SECONDS,
94
+ per_page: 50,
95
+ page: 0
96
+ }.merge(options)
97
+
98
+ SubscriptionSearch.new('pre-approvals', options)
99
+ end
100
+
101
+ def self.load_from_xml(xml)
102
+ new ResponseSerializer.new(xml).serialize_from_search
103
+ end
104
+
105
+ private
106
+
107
+ # Serialize the HTTP response into data.
108
+ def self.load_from_response(request) # :nodoc:
109
+ subscription = new
110
+ Response.new(request, subscription).serialize(:search)
111
+
112
+ subscription
113
+ end
114
+
115
+ # Send a get request to API version, with the path given
116
+ def self.send_request(path, credentials)
117
+ Request.get_with_auth_on_url(path, API_VERSION, credentials)
118
+ end
119
+
120
+ def xml_params
121
+ RequestSerializer.new(self).serialize
122
+ end
123
+
124
+ def extra_options
125
+ { headers: { "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1" }}
126
+ end
127
+
128
+ def after_initialize
129
+ @errors = Errors.new
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,129 @@
1
+ module PagSeguro
2
+ class Subscription
3
+ class RequestSerializer
4
+ # Get the object
5
+ attr_reader :object
6
+
7
+ def initialize(object)
8
+ @object = object
9
+ end
10
+
11
+ def serialize
12
+ build.to_xml(save_with:
13
+ Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
14
+ Nokogiri::XML::Node::SaveOptions::FORMAT
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ def build
21
+ Nokogiri::XML::Builder.new(encoding: PagSeguro.encoding) do |xml|
22
+ xml.send(:directPreApproval) {
23
+ xml.send(:plan, object.plan) if object.plan
24
+ xml.send(:reference, object.reference) if object.reference
25
+ serialize_sender(xml, object.sender)
26
+ serialize_payment_method(xml, object.payment_method)
27
+ }
28
+ end
29
+ end
30
+
31
+ def serialize_sender(xml, sender)
32
+ return unless sender
33
+
34
+ xml.send(:sender) {
35
+ xml.send(:name, sender.name) if sender.name
36
+ xml.send(:email, sender.email) if sender.email
37
+ xml.send(:ip, sender.ip) if sender.ip
38
+ xml.send(:hash_, sender.hash) if sender.hash
39
+
40
+ serialize_phone(xml, sender.phone)
41
+ serialize_address(xml, sender.address)
42
+ serialize_documents(xml, sender.documents)
43
+ }
44
+ end
45
+
46
+ def serialize_phone(xml, phone)
47
+ return unless phone
48
+
49
+ xml.send(:phone) {
50
+ xml.send(:areaCode, phone.area_code)
51
+ xml.send(:number, phone.number)
52
+ }
53
+ end
54
+
55
+ def serialize_address(xml, address)
56
+ return unless address
57
+
58
+ xml.send(:address) {
59
+ xml.send(:street, address.street) if address.street
60
+ xml.send(:number, address.number) if address.number
61
+ xml.send(:complement, address.complement) if address.complement
62
+ xml.send(:district, address.district) if address.district
63
+ xml.send(:city, address.city) if address.city
64
+ xml.send(:state, address.state) if address.state
65
+ xml.send(:country, address.country) if address.country
66
+ xml.send(:postalCode, address.postal_code) if address.postal_code
67
+ }
68
+ end
69
+
70
+ def serialize_billing_address(xml, address)
71
+ return unless address
72
+
73
+ xml.send(:billingAddress) {
74
+ xml.send(:street, address.street) if address.street
75
+ xml.send(:number, address.number) if address.number
76
+ xml.send(:complement, address.complement) if address.complement
77
+ xml.send(:district, address.district) if address.district
78
+ xml.send(:city, address.city) if address.city
79
+ xml.send(:state, address.state) if address.state
80
+ xml.send(:country, address.country) if address.country
81
+ xml.send(:postalCode, address.postal_code) if address.postal_code
82
+ }
83
+ end
84
+
85
+ def serialize_documents(xml, documents)
86
+ return if documents.empty?
87
+
88
+ xml.send(:documents) {
89
+ documents.each do |document|
90
+ serialize_document(xml, document)
91
+ end
92
+ }
93
+ end
94
+
95
+ def serialize_document(xml, document)
96
+ return unless document
97
+
98
+ xml.send(:document) {
99
+ xml.send(:type, document.type)
100
+ xml.send(:value, document.value)
101
+ }
102
+ end
103
+
104
+ def serialize_payment_method(xml, payment_method)
105
+ return unless payment_method
106
+
107
+ xml.send(:paymentMethod) {
108
+ xml.send(:type, payment_method.type)
109
+ xml.send(:creditCard) {
110
+ xml.send(:token, payment_method.token)
111
+ serialize_holder(xml, payment_method.holder)
112
+ }
113
+ }
114
+ end
115
+
116
+ def serialize_holder(xml, holder)
117
+ return unless holder
118
+
119
+ xml.send(:holder) {
120
+ xml.send(:name, holder.name) if holder.name
121
+ xml.send(:birthDate, holder.birth_date) if holder.birth_date
122
+ serialize_document(xml, holder.document)
123
+ serialize_billing_address(xml, holder.billing_address)
124
+ serialize_phone(xml, holder.phone)
125
+ }
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,49 @@
1
+ module PagSeguro
2
+ class Subscription
3
+ class Response
4
+ # The http response
5
+ attr_reader :response
6
+
7
+ # Set the object that will recive errors or updates
8
+ attr_reader :object
9
+
10
+ def initialize(response, object)
11
+ @response = response
12
+ @object = object
13
+ end
14
+
15
+ def serialize(kind = :normal)
16
+ if success?
17
+ case kind
18
+ when :normal
19
+ object.update_attributes(serialized_data)
20
+ when :search
21
+ object.update_attributes(serialized_data_from_search)
22
+ end
23
+ else
24
+ object.errors.add response
25
+ end
26
+
27
+ object
28
+ end
29
+
30
+ def success?
31
+ response.success? && response.xml?
32
+ end
33
+
34
+ private
35
+
36
+ def xml
37
+ Nokogiri::XML(response.body)
38
+ end
39
+
40
+ def serialized_data
41
+ ResponseSerializer.new(xml).serialize
42
+ end
43
+
44
+ def serialized_data_from_search
45
+ ResponseSerializer.new(xml).serialize_from_search
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,62 @@
1
+ module PagSeguro
2
+ class Subscription
3
+ class ResponseSerializer
4
+ attr_reader :xml
5
+
6
+ def initialize(xml)
7
+ @xml = xml
8
+ end
9
+
10
+ def serialize
11
+ {}.tap do |data|
12
+ data[:code] = xml.css('directPreApproval > code').text
13
+ end
14
+ end
15
+
16
+ def serialize_from_search
17
+ {}.tap do |data|
18
+ data[:name] = xml.at_css('name').text
19
+ data[:code] = xml.css('code').text
20
+ data[:date] = xml.css('date').text
21
+ data[:tracker] = xml.css('tracker').text
22
+ data[:status] = xml.css('status').text
23
+ data[:reference] = xml.css('reference').text
24
+ data[:last_event_date] = xml.css('lastEventDate').text
25
+ data[:charge] = xml.css('charge').text
26
+ data[:sender] = serialize_sender if xml.at_css('sender')
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def serialize_sender
33
+ {}.tap do |data|
34
+ data[:name] = xml.at_css('sender > name').text
35
+ data[:email] = xml.at_css('sender > email').text
36
+ data[:phone] = serialize_phone if xml.at_css('phone')
37
+ data[:address] = serialize_address if xml.at_css('address')
38
+ end
39
+ end
40
+
41
+ def serialize_phone
42
+ {}.tap do |data|
43
+ data[:area_code] = xml.css('sender > phone > areaCode').text
44
+ data[:number] = xml.css('sender > phone > number').text
45
+ end
46
+ end
47
+
48
+ def serialize_address
49
+ {}.tap do |data|
50
+ data[:street] = xml.at_css('sender > address > street').text
51
+ data[:number] = xml.at_css('sender > address > number').text
52
+ data[:complement] = xml.at_css('sender > address > complement').text
53
+ data[:district] = xml.at_css('sender > address > district').text
54
+ data[:city] = xml.at_css('sender > address > city').text
55
+ data[:state] = xml.at_css('sender > address > state').text
56
+ data[:country] = xml.at_css('sender > address > country').text
57
+ data[:postal_code] = xml.at_css('sender > address > postalCode').text
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end