pagseguro 0.1.6 → 0.1.7.beta.0

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagseguro (0.1.6)
4
+ pagseguro (0.1.7.beta.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.markdown CHANGED
@@ -84,6 +84,23 @@ Se você precisar, pode definir o tipo de frete com o método `shipping_type`.
84
84
  @order.shipping_type = "EN" # PAC
85
85
  @order.shipping_type = "FR" # Frete Próprio
86
86
 
87
+ Se você precisar, pode definir os dados de cobrança com o método `billing`.
88
+
89
+ @order.billing = {
90
+ :name => "John Doe",
91
+ :email => "john@doe.com",
92
+ :address_zipcode => "01234-567",
93
+ :address_street => "Rua Orobó",
94
+ :address_number => 72,
95
+ :address_complement => "Casa do fundo",
96
+ :address_neighbourhood => "Tenório",
97
+ :address_city => "Pantano Grande",
98
+ :address_state => "AC",
99
+ :address_country => "Brasil",
100
+ :phone_area_code => "22",
101
+ :phone_number => "1234-5678"
102
+ }
103
+
87
104
  Depois que você definiu os produtos do pedido, você pode exibir o formulário.
88
105
 
89
106
  <!-- app/views/cart/checkout.html.erb -->
data/lib/pagseguro.rb CHANGED
@@ -11,3 +11,4 @@ require "pagseguro/notification"
11
11
  require "pagseguro/order"
12
12
  require "pagseguro/action_controller"
13
13
  require "pagseguro/helper"
14
+ require "pagseguro/utils"
@@ -45,14 +45,14 @@ module PagSeguro
45
45
  # Normalize the specified hash converting all data to UTF-8
46
46
  def normalize(hash)
47
47
  each_value(hash) do |value|
48
- value.to_s.unpack('C*').pack('U*')
48
+ Utils.to_utf8(value)
49
49
  end
50
50
  end
51
51
 
52
52
  # Denormalize the specified hash converting all data to ISO-8859-1
53
53
  def denormalize(hash)
54
54
  each_value(hash) do |value|
55
- value.to_s.unpack('U*').pack('C*')
55
+ Utils.to_iso8859(value)
56
56
  end
57
57
  end
58
58
 
@@ -1,8 +1,27 @@
1
1
  module PagSeguro
2
2
  class Order
3
+ # Map all billing attributes that will be added as form inputs.
4
+ BILLING_MAPPING = {
5
+ :name => "cliente_nome",
6
+ :address_zipcode => "cliente_cep",
7
+ :address_street => "cliente_end",
8
+ :address_number => "cliente_num",
9
+ :address_complement => "cliente_compl",
10
+ :address_neighbourhood => "cliente_bairro",
11
+ :address_city => "cliente_cidade",
12
+ :address_state => "cliente_uf",
13
+ :address_country => "cliente_pais",
14
+ :phone_area_code => "cliente_ddd",
15
+ :phone_number => "cliente_tel",
16
+ :email => "cliente_email"
17
+ }
18
+
3
19
  # The list of products added to the order
4
20
  attr_accessor :products
5
21
 
22
+ # The billing info that will be sent to PagSeguro.
23
+ attr_accessor :billing
24
+
6
25
  # Define the shipping type.
7
26
  # Can be EN (PAC) or SD (Sedex)
8
27
  attr_accessor :shipping_type
@@ -10,6 +29,7 @@ module PagSeguro
10
29
  def initialize(order_id = nil)
11
30
  reset!
12
31
  self.id = order_id
32
+ self.billing = {}
13
33
  end
14
34
 
15
35
  # Set the order identifier. Should be a unique
@@ -0,0 +1,13 @@
1
+ module PagSeguro
2
+ module Utils
3
+ extend self
4
+
5
+ def to_utf8(string)
6
+ string.to_s.unpack('C*').pack('U*')
7
+ end
8
+
9
+ def to_iso8859(string)
10
+ string.to_s.unpack('U*').pack('C*')
11
+ end
12
+ end
13
+ end
@@ -2,7 +2,7 @@ module PagSeguro
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 6
6
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
5
+ PATCH = 7
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.beta.0"
7
7
  end
8
8
  end
@@ -1,6 +1,6 @@
1
- <form accept-charset="ISO-8859-1" action="<%= PagSeguro.gateway_url %>" id="pagseguro" class="pagseguro" method="post">
1
+ <form accept-charset="ISO-8859-1" action="<%= PagSeguro.gateway_url %>" class="pagseguro" method="post">
2
2
  <div>
3
- <%= hidden_field_tag "email_cobranca", options[:email] || PagSeguro.config["email"] %>
3
+ <%= hidden_field_tag "email_cobranca", options.fetch(:email, PagSeguro.config["email"]) %>
4
4
  <%= hidden_field_tag "tipo", "CP" %>
5
5
  <%= hidden_field_tag "moeda", "BRL" %>
6
6
  <%= hidden_field_tag "ref_transacao", order.id %>
@@ -10,12 +10,16 @@
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}", product[:description] %>
13
+ <%= hidden_field_tag "item_descr_#{i}", PagSeguro::Utils.to_iso8859(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
+ <% order.billing.each do |name, value| %>
20
+ <%= hidden_field_tag PagSeguro::Order::BILLING_MAPPING[name.to_sym], PagSeguro::Utils.to_iso8859(value) %>
21
+ <% end %>
22
+
19
23
  <%= submit_tag options[:submit] %>
20
24
  </div>
21
25
  </form>
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # -*- encoding: utf-8 -*-
2
2
  require "spec_helper"
3
3
 
4
4
  describe PagSeguro::Helper do
@@ -14,7 +14,6 @@ describe PagSeguro::Helper do
14
14
  context "with default attributes" do
15
15
  it { should have_attr("accept-charset", "ISO-8859-1") }
16
16
  it { should have_attr("action", PagSeguro::GATEWAY_URL) }
17
- it { should have_attr("id", "pagseguro") }
18
17
  it { should have_attr("class", "pagseguro") }
19
18
  it { should have_input(:name => "tipo", :value => "CP") }
20
19
  it { should have_input(:name => "moeda", :value => "BRL") }
@@ -77,4 +76,36 @@ describe PagSeguro::Helper do
77
76
  it { should have_input(:name => "item_valor_2", :value => "1900") }
78
77
  it { should have_input(:name => "item_descr_2", :value => "Rails 3 e-Book + Screencast") }
79
78
  end
79
+
80
+ context "with billing info" do
81
+ before do
82
+ @order.billing = {
83
+ :name => "John Doe",
84
+ :email => "john@doe.com",
85
+ :address_zipcode => "01234-567",
86
+ :address_street => "Rua Orobó",
87
+ :address_number => 72,
88
+ :address_complement => "Casa do fundo",
89
+ :address_neighbourhood => "Tenório",
90
+ :address_city => "Pantano Grande",
91
+ :address_state => "AC",
92
+ :address_country => "Brasil",
93
+ :phone_area_code => "22",
94
+ :phone_number => "1234-5678"
95
+ }
96
+ end
97
+
98
+ it { should have_input(:name => "cliente_nome", :value => "John Doe") }
99
+ it { should have_input(:name => "cliente_email", :value => "john@doe.com") }
100
+ it { should have_input(:name => "cliente_cep", :value => "01234-567") }
101
+ it { should have_input(:name => "cliente_end", :value => "Rua Orobó") }
102
+ it { should have_input(:name => "cliente_num", :value => "72") }
103
+ it { should have_input(:name => "cliente_compl", :value => "Casa do fundo") }
104
+ it { should have_input(:name => "cliente_bairro", :value => "Tenório") }
105
+ it { should have_input(:name => "cliente_cidade", :value => "Pantano Grande") }
106
+ it { should have_input(:name => "cliente_uf", :value => "AC") }
107
+ it { should have_input(:name => "cliente_pais", :value => "Brasil") }
108
+ it { should have_input(:name => "cliente_ddd", :value => "22") }
109
+ it { should have_input(:name => "cliente_tel", :value => "1234-5678") }
110
+ end
80
111
  end
@@ -83,4 +83,12 @@ describe PagSeguro::Order do
83
83
  @order << @product.merge(:weight => 1.3)
84
84
  @order.products.first[:weight].should == 1300
85
85
  end
86
+
87
+ it "should respond to billing attribute" do
88
+ @order.should respond_to(:billing)
89
+ end
90
+
91
+ it "should initialize billing attribute" do
92
+ @order.billing.should be_instance_of(Hash)
93
+ end
86
94
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.6
4
+ prerelease: 6
5
+ version: 0.1.7.beta.0
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-02-28 00:00:00 -03:00
13
+ date: 2011-03-03 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -108,6 +108,7 @@ files:
108
108
  - lib/pagseguro/railtie.rb
109
109
  - lib/pagseguro/rake.rb
110
110
  - lib/pagseguro/routes.rb
111
+ - lib/pagseguro/utils.rb
111
112
  - lib/pagseguro/version.rb
112
113
  - lib/pagseguro/views/_form.html.erb
113
114
  - lib/tasks/pagseguro.rake
@@ -153,13 +154,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
154
  required_rubygems_version: !ruby/object:Gem::Requirement
154
155
  none: false
155
156
  requirements:
156
- - - ">="
157
+ - - ">"
157
158
  - !ruby/object:Gem::Version
158
- version: "0"
159
+ version: 1.3.1
159
160
  requirements: []
160
161
 
161
162
  rubyforge_project:
162
- rubygems_version: 1.5.2
163
+ rubygems_version: 1.6.0
163
164
  signing_key:
164
165
  specification_version: 3
165
166
  summary: The official PagSeguro library