Cálculo de frete através do PayPal Frete Fácil (www.paypal-brasil.com.br/fretefacil).
gem 'paypal-frete-facil', '~> 0.2.2'
$ gem install paypal-frete-facil
require 'paypal-frete-facil' frete = PayPal::FreteFacil::Frete.new :cep_origem => "04094-050", :cep_destino => "90619-900", :largura => 15, :altura => 2, :profundidade => 30, :peso => 0.3 frete.calcular # => 13.87 frete.calculate # => 13.87
Por padrão, cada chamada ao Web Service do PayPal Frete Fácil é logada em STDOUT, com nível de log :info, usando a gem LogMe.
Exemplo de log:
I, [2011-08-29T22:00:52.624430 #2186] INFO -- : PayPal-Frete-Facil Request: https://ff.paypal-brasil.com.br/FretesPayPalWS/WSFretesPayPal <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:frete="https://ff.paypal-brasil.com.br/FretesPayPalWS"><soapenv:Header /><soapenv:Body><frete:getPreco><cepOrigem>04094-050</cepOrigem><cepDestino>90619-900</cepDestino><largura>15</largura><altura>2</altura><profundidade>30</profundidade><peso>0.3</peso></frete:getPreco></soapenv:Body></soapenv:Envelope> I, [2011-08-29T22:00:53.917895 #2186] INFO -- : PayPal-Frete-Facil Response: HTTP/1.1 200 OK <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getPrecoResponse xmlns:ns2="https://ff.paypal-brasil.com.br/FretesPayPalWS"><return>13.873999999999999</return></ns2:getPrecoResponse></S:Body></S:Envelope>
Se você configurar o nível de log como :debug, serão logados também todos os cabeçalhos HTTP da requisição e da resposta:
D, [2011-08-29T22:00:52.624430 #2186] DEBUG -- : PayPal-Frete-Facil Request: https://ff.paypal-brasil.com.br/FretesPayPalWS/WSFretesPayPal accept: */* user-agent: Ruby content-type: text/xml; charset=utf-8 soapaction: https://ff.paypal-brasil.com.br/FretesPayPalWS/WSFretesPayPal/getPreco <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:frete="https://ff.paypal-brasil.com.br/FretesPayPalWS"><soapenv:Header /><soapenv:Body><frete:getPreco><cepOrigem>04094-050</cepOrigem><cepDestino>90619-900</cepDestino><largura>15</largura><altura>2</altura><profundidade>30</profundidade><peso>0.3</peso></frete:getPreco></soapenv:Body></soapenv:Envelope> D, [2011-08-29T22:00:53.917895 #2186] DEBUG -- : PayPal-Frete-Facil Response: HTTP/1.1 200 OK date: Tue, 30 Aug 2011 01:00:52 GMT server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_jk/1.2.30 content-length: 271 content-type: text/xml;charset=utf-8 set-cookie: ROUTEID=.2; path=/ connection: close <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getPrecoResponse xmlns:ns2="https://ff.paypal-brasil.com.br/FretesPayPalWS"><return>13.873999999999999</return></ns2:getPrecoResponse></S:Body></S:Envelope>
Para desabilitar o log, mudar o nível do log ou configurar um outro mecanismo de log, use o módulo PayPal::FreteFacil.
PayPal::FreteFacil.configure do |config| config.log_enabled = false # Desabilita o log config.log_level = :debug # Altera o nível do log config.logger = Rails.logger # Usa o logger do Rails end
frete = PayPal::FreteFacil::Frete.new :cep_origem => "04094-050", :cep_destino => "90619-900", :largura => 15, :altura => 2, :profundidade => 30, :peso => 0.3
frete = PayPal::FreteFacil::Frete.new do |f| f.cep_origem = "04094-050" f.cep_destino = "90619-900" f.largura = 15 f.altura = 2 f.profundidade = 30 f.peso = 0.3 end
cep_origem, cep_destino
largura, altura, profundidade
peso
(The MIT License)
Prodis a.k.a. Fernando Hamasaki
Copyright © 2011 Prodis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.