pagseguro 0.1.7.beta.0 → 0.1.7.beta.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagseguro (0.1.7.beta.0)
4
+ pagseguro (0.1.7.beta.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -50,6 +50,20 @@ module PagSeguro
50
50
  config? && config["developer"] == true
51
51
  end
52
52
 
53
+ # Detect if current encoding is UTF-8
54
+ def utf8?
55
+ encoding == "UTF-8"
56
+ end
57
+
58
+ # Set encoding based on running environment.
59
+ def encoding
60
+ if developer?
61
+ "UTF-8"
62
+ else
63
+ "ISO-8859-1"
64
+ end
65
+ end
66
+
53
67
  class MissingEnvironmentError < StandardError; end
54
68
  class MissingConfigurationError < StandardError; end
55
69
  end
@@ -39,7 +39,7 @@ module PagSeguro
39
39
  # Expects the params object from the current request
40
40
  def initialize(params, token = nil)
41
41
  @token = token
42
- @params = normalize(params)
42
+ @params = PagSeguro.utf8? ? params : normalize(params)
43
43
  end
44
44
 
45
45
  # Normalize the specified hash converting all data to UTF-8
@@ -2,6 +2,14 @@ module PagSeguro
2
2
  module Utils
3
3
  extend self
4
4
 
5
+ def encode(string)
6
+ if PagSeguro.utf8?
7
+ string
8
+ else
9
+ to_iso8859(string)
10
+ end
11
+ end
12
+
5
13
  def to_utf8(string)
6
14
  string.to_s.unpack('C*').pack('U*')
7
15
  end
@@ -3,6 +3,6 @@ module PagSeguro
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  PATCH = 7
6
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.beta.0"
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.beta.1"
7
7
  end
8
8
  end
@@ -1,4 +1,4 @@
1
- <form accept-charset="ISO-8859-1" action="<%= PagSeguro.gateway_url %>" class="pagseguro" method="post">
1
+ <form accept-charset="<%= PagSeguro.encoding %>" action="<%= PagSeguro.gateway_url %>" class="pagseguro" method="post">
2
2
  <div>
3
3
  <%= hidden_field_tag "email_cobranca", options.fetch(:email, PagSeguro.config["email"]) %>
4
4
  <%= hidden_field_tag "tipo", "CP" %>
@@ -10,14 +10,14 @@
10
10
  <% i += 1 %>
11
11
  <%= hidden_field_tag "item_quant_#{i}", product[:quantity] %>
12
12
  <%= hidden_field_tag "item_id_#{i}", product[:id] %>
13
- <%= hidden_field_tag "item_descr_#{i}", PagSeguro::Utils.to_iso8859(product[:description]) %>
13
+ <%= hidden_field_tag "item_descr_#{i}", PagSeguro::Utils.encode(product[:description]) %>
14
14
  <%= hidden_field_tag "item_valor_#{i}", product[:price] %>
15
15
  <%= hidden_field_tag "item_peso_#{i}", product[:weight].to_i if product[:weight] %>
16
16
  <%= hidden_field_tag "item_frete_#{i}", product[:shipping].to_i if product[:shipping] %>
17
17
  <% end %>
18
18
 
19
19
  <% order.billing.each do |name, value| %>
20
- <%= hidden_field_tag PagSeguro::Order::BILLING_MAPPING[name.to_sym], PagSeguro::Utils.to_iso8859(value) %>
20
+ <%= hidden_field_tag PagSeguro::Order::BILLING_MAPPING[name.to_sym], PagSeguro::Utils.encode(value) %>
21
21
  <% end %>
22
22
 
23
23
  <%= submit_tag options[:submit] %>
@@ -23,6 +23,14 @@ describe PagSeguro::Helper do
23
23
  it { should have_input(:type => "submit", :value => "Pagar com PagSeguro") }
24
24
  end
25
25
 
26
+ context "when running development mode" do
27
+ before do
28
+ PagSeguro.stub :developer? => true
29
+ end
30
+
31
+ it { should have_attr("accept-charset", "UTF-8") }
32
+ end
33
+
26
34
  it "should include shipping type" do
27
35
  @order.shipping_type = "SD"
28
36
  subject.should have_input(:name => "tipo_frete", :value => "SD")
@@ -11,6 +11,16 @@ describe PagSeguro do
11
11
  module PagSeguro; @@config = nil; end
12
12
  end
13
13
 
14
+ it "should set encoding as UTF-8 when running in development mode" do
15
+ PagSeguro.stub :developer? => true
16
+ PagSeguro.encoding.should == "UTF-8"
17
+ end
18
+
19
+ it "should set encoding as ISO-8859-1 when running in production mode" do
20
+ PagSeguro.stub :developer? => false
21
+ PagSeguro.encoding.should == "ISO-8859-1"
22
+ end
23
+
14
24
  it "should raise error if configuration is not found" do
15
25
  File.should_receive(:exist?).with(@config_file).and_return(false)
16
26
  expect { PagSeguro.config }.to raise_error(PagSeguro::MissingConfigurationError)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pagseguro
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.1.7.beta.0
5
+ version: 0.1.7.beta.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nando Vieira
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-03 00:00:00 -03:00
13
+ date: 2011-03-04 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency