Skip to content

Commit

Permalink
Bill#response returns complete response from WSFE.
Browse files Browse the repository at this point in the history
  • Loading branch information
leanucci committed Mar 4, 2011
1 parent 12321c2 commit 602fa11
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 17 additions & 7 deletions lib/bravo/bill.rb
Expand Up @@ -46,9 +46,7 @@ def authorize
soap.body = body
end

response = response.to_hash

setup_response(response)
setup_response(response.to_hash)
self.authorized?
end

Expand Down Expand Up @@ -112,11 +110,23 @@ def header(cbte_type)#todo sacado de la factura
end

def setup_response(response)
detail_response = response[:fecae_solicitar_response][:fecae_solicitar_result][:fe_det_resp][:fecae_det_response]
header_response = response[:fecae_solicitar_response][:fecae_solicitar_result][:fe_cab_resp]
header_response = response[:fecae_solicitar_response][:fecae_solicitar_result][:fe_cab_resp].symbolize_keys
detail_response = response[:fecae_solicitar_response][:fecae_solicitar_result][:fe_det_resp][:fecae_det_response].symbolize_keys

iva = self.body["FeCAEReq"]["FeDetReq"]["FECAEDetRequest"]["Iva"]["AlicIva"].underscore_keys!

detail_response.merge!(iva.symbolize_keys!)

response_hash = {:header_result => header_response.delete(:resultado),
:detail_result => detail_response.delete(:resultado),
:cae_due_date => detail_response.delete(:cae_fch_vto),
:authorized_on => header_response.delete(:fch_proceso),
:iva_id => detail_response.delete(:id),
:iva_importe => detail_response.delete(:importe)
}.merge!(header_response).merge!(detail_response)

response_struct = Struct.new("Response", :header_result, :detail_result, :cae, :cae_due_date, :authorized_on)
self.response = response_struct.new(header_response[:resultado], detail_response[:resultado], detail_response[:cae], detail_response[:cae_fch_vto], header_response[:fch_proceso])
keys, values = response_hash.to_a.transpose
self.response = Struct.new("Response", *keys).new(*values)
end
end
end
10 changes: 9 additions & 1 deletion spec/bravo/bill_spec.rb
Expand Up @@ -96,7 +96,15 @@
@bill.authorize.should == true

@bill.authorized?.should == true
@bill.response.cae.length.should == 14

response = @bill.response

response.cae.length.should == 14

pp response

response.length.should == 19

end
end
end

0 comments on commit 602fa11

Please sign in to comment.