Permalink
Browse files

Basic functionality is there.

  • Loading branch information...
1 parent 24f1b89 commit 8c0eb2ec6008fc0e850aa1debef2eb77f6ebc60e @leanucci leanucci committed Jan 13, 2011
Showing with 71 additions and 44 deletions.
  1. +1 −0 Gemfile
  2. +10 −9 Gemfile.lock
  3. +9 −4 lib/bravo.rb
  4. +13 −12 lib/bravo/auth_data.rb
  5. +7 −6 lib/bravo/biller.rb
  6. +3 −4 spec/bravo/auth_data_spec.rb
  7. +0 −3 spec/bravo/authorizer_spec.rb
  8. +8 −1 spec/bravo/biller_spec.rb
  9. +2 −1 spec/spec_helper.rb
  10. +18 −4 wsaa-client.sh
View
1 Gemfile
@@ -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"
View
19 Gemfile.lock
@@ -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)
@@ -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
@@ -38,4 +38,5 @@ DEPENDENCIES
jeweler (~> 1.5.1)
rcov
rspec (~> 2.4.0)
+ ruby-debug
savon
View
13 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
@@ -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
View
25 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
View
13 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},
@@ -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"},
@@ -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",
@@ -75,6 +75,7 @@ def dummy
}
}
end
+ resp.to_hash
end
end
end
View
7 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
View
3 spec/bravo/authorizer_spec.rb
@@ -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
View
9 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
View
3 spec/spec_helper.rb
@@ -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'
View
22 wsaa-client.sh
@@ -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
@@ -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"
}
@@ -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

0 comments on commit 8c0eb2e

Please sign in to comment.