Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rescue error when server is not responding.

  • Loading branch information...
commit 2a7bfecc29c0746514a85df7a331505ed6a9ad0a 1 parent 4103d83
@miloops authored
Showing with 17 additions and 7 deletions.
  1. +17 −7 lib/bravo/bill.rb
View
24 lib/bravo/bill.rb
@@ -49,7 +49,7 @@ def iva_sum
end
def authorize
- setup_bill
+ return false unless setup_bill
response = client.request :fecae_solicitar do |soap|
soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
soap.body = body
@@ -86,7 +86,12 @@ def setup_bill
detail["ImpNeto"] = net.to_f
detail["ImpIVA"] = iva_sum
detail["ImpTotal"] = total
- detail["CbteDesde"] = detail["CbteHasta"] = next_bill_number
+
+ if bill_number = next_bill_number
+ detail["CbteDesde"] = detail["CbteHasta"] = bill_number
+ else
+ return false
+ end
unless concepto == 0
detail.merge!({"FchServDesde" => fch_serv_desde || today,
@@ -95,15 +100,20 @@ def setup_bill
end
body.merge!(fecaereq)
+ true
end
def next_bill_number
- resp = client.request :fe_comp_ultimo_autorizado do
- soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
- soap.body = {"Auth" => Bravo.auth_hash, "PtoVta" => Bravo.sale_point, "CbteTipo" => cbte_type}
+ begin
+ resp = client.request :fe_comp_ultimo_autorizado do
+ soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
+ soap.body = {"Auth" => Bravo.auth_hash, "PtoVta" => Bravo.sale_point, "CbteTipo" => cbte_type}
+ end
+
+ resp.to_hash[:fe_comp_ultimo_autorizado_response][:fe_comp_ultimo_autorizado_result][:cbte_nro].to_i + 1
+ rescue Curl::Err::GotNothingError
+ nil
end
-
- resp.to_hash[:fe_comp_ultimo_autorizado_response][:fe_comp_ultimo_autorizado_result][:cbte_nro].to_i + 1
end
def authorized?
Please sign in to comment.
Something went wrong with that request. Please try again.