tnt_mercurio 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8478ccc498c902bb778946b583a7b3806cf09f74
4
- data.tar.gz: 68a13b623d52184bc84e357cac8bea25418cede2
3
+ metadata.gz: fc18607b47b82ad90efb4a2be319c3486dfe9dab
4
+ data.tar.gz: b09043735c7ba514c49271345b8cf89a8a3a1b0d
5
5
  SHA512:
6
- metadata.gz: 576411f5b7c1d60902094a3a756571effe1056d86fc4552d6ed3052e07819c03d7a98d6f92f21894c8f732183820771fd008cf4474f07db6ef7f96151ff0ab58
7
- data.tar.gz: 908788e27feb99d98f6a2c4808ba51875cc668809e8c0d6d693e6c795d80762aa19a3af4d3375361e81112d224a4d235a88f2c8cd9ced98af1a5758d033cacee
6
+ metadata.gz: c05dbd5191da971a62d6d886dfaa8436755f06b5813822ccc08799f861d9b7d55751a9e78791399c7d4542c5cb96164aaa842644b97479d1c793e95ba563f4f3
7
+ data.tar.gz: b9c990c84068a27eecb1d4dc5826260409598e54166887fb0a1ef2b27bfe32136d05b47972d83afaba80620e10a78f6d1c8889551ac752d1d96565b8759a51d0
@@ -5,7 +5,7 @@ module TntMercurio
5
5
 
6
6
  def consultar(parametros)
7
7
  resposta = web_service.request(parametros)
8
- helper.build_response(resposta)
8
+ helper.build_response_calculo_frete(resposta)
9
9
  end
10
10
 
11
11
  def self.consultar(parametros)
@@ -2,20 +2,91 @@
2
2
  module TntMercurio
3
3
  module Service
4
4
  module Configuracao
5
+ #
6
+ # Configurações padrões
7
+ URL = 'http://ws.tntbrasil.com.br/servicos/CalculoFrete?wsdl' # Endereço do wsdl
8
+ DIVISAO_CLIENTE = 1 # Padrão utilizado pela TNT Mercúrio
9
+ SITUACAO_TRIBUTARIA_DESTINATARIO = 'CN' # Cia Mista Não Contribuinte
10
+ SITUACAO_TRIBUTARIA_REMETENTE = 'CO' # Contribuinte
11
+ TIPO_PESSOA_REMETENTE = 'J' # Jurídica
12
+ TIPO_PESSOA_DESTINATARIO = 'F' # Física
13
+ TIPO_SERVICO = 'RNC' # RNC Rodoviário Nacional
14
+ TIPO_FRETE = 'C' # C - CIF
15
+ attr_reader :divisao_cliente
16
+ attr_writer :situacao_tributaria_destinatario, :situacao_tributaria_remetente,
17
+ :tipo_pessoa_remetente, :tipo_pessoa_destinatario, :tipo_servico, :tipo_frete
5
18
 
