pag_seguro 0.5.5 → 0.5.6
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +3 -2
- data/README.md +16 -0
- data/lib/pag_seguro.rb +1 -0
- data/lib/pag_seguro/checkout.xml.haml +2 -0
- data/lib/pag_seguro/notification.rb +1 -1
- data/lib/pag_seguro/payment.rb +14 -6
- data/lib/pag_seguro/query.rb +2 -2
- data/lib/pag_seguro/transaction.rb +4 -2
- data/lib/pag_seguro/url.rb +36 -0
- data/lib/pag_seguro/version.rb +1 -1
- data/spec/pag_seguro/checkout_xml_spec.rb +77 -72
- data/spec/pag_seguro/day_of_year_spec.rb +9 -9
- data/spec/pag_seguro/errors/invalid_data_spec.rb +1 -1
- data/spec/pag_seguro/errors/unauthorized_spec.rb +1 -1
- data/spec/pag_seguro/errors/unknown_error_spec.rb +1 -1
- data/spec/pag_seguro/integration/checkout_spec.rb +9 -9
- data/spec/pag_seguro/integration/config.yml +4 -4
- data/spec/pag_seguro/integration/notification_spec.rb +21 -21
- data/spec/pag_seguro/integration/query_spec.rb +23 -23
- data/spec/pag_seguro/item_spec.rb +44 -44
- data/spec/pag_seguro/notification_spec.rb +1 -1
- data/spec/pag_seguro/payment_method_spec.rb +8 -8
- data/spec/pag_seguro/payment_spec.rb +177 -160
- data/spec/pag_seguro/pre_approval_spec.rb +56 -56
- data/spec/pag_seguro/query_spec.rb +26 -24
- data/spec/pag_seguro/sender_spec.rb +10 -10
- data/spec/pag_seguro/shipping_spec.rb +13 -13
- data/spec/pag_seguro/url_spec.rb +53 -0
- data/spec/pag_seguro/version_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- data/spec/support/transaction_shared_examples.rb +186 -167
- metadata +20 -17
@@ -2,8 +2,8 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe PagSeguro::DayOfYear do
|
5
|
-
it {
|
6
|
-
it {
|
5
|
+
it { is_expected.to have_attribute_accessor(:day) }
|
6
|
+
it { is_expected.to have_attribute_accessor(:month) }
|
7
7
|
|
8
8
|
context "initialized with attributes" do
|
9
9
|
subject{ build :day_of_year, month: 10, day: 21 }
|
@@ -14,10 +14,10 @@ describe PagSeguro::DayOfYear do
|
|
14
14
|
|
15
15
|
describe "#to_s" do
|
16
16
|
it "should output format MM-dd" do
|
17
|
-
build(:day_of_year, month: 11, day: 21).to_s.
|
18
|
-
build(:day_of_year, month: 1, day: 21).to_s.
|
19
|
-
build(:day_of_year, month: 11, day: 1).to_s.
|
20
|
-
build(:day_of_year, month: 1, day: 1).to_s.
|
17
|
+
expect(build(:day_of_year, month: 11, day: 21).to_s).to eq("11-21")
|
18
|
+
expect(build(:day_of_year, month: 1, day: 21).to_s).to eq("01-21")
|
19
|
+
expect(build(:day_of_year, month: 11, day: 1).to_s).to eq("11-01")
|
20
|
+
expect(build(:day_of_year, month: 1, day: 1).to_s).to eq("01-01")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should raise error if month is bigger than 13" do
|
@@ -35,15 +35,15 @@ describe PagSeguro::DayOfYear do
|
|
35
35
|
|
36
36
|
describe "comparisons" do
|
37
37
|
it "should be bigger when month is ahead" do
|
38
|
-
build(:day_of_year, month: 2).
|
38
|
+
expect(build(:day_of_year, month: 2)).to be > build(:day_of_year, month: 1)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should be bigger when day is ahead if month is the same" do
|
42
|
-
build(:day_of_year, day: 2).
|
42
|
+
expect(build(:day_of_year, day: 2)).to be > build(:day_of_year, day: 1)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should be equal if both day and month are the same" do
|
46
|
-
build(:day_of_year).
|
46
|
+
expect(build(:day_of_year)).to eq(build(:day_of_year))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -17,6 +17,6 @@ end
|
|
17
17
|
|
18
18
|
describe PagSeguro::Errors::InvalidData do
|
19
19
|
it "should be able to parse an error xml and raise the error codes" do
|
20
|
-
|
20
|
+
expect { raise PagSeguro::Errors::InvalidData.new(invalid_data_xml) }.to raise_error(PagSeguro::Errors::InvalidData, "404: Not Found\n422: Unauthorized\n")
|
21
21
|
end
|
22
22
|
end
|
@@ -2,6 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe PagSeguro::Errors::Unauthorized do
|
4
4
|
it "should be able to raise an unauthorized error" do
|
5
|
-
|
5
|
+
expect { raise PagSeguro::Errors::Unauthorized.new }.to raise_error(PagSeguro::Errors::Unauthorized, "Credentials provided (e-mail and token) failed to authenticate")
|
6
6
|
end
|
7
7
|
end
|
@@ -12,6 +12,6 @@ end
|
|
12
12
|
|
13
13
|
describe PagSeguro::Errors::UnknownError do
|
14
14
|
it "should be able to raise an unknown error" do
|
15
|
-
|
15
|
+
expect { raise PagSeguro::Errors::UnknownError.new(MockResponse.new) }.to raise_error(PagSeguro::Errors::UnknownError, "Unknown response code (10000):\n error description")
|
16
16
|
end
|
17
17
|
end
|
@@ -14,11 +14,11 @@ describe PagSeguro::Payment do
|
|
14
14
|
let(:payment){ build :payment_with_all_fields, email: EMAIL, token: TOKEN }
|
15
15
|
subject { payment }
|
16
16
|
|
17
|
-
its('code.size'){
|
18
|
-
its(:date){
|
17
|
+
its('code.size'){ is_expected.to eq(32) }
|
18
|
+
its(:date){ is_expected.to be_an_instance_of(DateTime) }
|
19
19
|
|
20
20
|
it "should give a response code of 200 for the user pagseguro url" do
|
21
|
-
RestClient.get(payment.checkout_payment_url).code.
|
21
|
+
expect(RestClient.get(payment.checkout_payment_url).code).to eq(200)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -26,11 +26,11 @@ describe PagSeguro::Payment do
|
|
26
26
|
let(:payment){ build :payment_with_item, email: EMAIL, token: TOKEN, pre_approval: build(:minimum_pre_approval) }
|
27
27
|
subject { payment }
|
28
28
|
|
29
|
-
its('code.size'){
|
30
|
-
its(:date){
|
29
|
+
its('code.size'){ is_expected.to eq(32) }
|
30
|
+
its(:date){ is_expected.to be_an_instance_of(DateTime) }
|
31
31
|
|
32
32
|
it "should give a response code of 200 for the user pagseguro url" do
|
33
|
-
RestClient.get(payment.checkout_payment_url).code.
|
33
|
+
expect(RestClient.get(payment.checkout_payment_url).code).to eq(200)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -38,11 +38,11 @@ describe PagSeguro::Payment do
|
|
38
38
|
let(:payment){ build :payment_with_items, email: EMAIL, token: TOKEN }
|
39
39
|
subject { payment }
|
40
40
|
|
41
|
-
its('code.size'){
|
42
|
-
its(:date){
|
41
|
+
its('code.size'){ is_expected.to eq(32) }
|
42
|
+
its(:date){ is_expected.to be_an_instance_of(DateTime) }
|
43
43
|
|
44
44
|
it "should give a response code of 200 for the user pagseguro url" do
|
45
|
-
RestClient.get(payment.checkout_payment_url).code.
|
45
|
+
expect(RestClient.get(payment.checkout_payment_url).code).to eq(200)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
email:
|
2
|
-
token:
|
3
|
-
notification_code:
|
4
|
-
transaction_id:
|
1
|
+
email: seu_email_cadastrado@nopagseguro.com.br
|
2
|
+
token: SEU_TOKEN_GERADO_NO_PAG_SEGURO
|
3
|
+
notification_code: SEU_CODIGO_DE_NOTIFICACAO
|
4
|
+
transaction_id: UM_CODIGO_DE_TRANSACAO
|
@@ -14,31 +14,31 @@ describe PagSeguro::Notification do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
it { @notification.transaction_id.
|
18
|
-
it { @notification.date.
|
19
|
-
it { @notification.id.
|
20
|
-
it { @notification.type.
|
21
|
-
it { @notification.status.
|
22
|
-
it { @notification.payment_method.type.
|
23
|
-
it { @notification.payment_method.code.
|
24
|
-
it { @notification.gross_amount.
|
25
|
-
it { @notification.discount_amount.
|
26
|
-
it { @notification.fee_amount.
|
27
|
-
it { @notification.net_amount.
|
28
|
-
it { @notification.extra_amount.
|
29
|
-
it { @notification.installment_count.
|
30
|
-
it { @notification.item_count.
|
31
|
-
it { @notification.items.
|
17
|
+
it { expect(@notification.transaction_id).to be_present }
|
18
|
+
it { expect(@notification.date).to be_present }
|
19
|
+
it { expect(@notification.id).to be_present }
|
20
|
+
it { expect(@notification.type).to be_present }
|
21
|
+
it { expect(@notification.status).to be_present }
|
22
|
+
it { expect(@notification.payment_method.type).to be_present }
|
23
|
+
it { expect(@notification.payment_method.code).to be_present }
|
24
|
+
it { expect(@notification.gross_amount).to be_present }
|
25
|
+
it { expect(@notification.discount_amount).to be_present }
|
26
|
+
it { expect(@notification.fee_amount).to be_present }
|
27
|
+
it { expect(@notification.net_amount).to be_present }
|
28
|
+
it { expect(@notification.extra_amount).to be_present }
|
29
|
+
it { expect(@notification.installment_count).to be_present }
|
30
|
+
it { expect(@notification.item_count).to be_present }
|
31
|
+
it { expect(@notification.items).to be_present }
|
32
32
|
|
33
33
|
it "should have all required item attributes" do
|
34
34
|
@notification.items.each do |item|
|
35
|
-
item.id.
|
36
|
-
item.description.
|
37
|
-
item.amount.
|
38
|
-
item.quantity.
|
35
|
+
expect(item.id).to be_present
|
36
|
+
expect(item.description).to be_present
|
37
|
+
expect(item.amount).to be_present
|
38
|
+
expect(item.quantity).to be_present
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
it { @notification.sender.email.
|
43
|
-
it { @notification.shipping.type.
|
42
|
+
it { expect(@notification.sender.email).to be_present }
|
43
|
+
it { expect(@notification.shipping.type).to be_present }
|
44
44
|
end
|
@@ -15,33 +15,33 @@ describe PagSeguro::Query do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
it { @query.transaction_id.
|
19
|
-
it { @query.date.
|
20
|
-
it { @query.id.
|
21
|
-
it { @query.type.
|
22
|
-
it { @query.status.
|
23
|
-
it { @query.payment_method.type.
|
24
|
-
it { @query.payment_method.code.
|
25
|
-
it { @query.gross_amount.
|
26
|
-
it { @query.discount_amount.
|
27
|
-
it { @query.fee_amount.
|
28
|
-
it { @query.net_amount.
|
29
|
-
it { @query.extra_amount.
|
30
|
-
it { @query.installment_count.
|
31
|
-
it { @query.item_count.
|
32
|
-
it { @query.items.
|
18
|
+
it { expect(@query.transaction_id).to be_present }
|
19
|
+
it { expect(@query.date).to be_present }
|
20
|
+
it { expect(@query.id).to be_present }
|
21
|
+
it { expect(@query.type).to be_present }
|
22
|
+
it { expect(@query.status).to be_present }
|
23
|
+
it { expect(@query.payment_method.type).to be_present }
|
24
|
+
it { expect(@query.payment_method.code).to be_present }
|
25
|
+
it { expect(@query.gross_amount).to be_present }
|
26
|
+
it { expect(@query.discount_amount).to be_present }
|
27
|
+
it { expect(@query.fee_amount).to be_present }
|
28
|
+
it { expect(@query.net_amount).to be_present }
|
29
|
+
it { expect(@query.extra_amount).to be_present }
|
30
|
+
it { expect(@query.installment_count).to be_present }
|
31
|
+
it { expect(@query.item_count).to be_present }
|
32
|
+
it { expect(@query.items).to be_present }
|
33
33
|
|
34
34
|
it "should have all required item attributes" do
|
35
35
|
@query.items.each do |item|
|
36
|
-
item.id.
|
37
|
-
item.description.
|
38
|
-
item.amount.
|
39
|
-
item.quantity.
|
36
|
+
expect(item.id).to be_present
|
37
|
+
expect(item.description).to be_present
|
38
|
+
expect(item.amount).to be_present
|
39
|
+
expect(item.quantity).to be_present
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
it { @query.sender.email.
|
44
|
-
it { @query.shipping.type.
|
43
|
+
it { expect(@query.sender.email).to be_present }
|
44
|
+
it { expect(@query.shipping.type).to be_present }
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "::find" do
|
@@ -58,8 +58,8 @@ describe PagSeguro::Query do
|
|
58
58
|
|
59
59
|
it "should return an array of Transactions" do
|
60
60
|
@transactions.each do |transaction|
|
61
|
-
transaction.
|
62
|
-
transaction.id.
|
61
|
+
expect(transaction).to be_an_instance_of(PagSeguro::Transaction)
|
62
|
+
expect(transaction.id).to be_present
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -1,55 +1,55 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe PagSeguro::Item do
|
4
|
-
it {
|
5
|
-
it {
|
6
|
-
it {
|
7
|
-
it {
|
8
|
-
it {
|
9
|
-
it {
|
4
|
+
it { is_expected.to have_attribute_accessor(:id) }
|
5
|
+
it { is_expected.to have_attribute_accessor(:description) }
|
6
|
+
it { is_expected.to have_attribute_accessor(:amount) }
|
7
|
+
it { is_expected.to have_attribute_accessor(:quantity) }
|
8
|
+
it { is_expected.to have_attribute_accessor(:shipping_cost) }
|
9
|
+
it { is_expected.to have_attribute_accessor(:weight) }
|
10
10
|
|
11
11
|
it "should be valid with valid attributes" do
|
12
|
-
build(:item).
|
12
|
+
expect(build(:item)).to be_valid
|
13
13
|
end
|
14
14
|
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
24
|
-
|
25
|
-
it {
|
26
|
-
it {
|
27
|
-
it {
|
28
|
-
it {
|
29
|
-
it {
|
30
|
-
it {
|
31
|
-
it {
|
32
|
-
|
33
|
-
it {
|
34
|
-
it {
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
38
|
-
it {
|
39
|
-
it {
|
40
|
-
it {
|
41
|
-
|
42
|
-
it {
|
43
|
-
it {
|
44
|
-
it {
|
45
|
-
it {
|
46
|
-
|
47
|
-
it {
|
48
|
-
it {
|
49
|
-
it {
|
50
|
-
it {
|
15
|
+
it { is_expected.to validate_presence_of :id }
|
16
|
+
it { is_expected.to validate_presence_of :description }
|
17
|
+
it { is_expected.to validate_presence_of :amount }
|
18
|
+
|
19
|
+
it { is_expected.not_to allow_value(nil).for(:quantity) }
|
20
|
+
it { is_expected.not_to allow_value(0).for(:quantity) }
|
21
|
+
it { is_expected.not_to allow_value(1000).for(:quantity) }
|
22
|
+
it { is_expected.to allow_value(1).for(:quantity) }
|
23
|
+
it { is_expected.to allow_value(999).for(:quantity) }
|
24
|
+
|
25
|
+
it { is_expected.not_to allow_value("10,50").for(:amount) }
|
26
|
+
it { is_expected.not_to allow_value("R$ 10.50").for(:amount) }
|
27
|
+
it { is_expected.not_to allow_value("-10.50").for(:amount) }
|
28
|
+
it { is_expected.not_to allow_value("10.50\nanything").for(:amount) }
|
29
|
+
it { is_expected.to allow_value("10.50").for(:amount) }
|
30
|
+
it { is_expected.to allow_value(10).for(:amount) }
|
31
|
+
it { is_expected.to allow_value(BigDecimal.new("10.5")).for(:amount) }
|
32
|
+
|
33
|
+
it { is_expected.not_to allow_value("10,50").for(:shipping_cost) }
|
34
|
+
it { is_expected.not_to allow_value("R$ 10.50").for(:shipping_cost) }
|
35
|
+
it { is_expected.not_to allow_value("-10.50").for(:shipping_cost) }
|
36
|
+
it { is_expected.not_to allow_value("10.50\nanything").for(:shipping_cost) }
|
37
|
+
it { is_expected.to allow_value("10.50").for(:shipping_cost) }
|
38
|
+
it { is_expected.to allow_value(10).for(:shipping_cost) }
|
39
|
+
it { is_expected.to allow_value(BigDecimal.new("10.5")).for(:shipping_cost) }
|
40
|
+
it { is_expected.to allow_value(nil).for(:shipping_cost) }
|
41
|
+
|
42
|
+
it { is_expected.not_to allow_value("1000").for(:quantity) }
|
43
|
+
it { is_expected.not_to allow_value("0").for(:quantity) }
|
44
|
+
it { is_expected.not_to allow_value("-1").for(:quantity) }
|
45
|
+
it { is_expected.to allow_value("1").for(:quantity) }
|
46
|
+
|
47
|
+
it { is_expected.not_to allow_value("-10").for(:weight) }
|
48
|
+
it { is_expected.not_to allow_value("10.5").for(:weight) }
|
49
|
+
it { is_expected.not_to allow_value("10,5").for(:weight) }
|
50
|
+
it { is_expected.to allow_value("3").for(:weight) }
|
51
51
|
|
52
52
|
it "should trim description to 100 characters if it has more than 100 characters" do
|
53
|
-
PagSeguro::Item.new(description: "-" * 101).description.size.
|
53
|
+
expect(PagSeguro::Item.new(description: "-" * 101).description.size).to eq(100)
|
54
54
|
end
|
55
55
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe PagSeguro::Notification do
|
6
|
-
before { PagSeguro::Notification.
|
6
|
+
before { allow_any_instance_of(PagSeguro::Notification).to receive_messages(transaction_data: transaction_data) }
|
7
7
|
let(:transaction){ PagSeguro::Notification.new("mail", "token", "not_code") }
|
8
8
|
subject{ PagSeguro::Notification }
|
9
9
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe PagSeguro::PaymentMethod do
|
5
|
-
it {
|
6
|
-
it {
|
5
|
+
it { is_expected.to have_attribute_accessor(:code) }
|
6
|
+
it { is_expected.to have_attribute_accessor(:type) }
|
7
7
|
|
8
8
|
context "initalized with code and type" do
|
9
9
|
subject { build :payment_method, code: "101", type: "1" }
|
@@ -17,33 +17,33 @@ describe PagSeguro::PaymentMethod do
|
|
17
17
|
|
18
18
|
context "with type 1" do
|
19
19
|
subject { build :payment_method, type: 1 }
|
20
|
-
it {
|
20
|
+
it { is_expected.to be_credit_card }
|
21
21
|
end
|
22
22
|
|
23
23
|
context "with if type 2" do
|
24
24
|
subject { build :payment_method, type: 2 }
|
25
|
-
it {
|
25
|
+
it { is_expected.to be_bank_bill }
|
26
26
|
end
|
27
27
|
|
28
28
|
context "with if type 3" do
|
29
29
|
subject { build :payment_method, type: 3 }
|
30
|
-
it {
|
30
|
+
it { is_expected.to be_online_debit }
|
31
31
|
end
|
32
32
|
|
33
33
|
context "with if type 4" do
|
34
34
|
subject { build :payment_method, type: 4 }
|
35
|
-
it {
|
35
|
+
it { is_expected.to be_pag_seguro_balance }
|
36
36
|
end
|
37
37
|
|
38
38
|
context "with type 5" do
|
39
39
|
subject { build :payment_method, type: 5 }
|
40
|
-
it {
|
40
|
+
it { is_expected.to be_oi_paggo }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe "codes" do
|
45
45
|
def should_have_meaning_for_code(meaning, code)
|
46
|
-
PagSeguro::PaymentMethod.new(code: code).name.
|
46
|
+
expect(PagSeguro::PaymentMethod.new(code: code).name).to eq(meaning)
|
47
47
|
end
|
48
48
|
|
49
49
|
it { should_have_meaning_for_code("Cartão de crédito Visa", 101) }
|
@@ -4,202 +4,219 @@ describe PagSeguro::Payment do
|
|
4
4
|
let(:payment){ PagSeguro::Payment.new }
|
5
5
|
subject{ payment }
|
6
6
|
|
7
|
-
it {
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
describe '#date' do
|
29
|
-
subject{ payment.send(:parse_date) }
|
30
|
-
before{ payment.stub response: double(:response, body: '<checkout><date>2001-02-03T04:05:06+07:00</date></checkout>') }
|
31
|
-
|
32
|
-
it { should be_an_instance_of(DateTime) }
|
33
|
-
its(:year){ should == 2001 }
|
34
|
-
its(:month){ should == 2 }
|
35
|
-
its(:day){ should == 3 }
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#code' do
|
39
|
-
before{ payment.stub response: double(:response, body: '<checkout><code>EE603A-59F0DEF0DAAD-2334FFBF9A1E-3223E3</code></checkout>') }
|
7
|
+
it { is_expected.to have_attribute_accessor(:id) }
|
8
|
+
it { is_expected.to have_attribute_accessor(:items) }
|
9
|
+
it { is_expected.to have_attribute_accessor(:sender) }
|
10
|
+
it { is_expected.to have_attribute_accessor(:shipping) }
|
11
|
+
it { is_expected.to have_attribute_accessor(:email) }
|
12
|
+
it { is_expected.to have_attribute_accessor(:token) }
|
13
|
+
it { is_expected.to have_attribute_accessor(:extra_amount) }
|
14
|
+
it { is_expected.to have_attribute_accessor(:redirect_url) }
|
15
|
+
it { is_expected.to have_attribute_accessor(:max_uses) }
|
16
|
+
it { is_expected.to have_attribute_accessor(:max_age) }
|
17
|
+
it { is_expected.to have_attribute_accessor(:response) }
|
18
|
+
it { is_expected.to have_attribute_accessor(:pre_approval) }
|
19
|
+
|
20
|
+
it { is_expected.to respond_to :code }
|
21
|
+
it { is_expected.to respond_to :date }
|
22
|
+
|
23
|
+
context "sandbox" do
|
24
|
+
before do
|
25
|
+
PagSeguro::Url.environment= :sandbox
|
26
|
+
end
|
40
27
|
|
41
|
-
|
28
|
+
describe "checkout url" do
|
29
|
+
subject { PagSeguro::Payment.checkout_url }
|
30
|
+
it { is_expected.to eq("https://ws.sandbox.pagseguro.uol.com.br/v2/checkout") }
|
31
|
+
end
|
42
32
|
end
|
43
33
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
context 'with email and token initialization' do
|
49
|
-
subject{ build(:payment) }
|
50
|
-
let(:payment){ subject }
|
51
|
-
its(:email){ should == 'myemail' }
|
52
|
-
its(:token){ should == 'mytoken' }
|
53
|
-
|
54
|
-
it { validate_presence_of :email }
|
55
|
-
it { validate_presence_of :token }
|
56
|
-
|
57
|
-
it { should_not allow_value('10,50').for(:extra_amount) }
|
58
|
-
it { should_not allow_value('R$ 10.50').for(:extra_amount) }
|
59
|
-
it { should_not allow_value('-10.50').for(:extra_amount) }
|
60
|
-
it { should_not allow_value('10.50\nanything').for(:extra_amount) }
|
61
|
-
it { should allow_value('10.50').for(:extra_amount) }
|
62
|
-
it { should allow_value(10).for(:extra_amount) }
|
63
|
-
it { should allow_value(BigDecimal.new('10.5')).for(:extra_amount) }
|
64
|
-
|
65
|
-
it { should_not allow_value('something.com.br').for(:redirect_url)}
|
66
|
-
it { should allow_value('http://something.com.br').for(:redirect_url)}
|
67
|
-
|
68
|
-
it { should_not allow_value(0).for(:max_uses) }
|
69
|
-
it { should_not allow_value('0').for(:max_uses) }
|
70
|
-
it { should allow_value(10).for(:max_uses) }
|
71
|
-
it { should allow_value('10').for(:max_uses) }
|
72
|
-
|
73
|
-
it { should_not allow_value(29).for(:max_age) }
|
74
|
-
it { should allow_value(30).for(:max_age) }
|
75
|
-
|
76
|
-
it 'should not be valid if its pre_approval in invalid' do
|
77
|
-
payment.pre_approval = PagSeguro::PreApproval.new
|
78
|
-
payment.should_not be_valid
|
34
|
+
context "production" do
|
35
|
+
before do
|
36
|
+
PagSeguro::Url.environment= :production
|
79
37
|
end
|
80
38
|
|
81
|
-
|
82
|
-
|
83
|
-
|
39
|
+
describe "checkout url" do
|
40
|
+
subject { PagSeguro::Payment.checkout_url }
|
41
|
+
it { is_expected.to eq("https://ws.pagseguro.uol.com.br/v2/checkout") }
|
84
42
|
end
|
85
43
|
|
86
|
-
|
87
|
-
|
88
|
-
|
44
|
+
describe '#date' do
|
45
|
+
subject{ payment.send(:parse_date) }
|
46
|
+
before{ allow(payment).to receive_messages response: double(:response, body: '<checkout><date>2001-02-03T04:05:06+07:00</date></checkout>') }
|
89
47
|
|
90
|
-
|
91
|
-
|
92
|
-
|
48
|
+
it { is_expected.to be_an_instance_of(DateTime) }
|
49
|
+
its(:year){ should == 2001 }
|
50
|
+
its(:month){ should == 2 }
|
51
|
+
its(:day){ should == 3 }
|
93
52
|
end
|
94
53
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
its(:
|
54
|
+
describe '#code' do
|
55
|
+
before{ allow(payment).to receive_messages response: double(:response, body: '<checkout><code>EE603A-59F0DEF0DAAD-2334FFBF9A1E-3223E3</code></checkout>') }
|
56
|
+
|
57
|
+
its(:code){ should == 'EE603A-59F0DEF0DAAD-2334FFBF9A1E-3223E3' }
|
99
58
|
end
|
100
59
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
60
|
+
its(:items){ should be_an_instance_of(Array) }
|
61
|
+
its(:items){ should be_empty }
|
62
|
+
its(:sender){ should be_an_instance_of(PagSeguro::Sender) }
|
63
|
+
|
64
|
+
context 'with email and token initialization' do
|
65
|
+
subject{ build(:payment) }
|
66
|
+
let(:payment){ subject }
|
67
|
+
its(:email){ should == 'myemail' }
|
68
|
+
its(:token){ should == 'mytoken' }
|
69
|
+
|
70
|
+
it { validate_presence_of :email }
|
71
|
+
it { validate_presence_of :token }
|
72
|
+
|
73
|
+
it { is_expected.not_to allow_value('10,50').for(:extra_amount) }
|
74
|
+
it { is_expected.not_to allow_value('R$ 10.50').for(:extra_amount) }
|
75
|
+
it { is_expected.not_to allow_value('-10.50').for(:extra_amount) }
|
76
|
+
it { is_expected.not_to allow_value('10.50\nanything').for(:extra_amount) }
|
77
|
+
it { is_expected.to allow_value('10.50').for(:extra_amount) }
|
78
|
+
it { is_expected.to allow_value(10).for(:extra_amount) }
|
79
|
+
it { is_expected.to allow_value(BigDecimal.new('10.5')).for(:extra_amount) }
|
80
|
+
|
81
|
+
it { is_expected.not_to allow_value('something.com.br').for(:redirect_url)}
|
82
|
+
it { is_expected.to allow_value('http://something.com.br').for(:redirect_url)}
|
83
|
+
|
84
|
+
it { is_expected.not_to allow_value(0).for(:max_uses) }
|
85
|
+
it { is_expected.not_to allow_value('0').for(:max_uses) }
|
86
|
+
it { is_expected.to allow_value(10).for(:max_uses) }
|
87
|
+
it { is_expected.to allow_value('10').for(:max_uses) }
|
88
|
+
|
89
|
+
it { is_expected.not_to allow_value(29).for(:max_age) }
|
90
|
+
it { is_expected.to allow_value(30).for(:max_age) }
|
91
|
+
|
92
|
+
it 'should not be valid if its pre_approval in invalid' do
|
93
|
+
payment.pre_approval = PagSeguro::PreApproval.new
|
94
|
+
expect(payment).not_to be_valid
|
105
95
|
end
|
106
96
|
|
107
|
-
it 'should
|
108
|
-
payment.
|
109
|
-
payment.
|
97
|
+
it 'should not be valid if one of its items is invalid' do
|
98
|
+
payment.items = [PagSeguro::Item.new]
|
99
|
+
expect(payment).not_to be_valid
|
110
100
|
end
|
111
|
-
end
|
112
101
|
|
113
|
-
|
114
|
-
|
115
|
-
it 'should not raise errors if response code is 200' do
|
116
|
-
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 200 }
|
117
|
-
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some body info' }
|
118
|
-
expect { payment.send(:parse_checkout_response) }.to_not raise_error
|
102
|
+
context 'without items' do
|
103
|
+
it { is_expected.not_to be_valid }
|
119
104
|
end
|
120
105
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::InvalidData)
|
106
|
+
context 'with items' do
|
107
|
+
subject { build :payment_with_item }
|
108
|
+
it { is_expected.to be_valid }
|
125
109
|
end
|
126
110
|
|
127
|
-
|
128
|
-
|
129
|
-
|
111
|
+
context 'using reference instead of id' do
|
112
|
+
subject { build :payment_with_item, id: nil, reference: "REF1234" }
|
113
|
+
its(:id){ should == "REF1234" }
|
114
|
+
its(:reference){ should == "REF1234" }
|
130
115
|
end
|
131
116
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
117
|
+
context 'checking out' do
|
118
|
+
let(:payment){ build(:payment) }
|
119
|
+
it 'should generate a checkout url with an external code' do
|
120
|
+
expect(PagSeguro::Payment.checkout_payment_url('aabbcc')).to eq('https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc')
|
121
|
+
end
|
137
122
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
123
|
+
it 'should generate a checkout url based on the received response' do
|
124
|
+
allow(payment).to receive_messages code: 'aabbcc'
|
125
|
+
expect(payment.checkout_payment_url).to eq('https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc')
|
126
|
+
end
|
142
127
|
end
|
143
128
|
|
144
|
-
|
145
|
-
|
146
|
-
|
129
|
+
describe '#parse_checkout_response' do
|
130
|
+
|
131
|
+
it 'should not raise errors if response code is 200' do
|
132
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 200 }
|
133
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some body info' }
|
134
|
+
expect { payment.send(:parse_checkout_response) }.to_not raise_error
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should raise PagSeguro::Errors::InvalidData if response code is 400' do
|
138
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 400 }
|
139
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some error description' }
|
140
|
+
expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::InvalidData)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should raise PagSeguro::Errors::Unauthorized if response code is 400' do
|
144
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 401 }
|
145
|
+
expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::Unauthorized)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should raise PagSeguro::Errors::UnknownError if response code is not 200, 400 or 401' do
|
149
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 300 }
|
150
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some response body' }
|
151
|
+
expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::UnknownError)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should set response attribute if code is 200' do
|
155
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 200 }
|
156
|
+
allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some response body' }
|
157
|
+
expect { payment.send(:parse_checkout_response) }.to change { payment.response }.from(nil).to('some response body')
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should be able to reset response' do
|
161
|
+
payment.response = 'something'
|
162
|
+
expect { payment.reset! }.to change{ payment.response }.from('something').to(nil)
|
163
|
+
end
|
147
164
|
end
|
148
165
|
end
|
149
|
-
end
|
150
166
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
167
|
+
describe '#code' do
|
168
|
+
it 'should call #parse_checkout_response if #response is nil' do
|
169
|
+
allow(payment).to receive_messages(response: nil, parse_code: nil)
|
170
|
+
expect(payment).to receive(:parse_checkout_response)
|
171
|
+
payment.code
|
172
|
+
end
|
157
173
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
174
|
+
it 'should not call #parse_checkout_response if #response is present' do
|
175
|
+
allow(payment).to receive_messages(response: true, parse_code: nil)
|
176
|
+
expect(payment).not_to receive(:parse_checkout_response)
|
177
|
+
payment.code
|
178
|
+
end
|
163
179
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
180
|
+
it 'should call #parse_code' do
|
181
|
+
allow(payment).to receive_messages(response: true)
|
182
|
+
expect(payment).to receive(:parse_code)
|
183
|
+
payment.code
|
184
|
+
end
|
168
185
|
end
|
169
|
-
end
|
170
186
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
187
|
+
describe '#date' do
|
188
|
+
it 'should call #parse_checkout_response if #response is nil' do
|
189
|
+
allow(payment).to receive_messages(response: nil, parse_date: nil)
|
190
|
+
expect(payment).to receive(:parse_checkout_response)
|
191
|
+
payment.date
|
192
|
+
end
|
177
193
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
194
|
+
it 'should not call #parse_checkout_response if #response is present' do
|
195
|
+
allow(payment).to receive_messages(response: true, parse_date: nil)
|
196
|
+
expect(payment).not_to receive(:parse_checkout_response)
|
197
|
+
payment.date
|
198
|
+
end
|
183
199
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
200
|
+
it 'should call #parse_code' do
|
201
|
+
allow(payment).to receive_messages(response: true)
|
202
|
+
expect(payment).to receive(:parse_date)
|
203
|
+
payment.date
|
204
|
+
end
|
188
205
|
end
|
189
|
-
end
|
190
206
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
207
|
+
describe "#send_checkout" do
|
208
|
+
let(:payment){ PagSeguro::Payment.new "email@mail.com", "sometoken" }
|
209
|
+
it "should call pagseguro's webservice" do
|
210
|
+
checkout_xml = double(:checkout_xml)
|
211
|
+
allow(payment).to receive_messages(checkout_xml: checkout_xml)
|
212
|
+
params = { email: "email@mail.com", token: "sometoken", ssl_version: :SSLv3 }
|
213
|
+
expect(RestClient).to receive(:post).with(
|
214
|
+
PagSeguro::Payment.checkout_url,
|
215
|
+
checkout_xml,
|
216
|
+
params: params,
|
217
|
+
content_type: "application/xml")
|
218
|
+
payment.send :send_checkout
|
219
|
+
end
|
203
220
|
end
|
204
221
|
end
|
205
222
|
end
|