Skip to content

Commit

Permalink
Basic functionality is there.
Browse files Browse the repository at this point in the history
  • Loading branch information
leanucci committed Mar 1, 2011
1 parent 24f1b89 commit 8c0eb2e
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 44 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -2,6 +2,7 @@ source "http://rubygems.org"
gem "savon"

group :development do
gem "ruby-debug"
gem "rspec", "~> 2.4.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
Expand Down
19 changes: 10 additions & 9 deletions Gemfile.lock
Expand Up @@ -2,18 +2,15 @@ GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
columnize (0.3.2)
crack (0.1.8)
diff-lcs (1.1.2)
git (1.2.5)
gyoku (0.1.1)
builder (>= 2.1.2)
httpi (0.7.7)
rack
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
rack (1.2.1)
linecache (0.43)
rake (0.8.7)
rcov (0.9.9)
rspec (2.4.0)
Expand All @@ -24,11 +21,14 @@ GEM
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
savon (0.8.2)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
savon (0.7.8)
builder (>= 2.1.2)
crack (~> 0.1.8)
gyoku (>= 0.1.1)
httpi (>= 0.7.5)
crack (>= 0.1.4)

PLATFORMS
ruby
Expand All @@ -38,4 +38,5 @@ DEPENDENCIES
jeweler (~> 1.5.1)
rcov
rspec (~> 2.4.0)
ruby-debug
savon
13 changes: 9 additions & 4 deletions lib/bravo.rb
@@ -1,11 +1,16 @@
require "rubygems"
require "bundler/setup"
require "bravo/version"
require "savon"
require "ruby-debug"

module Bravo
autoload :Version, "bravo/version"
autoload :Authorizer, "bravo/authorizer"
autoload :AuthData, "bravo/auth_data"
autoload :Biller, "bravo/biller"

extend self
attr_reader :pkey, :cert, :cuit
attr_reader :pkey, :cert
def pkey=(relative_path)
@pkey = File.read(relative_path)
end
Expand All @@ -14,8 +19,8 @@ def cert=(relative_path)
@cert = File.read(relative_path)
end

def cuit=()
@cuit = "30711034389"
def self.cuit
"30711034389"
end

def auth_hash
Expand Down
25 changes: 13 additions & 12 deletions lib/bravo/auth_data.rb
@@ -1,20 +1,21 @@
require 'yaml'
module Bravo
class AuthData

def read
get_authdata
end

def get_authdata
# setear endpoint, key, cert, cuit, filename ✔
# crear filename del dia ✔
class << self
def fetch
todays_datafile = "/tmp/bravo_#{Time.new.strftime('%d_%m_%Y')}.yml"
opts = "-u https://wsaahomo.afip.gov.ar/ws/services/LoginCms"
keys_root = "/Users/leanucci/Xephstratus/afip/claves/"
opts += " -k #{keys_root}vurbia_dev_pkey"
opts += " -c #{keys_root}vurbia_wsfe_test.crt"

