-
-
Save diegorv/260102 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module PagseguroHelper | |
def pagseguro_form(order) | |
content_tag(:form, :id => "pagseguro", :target => 'pagseguro', :method => 'post', :action => 'https://pagseguro.uol.com.br/security/webpagamentos/webpagto.aspx') do | |
result = "" | |
result << hidden_field_tag(:email_cobranca, '[email protected]') | |
result << hidden_field_tag(:tipo, 'CP') # Chumbado | |
result << hidden_field_tag(:moeda, 'BRL') # Chumbado | |
result << hidden_field_tag(:ref_transacao, order.id) | |
result << hidden_field_tag(:encoding, 'utf-8') | |
result << hidden_field_tag(:tipo_frete, 'SD') # Sedex - pro pagseguro calcular o frete automagicamente | |
order.product_orders.each_with_index do |product_order, i| | |
i += 1 | |
result << hidden_field_tag(:"item_id_#{i}", product_order.id) | |
result << hidden_field_tag(:"item_descr_#{i}", "descr do item") | |
price = (product_order.price * 100).to_i # O pag seguro quer 10000 pra R$100,00 | |
result << hidden_field_tag(:"item_valor_#{i}", price.to_s) | |
result << hidden_field_tag(:"item_quant_#{i}", product_order.quantity) | |
result << hidden_field_tag(:"item_peso_#{i}", product_order.product_weight) | |
end | |
result << create_cliente_fields({ | |
:cliente_nome => current_user.full_name, | |
:cliente_cep => current_user.zipcode.gsub('-', ''), | |
:cliente_num => "", | |
:cliente_compl => current_user.address_complement, | |
:cliente_bairro => current_user.address_neighborhood, | |
:cliente_cidade => current_user.city, | |
:cliente_uf => current_user.state, | |
:cliente_pais => "BRA", | |
:cliente_ddd => "", | |
:cliente_telefone => "", | |
:cliente_email => current_user.email | |
}) | |
result << image_submit_tag('https://pagseguro.uol.com.br/Security/Imagens/btnfinalizaBR.jpg', :alt => 'Pague com PagSeguro - é rápido, grátis e seguro!') | |
result | |
end | |
end | |
private | |
def create_cliente_fields(tuples) | |
result = "" | |
for key, data in tuples | |
result << hidden_field_tag(key, data) | |
end | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment