paypal-frete-facil

Cálculo de frete através do PayPal Frete Fácil.

Downloads
39.4K
Stars
4
Committers
1

= paypal-frete-facil

Cálculo de frete através do PayPal Frete Fácil (http://www.paypal-brasil.com.br/fretefacil).

== Instalando

=== Gemfile gem 'paypal-frete-facil'

=== Instalação direta $ gem install paypal-frete-facil

== Usando

require 'paypal-frete-facil'

shipping = PayPal::FreteFacil::Shipping.new :from_zip => "04094-050", :to_zip => "90619-900", :width => 15, :height => 2, :length => 30, :weight => 0.3

result = shipping.calculate result.value # => 14.77

Verificação de sucesso e erro:

shipping.height = 200

result = shipping.calculate result.success? # => false result.error? # => true result.error_message # => "Não foi possível calcular o frete." result.value # => 0

Usando a interface pública em português:

frete = PayPal::FreteFacil::Frete.new :cep_origem => "04094-050", :cep_destino => "90619-900", :largura => 15, :altura => 2, :comprimento => 30, :peso => 0.3

resultado = frete.calcular resultado.valor # => 14.77 resultado.sucesso? # => true resultado.erro? # => false resultado.mensagem_erro # => ""

== Log

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}[http://github.com/prodis/log-me].

Exemplo de log: I, [2011-08-29T22:00:52.624430 #2186] INFO -- : PayPal-Frete-Facil Request: POST 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:Bodyfrete:getPreco04094-05090619-900152300.3</frete:getPreco></soapenv:Body></soapenv:Envelope>

I, [2011-08-29T22:00:53.917895 #2186] INFO -- : PayPal-Frete-Facil Response: HTTP/1.1 200 OK

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: POST 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:Bodyfrete:getPreco04094-05090619-900152300.3</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

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

== Informações adicionais

=== Maneiras de configurar atributos no construtor de PayPal::FreteFacil::Shipping (o mesmo vale para a classe PayPal::FreteFacil::Frete)

==== Com um hash shipping = PayPal::FreteFacil::Shipping.new :from_zip => "04094-050", :to_zip => "90619-900", :width => 15, :height => 2, :length => 30, :weight => 0.3

==== Com um bloco shipping = PayPal::FreteFacil::Shipping.new do |s| s.from_zip = "04094-050" s.to_zip = "90619-900" s.width = 15 s.height = 2 s.length = 30 s.weight = 0.3 end

=== Atributos de PayPal::FreteFacil::Shipping

==== String from_zip, to_zip ==== Fixnum width, height, length ==== Float weight

=== Observações da classe PayPal::FreteFacil::Shipping

  • Os atributos width, height e length também aceitam valores com casas decimais (float), mas para fazer o cálculo do frete será feito um round de seus valores.

=== Atributos de PayPal::FreteFacil::Frete

==== String cep_origem, cep_destino ==== Fixnum largura, altura, comprimento ==== Float peso

=== Observações da classe PayPal::FreteFacil::Frete

  • Os atributos largura, altura e comprimento também aceitam valores com casas decimais (float), mas para fazer o cálculo do frete será feito um round de seus valores.

== Copyright

(The MIT License)

{Prodis a.k.a. Fernando Hamasaki}[http://prodis.blog.br]

Copyright (c) 2011-2012 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.