Skip to content
Browse files

extra infos returned optionallyé

  • Loading branch information...
1 parent 8c7be16 commit e01ae0a75b721039f2e794e5a01a2fac74a28063 @aurels committed Nov 8, 2011
Showing with 24 additions and 6 deletions.
  1. +2 −2 lib/vat_validator.rb
  2. +18 −3 lib/vies_checker.rb
  3. +4 −1 spec/spec_helper.rb
View
4 lib/vat_validator.rb
@@ -50,9 +50,9 @@ def validate_each(record, attribute, value)
if format_valid && options[:vies]
if options[:vies_host]
- valid = ViesChecker.check(value, options[:vies_host])
+ valid = ViesChecker.check(value, false, options[:vies_host])
else
- valid = ViesChecker.check(value)
+ valid = ViesChecker.check(value, false)
end
unless valid
View
21 lib/vies_checker.rb
@@ -11,7 +11,7 @@
module VatValidations
class ViesChecker
- def self.check(complete_vat_number, vies_host='http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl')
+ def self.check(complete_vat_number, return_extra_infos = false, vies_host='http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl')
country_code = complete_vat_number[0..1]
vat_number = complete_vat_number[2..15]
@@ -29,7 +29,15 @@ def self.check(complete_vat_number, vies_host='http://ec.europa.eu/taxation_cust
rescue Savon::SOAP::Fault => fault
# https://github.com/rubiii/savon/blob/master/lib/savon/soap/fault.rb
if fault.to_hash[:fault][:faultstring] == "{ 'INVALID_INPUT' }"
- return false
+ if return_extra_infos
+ {
+ :valid => false,
+ :name => nil
+ }
+ else
+ return false
+ end
+
else
raise ViesContactError
end
@@ -39,7 +47,14 @@ def self.check(complete_vat_number, vies_host='http://ec.europa.eu/taxation_cust
end
if response.success?
- return response[:check_vat_response][:valid]
+ if return_extra_infos
+ {
+ :valid => response[:check_vat_response][:valid],
+ :name => response[:check_vat_response][:name]
+ }
+ else
+ return response[:check_vat_response][:valid]
+ end
else
raise ViesContactError
end
View
5 spec/spec_helper.rb
@@ -53,5 +53,8 @@ class ViesCheckedInvoice < BaseTestModel
end
class WrongViesCheckedInvoice < BaseTestModel
- validates :vat_number, :vat => {:vies => true, :vies_host => 'http://agilitic.com/wrong.wsdl'}
+ validates :vat_number, :vat => {
+ :vies => true,
+ :vies_host => 'http://agilitic.com/wrong.wsdl'
+ }
end

0 comments on commit e01ae0a

Please sign in to comment.
Something went wrong with that request. Please try again.