braspag-pagador 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.md +23 -0
  6. data/README.md +532 -0
  7. data/RELEASES.md +20 -0
  8. data/Rakefile +6 -0
  9. data/braspag-pagador.gemspec +32 -0
  10. data/coverage/.resultset.json +2732 -0
  11. data/coverage/assets/0.5.3/app.js +88 -0
  12. data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  13. data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  14. data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  15. data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  16. data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  17. data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  18. data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  19. data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  20. data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  21. data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  22. data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  23. data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  24. data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  25. data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  26. data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  27. data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  28. data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  29. data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  30. data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  31. data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  32. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
  33. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
  34. data/coverage/assets/0.5.3/favicon_green.png +0 -0
  35. data/coverage/assets/0.5.3/favicon_red.png +0 -0
  36. data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  37. data/coverage/assets/0.5.3/highlight.css +129 -0
  38. data/coverage/assets/0.5.3/highlight.pack.js +1 -0
  39. data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
  40. data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
  41. data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
  42. data/coverage/assets/0.5.3/jquery.url.js +174 -0
  43. data/coverage/assets/0.5.3/loading.gif +0 -0
  44. data/coverage/assets/0.5.3/magnify.png +0 -0
  45. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  46. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  47. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  48. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  49. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  50. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  51. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  52. data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  53. data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  54. data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  55. data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  56. data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  57. data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  58. data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
  59. data/coverage/assets/0.5.3/stylesheet.css +383 -0
  60. data/coverage/index.html +17219 -0
  61. data/lib/braspag.rb +96 -0
  62. data/lib/braspag/core/connection.rb +112 -0
  63. data/lib/braspag/core/converter.rb +63 -0
  64. data/lib/braspag/core/customer.rb +13 -0
  65. data/lib/braspag/core/order.rb +286 -0
  66. data/lib/braspag/core/poster.rb +40 -0
  67. data/lib/braspag/crypto/no_crypto.rb +6 -0
  68. data/lib/braspag/crypto/webservice.rb +63 -0
  69. data/lib/braspag/payment/billet.rb +79 -0
  70. data/lib/braspag/payment/credit_card.rb +190 -0
  71. data/lib/braspag/payment/eft.rb +65 -0
  72. data/lib/braspag/payment/recurrency_credit_card.rb +15 -0
  73. data/lib/braspag/templates/crypto/decrypt.xml.erb +10 -0
  74. data/lib/braspag/templates/crypto/encrypt.xml.erb +14 -0
  75. data/lib/braspag/templates/justclick/archive.xml.erb +16 -0
  76. data/lib/braspag/templates/justclick/get_recurrency.xml.erb +12 -0
  77. data/lib/braspag/templates/justclick/recurrency.xml.erb +23 -0
  78. data/lib/braspag/version.rb +3 -0
  79. data/spec/core/connection_spec.rb +149 -0
  80. data/spec/core/converter_spec.rb +123 -0
  81. data/spec/core/customer_spec.rb +49 -0
  82. data/spec/core/order_spec.rb +504 -0
  83. data/spec/core/poster_spec.rb +63 -0
  84. data/spec/crypto/webservice_spec.rb +136 -0
  85. data/spec/integration/billet_spec.rb +38 -0
  86. data/spec/integration/credit_card_spec.rb +0 -0
  87. data/spec/payment/billet_spec.rb +205 -0
  88. data/spec/payment/credit_card_spec.rb +385 -0
  89. data/spec/payment/eft_spec.rb +88 -0
  90. data/spec/payment/recurrency_credit_card_spec.rb +100 -0
  91. data/spec/spec_helper.rb +24 -0
  92. metadata +292 -0
