moip 1.0.1
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.
- data/.document +5 -0
- data/.gitignore +24 -0
- data/LICENSE +20 -0
- data/README.markdown +79 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/direct_payment.rb +130 -0
- data/lib/moip.rb +61 -0
- data/moip.gemspec +51 -0
- data/spec/lib/config.yaml +14 -0
- data/spec/lib/moip_spec.rb +125 -0
- metadata +78 -0
data/.document
ADDED
data/.gitignore
ADDED
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,79 @@
|
|
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, crie o arquivo moip.yml na pasta Rails.root/config e adicione o token e chave do MoIP.
|
28
|
+
|
29
|
+
## moip.yml
|
30
|
+
|
31
|
+
development:
|
32
|
+
uri: https://desenvolvedor.moip.com.br/sandbox
|
33
|
+
token: SEU_TOKEN
|
34
|
+
key: SUA_KEY
|
35
|
+
|
36
|
+
production:
|
37
|
+
uri:
|
38
|
+
token:
|
39
|
+
key:
|
40
|
+
|
41
|
+
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 o token e chave de produção no arquivo moip.yml.
|
42
|
+
|
43
|
+
###Crie os dados do pagador
|
44
|
+
|
45
|
+
pagador = { :nome => "Luiz Inácio Lula da Silva",
|
46
|
+
:login_moip => "lula",
|
47
|
+
:email => "presidente@planalto.gov.br",
|
48
|
+
:tel_cel => "(61)9999-9999",
|
49
|
+
:apelido => "Lula",
|
50
|
+
:identidade => "111.111.111-11",
|
51
|
+
:logradouro => "Praça dos Três Poderes",
|
52
|
+
:numero => "0",
|
53
|
+
:complemento => "Palácio do Planalto",
|
54
|
+
:bairro => "Zona Cívico-Administrativa",
|
55
|
+
:cidade => "Brasília",
|
56
|
+
:estado => "DF",
|
57
|
+
:pais => "BRA",
|
58
|
+
:cep => "70100-000",
|
59
|
+
:tel_fixo => "(61)3211-1221" }
|
60
|
+
|
61
|
+
###Dados do boleto
|
62
|
+
|
63
|
+
boleto = { :valor => "50",
|
64
|
+
:id_proprio => "Pag#{rand(1000)}",
|
65
|
+
:forma => "BoletoBancario",
|
66
|
+
:dias_expiracao => 5,
|
67
|
+
:pagador => pagador }
|
68
|
+
|
69
|
+
###Checkout
|
70
|
+
|
71
|
+
def checkout
|
72
|
+
response = MoIP.checkout(boleto)
|
73
|
+
|
74
|
+
# exibe o boleto para impressão
|
75
|
+
redirect_to MoIP.moip_page(response["Token"])
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
Baseado no projeto do [Daniel Lopes](http://github.com/danielvlopes/moip_usage).
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "moip"
|
8
|
+
gem.summary = %Q{Gem para utilização da API MoIP}
|
9
|
+
gem.description = %Q{Gem para utilização da API MoIP}
|
10
|
+
gem.email = "guilherme.ruby@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/guinascimento/moip"
|
12
|
+
gem.authors = ["Guilherme Nascimento"]
|
13
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "moip #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
54
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module MoIP
|
2
|
+
|
3
|
+
class DirectPayment
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
# Cria uma instrução de pagamento direto
|
8
|
+
def direct(attributes = {})
|
9
|
+
builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
|
10
|
+
|
11
|
+
# Identificador do tipo de instrução
|
12
|
+
xml.EnviarInstrucao {
|
13
|
+
xml.InstrucaoUnica {
|
14
|
+
# Dados da transação
|
15
|
+
xml.Razao {
|
16
|
+
xml.text "Pagamento"
|
17
|
+
}
|
18
|
+
xml.Valores {
|
19
|
+
xml.Valor(:moeda => "BRL") {
|
20
|
+
xml.text attributes[:valor]
|
21
|
+
}
|
22
|
+
}
|
23
|
+
xml.IdProprio {
|
24
|
+
xml.text attributes[:id_proprio]
|
25
|
+
}
|
26
|
+
|
27
|
+
# Definindo o pagamento direto
|
28
|
+
xml.PagamentoDireto {
|
29
|
+
xml.Forma {
|
30
|
+
xml.text attributes[:forma]
|
31
|
+
}
|
32
|
+
|
33
|
+
# Débito Bancário
|
34
|
+
if attributes[:forma] == "DebitoBancario"
|
35
|
+
xml.Instituicao {
|
36
|
+
xml.text attributes[:instituicao]
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Cartão de Crédito
|
41
|
+
if attributes[:forma] == "CartaoCredito"
|
42
|
+
xml.Instituicao {
|
43
|
+
xml.text attributes[:instituicao]
|
44
|
+
}
|
45
|
+
|
46
|
+
xml.CartaoCredito {
|
47
|
+
xml.Numero {
|
48
|
+
xml.text attributes[:numero]
|
49
|
+
}
|
50
|
+
xml.Expiracao {
|
51
|
+
xml.text attributes[:expiracao]
|
52
|
+
}
|
53
|
+
xml.CodigoSeguranca {
|
54
|
+
xml.text attributes[:codigo_seguranca]
|
55
|
+
}
|
56
|
+
xml.Portador {
|
57
|
+
xml.Nome {
|
58
|
+
xml.text attributes[:nome]
|
59
|
+
}
|
60
|
+
xml.Identidade(:Tipo => "CPF") {
|
61
|
+
xml.text attributes[:identidade]
|
62
|
+
}
|
63
|
+
xml.Telefone {
|
64
|
+
xml.text attributes[:telefone]
|
65
|
+
}
|
66
|
+
xml.DataNascimento {
|
67
|
+
xml.text attributes[:data_nascimento]
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
xml.Parcelamento {
|
72
|
+
xml.Parcelas {
|
73
|
+
xml.text attributes[:parcelas]
|
74
|
+
}
|
75
|
+
xml.Recebimento {
|
76
|
+
xml.text attributes[:recebimento]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
}
|
81
|
+
|
82
|
+
# Dados do pagador
|
83
|
+
raise(StandardError, "É obrigatório passar as informações do pagador") if attributes[:pagador].nil?
|
84
|
+
xml.Pagador {
|
85
|
+
xml.Nome { xml.text attributes[:pagador][:nome] }
|
86
|
+
xml.LoginMoIP { xml.text attributes[:pagador][:login_moip] }
|
87
|
+
xml.Email { xml.text attributes[:pagador][:email] }
|
88
|
+
xml.TelefoneCelular { xml.text attributes[:pagador][:tel_cel] }
|
89
|
+
xml.Apelido { xml.text attributes[:pagador][:apelido] }
|
90
|
+
xml.Identidade { xml.text attributes[:pagador][:identidade] }
|
91
|
+
xml.EnderecoCobranca {
|
92
|
+
xml.Logradouro { xml.text attributes[:pagador][:logradouro] }
|
93
|
+
xml.Numero { xml.text attributes[:pagador][:numero] }
|
94
|
+
xml.Complemento { xml.text attributes[:pagador][:complemento] }
|
95
|
+
xml.Bairro { xml.text attributes[:pagador][:bairro] }
|
96
|
+
xml.Cidade { xml.text attributes[:pagador][:cidade] }
|
97
|
+
xml.Estado { xml.text attributes[:pagador][:estado] }
|
98
|
+
xml.Pais { xml.text attributes[:pagador][:pais] }
|
99
|
+
xml.CEP { xml.text attributes[:pagador][:cep] }
|
100
|
+
xml.TelefoneFixo { xml.text attributes[:pagador][:tel_fixo] }
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
# Boleto Bancario
|
105
|
+
if attributes[:forma] == "BoletoBancario"
|
106
|
+
# Dados extras
|
107
|
+
xml.Boleto {
|
108
|
+
xml.DiasExpiracao(:Tipo => "Corridos") {
|
109
|
+
xml.text attributes[:dias_expiracao]
|
110
|
+
}
|
111
|
+
xml.Instrucao1 {
|
112
|
+
xml.text attributes[:instrucao_1]
|
113
|
+
}
|
114
|
+
xml.URLLogo {
|
115
|
+
xml.text attributes[:url_logo]
|
116
|
+
}
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
builder.to_xml
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
data/lib/moip.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'httparty'
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
require "direct_payment"
|
6
|
+
|
7
|
+
module MoIP
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
CONFIG = YAML.load_file("config/moip.yml")["development"]
|
11
|
+
STATUS = { 1 => "authorized", 2 => "started", 3 => "printed", 4 => "completed", 5 => "canceled", 6 => "analysing"}
|
12
|
+
|
13
|
+
base_uri "#{CONFIG["uri"]}/ws/alpha"
|
14
|
+
basic_auth CONFIG["token"], CONFIG["key"]
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
# Envia uma instrução para pagamento único
|
19
|
+
def checkout(attributes = {})
|
20
|
+
full_data = post('EnviarInstrucao/Unica', :body => DirectPayment.direct(attributes))
|
21
|
+
|
22
|
+
raise(StandardError, "Ocorreu um erro ao chamar o webservice") if full_data.nil?
|
23
|
+
|
24
|
+
response = full_data["ns1:EnviarInstrucaoUnicaResponse"]["Resposta"]
|
25
|
+
raise(StandardError, response["Erro"]) if response["Status"] == "Falha"
|
26
|
+
|
27
|
+
return response
|
28
|
+
end
|
29
|
+
|
30
|
+
# Consulta dos dados das autorizações e pagamentos associados à Instrução
|
31
|
+
def query(token)
|
32
|
+
full_data = get("ConsultarInstrucao/#{token}")
|
33
|
+
raise(StandardError, "Ocorreu um erro ao chamar o webservice") if full_data.nil?
|
34
|
+
|
35
|
+
response = full_data["ns1:ConsultarTokenResponse"]["RespostaConsultar"]
|
36
|
+
raise(StandardError, response["Erro"]) if response["Status"] == "Falha"
|
37
|
+
|
38
|
+
return response
|
39
|
+
end
|
40
|
+
|
41
|
+
# Retorna a URL de acesso ao MoIP
|
42
|
+
def moip_page(token)
|
43
|
+
raise(StandardError, "É necessário informar um token para retornar os dados da transação") if token.nil?
|
44
|
+
"#{CONFIG["uri"]}/Instrucao.do?token=#{token}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Monta o NASP
|
48
|
+
def notification(params)
|
49
|
+
notification = {}
|
50
|
+
notification[:transaction_id] = params["id_transacao"]
|
51
|
+
notification[:amount] = sprintf("%.2f", params["valor"].to_f / 100).to_d
|
52
|
+
notification[:status] = STATUS[params["status_pagamento"].to_i]
|
53
|
+
notification[:code] = params["cod_moip"]
|
54
|
+
notification[:payment_type] = params["tipo_pagamento"]
|
55
|
+
notification[:email] = params["email_consumidor"]
|
56
|
+
notification
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/moip.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{moip}
|
8
|
+
s.version = "1.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Guilherme Nascimento"]
|
12
|
+
s.date = %q{2010-11-02}
|
13
|
+
s.description = %q{Gem para utilização da API MoIP}
|
14
|
+
s.email = %q{guilherme.ruby@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/direct_payment.rb",
|
27
|
+
"lib/moip.rb",
|
28
|
+
"moip.gemspec",
|
29
|
+
"spec/lib/config.yaml",
|
30
|
+
"spec/lib/moip_spec.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/guinascimento/moip}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{Gem para utilização da API MoIP}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/lib/moip_spec.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require "moip"
|
2
|
+
|
3
|
+
describe "Make payments with the MoIP API" do
|
4
|
+
|
5
|
+
CONFIG_TEST = YAML.load_file("config.yaml")["test"]
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@pagador = { :nome => "Luiz Inácio Lula da Silva",
|
9
|
+
:login_moip => "lula",
|
10
|
+
:email => "presidente@planalto.gov.br",
|
11
|
+
:tel_cel => "(61)9999-9999",
|
12
|
+
:apelido => "Lula",
|
13
|
+
:identidade => "111.111.111-11",
|
14
|
+
:logradouro => "Praça dos Três Poderes",
|
15
|
+
:numero => "0",
|
16
|
+
:complemento => "Palácio do Planalto",
|
17
|
+
:bairro => "Zona Cívico-Administrativa",
|
18
|
+
:cidade => "Brasília",
|
19
|
+
:estado => "DF",
|
20
|
+
:pais => "BRA",
|
21
|
+
:cep => "70100-000",
|
22
|
+
:tel_fixo => "(61)3211-1221" }
|
23
|
+
|
24
|
+
@billet = { :value => "8.90", :id_proprio => id, :forma => "BoletoBancario", :pagador => @pagador }
|
25
|
+
@debit = { :value => "8.90", :id_proprio => id, :forma => "DebitoBancario", :instituicao => "BancoDoBrasil", :pagador => @pagador }
|
26
|
+
@credit = { :value => "8.90", :id_proprio => id, :forma => "CartaoCredito", :instituicao => "AmericanExpress", :numero => "345678901234564", :expiracao => "08/11", :codigo_seguranca => "1234", :nome => "João Silva", :identidade => "134.277.017.00", :telefone => "(21)9208-0547", :data_nascimento => "25/10/1980", :parcelas => "2", :recebimento => "AVista", :pagador => @pagador }
|
27
|
+
end
|
28
|
+
|
29
|
+
context "make a billet checkout" do
|
30
|
+
it "should have status Sucesso" do
|
31
|
+
MoIP.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>{ "Resposta"=>{ "ID"=>Time.now.strftime("%y%m%d%H%M%S"), "Status"=>"Sucesso", "Token" => "T2N0L0X8E0S71217U2H3W1T4F4S4G4K731D010V0S0V0S080M010E0Q082X2" }})
|
32
|
+
response = MoIP.checkout(@billet)
|
33
|
+
response["Status"].should == "Sucesso"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "make a debit checkout" do
|
38
|
+
it "should have status Sucesso" do
|
39
|
+
MoIP.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>{ "Resposta"=>{ "ID"=>Time.now.strftime("%y%m%d%H%M%S"), "Status"=>"Sucesso", "Token" => "T2N0L0X8E0S71217U2H3W1T4F4S4G4K731D010V0S0V0S080M010E0Q082X2" }})
|
40
|
+
response = MoIP.checkout(@debit)
|
41
|
+
response["Status"].should == "Sucesso"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "make a debit checkout without pass a institution" do
|
46
|
+
it "should have status Falha" do
|
47
|
+
@incorrect_debit = { :value => "37.90", :id_proprio => id, :forma => "DebitoBancario", :pagador => @pagador }
|
48
|
+
MoIP.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>{ "Resposta"=>{"Status"=>"Falha", "Erro"=>"Pagamento direto não é possível com a instituição de pagamento enviada" }})
|
49
|
+
lambda { MoIP.checkout(@incorrect_debit) }.should raise_error(StandardError, "Pagamento direto não é possível com a instituição de pagamento enviada")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "make a debit checkout without pass the payer informations" do
|
54
|
+
it "should raise an exception" do
|
55
|
+
@incorrect_debit = { :value => "37.90", :id_proprio => id, :forma => "DebitoBancario", :instituicao => "BancoDoBrasil" }
|
56
|
+
lambda { MoIP.checkout(@incorrect_debit) }.should raise_error(StandardError, "É obrigatório passar as informações do pagador")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "make a credit card checkout" do
|
61
|
+
it "should have status Sucesso" do
|
62
|
+
MoIP.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>{ "Resposta"=>{ "ID"=>Time.now.strftime("%y%m%d%H%M%S"), "Status"=>"Sucesso", "Token" => "T2N0L0X8E0S71217U2H3W1T4F4S4G4K731D010V0S0V0S080M010E0Q082X2" }})
|
63
|
+
response = MoIP.checkout(@credit)
|
64
|
+
response["Status"].should == "Sucesso"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "make a credit card checkout without pass card informations" do
|
69
|
+
it "should have status Falha" do
|
70
|
+
@incorrect_credit = { :value => "8.90", :id_proprio => id, :forma => "CartaoCredito", :pagador => @pagador }
|
71
|
+
MoIP.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>{ "Resposta"=>{"Status"=>"Falha", "Erro"=>"Pagamento direto não é possível com a instituição de pagamento enviada" }})
|
72
|
+
lambda { MoIP.checkout(@incorrect_credit) }.should raise_error(StandardError, "Pagamento direto não é possível com a instituição de pagamento enviada")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "in error scenario" do
|
77
|
+
it "should raise an exception if response is nil" do
|
78
|
+
MoIP.stub!(:post).and_return(nil)
|
79
|
+
lambda { MoIP.checkout(@billet) }.should raise_error(StandardError, "Ocorreu um erro ao chamar o webservice")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise an exception if status is fail" do
|
83
|
+
MoIP.stub!(:post).and_return("ns1:EnviarInstrucaoUnicaResponse"=>{ "Resposta"=>{"Status"=>"Falha", "Erro"=>"O status da resposta é Falha" }})
|
84
|
+
lambda { MoIP.checkout(@billet) }.should raise_error(StandardError, "O status da resposta é Falha")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "query a transaction token" do
|
89
|
+
it "should retrieve the transaction" do
|
90
|
+
MoIP.stub!(:get).and_return("ns1:ConsultarTokenResponse"=>{ "RespostaConsultar"=>{"Status"=>"Sucesso", "ID"=>"201010291031001210000000046760" }})
|
91
|
+
response = MoIP.query(token)
|
92
|
+
response["Status"].should == "Sucesso"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "query a transaction token in a error scenario" do
|
97
|
+
it "should retrieve status Falha" do
|
98
|
+
MoIP.stub!(:get).and_return("ns1:ConsultarTokenResponse"=>{ "RespostaConsultar"=>{"Status"=>"Falha", "Erro"=>"Instrução não encontrada", "ID"=>"201010291102522860000000046768"}})
|
99
|
+
lambda { MoIP.query("000000000000000000000000000000000000000000000000000000000000") }.should raise_error(StandardError, "Instrução não encontrada")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "build the MoIP URL" do
|
104
|
+
it "should build the correct URL" do
|
105
|
+
MoIP.moip_page(token).should == "#{CONFIG_TEST["uri"]}/Instrucao.do?token=#{token}"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise an error if the token is not informed" do
|
109
|
+
lambda { MoIP.moip_page("").should raise_error(ArgumentError, "É necessário informar um token para retornar os dados da transação") }
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should raise an error if nil is passed as the token" do
|
113
|
+
lambda { MoIP.moip_page(nil).should raise_error(ArgumentError, "É necessário informar um token para retornar os dados da transação") }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def id
|
118
|
+
"transaction_" + Digest::SHA1.hexdigest([Time.now, rand].join)
|
119
|
+
end
|
120
|
+
|
121
|
+
def token
|
122
|
+
"T2X0Q1N021E0B2S9U1P0V3Y0G1F570Y2P4M0P000M0Z0F0J0G0U4N6C7W5T9"
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Guilherme Nascimento
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-02 00:00:00 -02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "Gem para utiliza\xC3\xA7\xC3\xA3o da API MoIP"
|
23
|
+
email: guilherme.ruby@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.markdown
|
31
|
+
files:
|
32
|
+
- .document
|
33
|
+
- .gitignore
|
34
|
+
- LICENSE
|
35
|
+
- README.markdown
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- lib/direct_payment.rb
|
39
|
+
- lib/moip.rb
|
40
|
+
- moip.gemspec
|
41
|
+
- spec/lib/config.yaml
|
42
|
+
- spec/lib/moip_spec.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/guinascimento/moip
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: "Gem para utiliza\xC3\xA7\xC3\xA3o da API MoIP"
|
77
|
+
test_files:
|
78
|
+
- spec/lib/moip_spec.rb
|