pagseguro-oficial 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +17 -1
  4. data/Gemfile +0 -2
  5. data/README.md +1 -1
  6. data/docs/transparent_checkout.md +3 -3
  7. data/examples/authorization/create_authorization.rb +32 -0
  8. data/examples/authorization/create_authorization_with_account.rb +56 -0
  9. data/examples/authorization/{authorization_by_code.rb → search/search_authorization_by_code.rb} +4 -4
  10. data/examples/authorization/search/search_authorization_by_date.rb +35 -0
  11. data/examples/authorization/{authorization_by_notification_code.rb → search/search_authorization_by_notification_code.rb} +4 -5
  12. data/examples/authorization/search/search_authorization_by_reference.rb +31 -0
  13. data/examples/{payment_request.rb → checkout/create_payment_request.rb} +5 -7
  14. data/examples/{transaction/abandoned_transactions.rb → checkout/search/search_abandoned_transactions.rb} +6 -3
  15. data/examples/{transaction/transaction_by_code.rb → checkout/search/search_transaction_by_code.rb} +3 -3
  16. data/examples/{transaction/transaction_by_notification_code.rb → checkout/search/search_transaction_by_notification_code.rb} +3 -3
  17. data/examples/{transaction/transaction_by_reference.rb → checkout/search/search_transaction_by_reference.rb} +3 -3
  18. data/examples/{transaction/transaction_status_history.rb → checkout/search/search_transaction_status_history.rb} +2 -2
  19. data/examples/{transaction/transactions_by_date.rb → checkout/search/search_transactions_by_date.rb} +3 -3
  20. data/examples/{transaction/boleto_transaction_request.rb → direct/create_transaction_using_boleto.rb} +1 -1
  21. data/examples/{transaction/credit_card_transaction_request.rb → direct/create_transaction_using_credit_card.rb} +1 -1
  22. data/examples/{transaction/online_debit_transaction.rb → direct/create_transaction_using_online_debit.rb} +1 -1
  23. data/examples/{installment.rb → get_installments.rb} +3 -3
  24. data/examples/{transaction/transaction_cancellation.rb → request_transaction_cancellation.rb} +2 -2
  25. data/examples/{authorization/authorization.rb → split_payment/create_authorization.rb} +5 -4
  26. data/examples/split_payment/create_payment_request.rb +71 -0
  27. data/lib/pagseguro.rb +14 -8
  28. data/lib/pagseguro/account.rb +29 -0
  29. data/lib/pagseguro/authorization.rb +10 -4
  30. data/lib/pagseguro/authorization/collection.rb +3 -1
  31. data/lib/pagseguro/authorization/request_serializer.rb +6 -6
  32. data/lib/pagseguro/authorization/response.rb +2 -2
  33. data/lib/pagseguro/authorization_request.rb +16 -4
  34. data/lib/pagseguro/authorization_request/request_serializer.rb +127 -15
  35. data/lib/pagseguro/authorization_request/response.rb +2 -2
  36. data/lib/pagseguro/company.rb +41 -0
  37. data/lib/pagseguro/document.rb +4 -0
  38. data/lib/pagseguro/documents.rb +5 -0
  39. data/lib/pagseguro/errors.rb +27 -5
  40. data/lib/pagseguro/extensions/collection_object.rb +34 -0
  41. data/lib/pagseguro/item.rb +4 -0
  42. data/lib/pagseguro/items.rb +10 -17
  43. data/lib/pagseguro/partner.rb +20 -0
  44. data/lib/pagseguro/payment_request.rb +30 -2
  45. data/lib/pagseguro/payment_request/{serializer.rb → request_serializer.rb} +86 -1
  46. data/lib/pagseguro/person.rb +40 -0
  47. data/lib/pagseguro/phone.rb +8 -0
  48. data/lib/pagseguro/phones.rb +5 -0
  49. data/lib/pagseguro/receiver.rb +17 -0
  50. data/lib/pagseguro/receiver_split.rb +15 -0
  51. data/lib/pagseguro/request.rb +25 -1
  52. data/lib/pagseguro/transaction.rb +7 -5
  53. data/lib/pagseguro/transaction_cancellation.rb +3 -6
  54. data/lib/pagseguro/transaction_cancellation/response.rb +7 -6
  55. data/lib/pagseguro/{refund.rb → transaction_refund.rb} +2 -2
  56. data/lib/pagseguro/{refund → transaction_refund}/request_serializer.rb +1 -1
  57. data/lib/pagseguro/{refund → transaction_refund}/response.rb +9 -9
  58. data/lib/pagseguro/{refund → transaction_refund}/response_serializer.rb +1 -1
  59. data/lib/pagseguro/transaction_request.rb +1 -4
  60. data/lib/pagseguro/transaction_request/response.rb +8 -7
  61. data/lib/pagseguro/version.rb +1 -1
  62. data/locales/pt-BR.yml +1 -0
  63. data/pagseguro-oficial.gemspec +13 -13
  64. data/spec/fixtures/authorization/search_authorization.xml +47 -0
  65. data/spec/fixtures/authorization_request/authorization_request.xml +11 -0
  66. data/spec/fixtures/authorization_request/authorization_request_with_account.xml +47 -0
  67. data/spec/pagseguro/account_spec.rb +27 -0
  68. data/spec/pagseguro/authorization/collection_spec.rb +3 -3
  69. data/spec/pagseguro/authorization/request_serializer_spec.rb +1 -2
  70. data/spec/pagseguro/authorization/response_spec.rb +70 -15
  71. data/spec/pagseguro/authorization_request/request_serializer_spec.rb +314 -14
  72. data/spec/pagseguro/authorization_request_spec.rb +96 -31
  73. data/spec/pagseguro/authorization_spec.rb +52 -10
  74. data/spec/pagseguro/company_spec.rb +12 -0
  75. data/spec/pagseguro/documents_spec.rb +37 -0
  76. data/spec/pagseguro/errors_spec.rb +45 -6
  77. data/spec/pagseguro/extensions/collection_object_spec.rb +77 -0
  78. data/spec/pagseguro/features/create_transaction_request_spec.rb +2 -2
  79. data/spec/pagseguro/installment/response_spec.rb +5 -3
  80. data/spec/pagseguro/installment_spec.rb +5 -2
  81. data/spec/pagseguro/items_spec.rb +104 -12
  82. data/spec/pagseguro/pagseguro_spec.rb +8 -8
  83. data/spec/pagseguro/partner_spec.rb +8 -0
  84. data/spec/pagseguro/payment_request/request_serializer_spec.rb +251 -0
  85. data/spec/pagseguro/payment_request_spec.rb +67 -11
  86. data/spec/pagseguro/person_spec.rb +10 -0
  87. data/spec/pagseguro/phones_spec.rb +38 -0
  88. data/spec/pagseguro/receiver_spec.rb +6 -0
  89. data/spec/pagseguro/receiver_split_spec.rb +7 -0
  90. data/spec/pagseguro/request_spec.rb +27 -4
  91. data/spec/pagseguro/session/response_spec.rb +6 -2
  92. data/spec/pagseguro/session_spec.rb +5 -2
  93. data/spec/pagseguro/transaction/response_spec.rb +14 -8
  94. data/spec/pagseguro/transaction/search_spec.rb +15 -8
  95. data/spec/pagseguro/transaction_cancellation/response_spec.rb +6 -3
  96. data/spec/pagseguro/transaction_cancellation_spec.rb +7 -5
  97. data/spec/pagseguro/{refund → transaction_refund}/request_serializer_spec.rb +3 -3
  98. data/spec/pagseguro/{refund → transaction_refund}/response_serializer_spec.rb +1 -1
  99. data/spec/pagseguro/{refund → transaction_refund}/response_spec.rb +3 -3
  100. data/spec/pagseguro/{refund_spec.rb → transaction_refund_spec.rb} +15 -7
  101. data/spec/pagseguro/transaction_request/request_serializer_spec.rb +9 -9
  102. data/spec/pagseguro/transaction_request/response_spec.rb +5 -2
  103. data/spec/pagseguro/transaction_request_spec.rb +14 -9
  104. data/spec/pagseguro/transaction_spec.rb +37 -30
  105. data/spec/spec_helper.rb +0 -3
  106. data/spec/support/ensure_type_macro.rb +20 -2
  107. data/{examples/refund.rb → transaction/transaction_refund.rb} +1 -1
  108. metadata +112 -96
  109. data/examples/transaction/invalid_transaction_by_notification_code.rb +0 -22
  110. data/lib/pagseguro/refund/serializer.rb +0 -24
  111. data/lib/pagseguro/transaction_cancellation/serializer.rb +0 -18
  112. data/spec/pagseguro/payment_request/serializer_spec.rb +0 -166
  113. data/spec/pagseguro/refund/serializer_spec.rb +0 -15
  114. data/spec/pagseguro/transaction_cancellation/serializer_spec.rb +0 -13
