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
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::ManualSubscriptionCharger do
4
+ it_assigns_attribute :reference
5
+ it_assigns_attribute :subscription_code
6
+ it_assigns_attribute :transaction_code
7
+
8
+ it_ensures_collection_type PagSeguro::Item, :items, [{id: '123', description: 'abc', amount: 100.00, quantity: 1}]
9
+
10
+ context 'errors attribute' do
11
+ it 'should start with errors' do
12
+ expect(subject.errors).to be_a PagSeguro::Errors
13
+ end
14
+
15
+ it 'should start with empty errors' do
16
+ expect(subject.errors).to be_empty
17
+ end
18
+ end
19
+
20
+ describe '#create' do
21
+ before do
22
+ subject.credentials = credentials
23
+
24
+ FakeWeb.register_uri(
25
+ :post,
26
+ 'https://ws.pagseguro.uol.com.br/v2/pre-approvals/payment?email=user@example.com&token=TOKEN',
27
+ body: ''
28
+ )
29
+ end
30
+
31
+ let(:credentials) do
32
+ PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN')
33
+ end
34
+
35
+ let(:request) do
36
+ double(
37
+ :Request,
38
+ success?: true,
39
+ xml?: true,
40
+ body: '<result><transactionCode>1234</transactionCode><date>2011-08-19T14:47:59.000-03:00</date></result>'
41
+ )
42
+ end
43
+
44
+ it 'sends it to correct url' do
45
+ expect(PagSeguro).to receive(:api_url).with(
46
+ 'v2/pre-approvals/payment?email=user@example.com&token=TOKEN'
47
+ ).and_return('https://ws.pagseguro.uol.com.br/v2/pre-approvals/payment?email=user@example.com&token=TOKEN')
48
+
49
+ subject.create
50
+ end
51
+
52
+ context 'when creating' do
53
+ it 'send to correct url' do
54
+ expect(PagSeguro::Request).to receive(:post_xml).with(
55
+ 'pre-approvals/payment', :v2, credentials, a_string_matching(/<payment>/)
56
+ ).and_return(request)
57
+
58
+ subject.create
59
+ end
60
+
61
+ it 'update with the new transaction_code' do
62
+ allow(PagSeguro::Request).to receive(:post_xml).and_return(request)
63
+
64
+ expect { subject.create }.to change { subject.transaction_code }.to('1234')
65
+ end
66
+ end
67
+ end
68
+ end
@@ -34,6 +34,38 @@ describe PagSeguro::PaymentRequest::RequestSerializer do
34
34
  expect(subject.to_xml_params).to match %r[<sender>.*<name>Sender<\/name>.*<email>b@example.com<\/email>.*<phone>.*<areaCode>51<\/areaCode>.*<number>2<\/number>]m
35
35
  end
36
36
 
37
+ context 'should serialize sender document' do
38
+ it 'when it was CPF' do
39
+ payment.sender = PagSeguro::Sender.new(document: PagSeguro::Document.new(type: 'CPF', value: '12312312312'))
40
+
41
+ expect(subject.to_xml_params).to match %r[
42
+ .*<sender>
43
+ .*<documents>
44
+ .*<document>
45
+ .*<type>CPF</type>
46
+ .*<value>12312312312</value>
47
+ .*</document>
48
+ .*</documents>
49
+ .*</sender>
50
+ ]mx
51
+ end
52
+
53
+ it 'when it was CNPJ' do
54
+ payment.sender = PagSeguro::Sender.new(document: PagSeguro::Document.new(type: 'CNPJ', value: '12123123000112'))
55
+
56
+ expect(subject.to_xml_params).to match %r[
57
+ .*<sender>
58
+ .*<documents>
59
+ .*<document>
60
+ .*<type>CNPJ</type>
61
+ .*<value>12123123000112</value>
62
+ .*</document>
63
+ .*</documents>
64
+ .*</sender>
65
+ ]mx
66
+ end
67
+ end
68
+
37
69
  it 'should serializer currency' do
38
70
  payment.currency = 'BRL'
39
71
  expect(subject.to_xml_params).to match %r[<currency>BRL</currency>]
@@ -163,36 +195,36 @@ describe PagSeguro::PaymentRequest::RequestSerializer do
163
195
  it { expect(params).to include(shippingAddressComplement: "COMPLEMENT") }
164
196
  end
165
197
 
166
- context "sender serialization" do
198
+ context 'sender serialize' do
167
199
  before do