@@ -0,0 +1,15 @@
1
+ module Braspag
2
+ class Connection
3
+ def save_credit_card(credit_card, customer, request_id)
4
+ response = self.soap_request(:save_credit_card, credit_card, customer, request_id)
5
+ end
6
+ # request the credit card info in Braspag PCI Compliant
7
+ def get_recurrency(credit_card)
8
+
9
+ end
10
+
11
+ def recurrency(order, credit_card, request_id)
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
3
+ <env:Header />
4
+ <env:Body>
5
+ <tns:DecryptRequest xmlns:tns="https://www.pagador.com.br/webservice/BraspagGeneralService">
6
+ <tns:merchantId><%= connection.merchant_id %></tns:merchantId>
7
+ <tns:cryptString><%= encripted_text %></tns:cryptString>
8
+ </tns:DecryptRequest>
9
+ </env:Body>
10
+ </env:Envelope>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
3
+ <env:Header />
4
+ <env:Body>
5
+ <tns:EncryptRequest xmlns:tns="https://www.pagador.com.br/webservice/BraspagGeneralService">
6
+ <tns:merchantId><%= connection.merchant_id %></tns:merchantId>
7
+ <tns:request>
8
+ <% map.each do |key, value| %>
9
+ <tns:string><%= key %>=<%= value %></tns:string>
10
+ <% end %>
11
+ </tns:request>
12
+ </tns:EncryptRequest>
13
+ </env:Body>
14
+ </env:Envelope>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soap:Body>
4
+ <SaveCreditCard xmlns="http://www.cartaoprotegido.com.br/WebService/">
5
+ <saveCreditCardRequestWS>
6
+ <MerchantKey><%= merchant_id %></MerchantKey>
7
+ <CustomerIdentification><%= customer.cpf%></CustomerIdentification>
8
+ <CustomerName><%= customer.name %></CustomerName>
9
+ <CardHolder><%= credit_card.holder_name %></CardHolder>
10
+ <CardNumber><%= credit_card.number %></CardNumber>
11
+ <CardExpiration><%= credit_card.year + credit_card.month %></CardExpiration>
12
+ <JustClickAlias><%= creditcard_alias%></JustClickAlias>
13
+ </saveCreditCardRequestWS>
14
+ </SaveCreditCard>
15
+ </soap:Body>
16
+ </soap:Envelope>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soap:Body>
4
+ <GetCreditCard xmlns="http://www.cartaoprotegido.com.br/WebService/">
5
+ <getCreditCardRequestWS>
6
+ <MerchantKey><%= merchant_id %></MerchantKey>
7
+ <JustClickKey>guid</JustClickKey>
8
+ <JustClickAlias>string</JustClickAlias>
9
+ </getCreditCardRequestWS>
10
+ </GetCreditCard>
11
+ </soap:Body>
12
+ </soap:Envelope>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soap:Body>
4
+ <JustClickShop xmlns="http://www.cartaoprotegido.com.br/WebService/">
5
+ <justClickShopRequestWS>
6
+ <MerchantKey>guid</MerchantKey>
7
+ <CustomerIdentification>string</CustomerIdentification>
8
+ <CustomerName>string</CustomerName>
9
+ <OrderId>string</OrderId>
10
+ <Amount>int</Amount>
11
+ <PaymentMethod>short</PaymentMethod>
12
+ <NumberInstallments>short</NumberInstallments>
13
+ <PaymentType>short</PaymentType>
14
+ <JustClickKey>guid</JustClickKey>
15
+ <SecurityCode>string</SecurityCode>
16
+ <Country>string</Country>
17
+ <Currency>string</Currency>
18
+ <MerchantIdPagador>guid</MerchantIdPagador>
19
+ <JustClickAlias>string</JustClickAlias>
20
+ </justClickShopRequestWS>
21
+ </JustClickShop>
22
+ </soap:Body>
23
+ </soap:Envelope>
@@ -0,0 +1,3 @@
1
+ module Braspag
2
+ VERSION = "0.9.4"
3
+ end
@@ -0,0 +1,149 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe Braspag::Connection do
5
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
6
+
7
+ it "should accept a valid merchant" do
8
+ expect {
9
+ Braspag::Connection.new(:merchant_id => merchant_id)
10
+ }.to_not raise_error(Braspag::Connection::InvalidMerchantId)
11
+ end
12
+
13
+ it "should raise error with invalid merchant" do
14
+ expect {
15
+ Braspag::Connection.new(:merchant_id => "INVALID")
16
+ }.to raise_error(Braspag::Connection::InvalidMerchantId)
17
+ end
18
+
19
+ [:homologation, :production].each do |env|
20
+ it "should accept #{env} environment" do
21
+ expect {
22
+ Braspag::Connection.new(:merchant_id => merchant_id, :environment => env)
23
+ }.to_not raise_error(Braspag::Connection::InvalidEnvironment)
24
+ end
25
+ end
26
+
27
+ it "should raise error with invalid environment" do
28
+ expect {
29
+ Braspag::Connection.new(:merchant_id => merchant_id, :environment => :bla)
30
+ }.to raise_error(Braspag::Connection::InvalidEnvironment)
31
+ end
32
+
33
+ describe ".production?" do
34
+ it "should return true" do
35
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :production)
36
+ connection.production?.should be(true)
37
+ end
38
+
39
+ it "should return false" do
40
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)
41
+ connection.production?.should be(false)
42
+ end
43
+ end
44
+
45
+ describe ".homologation?" do
46
+ it "should return true" do
47
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)
48
+ connection.homologation?.should be(true)
49
+ end
50
+
51
+ it "should return false" do
52
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :production)
53
+ connection.homologation?.should be(false)
54
+ end
55
+ end
56
+
57
+ describe ".url_for" do
58
+ let(:braspag_homologation_url) { "https://homologacao.pagador.com.br" }
59
+ let(:braspag_production_url) { "https://transaction.pagador.com.br" }
60
+ let(:braspag_homologation_protected_card_url) { "https://homologacao.braspag.com.br/services/testenvironment" }
61
+ let(:braspag_production_protected_card_url) { "https://cartaoprotegido.braspag.com.br/Services" }
62
+
63
+ it "should return the correct credit card creation url when connection environment is homologation" do
64
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)
65
+ connection.url_for(:authorize).should == "#{braspag_homologation_url}/webservices/pagador/Pagador.asmx/Authorize"
66
+ connection.url_for(:capture).should == "#{braspag_homologation_url}/webservices/pagador/Pagador.asmx/Capture"
67
+ connection.url_for(:void).should == "#{braspag_homologation_url}/webservices/pagador/Pagador.asmx/VoidTransaction"
68
+ connection.url_for(:generate_billet).should == "#{braspag_homologation_url}/webservices/pagador/Boleto.asmx/CreateBoleto"
69
+ connection.url_for(:generate_eft).should == "#{braspag_homologation_url}/pagador/passthru.asp"
70
+ connection.url_for(:info_billet).should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosBoleto"
71
+ connection.url_for(:info_credit_card).should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosCartao"
72
+ connection.url_for(:info).should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosPedido"
73
+ connection.url_for(:encrypt).should == "#{braspag_homologation_url}/BraspagGeneralService/BraspagGeneralService.asmx"
74
+ connection.url_for(:archive_card).should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx?wsdl"
75
+ connection.url_for(:get_card).should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx/GetCreditCard"
76
+ connection.url_for(:recurrency).should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx?wsdl"
77
+ end
78
+
79
+ it "should return the correct credit card creation url when connection environment is production" do
80
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :production)
81
+ connection.url_for(:authorize).should == "#{braspag_production_url}/webservices/pagador/Pagador.asmx/Authorize"
82
+ connection.url_for(:capture).should == "#{braspag_production_url}/webservices/pagador/Pagador.asmx/Capture"
83
+ connection.url_for(:void).should == "#{braspag_production_url}/webservices/pagador/Pagador.asmx/VoidTransaction"
84
+ connection.url_for(:generate_billet).should == "#{braspag_production_url}/webservices/pagador/Boleto.asmx/CreateBoleto"
85
+ connection.url_for(:generate_eft).should == "#{braspag_production_url}/pagador/passthru.asp"
86
+ connection.url_for(:info_billet).should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosBoleto"
87
+ connection.url_for(:info_credit_card).should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosCartao"
88
+ connection.url_for(:info).should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosPedido"
89
+ connection.url_for(:encrypt).should == "#{braspag_production_url}/BraspagGeneralService/BraspagGeneralService.asmx"
90
+ connection.url_for(:archive_card).should == "#{braspag_production_protected_card_url}/CartaoProtegido.asmx?wsdl"
91
+ connection.url_for(:get_card).should == "#{braspag_production_protected_card_url}/CartaoProtegido.asmx/GetCreditCard"
92
+ connection.url_for(:recurrency).should == "#{braspag_production_protected_card_url}/CartaoProtegido.asmx?wsdl"
93
+ end
94
+ end
95
+
96
+ describe ".post" do
97
+ it "should convert data" do
98
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)
99
+
100
+ mock1 = mock
101
+ mock2 = mock
102
+ resp = mock
103
+ convert_to = mock
104
+
105
+ connection.should_receive(:convert).with(
106
+ :info,
107
+ :to,
108
+ [mock1, mock2]
109
+ ).and_return(convert_to)
110
+
111
+ connection.should_receive(:convert).with(
112
+ :info,
113
+ :from,
114
+ [mock1, mock2, resp]
115
+ )
116
+
117
+ Braspag::Poster.any_instance.should_receive(:do_post).with(
118
+ :info,
119
+ convert_to
120
+ ).and_return(resp)
121
+
122
+ connection.post(:info, mock1, mock2)
123
+ end
124
+ end
125
+
126
+ describe ".convert" do
127
+ let (:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation) }
128
+ {
129
+ :authorize => Braspag::CreditCard,
130
+ :void => Braspag::CreditCard,
131
+ :capture => Braspag::CreditCard,
132
+ :archive_card => Braspag::CreditCard,
133
+ :get_card => Braspag::CreditCard,
134
+ :recurrency => Braspag::CreditCard,
135
+ :generate_billet => Braspag::Billet,
136
+ :generate_eft => Braspag::EFT,
137
+ :info_billet => Braspag::Order,
138
+ :info_credit_card => Braspag::Order,
139
+ :info => Braspag::Order,
140
+ :encrypt => Braspag::Crypto::Webservice
141
+ }.each do |method_name, kclass|
142
+ it "should call method when convert #{method_name} to #{kclass}" do
143
+ args = [mock, mock]
144
+ kclass.should_receive("to_#{method_name}".to_sym).with(connection, args[0], args[1])
145
+ connection.convert(method_name, :to, args)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Braspag::Converter do
4
+ describe ".decimal_to_string" do
5
+ it "should convert decimal to string with comma as decimal separator" do
6
+ Braspag::Converter.decimal_to_string(10).should eq("10,00")
7
+ Braspag::Converter.decimal_to_string(1).should eq("1,00")
8
+ Braspag::Converter.decimal_to_string(0.1).should eq("0,10")
9
+ Braspag::Converter.decimal_to_string(0.01).should eq("0,01")
10
+ Braspag::Converter.decimal_to_string(9.99999).should eq("10,00") # round up
11
+ Braspag::Converter.decimal_to_string(10.9).should eq("10,90")
12
+ Braspag::Converter.decimal_to_string(9.1111).should eq("9,11")
13
+ Braspag::Converter.decimal_to_string("10,00").should eq("10,00")
14
+ end
15
+ end
16
+
17
+ describe ".string_to_decimal" do
18
+ it "should string with comma as decimal separator to decimal" do
19
+ Braspag::Converter.string_to_decimal("1000,00").should eq(1000.00)
20
+ Braspag::Converter.string_to_decimal("1.000,00").should eq(1000.00)
21
+ Braspag::Converter.string_to_decimal("10,00").should eq(10.00)
22
+ Braspag::Converter.string_to_decimal("1,00").should eq(1.00)
23
+ Braspag::Converter.string_to_decimal("0,10").should eq(0.1)
24
+ Braspag::Converter.string_to_decimal("0,01").should eq(0.01)
25
+ Braspag::Converter.string_to_decimal("9,99").should eq(9.99)
26
+ Braspag::Converter.string_to_decimal("10,9").should eq(10.90)
27
+ Braspag::Converter.string_to_decimal("9,1111").should eq(9.1111)
28
+ end
29
+ end
30
+
31
+ describe ".hash_from_xml" do
32
+ let(:document) do
33
+ <<-XML
34
+ <root>
35
+ <foo>blabla</foo>
36
+ <bar>bleble</bar>
37
+ <baz></baz>
38
+ </root>
39
+ XML
40
+ end
41
+
42
+ context "basic document and keys" do
43
+ it "should return a Hash" do
44
+ keys = { :foo => nil, :meu_elemento => "bar", :outro_elemento => "baz" }
45
+ expected = { :foo => "blabla", :meu_elemento => "bleble", :outro_elemento => nil }
46
+
47
+ Braspag::Converter::hash_from_xml(document, keys).should == expected
48
+ end
49
+
50
+ it "should return a Hash with invalid key" do
51
+ keys = { :foo => "invalid", :meu_elemento => "bar", :outro_elemento => "baz" }
52
+ expected = { :foo => nil, :meu_elemento => "bleble", :outro_elemento => nil }
53
+
54
+ Braspag::Converter::hash_from_xml(document, keys).should == expected
55
+ end
56
+ end
57
+
58
+ context "keys with a Proc" do
59
+ it "should return a Hash" do
60
+ proc = Proc.new { "value returned by Proc" }
61
+
62
+ keys = { :foo => proc, :meu_elemento => "bar", :outro_elemento => "baz" }
63
+ expected = { :foo => "value returned by Proc", :meu_elemento => "bleble", :outro_elemento => nil }
64
+
65
+ Braspag::Converter::hash_from_xml(document, keys).should == expected
66
+ end
67
+ end
68
+ end
69
+
70
+ describe ".payment_method_name?" do
71
+ it "should return name from number" do
72
+ Braspag::Converter.payment_method_name?(6).should eq(:billet_bradesco)
73
+ end
74
+
75
+ it "should return name from string" do
76
+ Braspag::Converter.payment_method_name?("6").should eq(:billet_bradesco)
77
+ end
78
+
79
+ it "should return name from string with 0" do
80
+ Braspag::Converter.payment_method_name?("06").should eq(:billet_bradesco)
81
+ end
82
+
83
+ it "should return nil when not found" do
84
+ Braspag::Converter.payment_method_name?("AAA").should be(nil)
85
+ end
86
+ end
87
+
88
+ describe ".status_name?" do
89
+ it "should return name from number" do
90
+ Braspag::Converter.status_name?(1).should eq(:starting)
91
+ end
92
+
93
+ it "should return name from string" do
94
+ Braspag::Converter.status_name?("1").should eq(:starting)
95
+ end
96
+
97
+ it "should return name from string with 0" do
98
+ Braspag::Converter.status_name?("01").should eq(:starting)
99
+ end
100
+
101
+ it "should return nil when not found" do
102
+ Braspag::Converter.status_name?("AAA").should be(nil)
103
+ end
104
+ end
105
+
106
+ describe "payment_method_type?" do
107
+ it "should response nil when invalid method" do
108
+ Braspag::Converter.payment_method_type?(999).should be(nil)
109
+ end
110
+
111
+ it "should response billet" do
112
+ Braspag::Converter.payment_method_type?(6).should be(:billet)
113
+ end
114
+
115
+ it "should response eft" do
116
+ Braspag::Converter.payment_method_type?(16).should be(:eft)
117
+ end
118
+
119
+ it "should response credit_card" do
120
+ Braspag::Converter.payment_method_type?(997).should be(:credit_card)
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Braspag::Customer do
4
+ [:purchase, :generate, :authorize, :archive, :recurrency ].each do |context_type|
5
+ context "on #{context_type}" do
6
+ it "should validate minimum 1 length of name" do
7
+ subject.name = ''
8
+ subject.valid?(context_type)
9
+ subject.errors.messages[:name].should include("is too short (minimum is 1 characters)")
10
+ end
11
+
12
+ it "should validate maximum 100 length of name" do
13
+ subject.name = '*' * 110
14
+ subject.valid?(context_type)
15
+ subject.errors.messages[:name].should include("is too long (maximum is 100 characters)")
16
+ end
17
+
18
+ it "should allow blank for email" do
19
+ subject.email = ''
20
+ subject.valid?(context_type)
21
+ subject.errors.messages[:email].should be(nil)
22
+ end
23
+
24
+ it "should validate maximum 255 length of email" do
25
+ subject.email = '*' * 260
26
+ subject.valid?(context_type)
27
+ subject.errors.messages[:email].should include("is too long (maximum is 255 characters)")
28
+ end
29
+
30
+ it "should allow blank for document" do
31
+ subject.document = ''
32
+ subject.valid?(context_type)
33
+ subject.errors.messages[:document].should be(nil)
34
+ end
35
+
36
+ it "should validate minimum 11 length of document" do
37
+ subject.document = 'XXX'
38
+ subject.valid?(context_type)
39
+ subject.errors.messages[:document].should include("is too short (minimum is 11 characters)")
40
+ end
41
+
42
+ it "should validate maximum 18 length of document" do
43
+ subject.document = '*' * 20
44
+ subject.valid?(context_type)
45
+ subject.errors.messages[:document].should include("is too long (maximum is 18 characters)")
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,504 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe Braspag::Connection do
5
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
6
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
7
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
8
+
9
+ describe ".get" do
10
+ context "when error" do
11
+ it "should return message for response blank" do
12
+ connection.stub(:post).and_return({})
13
+ response = connection.get(order)
14
+
15
+ response.success?.should eq(false)
16
+ response.message.should eq('')
17
+ response.params.should eq({})
18
+ response.test.should eq(true)
19
+ end
20
+
21
+ it "should return message for error code" do
22
+ order_response = {:error_code => 'bla', :error_message => 'xpto', :status => '223'}
23
+ connection.stub(:post).and_return(order_response)
24
+ response = connection.get(order)
25
+
26
+ response.success?.should eq(false)
27
+ response.message.should eq(order_response[:error_message])
28
+ response.params.should eq({"error_code"=>"bla", "error_message"=>"xpto", "status" => '223'})
29
+ response.test.should eq(true)
30
+ end
31
+
32
+ it "should return message for empty status" do
33
+ connection.stub(:post).and_return({:error_message => 'bla'})
34
+ response = connection.get(order)
35
+
36
+ response.success?.should eq(false)
37
+ response.message.should eq('bla')
38
+ response.params.should eq({"error_message"=>"bla"})
39
+ response.test.should eq(true)
40
+ end
41
+ end
42
+
43
+ it "should return response ok" do
44
+ connection.stub(:post).and_return({:status => '1'})
45
+ response = connection.get(order)
46
+
47
+ response.success?.should eq(true)
48
+ response.message.should eq('OK')
49
+ response.params.should eq({"status" => "1"})
50
+ response.test.should eq(true)
51
+ end
52
+
53
+ it "should get more info for billet" do
54
+ connection.should_receive(:post).and_return({:status => '1'})
55
+ connection.should_receive(:post).with(:info_billet, order)
56
+ order.payment_method = 6 #BILLET BRADESCO
57
+ response = connection.get(order)
58
+
59
+ response.success?.should eq(true)
60
+ response.message.should eq('OK')
61
+ response.params.should eq({"status" => "1"})
62
+ response.test.should eq(true)
63
+ end
64
+
65
+ it "should get more info for credit_card" do
66
+ connection.should_receive(:post).and_return({:status => '1'})
67
+ connection.should_receive(:post).with(:info_credit_card, order)
68
+ order.payment_method = 18 #AMEX
69
+ response = connection.get(order)
70
+
71
+ response.success?.should eq(true)
72
+ response.message.should eq('OK')
73
+ response.params.should eq({"status" => "1"})
74
+ response.test.should eq(true)
75
+ end
76
+ end
77
+ end
78
+
79
+ describe Braspag::Order do
80
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
81
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
82
+
83
+ describe ".payment_method_type?" do
84
+ it "should return payment method type" do
85
+ order = subject
86
+ order.payment_method = 6
87
+ order.payment_method_type?.should eq(:billet)
88
+ end
89
+ end
90
+
91
+ context "on info" do
92
+ let(:valid_xml) do
93
+ <<-EOXML
94
+ <?xml version="1.0" encoding="utf-8"?>
95
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
96
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
97
+ xmlns="http://www.pagador.com.br/">
98
+ <CodigoAutorizacao>885796</CodigoAutorizacao>
99
+ <CodigoPagamento>18</CodigoPagamento>
100
+ <FormaPagamento>American Express 2P</FormaPagamento>
101
+ <NumeroParcelas>1</NumeroParcelas>
102
+ <Status>3</Status>
103
+ <Valor>0.01</Valor>
104
+ <DataCancelamento>7/8/2011 1:19:38 PM</DataCancelamento>
105
+ <DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
106
+ <DataPedido>7/8/2011 1:06:06 PM</DataPedido>
107
+ <TransId>398591</TransId>
108
+ <BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
109
+ </DadosPedido>
110
+ EOXML
111
+ end
112
+
113
+ let(:invalid_xml) do
114
+ <<-EOXML
115
+ <?xml version="1.0" encoding="utf-8"?>
116
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
117
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
118
+ xsi:nil="true"
119
+ xmlns="http://www.pagador.com.br/" />
120
+ EOXML
121
+ end
122
+
123
+ let(:error_xml) do
124
+ <<-EOXML
125
+ <?xml version="1.0" encoding="utf-8"?>
126
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
127
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
128
+ xmlns="http://www.pagador.com.br/">
129
+ <CodigoErro>885796</CodigoErro>
130
+ <MensagemErro>Deu um erro terrivel</MensagemErro>
131
+ </DadosPedido>
132
+ EOXML
133
+ end
134
+
135
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
136
+
137
+ it "should convert objects to hash" do
138
+ Braspag::Order.to_info(connection, order).should eq({
139
+ "loja" => "#{merchant_id}",
140
+ "numeroPedido" => "#{order.id}"
141
+ })
142
+ end
143
+
144
+ it "should populate data" do
145
+ resp = Braspag::Order.from_info(connection, order, mock(:body => valid_xml))
146
+
147
+ order.authorization.should eq('885796')
148
+ order.payment_method_name.should eq('American Express 2P')
149
+ order.payment_method.should eq('18')
150
+ order.installments.should eq('1')
151
+ order.status.should eq('3')
152
+ order.amount.should eq(0.01)
153
+ order.gateway_cancelled_at.should eq(Time.parse('2011-08-07 13:19:38 -0300'))
154
+ order.gateway_paid_at.should eq(Time.parse('2011-08-07 13:19:38 -0300'))
155
+ order.gateway_created_at.should eq(Time.parse('2011-08-07 13:06:06 -0300'))
156
+ order.transaction_id.should eq('398591')
157
+ order.gateway_id.should eq('5a1d4463-1d11-4571-a877-763aba0ef7ff')
158
+
159
+ resp.should eq({
160
+ :authorization => "885796",
161
+ :error_code => nil,
162
+ :error_message => nil,
163
+ :payment_method => "18",
164
+ :payment_method_name => "American Express 2P",
165
+ :installments => "1",
166
+ :status => "3",
167
+ :amount => "0.01",
168
+ :cancelled_at => Time.parse('2011-08-07 13:19:38 -0300'),
169
+ :paid_at => Time.parse('2011-08-07 13:19:38 -0300'),
170
+ :order_date => Time.parse('2011-08-07 13:06:06 -0300'),
171
+ :transaction_id => "398591",
172
+ :tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
173
+ })
174
+ end
175
+
176
+ it "should populate data accepts invalid xml" do
177
+ resp = Braspag::Order.from_info(connection, order, mock(:body => invalid_xml))
178
+
179
+ resp.should eq({
180
+ :authorization => nil,
181
+ :error_code => nil,
182
+ :error_message => nil,
183
+ :payment_method => nil,
184
+ :payment_method_name => nil,
185
+ :installments => nil,
186
+ :status => nil,
187
+ :amount => nil,
188
+ :cancelled_at => nil,
189
+ :paid_at => nil,
190
+ :order_date => nil,
191
+ :transaction_id => nil,
192
+ :tid => nil
193
+ })
194
+ end
195
+
196
+ it "should populate data for error" do
197
+ resp = Braspag::Order.from_info(connection, order, mock(:body => error_xml))
198
+
199
+ resp.should eq({
200
+ :authorization => nil,
201
+ :error_code => "885796",
202
+ :error_message => "Deu um erro terrivel",
203
+ :payment_method => nil,
204
+ :payment_method_name => nil,
205
+ :installments => nil,
206
+ :status => nil,
207
+ :amount => nil,
208
+ :cancelled_at => nil,
209
+ :paid_at => nil,
210
+ :order_date => nil,
211
+ :transaction_id => nil,
212
+ :tid => nil
213
+ })
214
+ end
215
+ end
216
+
217
+ context "on info for billet" do
218
+ let(:valid_xml) do
219
+ <<-EOXML
220
+ <?xml version="1.0" encoding="utf-8"?>
221
+ <DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
222
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
223
+ xmlns="http://www.pagador.com.br/">
224
+ <NumeroDocumento>999</NumeroDocumento>
225
+ <Sacado>XPTO</Sacado>
226
+ <NossoNumero>999</NossoNumero>
227
+ <LinhaDigitavel>35690.00361 03962.070003 00000.009993 4 50160000001000</LinhaDigitavel>
228
+ <DataDocumento>22/6/2011</DataDocumento>
229
+ <DataVencimento>2/7/2011</DataVencimento>
230
+ <DataCredito>2/7/2011</DataCredito>
231
+ <Cedente>Acessoria Empresarial Ltda</Cedente>
232
+ <Banco>356-5</Banco>
233
+ <Agencia>0003</Agencia>
234
+ <Conta>6039620</Conta>
235
+ <Carteira>57</Carteira>
236
+ <ValorDocumento>10,00</ValorDocumento>
237
+ <ValorPago>10,00</ValorPago>
238
+ </DadosBoleto>
239
+ EOXML
240
+ end
241
+
242
+ let(:invalid_xml) do
243
+ <<-EOXML
244
+ <?xml version="1.0" encoding="utf-8"?>
245
+ <DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
246
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
247
+ xmlns="http://www.pagador.com.br/">
248
+ </DadosBoleto>
249
+ EOXML
250
+ end
251
+
252
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
253
+
254
+ it "should convert objects to hash" do
255
+ Braspag::Order.to_info_billet(connection, order).should eq({
256
+ "loja" => "#{merchant_id}",
257
+ "numeroPedido" => "#{order.id}"
258
+ })
259
+ end
260
+
261
+ it "should populate data" do
262
+ resp = Braspag::Order.from_info_billet(connection, order, mock(:body => valid_xml))
263
+
264
+ order.customer.name.should eq('XPTO')
265
+
266
+ order.billet.id.should eq('999')
267
+ order.billet.code.should eq('35690.00361 03962.070003 00000.009993 4 50160000001000')
268
+
269
+ order.billet.created_at.should eq(Date.parse('2011-06-22'))
270
+ order.billet.due_date_on.should eq(Date.parse('2011-07-2'))
271
+
272
+ order.billet.receiver.should eq('Acessoria Empresarial Ltda')
273
+
274
+ order.billet.bank.should eq('356-5')
275
+ order.billet.agency.should eq('0003')
276
+ order.billet.account.should eq('6039620')
277
+ order.billet.wallet.should eq('57')
278
+ order.billet.amount.should eq(10.00)
279
+ order.billet.amount_paid.should eq(10.00)
280
+ order.billet.paid_at.should eq(Date.parse('2011-07-02'))
281
+
282
+ resp.should eq({
283
+ :document_number=>"999",
284
+ :payer=>"XPTO",
285
+ :our_number=>"999",
286
+ :bill_line=>"35690.00361 03962.070003 00000.009993 4 50160000001000",
287
+ :document_date=>Date.parse('2011-06-22'),
288
+ :expiration_date=>Date.parse('2011-07-2'),
289
+ :receiver=>"Acessoria Empresarial Ltda",
290
+ :bank=>"356-5",
291
+ :agency=>"0003",
292
+ :account=>"6039620",
293
+ :wallet=>"57",
294
+ :amount=>"10,00",
295
+ :amount_invoice=>"10,00",
296
+ :invoice_date=> Date.parse('2011-07-02')
297
+ })
298
+ end
299
+
300
+ it "should not raise error for invalid xml" do
301
+ resp = Braspag::Order.from_info_billet(connection, order, mock(:body => invalid_xml))
302
+
303
+ resp.should eq({
304
+ :document_number => nil,
305
+ :payer => nil,
306
+ :our_number => nil,
307
+ :bill_line => nil,
308
+ :document_date => nil,
309
+ :expiration_date => nil,
310
+ :receiver => nil,
311
+ :bank=> nil,
312
+ :agency=> nil,
313
+ :account=> nil,
314
+ :wallet=> nil,
315
+ :amount=> nil,
316
+ :amount_invoice=> nil,
317
+ :invoice_date=> nil
318
+ })
319
+ end
320
+ end
321
+
322
+ context "on info for credit card" do
323
+ let(:valid_xml) do
324
+ <<-EOXML
325
+ <DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
326
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
327
+ xmlns="http://www.pagador.com.br/">
328
+ <RetornoAVS>12</RetornoAVS>
329
+ <Emissor>VISA</Emissor>
330
+ <NumeroAutenticacao>12345</NumeroAutenticacao>
331
+ <NumeroComprovante>11111</NumeroComprovante>
332
+ <Autenticada>false</Autenticada>
333
+ <NumeroAutorizacao>557593</NumeroAutorizacao>
334
+ <NumeroCartao>345678*****0007</NumeroCartao>
335
+ <NumeroTransacao>101001225645</NumeroTransacao>
336
+ </DadosCartao>
337
+ EOXML
338
+ end
339
+
340
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
341
+
342
+ it "should convert objects to hash" do
343
+ Braspag::Order.to_info_credit_card(connection, order).should eq({
344
+ "loja" => "#{merchant_id}",
345
+ "numeroPedido" => "#{order.id}"
346
+ })
347
+ end
348
+
349
+ it "should populate data" do
350
+ resp = Braspag::Order.from_info_credit_card(connection, order, mock(:body => valid_xml))
351
+
352
+ order.credit_card.checking_number.should eq('11111')
353
+ order.credit_card.avs.should eq('false')
354
+ order.credit_card.autorization_number.should eq('557593')
355
+ order.credit_card.number.should eq('345678*****0007')
356
+ order.credit_card.transaction_number.should eq('101001225645')
357
+ order.credit_card.avs_response.should eq('12')
358
+ order.credit_card.issuing.should eq('VISA')
359
+ order.credit_card.authenticated_number.should eq('12345')
360
+
361
+ resp.should eq({
362
+ :checking_number => "11111",
363
+ :certified => "false",
364
+ :autorization_number => "557593",
365
+ :card_number => "345678*****0007",
366
+ :transaction_number => "101001225645",
367
+ :avs_response => "12",
368
+ :issuing => "VISA",
369
+ :authenticated_number => "12345"
370
+ })
371
+ end
372
+ end
373
+
374
+ [:purchase, :generate, :authorize, :capture, :void, :recurrency].each do |context_type|
375
+ context "on #{context_type}" do
376
+ it "should validate minimum 1 length of id" do
377
+ subject.id = ''
378
+ subject.valid?(context_type)
379
+ subject.errors.messages[:id].should include("is too short (minimum is 1 characters)")
380
+ end
381
+
382
+ it "should validate maximum 20 length of id" do
383
+ subject.id = '*' * 25
384
+ subject.valid?(context_type)
385
+ subject.errors.messages[:id].should include("is too long (maximum is 20 characters)")
386
+ end
387
+
388
+ it "should allow characters without payment_method" do
389
+ subject.id = '*13*'
390
+ subject.valid?(context_type)
391
+ subject.errors.messages[:id].should eq(nil)
392
+ end
393
+
394
+ [:cielo_noauth_visa, :cielo_preauth_visa, :cielo_noauth_mastercard, :cielo_preauth_mastercard, :cielo_noauth_elo, :cielo_noauth_diners ].each do |payment_method|
395
+ context "when has payment method for #{payment_method}" do
396
+ it "should not allow spaces" do
397
+ subject.payment_method = Braspag::PAYMENT_METHOD[payment_method]
398
+ subject.id = '123 4'
399
+ subject.valid?(context_type)
400
+ subject.errors.messages[:id].should include("is invalid")
401
+ end
402
+ it "should not allow characters" do
403
+ subject.payment_method = Braspag::PAYMENT_METHOD[payment_method]
404
+ subject.id = 'abcd'
405
+ subject.valid?(context_type)
406
+ subject.errors.messages[:id].should include("is invalid")
407
+ end
408
+
409
+ it "should not allow special characters" do
410
+ subject.payment_method = Braspag::PAYMENT_METHOD[payment_method]
411
+ subject.id = '*-[]'
412
+ subject.valid?(context_type)
413
+ subject.errors.messages[:id].should include("is invalid")
414
+ end
415
+ end
416
+ end
417
+ end
418
+ end
419
+
420
+ [:purchase, :generate, :authorize, :recurrency].each do |context_type|
421
+ context "on #{context_type}" do
422
+ it "should not allow blank for payment_method" do
423
+ subject.payment_method = ''
424
+ subject.valid?(context_type)
425
+ subject.errors.messages[:payment_method].should include("can't be blank")
426
+ end
427
+
428
+ it "should not allow blank for amount" do
429
+ subject.amount = ''
430
+ subject.valid?(context_type)
431
+ subject.errors.messages[:amount].should include("can't be blank")
432
+ end
433
+
434
+ it "should validate minimum 1 of amount" do
435
+ subject.amount = 0
436
+ subject.valid?(context_type)
437
+ subject.errors.messages[:amount].should include("must be greater than 0")
438
+ end
439
+
440
+ it "should not allow blank for customer" do
441
+ subject.customer = ''
442
+ subject.valid?(context_type)
443
+ subject.errors.messages[:customer].should include("can't be blank")
444
+ end
445
+
446
+ it "should not allow invalid customer" do
447
+ subject.customer = Braspag::Customer.new
448
+ subject.valid?(context_type)
449
+ subject.errors.messages[:customer].should include("invalid data")
450
+ end
451
+
452
+ it "should accept only valid payment method" do
453
+ subject.payment_method = 0
454
+ subject.valid?(context_type)
455
+ subject.errors.messages[:payment_method].should include("invalid payment code")
456
+ end
457
+ end
458
+ end
459
+
460
+ [:purchase, :authorize, :recurrency].each do |context_type|
461
+ context "on #{context_type}" do
462
+ it "should not allow blank for installments" do
463
+ subject.installments = ''
464
+ subject.valid?(context_type)
465
+ subject.errors.messages[:installments].should include("can't be blank")
466
+ end
467
+
468
+ it "should validate minimum 1 of installments" do
469
+ subject.installments = 0
470
+ subject.valid?(context_type)
471
+ subject.errors.messages[:installments].should include("must be greater than 0")
472
+ end
473
+
474
+
475
+ it "should validate maxium 99 of installments" do
476
+ subject.installments = 100
477
+ subject.valid?(context_type)
478
+ subject.errors.messages[:installments].should include("must be less than 100")
479
+ end
480
+
481
+ it "should not allow blank for installments_type" do
482
+ subject.installments_type = ''
483
+ subject.valid?(context_type)
484
+ subject.errors.messages[:installments_type].should include("can't be blank")
485
+ end
486
+
487
+ it "should accept only valid installments_type" do
488
+ subject.installments_type = 100
489
+ subject.valid?(context_type)
490
+ subject.errors.messages[:installments_type].should include("invalid installments type")
491
+ end
492
+
493
+
494
+ context "when installments_type is NO_INTEREST" do
495
+ it "should installments is one" do
496
+ subject.installments_type = Braspag::INTEREST[:no]
497
+ subject.installments = 3
498
+ subject.valid?(context_type)
499
+ subject.errors.messages[:installments].should include("is invalid")
500
+ end
501
+ end
502
+ end
503
+ end
504
+ end