todays_datafile = "/tmp/bravo_#{Time.new.strftime('%d_%m_%Y')}.yml"
%x("./wsaa-client.sh") unless File.exists?(todays_datafile)
unless File.exists?(todays_datafile)
%x(#{ENV["BUNDLE_PATH"]}/gems/bravo-#{Bravo::VERSION}/wsaa-client.sh #{opts})
end

@data = YAML.load_file(todays_datafile).each do |k, v|
Bravo.const_set(k.to_s.upcase, v)
@data = YAML.load_file(todays_datafile).each do |k, v|
Bravo.const_set(k.to_s.upcase, v) unless Bravo.const_defined?(k.to_s.upcase)
end
end
end
end
Expand Down
13 changes: 7 additions & 6 deletions lib/bravo/biller.rb
@@ -1,11 +1,11 @@
module Bravo
class Biller
def initialize
Bravo::AuthData.read
Bravo::AuthData.fetch
end

def dummy
client = Savon::Client.new "http://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL"
client = Savon::Client.new("http://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL")
# client.fecaea_solicitar do |s|
# s.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
# s.body = {"Auth" => {"Token" => TOKEN, "Sign" => SIGN, "Cuit" => CUIT.to_i},
Expand Down Expand Up @@ -40,15 +40,15 @@ def dummy

resp = client.fe_comp_ultimo_autorizado do |s|
s.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
s.body = {"Auth" => Bravo.auth_hash,
s.body = {"Auth" => {"Token" => Bravo::TOKEN, "Sign" => Bravo::SIGN, "Cuit" => Bravo.cuit},
"PtoVta" => "2", "CbteTipo" => "1"}
end

@nro = resp.to_hash[:fe_comp_ultimo_autorizado_response][:fe_comp_ultimo_autorizado_result][:cbte_nro]

client.fecae_solicitar do |s|
resp = client.fecae_solicitar do |s|
s.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
s.body = {"Auth" => Bravo.auth_hash,
s.body = {"Auth" => {"Token" => Bravo::TOKEN, "Sign" => Bravo::SIGN, "Cuit" => Bravo.cuit},
"FeCAEReq" => {"FeCabReq" => {"CantReg" => "1", #todo sacado de la factura
"CbteTipo" => "1",
"PtoVta" => "2"},
Expand All @@ -57,7 +57,7 @@ def dummy
"DocNro" => "30710151543",
"CbteDesde" => @nro.to_i+1,
"CbteHasta" => @nro.to_i+1,
"CbteFch" => "20110105",
"CbteFch" => Time.new.strftime('%Y%m%d'),
"ImpTotal" => "121.00",
"ImpTotConc" => "0.00",
"ImpNeto" => "100.00",
Expand All @@ -75,6 +75,7 @@ def dummy
}
}
end
resp.to_hash
end
end
end
7 changes: 3 additions & 4 deletions spec/bravo/auth_data_spec.rb
@@ -1,9 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "AuthData" do
it "should read todays data" do
Bravo::AuthData.new.read
it "should create constants for todays data" do
Bravo::AuthData.fetch
Bravo.constants.should include("TOKEN", "SIGN")
end
it "should get sign and key for the day"
it "should get todays data and store it to file"
end
3 changes: 0 additions & 3 deletions spec/bravo/authorizer_spec.rb
Expand Up @@ -6,7 +6,4 @@
authorizer.pkey.should == File.read('spec/fixtures/pkey')
authorizer.cert.should == File.read('spec/fixtures/cert.crt')
end

it "should store sign and key for the day"
it "should return sign and key for the day"
end
9 changes: 8 additions & 1 deletion spec/bravo/biller_spec.rb
@@ -1,5 +1,12 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "Biller" do
it "should get basic CAE"
it "should authorize basic bill" do
bill = Bravo::Biller.new
resp = bill.dummy

res = resp[:fecae_solicitar_response][:fecae_solicitar_result]
res[:fe_cab_resp][:resultado].should == "A"
res[:fe_det_resp][:fecae_det_response][:resultado].should == "A"
end
end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -10,5 +10,6 @@
RSpec.configure do |config|

end

Bravo.pkey = 'spec/fixtures/pkey'
Bravo.cert = 'spec/fixtures/cert.crt'
Bravo.cert = 'spec/fixtures/cert.crt'
22 changes: 18 additions & 4 deletions wsaa-client.sh
Expand Up @@ -5,9 +5,9 @@
#
# Modify following definitions according to your environment:
#
URL=https://wsaahomo.afip.gov.ar/ws/services/LoginCms # WSAA URL
KEY=spec/fixtures/pkey # file containing the private key in PEM format
CRT=spec/fixtures/cert.crt # file containing the X.509 certificate in PEM format
# URL=https://wsaahomo.afip.gov.ar/ws/services/LoginCms # WSAA URL
# KEY=spec/fixtures/pkey # file containing the private key in PEM format
# CRT=spec/fixtures/cert.crt # file containing the X.509 certificate in PEM format
TAFN="TA.xml" # file name of the output file
# modify next line if you need a proxy to get to the Internet or comment it out
# if you don't need a proxy
Expand Down Expand Up @@ -79,7 +79,7 @@ function CallWSAA()
{
RESPONSE=$(
echo "$REQUEST" |
curl -v -k -H 'Content-Type: application/soap+xml; action=""' -d @- $URL
curl -k -H 'Content-Type: application/soap+xml; action=""' -d @- $URL
)
echo "$REQUEST"
}
Expand Down Expand Up @@ -145,6 +145,20 @@ EOF
#[ $# -eq 1 ] && SERVICE=$1
# otherwise, ask for it
#[ $# -eq 0 ] && read -p "Service name: " SERVICE

# Parse commandline arguments
while getopts 'k:u:c:' OPTION
do
case $OPTION in
c) CRT=$OPTARG
;;
k) KEY=$OPTARG
;;
u) URL=$OPTARG
;;
esac
done
shift $(($OPTIND - 1))
MakeTRA # Generate TRA
MakeCMS # Generate CMS (TRA + signature + certificate)
MakeSOAPrequest # Generate the SOAP request XML
Expand Down

0 comments on commit 8c0eb2e

Please sign in to comment.