168
- sender = PagSeguro::Sender.new({
169
- email: "EMAIL",
170
- name: "NAME",
171
- cpf: "CPF"
172
- })
200
+ sender = PagSeguro::Sender.new(
201
+ name: 'NAME',
202
+ email: 'EMAIL',
203
+ phone: { area_code: 'AREA_CODE', number: 'NUMBER' }
204
+ )
173
205
 
174
206
  allow(payment_request).to receive(:sender).and_return(sender)
175
207
  end
176
208
 
177
- it { expect(params).to include(senderEmail: "EMAIL") }
178
- it { expect(params).to include(senderName: "NAME") }
179
- it { expect(params).to include(senderCPF: "CPF") }
180
- end
209
+ it { expect(params).to include(senderName: 'NAME') }
210
+ it { expect(params).to include(senderEmail: 'EMAIL') }
181
211
 
182
- context "phone serialization" do
183
- before do
184
- sender = PagSeguro::Sender.new({
185
- phone: {
186
- area_code: "AREA_CODE",
187
- number: "NUMBER"
188
- }
189
- })
190
-
191
- allow(payment_request).to receive(:sender).and_return(sender)
212
+ context "phone" do
213
+ it { expect(params).to include(senderAreaCode: "AREA_CODE") }
214
+ it { expect(params).to include(senderPhone: "NUMBER") }
192
215
  end
193
216
 
194
- it { expect(params).to include(senderAreaCode: "AREA_CODE") }
195
- it { expect(params).to include(senderPhone: "NUMBER") }
217
+ context 'documents' do
218
+ it 'when is CPF' do
219
+ payment_request.sender.document = PagSeguro::Document.new(type: 'CPF', value: '12312312312')
220
+ expect(params).to include(senderCPF: '12312312312')
221
+ end
222
+
223
+ it 'when is CNPJ' do
224
+ payment_request.sender.document = PagSeguro::Document.new(type: 'CNPJ', value: '12123123000112')
225
+ expect(params).to include(senderCNPJ: '12123123000112')
226
+ end
227
+ end
196
228
  end
197
229
 
198
230
  context "items serialization" do
@@ -2,5 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe PagSeguro::Receiver do
4
4
  it_assigns_attribute :email
5
+ it_assigns_attribute :public_key
5
6
  it_ensures_type PagSeguro::ReceiverSplit, :split
6
7
  end
@@ -3,9 +3,23 @@ require "spec_helper"
3
3
  describe PagSeguro::Sender do
4
4
  it_assigns_attribute :name
5
5
  it_assigns_attribute :email
6
- it_assigns_attribute :cpf
7
6
  it_assigns_attribute :hash
7
+ it_assigns_attribute :ip
8
+
8
9
  it_ensures_type PagSeguro::Phone, :phone
9
- it_ensures_type PagSeguro::Document, :document
10
+ it_ensures_type PagSeguro::Address, :address
11
+
12
+ it_ensures_collection_type PagSeguro::Document, :documents, [{type: 'CPF', value: 12312312312}]
13
+
14
+ context 'when assign document' do
15
+ it 'documents collection should increasing by 1' do
16
+ expect{ subject.document = { type: 'CPF', value: 'VALUE' } }.to change{ subject.documents.size }.to 1
17
+ end
18
+
19
+ it 'document collection should have the document added' do
20
+ subject.document = { type: 'CPF', value: 'VALUE' }
21
+ expect(subject.documents.first).to eq PagSeguro::Document.new(type: 'CPF', value: 'VALUE')
22
+ end
23
+ end
10
24
  end
