pagseguro-oficial 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -7
  3. data/CHANGELOG.md +9 -3
  4. data/README.md +26 -8
  5. data/examples/abandoned_transactions.rb +16 -4
  6. data/examples/authorization.rb +31 -0
  7. data/examples/authorization_by_code.rb +29 -0
  8. data/examples/authorization_by_notification_code.rb +30 -0
  9. data/examples/boleto_transaction_request.rb +6 -0
  10. data/examples/boot.rb +19 -2
  11. data/examples/create_session.rb +6 -0
  12. data/examples/credit_card_transaction_request.rb +6 -0
  13. data/examples/installment.rb +21 -11
  14. data/examples/invalid_transaction_by_notification_code.rb +14 -1
  15. data/examples/online_debit_transaction.rb +6 -0
  16. data/examples/payment_request.rb +11 -0
  17. data/examples/transaction_by_code.rb +23 -9
  18. data/examples/transaction_by_notification_code.rb +22 -9
  19. data/examples/transaction_by_reference.rb +13 -1
  20. data/examples/transactions_by_date.rb +17 -1
  21. data/lib/pagseguro/account_credentials.rb +14 -0
  22. data/lib/pagseguro/application_credentials.rb +18 -0
  23. data/lib/pagseguro/authorization/collection.rb +26 -0
  24. data/lib/pagseguro/authorization/request_serializer.rb +24 -0
  25. data/lib/pagseguro/authorization/response.rb +49 -0
  26. data/lib/pagseguro/authorization/response_serializer.rb +39 -0
  27. data/lib/pagseguro/authorization.rb +52 -0
  28. data/lib/pagseguro/authorization_request/request_serializer.rb +30 -0
  29. data/lib/pagseguro/authorization_request/response.rb +26 -0
  30. data/lib/pagseguro/authorization_request/response_serializer.rb +18 -0
  31. data/lib/pagseguro/authorization_request.rb +72 -0
  32. data/lib/pagseguro/config.rb +20 -0
  33. data/lib/pagseguro/errors.rb +1 -0
  34. data/lib/pagseguro/extensions/credentiable.rb +17 -0
  35. data/lib/pagseguro/installment.rb +4 -2
  36. data/lib/pagseguro/notification/authorization.rb +15 -0
  37. data/lib/pagseguro/notification/transaction.rb +15 -0
  38. data/lib/pagseguro/notification.rb +0 -10
  39. data/lib/pagseguro/payment_request/serializer.rb +1 -0
  40. data/lib/pagseguro/payment_request.rb +2 -13
  41. data/lib/pagseguro/permission.rb +13 -0
  42. data/lib/pagseguro/request.rb +37 -5
  43. data/lib/pagseguro/transaction/search/search_abandoned.rb +2 -1
  44. data/lib/pagseguro/transaction/search/search_by_date.rb +2 -1
  45. data/lib/pagseguro/transaction/search/search_by_reference.rb +1 -0
  46. data/lib/pagseguro/transaction.rb +27 -25
  47. data/lib/pagseguro/version.rb +1 -1
  48. data/lib/pagseguro.rb +57 -14
  49. data/locales/pt-BR.yml +1 -0
  50. data/pagseguro-oficial.gemspec +0 -1
  51. data/spec/fixtures/authorization/find_authorization.xml +17 -0
  52. data/spec/fixtures/authorization_request/success.xml +4 -0
  53. data/spec/pagseguro/account_credentials_spec.rb +10 -0
  54. data/spec/pagseguro/application_credentials_spec.rb +11 -0
  55. data/spec/pagseguro/authorization/collection_spec.rb +49 -0
  56. data/spec/pagseguro/authorization/request_serializer_spec.rb +11 -0
  57. data/spec/pagseguro/authorization/response_serializer_spec.rb +19 -0
  58. data/spec/pagseguro/authorization/response_spec.rb +35 -0
  59. data/spec/pagseguro/authorization_request/request_serializer_spec.rb +23 -0
  60. data/spec/pagseguro/authorization_request/response_serializer_spec.rb +15 -0
  61. data/spec/pagseguro/authorization_request/response_spec.rb +36 -0
  62. data/spec/pagseguro/authorization_request_spec.rb +62 -0
  63. data/spec/pagseguro/authorization_spec.rb +69 -0
  64. data/spec/pagseguro/errors_spec.rb +17 -5
  65. data/spec/pagseguro/installment/response_spec.rb +3 -1
  66. data/spec/pagseguro/installment_spec.rb +1 -1
  67. data/spec/pagseguro/notification_spec.rb +0 -12
  68. data/spec/pagseguro/pagseguro_spec.rb +15 -15
  69. data/spec/pagseguro/payment_request/serializer_spec.rb +10 -0
  70. data/spec/pagseguro/payment_request_spec.rb +0 -31
  71. data/spec/pagseguro/permission_spec.rb +7 -0
  72. data/spec/pagseguro/request_spec.rb +25 -5
  73. data/spec/pagseguro/session/response_spec.rb +2 -1
  74. data/spec/pagseguro/session_spec.rb +2 -1
  75. data/spec/pagseguro/transaction/search/search_abandoned_spec.rb +15 -0
  76. data/spec/pagseguro/transaction/search_spec.rb +1 -1
  77. data/spec/pagseguro/transaction_request/response_spec.rb +1 -1
  78. data/spec/pagseguro/transaction_request_spec.rb +1 -1
  79. data/spec/pagseguro/transaction_spec.rb +34 -1
  80. data/spec/spec_helper.rb +0 -1
  81. data/spec/support/shared_examples_for_configuration.rb +3 -1
  82. metadata +49 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 195f2fa2ef3756e03ccdde0b6e0d6dd6f632edf3
4
- data.tar.gz: 159f0ddf89ed6d5bd3e25e13d8c292456466be3d
3
+ metadata.gz: a980612b48482830bbc795d21b5e9b42c93fa734
4
+ data.tar.gz: d6d5239ec8867b09b90f1c916e57caeda56542f6
5
5
  SHA512:
6
- metadata.gz: 4e648a26a4dedcc676c19a3f2f9158db9672993529d18889af97bf3bcd9314a2428dbca8c8e3232b78b33d63d852791a5d55c2c5aae83d33e040035d9072cbac
7
- data.tar.gz: c265b5e829a21f3ecf99e8fcc3efd6cb956f252bc5806c8e23fd8fa64474e5a1eb74600333641bd1d60285fee6201256896ed1036e2ae7f494d2bee93eadc597
6
+ metadata.gz: ecb011aceae73b1cc57da82e3ab009b17608c07304b776775cea35f00fa8dfd4ef95139ecf164c22ab3bf268cfeafa9c7251b57d257c89c0e5a330ba5ef393e7
7
+ data.tar.gz: 9bd96ab418caf1824bdcecf0b9301ebf1d5440eeb7fc9bedec9a1fb638a788e9c7b897b92fcde4cc39c3f95253d5d637f454fa86641a16d0ba9a0a92f3c89342
data/.travis.yml CHANGED
@@ -1,14 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
4
- - 2.1.6
3
+ - 2.2.3
4
+ - 2.1.7
5
5
  - 2.0.0
6
6
  - 1.9.3
7
7
  - jruby-19mode
8
8
  notifications:
9
9
  email:
10
- - lucas.renan@codeminer42.com
11
- - vitor.kusiaki@codeminer42.com
12
- - dmitry.rocha@codeminer42.com
13
- slack:
14
- secure: H7PR+eH28CRGZ7E71EQ2xAjkbLX53eXbJ8nadHgx6W2gggNSB8UPw6gqQg/UC0lCbK6ejQ0wE/pEPfLBnCJkqL8mfBr7ADTqZe2fM/YxXQktdOlldJtZaxUikDwOWZSXdOG+3ITdbv/MQW/wehi8UWzFC+XkhJCudOPW1n+9bqs=
10
+ - lucas.renan@codeminer42.com
11
+ - dmitry.rocha@codeminer42.com
12
+ - rafael.belo@codeminer42.com
data/CHANGELOG.md CHANGED
@@ -1,8 +1,14 @@
1
- ## Next release - 2.2.0
1
+ ## Stable
2
2
 
3
- - Checkout transparente
3
+ 2.3.0
4
4
 
5
- ## Stable
5
+ - Modelo de aplicações (autenticação na api como vendedor ou como aplicação)
6
+ - Removendo utilização de threads para armazenar o objeto de configuração (a abordagem com threads não funciona no Rails 4, que é threadsafe)
7
+ - Adicionando deprecation warnings para configuration writers do módulo PagSeguro. Será removido no futuro. Utilizar o bloco de configuração.
8
+
9
+ 2.2.0
10
+
11
+ - Checkout transparente
6
12
 
7
13
  2.1.1
8
14
 
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Biblioteca de integração PagSeguro em Ruby
2
2
 
