pag_seguro 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +5 -2
- data/README.md +71 -6
- data/lib/pag_seguro/checkout.xml.haml +24 -5
- data/lib/pag_seguro/convert_field_to_digit.rb +15 -0
- data/lib/pag_seguro/day_of_year.rb +35 -0
- data/lib/pag_seguro/item.rb +9 -11
- data/lib/pag_seguro/notification.rb +1 -1
- data/lib/pag_seguro/payment.rb +26 -19
- data/lib/pag_seguro/pre_approval.rb +84 -0
- data/lib/pag_seguro/query.rb +27 -1
- data/lib/pag_seguro/sender.rb +2 -2
- data/lib/pag_seguro/shipping.rb +2 -2
- data/lib/pag_seguro/transaction.rb +1 -1
- data/lib/pag_seguro/version.rb +1 -1
- data/lib/pag_seguro.rb +9 -1
- data/lib/pagseguro_decimal_validator.rb +9 -0
- data/pag_seguro.gemspec +1 -0
- data/spec/factories.rb +137 -0
- data/spec/fixtures/transaction_history.xml +40 -0
- data/spec/pag_seguro/checkout_xml_spec.rb +142 -159
- data/spec/pag_seguro/convert_field_to_digit_spec.rb +68 -0
- data/spec/pag_seguro/day_of_year_spec.rb +49 -0
- data/spec/pag_seguro/integration/checkout_spec.rb +34 -67
- data/spec/pag_seguro/integration/config.yml +4 -4
- data/spec/pag_seguro/integration/query_spec.rb +56 -34
- data/spec/pag_seguro/item_spec.rb +46 -72
- data/spec/pag_seguro/payment_method_spec.rb +58 -63
- data/spec/pag_seguro/payment_spec.rb +150 -123
- data/spec/pag_seguro/pre_approval_spec.rb +112 -0
- data/spec/pag_seguro/query_spec.rb +111 -4
- data/spec/pag_seguro/sender_spec.rb +50 -62
- data/spec/pag_seguro/shipping_spec.rb +36 -51
- data/spec/spec_helper.rb +11 -20
- data/spec/support/transaction_shared_examples.rb +7 -7
- metadata +32 -3
data/spec/factories.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
FactoryGirl.define do
|
3
|
+
factory :day_of_year, class: PagSeguro::DayOfYear do
|
4
|
+
day 7
|
5
|
+
month 7
|
6
|
+
end
|
7
|
+
|
8
|
+
factory :item, class: PagSeguro::Item do
|
9
|
+
id 1
|
10
|
+
description "descrevendo um item"
|
11
|
+
amount "100.50"
|
12
|
+
quantity 1
|
13
|
+
shipping_cost nil
|
14
|
+
weight nil
|
15
|
+
|
16
|
+
factory :item_1 do
|
17
|
+
id 25
|
18
|
+
description 'A Bic Pen'
|
19
|
+
amount '1.50'
|
20
|
+
quantity '4'
|
21
|
+
shipping_cost '1.00'
|
22
|
+
weight 10
|
23
|
+
end
|
24
|
+
|
25
|
+
factory :item_2 do
|
26
|
+
id 73
|
27
|
+
description 'A Book & Cover'
|
28
|
+
amount '38.23'
|
29
|
+
quantity '1'
|
30
|
+
shipping_cost '12.00'
|
31
|
+
weight 300
|
32
|
+
end
|
33
|
+
|
34
|
+
factory :item_3 do
|
35
|
+
id 95
|
36
|
+
description 'A Towel'
|
37
|
+
amount '69.35'
|
38
|
+
quantity '2'
|
39
|
+
weight 400
|
40
|
+
end
|
41
|
+
|
42
|
+
factory :item_4 do
|
43
|
+
id 17
|
44
|
+
description 'A pipe'
|
45
|
+
amount '3.00'
|
46
|
+
quantity '89'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
factory :payment, class: PagSeguro::Payment do
|
51
|
+
ignore do
|
52
|
+
email 'myemail'
|
53
|
+
token 'mytoken'
|
54
|
+
end
|
55
|
+
items []
|
56
|
+
shipping nil
|
57
|
+
sender nil
|
58
|
+
pre_approval nil
|
59
|
+
|
60
|
+
initialize_with { new(email, token) }
|
61
|
+
|
62
|
+
factory(:payment_with_item) { items { [build(:item)] } }
|
63
|
+
factory(:payment_with_items) { items { [build(:item_1), build(:item_2), build(:item_3), build(:item_4)] } }
|
64
|
+
factory(:payment_with_sender) { sender { build(:sender) } }
|
65
|
+
factory(:payment_with_shipping) { shipping { build(:shipping) } }
|
66
|
+
factory(:payment_with_pre_approval) { pre_approval { build(:pre_approval) } }
|
67
|
+
factory(:payment_with_weekly_pre_approval) { pre_approval { build(:weekly_pre_approval) } }
|
68
|
+
factory(:payment_with_monthly_pre_approval) { pre_approval { build(:monthly_pre_approval) } }
|
69
|
+
factory(:payment_with_yearly_pre_approval) { pre_approval { build(:yearly_pre_approval) } }
|
70
|
+
factory :payment_with_all_fields do
|
71
|
+
items { [build(:item_1), build(:item_2), build(:item_3), build(:item_4)] }
|
72
|
+
shipping { build(:shipping) }
|
73
|
+
sender { build(:sender) }
|
74
|
+
pre_approval { build(:weekly_pre_approval) }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
factory :payment_method, class: PagSeguro::PaymentMethod do
|
79
|
+
code 101
|
80
|
+
type 1
|
81
|
+
end
|
82
|
+
|
83
|
+
factory :minimum_pre_approval, class: PagSeguro::PreApproval do
|
84
|
+
name "Super seguro para notebook"
|
85
|
+
final_date Date.new(2014, 1, 17)
|
86
|
+
max_amount_per_period BigDecimal.new('200.00')
|
87
|
+
max_total_amount BigDecimal.new('900.00')
|
88
|
+
period :weekly
|
89
|
+
day_of_week :monday
|
90
|
+
details nil
|
91
|
+
initial_date nil
|
92
|
+
amount_per_payment nil
|
93
|
+
review_URL nil
|
94
|
+
|
95
|
+
factory :pre_approval do
|
96
|
+
details "Toda segunda feira será cobrado o valor de R$150,00 para o seguro do notebook"
|
97
|
+
amount_per_payment BigDecimal.new('150.00')
|
98
|
+
initial_date Date.new(2015, 1, 17)
|
99
|
+
final_date Date.new(2017, 1, 17)
|
100
|
+
review_URL "http://sounoob.com.br/produto1"
|
101
|
+
end
|
102
|
+
|
103
|
+
factory :weekly_pre_approval do
|
104
|
+
period :weekly
|
105
|
+
day_of_week :monday
|
106
|
+
end
|
107
|
+
|
108
|
+
factory :monthly_pre_approval do
|
109
|
+
period :monthly
|
110
|
+
day_of_month 3
|
111
|
+
end
|
112
|
+
|
113
|
+
factory :yearly_pre_approval do
|
114
|
+
period :yearly
|
115
|
+
day_of_year PagSeguro::DayOfYear.new(day: 1, month: 3)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
factory :shipping, class: PagSeguro::Shipping do
|
120
|
+
type PagSeguro::Shipping::SEDEX
|
121
|
+
state "SP"
|
122
|
+
city "São Paulo"
|
123
|
+
postal_code "05363000"
|
124
|
+
district "Jd. PoliPoli"
|
125
|
+
street "Av. Otacilio Tomanik"
|
126
|
+
number "775"
|
127
|
+
complement "apto. 92"
|
128
|
+
cost "12.13"
|
129
|
+
end
|
130
|
+
|
131
|
+
factory :sender, class: PagSeguro::Sender do
|
132
|
+
name "Stefano Diem Benatti"
|
133
|
+
email "stefano@heavenstudio.com.br"
|
134
|
+
phone_ddd 11
|
135
|
+
phone_number 993430994
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<transactionSearchResult>
|
2
|
+
<date>2011-02-16T20:14:35.000-02:00</date>
|
3
|
+
<currentPage>1</currentPage>
|
4
|
+
<resultsInThisPage>10</resultsInThisPage>
|
5
|
+
<totalPages>1</totalPages>
|
6
|
+
<transactions>
|
7
|
+
<transaction>
|
8
|
+
<date>2011-02-05T15:46:12.000-02:00</date>
|
9
|
+
<lastEventDate>2011-02-15T17:39:14.000-03:00</lastEventDate>
|
10
|
+
<code>9E884542-81B3-4419-9A75-BCC6FB495EF1</code>
|
11
|
+
<reference>REF1234</reference>
|
12
|
+
<type>1</type>
|
13
|
+
<status>3</status>
|
14
|
+
<paymentMethod>
|
15
|
+
<type>1</type>
|
16
|
+
</paymentMethod>
|
17
|
+
<grossAmount>49900.00</grossAmount>
|
18
|
+
<discountAmount>0.00</discountAmount>
|
19
|
+
<feeAmount>0.00</feeAmount>
|
20
|
+
<netAmount>49900.00</netAmount>
|
21
|
+
<extraAmount>0.00</extraAmount>
|
22
|
+
</transaction>
|
23
|
+
<transaction>
|
24
|
+
<date>2011-02-07T18:57:52.000-02:00</date>
|
25
|
+
<lastEventDate>2011-02-14T21:37:24.000-03:00</lastEventDate>
|
26
|
+
<code>2FB07A22-68FF-4F83-A356-24153A0C05E1</code>
|
27
|
+
<reference>REF5678</reference>
|
28
|
+
<type>3</type>
|
29
|
+
<status>4</status>
|
30
|
+
<paymentMethod>
|
31
|
+
<type>3</type>
|
32
|
+
</paymentMethod>
|
33
|
+
<grossAmount>26900.00</grossAmount>
|
34
|
+
<discountAmount>0.00</discountAmount>
|
35
|
+
<feeAmount>0.00</feeAmount>
|
36
|
+
<netAmount>26900.00</netAmount>
|
37
|
+
<extraAmount>0.00</extraAmount>
|
38
|
+
</transaction>
|
39
|
+
</transactions>
|
40
|
+
</transactionSearchResult>
|
@@ -1,193 +1,176 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
PagSeguro::
|
6
|
-
|
7
|
-
PagSeguro::Item.new(id: 95, description: "A Towel", amount: "69.35", quantity: "2", weight: 400),
|
8
|
-
PagSeguro::Item.new(id: 17, description: "A pipe", amount: "3.00", quantity: "89")
|
9
|
-
]
|
10
|
-
|
11
|
-
sender_info = {name: "Stefano Diem Benatti", email: "stefano@heavenstudio.com.br", phone_ddd: "11", phone_number: "93430994"}
|
4
|
+
describe PagSeguro::Payment do
|
5
|
+
let(:payment){ PagSeguro::Payment.new }
|
6
|
+
let(:xml){ Nokogiri::XML(payment.checkout_xml) }
|
12
7
|
|
13
|
-
|
14
|
-
|
8
|
+
# Nokogiri helper methods
|
9
|
+
def xml_content(selector)
|
10
|
+
xml.css(selector).present? ? xml.css(selector).first.content : []
|
11
|
+
end
|
15
12
|
|
13
|
+
def xml_collection(selector)
|
14
|
+
xml.css(selector).map(&:content)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
it "should be a valid xml" do
|
22
|
-
lambda { Nokogiri::XML(@payment.checkout_xml) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT } }.should_not raise_error
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should have encoding UTF-8" do
|
26
|
-
@payment.checkout_xml.should match(/^<\?xml.+encoding="UTF-8".+\?>$/)
|
17
|
+
context 'checkout_xml' do
|
18
|
+
it 'should be a valid xml' do
|
19
|
+
expect { Nokogiri::XML(payment.checkout_xml) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT } }.to_not raise_error
|
27
20
|
end
|
28
21
|
|
29
|
-
|
30
|
-
Nokogiri::XML(@payment.checkout_xml).css("checkout currency").first.content.should == "BRL"
|
31
|
-
end
|
22
|
+
its(:checkout_xml){ should match(/^<\?xml.+encoding="UTF-8".+\?>$/) }
|
32
23
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
it
|
40
|
-
|
24
|
+
describe 'settings' do
|
25
|
+
it { xml_content('checkout reference').should be_empty }
|
26
|
+
it { xml_content('checkout extraAmount').should be_empty }
|
27
|
+
it { xml_content('checkout redirectURL').should be_empty }
|
28
|
+
it { xml_content('checkout maxUses').should be_empty }
|
29
|
+
it { xml_content('checkout maxAge').should be_empty }
|
30
|
+
it { xml_content('checkout currency').should == 'BRL' }
|
31
|
+
|
32
|
+
context 'with id' do
|
33
|
+
before{ payment.id = 305 }
|
34
|
+
it { xml_content('checkout reference').should == '305' }
|
41
35
|
end
|
42
36
|
|
43
|
-
|
44
|
-
|
37
|
+
context 'with extra amount' do
|
38
|
+
before{ payment.extra_amount = '10.50' }
|
39
|
+
it { xml_content('checkout extraAmount').should == '10.50' }
|
45
40
|
end
|
46
41
|
|
47
|
-
|
48
|
-
|
42
|
+
context 'with redirect url' do
|
43
|
+
before{ payment.redirect_url = 'http://heavenstudio.com.br' }
|
44
|
+
it { xml_content('checkout redirectURL').should == 'http://heavenstudio.com.br' }
|
49
45
|
end
|
50
46
|
|
51
|
-
|
52
|
-
|
47
|
+
context 'with max uses' do
|
48
|
+
before{ payment.max_uses = '10' }
|
49
|
+
it { xml_content('checkout maxUses').should == '10' }
|
53
50
|
end
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
it "should show all quantities" do
|
60
|
-
@xml.css("checkout items item quantity").map(&:content).should == ["4","1","2","89"]
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should show all shipping_costs" do
|
64
|
-
@xml.css("checkout items item shippingCost").map(&:content).should == ["1.00","12.00"]
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should show all weights" do
|
68
|
-
@xml.css("checkout items item weight").map(&:content).should == ["10","300","400"]
|
52
|
+
context 'with max age' do
|
53
|
+
before{ payment.max_age = '5000' }
|
54
|
+
it { xml_content('checkout maxAge').should == '5000' }
|
69
55
|
end
|
70
56
|
end
|
71
|
-
|
72
|
-
context "sender info" do
|
73
|
-
before do
|
74
|
-
@xml_without_sender_info = Nokogiri::XML(@payment.checkout_xml)
|
75
|
-
@payment.sender = PagSeguro::Sender.new(sender_info)
|
76
|
-
@xml = Nokogiri::XML(@payment.checkout_xml)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should have sender name" do
|
80
|
-
@xml_without_sender_info.css("checkout sender name").should be_empty
|
81
|
-
@xml.css("checkout sender name").first.content.should == "Stefano Diem Benatti"
|
82
|
-
end
|
83
57
|
|
84
|
-
|
85
|
-
|
86
|
-
@xml.css("checkout sender email").first.content.should == "stefano@heavenstudio.com.br"
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should have sender phone ddd" do
|
90
|
-
@xml_without_sender_info.css("checkout sender phone areaCode").should be_empty
|
91
|
-
@xml.css("checkout sender phone areaCode").first.content.should == "11"
|
92
|
-
end
|
58
|
+
describe 'items' do
|
59
|
+
let(:payment){ build :payment_with_items }
|
93
60
|
|
94
|
-
it
|
95
|
-
|
96
|
-
|
61
|
+
it { xml_collection('checkout items item').size.should == 4 }
|
62
|
+
it { xml_collection('checkout items item id').should == ['25', '73', '95', '17'] }
|
63
|
+
it { xml_collection('checkout items item description').should == ['A Bic Pen', 'A Book & Cover', 'A Towel', 'A pipe'] }
|
64
|
+
it { xml_collection('checkout items item amount').should == ['1.50', '38.23', '69.35', '3.00'] }
|
65
|
+
it { xml_collection('checkout items item quantity').should == ['4', '1', '2', '89'] }
|
66
|
+
it { xml_collection('checkout items item shippingCost').should == ['1.00', '12.00'] }
|
67
|
+
it { xml_collection('checkout items item weight').should == ['10', '300', '400'] }
|
68
|
+
|
69
|
+
it 'should escape html in item description' do
|
70
|
+
payment.checkout_xml.should include('A Book & Cover')
|
97
71
|
end
|
98
72
|
end
|
99
73
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
it "should not have any shipping info unless shipping is provided" do
|
108
|
-
@xml_without_shipping_info.css("checkout shipping").should be_empty
|
109
|
-
@xml.css("checkout shipping").should_not be_empty
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should have a default shipping type of UNINDENTIFIED" do
|
113
|
-
@payment.shipping = PagSeguro::Shipping.new
|
114
|
-
xml_with_empty_shipping = Nokogiri::XML(@payment.checkout_xml)
|
115
|
-
xml_with_empty_shipping.css("checkout shipping type").first.content.to_i.should == PagSeguro::Shipping::UNIDENTIFIED
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should allow to set a different shipping type" do
|
119
|
-
@xml.css("checkout shipping type").first.content.to_i.should == PagSeguro::Shipping::SEDEX
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should allow to set a shipping cost" do
|
123
|
-
@xml.css("checkout shipping cost").first.content.should == "12.13"
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should have state" do
|
127
|
-
@xml_without_shipping_info.css("checkout shipping address state").should be_empty
|
128
|
-
@xml.css("checkout shipping address state").first.content.should == "SP"
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should have city" do
|
132
|
-
@xml_without_shipping_info.css("checkout shipping address city").should be_empty
|
133
|
-
@xml.css("checkout shipping address city").first.content.should == "São Paulo"
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should have postal code" do
|
137
|
-
@xml_without_shipping_info.css("checkout shipping address postalCode").should be_empty
|
138
|
-
@xml.css("checkout shipping address postalCode").first.content.should == "05363000"
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should have district" do
|
142
|
-
@xml_without_shipping_info.css("checkout shipping address district").should be_empty
|
143
|
-
@xml.css("checkout shipping address district").first.content.should == "Jd. PoliPoli"
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should have street" do
|
147
|
-
@xml_without_shipping_info.css("checkout shipping address street").should be_empty
|
148
|
-
@xml.css("checkout shipping address street").first.content.should == "Av. Otacilio Tomanik"
|
74
|
+
describe 'sender info' do
|
75
|
+
context 'without sender' do
|
76
|
+
it { xml_content('checkout sender name').should be_empty }
|
77
|
+
it { xml_content('checkout sender email').should be_empty }
|
78
|
+
it { xml_content('checkout sender phone areaCode').should be_empty }
|
79
|
+
it { xml_content('checkout sender phone number').should be_empty }
|
149
80
|
end
|
150
81
|
|
151
|
-
|
152
|
-
|
153
|
-
@xml.css("checkout shipping address number").first.content.should == "775"
|
154
|
-
end
|
82
|
+
context 'with sender' do
|
83
|
+
let(:payment){ build :payment_with_sender }
|
155
84
|
|
156
|
-
|
157
|
-
|
158
|
-
|
85
|
+
it { xml_content('checkout sender name').should == 'Stefano Diem Benatti' }
|
86
|
+
it { xml_content('checkout sender email').should == 'stefano@heavenstudio.com.br' }
|
87
|
+
it { xml_content('checkout sender phone areaCode').should == '11' }
|
88
|
+
it { xml_content('checkout sender phone number').should == '993430994' }
|
159
89
|
end
|
160
90
|
end
|
161
91
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
92
|
+
describe 'shipping info' do
|
93
|
+
context 'without shipping' do
|
94
|
+
it { xml_content('checkout shipping').should be_empty }
|
95
|
+
it { xml_content('checkout shipping address').should be_empty }
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with empty shipping' do
|
99
|
+
before{ payment.shipping = PagSeguro::Shipping.new }
|
100
|
+
|
101
|
+
it { xml_content('checkout shipping').should_not be_empty }
|
102
|
+
it { xml_content('checkout shipping address').should_not be_empty }
|
103
|
+
it { xml_content('checkout shipping address state').should be_empty }
|
104
|
+
it { xml_content('checkout shipping address city').should be_empty }
|
105
|
+
it { xml_content('checkout shipping address postalCode').should be_empty }
|
106
|
+
it { xml_content('checkout shipping address district').should be_empty }
|
107
|
+
it { xml_content('checkout shipping address street').should be_empty }
|
108
|
+
it { xml_content('checkout shipping address number').should be_empty }
|
109
|
+
it { xml_content('checkout shipping address complement').should be_empty }
|
110
|
+
it { xml_content('checkout shipping type').to_i.should == PagSeguro::Shipping::UNIDENTIFIED }
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with shipping' do
|
114
|
+
let(:payment){ build :payment_with_shipping }
|
115
|
+
|
116
|
+
it { xml_content('checkout shipping').should_not be_empty }
|
117
|
+
it { xml_content('checkout shipping address').should_not be_empty }
|
118
|
+
it { xml_content('checkout shipping type').to_i.should == PagSeguro::Shipping::SEDEX }
|
119
|
+
it { xml_content('checkout shipping cost').should == '12.13' }
|
120
|
+
it { xml_content('checkout shipping address state').should == 'SP' }
|
121
|
+
it { xml_content('checkout shipping address city').should == 'São Paulo' }
|
122
|
+
it { xml_content('checkout shipping address postalCode').should == '05363000' }
|
123
|
+
it { xml_content('checkout shipping address district').should == 'Jd. PoliPoli' }
|
124
|
+
it { xml_content('checkout shipping address street').should == 'Av. Otacilio Tomanik' }
|
125
|
+
it { xml_content('checkout shipping address number').should == '775' }
|
126
|
+
it { xml_content('checkout shipping address complement').should == 'apto. 92' }
|
167
127
|
end
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'pre approval info' do
|
131
|
+
context 'without pre approval' do
|
132
|
+
it { xml_content('checkout preApproval').should be_empty }
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'with pre_approval' do
|
136
|
+
let(:payment){ build :payment_with_pre_approval }
|
137
|
+
|
138
|
+
it { xml_content('checkout preApproval').should_not be_empty }
|
139
|
+
it { xml_content('checkout preApproval name').should == 'Super seguro para notebook' }
|
140
|
+
it { xml_content('checkout preApproval details').should == 'Toda segunda feira será cobrado o valor de R$150,00 para o seguro do notebook' }
|
141
|
+
it { xml_content('checkout preApproval amountPerPayment').should == '150.00' }
|
142
|
+
it { xml_content('checkout preApproval initialDate').should == '2015-01-17T00:00:00+00:00' }
|
143
|
+
it { xml_content('checkout preApproval finalDate').should == '2017-01-17T00:00:00+00:00' }
|
144
|
+
it { xml_content('checkout preApproval maxAmountPerPeriod').should == '200.00' }
|
145
|
+
it { xml_content('checkout preApproval maxTotalAmount').should == '900.00' }
|
146
|
+
it { xml_content('checkout preApproval reviewURL').should == 'http://sounoob.com.br/produto1' }
|
147
|
+
|
148
|
+
context 'weekly' do
|
149
|
+
let(:payment){ build :payment_with_weekly_pre_approval }
|
150
|
+
|
151
|
+
it { xml_content('checkout preApproval period').should == 'weekly' }
|
152
|
+
it { xml_content('checkout preApproval dayOfWeek').should == 'monday' }
|
153
|
+
it { xml_content('checkout preApproval dayOfMonth').should be_empty }
|
154
|
+
it { xml_content('checkout preApproval dayOfYear').should be_empty }
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'monthly' do
|
158
|
+
let(:payment){ build :payment_with_monthly_pre_approval }
|
159
|
+
|
160
|
+
it { xml_content('checkout preApproval period').should == 'monthly' }
|
161
|
+
it { xml_content('checkout preApproval dayOfWeek').should be_empty }
|
162
|
+
it { xml_content('checkout preApproval dayOfMonth').should == '3' }
|
163
|
+
it { xml_content('checkout preApproval dayOfYear').should be_empty }
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'yearly' do
|
167
|
+
let(:payment){ build :payment_with_yearly_pre_approval }
|
168
|
+
|
169
|
+
it { xml_content('checkout preApproval period').should == 'yearly' }
|
170
|
+
it { xml_content('checkout preApproval dayOfWeek').should be_empty }
|
171
|
+
it { xml_content('checkout preApproval dayOfMonth').should be_empty }
|
172
|
+
it { xml_content('checkout preApproval dayOfYear').should == '03-01' }
|
173
|
+
end
|
191
174
|
end
|
192
175
|
end
|
193
176
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MyObject
|
4
|
+
attr_accessor :price, :amount
|
5
|
+
end
|
6
|
+
|
7
|
+
describe PagSeguro::ConvertFieldToDigit do
|
8
|
+
subject{ MyObject.new }
|
9
|
+
|
10
|
+
context "normal object" do
|
11
|
+
context "with numeric price" do
|
12
|
+
before{ subject.price = 10.02 }
|
13
|
+
its(:price){ should == 10.02 }
|
14
|
+
its(:price){ should be_an_instance_of(Float) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with string price" do
|
18
|
+
before{ subject.price = '10.02' }
|
19
|
+
its(:price){ should == '10.02' }
|
20
|
+
its(:price){ should be_an_instance_of(String) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with decimal price" do
|
24
|
+
before{ subject.price = BigDecimal.new('10.02') }
|
25
|
+
its(:price){ should == BigDecimal.new('10.02') }
|
26
|
+
its(:price){ should be_an_instance_of(BigDecimal) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "object with price converted to digit" do
|
31
|
+
before do
|
32
|
+
MyObject.class_eval do
|
33
|
+
extend PagSeguro::ConvertFieldToDigit
|
34
|
+
attr_reader_as_digit :price, :amount
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with numeric attribute" do
|
39
|
+
before{ subject.price, subject.amount = 10.2, 10 }
|
40
|
+
its(:price){ should == '10.20' }
|
41
|
+
its(:price){ should be_an_instance_of(String) }
|
42
|
+
its(:amount){ should == '10.00' }
|
43
|
+
its(:amount){ should be_an_instance_of(String) }
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with string attribute" do
|
47
|
+
before{ subject.price, subject.amount = '10.2', '10' }
|
48
|
+
its(:price){ should == '10.20' }
|
49
|
+
its(:price){ should be_an_instance_of(String) }
|
50
|
+
its(:amount){ should == '10.00' }
|
51
|
+
its(:amount){ should be_an_instance_of(String) }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with decimal attribute" do
|
55
|
+
before{ subject.price, subject.amount = BigDecimal.new('10.02'), BigDecimal.new('10') }
|
56
|
+
its(:price){ should == '10.02' }
|
57
|
+
its(:price){ should be_an_instance_of(String) }
|
58
|
+
its(:amount){ should == '10.00' }
|
59
|
+
its(:amount){ should be_an_instance_of(String) }
|
60
|
+
end
|
61
|
+
|
62
|
+
context "with invalid conversion type" do
|
63
|
+
before{ subject.price, subject.amount = '$ 10.00', nil }
|
64
|
+
its(:price){ should == '$ 10.00' }
|
65
|
+
its(:amount){ should == nil }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe PagSeguro::DayOfYear do
|
5
|
+
it { should have_attribute_accessor(:day) }
|
6
|
+
it { should have_attribute_accessor(:month) }
|
7
|
+
|
8
|
+
context "initialized with attributes" do
|
9
|
+
subject{ build :day_of_year, month: 10, day: 21 }
|
10
|
+
|
11
|
+
its(:month){ should == 10 }
|
12
|
+
its(:day){ should == 21 }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#to_s" do
|
16
|
+
it "should output format MM-dd" do
|
17
|
+
build(:day_of_year, month: 11, day: 21).to_s.should == "11-21"
|
18
|
+
build(:day_of_year, month: 1, day: 21).to_s.should == "01-21"
|
19
|
+
build(:day_of_year, month: 11, day: 1).to_s.should == "11-01"
|
20
|
+
build(:day_of_year, month: 1, day: 1).to_s.should == "01-01"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise error if month is bigger than 13" do
|
24
|
+
expect {
|
25
|
+
build(:day_of_year, month: 13, day: 21).to_s
|
26
|
+
}.to raise_error(PagSeguro::Error::InvalidDayOfYear, "DateOfYear should be a valid date: (month: 13, day: 21)")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise error if day is bigger than 31" do
|
30
|
+
expect {
|
31
|
+
build(:day_of_year, month: 1, day: 32).to_s
|
32
|
+
}.to raise_error(PagSeguro::Error::InvalidDayOfYear, "DateOfYear should be a valid date: (month: 1, day: 32)")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "comparisons" do
|
37
|
+
it "should be bigger when month is ahead" do
|
38
|
+
build(:day_of_year, month: 2).should be > build(:day_of_year, month: 1)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be bigger when day is ahead if month is the same" do
|
42
|
+
build(:day_of_year, day: 2).should be > build(:day_of_year, day: 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be equal if both day and month are the same" do
|
46
|
+
build(:day_of_year).should be == build(:day_of_year)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|