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
data/lib/pagseguro.rb CHANGED
@@ -6,12 +6,24 @@ require "nokogiri"
6
6
  require "aitch"
7
7
  require "i18n"
8
8
 
9
- require "pagseguro/version"
10
- require "pagseguro/config"
11
-
12
9
  require "pagseguro/extensions/mass_assignment"
13
10
  require "pagseguro/extensions/ensure_type"
11
+ require "pagseguro/extensions/credentiable"
12
+
13
+ require "pagseguro/version"
14
+ require "pagseguro/config"
14
15
 
16
+ require "pagseguro/account_credentials"
17
+ require "pagseguro/application_credentials"
18
+ require "pagseguro/authorization"
19
+ require "pagseguro/authorization/collection"
20
+ require "pagseguro/authorization/request_serializer"
21
+ require "pagseguro/authorization/response_serializer"
22
+ require "pagseguro/authorization/response"
23
+ require "pagseguro/authorization_request"
24
+ require "pagseguro/authorization_request/request_serializer"
25
+ require "pagseguro/authorization_request/response_serializer"
26
+ require "pagseguro/authorization_request/response"
15
27
  require "pagseguro/creditor_fee"
16
28
  require "pagseguro/errors"
17
29
  require "pagseguro/exceptions"
@@ -36,12 +48,15 @@ require "pagseguro/payment_request"
36
48
  require "pagseguro/payment_request/serializer"
37
49
  require "pagseguro/payment_request/response"
38
50
  require "pagseguro/payment_status"
51
+ require "pagseguro/permission"
39
52
  require "pagseguro/request"
40
53
  require "pagseguro/sender"
41
54
  require "pagseguro/session"
42
55
  require "pagseguro/session/response"
43
56
  require "pagseguro/session/response_serializer"
44
57
  require "pagseguro/notification"
58
+ require "pagseguro/notification/authorization"
59
+ require "pagseguro/notification/transaction"
45
60
  require "pagseguro/transaction"
46
61
  require "pagseguro/transaction/response"
47
62
  require "pagseguro/transaction/serializer"
@@ -64,19 +79,44 @@ module PagSeguro
64
79
  class << self
65
80
  # Delegates some calls to the config object
66
81
  extend Forwardable
67
- def_delegators :configuration, :email, :receiver_email, :token
68
- def_delegators :configuration, :email=, :receiver_email=, :token=
82
+ def_delegators :configuration, :email, :receiver_email, :token,
83
+ :environment, :encoding, :app_id, :app_key
69
84
 
70
- # The encoding that will be used.
71
- attr_accessor :encoding
85
+ def email=(email)
86
+ warn "[DEPRECATION] `email=` is deprecated and will be removed. Please use configuration block instead."
87
+ configuration.email = email
88
+ end
72
89
 
73
- # The PagSeguro environment.
74
- # +production+ or +sandbox+.
75
- attr_accessor :environment
90
+ def receiver_email=(receiver_email)
91
+ warn "[DEPRECATION] `receiver_email=` is deprecated and will be removed. Please use configuration block instead."
92
+ configuration.receiver_email = receiver_email
93
+ end
94
+
95
+ def token=(token)
96
+ warn "[DEPRECATION] `token=` is deprecated and will be removed. Please use configuration block instead."
97
+ configuration.token = token
98
+ end
99
+
100
+ def environment=(environment)
101
+ warn "[DEPRECATION] `environment=` is deprecated and will be removed. Please use configuration block instead."
102
+ configuration.environment = environment
103
+ end
104
+
105
+ def encoding=(encoding)
106
+ warn "[DEPRECATION] `encoding=` is deprecated and will be removed. Please use configuration block instead."
107
+ configuration.encoding = encoding
108
+ end
76
109
  end
77
110
 
78
- self.encoding = "UTF-8"
79
- self.environment = :production
111
+ # Returns an object with the configured account credentials
112
+ def self.account_credentials
113
+ PagSeguro::AccountCredentials.new(PagSeguro.email, PagSeguro.token)
114
+ end
115
+
116
+ # Returns an object with the configured application credentials
117
+ def self.application_credentials
118
+ PagSeguro::ApplicationCredentials.new(PagSeguro.app_id, PagSeguro.app_key)
119
+ end
80
120
 