6
- # Endereço do wsdl
7
- URL = 'http://ws.tntbrasil.com.br/servicos/CalculoFrete?wsdl'
8
-
9
- # Configurações padrões para E-Commerce
10
- CONFIGURACAO = {
11
- cdDivisaoCliente: '1',
12
- tpSituacaoTributariaDestinatario: 'CN',
13
- tpSituacaoTributariaRemetente: 'CO',
14
- tpServico: 'RNC',
15
- tpFrete: 'C',
16
- tpPessoaRemetente: 'J',
17
- tpPessoaDestinatario: 'F',
18
- }
19
+ #
20
+ # Comando que recebe as configuracoes
21
+ def configure
22
+ yield self if block_given?
23
+ end
24
+
25
+ def divisao_cliente
26
+ @divisao_cliente = DIVISAO_CLIENTE
27
+ end
28
+
29
+ #
30
+ # Opções para Situação Tributaria do Remetente e Destinatário
31
+ # 'CO' (Contribuinte)
32
+ # 'NC' (Não Contribuinte)
33
+ # 'CI' (Contrib Incentivado)
34
+ # 'CM' (Contrib Incentivado)
35
+ # 'CN' (Cia Mista Não Contribuinte)
36
+ # 'ME' (ME / EPP / Simples Nacional Contribuinte)
37
+ # 'MN' (ME / EPP / Simples Nacional Não Contribuinte)
38
+ # 'PR' (Produtor Rural Contribuinte)
39
+ # 'PN' (Produtor Rural Não Contribuinte)
40
+ # 'OP' (Órgão Público Contribuinte)
41
+ # 'ON' (Órgão Público Não Contribuinte)
42
+ # 'OF' (Órgão Público - Programas de fortalecimento e modernização Estadual)
43
+ def situacao_tributaria_destinatario
44
+ @situacao_tributaria_destinatario ||= SITUACAO_TRIBUTARIA_DESTINATARIO
45
+ end
46
+ def situacao_tributaria_remetente
47
+ @situacao_tributaria_remetente ||= SITUACAO_TRIBUTARIA_REMETENTE
48
+ end
49
+
50
+ #
51
+ # Opções para Tipo de Pessoa do Remetente e Destinatário
52
+ # F (Física) ou J (Jurídica)
53
+ def tipo_pessoa_remetente
54
+ @tipo_pessoa_remetente ||= TIPO_PESSOA_REMETENTE
55
+ end
56
+ def tipo_pessoa_destinatario
57
+ @tipo_pessoa_destinatario ||= TIPO_PESSOA_DESTINATARIO
58
+ end
59
+
60
+ #
61
+ # Opções para Tipo de Modalidade: String de três posições.
62
+ # 'RNC' Rodoviário Nacional
63
+ # 'ANC' Aéreo Nacional.
64
+ def tipo_servico
65
+ @tipo_servico ||= TIPO_SERVICO
66
+ end
67
+
68
+ #
69
+ # Opções para Tipo de Cobrança do Frete: String de 1
70
+ # 'C' - CIF
71
+ # 'F' - FOB
72
+ def tipo_frete
73
+ @tipo_frete ||= TIPO_FRETE
74
+ end
75
+
76
+ #
77
+ # Montar o Hash de configurações
78
+ def configuracoes_calculo_frete
79
+ configuracoes = {
80
+ cdDivisaoCliente: divisao_cliente,
81
+ tpSituacaoTributariaDestinatario: situacao_tributaria_destinatario,
82
+ tpSituacaoTributariaRemetente: situacao_tributaria_remetente,
83
+ tpPessoaRemetente: tipo_pessoa_remetente,
84
+ tpPessoaDestinatario: tipo_pessoa_destinatario,
85
+ tpServico: tipo_servico,
86
+ tpFrete: tipo_frete,
87
+ }
88
+ return configuracoes
89
+ end
19
90
 
20
91
  end
21
92
  end
@@ -3,31 +3,62 @@ module TntMercurio
3
3
  module Service
4
4
  class Helper
5
5
 
6
- def build_request(parametros = {})
7
- parametros = {
6
+ #
7
+ # Montar o Hash com a requisão de calculo de frete
8
+ def build_request_calculo_frete(parametros = {})
9
+
10
+ # Valida os parâmetros informados
11
+ erros_params = ""
12
+ erros_params << "Parâmetro obrigatório: login\n" if parametros[:login].blank?
13
+ erros_params << "Parâmetro obrigatório: cep_origem\n" if parametros[:cep_origem].blank?
14
+ erros_params << "Parâmetro obrigatório: cnpj_remetente\n" if parametros[:cnpj_remetente].blank?
15
+ erros_params << "Parâmetro obrigatório: ie_remetente\n" if parametros[:ie_remetente].blank?
16
+ erros_params << "Parâmetro obrigatório: cep_destino\n" if parametros[:cep_destino].blank?
17
+ erros_params << "Parâmetro obrigatório: cpf_destinatario\n" if parametros[:cpf_destinatario].blank?
18
+ erros_params << "Parâmetro obrigatório: valor_total\n" if parametros[:valor_total].blank?
19
+ erros_params << "Parâmetro obrigatório: peso\n" if parametros[:peso].blank?
20
+ raise erros_params unless erros_params.blank?
21
+
22
+ params = {
8
23
  in0: {
9
- login: 'walber@pneusboni.com.br',
10
- cepOrigem: '13560320',
11
- nrIdentifClienteRem: '10670773000139',
12
- nrInscricaoEstadualRemetente: '637320245117',
13
-
14
- cepDestino: '13562503',
15
- nrIdentifClienteDest: '32496250860',
16
- vlMercadoria: '1500.00',
17
- psReal: '10.000',
24
+ login: parametros[:login],
25
+ cepOrigem: parametros[:cep_origem],
26
+ nrIdentifClienteRem: parametros[:cnpj_remetente],
27
+ nrInscricaoEstadualRemetente: parametros[:ie_remetente],
28
+
29
+ cepDestino: parametros[:cep_destino],
30
+ nrIdentifClienteDest: parametros[:cpf_destinatario],
31
+
32
+ vlMercadoria: parametros[:valor_total],
33
+ psReal: parametros[:peso],
18
34
  }
19
35
  }
20
36
 
21
37
  # Adiciona as configurações padrões
22
- parametros[:in0].merge! TntMercurio::Service::Configuracao::CONFIGURACAO
38
+ params[:in0].merge! TntMercurio::Service.configuracoes_calculo_frete
23
39
 
24
- return parametros
40
+ return params
25
41
  end
26
42
 
27
- def build_response(resposta = {})
43
+ #
44
+ # Montar o Hash com a resposta de calculo de frete
45
+ def build_response_calculo_frete(resposta = {})
28
46
  response = {}
29
- response[:valor_frete] = resposta[:calcula_frete_response][:out][:vl_total_frete]
30
- response[:prazo_entrega] = resposta[:calcula_frete_response][:out][:prazo_entrega]
47
+ if resposta.blank? or resposta[:calcula_frete_response].blank? or !resposta[:error].blank? or !resposta[:calcula_frete_response][:out][:error_list][:string].blank?
48
+ response[:sucesso?] = false
49
+ if resposta[:error].blank?
50
+ response[:error] = resposta[:calcula_frete_response][:out][:error_list][:string]
51
+ else
52
+ response[:error] = resposta[:error].to_s
53
+ end
54
+ response[:valor] = 0
55
+ response[:prazo_entrega] = 0
56
+ else
57
+ response[:sucesso?] = true
58
+ response[:error] = ''
59
+ response[:valor] = resposta[:calcula_frete_response][:out][:vl_total_frete]
60
+ response[:prazo_entrega] = resposta[:calcula_frete_response][:out][:prazo_entrega]
61
+ end
31
62
  return response
32
63
  end
33
64
 
@@ -16,17 +16,20 @@ module TntMercurio
16
16
 
17
17
  def request(parametros = {})
18
18
  # Monta os parâmetros
19
- params = helper.build_request(parametros)
19
+ params = helper.build_request_calculo_frete(parametros)
20
20
 
21
21
  # Faz a requisição para o wsdl
22
- retorno = @savon_client.call(:calcula_frete, message: params)
23
-
24
- # Coverte a resposta
25
- resposta = retorno.to_array.first
22
+ begin
23
+ retorno = @savon_client.call(:calcula_frete, message: params)
24
+ # Coverte a resposta
25
+ resposta = retorno.to_array.first unless retorno.blank?
26
+ rescue Savon::SOAPFault => error
27
+ return helper.build_response_calculo_frete({error: error.to_hash[:fault][:faultstring]})
28
+ end
26
29
 
27
30
  # Verifica se a resposta veio correta ou se deu problema
28
31
  if resposta.blank?
29
- return {erros: retorno}
32
+ return {error: true}
30
33
  else
31
34
  return resposta
32
35
  end
@@ -4,6 +4,3 @@ module TntMercurio
4
4
  extend TntMercurio::Service::Configuracao
5
5
  end
6
6
  end
7
-
8
- # finder = TntMercurio::Service::CalcularFrete.new
9
- # address = finder.consultar({})
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module TntMercurio
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tnt_mercurio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - QW3 Software & Marketing
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brdinheiro