pagseguro-transparente 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +34 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +89 -0
  6. data/README.md +79 -0
  7. data/Rakefile +5 -0
  8. data/coverage/.last_run.json +5 -0
  9. data/coverage/.resultset.json +1665 -0
  10. data/coverage/assets/0.8.0/application.css +799 -0
  11. data/coverage/assets/0.8.0/application.js +1559 -0
  12. data/coverage/assets/0.8.0/colorbox/border.png +0 -0
  13. data/coverage/assets/0.8.0/colorbox/controls.png +0 -0
  14. data/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
  15. data/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
  16. data/coverage/assets/0.8.0/favicon_green.png +0 -0
  17. data/coverage/assets/0.8.0/favicon_red.png +0 -0
  18. data/coverage/assets/0.8.0/favicon_yellow.png +0 -0
  19. data/coverage/assets/0.8.0/loading.gif +0 -0
  20. data/coverage/assets/0.8.0/magnify.png +0 -0
  21. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  22. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  23. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  24. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  25. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  26. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  27. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  28. data/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  29. data/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  30. data/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  31. data/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  32. data/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  33. data/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  34. data/coverage/index.html +10198 -0
  35. data/lib/pagseguro/address.rb +46 -0
  36. data/lib/pagseguro/bank.rb +15 -0
  37. data/lib/pagseguro/credit_card.rb +23 -0
  38. data/lib/pagseguro/document.rb +20 -0
  39. data/lib/pagseguro/exceptions.rb +22 -0
  40. data/lib/pagseguro/holder.rb +24 -0
  41. data/lib/pagseguro/installment.rb +17 -0
  42. data/lib/pagseguro/item.rb +29 -0
  43. data/lib/pagseguro/items.rb +16 -0
  44. data/lib/pagseguro/notification/address.rb +43 -0
  45. data/lib/pagseguro/notification/item.rb +14 -0
  46. data/lib/pagseguro/notification/items.rb +18 -0
  47. data/lib/pagseguro/notification/payment_method.rb +19 -0
  48. data/lib/pagseguro/notification/phone.rb +19 -0
  49. data/lib/pagseguro/notification/sender.rb +23 -0
  50. data/lib/pagseguro/notification/shipping.rb +23 -0
  51. data/lib/pagseguro/notification.rb +82 -0
  52. data/lib/pagseguro/phone.rb +21 -0
  53. data/lib/pagseguro/request.rb +21 -0
  54. data/lib/pagseguro/sender.rb +28 -0
  55. data/lib/pagseguro/session/response.rb +15 -0
  56. data/lib/pagseguro/session.rb +7 -0
  57. data/lib/pagseguro/shipping.rb +23 -0
  58. data/lib/pagseguro/transaction/serializer.rb +158 -0
  59. data/lib/pagseguro/transaction.rb +91 -0
  60. data/lib/pagseguro/version.rb +3 -0
  61. data/lib/pagseguro-transparente.rb +1 -0
  62. data/lib/pagseguro.rb +54 -0
  63. data/pagseguro-transparente.gemspec +34 -0
  64. data/spec/pagseguro/address_spec.rb +35 -0
  65. data/spec/pagseguro/bank_spec.rb +17 -0
  66. data/spec/pagseguro/credit_card_spec.rb +18 -0
  67. data/spec/pagseguro/document_spec.rb +18 -0
  68. data/spec/pagseguro/holder_spec.rb +18 -0
  69. data/spec/pagseguro/installment_spec.rb +14 -0
  70. data/spec/pagseguro/item_spec.rb +28 -0
  71. data/spec/pagseguro/items_spec.rb +13 -0
  72. data/spec/pagseguro/notification/address_spec.rb +33 -0
  73. data/spec/pagseguro/notification/item_spec.rb +15 -0
  74. data/spec/pagseguro/notification/items_spec.rb +31 -0
  75. data/spec/pagseguro/notification/payment_method_spec.rb +21 -0
  76. data/spec/pagseguro/notification/phone_spec.rb +21 -0
  77. data/spec/pagseguro/notification/sender_spec.rb +26 -0
  78. data/spec/pagseguro/notification/shipping_spec.rb +22 -0
  79. data/spec/pagseguro/notification_spec.rb +45 -0
  80. data/spec/pagseguro/pagseguro_spec.rb +23 -0
  81. data/spec/pagseguro/phone_spec.rb +19 -0
  82. data/spec/pagseguro/sender_spec.rb +20 -0
  83. data/spec/pagseguro/session/response_spec.rb +17 -0
  84. data/spec/pagseguro/session_spec.rb +23 -0
  85. data/spec/pagseguro/shipping_spec.rb +22 -0
  86. data/spec/pagseguro/transaction/serializer_spec.rb +131 -0
  87. data/spec/pagseguro/transaction_spec.rb +91 -0
  88. data/spec/spec_helper.rb +16 -0
  89. metadata +311 -0
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Notification::Shipping do
4
+ let(:xml) { MultiXml.parse(xml_file) }
5
+
6
+ let(:shipping) do
7
+ PagSeguro::Notification::Shipping.new(xml['shipping'])
8
+ end
9
+
10
+ subject { shipping }
11
+
12
+ its(:type) { should eq('1') }
13
+ its(:cost) { should eq('21.50') }
14
+ its(:address) { should be_a_kind_of(PagSeguro::Notification::Address) }
15
+
16
+ let(:xml_file) {
17
+ "<shipping>
18
+ <type>1</type>
19
+ <cost>21.50</cost>
20
+ </shipping>"
21
+ }
22
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
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
+ }
45
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro do
4
+ before do
5
+ PagSeguro.email = "EMAIL"
6
+ PagSeguro.token = "TOKEN"
7
+ end
8
+
9
+ it { expect(PagSeguro.email).to eql("EMAIL") }
10
+ it { expect(PagSeguro.token).to eql("TOKEN") }
11
+
12
+ context "configuring library" do
13
+ it "yields PagSeguro" do
14
+ expect {|block|
15
+ PagSeguro.configure(&block)
16
+ }.to yield_with_args(PagSeguro)
17
+ end
18
+ end
19
+
20
+ context "default settings" do
21
+ it { expect(PagSeguro.environment).to eql(:production) }
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Phone do
4
+ let(:phone) { PagSeguro::Phone.new('11', '3042-4007') }
5
+ subject { phone }
6
+
7
+ it { should respond_to(:area_code) }
8
+ it { should respond_to(:number) }
9
+
10
+ describe 'presence validations' do
11
+ it { should validate_presence_of(:area_code) }
12
+ it { should validate_presence_of(:number) }
13
+ end
14
+
15
+ describe 'length validations' do
16
+ it { should ensure_length_of(:area_code).is_equal_to(2) }
17
+ it { should ensure_length_of(:number).is_at_least(7).is_at_most(9) }
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Sender do
4
+ let(:sender) { PagSeguro::Sender.new }
5
+ subject { sender }
6
+
7
+ it { should respond_to(:email) }
8
+ it { should respond_to(:name) }
9
+ it { should respond_to(:hash_id) }
10
+ it { should respond_to(:document) }
11
+ it { should respond_to(:phone) }
12
+
13
+ describe 'presence validations' do
14
+ it { should validate_presence_of(:email) }
15
+ it { should validate_presence_of(:name) }
16
+ it { should validate_presence_of(:hash_id) }
17
+ it { should validate_presence_of(:document) }
18
+ it { should validate_presence_of(:phone) }
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Session::Response do
4
+ let(:xml) do
5
+ MultiXml.parse('<session><id>620f99e348c24f07877c927b353e49d3</id></session>')
6
+ end
7
+
8
+ let(:session) { PagSeguro::Session::Response.new(xml) }
9
+
10
+ subject { session }
11
+
12
+ it { should respond_to(:id) }
13
+
14
+ describe '#id' do
15
+ its(:id) { should eq('620f99e348c24f07877c927b353e49d3') }
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Session do
4
+ let(:session) { PagSeguro::Session.new }
5
+ subject { session }
6
+
7
+ before do
8
+ PagSeguro.email = 'mail'
9
+ PagSeguro.token = 'token'
10
+ end
11
+
12
+ it { should respond_to(:create) }
13
+
14
+ describe "#create" do
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)
19
+ end
20
+
21
+ it { should be_a_kind_of(PagSeguro::Session::Response) }
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Shipping do
4
+ let(:shipping) { PagSeguro::Shipping.new }
5
+ subject { shipping }
6
+
7
+ it { should respond_to(:type_id) }
8
+ it { should respond_to(:cost) }
9
+ it { should respond_to(:address) }
10
+
11
+ describe 'presence validations' do
12
+ it { should validate_presence_of(:address) }
13
+ end
14
+
15
+ describe 'numericality validations' do
16
+ it { should validate_numericality_of(:cost).is_greater_than(0) }
17
+ end
18
+
19
+ describe 'inclusion validations' do
20
+ it { should ensure_inclusion_of(:type_id).in_array( %w( 1 2 3 ) ) }
21
+ end
22
+ end
@@ -0,0 +1,131 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Transaction::Serializer do
4
+ let(:params) { PagSeguro::Transaction::Serializer.new(transaction).to_params }
5
+ subject { params }
6
+
7
+ let(:options) {
8
+ {
9
+ notification_url: 'https://sualoja.com.br/notifica.html',
10
+ payment_method: 'boleto',
11
+ reference: 'REF1234',
12
+ extra_amount: '1.00'
13
+ }
14
+ }
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
25
+ end
26
+
27
+ let(:document) { PagSeguro::Document.new('22111944785') }
28
+ let(:phone) {PagSeguro::Phone.new('11', '56273440') }
29
+ let(:sender) do
30
+ sender = PagSeguro::Sender.new({
31
+ email: 'comprador@uol.com.br',
32
+ name: 'Jose Comprador',
33
+ hash_id: 'abc123'
34
+ })
35
+ sender.phone = phone
36
+ sender.document = document
37
+ sender
38
+ end
39
+
40
+ let(:address) do
41
+ PagSeguro::Address.new({
42
+ postal_code: '01452002',
43
+ street: 'Av. Brig. Faria Lima',
44
+ number: '1384',
45
+ complement: '5o andar',
46
+ district: 'Jardim Paulistano',
47
+ city: 'Sao Paulo',
48
+ state: 'SP'
49
+ })
50
+ end
51
+
52
+ let(:shipping){
53
+ shipping = PagSeguro::Shipping.new('1', '1.00')
54
+ shipping.address = address
55
+ shipping
56
+ }
57
+
58
+
59
+ let(:installment) { PagSeguro::Installment.new('5', '125.22')}
60
+
61
+ let(:holder) do
62
+ holder = PagSeguro::Holder.new('Jose Comprador', '27/10/1987')
63
+ holder.document = document
64
+ holder.phone = phone
65
+ holder
66
+ end
67
+
68
+ let(:credit_card) do
69
+ credit_card = PagSeguro::CreditCard.new('4as56d4a56d456as456dsa')
70
+ credit_card.installment = installment
71
+ credit_card.holder = holder
72
+ credit_card.billing_address = address
73
+ credit_card
74
+ end
75
+ before do
76
+ PagSeguro.email = 'pagseguro@eventick.com.br'
77
+ PagSeguro.token = 'my_token'
78
+ end
79
+ let(:bank) { PagSeguro::Bank.new('bancodobrasil') }
80
+
81
+ it { subject[:email].should eq('pagseguro@eventick.com.br') }
82
+ it { subject[:token].should eq('my_token') }
83
+ it { subject[:paymentMode].should eq('default') }
84
+ it { subject[:paymentMethod].should eq('boleto') }
85
+ it { subject[:currency].should eq('BRL') }
86
+ it { subject[:extraAmount].should eq('1.00') }
87
+ it { subject[:notificationURL].should eq('https://sualoja.com.br/notifica.html') }
88
+ it { subject[:reference].should eq('REF1234') }
89
+ it { subject[:senderName].should eq('Jose Comprador') }
90
+ it { subject[:senderCPF].should eq('22111944785') }
91
+ it { subject[:senderAreaCode].should eq('11') }
92
+ it { subject[:senderPhone].should eq('56273440') }
93
+ it { subject[:senderEmail].should eq('comprador@uol.com.br') }
94
+ it { subject[:senderHash].should eq('abc123') }
95
+ it { subject[:shippingAddressStreet].should eq('Av. Brig. Faria Lima') }
96
+ it { subject[:shippingAddressNumber].should eq('1384') }
97
+ it { subject[:shippingAddressComplement].should eq('5o andar') }
98
+ it { subject[:shippingAddressDistrict].should eq('Jardim Paulistano') }
99
+ it { subject[:shippingAddressPostalCode].should eq('01452002') }
100
+ it { subject[:shippingAddressCity].should eq('Sao Paulo') }
101
+ it { subject[:shippingAddressState].should eq('SP') }
102
+ it { subject[:shippingAddressCountry].should eq('BRA') }
103
+ it { subject[:shippingType].should eq('1') }
104
+ it { subject[:shippingCost].should eq('1.00') }
105
+ it { subject[:creditCardToken].should eq('4as56d4a56d456as456dsa') }
106
+ it { subject[:installmentQuantity].should eq('5') }
107
+ it { subject[:installmentValue].should eq('125.22') }
108
+ it { subject[:creditCardHolderName].should eq('Jose Comprador') }
109
+ it { subject[:creditCardHolderCPF].should eq('22111944785') }
110
+ it { subject[:creditCardHolderBirthDate].should eq('27/10/1987') }
111
+ it { subject[:creditCardHolderAreaCode].should eq('11') }
112
+ it { subject[:creditCardHolderPhone].should eq('56273440') }
113
+
114
+ it { subject[:billingAddressStreet].should eq('Av. Brig. Faria Lima') }
115
+ it { subject[:billingAddressNumber].should eq('1384') }
116
+ it { subject[:billingAddressComplement].should eq('5o andar') }
117
+ it { subject[:billingAddressDistrict].should eq('Jardim Paulistano') }
118
+ it { subject[:billingAddressPostalCode].should eq('01452002') }
119
+ it { subject[:billingAddressCity].should eq('Sao Paulo') }
120
+ it { subject[:billingAddressState].should eq('SP') }
121
+ it { subject[:billingAddressCountry].should eq('BRA') }
122
+
123
+ it { subject[:itemId1].should eq('0001') }
124
+ it { subject[:itemDescription1].should eq('Notebook Prata') }
125
+ it { subject[:itemAmount1].should eq('24300.00') }
126
+ it { subject[:itemQuantity1].should eq('1') }
127
+ it { subject[:itemId2].should eq('0002') }
128
+ it { subject[:itemDescription2].should eq('Notebook Rosa') }
129
+ it { subject[:itemAmount2].should eq('25600.00') }
130
+ it { subject[:itemQuantity2].should eq('2') }
131
+ end
@@ -0,0 +1,91 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Transaction do
4
+ subject { transaction }
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(:transaction) do
18
+ transaction = PagSeguro::Transaction.new(options)
19
+ transaction.sender = sender
20
+ transaction.shipping = shipping
21
+ transaction.items = [PagSeguro::Item.new(1, 'Ingresso Teste', 2, 1)]
22
+ transaction
23
+ end
24
+
25
+
26
+ let(:document) { PagSeguro::Document.new('017.355.323-00') }
27
+ let(:phone) {PagSeguro::Phone.new('11', '99999999') }
28
+ let(:sender) do
29
+ sender = PagSeguro::Sender.new({
30
+ email: 'produtor@eventick.com.br',
31
+ name: 'João do evento',
32
+ hash_id: 'abc1234'
33
+ })
34
+ sender.phone = phone
35
+ sender.document = document
36
+ sender
37
+ end
38
+
39
+ let(:address) do
40
+ PagSeguro::Address.new({
41
+ postal_code: '01452002',
42
+ street: 'Rua Fernando de Albuquerque',
43
+ number: '35',
44
+ complement: '31',
45
+ district: 'Consolação',
46
+ city: 'São Paulo',
47
+ state: 'SP'
48
+ })
49
+ end
50
+
51
+ let(:shipping){
52
+ shipping = PagSeguro::Shipping.new
53
+ shipping.address = address
54
+ shipping
55
+ }
56
+
57
+ it { should respond_to(:receiver_email) }
58
+ it { should respond_to(:notification_url) }
59
+ it { should respond_to(:currency) }
60
+ it { should respond_to(:payment_method) }
61
+ it { should respond_to(:payment_mode) }
62
+ it { should respond_to(:items) }
63
+ it { should respond_to(:reference) }
64
+ it { should respond_to(:extra_amount) }
65
+ it { should respond_to(:sender) }
66
+ it { should respond_to(:shipping) }
67
+ it { should respond_to(:bank) }
68
+ it { should respond_to(:credit_card) }
69
+
70
+ describe 'presence validations' do
71
+ it { should validate_presence_of(:currency) }
72
+ it { should validate_presence_of(:payment_method) }
73
+ it { should validate_presence_of(:sender) }
74
+ it { should validate_presence_of(:shipping) }
75
+ end
76
+
77
+ describe 'inclusion validations' do
78
+ let(:payment_methods) { %w(creditCard boleto eft) }
79
+ it { should ensure_inclusion_of(:payment_method).in_array(payment_methods) }
80
+ end
81
+
82
+ context 'eft' do
83
+ let(:payment_method) { 'eft' }
84
+ it { should validate_presence_of(:bank) }
85
+ end
86
+
87
+ context 'credit card' do
88
+ let(:payment_method) { 'creditCard' }
89
+ it { should validate_presence_of(:credit_card) }
90
+ end
91
+ end
@@ -0,0 +1,16 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'bundler/setup'
5
+ Bundler.require(:default, :development)
6
+
7
+ require 'webmock/rspec'
8
+ require "pagseguro"
9
+
10
+ require 'shoulda/matchers'
11
+
12
+ RSpec.configure do |config|
13
+ config.before(:each) do
14
+ load './lib/pagseguro.rb'
15
+ end
16
+ end