Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing the checkout form generator to HAML Engine.
Changing the Integration class, extracting the to_weight and to_money methods and implementing them in other class: Util, in Pagseguro Module. This approuch looks better than join all in Integration class.
- Loading branch information
Bruno Azisaka Maciel
committed
Nov 9, 2008
1 parent
7d4f675
commit 6c0329f
Showing
5 changed files
with
119 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Util | ||
Object.class_eval do | ||
#TODO Traduzir para ingles............ | ||
# Formata o campo de decimal para String no padrao solicitado do PagSeguro | ||
# Ex.: | ||
# integracao.to_peso "0.5" ==> 500 #500 gramas | ||
# integracao.to_peso "0.50 ==> 500 #500 gramas | ||
# integracao.to_peso "0.05" ==> 050 #50 gramas | ||
# integracao.to_peso "0.005" ==> 005 #5 gramas | ||
# integracao.to_peso "1" ==> 1000 #1 kilo | ||
# integracao.to_peso "1.0" ==> 1000 #1 kilo | ||
# | ||
def to_ps_weight | ||
return nil if self.nil? | ||
return nil if self.class != String | ||
return "000" if self.to_f == 0 | ||
|
||
# obtem a parte fracionaria e transforma em string. | ||
frac = self.to_f - self.to_i | ||
frac = frac.to_s + "00" | ||
frac = frac[2..4] | ||
inteiro = "" | ||
inteiro = self.to_i.to_s if (self.to_f.truncate > 0) | ||
novo_valor = inteiro + frac.to_s | ||
end | ||
|
||
|
||
# TODO traduzir para ingles................ | ||
# Formata o campo de decimal para String no padrao solicitado do PagSeguro | ||
# Ex.: | ||
# integracao.to_dinheiro "0.5" ==> 50 #50 centavos | ||
# integracao.to_dinheiro "0.50 ==> 50 #50 centavos | ||
# integracao.to_dinheiro "0.05" ==> 05 #5 centavos | ||
# integracao.to_dinheiro "1" ==> 100 #1 real | ||
# integracao.to_dinheiro "1.0" ==> 100 #1 real | ||
# | ||
def to_ps_money | ||
return nil if self.nil? | ||
return nil if self.class != String | ||
return "00" if self.to_f == 0 | ||
|
||
# obtem a parte fracionaria e transforma em string. | ||
frac = self.to_f - self.to_i | ||
frac = frac.to_s + "0" | ||
frac = frac[2..3] | ||
# Se tiver parte inteira, concatena com a parte fracionaria | ||
inteiro = "" | ||
inteiro = self.to_i.to_s if self.to_f.truncate > 0 | ||
inteiro + frac | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
%form{ :action=>config['webpagto'], :method=>"post", :name=>"payment_form" } | ||
%input{ :type=>"hidden", :name=>"ref_transacao", :value=>sale.code} | ||
%input{ :type=>"hidden", :name=>"email_cobranca", :value=>config['email_cobranca'] } | ||
%input{ :type=>"hidden", :name=>"tipo", :value=>config['tipo_carrinho'] } | ||
%input{ :type=>"hidden", :name=>"moeda", :value=>config['moeda'] } | ||
%input{ :type=>"hidden", :name=>"cliente_pais", :value=>config['pais'] } | ||
%input{ :type=>"hidden", :name=>"cliente_nome", :value=>sale.buyer.name } | ||
%input{ :type=>"hidden", :name=>"cliente_cep", :value=>sale.buyer.zip } | ||
%input{ :type=>"hidden", :name=>"cliente_end", :value=>sale.buyer.address } | ||
%input{ :type=>"hidden", :name=>"cliente_num", :value=>sale.buyer.number } | ||
%input{ :type=>"hidden", :name=>"cliente_compl", :value=>sale.buyer.complement } | ||
%input{ :type=>"hidden", :name=>"cliente_bairro", :value=>sale.buyer.district } | ||
%input{ :type=>"hidden", :name=>"cliente_cidade", :value=>sale.buyer.city } | ||
%input{ :type=>"hidden", :name=>"cliente_uf", :value=>sale.buyer.state } | ||
%input{ :type=>"hidden", :name=>"cliente_ddd", :value=>sale.buyer.ext } | ||
%input{ :type=>"hidden", :name=>"cliente_tel", :value=>sale.buyer.phone } | ||
%input{ :type=>"hidden", :name=>"cliente_email", :value=>sale.buyer.email } | ||
|
||
- if frete.empty? | ||
- unless sale.shipment_type.nil? | ||
%input{ :type=>"hidden", :name=>"tipo_frete", :value=>sale.shipment_type} | ||
- else | ||
%input{ :type=>"hidden", :name=>"item_frete_1", :value=>frete.first } | ||
|
||
- sale.itens.values.each_with_index do |item, i| | ||
%input{ :type=>"hidden", :name=>"item_id_#{i+1}", :value=>item.code } | ||
%input{ :type=>"hidden", :name=>"item_descr_#{i+1}", :value=>item.description } | ||
%input{ :type=>"hidden", :name=>"item_quant_#{i+1}", :value=>item.quantity } | ||
%input{ :type=>"hidden", :name=>"item_valor_#{i+1}", :value=>item.price.to_ps_money } | ||
%input{ :type=>"hidden", :name=>"item_peso_#{i+1}", :value=>item.weight.to_ps_weight } | ||
|
||
%input{ :type=>"submit" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters