Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/pjbank/contadigital/contadigital.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require_relative 'credenciamento/credenciamento'
require_relative 'recebimento/boleto'
require_relative 'transacoes/transacoes'

class ContaDigitalController

def initialize

@credenciamentoController = CredenciamentoContaDigital.new
@transacoesController = TransacoesContaDigital.new
# @credenciamentoController = CredenciamentoContaDigital.new

# @transacoesController = TransacoesContaDigital.new

end

Expand All @@ -17,7 +18,7 @@ def credenciamento
opcao = gets.chomp

case opcao
when '1'
when '1'
@credenciamentoController.credenciamento
when '2'
@credenciamentoController.consulta
Expand All @@ -32,7 +33,7 @@ def transacoes
opcao = gets.chomp

case opcao
when '1'
when '1'
@transacoesController.pagamentoBoleto
end
end
Expand All @@ -49,4 +50,4 @@ def transacoes

# end

end
end
19 changes: 19 additions & 0 deletions lib/pjbank/contadigital/credenciamento/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module PJBank
module Contadigital
module Credenciamento
class Base
attr_reader :http

def initialize(http)
@http = http
end

private

def base_url_path
"/contadigital"
end
end
end
end
end
126 changes: 11 additions & 115 deletions lib/pjbank/contadigital/credenciamento/credenciamento.rb
Original file line number Diff line number Diff line change
@@ -1,117 +1,13 @@
class CredenciamentoContaDigital

def credenciamento

puts "Nome da empresa. Ex: Exemplo Conta Digital"
nome_empresa = gets.chomp
puts "CNPJ. Ex: 60285827000110"
cnpj = gets.chomp
puts "CEP. Ex: 13032-525"
cep = gets.chomp
puts "Endereço. Ex: Rua Joaquim Vilac"
endereco = gets.chomp
puts "Número. Ex: 509"
numero = gets.chomp
puts "Bairro. Ex: Vila Teixeira"
bairro = gets.chomp
puts "Complemento. Ex: (opcional)"
complemento = gets.chomp
puts "Cidade. Ex: Campinas"
cidade = gets.chomp
puts "Estado. Ex: SP"
estado = gets.chomp
puts "DDD. Ex: 19"
ddd = gets.chomp
puts "Telefone. Ex: 987652345"
telefone = gets.chomp
puts "E-mail. Ex: [email protected]"
email = gets.chomp

puts "\nLoading...\n"

begin
response = RestClient::Request.execute(
method: :post,
url: 'https://api.pjbank.com.br/contadigital/',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
payload: {
nome_empresa: "#{nome_empresa}",
cnpj: "#{cnpj}",
cep: "#{cep}",
endereco: "#{endereco}",
numero: numero,
bairro: "#{bairro}",
complemento: "#{complemento}",
cidade: "#{cidade}",
estado: "#{estado}",
ddd: "#{ddd}",
telefone: "#{telefone}",
email: "#{email}"
}
)

return response
rescue RestClient::ExceptionWithResponse => err
return err
require_relative 'base'

module PJBank
module Contadigital
module Credenciamento
class Credenciamento < Base
def credenciamento(dados)
http.post("#{base_url_path}/", payload: dados)
end
end
end

def consulta

puts "Digite a Credencial. Ex: eb2af021c5e2448c343965a7a80d7d090eb64164"
credencial = gets.chomp
puts "Digite a Chave. Ex: a834d47e283dd12f50a1b3a771603ae9dfd5a32c"
chave = gets.chomp

puts "\nLoading...\n"

begin
response = RestClient::Request.execute(
method: :get,
url: "https://api.pjbank.com.br/contadigital/#{credencial}",
headers: {
'x-chave-conta': chave,
}
)

return response
rescue RestClient::ExceptionWithResponse => err
return err
end

end

def boleto

puts "Digite a Credencial. Ex: eb2af021c5e2448c343965a7a80d7d090eb64164"
credencial = gets.chomp
puts "Digite a Chave. Ex: a834d47e283dd12f50a1b3a771603ae9dfd5a32c"
chave = gets.chomp
puts "Valor a ser adicionado. Ex: 900.00"
valor = gets.chomp

puts "\nLoading...\n"

begin
response = RestClient::Request.execute(
method: :post,
url: "https://api.pjbank.com.br/contadigital/#{credencial}",
headers: {
'x-chave-conta': chave,
"Content-Type": "application/x-www-form-urlencoded"
},
payload: {
'valor': valor
}
)

return response
rescue RestClient::ExceptionWithResponse => err
return err
end

end

end
end
end
19 changes: 19 additions & 0 deletions lib/pjbank/contadigital/recebimento/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module PJBank
module Contadigital
module Recebimento
class Base
attr_reader :http

def initialize(http)
@http = http
end

private

def base_url_path
"/contadigital"
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/pjbank/contadigital/recebimento/boleto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'base'

module PJBank
module Contadigital
module Recebimento
class Boleto < Base
def emitir(dados)
http.post("#{base_url_path}/:credencial/recebimentos/transacoes", payload: dados)
end

def cancelar(id)
http.delete("#{base_url_path}/:credencial/recebimentos/transacoes/#{id}")
end
end
end
end
end
52 changes: 52 additions & 0 deletions spec/pjbank/contadigital/credenciamento/credenciamento_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'spec_helper'

RSpec.describe PJBank::Contadigital::Credenciamento::Credenciamento do
subject { described_class.new(http) }

describe "#credenciamento" do
let(:http) { PJBank::Http.new }

let(:dados) do
{
nome_empresa: "Boleto Sem Conta Digital",
cnpj: "61702829000120",
cep: "22031030",
endereco: "Rua Silva Castro",
numero: "48",
bairro: "Copacabana",
complemento: "8 andar",
cidade: "Rio de Janeiro",
estado: "RJ",
ddd: "22",
telefone: "988225511",
email: "[email protected]"
}
end

context "when success" do
it "returns the object with correct data" do
VCR.use_cassette("contadigital/credenciamento/credenciamento/sucesso") do
response = subject.credenciamento(dados)
expect(response.credencial).to_not be_nil
expect(response.chave).to_not be_nil
end
end
end

context "when failure" do
before { dados[:cnpj] = "" }

context "when validation error (400)" do
it "raises PJBank::RequestError" do
VCR.use_cassette("contadigital/credenciamento/credenciamento/erro_400") do
expect { subject.credenciamento(dados) }.to raise_error do |error|
expect(error).to be_a(PJBank::RequestError)
expect(error.message).to eql("CNPJ inválido.")
expect(error.code).to eql(400)
end
end
end
end
end
end
end
Loading