From 712635106a8029483327062ee95743c47e9398b4 Mon Sep 17 00:00:00 2001 From: "Gun.io Whitespace Robot" Date: Fri, 16 Dec 2011 17:30:35 -0500 Subject: [PATCH] Remove whitespace [Gun.io WhitespaceBot] --- README.markdown | 14 +- Rakefile | 2 +- correios/lib/config/correios.yml | 6 +- correios/lib/correios/correios.rb | 34 +-- correios/test/correios_test.rb | 36 +-- correios/test/correios_test.yml | 2 +- general/lib/general/item.rb | 8 +- general/lib/general/sale.rb | 8 +- general/test/item_test.rb | 20 +- general/test/sales_test.rb | 80 +++--- install.rb | 8 +- install/breshop.yml | 2 +- .../controllers/autoret_controller.rb | 24 +- .../pagseguro/test/fixtures/psproducts.yml | 10 +- .../test/fixtures/pstransactions.yml | 14 +- .../functional/autoret_controller_test.rb | 250 +++++++++--------- install/pagseguro/views/autoret/show.html.erb | 18 +- pagseguro/lib/pagseguro/integration.rb | 22 +- pagseguro/lib/pagseguro/util.rb | 10 +- pagseguro/lib/pagseguro/views/form.html.haml | 2 +- pagseguro/test/pagseguro_test.rb | 114 ++++---- 21 files changed, 342 insertions(+), 342 deletions(-) diff --git a/README.markdown b/README.markdown index b8f826d..911fd05 100644 --- a/README.markdown +++ b/README.markdown @@ -22,7 +22,7 @@ To use brEshop plugin you have to have HAML installed: $ gem install --no-ri haml -And to install brEshop as plugin type: +And to install brEshop as plugin type: ruby script/plugin install git://github.com/mangar/breshop.git @@ -39,18 +39,18 @@ And to install brEshop as plugin type: :quantity=>1, :price=>11.50, :weight=>0.100}) - + @item_2 = Item.new({:code=>"2", :description=>"producto02", :quantity=>2, :price=>22.30, - :weight=>0.200}) - + :weight=>0.200}) + #cria o carrinho de compras e insere os itens.. sale = Sale.new sale << @item_1 sale << @item_2 - + #registra os dados do comprador.... e as ultimas opos de entrega... sale.buyer = Buyer.new sale.buyer.name = request.parameters['name'] + " " + request.parameters['last_name'] @@ -67,7 +67,7 @@ And to install brEshop as plugin type: sale.buyer.phone = request.parameters['phone1'][4..12] sale.buyer.phone = sale.buyer.phone.gsub('-', '') sale.shipment_type = sale.shipment_type - + pagseguro = Integration.new @content = pagseguro.checkout(sale) @@ -98,7 +98,7 @@ More info about Automatic Return service can be found in PagSeguro website, in f ## Help -Do you wanna to help? Do you have any new idea? Contact us! Make a fork! +Do you wanna to help? Do you have any new idea? Contact us! Make a fork! Enjoy! diff --git a/Rakefile b/Rakefile index 2e31066..095c182 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ -task :test do +task :test do require 'rake/runtest' Rake.run_tests '**/*test.rb' end diff --git a/correios/lib/config/correios.yml b/correios/lib/config/correios.yml index 0aa1c13..9cfb0d7 100644 --- a/correios/lib/config/correios.yml +++ b/correios/lib/config/correios.yml @@ -17,12 +17,12 @@ aviso_recebimento: N mao_propria: N # -# Default service (servico_padrao). Correios has two types of delivery service: +# Default service (servico_padrao). Correios has two types of delivery service: # 1 - SEDEX : faster but not so sheap # 2 - PAC : not so fast but sheap -# +# # The codes are: -# +# # 41106 = PAC # ????? = SEDEX # diff --git a/correios/lib/correios/correios.rb b/correios/lib/correios/correios.rb index 2695697..50c3ca7 100644 --- a/correios/lib/correios/correios.rb +++ b/correios/lib/correios/correios.rb @@ -9,7 +9,7 @@ class Correios # if no one is specified, will be used the default: /../config/correios.yml # def initialize(pars = {}) - + @config = (pars[:config].nil? ? YAML.load_file(File.dirname(__FILE__) + "/../config/correios.yml") : pars[:config]) @params_config = {:resposta => "xml"} @@ -18,15 +18,15 @@ def initialize(pars = {}) @params_config.merge!({:servico => "#{@config['servico_padrao']}"}) @params_config.merge!({:cepOrigem => "#{@config['cep_origem']}"}) - @uri = URI.parse(@config['url']) + @uri = URI.parse(@config['url']) end - - - - + + + + # # Calculates the freight based on brazilian delivery company called: Correios (www.correios.com.br) - # + # # Ex.: # correios = Correios.new # freight = correios.freight "14055-490", "0.300", "1500.00" ==> freight price @@ -37,31 +37,31 @@ def initialize(pars = {}) # freight = correios.freight "14055-490", "0.300", "1500.00", {:servico => "Correios.SEDEX", :cepOrigem => "04515-030"} ==> freight price # def freight (zip_destination, weight, price, pars = {}) - + raise "Invalid Destination Zip Code (#{zip_destination})" if (zip_destination.nil? || zip_destination.empty?) raise "Invalid Weight (#{weight})" if (weight.nil? || weight.empty?) raise "Invalid Price (#{price})" if (price.nil? || price.empty?) - + #replace some parameters..... - @params_config.merge!({:servico => pars[:servico]}) if pars.has_key?(:servico) - @params_config.merge!({:cepOrigem => pars[:cep_origem]}) if pars.has_key?(:cep_origem) + @params_config.merge!({:servico => pars[:servico]}) if pars.has_key?(:servico) + @params_config.merge!({:cepOrigem => pars[:cep_origem]}) if pars.has_key?(:cep_origem) #insert some new ones..... @params_config.merge!({:cepDestino => zip_destination}) @params_config.merge!({:peso => weight}) - @params_config.merge!({:valorDeclarado => price}) + @params_config.merge!({:valorDeclarado => price}) #sending requesto to Correios.... url_pars = "" @params_config.each do |k,v| url_pars += "&#{k}=#{v}" end - + response = Net::HTTP.get_response(URI.parse("#{@config['url']}#{url_pars}")) raise "Problem to get response. (#{response.code} - #{response.message})" unless response.kind_of?(Net::HTTPSuccess) - + doc = REXML::Document.new(response.body) # puts "#{doc}" - + freight = "" %w(descricao preco_postal).each do |elm| element = REXML::XPath.match(doc, "//#{elm}").first @@ -69,7 +69,7 @@ def freight (zip_destination, weight, price, pars = {}) freight = element.text if (elm.eql? 'preco_postal') end - return freight + return freight end - + end \ No newline at end of file diff --git a/correios/test/correios_test.rb b/correios/test/correios_test.rb index f589b79..c48e261 100644 --- a/correios/test/correios_test.rb +++ b/correios/test/correios_test.rb @@ -4,41 +4,41 @@ require File.dirname(__FILE__) + '/../lib/correios' class CorreiosTest < Test::Unit::TestCase - - - + + + def setup - + @config = YAML.load_file(File.dirname(__FILE__) + '/correios_test.yml') end - - - + + + def test_shipment_calculate - + correios = Correios.new({:config => @config}) - + #zip_destination, weight and total proce can not be nil... assert_raise RuntimeError do correios.freight nil, nil, nil; end - + #...neighter blank! assert_raise RuntimeError do correios.freight "", "", ""; end - + assert_equal('22.3', correios.freight("14055-490", "0.300", "1560.00"), "Check the freight price, may be it can be changed.") - + # Invalid service code! assert_raise RuntimeError do correios.freight("14055-490", "0.300", "1560.00", {:servico => "aaaa"}); end - + # Invalid Origin ZipCode assert_raise RuntimeError do correios.freight("14055-490", "0.300", "1560.00", {:cep_origem => ""}); end correios = Correios.new({:config => @config}) assert_equal('22.3', correios.freight("14055-490", "0.300", "1560.00", {:servico => "41106", :cep_origem => "04515-030"}), "Check the freight price, may be it can be changed.") - + end - - - - + + + + end \ No newline at end of file diff --git a/correios/test/correios_test.yml b/correios/test/correios_test.yml index db256f9..8a76e3a 100644 --- a/correios/test/correios_test.yml +++ b/correios/test/correios_test.yml @@ -13,6 +13,6 @@ url: http://www.correios.com.br/encomendas/precos/calculo.cfm? aviso_recebimento: N mao_propria: N -#41106 = PAC / +#41106 = PAC / servico_padrao: 41106 cep_origem: 04515-030 \ No newline at end of file diff --git a/general/lib/general/item.rb b/general/lib/general/item.rb index c964f7e..70025d1 100644 --- a/general/lib/general/item.rb +++ b/general/lib/general/item.rb @@ -1,6 +1,6 @@ class Item attr_accessor :code, :description, :quantity, :price, :weight - + def initialize(item = {}) @code = item[:code] @description = item[:description] @@ -8,13 +8,13 @@ def initialize(item = {}) @price = item[:price] @weight = item[:weight] end - + def price_total @quantity * @price end - + def weight_total @quantity * @weight end - + end \ No newline at end of file diff --git a/general/lib/general/sale.rb b/general/lib/general/sale.rb index 4a21a8e..ce383c7 100644 --- a/general/lib/general/sale.rb +++ b/general/lib/general/sale.rb @@ -20,19 +20,19 @@ def initialize(params = {}) # # Ex.: # sale << item - def <<(item) + def <<(item) return if (item.nil?) raise InvalidItem unless item.class.eql? Item #item is in sale.... if (@itens.has_key?(item.code)) - + #quantity eq zero, remove... @itens.delete item.code if (item.quantity == 0) #change the quantity @itens[item.code].quantity = item.quantity if (item.quantity > 0) - + else @itens[item.code] = item end @@ -47,7 +47,7 @@ def price price += (@shipment.nil? ? 0 : @shipment) price end - + # Returns the total weight of the all product in the sale def weight weight = 0 diff --git a/general/test/item_test.rb b/general/test/item_test.rb index e2a92be..2354489 100644 --- a/general/test/item_test.rb +++ b/general/test/item_test.rb @@ -2,22 +2,22 @@ require File.dirname(__FILE__) + '/../lib/general' class ItemTest < Test::Unit::TestCase - + def setup - @item_1 = Item.new({:code=>1, - :description=>"Primeiro Item", - :price=>100.0, - :quantity=>2, + @item_1 = Item.new({:code=>1, + :description=>"Primeiro Item", + :price=>100.0, + :quantity=>2, :weight=>10}) end - - def test_obtendo_peso_total + + def test_obtendo_peso_total assert_equal(10, @item_1.weight) end - + def test_obtendo_preco_total assert_equal(100, @item_1.price) end - - + + end diff --git a/general/test/sales_test.rb b/general/test/sales_test.rb index e18e6fb..8f4ad6e 100644 --- a/general/test/sales_test.rb +++ b/general/test/sales_test.rb @@ -3,87 +3,87 @@ class SalesTest < Test::Unit::TestCase def setup - @item_1 = Item.new({:code=>"1", - :description=>"Primeiro Item", - :price=>10.0, - :quantity=>1, + @item_1 = Item.new({:code=>"1", + :description=>"Primeiro Item", + :price=>10.0, + :quantity=>1, :weight=>1.000}) - - @item_2 = Item.new({:code=>"2", - :description=>"Segundo Item", - :price=>20.0, - :quantity=>2, - :weight=>2.000}) - - @item_3 = Item.new({:code=>"3", - :description=>"Terceiro Item", - :price=>3.99, - :quantity=>1, + + @item_2 = Item.new({:code=>"2", + :description=>"Segundo Item", + :price=>20.0, + :quantity=>2, + :weight=>2.000}) + + @item_3 = Item.new({:code=>"3", + :description=>"Terceiro Item", + :price=>3.99, + :quantity=>1, :weight=>0.100}) end - - + + def test_adiciona_item @sale = Sale.new - + assert_equal(0, @sale.itens.size, "Tamanho de itens deve ser igual a zero (1)") @sale << nil assert_equal(0, @sale.itens.size, "Tamanho de itens deve ser igual a zero (2)") - + @sale << @item_1 assert_equal(1, @sale.itens.size, "Tamanho de itens deve ser um (3)") - + item = @sale.itens["1"] assert_equal(1, item.quantity, "Quantidade deve ser 1 (4)") @item_1.quantity = 2 @sale << @item_1 item = @sale.itens["1"] - assert_equal(1, @sale.itens.size, "Tamanho de itens deve ser um (5)") + assert_equal(1, @sale.itens.size, "Tamanho de itens deve ser um (5)") assert_equal(2, item.quantity, "Quantidade deve ser 2 (6)") @item_1.quantity = 0 @sale << @item_1 item = @sale.itens["1"] - assert_equal(0, @sale.itens.size, "Tamanho de itens deve ser zero (7)") - + assert_equal(0, @sale.itens.size, "Tamanho de itens deve ser zero (7)") + @sale << @item_2 - assert_equal(1, @sale.itens.size, "Tamanho de itens deve ser um (8)") - + assert_equal(1, @sale.itens.size, "Tamanho de itens deve ser um (8)") + item = @sale.itens["2"] - assert_equal(2, item.quantity, "Quantidade deve ser 2 (9)") - + assert_equal(2, item.quantity, "Quantidade deve ser 2 (9)") + @item_1.quantity = 1 @sale << @item_1 - assert_equal(2, @sale.itens.size, "Tamanho de itens deve ser um (10)") + assert_equal(2, @sale.itens.size, "Tamanho de itens deve ser um (10)") item = @sale.itens["1"] assert_equal(1, item.quantity, "Quantidade deve ser 1 (11)") item = @sale.itens["2"] - assert_equal(2, item.quantity, "Quantidade deve ser 2 (12)") - - + assert_equal(2, item.quantity, "Quantidade deve ser 2 (12)") + + puts "P1.code: #{@sale.code}" p2 = Sale.new({:code => '123'}) puts "P2.code: #{p2.code}" - + end - - + + def test_pricetotal @sale = Sale.new - + assert_equal(0, @sale.price, "Valor do sale deve ser zero (1)") - + @sale << @item_1 assert_equal(10.0, @sale.price, "Valor do sale deve ser 10.0 (2)") assert_equal(1.000, @sale.weight, "Peso do sale deve ser 1.000 (3)") @item_1.quantity = 2 - @sale << @item_1 + @sale << @item_1 assert_equal(20.0, @sale.price, "Valor do sale deve ser 20.0 (4)") assert_equal(2.000, @sale.weight, "Peso do sale deve ser 2.000 (5)") @@ -94,8 +94,8 @@ def test_pricetotal @sale.shipment = 10.55 assert_equal(70.55, @sale.price, "Valor do sale deve ser 70.55 (60 de mercadoria + 10.55 de shipment) (8)") assert_equal(6.000, @sale.weight, "Peso do sale deve ser 6.000 (9)") - - + + @sale = Sale.new @sale << @item_3 assert_equal(3.99, @sale.price, "Valor do sale deve ser 3.99 (10)") @@ -107,5 +107,5 @@ def test_pricetotal assert_equal(0.200, @sale.weight, "Peso do sale deve ser 0.200 (13)") end - + end \ No newline at end of file diff --git a/install.rb b/install.rb index c8205b9..d02a29b 100644 --- a/install.rb +++ b/install.rb @@ -1,9 +1,9 @@ require 'fileutils' -puts "--------------------------------------------------------------------------------" -puts " Welcome to brEshop plugin" -puts "--------------------------------------------------------------------------------" - +puts "--------------------------------------------------------------------------------" +puts " Welcome to brEshop plugin" +puts "--------------------------------------------------------------------------------" + puts "Copying 'breshop.yml'..." breshop_yml_file = File.dirname(__FILE__) + '/../../../config/breshop.yml' FileUtils.cp File.dirname(__FILE__) + '/install/breshop.yml', breshop_yml_file unless File.exist?(breshop_yml_file) diff --git a/install/breshop.yml b/install/breshop.yml index 3a75c3b..9c6e978 100644 --- a/install/breshop.yml +++ b/install/breshop.yml @@ -1,6 +1,6 @@ # Este é o arquivo de configuração do plugin brEshop -pagseguro: +pagseguro: email_cobranca: email@servidor.com tipo_carrinho: CP moeda: BRL diff --git a/install/pagseguro/controllers/autoret_controller.rb b/install/pagseguro/controllers/autoret_controller.rb index bc7a379..d90b95f 100644 --- a/install/pagseguro/controllers/autoret_controller.rb +++ b/install/pagseguro/controllers/autoret_controller.rb @@ -1,21 +1,21 @@ class AutoretController < ApplicationController - + # ok 1 - token no arquivo de configuracao # 2 - install para copiar os arquivos apra dentro da aplicacao # ok 3 - testes # ok 4 - tela para mostrar os registros e excluir # ok 5 - post de confirmacao da mensagem # 6 - mostrar mensagem de texto apos a instalacao para executar o rake db:migrate - - def index + + def index @config = YAML.load_file(File.dirname(__FILE__) + "/../../config/breshop.yml")["pagseguro"] @params = Hash.new @params[:token] = @config['token'] @params.merge!(request.parameters) - + Pstransaction.transaction do - + tx = Pstransaction.new tx.transaction_id = request.parameters["TransacaoID"] tx.seller_email = request.parameters["VendedorEmail"] @@ -36,7 +36,7 @@ def index tx.cli_zip = request.parameters["CliCEP"] tx.cli_phone = request.parameters["CliTelefone"] tx.count_itens = request.parameters["NumItens"] - + 1.upto(request.parameters["NumItens"].to_i) do |c| product = Psproduct.new product.pstransaction = tx @@ -48,21 +48,21 @@ def index product.extra = request.parameters["ProdExtras_#{c}"] product.save end - + tx.save end - - end + + end def show @txs = Pstransaction.find_by_id(params[:id]) unless params[:id].blank? @txs = Pstransaction.find(:all) if params[:id].blank? end - + def clean Pstransaction.delete_all - Psproduct.delete_all + Psproduct.delete_all redirect_to :action => 'show' end - + end diff --git a/install/pagseguro/test/fixtures/psproducts.yml b/install/pagseguro/test/fixtures/psproducts.yml index 738dff7..04b51d0 100644 --- a/install/pagseguro/test/fixtures/psproducts.yml +++ b/install/pagseguro/test/fixtures/psproducts.yml @@ -19,9 +19,9 @@ one: pstransaction_id: "1" - product_id: "1" - description: "1" - price: "1" - quantity: "1" - freight_value: "1" + product_id: "1" + description: "1" + price: "1" + quantity: "1" + freight_value: "1" extra: "1" \ No newline at end of file diff --git a/install/pagseguro/test/fixtures/pstransactions.yml b/install/pagseguro/test/fixtures/pstransactions.yml index ee06242..0524896 100644 --- a/install/pagseguro/test/fixtures/pstransactions.yml +++ b/install/pagseguro/test/fixtures/pstransactions.yml @@ -46,12 +46,12 @@ one: cli_email: "1" cli_number: "1" cli_complement: "1" - cli_district: "1" - cli_city: "1" - cli_state: "1" - cli_zip: "1" - cli_phone: "1" - count_itens: "1" - checked: "1" + cli_district: "1" + cli_city: "1" + cli_state: "1" + cli_zip: "1" + cli_phone: "1" + count_itens: "1" + checked: "1" diff --git a/install/pagseguro/test/functional/autoret_controller_test.rb b/install/pagseguro/test/functional/autoret_controller_test.rb index ccacc6c..681345b 100644 --- a/install/pagseguro/test/functional/autoret_controller_test.rb +++ b/install/pagseguro/test/functional/autoret_controller_test.rb @@ -4,7 +4,7 @@ class AutoretController; def rescue_action(e)raise e end; end class AutoretControllerTest < ActionController::TestCase - + def setup @controller = AutoretController.new @request = ActionController::TestRequest.new @@ -12,45 +12,45 @@ def setup end def test_post_notification_one_product - + # cleanning db.. Pstransaction.delete_all Psproduct.delete_all - + txs = Pstransaction.find(:all) assert_equal 0, txs.size, "DB must be clean (Pstransaction)" prods = Psproduct.find(:all) assert_equal 0, prods.size, "DB must be clean (Psproduct)" - - # http://localhost:3000/autoret?VendedorEmail=emaildovendedor&TransacaoID=123&Referencia=referencia&TipoFrete=FR&ValorFrete=10,00&Anotacao=anotacaooo&DataTransacao=dd/mm/yyyy hh:mm:ss&TipoPagamento=Pagamento via cartão de crédito&StatusTransacao=Em Análise&CliNome=NomeDoCabra&CliEmail=email@uol.com.br&CliEndereco=Endereco do cliente&CliNumero=1741&CliComplemento=AP22&CliBairro=Moema&CliCidade=Sao Paulo&CliEstado=SP&CliCEP=14055490&CliTelefone=00 00000000&NumItens=1&ProdID_1=1&ProdDescricao_1=Nome do Produto 01&ProdValor_1=100,00&ProdQuantidade_1=2&ProdFrete_1=10&ProdExtras_1=0 - post :index, :VendedorEmail => 'emaildovendedor', - :TransacaoID => '123' , - :Referencia => 'referencia' , - :TipoFrete => 'FR' , - :ValorFrete => '10,00' , - :Anotacao => 'anotacaooo' , - :DataTransacao => 'dd/mm/yyyy hh :mm:ss' , - :TipoPagamento => 'Pagamento via cartão de crédito' , - :StatusTransacao => 'Em Análise' , - :CliNome => 'NomeDoCabra' , - :CliEmail => 'email@uol.com.br' , - :CliEndereco => 'Endereco do cliente' , - :CliNumero => '1741' , - :CliComplemento => 'AP22' , - :CliBairro => 'Moema' , + + # http://localhost:3000/autoret?VendedorEmail=emaildovendedor&TransacaoID=123&Referencia=referencia&TipoFrete=FR&ValorFrete=10,00&Anotacao=anotacaooo&DataTransacao=dd/mm/yyyy hh:mm:ss&TipoPagamento=Pagamento via cartão de crédito&StatusTransacao=Em Análise&CliNome=NomeDoCabra&CliEmail=email@uol.com.br&CliEndereco=Endereco do cliente&CliNumero=1741&CliComplemento=AP22&CliBairro=Moema&CliCidade=Sao Paulo&CliEstado=SP&CliCEP=14055490&CliTelefone=00 00000000&NumItens=1&ProdID_1=1&ProdDescricao_1=Nome do Produto 01&ProdValor_1=100,00&ProdQuantidade_1=2&ProdFrete_1=10&ProdExtras_1=0 + post :index, :VendedorEmail => 'emaildovendedor', + :TransacaoID => '123' , + :Referencia => 'referencia' , + :TipoFrete => 'FR' , + :ValorFrete => '10,00' , + :Anotacao => 'anotacaooo' , + :DataTransacao => 'dd/mm/yyyy hh :mm:ss' , + :TipoPagamento => 'Pagamento via cartão de crédito' , + :StatusTransacao => 'Em Análise' , + :CliNome => 'NomeDoCabra' , + :CliEmail => 'email@uol.com.br' , + :CliEndereco => 'Endereco do cliente' , + :CliNumero => '1741' , + :CliComplemento => 'AP22' , + :CliBairro => 'Moema' , :CliCidade => 'Sao Paulo' , - :CliEstado => 'SP' , - :CliCEP => '14055490' , - :CliTelefone => '00 00000000' , - :NumItens => '1' , - :ProdID_1 => '1' , - :ProdDescricao_1 => 'Nome do Produto 01' , - :ProdValor_1 => '100,00' , - :ProdQuantidade_1 => '2' , - :ProdFrete_1 => '10', - :ProdExtras_1 => '0' - + :CliEstado => 'SP' , + :CliCEP => '14055490' , + :CliTelefone => '00 00000000' , + :NumItens => '1' , + :ProdID_1 => '1' , + :ProdDescricao_1 => 'Nome do Produto 01' , + :ProdValor_1 => '100,00' , + :ProdQuantidade_1 => '2' , + :ProdFrete_1 => '10', + :ProdExtras_1 => '0' + txs = Pstransaction.find(:all) assert_equal 1, txs.size, "DB must be clean (Pstransaction)" @@ -58,154 +58,154 @@ def test_post_notification_one_product assert_equal 1, prods.size, "DB must be clean (Psproduct)" end - + def test_post_notification_two_products - + # cleanning db.. Pstransaction.delete_all Psproduct.delete_all - + txs = Pstransaction.find(:all) assert_equal 0, txs.size, "DB must be clean (Pstransaction)" prods = Psproduct.find(:all) assert_equal 0, prods.size, "DB must be clean (Psproduct)" - - # http://localhost:3000/autoret?VendedorEmail=emaildovendedor&TransacaoID=123&Referencia=referencia&TipoFrete=FR&ValorFrete=10,00&Anotacao=anotacaooo&DataTransacao=dd/mm/yyyy hh:mm:ss&TipoPagamento=Pagamento via cartão de crédito&StatusTransacao=Em Análise&CliNome=NomeDoCabra&CliEmail=email@uol.com.br&CliEndereco=Endereco do cliente&CliNumero=1741&CliComplemento=AP22&CliBairro=Moema&CliCidade=Sao Paulo&CliEstado=SP&CliCEP=14055490&CliTelefone=00 00000000&NumItens=2&ProdID_1=1&ProdDescricao_1=Nome do Produto 01&ProdValor_1=100,00&ProdQuantidade_1=2&ProdFrete_1=10&ProdExtras_1=0&&ProdID_2=2&ProdDescricao_2=Nome do Produto 02&ProdValor_2=200,00&ProdQuantidade_2=22&ProdFrete_2=20&ProdExtras_2=0 - post :index, :VendedorEmail => 'emaildovendedor', - :TransacaoID => '123' , - :Referencia => 'referencia' , - :TipoFrete => 'FR' , - :ValorFrete => '10,00' , - :Anotacao => 'anotacaooo' , - :DataTransacao => 'dd/mm/yyyy hh :mm:ss' , - :TipoPagamento => 'Pagamento via cartão de crédito' , - :StatusTransacao => 'Em Análise' , - :CliNome => 'NomeDoCabra' , - :CliEmail => 'email@uol.com.br' , - :CliEndereco => 'Endereco do cliente' , - :CliNumero => '1741' , - :CliComplemento => 'AP22' , - :CliBairro => 'Moema' , + + # http://localhost:3000/autoret?VendedorEmail=emaildovendedor&TransacaoID=123&Referencia=referencia&TipoFrete=FR&ValorFrete=10,00&Anotacao=anotacaooo&DataTransacao=dd/mm/yyyy hh:mm:ss&TipoPagamento=Pagamento via cartão de crédito&StatusTransacao=Em Análise&CliNome=NomeDoCabra&CliEmail=email@uol.com.br&CliEndereco=Endereco do cliente&CliNumero=1741&CliComplemento=AP22&CliBairro=Moema&CliCidade=Sao Paulo&CliEstado=SP&CliCEP=14055490&CliTelefone=00 00000000&NumItens=2&ProdID_1=1&ProdDescricao_1=Nome do Produto 01&ProdValor_1=100,00&ProdQuantidade_1=2&ProdFrete_1=10&ProdExtras_1=0&&ProdID_2=2&ProdDescricao_2=Nome do Produto 02&ProdValor_2=200,00&ProdQuantidade_2=22&ProdFrete_2=20&ProdExtras_2=0 + post :index, :VendedorEmail => 'emaildovendedor', + :TransacaoID => '123' , + :Referencia => 'referencia' , + :TipoFrete => 'FR' , + :ValorFrete => '10,00' , + :Anotacao => 'anotacaooo' , + :DataTransacao => 'dd/mm/yyyy hh :mm:ss' , + :TipoPagamento => 'Pagamento via cartão de crédito' , + :StatusTransacao => 'Em Análise' , + :CliNome => 'NomeDoCabra' , + :CliEmail => 'email@uol.com.br' , + :CliEndereco => 'Endereco do cliente' , + :CliNumero => '1741' , + :CliComplemento => 'AP22' , + :CliBairro => 'Moema' , :CliCidade => 'Sao Paulo' , - :CliEstado => 'SP' , - :CliCEP => '14055490' , - :CliTelefone => '00 00000000' , - :NumItens => '2' , - :ProdID_1 => '1' , - :ProdDescricao_1 => 'Nome do Produto 01' , - :ProdValor_1 => '100,00' , - :ProdQuantidade_1 => '2' , - :ProdFrete_1 => '10', + :CliEstado => 'SP' , + :CliCEP => '14055490' , + :CliTelefone => '00 00000000' , + :NumItens => '2' , + :ProdID_1 => '1' , + :ProdDescricao_1 => 'Nome do Produto 01' , + :ProdValor_1 => '100,00' , + :ProdQuantidade_1 => '2' , + :ProdFrete_1 => '10', :ProdExtras_1 => '0', - :ProdID_2 => '2' , - :ProdDescricao_2 => 'Nome do Produto 02' , - :ProdValor_2 => '200,00' , - :ProdQuantidade_2 => '4' , - :ProdFrete_2 => '20', - :ProdExtras_2 => '0' - + :ProdID_2 => '2' , + :ProdDescricao_2 => 'Nome do Produto 02' , + :ProdValor_2 => '200,00' , + :ProdQuantidade_2 => '4' , + :ProdFrete_2 => '20', + :ProdExtras_2 => '0' + txs = Pstransaction.find(:all) - # puts "Transactions count: #{txs.size}" + # puts "Transactions count: #{txs.size}" assert_equal 1, txs.size, "DB must be clean (Pstransaction)" prods = Psproduct.find(:all) # puts "Product count: #{prods.size}" assert_equal 2, prods.size, "DB must be clean (Psproduct)" - end - + end + def test_post_notification_three_products - + # cleanning db.. Pstransaction.delete_all - Psproduct.delete_all - + Psproduct.delete_all + txs = Pstransaction.find(:all) assert_equal 0, txs.size, "DB must be clean (Pstransaction)" prods = Psproduct.find(:all) assert_equal 0, prods.size, "DB must be clean (Psproduct)" - post :index, :VendedorEmail => 'emaildovendedor', - :TransacaoID => '123' , - :Referencia => 'referencia' , - :TipoFrete => 'FR' , - :ValorFrete => '10,00' , - :Anotacao => 'anotacaooo' , - :DataTransacao => 'dd/mm/yyyy hh :mm:ss' , - :TipoPagamento => 'Pagamento via cartão de crédito' , - :StatusTransacao => 'Em Análise' , - :CliNome => 'NomeDoCabra' , - :CliEmail => 'email@uol.com.br' , - :CliEndereco => 'Endereco do cliente' , - :CliNumero => '1741' , - :CliComplemento => 'AP22' , - :CliBairro => 'Moema' , + post :index, :VendedorEmail => 'emaildovendedor', + :TransacaoID => '123' , + :Referencia => 'referencia' , + :TipoFrete => 'FR' , + :ValorFrete => '10,00' , + :Anotacao => 'anotacaooo' , + :DataTransacao => 'dd/mm/yyyy hh :mm:ss' , + :TipoPagamento => 'Pagamento via cartão de crédito' , + :StatusTransacao => 'Em Análise' , + :CliNome => 'NomeDoCabra' , + :CliEmail => 'email@uol.com.br' , + :CliEndereco => 'Endereco do cliente' , + :CliNumero => '1741' , + :CliComplemento => 'AP22' , + :CliBairro => 'Moema' , :CliCidade => 'Sao Paulo' , - :CliEstado => 'SP' , - :CliCEP => '14055490' , - :CliTelefone => '00 00000000' , - :NumItens => '3' , - :ProdID_1 => '1' , - :ProdDescricao_1 => 'Nome do Produto 01' , - :ProdValor_1 => '100,00' , - :ProdQuantidade_1 => '2' , - :ProdFrete_1 => '10', + :CliEstado => 'SP' , + :CliCEP => '14055490' , + :CliTelefone => '00 00000000' , + :NumItens => '3' , + :ProdID_1 => '1' , + :ProdDescricao_1 => 'Nome do Produto 01' , + :ProdValor_1 => '100,00' , + :ProdQuantidade_1 => '2' , + :ProdFrete_1 => '10', :ProdExtras_1 => '0', - :ProdID_2 => '2' , - :ProdDescricao_2 => 'Nome do Produto 02' , - :ProdValor_2 => '200,00' , - :ProdQuantidade_2 => '4' , - :ProdFrete_2 => '20', + :ProdID_2 => '2' , + :ProdDescricao_2 => 'Nome do Produto 02' , + :ProdValor_2 => '200,00' , + :ProdQuantidade_2 => '4' , + :ProdFrete_2 => '20', :ProdExtras_2 => '0', - :ProdID_3 => '3' , - :ProdDescricao_3 => 'Nome do Produto 03' , - :ProdValor_3 => '300,00' , - :ProdQuantidade_3 => '6' , - :ProdFrete_3 => '30', - :ProdExtras_3 => '0' - + :ProdID_3 => '3' , + :ProdDescricao_3 => 'Nome do Produto 03' , + :ProdValor_3 => '300,00' , + :ProdQuantidade_3 => '6' , + :ProdFrete_3 => '30', + :ProdExtras_3 => '0' + txs = Pstransaction.find(:all) - # puts "Transactions count: #{txs.size}" + # puts "Transactions count: #{txs.size}" assert_equal 1, txs.size, "DB must be clean (Pstransaction)" prods = Psproduct.find(:all) # puts "Product count: #{prods.size}" assert_equal 3, prods.size, "DB must be clean (Psproduct)" - end - + end + def test_clean - + txs = Pstransaction.find(:all) assert_equal 1, txs.size, "At least one record from Fixtures (Pstransaction)" - + prods = Psproduct.find(:all) - assert_equal 1, prods.size, "At least one record from Fixtures (Psproduct)" - + assert_equal 1, prods.size, "At least one record from Fixtures (Psproduct)" + post :clean assert_redirected_to :action => "show" - + txs = Pstransaction.find(:all) assert_equal 0, txs.size, "DB must be clean (Pstransaction)" - + prods = Psproduct.find(:all) assert_equal 0, prods.size, "DB must be clean (Psproduct)" - + end - + def test_show - + txs = Pstransaction.find(:all) assert_equal 1, txs.size, "At least one record from Fixtures (Pstransaction)" - + prods = Psproduct.find(:all) assert_equal 1, prods.size, "At least one record from Fixtures (Psproduct)" - + post :show assert_not_nil assigns(:txs) - + end - + end diff --git a/install/pagseguro/views/autoret/show.html.erb b/install/pagseguro/views/autoret/show.html.erb index 350ac91..7e8033d 100644 --- a/install/pagseguro/views/autoret/show.html.erb +++ b/install/pagseguro/views/autoret/show.html.erb @@ -1,6 +1,6 @@ - Show Records + Show Records