81
121
  # Register endpoints by environment.
82
122
  def self.uris
@@ -99,9 +139,9 @@ module PagSeguro
99
139
  root[type.to_sym]
100
140
  end
101
141
 
102
- # The configuration intance for the thread
142
+ # The configuration instance
103
143
  def self.configuration
104
- Thread.current[:pagseguro_config] ||= PagSeguro::Config.new
144
+ @configuration ||= PagSeguro::Config.new
105
145
  end
106
146
 
107
147
  # Set the global configuration.
@@ -109,6 +149,9 @@ module PagSeguro
109
149
  # PagSeguro.configure do |config|
110
150
  # config.email = "john@example.com"
111
151
  # config.token = "abc"
152
+ # config.app_id = "app12345"
153
+ # config.app_key = "adju3cmADc52C"
154
+ # config.environment = :sandbox
112
155
  # end
113
156
  #
114
157
  def self.configure(&block)
data/locales/pt-BR.yml CHANGED
@@ -2,6 +2,7 @@ pt-BR:
2
2
  pagseguro:
3
3
  errors:
4
4
  unauthorized: "Não autorizado."
5
+ not_found: "Não encontrado."
5
6
  "10001": "O parâmetro email deve ser informado."
6
7
  "10002": "O parâmetro token deve ser informado."
7
8
  "10003": "O valor informado no parâmetro email é inválido."
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "rspec"
28
28
  spec.add_development_dependency "autotest-standalone"
29
- spec.add_development_dependency "test_notifier"
30
29
  spec.add_development_dependency "simplecov"
31
30
  spec.add_development_dependency "fakeweb"
32
31
  end
@@ -0,0 +1,17 @@
1
+ <authorization>
2
+ <code>9D7FF2E921216F1334EE9FBEB7B4EBBC</code>
3
+ <creationDate>2011-03-30T14:20:13.000-03:00</creationDate>
4
+ <reference>ref1234</reference>
5
+ <permissions>
6
+ <permission>
7
+ <code>CREATE_CHECKOUTS</code>
8
+ <status>APPROVED</status>
9
+ <lastUpdate>2011-03-30T15:35:44.000-03:00</lastUpdate>
10
+ </permission>
11
+ <permission>
12
+ <code>SEARCH_TRANSACTIONS</code>
13
+ <status>APPROVED</status>
14
+ <lastUpdate>2011-03-30T14:20:13.000-03:00</lastUpdate>
15
+ </permission>
16
+ </permissions>
17
+ </authorization>
@@ -0,0 +1,4 @@
1
+ <authorizationRequest>
2
+ <code>D8DD848AC9C98D9EE44C5FB3A1E53913</code>
3
+ <date>2011-02-25T11:40:50.000-03:00</date>
4
+ </authorizationRequest>
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::AccountCredentials do
4
+ describe 'credentials attributes' do
5
+ credentials = PagSeguro::AccountCredentials.new('foo@bar.com', 'token')
6
+
7
+ it { expect(credentials.email).to eq('foo@bar.com') }
8
+ it { expect(credentials.token).to eq('token') }
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::ApplicationCredentials do
4
+ describe 'credentials attributes' do
5
+ credentials = PagSeguro::ApplicationCredentials.new('app123', 'qwerty')
6
+
7
+ it { expect(credentials.app_id).to eq('app123') }
8
+ it { expect(credentials.app_key).to eq('qwerty') }
9
+ it { expect(credentials.authorization_code).to be_nil }
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::Authorization::Collection do
4
+ let(:permission) { double(:permission) }
5
+ let(:authorizations) do
6
+ [
7
+ { code: '1234', created_at: Date.today, permissions: [permission] },
8
+ { code: '4321', created_at: Date.today, permissions: [permission, permission] }
9
+ ]
10
+ end
11
+ subject { described_class.new({authorizations: authorizations}) }
12
+
13
+ describe "initialization" do
14
+ context "when options[:errors] is present" do
15
+ let(:errors) { double(:errors) }
16
+ subject { described_class.new({errors: errors}) }
17
+
18
+ it "sets errors" do
19
+ expect(subject.errors).to eq(errors)
20
+ end
21
+
22
+ it "has no authorizations" do
23
+ expect(subject).to be_empty
24
+ end
25
+ end
26
+
27
+ context "when options[:authorizations] is present" do
28
+ it { expect(subject).to be_any }
29
+ it { expect(subject).not_to be_empty }
30
+
31
+ it "has authorizations instances" do
32
+ subject.each do |installment|
33
+ expect(installment).to be_a(PagSeguro::Authorization)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#errors" do
40
+ it { expect(subject.errors).to be_a(PagSeguro::Errors) }
41
+ it { expect(subject.errors).to be_empty }
42
+ end
43
+
44
+ describe "method delegation" do
45
+ it { subject.respond_to? (:each) }
46
+ it { subject.respond_to? (:empty?) }
47
+ it { subject.respond_to? (:any?) }
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Authorization::RequestSerializer do
4
+ let(:credentials) { PagSeguro::ApplicationCredentials.new('app11', 'sada') }
5
+ let(:options) { { credentials: credentials } }
6
+ let(:authorization) { PagSeguro::Authorization.new(options) }
7
+ let(:serializer) { described_class.new(authorization) }
8
+ let(:params) { serializer.to_params }
9
+
10
+ it{ expect(params).to include(credentials: credentials) }
11
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Authorization::ResponseSerializer do
4
+ context "when payment request is created" do
5
+ let(:source) { File.read("./spec/fixtures/authorization/find_authorization.xml") }
6
+ let(:xml) { Nokogiri::XML(source) }
7
+ let(:serializer) { described_class.new(xml.css("authorization").first) }
8
+
9
+ subject(:data) { serializer.serialize }
10
+
11
+ it { expect(data[:code]).to eql("9D7FF2E921216F1334EE9FBEB7B4EBBC") }
12
+ it { expect(data[:created_at]).to eql(Time.parse("2011-03-30T14:20:13.000-03:00")) }
13
+ it { expect(data[:reference]).to eql("ref1234") }
14
+ it { expect(data[:permissions]).to be_a(Array) }
15
+ it { expect(data[:permissions].first.code).to eq("CREATE_CHECKOUTS") }
16
+ it { expect(data[:permissions].first.status).to eq("APPROVED") }
17
+ end
18
+ end
19
+
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Authorization::Response do
4
+ let(:xml) { File.read("./spec/fixtures/authorization/find_authorization.xml") }
5
+ let(:http_response) do
6
+ response = double(body: xml, code: 200, content_type: "text/xml", "[]" => nil)
7
+ Aitch::Response.new({xml_parser: Aitch::XMLParser}, response)
8
+ end
9
+
10
+
11
+ describe "#serialize" do
12
+ subject { described_class.new(http_response, authorization) }
13
+ let(:authorization) { PagSeguro::Authorization.new }
14
+
15
+ context "when request succeeds" do
16
+ let(:serializer) { double(:serializer) }
17
+ let(:serialized_data) { { code: "1234"} }
18
+
19
+ it "returns a hash with serialized response data" do
20
+ expect(subject.serialize).to eq(authorization)
21
+ end
22
+ end
23
+
24
+ context "when request fails" do
25
+ before do
26
+ expect(http_response).to receive(:success?).and_return(false)
27
+ end
28
+
29
+ it "returns a hash with an errors object" do
30
+ expect(subject.serialize.errors).to be_a(PagSeguro::Errors)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::AuthorizationRequest::RequestSerializer do
4
+ let(:credentials) { PagSeguro::ApplicationCredentials.new('app11', 'sada') }
5
+ let(:options) do
6
+ {
7
+ credentials: credentials,
8
+ permissions: [:checkouts, :notifications],
9
+ notification_url: 'foo.com',
10
+ redirect_url: 'bar.com',
11
+ reference: 'ref1234'
12
+ }
13
+ end
14
+ let(:authorization) { PagSeguro::AuthorizationRequest.new(options) }
15
+ let(:serializer) { described_class.new(authorization) }
16
+ let(:params) { serializer.to_params }
17
+
18
+ it{ expect(params).to include(credentials: credentials) }
19
+ it{ expect(params).to include(permissions: 'CREATE_CHECKOUTS,RECEIVE_TRANSACTION_NOTIFICATIONS') }
20
+ it{ expect(params).to include(notificationURL: 'foo.com') }
21
+ it{ expect(params).to include(redirectURL: 'bar.com') }
22
+ it{ expect(params).to include(reference: 'ref1234') }
23
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::AuthorizationRequest::ResponseSerializer do
4
+ context "when payment request is created" do
5
+ let(:source) { File.read("./spec/fixtures/authorization_request/success.xml") }
6
+ let(:xml) { Nokogiri::XML(source) }
7
+ let(:serializer) { described_class.new(xml.css("authorizationRequest").first) }
8
+
9
+ subject(:data) { serializer.serialize }
10
+
11
+ it { expect(data[:code]).to eql("D8DD848AC9C98D9EE44C5FB3A1E53913") }
12
+ it { expect(data[:date]).to eql(Time.parse("2011-02-25T11:40:50.000-03:00")) }
13
+ end
14
+ end
15
+
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::AuthorizationRequest::Response do
4
+ let(:http_response) do
5
+ response = double(body: "", code: 200, content_type: "text/xml", "[]" => nil)
6
+ Aitch::Response.new({xml_parser: Aitch::XMLParser}, response)
7
+ end
8
+
9
+ subject { described_class.new(http_response) }
10
+
11
+ describe "#serialize" do
12
+ context "when request succeeds" do
13
+ let(:serializer) { double(:serializer) }
14
+ let(:serialized_data) { double(:serialized_data) }
15
+
16
+ it "returns a hash with serialized response data" do
17
+ expect(PagSeguro::AuthorizationRequest::ResponseSerializer).to receive(:new)
18
+ .and_return(serializer)
19
+ expect(serializer).to receive(:serialize).and_return(serialized_data)
20
+
21
+ expect(subject.serialize).to eq(serialized_data)
22
+ end
23
+ end
24
+
25
+ context "when request fails" do
26
+ before do
27
+ expect(http_response).to receive(:success?).and_return(false)
28
+ end
29
+
30
+ it "returns a hash with an errors object" do
31
+ expect(subject.serialize[:errors]).to be_a(PagSeguro::Errors)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::AuthorizationRequest do
4
+ it_assigns_attribute :permissions
5
+ it_assigns_attribute :reference
6
+ it_assigns_attribute :notification_url
7
+ it_assigns_attribute :redirect_url
8
+
9
+ describe "#create" do
10
+ let(:request) { double(:request) }
11
+ let(:response) { double(:response) }
12
+ let(:options) do
13
+ {
14
+ notification_url: "foo",
15
+ redirect_url: "bar",
16
+ permissions: [:notifications, :searches]
17
+ }
18
+ end
19
+
20
+ let(:params) do
21
+ {
22
+ notificationURL: "foo",
23
+ redirectURL: "bar",
24
+ permissions: "RECEIVE_TRANSACTION_NOTIFICATIONS,SEARCH_TRANSACTIONS"
25
+ }
26
+ end
27
+
28
+ subject { described_class.new(options) }
29
+
30
+ before do
31
+ expect(PagSeguro::Request).to receive(:post)
32
+ .with("authorizations/request", 'v2', params)
33
+ .and_return(request)
34
+ expect(PagSeguro::AuthorizationRequest::Response).to receive(:new)
35
+ .with(request)
36
+ .and_return(response)
37
+ expect(response).to receive(:serialize).and_return(serialized_data)
38
+ end
39
+
40
+ context "when request succeeds" do
41
+ let(:serialized_data) { {code: "123"} }
42
+
43
+ it "creates a transaction request" do
44
+ expect(response).to receive(:success?).and_return(true)
45
+
46
+ expect(subject.create).to be_truthy
47
+ expect(subject.code).to eq(serialized_data[:code])
48
+ end
49
+ end
50
+
51
+ context "when request fails" do
52
+ let(:serialized_data) { {errors: PagSeguro::Errors.new} }
53
+
54
+ it "does not create a transaction request" do
55
+ expect(response).to receive(:success?).and_return(false)
56
+
57
+ expect(subject.create).to be_falsey
58
+ expect(subject.code).to be_nil
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::Authorization do
4
+ let(:code) { "1234" }
5
+ let(:notification_code) { "4321" }
6
+ let(:crendentials) { double(:crendentials) }
7
+ let(:options) { { crendentials: crendentials} }
8
+ let(:request) { double(:request) }
9
+ let(:response) { double(:response) }
10
+ let(:serialized_data) { { code: 1234 } }
11
+ let(:authorization) { double(:authorization) }
12
+ let(:collection) { double(:collection) }
13
+
14
+ describe ".find_by_notification_code" do
15
+ before do
16
+ expect(PagSeguro::Request).to receive(:get)
17
+ .with("authorizations/notifications/4321", 'v2', options)
18
+ .and_return(request)
19
+ expect(PagSeguro::Authorization).to receive(:new)
20
+ .and_return(authorization)
21
+ expect(PagSeguro::Authorization::Response).to receive(:new)
22
+ .with(request, authorization)
23
+ .and_return(response)
24
+ expect(response).to receive(:serialize)
25
+ end
26
+
27
+ it "finds authorization by the given notificationCode" do
28
+ expect(PagSeguro::Authorization.find_by_notification_code(notification_code, options))
29
+ .to eq(authorization)
30
+ end
31
+ end
32
+
33
+ describe ".find_by_code" do
34
+ before do
35
+ expect(PagSeguro::Request).to receive(:get)
36
+ .with("authorizations/1234", 'v2', options)
37
+ .and_return(request)
38
+ expect(PagSeguro::Authorization).to receive(:new)
39
+ .and_return(authorization)
40
+ expect(PagSeguro::Authorization::Response).to receive(:new)
41
+ .with(request, authorization)
42
+ .and_return(response)
43
+ expect(response).to receive(:serialize)
44
+ end
45
+
46
+ it "finds authorization by the given notificationCode" do
47
+ expect(PagSeguro::Authorization.find_by_code(code, options)).to eq(authorization)
48
+ end
49
+ end
50
+
51
+ describe "find_by_date" do
52
+ let(:date_options) { { initial_date: Date.today, final_date: Date.today + 1 } }
53
+ before do
54
+ expect(PagSeguro::Request).to receive(:get)
55
+ .with("authorizations", 'v2', {})
56
+ .and_return(request)
57
+ expect(PagSeguro::Authorization::Collection).to receive(:new)
58
+ .and_return(collection)
59
+ expect(PagSeguro::Authorization::Response).to receive(:new)
60
+ .with(request, collection)
61
+ .and_return(response)
62
+ expect(response).to receive(:serialize_collection)
63
+ end
64
+
65
+ it 'finds authorizations by a date range' do
66
+ expect(PagSeguro::Authorization.find_by_date(date_options)).to eq (collection)
67
+ end
68
+ end
69
+ end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe PagSeguro::Errors do
5
5
  let(:response) { double }
6
- let(:http_response) { double(:http_response, unauthorized?: true, bad_request?: false) }
6
+ let(:http_response) { double(:http_response, unauthorized?: true, bad_request?: false, not_found?: false) }
7
7
 
8
8
  context "when have no response" do
9
9
  it "returns errors" do
@@ -16,7 +16,7 @@ describe PagSeguro::Errors do
16
16
  subject(:errors) { PagSeguro::Errors.new(response) }
17
17
 
18
18
  before do
19
- response.stub unauthorized?: true, bad_request?: false
19
+ response.stub unauthorized?: true, bad_request?: false, not_found?: false
20
20
  errors.add(http_response)
21
21
  end
22
22
 
@@ -24,6 +24,18 @@ describe PagSeguro::Errors do
24
24
  it { expect(errors).to include(I18n.t("pagseguro.errors.unauthorized")) }
25
25
  end
26
26
 
27
+ context "when not found" do
28
+ subject(:errors) { PagSeguro::Errors.new(response) }
29
+
30
+ before do
31
+ response.stub unauthorized?: true, bad_request?: false, not_found?: true
32
+ errors.add(http_response)
33
+ end
34
+
35
+ it { expect(errors).not_to be_empty }
36
+ it { expect(errors).to include(I18n.t("pagseguro.errors.not_found")) }
37
+ end
38
+
27
39
  context "when message can't be translated" do
