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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +17 -1
- data/Gemfile +0 -2
- data/README.md +1 -1
- data/docs/transparent_checkout.md +3 -3
- data/examples/authorization/create_authorization.rb +32 -0
- data/examples/authorization/create_authorization_with_account.rb +56 -0
- data/examples/authorization/{authorization_by_code.rb → search/search_authorization_by_code.rb} +4 -4
- data/examples/authorization/search/search_authorization_by_date.rb +35 -0
- data/examples/authorization/{authorization_by_notification_code.rb → search/search_authorization_by_notification_code.rb} +4 -5
- data/examples/authorization/search/search_authorization_by_reference.rb +31 -0
- data/examples/{payment_request.rb → checkout/create_payment_request.rb} +5 -7
- data/examples/{transaction/abandoned_transactions.rb → checkout/search/search_abandoned_transactions.rb} +6 -3
- data/examples/{transaction/transaction_by_code.rb → checkout/search/search_transaction_by_code.rb} +3 -3
- data/examples/{transaction/transaction_by_notification_code.rb → checkout/search/search_transaction_by_notification_code.rb} +3 -3
- data/examples/{transaction/transaction_by_reference.rb → checkout/search/search_transaction_by_reference.rb} +3 -3
- data/examples/{transaction/transaction_status_history.rb → checkout/search/search_transaction_status_history.rb} +2 -2
- data/examples/{transaction/transactions_by_date.rb → checkout/search/search_transactions_by_date.rb} +3 -3
- data/examples/{transaction/boleto_transaction_request.rb → direct/create_transaction_using_boleto.rb} +1 -1
- data/examples/{transaction/credit_card_transaction_request.rb → direct/create_transaction_using_credit_card.rb} +1 -1
- data/examples/{transaction/online_debit_transaction.rb → direct/create_transaction_using_online_debit.rb} +1 -1
- data/examples/{installment.rb → get_installments.rb} +3 -3
- data/examples/{transaction/transaction_cancellation.rb → request_transaction_cancellation.rb} +2 -2
- data/examples/{authorization/authorization.rb → split_payment/create_authorization.rb} +5 -4
- data/examples/split_payment/create_payment_request.rb +71 -0
- data/lib/pagseguro.rb +14 -8
- data/lib/pagseguro/account.rb +29 -0
- data/lib/pagseguro/authorization.rb +10 -4
- data/lib/pagseguro/authorization/collection.rb +3 -1
- data/lib/pagseguro/authorization/request_serializer.rb +6 -6
- data/lib/pagseguro/authorization/response.rb +2 -2
- data/lib/pagseguro/authorization_request.rb +16 -4
- data/lib/pagseguro/authorization_request/request_serializer.rb +127 -15
- data/lib/pagseguro/authorization_request/response.rb +2 -2
- data/lib/pagseguro/company.rb +41 -0
- data/lib/pagseguro/document.rb +4 -0
- data/lib/pagseguro/documents.rb +5 -0
- data/lib/pagseguro/errors.rb +27 -5
- data/lib/pagseguro/extensions/collection_object.rb +34 -0
- data/lib/pagseguro/item.rb +4 -0
- data/lib/pagseguro/items.rb +10 -17
- data/lib/pagseguro/partner.rb +20 -0
- data/lib/pagseguro/payment_request.rb +30 -2
- data/lib/pagseguro/payment_request/{serializer.rb → request_serializer.rb} +86 -1
- data/lib/pagseguro/person.rb +40 -0
- data/lib/pagseguro/phone.rb +8 -0
- data/lib/pagseguro/phones.rb +5 -0
- data/lib/pagseguro/receiver.rb +17 -0
- data/lib/pagseguro/receiver_split.rb +15 -0
- data/lib/pagseguro/request.rb +25 -1
- data/lib/pagseguro/transaction.rb +7 -5
- data/lib/pagseguro/transaction_cancellation.rb +3 -6
- data/lib/pagseguro/transaction_cancellation/response.rb +7 -6
- data/lib/pagseguro/{refund.rb → transaction_refund.rb} +2 -2
- data/lib/pagseguro/{refund → transaction_refund}/request_serializer.rb +1 -1
- data/lib/pagseguro/{refund → transaction_refund}/response.rb +9 -9
- data/lib/pagseguro/{refund → transaction_refund}/response_serializer.rb +1 -1
- data/lib/pagseguro/transaction_request.rb +1 -4
- data/lib/pagseguro/transaction_request/response.rb +8 -7
- data/lib/pagseguro/version.rb +1 -1
- data/locales/pt-BR.yml +1 -0
- data/pagseguro-oficial.gemspec +13 -13
- data/spec/fixtures/authorization/search_authorization.xml +47 -0
- data/spec/fixtures/authorization_request/authorization_request.xml +11 -0
- data/spec/fixtures/authorization_request/authorization_request_with_account.xml +47 -0
- data/spec/pagseguro/account_spec.rb +27 -0
- data/spec/pagseguro/authorization/collection_spec.rb +3 -3
- data/spec/pagseguro/authorization/request_serializer_spec.rb +1 -2
- data/spec/pagseguro/authorization/response_spec.rb +70 -15
- data/spec/pagseguro/authorization_request/request_serializer_spec.rb +314 -14
- data/spec/pagseguro/authorization_request_spec.rb +96 -31
- data/spec/pagseguro/authorization_spec.rb +52 -10
- data/spec/pagseguro/company_spec.rb +12 -0
- data/spec/pagseguro/documents_spec.rb +37 -0
- data/spec/pagseguro/errors_spec.rb +45 -6
- data/spec/pagseguro/extensions/collection_object_spec.rb +77 -0
- data/spec/pagseguro/features/create_transaction_request_spec.rb +2 -2
- data/spec/pagseguro/installment/response_spec.rb +5 -3
- data/spec/pagseguro/installment_spec.rb +5 -2
- data/spec/pagseguro/items_spec.rb +104 -12
- data/spec/pagseguro/pagseguro_spec.rb +8 -8
- data/spec/pagseguro/partner_spec.rb +8 -0
- data/spec/pagseguro/payment_request/request_serializer_spec.rb +251 -0
- data/spec/pagseguro/payment_request_spec.rb +67 -11
- data/spec/pagseguro/person_spec.rb +10 -0
- data/spec/pagseguro/phones_spec.rb +38 -0
- data/spec/pagseguro/receiver_spec.rb +6 -0
- data/spec/pagseguro/receiver_split_spec.rb +7 -0
- data/spec/pagseguro/request_spec.rb +27 -4
- data/spec/pagseguro/session/response_spec.rb +6 -2
- data/spec/pagseguro/session_spec.rb +5 -2
- data/spec/pagseguro/transaction/response_spec.rb +14 -8
- data/spec/pagseguro/transaction/search_spec.rb +15 -8
- data/spec/pagseguro/transaction_cancellation/response_spec.rb +6 -3
- data/spec/pagseguro/transaction_cancellation_spec.rb +7 -5
- data/spec/pagseguro/{refund → transaction_refund}/request_serializer_spec.rb +3 -3
- data/spec/pagseguro/{refund → transaction_refund}/response_serializer_spec.rb +1 -1
- data/spec/pagseguro/{refund → transaction_refund}/response_spec.rb +3 -3
- data/spec/pagseguro/{refund_spec.rb → transaction_refund_spec.rb} +15 -7
- data/spec/pagseguro/transaction_request/request_serializer_spec.rb +9 -9
- data/spec/pagseguro/transaction_request/response_spec.rb +5 -2
- data/spec/pagseguro/transaction_request_spec.rb +14 -9
- data/spec/pagseguro/transaction_spec.rb +37 -30
- data/spec/spec_helper.rb +0 -3
- data/spec/support/ensure_type_macro.rb +20 -2
- data/{examples/refund.rb → transaction/transaction_refund.rb} +1 -1
- metadata +112 -96
- data/examples/transaction/invalid_transaction_by_notification_code.rb +0 -22
- data/lib/pagseguro/refund/serializer.rb +0 -24
- data/lib/pagseguro/transaction_cancellation/serializer.rb +0 -18
- data/spec/pagseguro/payment_request/serializer_spec.rb +0 -166
- data/spec/pagseguro/refund/serializer_spec.rb +0 -15
- data/spec/pagseguro/transaction_cancellation/serializer_spec.rb +0 -13
@@ -37,8 +37,8 @@ RSpec.describe "Creating Transaction Request" do
|
|
37
37
|
status: [400, "Bad Request"], body: body, content_type: "text/xml"
|
38
38
|
end
|
39
39
|
|
40
|
-
it "
|
41
|
-
expect
|
40
|
+
it "does not change attributes" do
|
41
|
+
expect { transaction.create }.not_to change { transaction.code }
|
42
42
|
end
|
43
43
|
|
44
44
|
describe "#errors" do
|
@@ -39,9 +39,11 @@ RSpec.describe PagSeguro::Installment::Response do
|
|
39
39
|
|
40
40
|
context "when request fails" do
|
41
41
|
before do
|
42
|
-
allow(http_response).to
|
43
|
-
|
44
|
-
|
42
|
+
allow(http_response).to receive_messages(
|
43
|
+
success?: false,
|
44
|
+
error?: true,
|
45
|
+
error: Aitch::BadRequestError
|
46
|
+
)
|
45
47
|
end
|
46
48
|
|
47
49
|
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
@@ -33,8 +33,11 @@ describe PagSeguro::Installment do
|
|
33
33
|
|
34
34
|
context "when request fails" do
|
35
35
|
before do
|
36
|
-
allow(request).to
|
37
|
-
|
36
|
+
allow(request).to receive_messages(
|
37
|
+
success?: false,
|
38
|
+
error?: true,
|
39
|
+
error: Aitch::BadRequestError
|
40
|
+
)
|
38
41
|
end
|
39
42
|
|
40
43
|
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
@@ -25,8 +25,8 @@ describe PagSeguro::Items do
|
|
25
25
|
it "sets item from Hash" do
|
26
26
|
item = PagSeguro::Item.new(id: 1234)
|
27
27
|
|
28
|
-
PagSeguro::Item
|
29
|
-
.
|
28
|
+
expect(PagSeguro::Item)
|
29
|
+
.to receive(:new)
|
30
30
|
.with({id: 1234})
|
31
31
|
.and_return(item)
|
32
32
|
|
@@ -36,16 +36,6 @@ describe PagSeguro::Items do
|
|
36
36
|
expect(items).to include(item)
|
37
37
|
end
|
38
38
|
|
39
|
-
it "increases quantity when adding duplicated item" do
|
40
|
-
item = PagSeguro::Item.new(id: 1234)
|
41
|
-
items = PagSeguro::Items.new
|
42
|
-
items << item
|
43
|
-
items << item
|
44
|
-
|
45
|
-
expect(items.size).to eql(1)
|
46
|
-
expect(item.quantity).to eql(2)
|
47
|
-
end
|
48
|
-
|
49
39
|
it "empties items" do
|
50
40
|
items = PagSeguro::Items.new
|
51
41
|
items << {id: 1234}
|
@@ -53,4 +43,106 @@ describe PagSeguro::Items do
|
|
53
43
|
|
54
44
|
expect(items).to be_empty
|
55
45
|
end
|
46
|
+
|
47
|
+
context "#<<" do
|
48
|
+
before do
|
49
|
+
subject << item
|
50
|
+
end
|
51
|
+
|
52
|
+
subject do
|
53
|
+
PagSeguro::Items.new
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:item) do
|
57
|
+
PagSeguro::Item.new(id: 1234, description: "Tea", quantity: 1, amount: 300.0)
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when add same item" do
|
61
|
+
context "and no quantity is informed" do
|
62
|
+
let(:other_item) do
|
63
|
+
{ id: 1234, description: "Tea", amount: 300.0 }
|
64
|
+
end
|
65
|
+
|
66
|
+
it "increases one in item quantity" do
|
67
|
+
expect { subject << other_item }.to change { item.quantity }.by(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not increase items size" do
|
71
|
+
expect { subject << other_item }.not_to change { subject.size }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "and quantity is informed" do
|
76
|
+
let(:other_item) do
|
77
|
+
{ id: 1234, description: "Tea", quantity: 20, amount: 300.0 }
|
78
|
+
end
|
79
|
+
|
80
|
+
it "increases item quantity" do
|
81
|
+
expect { subject << other_item }.to change { item.quantity }.by(20)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "does not increase items size" do
|
85
|
+
expect { subject << other_item }.not_to change { subject.size }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when add different item" do
|
91
|
+
context "with only description equals" do
|
92
|
+
let(:other_item) do
|
93
|
+
{ id: 4321, description: "Tea" }
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not increase item quantity" do
|
97
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
98
|
+
end
|
99
|
+
|
100
|
+
it "increases items size" do
|
101
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with only id equals" do
|
106
|
+
let(:other_item) do
|
107
|
+
{ id: 1234, description: "Coffee" }
|
108
|
+
end
|
109
|
+
|
110
|
+
it "does not increase item quantity" do
|
111
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
112
|
+
end
|
113
|
+
|
114
|
+
it "increases subject size" do
|
115
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with only amount equals" do
|
120
|
+
let(:other_item) do
|
121
|
+
{ id: 4321, description: "Coffee", amount: 300.0 }
|
122
|
+
end
|
123
|
+
|
124
|
+
it "does not increase item quantity" do
|
125
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "increases subject size" do
|
129
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with id and description different" do
|
134
|
+
let(:other_item) do
|
135
|
+
{ id: 4321, description: "Coffee" }
|
136
|
+
end
|
137
|
+
|
138
|
+
it "does not increase item quantity" do
|
139
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
140
|
+
end
|
141
|
+
|
142
|
+
it "increases subject size" do
|
143
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
56
148
|
end
|
@@ -7,12 +7,12 @@ describe PagSeguro do
|
|
7
7
|
config.app_key = "APPTOKEN"
|
8
8
|
config.email = "EMAIL"
|
9
9
|
config.token = "TOKEN"
|
10
|
+
config.receiver_email = "RECEIVER_EMAIL"
|
10
11
|
end
|
11
|
-
PagSeguro.receiver_email = "RECEIVER_EMAIL"
|
12
12
|
end
|
13
13
|
|
14
14
|
after do
|
15
|
-
PagSeguro.environment = :production
|
15
|
+
PagSeguro.configuration.environment = :production
|
16
16
|
end
|
17
17
|
|
18
18
|
it { expect(PagSeguro.email).to eql("EMAIL") }
|
@@ -33,8 +33,8 @@ describe PagSeguro do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
context "default settings" do
|
36
|
-
it { expect(PagSeguro.encoding).to eql("UTF-8") }
|
37
|
-
it { expect(PagSeguro.environment).to eql(:production) }
|
36
|
+
it { expect(PagSeguro.configuration.encoding).to eql("UTF-8") }
|
37
|
+
it { expect(PagSeguro.configuration.environment).to eql(:production) }
|
38
38
|
it { expect(PagSeguro.account_credentials.email).to eql("EMAIL") }
|
39
39
|
it { expect(PagSeguro.account_credentials.token).to eql("TOKEN") }
|
40
40
|
it { expect(PagSeguro.application_credentials.app_id).to eql("APP123") }
|
@@ -43,7 +43,7 @@ describe PagSeguro do
|
|
43
43
|
|
44
44
|
describe ".api_url" do
|
45
45
|
it "raises when environment has no endpoint" do
|
46
|
-
PagSeguro.environment = :invalid
|
46
|
+
PagSeguro.configuration.environment = :invalid
|
47
47
|
|
48
48
|
expect {
|
49
49
|
PagSeguro.api_url("/")
|
@@ -55,7 +55,7 @@ describe PagSeguro do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns sandbox api url when the environment is :sandbox" do
|
58
|
-
PagSeguro.environment = :sandbox
|
58
|
+
PagSeguro.configuration.environment = :sandbox
|
59
59
|
|
60
60
|
expect(PagSeguro.api_url("v2/some/path")).to eql("https://ws.sandbox.pagseguro.uol.com.br/v2/some/path")
|
61
61
|
end
|
@@ -63,7 +63,7 @@ describe PagSeguro do
|
|
63
63
|
|
64
64
|
describe ".site_url" do
|
65
65
|
it "raises when environment has no endpoint" do
|
66
|
-
PagSeguro.environment = :invalid
|
66
|
+
PagSeguro.configuration.environment = :invalid
|
67
67
|
|
68
68
|
expect {
|
69
69
|
PagSeguro.site_url("/")
|
@@ -75,7 +75,7 @@ describe PagSeguro do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "returns sandbox site url when the environment is :sandbox" do
|
78
|
-
PagSeguro.environment = :sandbox
|
78
|
+
PagSeguro.configuration.environment = :sandbox
|
79
79
|
expect(PagSeguro.site_url("v2/some/path")).to eql("https://sandbox.pagseguro.uol.com.br/v2/some/path")
|
80
80
|
end
|
81
81
|
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::PaymentRequest::RequestSerializer do
|
4
|
+
context '#to_xml_params' do
|
5
|
+
subject { described_class.new(payment) }
|
6
|
+
|
7
|
+
let(:payment) { PagSeguro::PaymentRequest.new }
|
8
|
+
|
9
|
+
it 'should serializer primary receivers' do
|
10
|
+
payment.primary_receiver = 'a@example.com'
|
11
|
+
expect(subject.to_xml_params).to match %r[<primaryReceiver>.*<email>a@example.com<\/email>.*<\/primaryReceiver>]m
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should serializer other receivers' do
|
15
|
+
payment.receivers = [
|
16
|
+
{
|
17
|
+
email: 'a@example.com',
|
18
|
+
split: {
|
19
|
+
amount: 10,
|
20
|
+
fee_percent: 11,
|
21
|
+
rate_percent: 12
|
22
|
+
}
|
23
|
+
}
|
24
|
+
]
|
25
|
+
expect(subject.to_xml_params).to match %r[<receivers>.*<receiver>.*<email>a@example.com<\/email>]m
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should serializer sender' do
|
29
|
+
payment.sender = PagSeguro::Sender.new(
|
30
|
+
name: 'Sender',
|
31
|
+
email: 'b@example.com',
|
32
|
+
phone: PagSeguro::Phone.new(area_code: 51, number: 2)
|
33
|
+
)
|
34
|
+
expect(subject.to_xml_params).to match %r[<sender>.*<name>Sender<\/name>.*<email>b@example.com<\/email>.*<phone>.*<areaCode>51<\/areaCode>.*<number>2<\/number>]m
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should serializer currency' do
|
38
|
+
payment.currency = 'BRL'
|
39
|
+
expect(subject.to_xml_params).to match %r[<currency>BRL</currency>]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should serializer reference' do
|
43
|
+
payment.reference = 'order123'
|
44
|
+
expect(subject.to_xml_params).to match %r[<reference>order123</reference>]
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should serializer redirect url' do
|
48
|
+
payment.redirect_url = 'http://example.com'
|
49
|
+
expect(subject.to_xml_params).to match %r[<redirectURL>http://example.com</redirectURL>]
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should serializer notification url' do
|
53
|
+
payment.notification_url = 'http://example.com'
|
54
|
+
expect(subject.to_xml_params).to match %r[<notificationURL>http://example.com</notificationURL>]
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'should serializer item' do
|
58
|
+
before do
|
59
|
+
payment.items << { id: 1, description: 'Description#1', quantity: 2, amount: 3, weight: 4, shipping_cost: 5 }
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'to include id' do
|
63
|
+
expect(subject.to_xml_params).to match %r[<id>1</id>]
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'to include description' do
|
67
|
+
expect(subject.to_xml_params).to match %r[<description>Description#1</description>]
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'to include quantity' do
|
71
|
+
expect(subject.to_xml_params).to match %r[<quantity>2</quantity>]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'to include amount' do
|
75
|
+
expect(subject.to_xml_params).to match %r[<amount>3.00</amount>]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'to include weight' do
|
79
|
+
expect(subject.to_xml_params).to match %r[<weight>4</weight>]
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'to include weight' do
|
83
|
+
expect(subject.to_xml_params).to match %r[<shippingCost>5.00</shippingCost>]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context '#to_params' do
|
89
|
+
let(:payment_request) { PagSeguro::PaymentRequest.new }
|
90
|
+
let(:params) { serializer.to_params }
|
91
|
+
subject(:serializer) { described_class.new(payment_request) }
|
92
|
+
|
93
|
+
context "global configuration serialization" do
|
94
|
+
before do
|
95
|
+
PagSeguro.configuration.receiver_email = "RECEIVER"
|
96
|
+
end
|
97
|
+
|
98
|
+
it { expect(params).to include(receiverEmail: PagSeguro.configuration.receiver_email) }
|
99
|
+
end
|
100
|
+
|
101
|
+
context "generic attributes serialization" do
|
102
|
+
let(:payment_request) do
|
103
|
+
double(:PaymentRequest,
|
104
|
+
currency: "BRL",
|
105
|
+
reference: "REF123",
|
106
|
+
extra_amount: 1234.50,
|
107
|
+
redirect_url: "REDIRECT_URL",
|
108
|
+
notification_url: "NOTIFICATION_URL",
|
109
|
+
abandon_url: "ABANDON_URL",
|
110
|
+
max_uses: 5,
|
111
|
+
max_age: 3600,
|
112
|
+
).as_null_object
|
113
|
+
end
|
114
|
+
|
115
|
+
it { expect(params).to include(currency: "BRL") }
|
116
|
+
it { expect(params).to include(reference: "REF123") }
|
117
|
+
it { expect(params).to include(extraAmount: "1234.50") }
|
118
|
+
it { expect(params).to include(redirectURL: "REDIRECT_URL") }
|
119
|
+
it { expect(params).to include(notificationURL: "NOTIFICATION_URL") }
|
120
|
+
it { expect(params).to include(abandonURL: "ABANDON_URL") }
|
121
|
+
it { expect(params).to include(maxUses: 5) }
|
122
|
+
it { expect(params).to include(maxAge: 3600) }
|
123
|
+
end
|
124
|
+
|
125
|
+
context "shipping serialization" do
|
126
|
+
before do
|
127
|
+
payment_request.shipping = PagSeguro::Shipping.new({
|
128
|
+
type_id: 1,
|
129
|
+
cost: 1234.56
|
130
|
+
})
|
131
|
+
end
|
132
|
+
|
133
|
+
it { expect(params).to include(shippingType: 1) }
|
134
|
+
it { expect(params).to include(shippingCost: "1234.56") }
|
135
|
+
end
|
136
|
+
|
137
|
+
context "address serialization" do
|
138
|
+
let(:address) do
|
139
|
+
PagSeguro::Address.new(
|
140
|
+
street: "STREET",
|
141
|
+
state: "STATE",
|
142
|
+
city: "CITY",
|
143
|
+
postal_code: "POSTAL_CODE",
|
144
|
+
district: "DISTRICT",
|
145
|
+
number: "NUMBER",
|
146
|
+
complement: "COMPLEMENT"
|
147
|
+
)
|
148
|
+
end
|
149
|
+
let(:payment_request) do
|
150
|
+
double(:PaymentRequest, shipping: shipping).as_null_object
|
151
|
+
end
|
152
|
+
let(:shipping) do
|
153
|
+
double(:Shipping, address: address).as_null_object
|
154
|
+
end
|
155
|
+
|
156
|
+
it { expect(params).to include(shippingAddressStreet: "STREET") }
|
157
|
+
it { expect(params).to include(shippingAddressCountry: "BRA") }
|
158
|
+
it { expect(params).to include(shippingAddressState: "STATE") }
|
159
|
+
it { expect(params).to include(shippingAddressCity: "CITY") }
|
160
|
+
it { expect(params).to include(shippingAddressPostalCode: "POSTAL_CODE") }
|
161
|
+
it { expect(params).to include(shippingAddressDistrict: "DISTRICT") }
|
162
|
+
it { expect(params).to include(shippingAddressNumber: "NUMBER") }
|
163
|
+
it { expect(params).to include(shippingAddressComplement: "COMPLEMENT") }
|
164
|
+
end
|
165
|
+
|
166
|
+
context "sender serialization" do
|
167
|
+
before do
|
168
|
+
sender = PagSeguro::Sender.new({
|
169
|
+
email: "EMAIL",
|
170
|
+
name: "NAME",
|
171
|
+
cpf: "CPF"
|
172
|
+
})
|
173
|
+
|
174
|
+
allow(payment_request).to receive(:sender).and_return(sender)
|
175
|
+
end
|
176
|
+
|
177
|
+
it { expect(params).to include(senderEmail: "EMAIL") }
|
178
|
+
it { expect(params).to include(senderName: "NAME") }
|
179
|
+
it { expect(params).to include(senderCPF: "CPF") }
|
180
|
+
end
|
181
|
+
|
182
|
+
context "phone serialization" do
|
183
|
+
before do
|
184
|
+
sender = PagSeguro::Sender.new({
|
185
|
+
phone: {
|
186
|
+
area_code: "AREA_CODE",
|
187
|
+
number: "NUMBER"
|
188
|
+
}
|
189
|
+
})
|
190
|
+
|
191
|
+
allow(payment_request).to receive(:sender).and_return(sender)
|
192
|
+
end
|
193
|
+
|
194
|
+
it { expect(params).to include(senderAreaCode: "AREA_CODE") }
|
195
|
+
it { expect(params).to include(senderPhone: "NUMBER") }
|
196
|
+
end
|
197
|
+
|
198
|
+
context "items serialization" do
|
199
|
+
def build_item(index)
|
200
|
+
PagSeguro::Item.new({
|
201
|
+
id: "ID#{index}",
|
202
|
+
description: "DESC#{index}",
|
203
|
+
quantity: "QTY#{index}",
|
204
|
+
amount: index * 100 + 0.12,
|
205
|
+
weight: "WEIGHT#{index}",
|
206
|
+
shipping_cost: index * 100 + 0.34
|
207
|
+
})
|
208
|
+
end
|
209
|
+
|
210
|
+
shared_examples_for "item serialization" do |index|
|
211
|
+
it { expect(params).to include("itemId#{index}" => "ID#{index}") }
|
212
|
+
it { expect(params).to include("itemDescription#{index}" => "DESC#{index}") }
|
213
|
+
it { expect(params).to include("itemAmount#{index}" => "#{index}00.12") }
|
214
|
+
it { expect(params).to include("itemShippingCost#{index}" => "#{index}00.34") }
|
215
|
+
it { expect(params).to include("itemQuantity#{index}" => "QTY#{index}") }
|
216
|
+
it { expect(params).to include("itemWeight#{index}" => "WEIGHT#{index}") }
|
217
|
+
end
|
218
|
+
|
219
|
+
before do
|
220
|
+
payment_request.items << build_item(1)
|
221
|
+
payment_request.items << build_item(2)
|
222
|
+
end
|
223
|
+
|
224
|
+
it_behaves_like "item serialization", 1
|
225
|
+
it_behaves_like "item serialization", 2
|
226
|
+
end
|
227
|
+
|
228
|
+
context "credentials serialization" do
|
229
|
+
before do
|
230
|
+
credentials = PagSeguro::ApplicationCredentials.new(
|
231
|
+
"app123", "qwerty", "authocode"
|
232
|
+
)
|
233
|
+
|
234
|
+
payment_request.stub(credentials: credentials)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context "extra params serialization" do
|
239
|
+
let(:payment_request) do
|
240
|
+
double(:PaymentRequest,
|
241
|
+
extra_params: [
|
242
|
+
{ extraParam: 'param_value' },
|
243
|
+
{ newExtraParam: 'extra_param_value' }
|
244
|
+
]).as_null_object
|
245
|
+
end
|
246
|
+
|
247
|
+
it { expect(params).to include(extraParam: 'param_value') }
|
248
|
+
it { expect(params).to include(newExtraParam: 'extra_param_value') }
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|