pagseguro-transparente 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -0
  3. data/Gemfile.lock +8 -8
  4. data/README.md +6 -6
  5. data/index.html +374 -0
  6. data/lib/pagseguro.rb +11 -8
  7. data/lib/pagseguro/item.rb +5 -5
  8. data/lib/pagseguro/notification.rb +8 -74
  9. data/lib/pagseguro/payment.rb +95 -0
  10. data/lib/pagseguro/{transaction → payment}/serializer.rb +17 -17
  11. data/lib/pagseguro/request.rb +17 -4
  12. data/lib/pagseguro/sender.rb +4 -0
  13. data/lib/pagseguro/session.rb +8 -1
  14. data/lib/pagseguro/shipping.rb +5 -1
  15. data/lib/pagseguro/transaction.rb +79 -62
  16. data/lib/pagseguro/{notification → transaction}/address.rb +1 -1
  17. data/lib/pagseguro/{notification → transaction}/item.rb +1 -1
  18. data/lib/pagseguro/{notification → transaction}/items.rb +1 -1
  19. data/lib/pagseguro/{notification → transaction}/payment_method.rb +8 -1
  20. data/lib/pagseguro/{notification → transaction}/phone.rb +1 -1
  21. data/lib/pagseguro/{notification → transaction}/sender.rb +1 -1
  22. data/lib/pagseguro/{notification → transaction}/shipping.rb +1 -1
  23. data/lib/pagseguro/version.rb +1 -1
  24. data/pagseguro-transparente.gemspec +3 -3
  25. data/spec/pagseguro/item_spec.rb +1 -1
  26. data/spec/pagseguro/notification_spec.rb +37 -41
  27. data/spec/pagseguro/{transaction → payment}/serializer_spec.rb +15 -13
  28. data/spec/pagseguro/payment_spec.rb +90 -0
  29. data/spec/pagseguro/session_spec.rb +17 -4
  30. data/spec/pagseguro/{notification → transaction}/address_spec.rb +2 -2
  31. data/spec/pagseguro/{notification → transaction}/item_spec.rb +2 -2
  32. data/spec/pagseguro/{notification → transaction}/items_spec.rb +2 -2
  33. data/spec/pagseguro/{notification → transaction}/payment_method_spec.rb +3 -2
  34. data/spec/pagseguro/{notification → transaction}/phone_spec.rb +2 -2
  35. data/spec/pagseguro/{notification → transaction}/sender_spec.rb +3 -3
  36. data/spec/pagseguro/{notification → transaction}/shipping_spec.rb +3 -3
  37. data/spec/pagseguro/transaction_spec.rb +56 -77
  38. data/spec/spec_helper.rb +2 -0
  39. metadata +37 -60
  40. data/coverage/.last_run.json +0 -5
  41. data/coverage/.resultset.json +0 -1665
  42. data/coverage/assets/0.8.0/application.css +0 -799
  43. data/coverage/assets/0.8.0/application.js +0 -1559
  44. data/coverage/assets/0.8.0/colorbox/border.png +0 -0
  45. data/coverage/assets/0.8.0/colorbox/controls.png +0 -0
  46. data/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
  47. data/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
  48. data/coverage/assets/0.8.0/favicon_green.png +0 -0
  49. data/coverage/assets/0.8.0/favicon_red.png +0 -0
  50. data/coverage/assets/0.8.0/favicon_yellow.png +0 -0
  51. data/coverage/assets/0.8.0/loading.gif +0 -0
  52. data/coverage/assets/0.8.0/magnify.png +0 -0
  53. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  54. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  55. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  56. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  57. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  58. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  59. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  60. data/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  61. data/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  62. data/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  63. data/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  64. data/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  65. data/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  66. data/coverage/index.html +0 -10198
@@ -1,5 +1,5 @@
1
1
  module PagSeguro
2
- class Notification
2
+ class Transaction
3
3
  class Address
4
4
  attr_reader :address
5
5
 
@@ -1,5 +1,5 @@
1
1
  module PagSeguro
2
- class Notification
2
+ class Transaction
3
3
  class Item
4
4
  attr_accessor :id, :description, :quantity, :amount
5
5
 
@@ -1,5 +1,5 @@
1
1
  module PagSeguro
2
- class Notification
2
+ class Transaction
3
3
  class Items
4
4
  attr_reader :count
5
5
 
@@ -1,8 +1,11 @@
1
1
  module PagSeguro
2
- class Notification
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
@@ -1,5 +1,5 @@
1
1
  module PagSeguro
2
- class Notification
2
+ class Transaction
3
3
  class Phone
4
4
  attr_reader :phone
5
5
 
@@ -1,5 +1,5 @@
1
1
  module PagSeguro
2
- class Notification
2
+ class Transaction
3
3
  class Sender
4
4
  attr_reader :sender
5
5
 
@@ -1,5 +1,5 @@
1
1
  module PagSeguro
2
- class Notification
2
+ class Transaction
3
3
  class Shipping
4
4
  attr_reader :shipping
5
5
 