28
40
  let(:error) {
29
41
  <<-XML
@@ -40,7 +52,7 @@ describe PagSeguro::Errors do
40
52
  subject(:errors) { PagSeguro::Errors.new(response) }
41
53
 
42
54
  before do
43
- response.stub data: xml, unauthorized?: false, bad_request?: true
55
+ response.stub data: xml, unauthorized?: false, bad_request?: true, not_found?: true
44
56
  end
45
57
 
46
58
  it { expect(errors).to include("Sample message") }
@@ -62,7 +74,7 @@ describe PagSeguro::Errors do
62
74
  subject(:errors) { PagSeguro::Errors.new(response) }
63
75
 
64
76
  before do
65
- response.stub data: xml, unauthorized?: false, bad_request?: true
77
+ response.stub data: xml, unauthorized?: false, bad_request?: true, not_found?: false
66
78
  end
67
79
 
68
80
  it { expect(errors).to include("O parâmetro email deve ser informado.") }
@@ -85,7 +97,7 @@ describe PagSeguro::Errors do
85
97
  subject(:errors) { PagSeguro::Errors.new(response) }
86
98
 
87
99
  before do
88
- response.stub data: xml, unauthorized?: false, bad_request?: true
100
+ response.stub data: xml, unauthorized?: false, bad_request?: true, not_found?: true
89
101
  errors.add(http_response)
90
102
  end
91
103
 
@@ -2,7 +2,8 @@ require "spec_helper"
2
2
 
3
3
  RSpec.describe PagSeguro::Installment::Response do
4
4
  let(:http_response) do
5
- double(:request, success?: true, xml?: true, data: xml_parsed, body: raw_xml, unauthorized?: false)
5
+ double(:request, success?: true, xml?: true, data: xml_parsed,
6
+ body: raw_xml, unauthorized?: false, :not_found? => false)
6
7
  end
7
8
  let(:xml_parsed) { Nokogiri::XML(raw_xml) }
8
9
  let(:collection) { PagSeguro::Installment::Collection.new }
@@ -40,6 +41,7 @@ RSpec.describe PagSeguro::Installment::Response do
40
41
  before do
41
42
  allow(http_response).to receive(:success?).and_return(false)
42
43
  allow(http_response).to receive(:bad_request?).and_return(true)
44
+ allow(http_response).to receive(:not_found?).and_return(false)
43
45
  end
44
46
 
45
47
  let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
@@ -8,7 +8,7 @@ describe PagSeguro::Installment do
8
8
  it_assigns_attribute :interest_free
9
9
 
10
10
  let(:request) do
11
- double(:request, success?: true, xml?: true, body: raw_xml, data: xml_parsed, unauthorized?: false)
11
+ double(:request, success?: true, xml?: true, body: raw_xml, data: xml_parsed, unauthorized?: false, not_found?: false)
12
12
  end
13
13
 
14
14
  let(:xml_parsed) { Nokogiri::XML(raw_xml) }
@@ -3,16 +3,4 @@ require "spec_helper"
3
3
  describe PagSeguro::Notification do
4
4
  it_assigns_attribute :code
5
5
  it_assigns_attribute :type
6
-
7
- it "detects notification as transaction" do
8
- expect(PagSeguro::Notification.new(type: "transaction")).to be_transaction
9
- end
10
-
11
- it "fetches transaction by its notificationCode" do
12
- PagSeguro::Transaction
13
- .should_receive(:find_by_notification_code)
14
- .with("CODE")
15
-
16
- PagSeguro::Notification.new(code: "CODE").transaction
17
- end
18
6
  end