@@ -1,22 +0,0 @@
1
- require_relative "../boot"
2
-
3
- # Invalid transaction by notification code
4
- #
5
- # You need to give:
6
- # - notification code (invalid)
7
- # - account credentials (EMAIL, TOKEN) OR application credentials (APP_ID, APP_KEY)
8
- #
9
- # You can pass this parameters to PagSeguro::Transaction#find_by_notification_code
10
-
11
- # credentials = PagSeguro::ApplicationCredentials.new('APP_ID', 'APP_KEY')
12
- credentials = PagSeguro::AccountCredentials.new('EMAIL', 'TOKEN')
13
-
14
- options = { credentials: credentials } # Unnecessary if you set in application config
15
-
16
- transaction = PagSeguro::Transaction.find_by_notification_code("Invalid", options)
17
-
18
- if transaction.errors.any?
19
- puts transaction.errors.join("\n")
20
- else
21
- puts transaction
22
- end
@@ -1,24 +0,0 @@
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
@@ -1,18 +0,0 @@
1
- module PagSeguro
2
- class TransactionCancellation
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
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,166 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe PagSeguro::PaymentRequest::Serializer do
4
- let(:payment_request) { PagSeguro::PaymentRequest.new }
5
- let(:params) { serializer.to_params }
6
- subject(:serializer) { described_class.new(payment_request) }
7
-
8
- context "global configuration serialization" do
9
- before do
10
- PagSeguro.receiver_email = "RECEIVER"
11
- end
12
-
13
- it { expect(params).to include(receiverEmail: PagSeguro.receiver_email) }
14
- end
15
-
16
- context "generic attributes serialization" do
17
- before do
18
- payment_request.stub({
19
- currency: "BRL",
20
- reference: "REF123",
21
- extra_amount: 1234.50,
22
- redirect_url: "REDIRECT_URL",
23
- notification_url: "NOTIFICATION_URL",
24
- abandon_url: "ABANDON_URL",
25
- max_uses: 5,
26
- max_age: 3600
27
- })
28
- end
29
-
30
- it { expect(params).to include(currency: "BRL") }
31
- it { expect(params).to include(reference: "REF123") }
32
- it { expect(params).to include(extraAmount: "1234.50") }
33
- it { expect(params).to include(redirectURL: "REDIRECT_URL") }
34
- it { expect(params).to include(notificationURL: "NOTIFICATION_URL") }
35
- it { expect(params).to include(abandonURL: "ABANDON_URL") }
36
- it { expect(params).to include(maxUses: 5) }
37
- it { expect(params).to include(maxAge: 3600) }
38
- end
39
-
40
- context "shipping serialization" do
41
- before do
42
- payment_request.shipping = PagSeguro::Shipping.new({
43
- type_id: 1,
44
- cost: 1234.56
45
- })
46
- end
47
-
48
- it { expect(params).to include(shippingType: 1) }
49
- it { expect(params).to include(shippingCost: "1234.56") }
50
- end
51
-
52
- context "address serialization" do
53
- before do
54
- address = PagSeguro::Address.new({
55
- street: "STREET",
56
- state: "STATE",
57
- city: "CITY",
58
- postal_code: "POSTAL_CODE",
59
- district: "DISTRICT",
60
- number: "NUMBER",
61
- complement: "COMPLEMENT"
62
- })
63
-
64
- shipping = double(address: address).as_null_object
65
-
66
- payment_request.stub(
67
- shipping: shipping
68
- )
69
- end
70
-
71
- it { expect(params).to include(shippingAddressStreet: "STREET") }
72
- it { expect(params).to include(shippingAddressCountry: "BRA") }
73
- it { expect(params).to include(shippingAddressState: "STATE") }
74
- it { expect(params).to include(shippingAddressCity: "CITY") }
75
- it { expect(params).to include(shippingAddressPostalCode: "POSTAL_CODE") }
76
- it { expect(params).to include(shippingAddressDistrict: "DISTRICT") }
77
- it { expect(params).to include(shippingAddressNumber: "NUMBER") }
78
- it { expect(params).to include(shippingAddressComplement: "COMPLEMENT") }
79
- end
80
-
81
- context "sender serialization" do
82
- before do
83
- sender = PagSeguro::Sender.new({
84
- email: "EMAIL",
85
- name: "NAME",
86
- cpf: "CPF"
87
- })
88
-
89
- payment_request.stub(sender: sender)
90
- end
91
-
92
- it { expect(params).to include(senderEmail: "EMAIL") }
93
- it { expect(params).to include(senderName: "NAME") }
94
- it { expect(params).to include(senderCPF: "CPF") }
95
- end
96
-
97
- context "phone serialization" do
98
- before do
99
- sender = PagSeguro::Sender.new({
100
- phone: {
101
- area_code: "AREA_CODE",
102
- number: "NUMBER"
103
- }
104
- })
105
-
106
- payment_request.stub(sender: sender)
107
- end
108
-
109
- it { expect(params).to include(senderAreaCode: "AREA_CODE") }
110
- it { expect(params).to include(senderPhone: "NUMBER") }
111
- end
112
-
113
- context "items serialization" do
114
- def build_item(index)
115
- PagSeguro::Item.new({
116
- id: "ID#{index}",
117
- description: "DESC#{index}",
118
- quantity: "QTY#{index}",
119
- amount: index * 100 + 0.12,
120
- weight: "WEIGHT#{index}",
121
- shipping_cost: index * 100 + 0.34
122
- })
123
- end
124
-
125
- shared_examples_for "item serialization" do |index|
126
- it { expect(params).to include("itemId#{index}" => "ID#{index}") }
127
- it { expect(params).to include("itemDescription#{index}" => "DESC#{index}") }
128
- it { expect(params).to include("itemAmount#{index}" => "#{index}00.12") }
129
- it { expect(params).to include("itemShippingCost#{index}" => "#{index}00.34") }
130
- it { expect(params).to include("itemQuantity#{index}" => "QTY#{index}") }
131
- it { expect(params).to include("itemWeight#{index}" => "WEIGHT#{index}") }
132
- end
133
-
134
- before do
135
- payment_request.items << build_item(1)
136
- payment_request.items << build_item(2)
137
- end
138
-
139
- it_behaves_like "item serialization", 1
140
- it_behaves_like "item serialization", 2
141
- end
142
-
143
- context "credentials serialization" do
144
- before do
145
- credentials = PagSeguro::ApplicationCredentials.new(
146
- "app123", "qwerty", "authocode"
147
- )
148
-
149
- payment_request.stub(credentials: credentials)
150
- end
151
- end
152
-
153
- context "extra params serialization" do
154
- before do
155
- payment_request.stub({
156
- extra_params: [
157
- { extraParam: 'param_value' },
158
- { newExtraParam: 'extra_param_value' }
159
- ]
160
- })
161
- end
162
-
163
- it { expect(params).to include(extraParam: 'param_value') }
164
- it { expect(params).to include(newExtraParam: 'extra_param_value') }
165
- end
166
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe PagSeguro::Refund::Serializer do
4
- let(:refund) { PagSeguro::Refund.new }
5
- let(:params) { serializer.to_params }
6
- subject(:serializer) { described_class.new(refund) }
7
-
8
- before do
9
- refund.transaction_code = "1234"
10
- refund.value = 100.50
11
- end
12
-
13
- it { expect(params).to include(transactionCode: "1234") }
14
- it { expect(params).to include(refundValue: "100.50") }
15
- end
@@ -1,13 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe PagSeguro::TransactionCancellation::Serializer do
4
- let(:cancellation) { PagSeguro::TransactionCancellation.new }
5
- let(:params) { serializer.to_params }
6
- subject(:serializer) { described_class.new(cancellation) }
7
-
8
- before do
9
- cancellation.transaction_code = "1234"
10
- end
11
-
12
- it { expect(params).to include(transactionCode: "1234") }
13
- end