@@ -1,3 +1,3 @@
1
1
  module PagSeguro
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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 = "http://www.eventick.com.br"
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
- spec.add_dependency "activemodel"
24
-
24
+
25
25
  spec.add_development_dependency "bundler"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "rspec"
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe PagSeguro::Item do
4
- let(:item) { PagSeguro::Item.new('id', 'my item', 10) }
4
+ let(:item) { PagSeguro::Item.new(id: 'id', description: 'my item', amount: 10) }
5
5
  subject { item }
6
6
 
7
7
  it { should respond_to(:id) }
@@ -1,45 +1,41 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe PagSeguro::Notification do
4
- let(:xml) { MultiXml.parse(xml_file) }
5
-
6
- let(:response) { PagSeguro::Notification.new(xml) }
7
-
8
- subject { response }
9
-
10
- its(:date) { should eq('2011-02-05T15:46:12.000-02:00') }
11
- its(:last_event_date) { should eq('2011-02-15T17:39:14.000-03:00') }
12
- its(:code) { should eq('9E884542-81B3-4419-9A75-BCC6FB495EF1') }
13
- its(:reference) { should eq('REF1234') }
14
- its(:type) { should eq('1') }
15
- its(:status) { should eq('3') }
16
- its(:payment_link) { should eq('https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml') }
17
- its(:gross_amount) { should eq('49900.00') }
18
- its(:discount_amount) { should eq("0.00") }
19
- its(:fee_amount) { should eq('0.00') }
20
- its(:net_amount) { should eq('49900.50') }
21
- its(:extra_amount) { should eq('0.00') }
22
- its(:installment_count) { should eq("1") }
23
- its(:payment_method) { should be_a_kind_of(PagSeguro::Notification::PaymentMethod) }
24
- its(:items) { should be_a_kind_of(PagSeguro::Notification::Items) }
25
- its(:sender) { should be_a_kind_of(PagSeguro::Notification::Sender) }
26
- its(:shipping) { should be_a_kind_of(PagSeguro::Notification::Shipping) }
27
-
28
- let(:xml_file) {
29
- "<transaction>
30
- <date>2011-02-05T15:46:12.000-02:00</date>
31
- <lastEventDate>2011-02-15T17:39:14.000-03:00</lastEventDate>
32
- <code>9E884542-81B3-4419-9A75-BCC6FB495EF1</code>
33
- <reference>REF1234</reference>
34
- <type>1</type>
35
- <status>3</status>
36
- <paymentLink>https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml</paymentLink>
37
- <grossAmount>49900.00</grossAmount>
38
- <discountAmount>0.00</discountAmount>
39
- <feeAmount>0.00</feeAmount>
40
- <netAmount>49900.50</netAmount>
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::Transaction::Serializer do
4
- let(:params) { PagSeguro::Transaction::Serializer.new(transaction).to_params }
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(:transaction) do
17
- transaction = PagSeguro::Transaction.new(options)
18
- transaction.sender = sender
19
- transaction.shipping = shipping
20
- transaction.credit_card = credit_card
21
- transaction.bank = bank
22
- transaction.items = [PagSeguro::Item.new('0001', 'Notebook Prata', '24300.00', '1') ,
23
- PagSeguro::Item.new('0002', 'Notebook Rosa', '25600.00', '2') ]
24
- transaction
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
- PagSeguro.email = 'pagseguro@eventick.com.br'
77
- PagSeguro.token = 'my_token'
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
- before do
17
- stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/sessions").
18
- with(body: "email=mail&token=token").to_return(status: 200)
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
- it { should be_a_kind_of(PagSeguro::Session::Response) }
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::Notification::Address do
3
+ describe PagSeguro::Transaction::Address do
4
4
  let(:xml) { MultiXml.parse(xml_file) }
5
5
 
6
6
  let(:address) do
7
- PagSeguro::Notification::Address.new(xml['address'])
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::Notification::Item do
3
+ describe PagSeguro::Transaction::Item do
4
4
  let(:item) do
5
- PagSeguro::Notification::Item.new('0001', 'Notebook Prata',
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::Notification::Items do
3
+ describe PagSeguro::Transaction::Items do
4
4
  let(:xml) { MultiXml.parse(xml_file) }
5
5
 
6
6
  let(:items) do
7
- PagSeguro::Notification::Items.new(xml['items'], '2')
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::Notification::PaymentMethod do
3
+ describe PagSeguro::Transaction::PaymentMethod do
4
4
  let(:xml) { MultiXml.parse(xml_file) }
5
5
 
6
6
  let(:payment_method) do
7
- PagSeguro::Notification::PaymentMethod.new(xml['paymentMethod'])
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::Notification::Phone do
3
+ describe PagSeguro::Transaction::Phone do
4
4
  let(:xml) { MultiXml.parse(xml_file) }
5
5
 
6
6
  let(:phone) do
7
- PagSeguro::Notification::Phone.new(xml['phone'])
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::Notification::Sender do
3
+ describe PagSeguro::Transaction::Sender do
4
4
  let(:xml) { MultiXml.parse(xml_file) }
5
5
 
6
6
  let(:sender) do
7
- PagSeguro::Notification::Sender.new(xml['sender'])
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::Notification::Phone) }
14
+ its(:phone) { should be_a_kind_of(PagSeguro::Transaction::Phone) }
15
15
 
16
16
  let(:xml_file) {
17
17
  "<sender>