Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicionado Banco Santander com e sem registro
- Loading branch information
Ronaldo de Sousa Araujo
committed
Sep 8, 2012
1 parent
04fe527
commit caa3cb3
Showing
5 changed files
with
253 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,94 @@ | |||
# -*- encoding: utf-8 -*- | |||
# @author Kivanio Barbosa | |||
# @author Ronaldo Araujo | |||
module Brcobranca | |||
module Boleto | |||
class Santander < Base # Banco Santander | |||
|
|||
# Usado somente em carteiras especiais com registro para complementar o número do cocumento | |||
attr_reader :seu_numero | |||
|
|||
validates_length_of :agencia, :maximum => 4, :message => "deve ser menor ou igual a 4 dígitos." | |||
validates_length_of :convenio, :maximum => 7, :message => "deve ser menor ou igual a 7 dígitos." | |||
validates_length_of :numero_documento, :maximum => 8, :message => "deve ser menor ou igual a 8 dígitos." | |||
validates_length_of :conta_corrente, :maximum => 5, :message => "deve ser menor ou igual a 5 dígitos." | |||
validates_length_of :seu_numero, :maximum => 7, :message => "deve ser menor ou igual a 7 dígitos." | |||
|
|||
# Nova instancia do Santander | |||
# @param (see Brcobranca::Boleto::Base#initialize) | |||
def initialize(campos={}) | |||
campos = {:carteira => "102"}.merge!(campos) | |||
super(campos) | |||
end | |||
|
|||
# Codigo do banco emissor (3 dígitos sempre) | |||
# | |||
# @return [String] 3 caracteres numéricos. | |||
def banco | |||
"033" | |||
end | |||
|
|||
# Número do convênio/contrato do cliente junto ao banco. | |||
# @return [String] 5 caracteres numéricos. | |||
def convenio=(valor) | |||
@convenio = valor.to_s.rjust(5,'0') unless valor.nil? | |||
end | |||
|
|||
# Conta corrente | |||
# @return [String] 5 caracteres numéricos. | |||
def conta_corrente=(valor) | |||
@conta_corrente = valor.to_s.rjust(5,'0') unless valor.nil? | |||
end | |||
|
|||
# Número seqüencial utilizado para identificar o boleto. | |||
# @return [String] 8 caracteres numéricos. | |||
def numero_documento=(valor) | |||
@numero_documento = valor.to_s.rjust(8,'0') unless valor.nil? | |||
end | |||
|
|||
# Número seqüencial utilizado para identificar o boleto. | |||
# @return [String] 7 caracteres numéricos. | |||
def seu_numero=(valor) | |||
@seu_numero = valor.to_s.rjust(7,'0') unless valor.nil? | |||
end | |||
|
|||
# Dígito verificador do nosso número. | |||
# @return [String] 1 caracteres numéricos. | |||
def nosso_numero_dv | |||
nosso_numero = self.numero_documento.to_s.rjust(12,'0') unless self.numero_documento.nil? | |||
nosso_numero.modulo11_2to9 | |||
end | |||
|
|||
# Nosso número para exibir no boleto. | |||
# @return [String] | |||
# @example | |||
# boleto.nosso_numero_boleto #=> "000090002720-7" | |||
def nosso_numero_boleto | |||
nosso_numero = self.numero_documento.to_s.rjust(12,'0') unless self.numero_documento.nil? | |||
"#{nosso_numero}-#{self.nosso_numero_dv}" | |||
end | |||
|
|||
# Agência + codigo do cedente do cliente para exibir no boleto. | |||
# @return [String] | |||
# @example | |||
# boleto.agencia_conta_boleto #=> "0059/1899775" | |||
def agencia_conta_boleto | |||
"#{self.agencia}/#{self.convenio}" | |||
end | |||
|
|||
# Segunda parte do código de barras. | |||
# 9(01) | Fixo 9 <br/> | |||
# 9(07) | Convenio <br/> | |||
# 9(05) | Fixo 00000<br/> | |||
# 9(08) | Nosso Numero<br/> | |||
# 9(01) | IOF<br/> | |||
# 9(03) | Carteira de cobrança<br/> | |||
# | |||
# @return [String] 25 caracteres numéricos. | |||
def codigo_barras_segunda_parte | |||
"9#{self.convenio}00000#{self.numero_documento}0#{self.carteira}" | |||
end | |||
|
|||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,153 @@ | |||
# -*- encoding: utf-8 -*- | |||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |||
|
|||
describe Brcobranca::Boleto::Santander do | |||
before(:each) do | |||
@valid_attributes = { | |||
:especie_documento => "DS", | |||
:moeda => "9", | |||
:data_documento => Date.today, | |||
:dias_vencimento => 1, | |||
:aceite => "N", | |||
:quantidade => 1, | |||
:valor => 25.0, | |||
:local_pagamento => "QUALQUER BANCO ATÉ O VENCIMENTO", | |||
:cedente => "Kivanio Barbosa", | |||
:documento_cedente => "12345678912", | |||
:sacado => "Claudio Pozzebom", | |||
:sacado_documento => "12345678900", | |||
:agencia => "0059", | |||
:conta_corrente => "53678", | |||
:convenio => 1899775, | |||
:numero_documento => "90000267" | |||
} | |||
end | |||
|
|||
it "Criar nova instancia com atributos padrões" do | |||
boleto_novo = Brcobranca::Boleto::Santander.new | |||
boleto_novo.banco.should eql("033") | |||
boleto_novo.especie_documento.should eql("DM") | |||
boleto_novo.especie.should eql("R$") | |||
boleto_novo.moeda.should eql("9") | |||
boleto_novo.data_documento.should eql(Date.today) | |||
boleto_novo.dias_vencimento.should eql(1) | |||
boleto_novo.data_vencimento.should eql(Date.today + 1) | |||
boleto_novo.aceite.should eql("S") | |||
boleto_novo.quantidade.should eql(1) | |||
boleto_novo.valor.should eql(0.0) | |||
boleto_novo.valor_documento.should eql(0.0) | |||
boleto_novo.local_pagamento.should eql("QUALQUER BANCO ATÉ O VENCIMENTO") | |||
boleto_novo.carteira.should eql("102") | |||
end | |||
|
|||
it "Criar nova instancia com atributos válidos" do | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.banco.should eql("033") | |||
boleto_novo.especie_documento.should eql("DS") | |||
boleto_novo.especie.should eql("R$") | |||
boleto_novo.moeda.should eql("9") | |||
boleto_novo.data_documento.should eql(Date.today) | |||
boleto_novo.dias_vencimento.should eql(1) | |||
boleto_novo.data_vencimento.should eql(Date.today + 1) | |||
boleto_novo.aceite.should eql("N") | |||
boleto_novo.quantidade.should eql(1) | |||
boleto_novo.valor.should eql(25.0) | |||
boleto_novo.valor_documento.should eql(25.0) | |||
boleto_novo.local_pagamento.should eql("QUALQUER BANCO ATÉ O VENCIMENTO") | |||
boleto_novo.cedente.should eql("Kivanio Barbosa") | |||
boleto_novo.documento_cedente.should eql("12345678912") | |||
boleto_novo.sacado.should eql("Claudio Pozzebom") | |||
boleto_novo.sacado_documento.should eql("12345678900") | |||
boleto_novo.conta_corrente.should eql("53678") | |||
boleto_novo.agencia.should eql("0059") | |||
boleto_novo.convenio.should eql("1899775") | |||
boleto_novo.numero_documento.should eql("90000267") | |||
boleto_novo.carteira.should eql("102") | |||
end | |||
|
|||
it "Gerar boleto" do | |||
@valid_attributes[:data_documento] = Date.parse("2011/10/08") | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.codigo_barras_segunda_parte.should eql("9189977500000900002670102") | |||
boleto_novo.codigo_barras.should eql("03391511500000025009189977500000900002670102") | |||
boleto_novo.codigo_barras.linha_digitavel.should eql("03399.18997 77500.000904 00026.701029 1 51150000002500") | |||
|
|||
@valid_attributes[:valor] = 54.00 | |||
@valid_attributes[:numero_documento] = "90002720" | |||
@valid_attributes[:data_documento] = Date.parse("2012/09/07") | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.codigo_barras_segunda_parte.should eql("9189977500000900027200102") | |||
boleto_novo.codigo_barras.should eql("03391545000000054009189977500000900027200102") | |||
boleto_novo.codigo_barras.linha_digitavel.should eql("03399.18997 77500.000904 00272.001025 1 54500000005400") | |||
end | |||
|
|||
it "Não permitir gerar boleto com atributos inválido" do | |||
boleto_novo = Brcobranca::Boleto::Santander.new | |||
lambda { boleto_novo.codigo_barras }.should raise_error(Brcobranca::BoletoInvalido) | |||
boleto_novo.errors.count.should eql(3) | |||
end | |||
|
|||
it "Montar agencia_conta_corrente_dv" do | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.agencia_conta_boleto.should eql("0059/1899775") | |||
end | |||
|
|||
it "Montar nosso_numero_dv" do | |||
@valid_attributes[:numero_documento] = "566612457800" | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.nosso_numero_dv.should eql(2) | |||
|
|||
@valid_attributes[:numero_documento] = "90002720" | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.nosso_numero_dv.should eql(7) | |||
end | |||
|
|||
it "Montar nosso_numero_boleto" do | |||
@valid_attributes[:numero_documento] = "566612457800" | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.nosso_numero_boleto.should eql("566612457800-2") | |||
|
|||
@valid_attributes[:numero_documento] = "90002720" | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
boleto_novo.nosso_numero_boleto.should eql("000090002720-7") | |||
end | |||
|
|||
it "Busca logotipo do banco" do | |||
boleto_novo = Brcobranca::Boleto::Santander.new | |||
File.exist?(boleto_novo.logotipo).should be_true | |||
File.stat(boleto_novo.logotipo).zero?.should be_false | |||
end | |||
|
|||
it "Gerar boleto nos formatos válidos com método to_" do | |||
@valid_attributes[:data_documento] = Date.parse("2009/08/13") | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
|
|||
%w| pdf jpg tif png ps |.each do |format| | |||
file_body=boleto_novo.send("to_#{format}".to_sym) | |||
tmp_file=Tempfile.new("foobar." << format) | |||
tmp_file.puts file_body | |||
tmp_file.close | |||
File.exist?(tmp_file.path).should be_true | |||
File.stat(tmp_file.path).zero?.should be_false | |||
File.delete(tmp_file.path).should eql(1) | |||
File.exist?(tmp_file.path).should be_false | |||
end | |||
end | |||
|
|||
it "Gerar boleto nos formatos válidos" do | |||
@valid_attributes[:data_documento] = Date.parse("2009/08/13") | |||
boleto_novo = Brcobranca::Boleto::Santander.new(@valid_attributes) | |||
|
|||
%w| pdf jpg tif png ps |.each do |format| | |||
file_body=boleto_novo.to(format) | |||
tmp_file=Tempfile.new("foobar." << format) | |||
tmp_file.puts file_body | |||
tmp_file.close | |||
File.exist?(tmp_file.path).should be_true | |||
File.stat(tmp_file.path).zero?.should be_false | |||
File.delete(tmp_file.path).should eql(1) | |||
File.exist?(tmp_file.path).should be_false | |||
end | |||
end | |||
|
|||
end |