pagseguro-oficial 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE-2.0.txt +177 -0
- data/README.md +320 -0
- data/Rakefile +5 -0
- data/examples/abandoned_transactions.rb +26 -0
- data/examples/boot.rb +9 -0
- data/examples/invalid_transaction_by_notification_code.rb +9 -0
- data/examples/payment_request.rb +49 -0
- data/examples/transaction_by_notification_code.rb +5 -0
- data/examples/transactions_by_date.rb +23 -0
- data/lib/pagseguro/address.rb +40 -0
- data/lib/pagseguro/errors.rb +28 -0
- data/lib/pagseguro/exceptions.rb +3 -0
- data/lib/pagseguro/extensions/ensure_type.rb +9 -0
- data/lib/pagseguro/extensions/mass_assignment.rb +11 -0
- data/lib/pagseguro/item.rb +30 -0
- data/lib/pagseguro/items.rb +27 -0
- data/lib/pagseguro/notification.rb +21 -0
- data/lib/pagseguro/payment_method.rb +38 -0
- data/lib/pagseguro/payment_request/response.rb +30 -0
- data/lib/pagseguro/payment_request/serializer.rb +91 -0
- data/lib/pagseguro/payment_request.rb +96 -0
- data/lib/pagseguro/payment_status.rb +33 -0
- data/lib/pagseguro/phone.rb +12 -0
- data/lib/pagseguro/report.rb +124 -0
- data/lib/pagseguro/request.rb +78 -0
- data/lib/pagseguro/sender.rb +23 -0
- data/lib/pagseguro/shipping.rb +57 -0
- data/lib/pagseguro/transaction/response.rb +12 -0
- data/lib/pagseguro/transaction/serializer.rb +115 -0
- data/lib/pagseguro/transaction.rb +167 -0
- data/lib/pagseguro/version.rb +3 -0
- data/lib/pagseguro-oficial.rb +1 -0
- data/lib/pagseguro.rb +94 -0
- data/locales/pt-BR.yml +115 -0
- data/pagseguro-oficial.gemspec +32 -0
- data/spec/fixtures/by_date/success.xml +85 -0
- data/spec/fixtures/invalid_code.xml +7 -0
- data/spec/fixtures/payment_request/failure.xml +7 -0
- data/spec/fixtures/payment_request/success.xml +5 -0
- data/spec/fixtures/transactions/additional.xml +53 -0
- data/spec/fixtures/transactions/success.xml +53 -0
- data/spec/pagseguro/address_spec.rb +17 -0
- data/spec/pagseguro/errors_spec.rb +91 -0
- data/spec/pagseguro/item_spec.rb +20 -0
- data/spec/pagseguro/items_spec.rb +56 -0
- data/spec/pagseguro/notification_spec.rb +18 -0
- data/spec/pagseguro/pagseguro_spec.rb +54 -0
- data/spec/pagseguro/payment_method_spec.rb +41 -0
- data/spec/pagseguro/payment_request/response_spec.rb +24 -0
- data/spec/pagseguro/payment_request/serializer_spec.rb +142 -0
- data/spec/pagseguro/payment_request_spec.rb +107 -0
- data/spec/pagseguro/payment_status_spec.rb +24 -0
- data/spec/pagseguro/phone_spec.rb +6 -0
- data/spec/pagseguro/request_spec.rb +75 -0
- data/spec/pagseguro/sender_spec.rb +9 -0
- data/spec/pagseguro/shipping_spec.rb +40 -0
- data/spec/pagseguro/transaction/serializer_spec.rb +61 -0
- data/spec/pagseguro/transaction_spec.rb +118 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/ensure_type_macro.rb +17 -0
- data/spec/support/mass_assignment_macro.rb +11 -0
- metadata +289 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro do
|
4
|
+
before do
|
5
|
+
PagSeguro.email = "EMAIL"
|
6
|
+
PagSeguro.token = "TOKEN"
|
7
|
+
PagSeguro.receiver_email = "RECEIVER_EMAIL"
|
8
|
+
end
|
9
|
+
|
10
|
+
it { expect(PagSeguro.email).to eql("EMAIL") }
|
11
|
+
it { expect(PagSeguro.token).to eql("TOKEN") }
|
12
|
+
it { expect(PagSeguro.receiver_email).to eql("RECEIVER_EMAIL") }
|
13
|
+
|
14
|
+
context "configuring library" do
|
15
|
+
it "yields PagSeguro" do
|
16
|
+
expect {|block|
|
17
|
+
PagSeguro.configure(&block)
|
18
|
+
}.to yield_with_args(PagSeguro)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "default settings" do
|
23
|
+
it { expect(PagSeguro.encoding).to eql("UTF-8") }
|
24
|
+
it { expect(PagSeguro.environment).to eql(:production) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".api_url" do
|
28
|
+
it "raises when environment has no endpoint" do
|
29
|
+
PagSeguro.environment = :invalid
|
30
|
+
|
31
|
+
expect {
|
32
|
+
PagSeguro.api_url("/")
|
33
|
+
}.to raise_exception(PagSeguro::InvalidEnvironmentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns api url" do
|
37
|
+
expect(PagSeguro.api_url("/some/path")).to eql("https://ws.pagseguro.uol.com.br/v2/some/path")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".site_url" do
|
42
|
+
it "raises when environment has no endpoint" do
|
43
|
+
PagSeguro.environment = :invalid
|
44
|
+
|
45
|
+
expect {
|
46
|
+
PagSeguro.site_url("/")
|
47
|
+
}.to raise_exception(PagSeguro::InvalidEnvironmentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns site url" do
|
51
|
+
expect(PagSeguro.site_url("/some/path")).to eql("https://pagseguro.uol.com.br/v2/some/path")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
shared_examples_for "type mapping" do |id, type|
|
5
|
+
it "returns #{type.inspect} as type when id is #{id}" do
|
6
|
+
expect(PagSeguro::PaymentMethod.new(type_id: id).type).to eql(type)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe PagSeguro::PaymentMethod do
|
11
|
+
context "type mapping" do
|
12
|
+
it_behaves_like "type mapping", 1, :credit_card
|
13
|
+
it_behaves_like "type mapping", 2, :boleto
|
14
|
+
it_behaves_like "type mapping", 3, :online_transfer
|
15
|
+
it_behaves_like "type mapping", 4, :balance
|
16
|
+
it_behaves_like "type mapping", 5, :oi_paggo
|
17
|
+
it_behaves_like "type mapping", 7, :direct_deposit
|
18
|
+
|
19
|
+
it "raises for invalid id" do
|
20
|
+
expect {
|
21
|
+
PagSeguro::PaymentMethod.new(type_id: "invalid").type
|
22
|
+
}.to raise_exception("PagSeguro::PaymentMethod#type_id isn't mapped")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "shortcuts" do
|
27
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 1)).to be_credit_card }
|
28
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 2)).to be_boleto }
|
29
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 3)).to be_online_transfer }
|
30
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 4)).to be_balance }
|
31
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 5)).to be_oi_paggo }
|
32
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 7)).to be_direct_deposit }
|
33
|
+
|
34
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 5)).not_to be_credit_card }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "description" do
|
38
|
+
subject(:payment_method) { PagSeguro::PaymentMethod.new(code: 102) }
|
39
|
+
it { expect(payment_method.description).to eql("Cartão de crédito MasterCard") }
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::PaymentRequest::Response do
|
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
|
+
let(:http_response) { xml_response("payment_request/success.xml") }
|
17
|
+
subject(:response) { described_class.new(http_response) }
|
18
|
+
|
19
|
+
it { expect(response.code).to eql("8CF4BE7DCECEF0F004A6DFA0A8243412") }
|
20
|
+
it { expect(response.created_at).to eql(Time.parse("2010-12-02T10:11:28.000-02:00")) }
|
21
|
+
it { expect(response.url).to eql("https://pagseguro.uol.com.br/v2/checkout/payment.html?code=8CF4BE7DCECEF0F004A6DFA0A8243412") }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,142 @@
|
|
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
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::PaymentRequest do
|
4
|
+
it_assigns_attribute :currency
|
5
|
+
it_assigns_attribute :redirect_url
|
6
|
+
it_assigns_attribute :extra_amount
|
7
|
+
it_assigns_attribute :reference
|
8
|
+
it_assigns_attribute :max_age
|
9
|
+
it_assigns_attribute :max_uses
|
10
|
+
it_assigns_attribute :notification_url
|
11
|
+
it_assigns_attribute :abandon_url
|
12
|
+
it_assigns_attribute :email
|
13
|
+
it_assigns_attribute :token
|
14
|
+
|
15
|
+
it_ensures_type PagSeguro::Sender, :sender
|
16
|
+
it_ensures_type PagSeguro::Shipping, :shipping
|
17
|
+
|
18
|
+
it "sets the sender" do
|
19
|
+
sender = PagSeguro::Sender.new
|
20
|
+
payment = PagSeguro::PaymentRequest.new(sender: sender)
|
21
|
+
|
22
|
+
expect(payment.sender).to eql(sender)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets the items" do
|
26
|
+
payment = PagSeguro::PaymentRequest.new
|
27
|
+
expect(payment.items).to be_a(PagSeguro::Items)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sets default currency" do
|
31
|
+
payment = PagSeguro::PaymentRequest.new
|
32
|
+
expect(payment.currency).to eql("BRL")
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#email" do
|
36
|
+
before { PagSeguro.email = 'DEFAULT_EMAIL' }
|
37
|
+
|
38
|
+
it "returns the email set in the constructor" do
|
39
|
+
expect(described_class.new(email: 'foo').email).to eq('foo')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "defaults to PagSeguro.email" do
|
43
|
+
expect(described_class.new.email).to eq('DEFAULT_EMAIL')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#token" do
|
48
|
+
before { PagSeguro.token = 'DEFAULT_TOKEN' }
|
49
|
+
|
50
|
+
it "returns the token set in the constructor" do
|
51
|
+
expect(described_class.new(token: 'foo').token).to eq('foo')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "defaults to PagSeguro.token" do
|
55
|
+
expect(described_class.new.token).to eq('DEFAULT_TOKEN')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#register" do
|
60
|
+
let(:payment) { PagSeguro::PaymentRequest.new }
|
61
|
+
before { FakeWeb.register_uri :any, %r[.*?], body: "" }
|
62
|
+
|
63
|
+
it "serializes payment request" do
|
64
|
+
PagSeguro::PaymentRequest::Serializer
|
65
|
+
.should_receive(:new)
|
66
|
+
.with(payment)
|
67
|
+
.and_return(double.as_null_object)
|
68
|
+
|
69
|
+
payment.register
|
70
|
+
end
|
71
|
+
|
72
|
+
it "performs request" do
|
73
|
+
params = double
|
74
|
+
|
75
|
+
params.should_receive(:merge).with({
|
76
|
+
email: PagSeguro.email,
|
77
|
+
token: PagSeguro.token
|
78
|
+
}).and_return(params)
|
79
|
+
|
80
|
+
PagSeguro::PaymentRequest::Serializer.any_instance.stub to_params: params
|
81
|
+
|
82
|
+
PagSeguro::Request
|
83
|
+
.should_receive(:post)
|
84
|
+
.with("checkout", params)
|
85
|
+
|
86
|
+
payment.register
|
87
|
+
end
|
88
|
+
|
89
|
+
it "initializes response" do
|
90
|
+
response = double
|
91
|
+
PagSeguro::Request.stub post: response
|
92
|
+
|
93
|
+
PagSeguro::PaymentRequest::Response
|
94
|
+
.should_receive(:new)
|
95
|
+
.with(response)
|
96
|
+
|
97
|
+
payment.register
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns response" do
|
101
|
+
response = double
|
102
|
+
PagSeguro::PaymentRequest::Response.stub new: response
|
103
|
+
|
104
|
+
expect(payment.register).to eql(response)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples_for "payment status mapping" do |id, status|
|
4
|
+
it "returns #{status} as status when id is #{id}" do
|
5
|
+
expect(PagSeguro::PaymentStatus.new(id).status).to eql(status)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "detects as #{status}" do
|
9
|
+
expect(PagSeguro::PaymentStatus.new(id).public_send("#{status}?")).to be
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe PagSeguro::PaymentStatus do
|
14
|
+
context "status mapping" do
|
15
|
+
it_behaves_like "payment status mapping", 0, :initiated
|
16
|
+
it_behaves_like "payment status mapping", 1, :waiting_payment
|
17
|
+
it_behaves_like "payment status mapping", 2, :in_analysis
|
18
|
+
it_behaves_like "payment status mapping", 3, :paid
|
19
|
+
it_behaves_like "payment status mapping", 4, :available
|
20
|
+
it_behaves_like "payment status mapping", 5, :in_dispute
|
21
|
+
it_behaves_like "payment status mapping", 6, :refunded
|
22
|
+
it_behaves_like "payment status mapping", 7, :cancelled
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Request do
|
4
|
+
context "default headers" do
|
5
|
+
subject(:headers) { PagSeguro::Request.config.default_headers }
|
6
|
+
|
7
|
+
it { should include("lib-description" => "ruby:#{PagSeguro::VERSION}") }
|
8
|
+
it { should include("language-engine-description" => "ruby:#{RUBY_VERSION}") }
|
9
|
+
end
|
10
|
+
|
11
|
+
context "POST request" do
|
12
|
+
before do
|
13
|
+
FakeWeb.register_uri :post, %r[.+], body: "BODY"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "includes credentials" do
|
17
|
+
PagSeguro.email = "EMAIL"
|
18
|
+
PagSeguro.token = "TOKEN"
|
19
|
+
PagSeguro::Request.post("checkout")
|
20
|
+
|
21
|
+
expect(FakeWeb.last_request.body).to include("email=EMAIL&token=TOKEN")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "includes custom credentials" do
|
25
|
+
PagSeguro.email = "EMAIL"
|
26
|
+
PagSeguro.token = "TOKEN"
|
27
|
+
PagSeguro::Request.post("checkout", email: 'foo', token: 'bar')
|
28
|
+
|
29
|
+
expect(FakeWeb.last_request.body).to include("email=foo&token=bar")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "includes encoding" do
|
33
|
+
PagSeguro::Request.post("checkout")
|
34
|
+
expect(FakeWeb.last_request.body).to include("charset=UTF-8")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "include request headers" do
|
38
|
+
PagSeguro::Request.post("checkout")
|
39
|
+
request = FakeWeb.last_request
|
40
|
+
|
41
|
+
expect(request["Accept-Charset"]).to eql("UTF-8")
|
42
|
+
expect(request["Content-Type"]).to eql("application/x-www-form-urlencoded; charset=UTF-8")
|
43
|
+
expect(request["lib-description"]).to be
|
44
|
+
expect(request["language-engine-description"]).to be
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "GET request" do
|
49
|
+
before do
|
50
|
+
FakeWeb.register_uri :get, %r[.+], body: "BODY"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "includes credentials" do
|
54
|
+
PagSeguro.email = "EMAIL"
|
55
|
+
PagSeguro.token = "TOKEN"
|
56
|
+
PagSeguro::Request.get("checkout")
|
57
|
+
|
58
|
+
expect(FakeWeb.last_request.path).to include("email=EMAIL&token=TOKEN")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "includes encoding" do
|
62
|
+
PagSeguro::Request.get("checkout")
|
63
|
+
expect(FakeWeb.last_request.path).to include("charset=UTF-8")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "include request headers" do
|
67
|
+
PagSeguro::Request.get("checkout")
|
68
|
+
request = FakeWeb.last_request
|
69
|
+
|
70
|
+
expect(request["Accept-Charset"]).to eql("UTF-8")
|
71
|
+
expect(request["lib-description"]).to be
|
72
|
+
expect(request["language-engine-description"]).to be
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|