Skip to content

Commit

Permalink
Add remessa
Browse files Browse the repository at this point in the history
  • Loading branch information
martinusso committed Jun 12, 2019
1 parent 742be06 commit f3b6a8a
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 19 deletions.
12 changes: 4 additions & 8 deletions boleto/boleto.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
"github.com/padmoney/cobranca"
)

const (
bancoNaoSuportado = "Banco não suportado."
)

type BoletoGenerator interface {
NossoNumero() string
CampoLivre() string
Expand All @@ -24,14 +20,14 @@ type Boleto struct {
numero int64
nossoNumero string
campoLivre string
conta Conta
conta cobranca.Conta
pagador Pagador
avalista Avalista
codigoBarras string
linhaDigitavel string
}

func NewBoleto(valor float64, dataVencimento time.Time, numero int64, conta Conta) (Boleto, error) {
func NewBoleto(valor float64, dataVencimento time.Time, numero int64, conta cobranca.Conta) (Boleto, error) {
boleto := Boleto{
valor: valor,
dataVencimento: dataVencimento,
Expand All @@ -44,7 +40,7 @@ func NewBoleto(valor float64, dataVencimento time.Time, numero int64, conta Cont
case cobranca.CodigoSantander:
bg = NewSantander(boleto)
default:
return boleto, errors.New(bancoNaoSuportado)
return boleto, errors.New(cobranca.BancoNaoSuportado)
}
boleto.nossoNumero = bg.NossoNumero()
boleto.campoLivre = bg.CampoLivre()
Expand All @@ -61,7 +57,7 @@ func (b Boleto) CodigoBarras() string {
return b.codigoBarras
}

func (b Boleto) Conta() Conta {
func (b Boleto) Conta() cobranca.Conta {
return b.conta
}

Expand Down
4 changes: 2 additions & 2 deletions boleto/boleto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNewBoleto(t *testing.T) {
today := time.Now().Local().Format(dateFormat)
valor := 273.71

c := NewConta(cobranca.CodigoSantander, "4042", "61900", "101", "0282033")
c := cobranca.NewConta(cobranca.CodigoSantander, "4042", "61900", "101", "0282033")

b, _ := NewBoleto(valor, venc, 1984, c)

Expand Down Expand Up @@ -52,7 +52,7 @@ func TestNewBoleto(t *testing.T) {
}

func TestBoletoBancoNaoSuportado(t *testing.T) {
c := NewConta("999", "4042", "61900", "101", "0282033")
c := cobranca.NewConta("999", "4042", "61900", "101", "0282033")
_, err := NewBoleto(1, time.Now(), 1984, c)

if err == nil {
Expand Down
4 changes: 2 additions & 2 deletions boleto/santander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ func TestBoletoSantanderSemRegistro(t *testing.T) {
}
}

func contaSantanderFixture(carteira, convenio string) Conta {
return NewConta(cobranca.CodigoSantander, "4042", "61900", carteira, convenio)
func contaSantanderFixture(carteira, convenio string) cobranca.Conta {
return cobranca.NewConta(cobranca.CodigoSantander, "4042", "61900", carteira, convenio)
}
2 changes: 1 addition & 1 deletion boleto/conta.go → conta.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package boleto
package cobranca

type Conta struct {
Banco string
Expand Down
10 changes: 4 additions & 6 deletions boleto/conta_test.go → conta_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package boleto
package cobranca

import (
"testing"

"github.com/padmoney/cobranca"
)

func TestNewConta(t *testing.T) {
Expand All @@ -12,10 +10,10 @@ func TestNewConta(t *testing.T) {
carteira := "01"
convenio := "123456789"

c := NewConta(cobranca.CodigoBancoBrasil, agencia, contaCorrente, carteira, convenio)
c := NewConta(CodigoBancoBrasil, agencia, contaCorrente, carteira, convenio)

if c.Banco != cobranca.CodigoBancoBrasil {
t.Errorf("Expected '%s' got '%s'", cobranca.CodigoBancoBrasil, c.Banco)
if c.Banco != CodigoBancoBrasil {
t.Errorf("Expected '%s' got '%s'", CodigoBancoBrasil, c.Banco)
}

if c.Agencia != agencia {
Expand Down
5 changes: 5 additions & 0 deletions messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cobranca

const (
BancoNaoSuportado = "Banco não suportado."
)
19 changes: 19 additions & 0 deletions remessa/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package remessa

type Params struct {
params map[string]string
}

func NewParams() Params {
p := make(map[string]string)
return Params{params: p}
}

func (p Params) Add(key, value string) Params {
p.params[key] = value
return p
}

func (p Params) Get(key string) string {
return p.params[key]
}
26 changes: 26 additions & 0 deletions remessa/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package remessa

import (
"testing"
)

func TestParams(t *testing.T) {
name := "Breno"
company := "Padmoney"
p := NewParams()
p.Add("name", name)
p.Add("company", company)
if got := p.Get("name"); got != name {
t.Errorf("Expected '%s', got '%s'", name, got)
}
if got := p.Get("company"); got != company {
t.Errorf("Expected '%s', got '%s'", company, got)
}

// updating
newName := "Bernardo"
p.Add("name", newName)
if got := p.Get("name"); got != newName {
t.Errorf("Expected '%s', got '%s'", newName, got)
}
}
48 changes: 48 additions & 0 deletions remessa/remessa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package remessa

import (
"errors"

"github.com/padmoney/cobranca"
)

type RemessaGenerator interface {
}

type Remessa struct {
Generator RemessaGenerator
}

func New(conta cobranca.Conta, params Params, sequential int64) (Remessa, error) {
remessa := Remessa{}

switch conta.Banco {
case cobranca.CodigoSantander:
remessa.Generator = NewSantander(conta, params, sequential)
default:
return remessa, errors.New(cobranca.BancoNaoSuportado)
}
return remessa, nil
}

/*
public function __construct($conta, array $params = [])
{
$this->conta = $conta;
$this->params = $params;
$agencia = explode('-', $conta->agencia());
$this->agencia = isset($agencia[0]) ? $agencia[0] : $conta->agencia();
$this->agencia_dv = $this->digitoAgencia();
$conta_numero = explode('-', $conta->contaCorrente());
$this->conta_numero = isset($conta_numero[0]) ? $conta_numero[0] : $conta->contaCorrente();
$this->conta_dv = isset($conta_numero[1]) ? $conta_numero[1] : '';
$this->nome_cedente = $conta->beneficiario()->nome();
$this->carteira = $conta->carteira();
$this->convenio = $conta->convenio();
$this->variacao = $conta->variacao();
$this->sequencial_remessa = $conta->sequencialRemessa();
}
*/
17 changes: 17 additions & 0 deletions remessa/santander.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package remessa

import "github.com/padmoney/cobranca"

type Santander struct {
conta cobranca.Conta
params Params
sequential int64
}

func NewSantander(conta cobranca.Conta, params Params, sequential int64) Santander {
return Santander{
conta: conta,
params: params,
sequential: sequential,
}
}
12 changes: 12 additions & 0 deletions remessa/santander_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package remessa

/*
func TestMethodName(t *testing.T) {
if err != nil {
t.Errorf("There should not be an error, error: %s", err)
}
if got != expected {
t.Errorf("Expected '%s', got '%s'", expected, got)
}
}
*/

0 comments on commit f3b6a8a

Please sign in to comment.