tnt_mercurio 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tnt_mercurio/service/calcula_frete.rb +1 -1
- data/lib/tnt_mercurio/service/configuracao.rb +84 -13
- data/lib/tnt_mercurio/service/helper.rb +47 -16
- data/lib/tnt_mercurio/service/web_service.rb +9 -6
- data/lib/tnt_mercurio/service.rb +0 -3
- data/lib/tnt_mercurio/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc18607b47b82ad90efb4a2be319c3486dfe9dab
|
4
|
+
data.tar.gz: b09043735c7ba514c49271345b8cf89a8a3a1b0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c05dbd5191da971a62d6d886dfaa8436755f06b5813822ccc08799f861d9b7d55751a9e78791399c7d4542c5cb96164aaa842644b97479d1c793e95ba563f4f3
|
7
|
+
data.tar.gz: b9c990c84068a27eecb1d4dc5826260409598e54166887fb0a1ef2b27bfe32136d05b47972d83afaba80620e10a78f6d1c8889551ac752d1d96565b8759a51d0
|
@@ -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
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
7
|
-
|
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:
|
10
|
-
cepOrigem:
|
11
|
-
nrIdentifClienteRem:
|
12
|
-
nrInscricaoEstadualRemetente:
|
13
|
-
|
14
|
-
cepDestino:
|
15
|
-
nrIdentifClienteDest:
|
16
|
-
|
17
|
-
|
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
|
-
|
38
|
+
params[:in0].merge! TntMercurio::Service.configuracoes_calculo_frete
|
23
39
|
|
24
|
-
return
|
40
|
+
return params
|
25
41
|
end
|
26
42
|
|
27
|
-
|
43
|
+
#
|
44
|
+
# Montar o Hash com a resposta de calculo de frete
|
45
|
+
def build_response_calculo_frete(resposta = {})
|
28
46
|
response = {}
|
29
|
-
|
30
|
-
|
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.
|
19
|
+
params = helper.build_request_calculo_frete(parametros)
|
20
20
|
|
21
21
|
# Faz a requisição para o wsdl
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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 {
|
32
|
+
return {error: true}
|
30
33
|
else
|
31
34
|
return resposta
|
32
35
|
end
|
data/lib/tnt_mercurio/service.rb
CHANGED
data/lib/tnt_mercurio/version.rb
CHANGED
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
|
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-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brdinheiro
|