pagseguro-transparente 0.0.1 → 0.0.2
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/.travis.yml +16 -0
- data/Gemfile.lock +8 -8
- data/README.md +6 -6
- data/index.html +374 -0
- data/lib/pagseguro.rb +11 -8
- data/lib/pagseguro/item.rb +5 -5
- data/lib/pagseguro/notification.rb +8 -74
- data/lib/pagseguro/payment.rb +95 -0
- data/lib/pagseguro/{transaction → payment}/serializer.rb +17 -17
- data/lib/pagseguro/request.rb +17 -4
- data/lib/pagseguro/sender.rb +4 -0
- data/lib/pagseguro/session.rb +8 -1
- data/lib/pagseguro/shipping.rb +5 -1
- data/lib/pagseguro/transaction.rb +79 -62
- data/lib/pagseguro/{notification → transaction}/address.rb +1 -1
- data/lib/pagseguro/{notification → transaction}/item.rb +1 -1
- data/lib/pagseguro/{notification → transaction}/items.rb +1 -1
- data/lib/pagseguro/{notification → transaction}/payment_method.rb +8 -1
- data/lib/pagseguro/{notification → transaction}/phone.rb +1 -1
- data/lib/pagseguro/{notification → transaction}/sender.rb +1 -1
- data/lib/pagseguro/{notification → transaction}/shipping.rb +1 -1
- data/lib/pagseguro/version.rb +1 -1
- data/pagseguro-transparente.gemspec +3 -3
- data/spec/pagseguro/item_spec.rb +1 -1
- data/spec/pagseguro/notification_spec.rb +37 -41
- data/spec/pagseguro/{transaction → payment}/serializer_spec.rb +15 -13
- data/spec/pagseguro/payment_spec.rb +90 -0
- data/spec/pagseguro/session_spec.rb +17 -4
- data/spec/pagseguro/{notification → transaction}/address_spec.rb +2 -2
- data/spec/pagseguro/{notification → transaction}/item_spec.rb +2 -2
- data/spec/pagseguro/{notification → transaction}/items_spec.rb +2 -2
- data/spec/pagseguro/{notification → transaction}/payment_method_spec.rb +3 -2
- data/spec/pagseguro/{notification → transaction}/phone_spec.rb +2 -2
- data/spec/pagseguro/{notification → transaction}/sender_spec.rb +3 -3
- data/spec/pagseguro/{notification → transaction}/shipping_spec.rb +3 -3
- data/spec/pagseguro/transaction_spec.rb +56 -77
- data/spec/spec_helper.rb +2 -0
- metadata +37 -60
- data/coverage/.last_run.json +0 -5
- data/coverage/.resultset.json +0 -1665
- data/coverage/assets/0.8.0/application.css +0 -799
- data/coverage/assets/0.8.0/application.js +0 -1559
- data/coverage/assets/0.8.0/colorbox/border.png +0 -0
- data/coverage/assets/0.8.0/colorbox/controls.png +0 -0
- data/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
- data/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.8.0/favicon_green.png +0 -0
- data/coverage/assets/0.8.0/favicon_red.png +0 -0
- data/coverage/assets/0.8.0/favicon_yellow.png +0 -0
- data/coverage/assets/0.8.0/loading.gif +0 -0
- data/coverage/assets/0.8.0/magnify.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +0 -10198
@@ -1,8 +1,11 @@
|
|
1
1
|
module PagSeguro
|
2
|
-
class
|
2
|
+
class Transaction
|
3
3
|
class PaymentMethod
|
4
4
|
attr_reader :payment_method
|
5
5
|
|
6
|
+
PAYMENT_TYPE = { '1' => :credit_card, '2' => :boleto, '3' => :tef,
|
7
|
+
'4' => :pagseguro_balance, '5' => :io_paggo, '6' => :deposit }
|
8
|
+
|
6
9
|
def initialize(payment_method)
|
7
10
|
@payment_method = payment_method
|
8
11
|
end
|
@@ -11,6 +14,10 @@ module PagSeguro
|
|
11
14
|
payment_method['type']
|
12
15
|
end
|
13
16
|
|
17
|
+
def payment_type_name
|
18
|
+
PAYMENT_TYPE[payment_type]
|
19
|
+
end
|
20
|
+
|
14
21
|
def payment_code
|
15
22
|
payment_method['code']
|
16
23
|
end
|
data/lib/pagseguro/version.rb
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["cirdes@gmail.com"]
|
10
10
|
spec.description = "Integração com o novo checkout transparente do Pagseguro."
|
11
11
|
spec.summary = spec.description
|
12
|
-
spec.homepage = "
|
12
|
+
spec.homepage = "https://github.com/eventick/pagseguro-transparente"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split($/)
|
@@ -17,11 +17,11 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
+
spec.add_dependency "activemodel"
|
20
21
|
spec.add_dependency "httparty"
|
21
22
|
spec.add_dependency "nokogiri"
|
22
23
|
spec.add_dependency "json"
|
23
|
-
|
24
|
-
|
24
|
+
|
25
25
|
spec.add_development_dependency "bundler"
|
26
26
|
spec.add_development_dependency "rake"
|
27
27
|
spec.add_development_dependency "rspec"
|
data/spec/pagseguro/item_spec.rb
CHANGED
@@ -1,45 +1,41 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe PagSeguro::Notification do
|
4
|
-
let(:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
subject {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
<extraAmount>0.00</extraAmount>
|
42
|
-
<installmentCount>1</installmentCount>
|
43
|
-
</transaction>"
|
44
|
-
}
|
4
|
+
let(:code) { '766B9C-AD4B044B04DA-77742F5FA653-E1AB24' }
|
5
|
+
let(:type) { 'transaction' }
|
6
|
+
|
7
|
+
let(:notification) { PagSeguro::Notification.new(code, type) }
|
8
|
+
subject { notification }
|
9
|
+
|
10
|
+
it { should respond_to(:transaction) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
PagSeguro.email = 'mail'
|
14
|
+
PagSeguro.token = 'token'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#transaction" do
|
18
|
+
context "with default credencials" do
|
19
|
+
subject { notification.transaction }
|
20
|
+
before do
|
21
|
+
stub_request(:get, "https://ws.pagseguro.uol.com.br/v2/transactions/notifications/766B9C-AD4B044B04DA-77742F5FA653-E1AB24").
|
22
|
+
with(body: "email=mail&token=token").to_return(status: 200)
|
23
|
+
end
|
24
|
+
|
25
|
+
it { should be_a_kind_of(PagSeguro::Transaction) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with custom credencials" do
|
29
|
+
subject { notification.transaction }
|
30
|
+
|
31
|
+
let(:notification) { PagSeguro::Notification.new(code, type, 'custom_email', 'custom_token') }
|
32
|
+
|
33
|
+
before do
|
34
|
+
stub_request(:get, "https://ws.pagseguro.uol.com.br/v2/transactions/notifications/766B9C-AD4B044B04DA-77742F5FA653-E1AB24").
|
35
|
+
with(body: "email=custom_email&token=custom_token").to_return(status: 200)
|
36
|
+
end
|
37
|
+
|
38
|
+
it { should be_a_kind_of(PagSeguro::Transaction) }
|
39
|
+
end
|
40
|
+
end
|
45
41
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::
|
4
|
-
let(:params) { PagSeguro::
|
3
|
+
describe PagSeguro::Payment::Serializer do
|
4
|
+
let(:params) { PagSeguro::Payment::Serializer.new(payment).to_params }
|
5
5
|
subject { params }
|
6
6
|
|
7
7
|
let(:options) {
|
@@ -13,15 +13,15 @@ describe PagSeguro::Transaction::Serializer do
|
|
13
13
|
}
|
14
14
|
}
|
15
15
|
|
16
|
-
let(:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
PagSeguro::Item.new('0002', 'Notebook Rosa', '25600.00', '2') ]
|
24
|
-
|
16
|
+
let(:payment) do
|
17
|
+
payment = PagSeguro::Payment.new(options)
|
18
|
+
payment.sender = sender
|
19
|
+
payment.shipping = shipping
|
20
|
+
payment.credit_card = credit_card
|
21
|
+
payment.bank = bank
|
22
|
+
payment.items = [PagSeguro::Item.new(id: '0001', description: 'Notebook Prata', amount: '24300.00', quantity: '1') ,
|
23
|
+
PagSeguro::Item.new(id: '0002', description: 'Notebook Rosa', amount: '25600.00', quantity: '2') ]
|
24
|
+
payment
|
25
25
|
end
|
26
26
|
|
27
27
|
let(:document) { PagSeguro::Document.new('22111944785') }
|
@@ -72,10 +72,12 @@ describe PagSeguro::Transaction::Serializer do
|
|
72
72
|
credit_card.billing_address = address
|
73
73
|
credit_card
|
74
74
|
end
|
75
|
+
|
75
76
|
before do
|
76
|
-
|
77
|
-
|
77
|
+
PagSeguro.email = 'pagseguro@eventick.com.br'
|
78
|
+
PagSeguro.token = 'my_token'
|
78
79
|
end
|
80
|
+
|
79
81
|
let(:bank) { PagSeguro::Bank.new('bancodobrasil') }
|
80
82
|
|
81
83
|
it { subject[:email].should eq('pagseguro@eventick.com.br') }
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Payment do
|
4
|
+
subject { payment }
|
5
|
+
|
6
|
+
let(:options) {
|
7
|
+
{
|
8
|
+
notification_url: 'www.eventick.com.br',
|
9
|
+
payment_method: payment_method,
|
10
|
+
reference: '0001',
|
11
|
+
extra_amount: '1.00'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:payment_method) { 'boleto' }
|
16
|
+
|
17
|
+
let(:payment) do
|
18
|
+
payment = PagSeguro::Payment.new(options)
|
19
|
+
payment.sender = sender
|
20
|
+
payment.shipping = shipping
|
21
|
+
payment.items = [PagSeguro::Item.new(id: 1, description: 'Ingresso Teste', amount: 2, quantity: 1)]
|
22
|
+
payment
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:document) { PagSeguro::Document.new('017.355.323-00') }
|
26
|
+
let(:phone) {PagSeguro::Phone.new('11', '99999999') }
|
27
|
+
let(:sender) do
|
28
|
+
sender = PagSeguro::Sender.new({
|
29
|
+
email: 'produtor@eventick.com.br',
|
30
|
+
name: 'João do evento',
|
31
|
+
hash_id: 'abc1234'
|
32
|
+
})
|
33
|
+
sender.phone = phone
|
34
|
+
sender.document = document
|
35
|
+
sender
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:address) do
|
39
|
+
PagSeguro::Address.new({
|
40
|
+
postal_code: '01452002',
|
41
|
+
street: 'Rua Fernando de Albuquerque',
|
42
|
+
number: '35',
|
43
|
+
complement: '31',
|
44
|
+
district: 'Consolação',
|
45
|
+
city: 'São Paulo',
|
46
|
+
state: 'SP'
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:shipping){
|
51
|
+
shipping = PagSeguro::Shipping.new
|
52
|
+
shipping.address = address
|
53
|
+
shipping
|
54
|
+
}
|
55
|
+
|
56
|
+
it { should respond_to(:receiver_email) }
|
57
|
+
it { should respond_to(:notification_url) }
|
58
|
+
it { should respond_to(:currency) }
|
59
|
+
it { should respond_to(:payment_method) }
|
60
|
+
it { should respond_to(:payment_mode) }
|
61
|
+
it { should respond_to(:items) }
|
62
|
+
it { should respond_to(:reference) }
|
63
|
+
it { should respond_to(:extra_amount) }
|
64
|
+
it { should respond_to(:sender) }
|
65
|
+
it { should respond_to(:shipping) }
|
66
|
+
it { should respond_to(:bank) }
|
67
|
+
it { should respond_to(:credit_card) }
|
68
|
+
|
69
|
+
describe 'presence validations' do
|
70
|
+
it { should validate_presence_of(:currency) }
|
71
|
+
it { should validate_presence_of(:payment_method) }
|
72
|
+
it { should validate_presence_of(:sender) }
|
73
|
+
it { should validate_presence_of(:shipping) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'inclusion validations' do
|
77
|
+
let(:payment_methods) { %w(creditCard boleto eft) }
|
78
|
+
it { should ensure_inclusion_of(:payment_method).in_array(payment_methods) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'eft' do
|
82
|
+
let(:payment_method) { 'eft' }
|
83
|
+
it { should validate_presence_of(:bank) }
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'credit card' do
|
87
|
+
let(:payment_method) { 'creditCard' }
|
88
|
+
it { should validate_presence_of(:credit_card) }
|
89
|
+
end
|
90
|
+
end
|
@@ -13,11 +13,24 @@ describe PagSeguro::Session do
|
|
13
13
|
|
14
14
|
describe "#create" do
|
15
15
|
subject { session.create }
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
context 'with default email and token' do
|
18
|
+
before do
|
19
|
+
stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/sessions").
|
20
|
+
with(body: "email=mail&token=token").to_return(status: 200)
|
21
|
+
end
|
22
|
+
|
23
|
+
it { should be_a_kind_of(PagSeguro::Session::Response) }
|
19
24
|
end
|
20
25
|
|
21
|
-
|
26
|
+
context 'with custom email and token' do
|
27
|
+
let(:session) { PagSeguro::Session.new('custom_email', 'custom_token') }
|
28
|
+
before do
|
29
|
+
stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/sessions").
|
30
|
+
with(body: "email=custom_email&token=custom_token").to_return(status: 200)
|
31
|
+
end
|
32
|
+
|
33
|
+
it { should be_a_kind_of(PagSeguro::Session::Response) }
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::
|
3
|
+
describe PagSeguro::Transaction::Address do
|
4
4
|
let(:xml) { MultiXml.parse(xml_file) }
|
5
5
|
|
6
6
|
let(:address) do
|
7
|
-
PagSeguro::
|
7
|
+
PagSeguro::Transaction::Address.new(xml['address'])
|
8
8
|
end
|
9
9
|
|
10
10
|
subject { address }
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::
|
3
|
+
describe PagSeguro::Transaction::Item do
|
4
4
|
let(:item) do
|
5
|
-
PagSeguro::
|
5
|
+
PagSeguro::Transaction::Item.new('0001', 'Notebook Prata',
|
6
6
|
'1', '24300.00')
|
7
7
|
end
|
8
8
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::
|
3
|
+
describe PagSeguro::Transaction::Items do
|
4
4
|
let(:xml) { MultiXml.parse(xml_file) }
|
5
5
|
|
6
6
|
let(:items) do
|
7
|
-
PagSeguro::
|
7
|
+
PagSeguro::Transaction::Items.new(xml['items'], '2')
|
8
8
|
end
|
9
9
|
|
10
10
|
subject { items }
|
@@ -1,15 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::
|
3
|
+
describe PagSeguro::Transaction::PaymentMethod do
|
4
4
|
let(:xml) { MultiXml.parse(xml_file) }
|
5
5
|
|
6
6
|
let(:payment_method) do
|
7
|
-
PagSeguro::
|
7
|
+
PagSeguro::Transaction::PaymentMethod.new(xml['paymentMethod'])
|
8
8
|
end
|
9
9
|
|
10
10
|
subject { payment_method }
|
11
11
|
|
12
12
|
its(:payment_type) { should eq('1') }
|
13
|
+
its(:payment_type_name) { should eq(:credit_card) }
|
13
14
|
its(:payment_code) { should eq('101') }
|
14
15
|
|
15
16
|
let(:xml_file) {
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::
|
3
|
+
describe PagSeguro::Transaction::Phone do
|
4
4
|
let(:xml) { MultiXml.parse(xml_file) }
|
5
5
|
|
6
6
|
let(:phone) do
|
7
|
-
PagSeguro::
|
7
|
+
PagSeguro::Transaction::Phone.new(xml['phone'])
|
8
8
|
end
|
9
9
|
|
10
10
|
subject { phone }
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe PagSeguro::
|
3
|
+
describe PagSeguro::Transaction::Sender do
|
4
4
|
let(:xml) { MultiXml.parse(xml_file) }
|
5
5
|
|
6
6
|
let(:sender) do
|
7
|
-
PagSeguro::
|
7
|
+
PagSeguro::Transaction::Sender.new(xml['sender'])
|
8
8
|
end
|
9
9
|
|
10
10
|
subject { sender }
|
11
11
|
|
12
12
|
its(:name) { should eq('José Comprador') }
|
13
13
|
its(:email) { should eq('comprador@uol.com.br') }
|
14
|
-
its(:phone) { should be_a_kind_of(PagSeguro::
|
14
|
+
its(:phone) { should be_a_kind_of(PagSeguro::Transaction::Phone) }
|
15
15
|
|
16
16
|
let(:xml_file) {
|
17
17
|
"<sender>
|