3
- [![Build Status](https://travis-ci.org/pagseguro/ruby.png?branch=master)](https://travis-ci.org/pagseguro/ruby)
4
-
5
- [![Code Climate](https://codeclimate.com/github/pagseguro/ruby.png)](https://codeclimate.com/github/pagseguro/ruby)
3
+ [![Build Status](https://travis-ci.org/pagseguro/ruby.svg?branch=master)](https://travis-ci.org/pagseguro/ruby)
4
+ [![Code Climate](https://codeclimate.com/github/pagseguro/ruby/badges/gpa.svg)](https://codeclimate.com/github/pagseguro/ruby)
6
5
 
7
6
  ## Descrição
8
7
 
@@ -26,7 +25,7 @@ A biblioteca PagSeguro em Ruby é um conjunto de classes de domínio que facilit
26
25
  - Adicione a biblioteca ao seu Gemfile.
27
26
 
28
27
  ```ruby
29
- gem "pagseguro-oficial", "~> 2.2.0"
28
+ gem "pagseguro-oficial", "~> 2.3.0"
30
29
  ```
31
30
 
32
31
  - Execute o comando `bundle install`.
@@ -37,8 +36,10 @@ Para fazer a autenticação, você precisará configurar as credenciais do PagSe
37
36
 
38
37
  ```ruby
39
38
  PagSeguro.configure do |config|
40
- config.token = "seu token"
41
- config.email = "seu e-mail"
39
+ config.token = "seu token"
40
+ config.email = "seu e-mail"
41
+ config.environment = :production # ou :sandbox. O padrão é production.
42
+ config.encoding = "UTF-8" # ou ISO-8859-1. O padrão é UTF-8.
42
43
  end
43
44
  ```
44
45
 
@@ -200,6 +201,24 @@ visa_installments.each do |installment|
200
201
  end
201
202
  ```
202
203
 
204
+ ## Modelo de aplicações
205
+
206
+ ### Setando autorizações
207
+
208
+ ```ruby
209
+ options = {
210
+ credentials: PagSeguro::ApplicationCredentials.new("app4521929942", "1D47384E6565EBE664DAEF9AD690438B"),
211
+ permissions: [:searches, :notifications],
212
+ notification_url: 'foo.com.br',
213
+ redirect_url: 'bar.com.br'
214
+ }
215
+ response = PagSeguro::Authorization.new(options).authorize
216
+ ```
217
+ Em seguida, acesse o link para confirmar as autorizações
218
+ ```ruby
219
+ response.url
220
+ ```
221
+
203
222
  ## API
204
223
 
205
224
  ### PagSeguro::PaymentRequest (utiliza versão V2)
@@ -287,10 +306,9 @@ payment.max_uses = 100
287
306
  payment.max_age = 3600 # em segundos
288
307
  ```
289
308
 
290
- #### Definindo environment e/ou encoding
309
+ #### Definindo encoding
291
310
 
292
311
  ```ruby
293
- PagSeguro.environment = "production" # production ou sandbox
294
312
  PagSeguro.encoding = "UTF-8" # UTF-8 ou ISO-8859-1
295
313
  ```
296
314
 
@@ -1,10 +1,22 @@
1
1
  require_relative "boot"
2
2
  require "active_support/all"
3
3
 
4
- report = PagSeguro::Transaction.find_abandoned(
5
- starts_at: 30.days.ago,
6
- size: 1
7
- )
4
+ # Abandoned Transactions
5
+ #
6
+ # The acount credentials (EMAIL, TOKEN) are required
7
+ #
8
+ # You can pass the credentials parameters to PagSeguro::Transaction#find_abandoned
9
+
10
+ options = {
11
+ credentials: PagSeguro::AccountCredentials.new('EMAIL', 'TOKEN')
12
+ # You can pass more arguments by params, look (/lib/pagseguro/transaction.rb)
13
+ }
14
+
15
+ report = PagSeguro::Transaction.find_abandoned(options)
16
+
17
+ # OR through the application settings like the boot file example (/examples/boot.rb)
18
+ #
19
+ # report = PagSeguro::Transaction.find_abandoned
8
20
 
9
21
  while report.next_page?
10
22
  report.next_page!
@@ -0,0 +1,31 @@
1
+ require_relative "boot"
2
+
3
+ # Authorization
4
+ #
5
+ # You need to give:
6
+ # - notification_url
7
+ # - redirect_url
8
+ # - permissions defaults to all permissions
9
+ # - applications credentials (APP_ID, APP_KEY)
10
+ #
11
+ # You can pass this parameters to PagSeguro::AuthorizationRequest#new
12
+ #
13
+ # PS: For more details look the class PagSeguro::AuthorizationRequest
14
+
15
+ credentials = PagSeguro::ApplicationCredentials.new('APP_ID', 'APP_KEY')
16
+
17
+ options = {
18
+ credentials: credentials, # Unnecessary if you set in application config
19
+ permissions: [:searches, :notifications],
20
+ notification_url: 'http://example.com/',
21
+ redirect_url: 'http://example.com/'
22
+ }
23
+
24
+ authorization_request = PagSeguro::AuthorizationRequest.new(options)
25
+
26
+ if authorization_request.create
27
+ print "Use this link to confirm authorizations: "
28
+ puts authorization_request.url
29
+ else
30
+ puts authorization_request.errors.join("\n")
31
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'boot'
2
+
3
+ # Authorization by code
4
+ #
5
+ # You need to give:
6
+ # - authorization code
7
+ # - application credentials (APP_ID, APP_KEY) OR account credentials (EMAIL, TOKEN)
8
+ #
9
+ # You can pass this parameters to PagSeguro::Authorization#find_by_code
10
+ #
11
+ # PS: For more details look the class PagSeguro::Authorization#find_by_code
12
+
13
+ # credentials = PagSeguro::AccountCredentials.new("EMAIL", "TOKEN")
14
+ credentials = PagSeguro::ApplicationCredentials.new("APP_ID", "APP_KEY")
15
+
16
+ options = { credentials: credentials } # Unnecessary if you set in application config
17
+
18
+ authorization = PagSeguro::Authorization.find_by_code('AUTHORIZATION_CODE', options)
19
+
20
+ if authorization.errors.any?
21
+ puts authorization.errors.join("\n")
22
+ else
23
+ authorization.permissions.each do |permission, index|
24
+ puts "Permission #{index}: "
25
+ puts " code: #{permission.code}"
26
+ puts " status: #{permission.status}"
27
+ end
28
+ puts
29
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'boot'
2
+
3
+ # Authorization by notification code
4
+ #
5
+ # You need to give:
6
+ # - authorization code
7
+ # - application credentials (APP_ID, APP_KEY)
8
+ #
9
+ # You can pass this parameters to PagSeguro::Authorization#find_by_notification_code
10
+ #
11
+ # PS: For more details look the class PagSeguro::Authorization#find_by_notification_code
12
+
13
+
14
+ credentials = PagSeguro::ApplicationCredentials.new('APP_ID', 'APP_KEY')
15
+
16
+ options = { credentials: credentials } # Unnecessary if you set in application config
17
+
18
+ authorization = PagSeguro::Authorization.find_by_notification_code('NOTIFICATION_CODE', options)
19
+
20
+ puts authorization.errors.inspect
21
+
22
+ if authorization.errors.any?
23
+ puts authorization.errors.join("\n")
24
+ else
25
+ authorization.permissions.each do |permission|
26
+ puts "Permission: "
27
+ puts permission.code
28
+ puts permission.status
29
+ end
30
+ end
@@ -1,5 +1,11 @@
1
1
  require_relative "boot"
2
2
 
3
+ # Credit card transaction request
4
+ #
5
+ # You need to set your AccountCredentials (EMAIL, TOKEN) in the application config
6
+ #
7
+ # P.S: See the boot file example for more details
8
+
3
9
  payment = PagSeguro::BoletoTransactionRequest.new
4
10
  payment.notification_url = "http://www.meusite.com.br/notification"
5
11
  payment.payment_mode = "default"
data/examples/boot.rb CHANGED
@@ -4,6 +4,23 @@ require "pagseguro"
4
4
  I18n.locale = "pt-BR"
5
5
 
6
6
  PagSeguro.configure do |config|
7
- config.token = ENV.fetch("PAGSEGURO_TOKEN")
8
- config.email = ENV.fetch("PAGSEGURO_EMAIL")
7
+ # You can setup with Application Credentials trough TOKEN and EMAIL
8
+ # config.token = ENV.fetch("PAGSEGURO_TOKEN")
9
+ # config.email = ENV.fetch("PAGSEGURO_EMAIL")
10
+ #
11
+ # OR with Application Credentials through APP_ID and APP_KEY
12
+ # config.app_id = ENV.fetch("PAGSEGURO_APP_ID")
13
+ # config.app_key = ENV.fetch("PAGSEGURO_APP_KEY")
14
+ #
15
+ #
16
+ # Ps: You can set the credentials when you to call some service like:
17
+ # For Account credentials based on EMAIL and TOKEN
18
+ # - PagSeguro::ApplicationCredentials.new("appteste_1", "TESTE11111")
19
+ #
20
+ # OR
21
+ #
22
+ # For Application credentials based on APP_KEY and APP_ID
23
+ # - PagSeguro::AccountCredentials.new("user@example.com", "token")
24
+
25
+ config.environment = :sandbox
9
26
  end
@@ -1,5 +1,11 @@
1
1
  require_relative "boot"
2
2
 
3
+ # Create Session
4
+ #
5
+ # You need to set your AccountCredentials (EMAIL, TOKEN) in the application config
6
+ #
7
+ # P.S: See the boot file example for more details.
8
+
3
9
  session = PagSeguro::Session.create
4
10
 
5
11
  if session.errors.any?
@@ -1,5 +1,11 @@
1
1
  require_relative "boot"
2
2
 
3
+ # Credit card transaction request
4
+ #
5
+ # You need to set your AccountCredentials (EMAIL, TOKEN) in the application config
6
+ #
7
+ # P.S: See the boot file example for more details.
8
+
3
9
  payment = PagSeguro::CreditCardTransactionRequest.new
4
10
  payment.notification_url = "http://www.meusite.com.br/notification"
5
11
  payment.payment_mode = "gateway"
@@ -1,30 +1,40 @@
1
1
  require_relative "boot"
2
2
 
3
- installments = PagSeguro::Installment.find("100.00")
3
+ # Installment
4
+ #
5
+ # Required AccountCredentials
6
+ #
7
+ # You need to give:
8
+ # - amount
9
+ # - brand_card
10
+ # - account credentials (EMAIL, TOKEN)
11
+ #
12
+ # You can pass this parameters to PagSeguro::Installment#find
13
+
14
+ credentials = PagSeguro::AccountCredentials.new('EMAIL', 'TOKEN')
15
+
16
+ options = {
17
+ credentials: credentials # Unnecessary if you set in application config
18
+ }
19
+
20
+ installments = PagSeguro::Installment.find("100.00", nil, options)
4
21
 
5
22
  if installments.errors.any?
6
- puts "=> ERRORS"
7
23
  puts installments.errors.join("\n")
8
- puts installments.inspect
9
24
  else
10
25
  puts "=> INSTALLMENTS"
11
26
  puts
12
27
  installments.each do |installment|
13
28
  puts installment.inspect
14
29
  end
15
- end
16
30
 
17
- visa_installments = PagSeguro::Installment.find("100.00", "visa")
31
+ visa_installments = PagSeguro::Installment.find("100.00", :visa, options)
18
32
 
19
- puts
20
- if installments.errors.any?
21
- puts "=> ERRORS"
22
- puts installments.errors.join("\n")
23
- puts installments.inspect
24
- else
33
+ puts
25
34
  puts "=> VISA INSTALLMENTS"
26
35
  puts
27
36
  visa_installments.each do |installment|
28
37
  puts installment.inspect
29
38
  end
30
39
  end
40
+
@@ -1,6 +1,19 @@
1
1
  require_relative "boot"
2
2
 
3
- transaction = PagSeguro::Transaction.find_by_notification_code("Invalid")
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)
4
17
 
5
18
  if transaction.errors.any?
6
19
  puts transaction.errors.join("\n")
@@ -1,5 +1,11 @@
1
1
  require_relative "boot"
2
2
 
3
+ # Credit card transaction request
4
+ #
5
+ # You need to set your AccountCredentials (EMAIL, TOKEN) in the application config
6
+ #
7
+ # P.S: See the boot file example for more details.
8
+
3
9
  payment = PagSeguro::OnlineDebitTransactionRequest.new
4
10
  payment.notification_url = "http://www.meusite.com.br/notification"
5
11
  payment.payment_mode = "gateway"
@@ -1,11 +1,22 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require_relative "boot"
3
3
 
4
+ # Payment request
5
+ #
6
+ # You need to set your AccountCredentials (EMAIL, TOKEN) in the application config
7
+ #
8
+ # P.S: See the boot file example for more details.
9
+
4
10
  payment = PagSeguro::PaymentRequest.new
5
11
  payment.abandon_url = "http://dev.simplesideias.com.br/?abandoned"
6
12
  payment.notification_url = "http://dev.simplesideias.com.br/?notification"
7
13
  payment.redirect_url = "http://dev.simplesideias.com.br/?redirect"
8
14
 
15
+ # if you don't want use the application config, can give your credentials object to payment request
16
+ #
17
+ # payment.credentials = PagSeguro::AccountCredentials.new('rafaelrpbelo@gmail.com', 'E280E0A9B6FA48A2AA9E4E73B5A6FC60')
18
+
19
+
9
20
  payment.items << {
10
21
  id: 1234,
11
22
  description: %[Televisão 19" Sony],
@@ -1,9 +1,22 @@
1
1
  require_relative "boot"
2
2
 
3
- transaction = PagSeguro::Transaction.find_by_code("E69FCE5813A142C29EB9B9652BCDC1A8")
3
+ # Transaction by code
4
+ #
5
+ # You need to give:
6
+ # - transaction code
7
+ # - account credentials (EMAIL, TOKEN) OR application credentials (APP_ID, APP_KEY)
8
+ #
9
+ # You can pass this parameters to PagSeguro::Transaction#find_by_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_code("TRANSACTION_CODE", options)
4
17
 
5
18
  if transaction.errors.any?
6
- transaction.errors.join("\n")
19
+ puts transaction.errors.join("\n")
7
20
  else
8
21
  puts "=> Transaction"
9
22
  puts " code: #{transaction.code}"
@@ -19,18 +32,19 @@ else
19
32
  puts " intermediation rate amount: #{transaction.creditor_fees.intermediation_rate_amount.to_f}"
20
33
  puts " intermediation fee amount: #{transaction.creditor_fees.intermediation_fee_amount.to_f}"
21
34
  puts " commission fee amount: #{transaction.creditor_fees.commission_fee_amount.to_f}"
35
+ puts " commission fee amount: #{transaction.creditor_fees.commission_fee_amount.to_f}"
22
36
  puts " efrete: #{transaction.creditor_fees.efrete.to_f}"
23
37
  puts " net amount: #{transaction.net_amount.to_f}"
24
38
  puts " extra amount: #{transaction.extra_amount.to_f}"
25
- puts " installment count: #{transaction.installments}"
26
39
 
27
- puts " => Payment Release"
40
+ puts " => Payments"
41
+ puts " installment count: #{transaction.installments}"
28
42
  transaction.payment_releases.each do |release|
29
- puts " current installment: #{release.installment}"
30
- puts " total amount: #{release.total_amount.to_f}"
31
- puts " release amount: #{release.release_amount.to_f}"
32
- puts " status: #{release.status}"
33
- puts " release date: #{release.release_date}"
43
+ puts " current installment: #{release.installment}"
44
+ puts " total amount: #{release.total_amount.to_f}"
45
+ puts " release amount: #{release.release_amount.to_f}"
46
+ puts " status: #{release.status}"
47
+ puts " release date: #{release.release_date}"
34
48
  end
35
49
 
36
50
  puts " => Items"
@@ -1,9 +1,22 @@
1
1
  require_relative "boot"
2
2
 
3
- transaction = PagSeguro::Transaction.find_by_notification_code("739D69-79C052C05280-55542D9FBB33-4AB2D0")
3
+ # Transaction by notification code
4
+ #
5
+ # You need to give:
6
+ # - transaction notification code
7
+ # - account credentials (EMAIL, TOKEN) OR application credentials (APP_ID, APP_KEY)
8
+ #
9
+ # You can pass this parameters to PagSeguro::Transaction#find_by_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("NOTIFICATION_CODE", options)
4
17
 
5
18
  if transaction.errors.any?
6
- transaction.errors.join("\n")
19
+ puts transaction.errors.join("\n")
7
20
  else
8
21
  puts "=> Transaction"
9
22
  puts " code: #{transaction.code}"
@@ -23,15 +36,15 @@ else
23
36
  puts " efrete: #{transaction.creditor_fees.efrete.to_f}"
24
37
  puts " net amount: #{transaction.net_amount.to_f}"
25
38
  puts " extra amount: #{transaction.extra_amount.to_f}"
26
- puts " installment count: #{transaction.installments}"
27
39
 
28
- puts " => Payment Release"
40
+ puts " => Payments"
41
+ puts " installment count: #{transaction.installments}"
29
42
  transaction.payment_releases.each do |release|
30
- puts " current installment: #{release.installment}"
31
- puts " total amount: #{release.total_amount.to_f}"
32
- puts " release amount: #{release.release_amount.to_f}"
33
- puts " status: #{release.status}"
34
- puts " release date: #{release.release_date}"
43
+ puts " current installment: #{release.installment}"
44
+ puts " total amount: #{release.total_amount.to_f}"
45
+ puts " release amount: #{release.release_amount.to_f}"
46
+ puts " status: #{release.status}"
47
+ puts " release date: #{release.release_date}"
35
48
  end
36
49
 
37
50
  puts " => Items"
@@ -1,6 +1,18 @@
1
1
  require_relative 'boot'
2
2
 
3
- transaction = PagSeguro::Transaction.find_by_reference("REF1234")
3
+ # Transaction by reference
4
+ #
5
+ # You need to give:
6
+ # - reference code
7
+ # - account credentials (EMAIL, TOKEN)
8
+ #
9
+ # You can pass this parameters to PagSeguro::Transaction#find_by_reference
10
+
11
+ credentials = PagSeguro::AccountCredentials.new('EMAIL', 'TOKEN')
12
+
13
+ options = { credentials: credentials } # Unnecessary if you set in application config
14
+
15
+ transaction = PagSeguro::Transaction.find_by_reference("REFERENCE_CODE", options)
4
16
 
5
17
  while transaction.next_page?
6
18
  transaction.next_page!
@@ -1,7 +1,23 @@
1
1
  require_relative "boot"
2
2
  require "active_support/all"
3
3
 
4
- report = PagSeguro::Transaction.find_by_date(starts_at: 29.days.ago, per_page: 1)
4
+ # Transactions by date
5
+ #
6
+ # You need to give:
7
+ # - reference code
8
+ # - account credentials (EMAIL, TOKEN)
9
+ #
10
+ # You can pass this parameters to PagSeguro::Transaction#find_by_date
11
+
12
+ credentials = PagSeguro::AccountCredentials.new('EMAIL', 'TOKEN')
13
+
14
+ options = {
15
+ starts_at: 29.days.ago,
16
+ per_page: 1,
17
+ credentials: credentials # Unnecessary if you set in application config
18
+ }
19
+
20
+ report = PagSeguro::Transaction.find_by_date(options)
5
21
 
6
22
  while report.next_page?
7
23
  report.next_page!
@@ -0,0 +1,14 @@
1
+ module PagSeguro
2
+ class AccountCredentials
3
+ # The user email
4
+ attr_accessor :email
5
+
6
+ # The token related to the user
7
+ attr_accessor :token
8
+
9
+ def initialize(email, token)
10
+ @email = email
11
+ @token = token
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module PagSeguro
2
+ class ApplicationCredentials
3
+ # The application id
4
+ attr_accessor :app_id
5
+
6
+ # The token related to the application
7
+ attr_accessor :app_key
8
+
9
+ # The application authorization code
10
+ attr_accessor :authorization_code
11
+
12
+ def initialize(app_id, app_key, authorization_code = nil)
13
+ @app_id = app_id
14
+ @app_key = app_key
15
+ @authorization_code = authorization_code
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ module PagSeguro
2
+ class Authorization
3
+ class Collection
4
+ extend Forwardable
5
+
6
+ def_delegators :@authorizations, :each, :empty?, :any?
7
+
8
+ def initialize(options)
9
+ @errors = options[:errors] if options[:errors]
10
+ @authorizations = instantiate_authorizations(options[:authorizations])
11
+ end
12
+
13
+ def errors
14
+ @errors ||= Errors.new
15
+ end
16
+
17
+ private
18
+ def instantiate_authorizations(authorizations)
19
+ return [] unless authorizations
20
+ authorizations.map do |authorization|
21
+ Authorization.new(authorization)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ module PagSeguro
2
+ class Authorization
3
+ class RequestSerializer
4
+ attr_reader :authorization
5
+
6
+ def initialize(authorization)
7
+ @authorization = authorization
8
+ end
9
+
10
+ def to_params
11
+ params[:credentials] = authorization.credentials if authorization.respond_to? :credentials
12
+ params[:initialDate] = authorization.initial_date if authorization.respond_to? :initial_date
13
+ params[:finalDate] = authorization.final_date if authorization.respond_to? :final_date
14
+
15
+ params
16
+ end
17
+
18
+ private
19
+ def params
20
+ @params ||= {}
21
+ end
22
+ end
23
+ end
24
+ end