pagseguro-oficial 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -5
- data/CHANGELOG.md +0 -1
- data/README.md +6 -1
- data/docs/transparent_checkout.md +201 -0
- data/examples/boleto_transaction_request.rb +94 -0
- data/examples/create_session.rb +13 -0
- data/examples/credit_card_transaction_request.rb +122 -0
- data/examples/installment.rb +20 -9
- data/examples/online_debit_transaction.rb +98 -0
- data/examples/transaction_by_code.rb +62 -0
- data/examples/transaction_by_notification_code.rb +55 -51
- data/lib/pagseguro.rb +17 -1
- data/lib/pagseguro/bank.rb +8 -0
- data/lib/pagseguro/boleto_transaction_request.rb +8 -0
- data/lib/pagseguro/credit_card_transaction_request.rb +39 -0
- data/lib/pagseguro/document.rb +2 -2
- data/lib/pagseguro/errors.rb +11 -5
- data/lib/pagseguro/holder.rb +28 -0
- data/lib/pagseguro/installment.rb +11 -16
- data/lib/pagseguro/installment/collection.rb +25 -0
- data/lib/pagseguro/installment/request_serializer.rb +24 -0
- data/lib/pagseguro/installment/response.rb +29 -4
- data/lib/pagseguro/installment/{serializer.rb → response_serializer.rb} +1 -1
- data/lib/pagseguro/items.rb +3 -0
- data/lib/pagseguro/online_debit_transaction_request.rb +17 -0
- data/lib/pagseguro/payment_method.rb +1 -0
- data/lib/pagseguro/payment_releases.rb +3 -0
- data/lib/pagseguro/sender.rb +4 -0
- data/lib/pagseguro/session.rb +34 -0
- data/lib/pagseguro/session/response.rb +32 -0
- data/lib/pagseguro/session/response_serializer.rb +18 -0
- data/lib/pagseguro/transaction.rb +6 -3
- data/lib/pagseguro/transaction/response.rb +1 -1
- data/lib/pagseguro/transaction_installment.rb +11 -0
- data/lib/pagseguro/transaction_request.rb +143 -0
- data/lib/pagseguro/transaction_request/request_serializer.rb +148 -0
- data/lib/pagseguro/transaction_request/response.rb +32 -0
- data/lib/pagseguro/transaction_request/response_serializer.rb +117 -0
- data/lib/pagseguro/version.rb +1 -1
- data/spec/fixtures/session/success.xml +4 -0
- data/spec/fixtures/transaction_request/success.xml +58 -0
- data/spec/fixtures/transactions/search.xml +40 -0
- data/spec/pagseguro/bank_spec.rb +5 -0
- data/spec/pagseguro/boleto_transaction_request_spec.rb +9 -0
- data/spec/pagseguro/credit_card_transaction_request_spec.rb +36 -0
- data/spec/pagseguro/document_spec.rb +1 -1
- data/spec/pagseguro/errors_spec.rb +5 -2
- data/spec/pagseguro/features/create_session_spec.rb +52 -0
- data/spec/pagseguro/features/create_transaction_request_spec.rb +58 -0
- data/spec/pagseguro/holder_spec.rb +9 -0
- data/spec/pagseguro/installment/collection_spec.rb +43 -0
- data/spec/pagseguro/installment/request_serializer_spec.rb +16 -0
- data/spec/pagseguro/installment/{serializer_spec.rb → response_serializer_spec.rb} +1 -1
- data/spec/pagseguro/installment/response_spec.rb +52 -0
- data/spec/pagseguro/installment_spec.rb +22 -73
- data/spec/pagseguro/online_debit_transaction_request_spec.rb +18 -0
- data/spec/pagseguro/payment_method_spec.rb +1 -0
- data/spec/pagseguro/payment_request/response_spec.rb +0 -11
- data/spec/pagseguro/sender_spec.rb +1 -0
- data/spec/pagseguro/session/response_serializer_spec.rb +12 -0
- data/spec/pagseguro/session/response_spec.rb +52 -0
- data/spec/pagseguro/session_spec.rb +41 -0
- data/spec/pagseguro/transaction/search/search_abandoned_spec.rb +27 -0
- data/spec/pagseguro/transaction/search/search_by_date_spec.rb +26 -0
- data/spec/pagseguro/transaction/search/search_by_reference_spec.rb +26 -0
- data/spec/pagseguro/transaction/search_spec.rb +131 -0
- data/spec/pagseguro/transaction_installment_spec.rb +6 -0
- data/spec/pagseguro/transaction_request/request_serializer_spec.rb +213 -0
- data/spec/pagseguro/transaction_request/response_serializer_spec.rb +52 -0
- data/spec/pagseguro/transaction_request/response_spec.rb +60 -0
- data/spec/pagseguro/transaction_request_spec.rb +125 -0
- data/spec/support/helpers.rb +14 -0
- metadata +79 -6
@@ -3,6 +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
7
|
|
7
8
|
context "when have no response" do
|
8
9
|
it "returns errors" do
|
@@ -16,10 +17,11 @@ describe PagSeguro::Errors do
|
|
16
17
|
|
17
18
|
before do
|
18
19
|
response.stub unauthorized?: true, bad_request?: false
|
20
|
+
errors.add(http_response)
|
19
21
|
end
|
20
22
|
|
21
|
-
it {
|
22
|
-
it {
|
23
|
+
it { expect(errors).not_to be_empty }
|
24
|
+
it { expect(errors).to include(I18n.t("pagseguro.errors.unauthorized")) }
|
23
25
|
end
|
24
26
|
|
25
27
|
context "when message can't be translated" do
|
@@ -84,6 +86,7 @@ describe PagSeguro::Errors do
|
|
84
86
|
|
85
87
|
before do
|
86
88
|
response.stub data: xml, unauthorized?: false, bad_request?: true
|
89
|
+
errors.add(http_response)
|
87
90
|
end
|
88
91
|
|
89
92
|
it { expect(errors).to include("Malformed request XML: XML document structures must start and end within the same entity..") }
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Creating Session" do
|
4
|
+
let(:session) { PagSeguro::Session.create }
|
5
|
+
|
6
|
+
context "when request succeeds" do
|
7
|
+
before do
|
8
|
+
body = %[<?xml version="1.0"?><session>
|
9
|
+
<id>620f99e348c24f07877c927b353e49d3</id></session>]
|
10
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/sessions"), body: body,
|
11
|
+
content_type: "text/xml"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a session object" do
|
15
|
+
expect(session).to be_a(PagSeguro::Session)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#errors" do
|
19
|
+
it "is an errors object" do
|
20
|
+
expect(session.errors).to be_a(PagSeguro::Errors)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has no errors" do
|
24
|
+
expect(session.errors).to be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when request fails" do
|
30
|
+
before do
|
31
|
+
body = %[<?xml version="1.0"?><errors><error><code>1234</code>
|
32
|
+
<message>Sample error</message></error></errors>]
|
33
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/sessions"),
|
34
|
+
status: [400, "Bad Request"], body: body, content_type: "text/xml"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns a session object" do
|
38
|
+
expect(session).to be_a(PagSeguro::Session)
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#errors" do
|
42
|
+
it "is an errors object" do
|
43
|
+
expect(session.errors).to be_a(PagSeguro::Errors)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has errors" do
|
47
|
+
expect(session.errors).to_not be_empty
|
48
|
+
expect(session.errors).to include("Sample error")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Creating Transaction Request" do
|
4
|
+
let(:transaction) { PagSeguro::OnlineDebitTransactionRequest.new }
|
5
|
+
|
6
|
+
context "when request succeeds" do
|
7
|
+
before do
|
8
|
+
body = File.read("./spec/fixtures/transaction_request/success.xml")
|
9
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/transactions"),
|
10
|
+
body: body, content_type: "text/xml"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns true" do
|
14
|
+
expect(transaction.create).to be_truthy
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#errors" do
|
18
|
+
before do
|
19
|
+
transaction.create
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is an errors object" do
|
23
|
+
expect(transaction.errors).to be_a(PagSeguro::Errors)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has no errors" do
|
27
|
+
expect(transaction.errors).to be_empty
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when request fails" do
|
33
|
+
before do
|
34
|
+
body = %[<?xml version="1.0"?><errors><error><code>1234</code>
|
35
|
+
<message>Sample error</message></error></errors>]
|
36
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/transactions"),
|
37
|
+
status: [400, "Bad Request"], body: body, content_type: "text/xml"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns false" do
|
41
|
+
expect(transaction.create).to be_falsey
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#errors" do
|
45
|
+
before do
|
46
|
+
transaction.create
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is an errors object" do
|
50
|
+
expect(transaction.errors).to be_a(PagSeguro::Errors)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has errors" do
|
54
|
+
expect(transaction.errors).to_not be_empty
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Installment::Collection do
|
4
|
+
let(:installments) do
|
5
|
+
[
|
6
|
+
{ amount: "100", card_brand: "visa" },
|
7
|
+
{ amount: "110", card_brand: "visa" }
|
8
|
+
]
|
9
|
+
end
|
10
|
+
subject { PagSeguro::Installment::Collection.new }
|
11
|
+
|
12
|
+
describe "initialization" do
|
13
|
+
it "errors should be a instance of PagSeguro::Errors" do
|
14
|
+
expect(subject.errors).to be_a(PagSeguro::Errors)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "delegate empty? to @installments" do
|
18
|
+
subject.installments = []
|
19
|
+
expect(subject).to be_empty
|
20
|
+
|
21
|
+
subject.installments = installments
|
22
|
+
expect(subject).not_to be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it "delegate any? to @installments" do
|
26
|
+
subject.installments = []
|
27
|
+
expect(subject).not_to be_any
|
28
|
+
|
29
|
+
subject.installments = installments
|
30
|
+
expect(subject).to be_any
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "#installments=" do
|
35
|
+
it "turns array of hash into installments" do
|
36
|
+
subject.installments = installments
|
37
|
+
|
38
|
+
subject.each do |installment|
|
39
|
+
expect(installment).to be_a(PagSeguro::Installment)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Installment::RequestSerializer do
|
4
|
+
let(:data) { { amount: "100.00", card_brand: "visa" } }
|
5
|
+
let(:params) { serializer.to_params }
|
6
|
+
subject(:serializer) { described_class.new(data) }
|
7
|
+
|
8
|
+
it { expect(params).to include(amount: "100.00") }
|
9
|
+
it { expect(params).to include(cardBrand: "visa") }
|
10
|
+
|
11
|
+
context "when card brand is not present" do
|
12
|
+
let(:data) { { amount: "100.00" } }
|
13
|
+
|
14
|
+
it { expect(params).to_not include(cardBrand: "visa") }
|
15
|
+
end
|
16
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::Installment::
|
3
|
+
describe PagSeguro::Installment::ResponseSerializer do
|
4
4
|
context "when there are installments" do
|
5
5
|
let(:source) { File.read("./spec/fixtures/installment/success.xml") }
|
6
6
|
let(:xml) { Nokogiri::XML(source) }
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PagSeguro::Installment::Response do
|
4
|
+
let(:http_response) do
|
5
|
+
double(:request, success?: true, xml?: true, data: xml_parsed, body: raw_xml, unauthorized?: false)
|
6
|
+
end
|
7
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
8
|
+
let(:collection) { PagSeguro::Installment::Collection.new }
|
9
|
+
subject { PagSeguro::Installment::Response.new(http_response, collection) }
|
10
|
+
|
11
|
+
context "#success?" do
|
12
|
+
let(:http_response) do
|
13
|
+
double(:HttpResponse, xml?: true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "delegate to response" do
|
17
|
+
allow(http_response).to receive(:success?).and_return(true)
|
18
|
+
expect(subject).to be_success
|
19
|
+
|
20
|
+
allow(http_response).to receive(:success?).and_return(false)
|
21
|
+
expect(subject).not_to be_success
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#serialize" do
|
26
|
+
context "when request succeeds" do
|
27
|
+
let(:serializer) { double(:serializer) }
|
28
|
+
let(:raw_xml) { File.read("./spec/fixtures/installment/success.xml") }
|
29
|
+
|
30
|
+
it "not change errors" do
|
31
|
+
expect { subject.serialize }.not_to change { collection.errors.empty? }
|
32
|
+
end
|
33
|
+
|
34
|
+
it "return a collection instance" do
|
35
|
+
expect(subject.serialize).to be_a(PagSeguro::Installment::Collection)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when request fails" do
|
40
|
+
before do
|
41
|
+
allow(http_response).to receive(:success?).and_return(false)
|
42
|
+
allow(http_response).to receive(:bad_request?).and_return(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
46
|
+
|
47
|
+
it "update collection errors" do
|
48
|
+
expect { subject.serialize }.to change { collection.errors.empty? }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -7,92 +7,41 @@ describe PagSeguro::Installment do
|
|
7
7
|
it_assigns_attribute :total_amount
|
8
8
|
it_assigns_attribute :interest_free
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
let(:version) { 'v2' }
|
14
|
-
|
15
|
-
it "finds installments by the given amount" do
|
16
|
-
expect(PagSeguro::Request).to receive(:get)
|
17
|
-
.with("installments?amount=100.00", version)
|
18
|
-
.and_return(request)
|
19
|
-
expect(PagSeguro::Installment).to receive(:load_from_response)
|
20
|
-
.with(request)
|
10
|
+
let(:request) do
|
11
|
+
double(:request, success?: true, xml?: true, body: raw_xml, data: xml_parsed, unauthorized?: false)
|
12
|
+
end
|
21
13
|
|
22
|
-
|
23
|
-
end
|
14
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
.and_return(request)
|
29
|
-
expect(PagSeguro::Installment).to receive(:load_from_response)
|
30
|
-
.with(request)
|
16
|
+
describe ".find" do
|
17
|
+
subject { PagSeguro::Installment }
|
18
|
+
let(:params) { { amount: "100.00", cardBrand: "visa" } }
|
31
19
|
|
32
|
-
|
33
|
-
|
20
|
+
before do
|
21
|
+
allow(PagSeguro::Request).to receive(:get)
|
22
|
+
.with("installments", "v2", params)
|
23
|
+
.and_return(request)
|
34
24
|
end
|
35
25
|
|
36
|
-
context "when request
|
37
|
-
|
38
|
-
body = %[<?xml version="1.0"?><errors><error><code>1234</code>
|
39
|
-
<message>Sample error</message></error></errors>]
|
40
|
-
FakeWeb.register_uri :get, %r[.+], status: [400, "Bad Request"],
|
41
|
-
body: body, content_type: "text/xml"
|
42
|
-
response = PagSeguro::Installment.find("invalid")
|
26
|
+
context "when request succeeds" do
|
27
|
+
let(:raw_xml) { File.read("./spec/fixtures/installment/success.xml") }
|
43
28
|
|
44
|
-
|
45
|
-
expect(
|
29
|
+
it "returns a instance of collection" do
|
30
|
+
expect(subject.find("100.00", "visa")).to be_a(PagSeguro::Installment::Collection)
|
46
31
|
end
|
47
32
|
end
|
48
|
-
end
|
49
33
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
double(:response, success?: true, xml?: true, body: response_body)
|
55
|
-
end
|
56
|
-
let(:xml) { double(:xml) }
|
57
|
-
let(:node) { double(:node) }
|
58
|
-
let(:installments_nodes) { [node] }
|
59
|
-
|
60
|
-
it "loads response" do
|
61
|
-
expect(Nokogiri).to receive(:XML).with(response_body).and_return(xml)
|
62
|
-
expect(xml).to receive(:css).with("installments > installment")
|
63
|
-
.and_return(installments_nodes)
|
64
|
-
expect(PagSeguro::Installment).to receive(:load_from_xml).with(node)
|
65
|
-
|
66
|
-
PagSeguro::Installment.load_from_response(response)
|
34
|
+
context "when request fails" do
|
35
|
+
before do
|
36
|
+
allow(request).to receive(:success?).and_return(false)
|
37
|
+
allow(request).to receive(:bad_request?).and_return(true)
|
67
38
|
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "when response fails" do
|
71
|
-
let(:response) { double(:response, success?: false) }
|
72
|
-
let(:error) { double(:error) }
|
73
39
|
|
74
|
-
|
75
|
-
expect(PagSeguro::Errors).to receive(:new).with(response)
|
76
|
-
.and_return(error)
|
77
|
-
expect(PagSeguro::Installment::Response).to receive(:new).with(error)
|
40
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
78
41
|
|
79
|
-
|
42
|
+
it "returns collection with error" do
|
43
|
+
expect(subject.find("100.00", "visa").errors).not_to be_empty
|
80
44
|
end
|
81
45
|
end
|
82
46
|
end
|
83
|
-
|
84
|
-
describe ".load_from_xml" do
|
85
|
-
let(:xml) { double(:xml) }
|
86
|
-
let(:serializer) { double(:serializer) }
|
87
|
-
let(:data) { double(:data) }
|
88
|
-
|
89
|
-
it "serializes the xml" do
|
90
|
-
expect(PagSeguro::Installment::Serializer).to receive(:new).with(xml)
|
91
|
-
.and_return(serializer)
|
92
|
-
expect(serializer).to receive(:serialize).and_return(data)
|
93
|
-
expect(PagSeguro::Installment).to receive(:new).with(data)
|
94
|
-
|
95
|
-
PagSeguro::Installment.load_from_xml(xml)
|
96
|
-
end
|
97
|
-
end
|
98
47
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::OnlineDebitTransactionRequest do
|
4
|
+
it_ensures_type PagSeguro::Bank, :bank
|
5
|
+
|
6
|
+
describe "#payment_method" do
|
7
|
+
it "is online_debit" do
|
8
|
+
expect(subject.payment_method).to eq("online_debit")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets the bank" do
|
13
|
+
bank = PagSeguro::Bank.new
|
14
|
+
payment = described_class.new(bank: bank)
|
15
|
+
|
16
|
+
expect(payment.bank).to eq(bank)
|
17
|
+
end
|
18
|
+
end
|
@@ -9,6 +9,7 @@ end
|
|
9
9
|
|
10
10
|
describe PagSeguro::PaymentMethod do
|
11
11
|
context "type mapping" do
|
12
|
+
it_behaves_like "type mapping", nil, :not_set
|
12
13
|
it_behaves_like "type mapping", 1, :credit_card
|
13
14
|
it_behaves_like "type mapping", 2, :boleto
|
14
15
|
it_behaves_like "type mapping", 3, :online_transfer
|
@@ -2,17 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe PagSeguro::PaymentRequest::Response do
|
4
4
|
context "when payment request is created" do
|
5
|
-
def xml_response(path)
|
6
|
-
response = double(
|
7
|
-
body: File.read("./spec/fixtures/#{path}"),
|
8
|
-
code: 200,
|
9
|
-
content_type: "text/xml",
|
10
|
-
"[]" => nil
|
11
|
-
)
|
12
|
-
|
13
|
-
Aitch::Response.new({xml_parser: Aitch::XMLParser}, response)
|
14
|
-
end
|
15
|
-
|
16
5
|
let(:http_response) { xml_response("payment_request/success.xml") }
|
17
6
|
subject(:response) { described_class.new(http_response) }
|
18
7
|
|