Show records....

@@ -14,7 +14,7 @@ - + @@ -30,19 +30,19 @@ <% @txs.each do |tx| %> - + - - - - + + + + - + @@ -60,7 +60,7 @@ - <% tx.psproducts.each do |prod|%> + <% tx.psproducts.each do |prod|%> diff --git a/pagseguro/lib/pagseguro/integration.rb b/pagseguro/lib/pagseguro/integration.rb index 7494316..98d328d 100644 --- a/pagseguro/lib/pagseguro/integration.rb +++ b/pagseguro/lib/pagseguro/integration.rb @@ -6,7 +6,7 @@ require "haml" class Integration - + # Integration can be instantiated using a config file as parameter # if no one is specified, will be used the default: /../config/pageguro.yml # @@ -17,18 +17,18 @@ def initialize(pars = {}) @parametros_config = "tipo=#{@config['tipo_carrinho']}" @parametros_config << "&moeda=#{@config['moeda']}" @parametros_config << "&email_cobranca=#{@config['email_cobranca']}" - + @uri = URI.parse(@config['webpagto']) end # Create the form on HTML format to be posted into the PagSeguro website. # It requires HAML - # + # # Ex.: # @form_html = integration.checkout sale ==> no shipment fee defined, will be calculated by PagSeguro - # if you define shipment_type (SD/EN) it will be used by PagSeguro, if not, the buyer will + # if you define shipment_type (SD/EN) it will be used by PagSeguro, if not, the buyer will # select one of then as shipment - # @form_html = integration.checkout sale, "10.00" ==> fixed shipment fee + # @form_html = integration.checkout sale, "10.00" ==> fixed shipment fee # #TODO test def checkout sale, *frete @@ -37,13 +37,13 @@ def checkout sale, *frete raise "Invalid buyer! (nil)" if sale.buyer.nil? raise "Invalid buyer! (not a Buyer)" unless sale.buyer.class.eql? Buyer raise "Invalid Itens! (qt = 0)" if sale.itens.size == 0 - + Haml::Engine.new(IO.readlines(File.dirname(__FILE__)+"/views/form.html.haml").join).render(Object.new, :config=>@config, :sale=>sale, :frete=>frete ) - + end # # Envia um post para o PagSeguro solicitando a autenticidade do post enviado pelo PagSeguro @@ -59,17 +59,17 @@ def checkout sale, *frete # #TODO # #TODO TEST # end - # - # + # + # # # Envia um post para o PagSeguro solicitando a autenticidade do post enviado pelo PagSeguro # # Segundo a documentacao do PagSeguro, após o pagamento da compra, o sistema envia uma notificacao # # via post para o site do lojista. - # # Este metodo é o responsavel por enviar um novo post ao PS, solicitando a autenticidade do post recebido + # # Este metodo é o responsavel por enviar um novo post ao PS, solicitando a autenticidade do post recebido # # informando o processamento da trasnacao, geramente a confirmacao de pagamento. # # # # Ex.: # # PsIntegracao.confirma_autenticidade cliente, items ==> ['FRAUDE', 'Alteracao do status da transacao fraudulenta!'] - # # PsIntegracao.confirma_autenticidade cliente, items ==> ['OK', 'Alteracao do status da transacao verificada!'] + # # PsIntegracao.confirma_autenticidade cliente, items ==> ['OK', 'Alteracao do status da transacao verificada!'] # # # def self.confirma_autenticidade ps_cliente, ps_items # #TODO diff --git a/pagseguro/lib/pagseguro/util.rb b/pagseguro/lib/pagseguro/util.rb index a9f9ef5..5384966 100644 --- a/pagseguro/lib/pagseguro/util.rb +++ b/pagseguro/lib/pagseguro/util.rb @@ -1,6 +1,6 @@ module Util Object.class_eval do - + # Format decimal field (weight format) to String (based on PagSeguro format) # Ex.: # integration.to_ps_weight "0.5" ==> 500 #500 gramas @@ -13,12 +13,12 @@ module Util def to_ps_weight return nil if self.nil? return "000" if self.to_f == 0 - + value = self.to_s # obtem a parte fracionaria e transforma em string. frac = value.to_f - value.to_i - frac = frac.to_s + "00" + frac = frac.to_s + "00" frac = frac[2..4] inteiro = "" inteiro = value.to_i.to_s if (value.to_f.truncate > 0) @@ -37,12 +37,12 @@ def to_ps_weight def to_ps_money return nil if self.nil? return "00" if self.to_f == 0 - + value = self.to_s # obtem a parte fracionaria e transforma em string. frac = value.to_f - value.to_i - frac = frac.to_s + "0" + frac = frac.to_s + "0" frac = frac[2..3] # Se tiver parte inteira, concatena com a parte fracionaria inteiro = "" diff --git a/pagseguro/lib/pagseguro/views/form.html.haml b/pagseguro/lib/pagseguro/views/form.html.haml index dce3fb1..5393591 100644 --- a/pagseguro/lib/pagseguro/views/form.html.haml +++ b/pagseguro/lib/pagseguro/views/form.html.haml @@ -22,7 +22,7 @@ %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 } diff --git a/pagseguro/test/pagseguro_test.rb b/pagseguro/test/pagseguro_test.rb index be33431..a0e6ee1 100644 --- a/pagseguro/test/pagseguro_test.rb +++ b/pagseguro/test/pagseguro_test.rb @@ -7,13 +7,13 @@ require File.dirname(__FILE__) + '/../../general/lib/general' class PagseguroTest < Test::Unit::TestCase - + PAGSEGURO_YML = {"pagseguro" => {'email_cobranca' => "email@servidor.com", 'tipo_carrinho' => "CP", 'moeda' => "BRL", 'pais' => "BRA", 'webpagto' => "https://pagseguro.uol.com.br/security/webpagamentos/webpagto.aspx"}} - + def setup @item_1 = Item.new({:code=>"1", :description=>"Descricao do Produto 01", @@ -28,132 +28,132 @@ def setup :weight=>0.500}) end - + def test_integration_constructor_load_breshop_yml_in_config_rails_folder integration = Integration.new(:config=> File.dirname(__FILE__) + "/../../install/breshop.yml" ) - assert_equal PAGSEGURO_YML["pagseguro"], integration.instance_variable_get("@config") + assert_equal PAGSEGURO_YML["pagseguro"], integration.instance_variable_get("@config") end - + def test_to_weight assert_equal @item_1.weight.to_ps_weight, "100" - + #1.1 - nil price = nil.to_ps_weight assert_nil price, "1.1 - nil, se o parametro for nil, o retorno tbem devera ser nil" - + #1.2 - price nao conversivel a decimal price = "abc".to_ps_weight assert_equal "000", price, "1.2 - o price deve ser conversivel a decimal, caso contrario retornara o weight zerado no formado PS (000)" - + #1.3 - price deve ser uma String price = 14.to_ps_weight assert_nil nil, "1.3 - price deve ser uma string" - + #2 - entradas validas price = "0.5".to_ps_weight assert_equal "500", price, "2.1 - 0.5 => 500" - + price = "0.50".to_ps_weight assert_equal "500", price, "2.2 - 0.50 => 500" - + price = "0.500".to_ps_weight assert_equal "500", price, "2.3 - 0.500 => 500" - + price = "0.05".to_ps_weight assert_equal "050", price, "2.4 - 0.05 => 050" - + price = "0.005".to_ps_weight assert_equal "005", price, "2.5 - 0.05 => 005" - + price = "1".to_ps_weight assert_equal "1000", price, "2.6 - 1 => 1000" - + price = "1.0".to_ps_weight - assert_equal "1000", price, "2.7 - 1.0 => 1000" - + assert_equal "1000", price, "2.7 - 1.0 => 1000" + price = "1.5".to_ps_weight - assert_equal "1500", price, "2.8 - 1.5 => 1500" - + assert_equal "1500", price, "2.8 - 1.5 => 1500" + price = "1.500".to_ps_weight assert_equal "1500", price, "2.9 - 1.500 => 1500" - + price = "1.501".to_ps_weight assert_equal "1501", price, "2.10 - 1.501 => 1501" - + price = "1.510".to_ps_weight - assert_equal "1510", price, "2.11 - 1.510 => 1510" + assert_equal "1510", price, "2.11 - 1.510 => 1510" price = "0.1".to_ps_weight - assert_equal "100", price, "2.12 - 0.1 => 100" + assert_equal "100", price, "2.12 - 0.1 => 100" end - + def test_to_money - + assert_equal @item_1.price.to_ps_money, "1150" #1.1 - nil price = nil.to_ps_money assert_nil price, "1.1 - nil, se o parametro for nil, o retorno tbem devera ser nil" - + #1.2 - price nao conversivel a decimal price = "abc".to_ps_money assert_equal "00", price, "1.2 - o price deve ser conversivel a decimal, caso contrario retornara o weight zerado no formado PS (000)" - + #1.3 - price deve ser uma String price = 14.to_ps_money assert_nil nil, "1.3 - price deve ser uma string" - + #2 - entradas validas price = "0.5".to_ps_money assert_equal "50", price, "2.1 - 0.5 => 50 centavos" - + price = "0.50".to_ps_money assert_equal "50", price, "2.2 - 0.50 => 50 centavos" - + price = "0.05".to_ps_money assert_equal "05", price, "2.3 - 0.05 => 05 centavos" - + price = "1".to_ps_money assert_equal "100", price, "2.4 - 1 => 1 real (100)" - + price = "1.0".to_ps_money assert_equal "100", price, "2.5 - 1.0 => 1 real (100)" - + price = "1.5".to_ps_money assert_equal "150", price, "2.6 - 1.5 => 1,5 real" - + price = "1.55".to_ps_money assert_equal "155", price, "2.7 - 1.55 => 1,55 real" - + price = "1.05".to_ps_money assert_equal "105", price, "2.8 - 1.05 => 105 real (100)" - + price = "0.05".to_ps_money assert_equal "05", price, "2.9 - 0.05 => 05 real" - + end - + def test_checkout pagseguro = Integration.new(:config=>File.dirname(__FILE__) + "/../../install/breshop.yml") - + sale = Sale.new - + # sale nil assert_raise RuntimeError do pagseguro.checkout nil; end - + # sale.buyer nil assert_raise RuntimeError do pagseguro.checkout sale end - + # sale.buyer = "some name" sale.buyer = "Some Name" assert_raise RuntimeError do pagseguro.checkout sale end buyer = Buyer.new sale.buyer = Buyer.new - + # itens qt == 0. assert_raise RuntimeError do pagseguro.checkout sale end sale << @item_1 - - + + sale.buyer.name = "Marcio Garcia" sale.code = "TC01" sale.buyer.zip = "04515030" @@ -167,15 +167,15 @@ def test_checkout sale.buyer.ext = "11" sale.buyer.phone = "86717148" sale.shipment_type = "EN" - + assert_equal(self.return_form_pac_one_product, pagseguro.checkout(sale), "Shipment type defined by the seller, calculated by weight (EN = PAC)") - + sale.shipment_type = "SD" assert_equal(self.return_form_sedex_one_product, pagseguro.checkout(sale), "Shipment type defined by the seller, calculated by weight (SD = SEDEX)") sale.shipment_type = nil assert_equal(self.return_form_one_product, pagseguro.checkout(sale), "Buyer will select the shipment type and price on PagSeguro") - + assert_equal(self.return_form_defined_one_product, pagseguro.checkout(sale, 1000), "Shipment fee defined by seller = R$10,00") sale.shipment_type = "SD" @@ -183,24 +183,24 @@ def test_checkout sale.shipment_type = "EN" assert_equal(self.return_form_defined_one_product, pagseguro.checkout(sale, 1000), "Shipment fee defined by seller = R$10,00") - + end - + def return_form_sedex_one_product data = "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n" end - + def return_form_pac_one_product data = "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n" end - + def return_form_one_product data = "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n" - end - + end + def return_form_defined_one_product data = "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n" - end - - + end + + end \ No newline at end of file
Record
Date
CheckedChecked TransactionID SellerEmail Ref
<%= tx.created_at%><%= tx.checked%><%= tx.checked%> <%= tx.transaction_id%> <%= tx.seller_email%><%= tx.ref%><%= tx.freight_type%><%= tx.freight_value%><%= tx.extras%><%= tx.ref%><%= tx.freight_type%><%= tx.freight_value%><%= tx.extras%> <%= tx.annotation%> <%= tx.payment_type%> <%= tx.status%> <%= tx.cli_name%> <%= tx.cli_email%> <%= tx.cli_address%> <%= tx.cli_number%> <%= tx.cli_complement%> <%= tx.cli_district%> <%= tx.cli_city%> <%= tx.cli_state%><%= tx.cli_zip%> <%= tx.cli_phone%> <%= tx.count_itens%><%= tx.cli_zip%> <%= tx.cli_phone%> <%= tx.count_itens%>
Products:created_at updated_at
<%= prod.id%> <%= prod.pstransaction_id%>