marnen-moip 1.0.2.pre.39f9dab38fc33fe9bf614deb8e90ca166ab2d6bf
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 +15 -0
- data/.document +5 -0
- data/.gitignore +26 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +20 -0
- data/README.markdown +86 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/lib/moip.rb +61 -0
- data/lib/moip/client.rb +97 -0
- data/lib/moip/direct_payment.rb +186 -0
- data/moip.gemspec +27 -0
- data/spec/moip_spec.rb +465 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzAxOTU4NjljM2RlYzA4ZmMyMjk1OWZhMGM5NDY4NDFiYWM0MDAzNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGMwNmE3MDY0NTFiOWQ2Njc0ZTI0YzIzMTdkNzY0NDRjZGVhZTgyMg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjdmOTMzODE1NWVhZmY4YTQ1NjA4ODkxNDM2YTgwZThiNjJiMTNhYzJkYTJm
|
10
|
+
MzRiYjJhNzUxYThlZGE5ZTBiOGU5NWRhMmZhYjE0OWNhMTRkZjhiMjYxNDE3
|
11
|
+
ZmFlZjkwZjdhMDQ3ODE4M2FjM2ZlZjE4NTMxNTU5ODNkMzE5MTE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2YyZTA2YTY2NjMzMTllYWEyODQ5YzM3OWE3NTkwNThlZmUzNWRkOWIwZWVm
|
14
|
+
MWVjMjliYjViNjlhNzA5NjAwNDAzMmMzNDNkMzU2MzVlZDE2ZmU0ZDllNzY3
|
15
|
+
NjQ0NWY1ZDc4YjM2ZGNlNGJmZjYwNjE0NGRkOGM2M2YzZGI5MTg=
|
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
.bundle
|
21
|
+
|
22
|
+
## PROJECT::SPECIFIC
|
23
|
+
lib/main.rb
|
24
|
+
config.yaml
|
25
|
+
config/
|
26
|
+
config/*
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
marnen-moip (1.0.2.pre.39f9dab38fc33fe9bf614deb8e90ca166ab2d6bf)
|
5
|
+
activesupport (>= 2.3.2)
|
6
|
+
httparty (~> 0.6.1)
|
7
|
+
nokogiri (~> 1.5.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (4.1.4)
|
13
|
+
i18n (~> 0.6, >= 0.6.9)
|
14
|
+
json (~> 1.7, >= 1.7.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
thread_safe (~> 0.1)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
crack (0.1.8)
|
19
|
+
diff-lcs (1.2.4)
|
20
|
+
httparty (0.6.1)
|
21
|
+
crack (= 0.1.8)
|
22
|
+
i18n (0.6.11)
|
23
|
+
json (1.8.1)
|
24
|
+
minitest (5.4.0)
|
25
|
+
nokogiri (1.5.11)
|
26
|
+
rspec (2.13.0)
|
27
|
+
rspec-core (~> 2.13.0)
|
28
|
+
rspec-expectations (~> 2.13.0)
|
29
|
+
rspec-mocks (~> 2.13.0)
|
30
|
+
rspec-core (2.13.1)
|
31
|
+
rspec-expectations (2.13.0)
|
32
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
33
|
+
rspec-mocks (2.13.1)
|
34
|
+
thread_safe (0.3.4)
|
35
|
+
tzinfo (1.2.1)
|
36
|
+
thread_safe (~> 0.1)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
marnen-moip!
|
43
|
+
rspec (>= 2.1.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Guilherme Nascimento
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# MoIP
|
2
|
+
|
3
|
+
Esta Gem permite utilizar a API do MoIP, gateway de pagamentos do IG.
|
4
|
+
|
5
|
+
## Pagamento direto
|
6
|
+
|
7
|
+
O Pagamento Direto é um recurso que a MoIP disponibiliza para aqueles clientes que necessitam de uma flexibilidade maior do que a Integração HTML pode oferecer.
|
8
|
+
|
9
|
+
Diferentemente de como é feito com a Integração HTML, seu cliente não precisa ser redirecionado para o site da MoIP para concluir a compra: tudo é feito dentro do ambiente do seu site, dando ao cliente uma maior segurança e confiança no processo.
|
10
|
+
|
11
|
+
As formas de pagamento disponibilizadas pela Gem são:
|
12
|
+
|
13
|
+
* Boleto
|
14
|
+
* Débito
|
15
|
+
* Cartão de Crédito
|
16
|
+
|
17
|
+
## Instalação
|
18
|
+
|
19
|
+
Instale a Gem
|
20
|
+
gem install moip
|
21
|
+
|
22
|
+
Adicione a Gem ao Gemfile
|
23
|
+
gem "moip"
|
24
|
+
|
25
|
+
## Utilização
|
26
|
+
|
27
|
+
O MoIP possui uma SandBox de testes que permite a simulação de pagamentos. Para utilizar a Gem com o SandBox, adicione a seguinte configuração no arquivo do environment que deseja utilizar.
|
28
|
+
|
29
|
+
### config/environments/development.rb
|
30
|
+
|
31
|
+
MoIP.setup do |config|
|
32
|
+
config.uri = "https://desenvolvedor.moip.com.br/sandbox"
|
33
|
+
config.token = SEU_TOKEN
|
34
|
+
config.key = SUA_KEY
|
35
|
+
end
|
36
|
+
|
37
|
+
Após realizar os testes na SandBox, você poderá fazer a mudança para o ambiente de produção do MoIP de maneira simples. Basta inserir no arquivo de environment de produção o token e chave que serão utilizados. Por padrão a gem já utiliza a URI de produção do MoIP.
|
38
|
+
|
39
|
+
###Crie os dados do pagador
|
40
|
+
|
41
|
+
pagador = { :nome => "Luiz Inácio Lula da Silva",
|
42
|
+
:login_moip => "lula",
|
43
|
+
:email => "presidente@planalto.gov.br",
|
44
|
+
:tel_cel => "(61)9999-9999",
|
45
|
+
:apelido => "Lula",
|
46
|
+
:identidade => "111.111.111-11",
|
47
|
+
:logradouro => "Praça dos Três Poderes",
|
48
|
+
:numero => "0",
|
49
|
+
:complemento => "Palácio do Planalto",
|
50
|
+
:bairro => "Zona Cívico-Administrativa",
|
51
|
+
:cidade => "Brasília",
|
52
|
+
:estado => "DF",
|
53
|
+
:pais => "BRA",
|
54
|
+
:cep => "70100-000",
|
55
|
+
:tel_fixo => "(61)3211-1221" }
|
56
|
+
|
57
|
+
###Dados do boleto
|
58
|
+
|
59
|
+
boleto = { :valor => "50",
|
60
|
+
:id_proprio => "Pag#{rand(1000)}",
|
61
|
+
:forma => "BoletoBancario",
|
62
|
+
:dias_expiracao => 5,
|
63
|
+
:pagador => pagador }
|
64
|
+
|
65
|
+
###Checkout
|
66
|
+
|
67
|
+
def checkout
|
68
|
+
response = MoIP::Client.checkout(boleto)
|
69
|
+
|
70
|
+
# exibe o boleto para impressão
|
71
|
+
redirect_to MoIP::Client.moip_page(response["Token"])
|
72
|
+
end
|
73
|
+
|
74
|
+
###Erros
|
75
|
+
|
76
|
+
- MoIP::MissingPaymentTypeError - Quando falta a razão do pagamento na requisição.
|
77
|
+
- MoIP::MissingPayerError - Quando falta as informações do pagador na requisição.
|
78
|
+
- MoIP::WebServerResponseError - Quando há algum erro ao se enviar a solicitação ao servidor. Normalmente a razão do erro vem como resposta da mensagem.
|
79
|
+
|
80
|
+
## Futuras implementações
|
81
|
+
|
82
|
+
* Pagamento Simples
|
83
|
+
* Pagamento Recorrente
|
84
|
+
|
85
|
+
|
86
|
+
Baseado no projeto do [Daniel Lopes](http://github.com/danielvlopes/moip_usage).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
RSpec::Core::RakeTask.new
|
9
|
+
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
Rake::RDocTask.new do |rdoc|
|
12
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
13
|
+
|
14
|
+
rdoc.rdoc_dir = 'rdoc'
|
15
|
+
rdoc.title = "moip #{version}"
|
16
|
+
rdoc.rdoc_files.include('README*')
|
17
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
18
|
+
end
|
19
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
data/lib/moip.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "rubygems"
|
3
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
4
|
+
require 'active_support/deprecation'
|
5
|
+
|
6
|
+
module MoIP
|
7
|
+
|
8
|
+
class ValidationError < StandardError; end
|
9
|
+
|
10
|
+
class MissingPaymentTypeError < ValidationError; end
|
11
|
+
class MissingPayerError < ValidationError; end
|
12
|
+
class MissingBirthdate < ValidationError; end
|
13
|
+
|
14
|
+
class InvalidCellphone < ValidationError; end
|
15
|
+
class InvalidExpiry < ValidationError; end
|
16
|
+
class InvalidInstitution < ValidationError; end
|
17
|
+
class InvalidPhone < ValidationError; end
|
18
|
+
class InvalidReceiving < ValidationError; end
|
19
|
+
class InvalidValue < ValidationError; end
|
20
|
+
|
21
|
+
autoload :DirectPayment, 'moip/direct_payment'
|
22
|
+
autoload :Client, 'moip/client'
|
23
|
+
|
24
|
+
# URI para acessar o serviço
|
25
|
+
mattr_accessor :uri
|
26
|
+
@@uri = 'https://www.moip.com.br'
|
27
|
+
|
28
|
+
# Token de autenticação
|
29
|
+
mattr_accessor :token
|
30
|
+
|
31
|
+
# Chave de acesso ao serviço
|
32
|
+
mattr_accessor :key
|
33
|
+
|
34
|
+
def self.setup
|
35
|
+
yield self
|
36
|
+
end
|
37
|
+
|
38
|
+
STATUS = {1 => "authorized", 2 => "started", 3 => "printed", 4 => "completed", 5 => "canceled", 6 => "analysing"}
|
39
|
+
|
40
|
+
class << self
|
41
|
+
def checkout(attributes = {})
|
42
|
+
ActiveSupport::Deprecation.warn("MoIP.checkout has been deprecated. Use MoIP::Client.checkout instead", caller)
|
43
|
+
MoIP::Client.checkout(attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
def query(token)
|
47
|
+
ActiveSupport::Deprecation.warn("MoIP.query has been deprecated. Use MoIP::Client.query instead", caller)
|
48
|
+
MoIP::Client.query(token)
|
49
|
+
end
|
50
|
+
|
51
|
+
def moip_page(token)
|
52
|
+
ActiveSupport::Deprecation.warn("MoIP.moip_page has been deprecated. use MoIP::Client.moip_page instead", caller)
|
53
|
+
MoIP::Client.moip_page(token)
|
54
|
+
end
|
55
|
+
|
56
|
+
def notification(params)
|
57
|
+
ActiveSupport::Deprecation.warn("MoIP.notification has been deprecated. use MoIP::Client.notification instead", caller)
|
58
|
+
MoIP::Client.moip_page(token)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/moip/client.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module MoIP
|
5
|
+
class WebServerResponseError < StandardError ; end
|
6
|
+
class MissingConfigError < StandardError ; end
|
7
|
+
class MissingTokenError < StandardError ; end
|
8
|
+
class MissingKeyError < StandardError ; end
|
9
|
+
|
10
|
+
class Client
|
11
|
+
include HTTParty
|
12
|
+
|
13
|
+
base_uri "#{MoIP.uri}/ws/alpha"
|
14
|
+
basic_auth MoIP.token, MoIP.key
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
# Verifica conta
|
19
|
+
# URL Produção: https://www.moip.com.br/ws/alpha/VerificarConta/{login_moip}
|
20
|
+
# URL SandBox: https://desenvolvedor.moip.com.br/sandbox/ws/alpha/VerificarConta/{login_moip}
|
21
|
+
# XML de Resposta:
|
22
|
+
# <ns1:verificarContaResponse>
|
23
|
+
# <RespostaVerificarConta>
|
24
|
+
# <Status>{status da conta}</Status>
|
25
|
+
# </RespostaVerificarConta>
|
26
|
+
# </ns1:verificarContaResponse>
|
27
|
+
#
|
28
|
+
# Valores Esperados: {status da conta}
|
29
|
+
# Inexistente " Login inexistente no sistema MoIP "
|
30
|
+
# Criado " Login criado, porem não verificado "
|
31
|
+
# Verificado " Login verificado "
|
32
|
+
# MoIP::Client.verify 'aaa'
|
33
|
+
|
34
|
+
def verify account
|
35
|
+
full_data = peform_action!(:get, "VerificarConta/#{account}")
|
36
|
+
return full_data["ns1:verificarContaResponse"]["RespostaVerificarConta"]["Status"] == "Verificado"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Envia uma instrução para pagamento único
|
40
|
+
def checkout(attributes = {})
|
41
|
+
body = DirectPayment.body(attributes)
|
42
|
+
puts "************ XML ************"
|
43
|
+
puts body
|
44
|
+
full_data = peform_action!(:post, 'EnviarInstrucao/Unica', :body => body)
|
45
|
+
# raise full_data.inspect
|
46
|
+
get_response!(full_data["ns1:EnviarInstrucaoUnicaResponse"]["Resposta"])
|
47
|
+
end
|
48
|
+
|
49
|
+
# Consulta dos dados das autorizações e pagamentos associados à Instrução
|
50
|
+
def query(token)
|
51
|
+
full_data = peform_action!(:get, "ConsultarInstrucao/#{token}")
|
52
|
+
|
53
|
+
get_response!(full_data["ns1:ConsultarTokenResponse"]["RespostaConsultar"])
|
54
|
+
end
|
55
|
+
|
56
|
+
# Retorna a URL de acesso ao MoIP
|
57
|
+
def moip_page(token)
|
58
|
+
raise(MissingTokenError, "É necessário informar um token para retornar os dados da transação") if token.nil?
|
59
|
+
"#{MoIP.uri}/Instrucao.do?token=#{token}"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Monta o NASP
|
63
|
+
def notification(params)
|
64
|
+
notification = {}
|
65
|
+
notification[:transaction_id] = params["id_transacao"]
|
66
|
+
notification[:amount] = params["valor"]
|
67
|
+
notification[:status] = MoIP::STATUS[params["status_pagamento"].to_i]
|
68
|
+
notification[:code] = params["cod_moip"]
|
69
|
+
notification[:payment_type] = params["tipo_pagamento"]
|
70
|
+
notification[:email] = params["email_consumidor"]
|
71
|
+
notification
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def peform_action!(action_name, url, options = {})
|
77
|
+
|
78
|
+
raise(MissingConfigError, "É necessário criar um arquivo de configuração para o moip. Veja mais em: https://github.com/moiplabs/moip-ruby") if MoIP.token.nil? && MoIP.key.nil?
|
79
|
+
|
80
|
+
raise(MissingTokenError, "É necessário informar um token na configuração") if MoIP.token.nil? || MoIP.token.empty?
|
81
|
+
|
82
|
+
raise(MissingKeyError, "É necessário informar um key na configuração") if MoIP.key.nil? || MoIP.key.empty?
|
83
|
+
|
84
|
+
response = self.send(action_name, url, options)
|
85
|
+
raise(WebServerResponseError, "Ocorreu um erro ao chamar o webservice") if response.nil?
|
86
|
+
response
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_response!(data)
|
90
|
+
# raise data.inspect
|
91
|
+
err = data["Erro"].is_a?(Array) ? data["Erro"].join(", ") : data["Erro"]
|
92
|
+
raise(WebServerResponseError, err) if data["Status"] == "Falha"
|
93
|
+
data
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
module MoIP
|
5
|
+
|
6
|
+
# Baseado em http://labs.moip.com.br/pdfs/Integra%C3%A7%C3%A3o%20API%20-%20Autorizar%20e%20Cancelar%20Pagamentos.pdf
|
7
|
+
CodigoErro = 0..999
|
8
|
+
CodigoEstado = %w{AC AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO}
|
9
|
+
CodigoMoeda = "BRL"
|
10
|
+
CodigoPais = "BRA"
|
11
|
+
Destino = %w{Nenhum MesmoCobranca AInformar PreEstabelecido}
|
12
|
+
InstituicaoPagamento = %w{MoIP Visa AmericanExpress Mastercard Diners BancoDoBrasil Bradesco Itau BancoReal Unibanco Aura Hipercard Paggo Banrisul}
|
13
|
+
FormaPagamento = %w{CarteiraMoIP CartaoCredito CartaoDebito DebitoBancario FinanciamentoBancario BoletoBancario}
|
14
|
+
FormaRestricao = %w{Contador Valor}
|
15
|
+
PapelIndividuo = %w{Integrador Recebedor Comissionado Pagado}
|
16
|
+
OpcaoDisponivel = %w{Sim Não PagadorEscolhe}
|
17
|
+
Parcelador = %w{Nenhum Administradora MoIP Recebedor}
|
18
|
+
StatusLembrete = %w{Enviado Realizado EmAndamento Aguardando Falha}
|
19
|
+
StatusPagamento = %w{Concluido EmAnalise Autorizado Iniciado Cancelado BoletoImpresso Estornado}
|
20
|
+
TipoDias = %w{Corridos Uteis}
|
21
|
+
TipoDuracao = %w{Minutos Horas Dias Semanas Meses Ano}
|
22
|
+
TipoFrete = %w{Proprio Correio}
|
23
|
+
TipoIdentidade = %w{CPF CNPJ}
|
24
|
+
TipoInstrucao = %w{Unico Recorrente PrePago PosPago Remessa}
|
25
|
+
TipoLembrete = %w{Email SMS}
|
26
|
+
TipoPeriodicidade = %w{Anual Mensal Semanal Diaria}
|
27
|
+
TipoRecebimento = %w{AVista Parcelado}
|
28
|
+
TipoRestricao = %w{Autorizacao Pagamento}
|
29
|
+
TipoStatus = %w{Sucesso Falha}
|
30
|
+
|
31
|
+
#
|
32
|
+
TiposComInstituicao = %w{CartaoCredito CartaoCredito DebitoBancario}
|
33
|
+
|
34
|
+
class DirectPayment
|
35
|
+
|
36
|
+
class << self
|
37
|
+
|
38
|
+
# Cria uma instrução de pagamento direto
|
39
|
+
def body(attributes = {})
|
40
|
+
|
41
|
+
#raise "#{attributes[:valor]}--#{attributes[:valor].to_f}"
|
42
|
+
raise(MissingPaymentTypeError, "É necessário informar a razão do pagamento") if attributes[:razao].nil?
|
43
|
+
raise(MissingPayerError, "É obrigatório passar as informarções do pagador") if attributes[:pagador].nil?
|
44
|
+
|
45
|
+
raise(InvalidValue, "Valor deve ser maior que zero.") if attributes[:valor].to_f <= 0.0
|
46
|
+
raise(InvalidPhone, "Telefone deve ter o formato (99)9999-9999.") if attributes[:pagador][:tel_fixo] !~ /\(\d{2}\)?\d{4}-\d{4}/
|
47
|
+
raise(InvalidCellphone, "Telefone celular deve ter o formato (99)9999-9999.") if attributes[:pagador][:tel_cel] !~ /\(\d{2}\)?\d{4}-\d{4}/
|
48
|
+
|
49
|
+
raise(MissingBirthdate, "É obrigatório passar as informarções do pagador") if TiposComInstituicao.include?(attributes[:forma]) && attributes[:data_nascimento].nil?
|
50
|
+
|
51
|
+
raise(InvalidExpiry, "Data de expiração deve ter o formato 01-00 até 12-99.") if TiposComInstituicao.include?(attributes[:forma]) && attributes[:expiracao] !~ /(1[0-2]|0\d)\/\d{2}/
|
52
|
+
|
53
|
+
|
54
|
+
raise(InvalidReceiving, "Recebimento é inválido. Escolha um destes: #{TipoRecebimento.join(', ')}") if !TipoRecebimento.include?(attributes[:recebimento]) && TiposComInstituicao.include?(attributes[:forma])
|
55
|
+
|
56
|
+
raise(InvalidInstitution, "A instituição #{attributes[:instituicao]} é inválida. Escolha uma destas: #{InstituicaoPagamento.join(', ')}") if TiposComInstituicao.include?(attributes[:forma]) && !InstituicaoPagamento.include?(attributes[:instituicao])
|
57
|
+
|
58
|
+
builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
|
59
|
+
|
60
|
+
# Identificador do tipo de instrução
|
61
|
+
xml.EnviarInstrucao {
|
62
|
+
xml.InstrucaoUnica {
|
63
|
+
|
64
|
+
# Dados da transação
|
65
|
+
xml.Razao {
|
66
|
+
xml.text attributes[:razao]
|
67
|
+
}
|
68
|
+
xml.Valores {
|
69
|
+
xml.Valor(:moeda => "BRL") {
|
70
|
+
xml.text attributes[:valor]
|
71
|
+
}
|
72
|
+
}
|
73
|
+
xml.IdProprio {
|
74
|
+
xml.text attributes[:id_proprio]
|
75
|
+
}
|
76
|
+
|
77
|
+
# Definindo o pagamento direto
|
78
|
+
xml.PagamentoDireto {
|
79
|
+
xml.Forma {
|
80
|
+
xml.text attributes[:forma]
|
81
|
+
}
|
82
|
+
|
83
|
+
# Débito Bancário
|
84
|
+
if ["DebitoBancario"].include?(attributes[:forma])
|
85
|
+
xml.Instituicao {
|
86
|
+
xml.text attributes[:instituicao]
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
# Cartão de Crédito
|
91
|
+
if attributes[:forma] == "CartaoCredito"
|
92
|
+
xml.Instituicao {
|
93
|
+
xml.text attributes[:instituicao]
|
94
|
+
}
|
95
|
+
xml.CartaoCredito {
|
96
|
+
xml.Numero {
|
97
|
+
xml.text attributes[:numero]
|
98
|
+
}
|
99
|
+
xml.Expiracao {
|
100
|
+
xml.text attributes[:expiracao]
|
101
|
+
}
|
102
|
+
xml.CodigoSeguranca {
|
103
|
+
xml.text attributes[:codigo_seguranca]
|
104
|
+
}
|
105
|
+
xml.Portador {
|
106
|
+
xml.Nome {
|
107
|
+
xml.text attributes[:nome]
|
108
|
+
}
|
109
|
+
xml.Identidade(:Tipo => "CPF") {
|
110
|
+
xml.text attributes[:identidade]
|
111
|
+
}
|
112
|
+
xml.Telefone {
|
113
|
+
xml.text attributes[:telefone]
|
114
|
+
}
|
115
|
+
xml.DataNascimento {
|
116
|
+
xml.text attributes[:data_nascimento]
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
xml.Parcelamento {
|
121
|
+
xml.Parcelas {
|
122
|
+
xml.text attributes[:parcelas]
|
123
|
+
}
|
124
|
+
xml.Recebimento {
|
125
|
+
xml.text attributes[:recebimento]
|
126
|
+
}
|
127
|
+
}
|
128
|
+
end
|
129
|
+
}
|
130
|
+
|
131
|
+
# Dados do pagador
|
132
|
+
xml.Pagador {
|
133
|
+
xml.Nome { xml.text attributes[:pagador][:nome] }
|
134
|
+
xml.LoginMoIP { xml.text attributes[:pagador][:login_moip] }
|
135
|
+
xml.Email { xml.text attributes[:pagador][:email] }
|
136
|
+
xml.TelefoneCelular { xml.text attributes[:pagador][:tel_cel] }
|
137
|
+
xml.Apelido { xml.text attributes[:pagador][:apelido] }
|
138
|
+
xml.Identidade(:Tipo => "CPF") { xml.text attributes[:pagador][:identidade] }
|
139
|
+
xml.EnderecoCobranca {
|
140
|
+
xml.Logradouro { xml.text attributes[:pagador][:logradouro] }
|
141
|
+
xml.Numero { xml.text attributes[:pagador][:numero] }
|
142
|
+
xml.Complemento { xml.text attributes[:pagador][:complemento] }
|
143
|
+
xml.Bairro { xml.text attributes[:pagador][:bairro] }
|
144
|
+
xml.Cidade { xml.text attributes[:pagador][:cidade] }
|
145
|
+
xml.Estado { xml.text attributes[:pagador][:estado] }
|
146
|
+
xml.Pais { xml.text attributes[:pagador][:pais] }
|
147
|
+
xml.CEP { xml.text attributes[:pagador][:cep] }
|
148
|
+
xml.TelefoneFixo { xml.text attributes[:pagador][:tel_fixo] }
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
# Boleto Bancario
|
153
|
+
if attributes[:forma] == "BoletoBancario"
|
154
|
+
# Dados extras
|
155
|
+
xml.Boleto {
|
156
|
+
xml.DiasExpiracao(:Tipo => "Corridos") {
|
157
|
+
xml.text attributes[:dias_expiracao]
|
158
|
+
}
|
159
|
+
xml.Instrucao1 {
|
160
|
+
xml.text attributes[:instrucao_1]
|
161
|
+
}
|
162
|
+
xml.URLLogo {
|
163
|
+
xml.text attributes[:url_logo]
|
164
|
+
}
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
if attributes[:url_retorno]
|
169
|
+
# URL de retorno
|
170
|
+
xml.URLRetorno {
|
171
|
+
xml.text attributes[:url_retorno]
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
}
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
builder.to_xml
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
data/moip.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = %q{marnen-moip}
|
5
|
+
gem.version = "1.0.2-39f9dab38fc33fe9bf614deb8e90ca166ab2d6bf"
|
6
|
+
|
7
|
+
gem.authors = ["Guilherme Nascimento", 'Marnen Laibow-Koser']
|
8
|
+
gem.date = %q{2010-11-10}
|
9
|
+
gem.description = %q{Gem para utilização da API MoIP}
|
10
|
+
gem.email = ['guilherme.ruby@gmail.com', 'marnen@marnen.org']
|
11
|
+
gem.summary = %q{Gem para utilização da API MoIP}
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- spec/*.rb`.split("\n")
|
15
|
+
|
16
|
+
gem.homepage = %q{http://github.com/marnen/moip-ruby}
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.rdoc_options = ["--charset=UTF-8"]
|
20
|
+
gem.extra_rdoc_files = [ "LICENSE", "README.markdown"]
|
21
|
+
|
22
|
+
gem.add_development_dependency(%q<rspec>, [">= 2.1.0"])
|
23
|
+
|
24
|
+
gem.add_runtime_dependency(%q<nokogiri>, ["~> 1.5.0"])
|
25
|
+
gem.add_runtime_dependency(%q<httparty>, ["~> 0.6.1"])
|
26
|
+
gem.add_runtime_dependency(%q<activesupport>, [">= 2.3.2"])
|
27
|
+
end
|
data/spec/moip_spec.rb
ADDED
@@ -0,0 +1,465 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "moip"
|
3
|
+
require "digest/sha1"
|
4
|
+
|
5
|
+
MoIP::Client
|
6
|
+
MoIP::DirectPayment
|
7
|
+
|
8
|
+
describe "Make payments with the MoIP API" do
|
9
|
+
let(:id){ '1' }
|
10
|
+
|
11
|
+
before :all do
|
12
|
+
|
13
|
+
@pagador = { :nome => "Luiz Inácio Lula da Silva",
|
14
|
+
:login_moip => "lula",
|
15
|
+
:email => "presidente@planalto.gov.br",
|
16
|
+
:tel_cel => "(61)9999-9999",
|
17
|
+
:apelido => "Lula",
|
18
|
+
:identidade => "111.111.111-11",
|
19
|
+
:logradouro => "Praça dos Três Poderes",
|
20
|
+
:numero => "0",
|
21
|
+
:complemento => "Palácio do Planalto",
|
22
|
+
:bairro => "Zona Cívico-Administrativa",
|
23
|
+
:cidade => "Brasília",
|
24
|
+
:estado => "DF",
|
25
|
+
:pais => "BRA",
|
26
|
+
:cep => "70100-000",
|
27
|
+
:tel_fixo => "(61)3211-1221" }
|
28
|
+
|
29
|
+
@billet_without_razao = { :valor => "8.90", :id_proprio => id,
|
30
|
+
:forma => "BoletoBancario", :pagador => @pagador}
|
31
|
+
@billet = { :valor => "8.90", :id_proprio => id,
|
32
|
+
:forma => "BoletoBancario", :pagador => @pagador ,
|
33
|
+
:razao=> "Pagamento" }
|
34
|
+
|
35
|
+
@debit = { :valor => "8.90", :id_proprio => id, :forma => "DebitoBancario",
|
36
|
+
:instituicao => "BancoDoBrasil", :pagador => @pagador,
|
37
|
+
:razao => "Pagamento"}
|
38
|
+
|
39
|
+
@credit = { :valor => "8.90", :id_proprio => id, :forma => "CartaoCredito",
|
40
|
+
:instituicao => "AmericanExpress",:numero => "345678901234564",
|
41
|
+
:expiracao => "08/11", :codigo_seguranca => "1234",
|
42
|
+
:nome => "João Silva", :identidade => "134.277.017.00",
|
43
|
+
:telefone => "(21)9208-0547", :data_nascimento => "25/10/1980",
|
44
|
+
:parcelas => "2", :recebimento => "AVista",
|
45
|
+
:pagador => @pagador, :razao => "Pagamento"}
|
46
|
+
end
|
47
|
+
|
48
|
+
context "misconfigured" do
|
49
|
+
it "should raise a missing config error " do
|
50
|
+
MoIP.setup do |config|
|
51
|
+
config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
52
|
+
config.token = nil
|
53
|
+
config.key = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
MoIP::Client # for autoload
|
57
|
+
lambda { MoIP::Client.checkout(@billet) }.should raise_error(MoIP::MissingConfigError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should raise a missing token error when token is nil" do
|
61
|
+
MoIP.setup do |config|
|
62
|
+
config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
63
|
+
config.token = nil
|
64
|
+
config.key = 'key'
|
65
|
+
end
|
66
|
+
|
67
|
+
MoIP::Client # for autoload
|
68
|
+
lambda { MoIP::Client.checkout(@billet) }.should raise_error(MoIP::MissingTokenError)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise a missing key error when key is nil" do
|
72
|
+
|
73
|
+
MoIP.setup do |config|
|
74
|
+
config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
75
|
+
config.token = 'token'
|
76
|
+
config.key = nil
|
77
|
+
end
|
78
|
+
|
79
|
+
MoIP::Client # for autoload
|
80
|
+
lambda { MoIP::Client.checkout(@billet) }.should raise_error(MoIP::MissingKeyError)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
it "should raise a missing token error when token is empty" do
|
86
|
+
MoIP.setup do |config|
|
87
|
+
config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
88
|
+
config.token = ''
|
89
|
+
config.key = 'key'
|
90
|
+
end
|
91
|
+
|
92
|
+
MoIP::Client # for autoload
|
93
|
+
lambda { MoIP::Client.checkout(@billet) }.should raise_error(MoIP::MissingTokenError)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should raise a missing key error when key is empty" do
|
97
|
+
|
98
|
+
MoIP.setup do |config|
|
99
|
+
config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
100
|
+
config.token = 'token'
|
101
|
+
config.key = ''
|
102
|
+
end
|
103
|
+
|
104
|
+
MoIP::Client # for autoload
|
105
|
+
lambda { MoIP::Client.checkout(@billet) }.should raise_error(MoIP::MissingKeyError)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "validations" do
|
110
|
+
|
111
|
+
|
112
|
+
before(:each) do
|
113
|
+
MoIP.setup do |config|
|
114
|
+
config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
115
|
+
config.token = 'token'
|
116
|
+
config.key = 'key'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
it "should raise invalid phone" do
|
120
|
+
@data = @credit.merge({:pagador => {:tel_fixo => 'InvalidPhone', :tel_cel => "(61)9999-9999"}})
|
121
|
+
lambda { MoIP::Client.checkout(@data) }.should raise_error(MoIP::InvalidPhone)
|
122
|
+
end
|
123
|
+
it "should raise invalid cellphone" do
|
124
|
+
@data = @credit.merge({:pagador => {:tel_cel => 'InvalidCellphone', :tel_fixo => "(61)9999-9999"}})
|
125
|
+
lambda { MoIP::Client.checkout(@data) }.should raise_error(MoIP::InvalidCellphone)
|
126
|
+
end
|
127
|
+
it "should raise invalid expiry" do
|
128
|
+
@data = @credit.merge({:expiracao => 'InvalidExpiry'})
|
129
|
+
lambda { MoIP::Client.checkout(@data) }.should raise_error(MoIP::InvalidExpiry)
|
130
|
+
end
|
131
|
+
it "should raise missing birthdate" do
|
132
|
+
@data = @credit.merge({:data_nascimento => nil})
|
133
|
+
lambda { MoIP::Client.checkout(@data) }.should raise_error(MoIP::MissingBirthdate)
|
134
|
+
end
|
135
|
+
it "should raise invalid institution error" do
|
136
|
+
@data = @credit.merge({:instituicao => 'InvalidInstitution'})
|
137
|
+
lambda { MoIP::Client.checkout(@data) }.should raise_error(MoIP::InvalidInstitution)
|
138
|
+
end
|
139
|
+
it "should raise invalid receiving error" do
|
140
|
+
@data = @credit.merge({:recebimento => 'InvalidReceiving'})
|
141
|
+
lambda { MoIP::Client.checkout(@data) }.should raise_error(MoIP::InvalidReceiving)
|
142
|
+
end
|
143
|
+
it "should raise invalid value error if 0" do
|
144
|
+
@credit[:valor] = 0
|
145
|
+
lambda { MoIP::Client.checkout(@credit) }.should raise_error(MoIP::InvalidValue)
|
146
|
+
end
|
147
|
+
it "should raise invalid value error if '0'" do
|
148
|
+
@credit[:valor] = '0'
|
149
|
+
lambda { MoIP::Client.checkout(@credit) }.should raise_error(MoIP::InvalidValue)
|
150
|
+
end
|
151
|
+
it "should raise invalid value error if 0.0" do
|
152
|
+
@credit[:valor] = 0.0
|
153
|
+
lambda { MoIP::Client.checkout(@credit) }.should raise_error(MoIP::InvalidValue)
|
154
|
+
end
|
155
|
+
it "should raise invalid value error if '0.0'" do
|
156
|
+
@credit[:valor] = '0.0'
|
157
|
+
lambda { MoIP::Client.checkout(@credit) }.should raise_error(MoIP::InvalidValue)
|
158
|
+
end
|
159
|
+
it "should raise invalid value error if -1" do
|
160
|
+
@credit[:valor] = -1
|
161
|
+
lambda { MoIP::Client.checkout(@credit) }.should raise_error(MoIP::InvalidValue)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
#
|
165
|
+
# context "checkout" do
|
166
|
+
# before(:each) do
|
167
|
+
# MoIP.setup do |config|
|
168
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
169
|
+
# config.token = 'token'
|
170
|
+
# config.key = 'key'
|
171
|
+
# end
|
172
|
+
# MoIP::Client.stub!(:post).
|
173
|
+
# and_return("ns1:EnviarInstrucaoUnicaResponse"=>
|
174
|
+
# { "Resposta"=>
|
175
|
+
# { "ID"=>Time.now.strftime("%y%m%d%H%M%S"),
|
176
|
+
# "Status"=>"Sucesso",
|
177
|
+
# "Token" => "T2N0L0X8E0S71217U2H3W1T4F4S4G4K731D010V0S0V0S080M010E0Q082X2"
|
178
|
+
# }
|
179
|
+
# })
|
180
|
+
# end
|
181
|
+
#
|
182
|
+
# it "with old api should be deprecated" do
|
183
|
+
# deprecations = collect_deprecations{ MoIP.checkout(@billet) }
|
184
|
+
#
|
185
|
+
# deprecations.should_not be_empty
|
186
|
+
# deprecations.any? {|w| w =~ /MoIP.checkout has been deprecated/ }.should be_true
|
187
|
+
# end
|
188
|
+
#
|
189
|
+
# context "when it is a billet checkout" do
|
190
|
+
# before(:each) do
|
191
|
+
# MoIP.setup do |config|
|
192
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
193
|
+
# config.token = 'token'
|
194
|
+
# config.key = 'key'
|
195
|
+
# end
|
196
|
+
# end
|
197
|
+
# it "should raise an exception when razao parameter is not passed" do
|
198
|
+
# error = "É necessário informar a razão do pagamento"
|
199
|
+
#
|
200
|
+
# lambda { MoIP::Client.checkout(@billet_without_razao) }.should raise_error(MoIP::MissingPaymentTypeError,error)
|
201
|
+
# end
|
202
|
+
#
|
203
|
+
# it "should have status 'Sucesso'" do
|
204
|
+
# response = MoIP::Client.checkout(@billet)
|
205
|
+
# response["Status"].should == "Sucesso"
|
206
|
+
# end
|
207
|
+
# end
|
208
|
+
#
|
209
|
+
# context "when it is a debit checkout" do
|
210
|
+
# before(:each) do
|
211
|
+
# MoIP.setup do |config|
|
212
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
213
|
+
# config.token = 'token'
|
214
|
+
# config.key = 'key'
|
215
|
+
# end
|
216
|
+
# end
|
217
|
+
# it "should have status 'Sucesso' with valid arguments" do
|
218
|
+
# response = MoIP::Client.checkout(@debit)
|
219
|
+
# response["Status"].should == "Sucesso"
|
220
|
+
# end
|
221
|
+
#
|
222
|
+
# it "should have status 'Falha' when a instituition is not passed as argument" do
|
223
|
+
# @incorrect_debit = { :valor => "37.90", :id_proprio => id,
|
224
|
+
# :forma => "DebitoBancario", :pagador => @pagador,
|
225
|
+
# :razao => "Pagamento"}
|
226
|
+
#
|
227
|
+
# error = "Pagamento direto não é possível com a instituição de pagamento enviada"
|
228
|
+
#
|
229
|
+
# MoIP::Client.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>
|
230
|
+
# { "Resposta"=>
|
231
|
+
# {
|
232
|
+
# "Status"=>"Falha",
|
233
|
+
# "Erro"=>error
|
234
|
+
# }
|
235
|
+
# })
|
236
|
+
# error = "Pagamento direto não é possível com a instituição de pagamento enviada"
|
237
|
+
# lambda { MoIP::Client.checkout(@incorrect_debit) }.should
|
238
|
+
# raise_error(MoIP::WebServerResponseError, error)
|
239
|
+
# end
|
240
|
+
#
|
241
|
+
# it "should raise an exception if payer informations were not passed" do
|
242
|
+
# @incorrect_debit = { :valor => "37.90", :id_proprio => id,
|
243
|
+
# :forma => "DebitoBancario",
|
244
|
+
# :instituicao => "BancoDoBrasil",
|
245
|
+
# :razao => "Pagamento"
|
246
|
+
# }
|
247
|
+
#
|
248
|
+
# lambda { MoIP::Client.checkout(@incorrect_debit) }.should
|
249
|
+
# raise_error(MoIP::MissingPayerError, "É obrigatório passar as informações do pagador")
|
250
|
+
# end
|
251
|
+
# end
|
252
|
+
#
|
253
|
+
# context "when it is a credit card checkout" do
|
254
|
+
# before(:each) do
|
255
|
+
# MoIP.setup do |config|
|
256
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
257
|
+
# config.token = 'token'
|
258
|
+
# config.key = 'key'
|
259
|
+
# end
|
260
|
+
# end
|
261
|
+
# it "should have status 'Sucesso' with valid arguments" do
|
262
|
+
# response = MoIP::Client.checkout(@credit)
|
263
|
+
# response["Status"].should == "Sucesso"
|
264
|
+
# end
|
265
|
+
#
|
266
|
+
# it "should have status 'Falha' when the card informations were not passed as argument" do
|
267
|
+
# @incorrect_credit = { :valor => "8.90", :id_proprio => id,
|
268
|
+
# :forma => "CartaoCredito", :pagador => @pagador,
|
269
|
+
# :razao => "Pagamento"
|
270
|
+
# }
|
271
|
+
#
|
272
|
+
# error = "Pagamento direto não é possível com a instituição de pagamento enviada"
|
273
|
+
# MoIP::Client.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>
|
274
|
+
# {
|
275
|
+
# "Resposta"=>
|
276
|
+
# {
|
277
|
+
# "Status"=>"Falha",
|
278
|
+
# "Erro"=>error
|
279
|
+
# }
|
280
|
+
# })
|
281
|
+
#
|
282
|
+
# error = "Pagamento direto não é possível com a instituição de pagamento enviada"
|
283
|
+
# lambda { MoIP::Client.checkout(@incorrect_credit) }.should
|
284
|
+
# raise_error(MoIP::WebServerResponseError, error)
|
285
|
+
# end
|
286
|
+
# end
|
287
|
+
#
|
288
|
+
# context "in error scenario" do
|
289
|
+
# before(:each) do
|
290
|
+
# MoIP.setup do |config|
|
291
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
292
|
+
# config.token = 'token'
|
293
|
+
# config.key = 'key'
|
294
|
+
# end
|
295
|
+
# end
|
296
|
+
# it "should raise an exception if response is nil" do
|
297
|
+
# MoIP::Client.stub!(:post).and_return(nil)
|
298
|
+
# lambda { MoIP::Client.checkout(@billet) }.should
|
299
|
+
# raise_error(StandardError,"Ocorreu um erro ao chamar o webservice")
|
300
|
+
# end
|
301
|
+
#
|
302
|
+
# it "should raise an exception if status is fail" do
|
303
|
+
# MoIP::Client.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>
|
304
|
+
# { "Resposta"=>
|
305
|
+
# {"Status"=>"Falha",
|
306
|
+
# "Erro"=>"O status da resposta é Falha"
|
307
|
+
# }
|
308
|
+
# })
|
309
|
+
#
|
310
|
+
# lambda { MoIP::Client.checkout(@billet) }.should raise_error(StandardError, "O status da resposta é Falha")
|
311
|
+
# end
|
312
|
+
# end
|
313
|
+
# end
|
314
|
+
#
|
315
|
+
# context "query a transaction token" do
|
316
|
+
#
|
317
|
+
# before(:each) do
|
318
|
+
#
|
319
|
+
# MoIP.setup do |config|
|
320
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
321
|
+
# config.token = 'token'
|
322
|
+
# config.key = 'key'
|
323
|
+
# end
|
324
|
+
# MoIP::Client.stub!(:get).and_return("ns1:ConsultarTokenResponse"=>
|
325
|
+
# { "RespostaConsultar"=>
|
326
|
+
# {"Status"=>"Sucesso",
|
327
|
+
# "ID"=>"201010291031001210000000046760"
|
328
|
+
# }
|
329
|
+
# })
|
330
|
+
# end
|
331
|
+
#
|
332
|
+
# it "with old api should be deprecated" do
|
333
|
+
# deprecations = collect_deprecations{ MoIP.query(token) }
|
334
|
+
#
|
335
|
+
# deprecations.should_not be_empty
|
336
|
+
# deprecations.any? {|w| w =~ /MoIP.query has been deprecated/ }.should be_true
|
337
|
+
# end
|
338
|
+
#
|
339
|
+
# it "should retrieve the transaction" do
|
340
|
+
# response = MoIP::Client.query(token)
|
341
|
+
# response["Status"].should == "Sucesso"
|
342
|
+
# end
|
343
|
+
#
|
344
|
+
# context "in a error scenario" do
|
345
|
+
# before(:each) do
|
346
|
+
# MoIP.setup do |config|
|
347
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
348
|
+
# config.token = 'token'
|
349
|
+
# config.key = 'key'
|
350
|
+
# end
|
351
|
+
# end
|
352
|
+
# it "should retrieve status 'Falha'" do
|
353
|
+
# MoIP::Client.stub!(:get).and_return("ns1:ConsultarTokenResponse"=>
|
354
|
+
# { "RespostaConsultar"=>
|
355
|
+
# {"Status"=>"Falha",
|
356
|
+
# "Erro"=>"Instrução não encontrada",
|
357
|
+
# "ID"=>"201010291102522860000000046768"
|
358
|
+
# }
|
359
|
+
# })
|
360
|
+
# query = "000000000000000000000000000000000000000000000000000000000000"
|
361
|
+
# lambda { MoIP::Client.query(query) }.should raise_error(StandardError, "Instrução não encontrada")
|
362
|
+
# end
|
363
|
+
# end
|
364
|
+
# end
|
365
|
+
#
|
366
|
+
# context "build the MoIP URL" do
|
367
|
+
# before(:each) do
|
368
|
+
# MoIP.setup do |config|
|
369
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
370
|
+
# config.token = 'token'
|
371
|
+
# config.key = 'key'
|
372
|
+
# end
|
373
|
+
# end
|
374
|
+
# it "with old api should be deprecated" do
|
375
|
+
# deprecations = collect_deprecations{ MoIP.moip_page(token) }
|
376
|
+
#
|
377
|
+
# deprecations.should_not be_empty
|
378
|
+
# deprecations.any? {|w| w =~ /MoIP.moip_page has been deprecated/ }.should be_true
|
379
|
+
# end
|
380
|
+
#
|
381
|
+
# it "should build the correct URL" do
|
382
|
+
# page = "https://desenvolvedor.moip.com.br/sandbox/Instrucao.do?token=#{token}"
|
383
|
+
# MoIP::Client.moip_page(token).should == page
|
384
|
+
# end
|
385
|
+
#
|
386
|
+
# it "should raise an error if the token is not informed" do
|
387
|
+
# error = "É necessário informar um token para retornar os dados da transação"
|
388
|
+
# lambda { MoIP::Client.moip_page("").should
|
389
|
+
# raise_error(ArgumentError, error) }
|
390
|
+
# end
|
391
|
+
#
|
392
|
+
# it "should raise an error if nil is passed as the token" do
|
393
|
+
# error = "É necessário informar um token para retornar os dados da transação"
|
394
|
+
# lambda { MoIP::Client.moip_page(nil).should
|
395
|
+
# raise_error(ArgumentError, error) }
|
396
|
+
# end
|
397
|
+
#
|
398
|
+
# it "should raise a missing token error if nil is passed as the token" do
|
399
|
+
# lambda { MoIP::Client.moip_page(nil).should raise_error(MissingTokenError) }
|
400
|
+
# end
|
401
|
+
#
|
402
|
+
# it "should raise a missing token error if an empty string is passed as the token" do
|
403
|
+
# lambda { MoIP::Client.moip_page("").should raise_error(MissingTokenError) }
|
404
|
+
# end
|
405
|
+
# end
|
406
|
+
#
|
407
|
+
# context "when receive notification" do
|
408
|
+
# before(:each) do
|
409
|
+
# MoIP.setup do |config|
|
410
|
+
# config.uri = 'https://desenvolvedor.moip.com.br/sandbox'
|
411
|
+
# config.token = 'token'
|
412
|
+
# config.key = 'key'
|
413
|
+
# end
|
414
|
+
# @params = { "id_transacao" => "Pag62", "valor" => "8.90",
|
415
|
+
# "status_pagamento" => "3", "cod_moip" => "001",
|
416
|
+
# "forma_pagamento" => "73", "tipo_pagamento" => "BoletoBancario",
|
417
|
+
# "email_consumidor" => "presidente@planalto.gov.br" }
|
418
|
+
# end
|
419
|
+
#
|
420
|
+
# it "with old api should be deprecated" do
|
421
|
+
# deprecations = collect_deprecations{ MoIP.notification(@param) }
|
422
|
+
#
|
423
|
+
# deprecations.should_not be_empty
|
424
|
+
# deprecations.any? {|w| w =~ /MoIP.notification has been deprecated/ }.should be_true
|
425
|
+
# end
|
426
|
+
#
|
427
|
+
# it "should return a hash with the params extracted from NASP" do
|
428
|
+
# response = { :transaction_id => "Pag62", :amount => "8.90",
|
429
|
+
# :status => "printed", :code => "001",
|
430
|
+
# :payment_type => "BoletoBancario",
|
431
|
+
# :email => "presidente@planalto.gov.br" }
|
432
|
+
#
|
433
|
+
# MoIP::Client.notification(@params).should == response
|
434
|
+
# end
|
435
|
+
#
|
436
|
+
# it "should return valid status based on status code" do
|
437
|
+
# MoIP::STATUS[1].should == "authorized"
|
438
|
+
# MoIP::STATUS[2].should == "started"
|
439
|
+
# MoIP::STATUS[3].should == "printed"
|
440
|
+
# MoIP::STATUS[4].should == "completed"
|
441
|
+
# MoIP::STATUS[5].should == "canceled"
|
442
|
+
# MoIP::STATUS[6].should == "analysing"
|
443
|
+
# end
|
444
|
+
# end
|
445
|
+
#
|
446
|
+
# def id
|
447
|
+
# "transaction_" + Digest::SHA1.hexdigest([Time.now, rand].join)
|
448
|
+
# end
|
449
|
+
#
|
450
|
+
# def token
|
451
|
+
# "T2X0Q1N021E0B2S9U1P0V3Y0G1F570Y2P4M0P000M0Z0F0J0G0U4N6C7W5T9"
|
452
|
+
# end
|
453
|
+
#
|
454
|
+
# def collect_deprecations
|
455
|
+
# old_behavior = ActiveSupport::Deprecation.behavior
|
456
|
+
# deprecations = []
|
457
|
+
# ActiveSupport::Deprecation.behavior = Proc.new do |message, callstack|
|
458
|
+
# deprecations << message
|
459
|
+
# end
|
460
|
+
# result = yield
|
461
|
+
# deprecations
|
462
|
+
# ensure
|
463
|
+
# ActiveSupport::Deprecation.behavior = old_behavior
|
464
|
+
# end
|
465
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marnen-moip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2.pre.39f9dab38fc33fe9bf614deb8e90ca166ab2d6bf
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guilherme Nascimento
|
8
|
+
- Marnen Laibow-Koser
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2010-11-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.1.0
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.1.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: nokogiri
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.5.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.5.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: httparty
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.6.1
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.1
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activesupport
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.3.2
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.3.2
|
70
|
+
description: Gem para utilização da API MoIP
|
71
|
+
email:
|
72
|
+
- guilherme.ruby@gmail.com
|
73
|
+
- marnen@marnen.org
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files:
|
77
|
+
- LICENSE
|
78
|
+
- README.markdown
|
79
|
+
files:
|
80
|
+
- .document
|
81
|
+
- .gitignore
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- LICENSE
|
85
|
+
- README.markdown
|
86
|
+
- Rakefile
|
87
|
+
- VERSION
|
88
|
+
- lib/moip.rb
|
89
|
+
- lib/moip/client.rb
|
90
|
+
- lib/moip/direct_payment.rb
|
91
|
+
- moip.gemspec
|
92
|
+
- spec/moip_spec.rb
|
93
|
+
homepage: http://github.com/marnen/moip-ruby
|
94
|
+
licenses: []
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- --charset=UTF-8
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>'
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.3.1
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.1.11
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Gem para utilização da API MoIP
|
117
|
+
test_files:
|
118
|
+
- spec/moip_spec.rb
|