11
25
 
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::Subscription::RequestSerializer do
4
+ let(:subscription) { PagSeguro::Subscription.new }
5
+ let(:xml) { described_class.new(subscription).serialize }
6
+
7
+ context 'serialize' do
8
+ it 'plan attribute' do
9
+ subscription.plan = '89A1108EFEFE7A8EE4065FAD7872DE0D'
10
+ expect(xml).to match %r[
11
+ <directPreApproval>
12
+ .*<plan>89A1108EFEFE7A8EE4065FAD7872DE0D</plan>
13
+ ]xm
14
+ end
15
+
16
+ it 'reference attribute' do
17
+ subscription.reference = 'ID-CND'
18
+ expect(xml).to match %r[
19
+ <directPreApproval>
20
+ .*<reference>ID-CND</reference>
21
+ ]xm
22
+ end
23
+
24
+ context 'sender attributes' do
25
+ before do
26
+ subscription.sender = {
27
+ name: 'Comprador',
28
+ email: 'user@example.com',
29
+ ip: '192.168.0.1',
30
+ hash: 'hash',
31
+ phone: {
32
+ area_code: 12,
33
+ number: '23456789'
34
+ },
35
+ document: { type: 'CPF', value: '23606838450' },
36
+ address: {
37
+ street: 'Av Brigadeira Faria Lima',
38
+ number: '1384',
39
+ complement: '3 andar',
40
+ district: 'Jd Paulistano',
41
+ city: 'Sao Paulo',
42
+ state: 'SP',
43
+ country: 'BRA',
44
+ postal_code: '01452002'
45
+ }
46
+ }
47
+ end
48
+
49
+ it 'name attribute' do
50
+ expect(xml).to match %r[
51
+ <directPreApproval>
52
+ .*<sender>
53
+ .*<name>Comprador</name>
54
+ ]xm
55
+ end
56
+
57
+ it 'email attribute' do
58
+ expect(xml).to match %r[
59
+ <directPreApproval>
60
+ .*<sender>
61
+ .*<email>user@example.com</email>
62
+ ]xm
63
+ end
64
+
65
+ it 'ip attribute' do
66
+ expect(xml).to match %r[
67
+ <directPreApproval>
68
+ .*<sender>
69
+ .*<ip>192.168.0.1</ip>
70
+ ]xm
71
+ end
72
+
73
+ it 'hash attribute' do
74
+ expect(xml).to match %r[
75
+ <directPreApproval>
76
+ .*<sender>
77
+ .*<hash>hash</hash>
78
+ ]xm
79
+ end
80
+
81
+ it 'phone attribute' do
82
+ expect(xml).to match %r[
83
+ <directPreApproval>
84
+ .*<sender>
85
+ .*<phone>
86
+ .*<areaCode>12</areaCode>
87
+ .*<number>23456789</number>
88
+ .*</phone>
89
+ ]xm
90
+ end
91
+
92
+ it 'address attribute' do
93
+ expect(xml).to match %r[
94
+ <directPreApproval>
95
+ .*<sender>
96
+ .*<address>
97
+ .*<street>Av\ Brigadeira\ Faria\ Lima</street>
98
+ .*<number>1384</number>
99
+ .*<complement>3\ andar</complement>
100
+ .*<district>Jd\ Paulistano</district>
101
+ .*<city>Sao\ Paulo</city>
102
+ .*<state>SP</state>
103
+ .*<country>BRA</country>
104
+ .*<postalCode>01452002</postalCode>
105
+ .*</address>
106
+ ]xm
107
+ end
108
+
109
+ it 'documents attribute' do
110
+ expect(xml).to match %r[
111
+ <directPreApproval>
112
+ .*<sender>
113
+ .*<documents>
114
+ .*<document>
115
+ .*<type>CPF</type>
116
+ .*<value>23606838450</value>
117
+ .*</document>
118
+ .*</documents>
119
+ ]xm
120
+ end
121
+ end
122
+
123
+ context 'payment method attributes' do
124
+ before do
125
+ subscription.payment_method = {
126
+ token: 'd05df2a777de4c4f882b3e8aaef09030',
127
+ holder: {
128
+ name: 'Nome',
129
+ birth_date: '11/01/1984',
130
+ document: { type: 'CPF', value: '00000000191' },
131
+ billing_address: {
132
+ street: 'Av Brigadeira Faria Lima',
133
+ number: '1384',
134
+ complement: '3 andar',
135
+ district: 'Jd Paulistano',
136
+ city: 'Sao Paulo',
137
+ state: 'SP',
138
+ country: 'BRA',
139
+ postal_code: '01452002'
140
+ },
141
+ phone: { area_code: '11', number: '988881234' }
142
+ }
143
+ }
144
+ end
145
+
146
+ it 'type attribute' do
147
+ expect(xml).to match %r[
148
+ <directPreApproval>
149
+ .*<paymentMethod>
150
+ .*<type>CREDITCARD</type>
151
+ ]xm
152
+ end
153
+
154
+ context 'creditcard attributes' do
155
+ it 'token attribute' do
156
+ expect(xml).to match %r[
157
+ <directPreApproval>
158
+ .*<paymentMethod>
159
+ .*<creditCard>
160
+ .*<token>d05df2a777de4c4f882b3e8aaef09030</token>
161
+ ]xm
162
+ end
163
+
164
+ context 'holder attributes' do
165
+ it 'name attribute' do
166
+ expect(xml).to match %r[
167
+ <directPreApproval>
168
+ .*<paymentMethod>
169
+ .*<creditCard>
170
+ .*<holder>
171
+ .*<name>Nome</name>
172
+ ]xm
173
+ end
174
+
175
+ it 'birth_date attribute' do
176
+ expect(xml).to match %r[
177
+ <directPreApproval>
178
+ .*<paymentMethod>
179
+ .*<creditCard>
180
+ .*<holder>
181
+ .*<birthDate>11/01/1984</birthDate>
182
+ ]xm
183
+ end
184
+
185
+ it 'document attribute' do
186
+ expect(xml).to match %r[
187
+ <directPreApproval>
188
+ .*<paymentMethod>
189
+ .*<creditCard>
190
+ .*<holder>
191
+ .*<document>
192
+ .*<type>CPF</type>
193
+ .*<value>00000000191</value>
194
+ .*</document>
195
+ ]xm
196
+ end
197
+
198
+ it 'billing_address attributes' do
199
+ expect(xml).to match %r[
200
+ <directPreApproval>
201
+ .*<paymentMethod>
202
+ .*<creditCard>
203
+ .*<holder>
204
+ .*<billingAddress>
205
+ .*<street>Av\ Brigadeira\ Faria\ Lima</street>
206
+ .*<number>1384</number>
207
+ .*<complement>3\ andar</complement>
208
+ .*<district>Jd\ Paulistano</district>
209
+ .*<city>Sao\ Paulo</city>
210
+ .*<state>SP</state>
211
+ .*<country>BRA</country>
212
+ .*<postalCode>01452002</postalCode>
213
+ .*</billingAddress>
214
+ ]xm
215
+ end
216
+
217
+ it 'phone attributes' do
218
+ expect(xml).to match %r[
219
+ <directPreApproval>
220
+ .*<paymentMethod>
221
+ .*<creditCard>
222
+ .*<holder>
223
+ .*<phone>
224
+ .*<areaCode>11</areaCode>
225
+ .*<number>988881234</number>
226
+ .*</phone>
227
+ ]xm
228
+ end
229
+ end
230
+ end
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::Subscription::ResponseSerializer do
4
+ subject { PagSeguro::Subscription::ResponseSerializer.new(xml) }
5
+
6
+ let(:xml) { Nokogiri::XML(source) }
7
+
8
+ context 'serializer from normal response' do
9
+ let(:source) { File.read('./spec/fixtures/subscription/success.xml') }
10
+
11
+ it 'must return the code' do
12
+ expect(subject.serialize).to eq({code: '12345'})
13
+ end
14
+ end
15
+
16
+ context 'serializer from a find response' do
17
+ let(:source) { File.read('./spec/fixtures/subscription/find_success.xml') }
18
+
19
+ context 'must a hash with the serialized attributes' do
20
+ let(:data) { subject.serialize_from_search }
21
+
22
+ it { expect(data[:name]).to eq 'Seguro contra roubo do Notebook Prata' }
23
+ it { expect(data[:code]).to eq 'C08984179E9EDF3DD4023F87B71DE349' }
24
+ it { expect(data[:date]).to eq '2011-11-23T13:40:23.000-02:00' }
25
+ it { expect(data[:tracker]).to eq '538C53' }
26
+ it { expect(data[:status]).to eq 'CANCELLED' }
27
+ it { expect(data[:reference]).to eq 'REF1234' }
28
+ it { expect(data[:status]).to eq 'CANCELLED' }
29
+ it { expect(data[:last_event_date]).to eq '2011-11-25T20:04:23.000-02:00' }
30
+ it { expect(data[:charge]).to eq 'auto' }
31
+ it { expect(data[:last_event_date]).to eq '2011-11-25T20:04:23.000-02:00' }
32
+ it { expect(data[:sender][:name]).to eq 'Comprador Istambul' }
33
+ it { expect(data[:sender][:email]).to eq 'c@i.com' }
34
+ it { expect(data[:sender][:phone][:area_code]).to eq '11' }
35
+ it { expect(data[:sender][:phone][:number]).to eq '30389678' }
36
+ it { expect(data[:sender][:address][:street]).to eq 'ALAMEDA ITU' }
37
+ it { expect(data[:sender][:address][:number]).to eq '78' }
38
+ it { expect(data[:sender][:address][:complement]).to eq 'ap. 2601' }
39
+ it { expect(data[:sender][:address][:district]).to eq 'Jardim Paulista' }
40
+ it { expect(data[:sender][:address][:city]).to eq 'SAO PAULO' }
41
+ it { expect(data[:sender][:address][:state]).to eq 'SP' }
42
+ it { expect(data[:sender][:address][:country]).to eq 'BRASIL' }
43
+ it { expect(data[:sender][:address][:postal_code]).to eq '01421000' }
44
+ end
45
+ end
46
+ end