deltavista_crif_dva_interface 0.0.30 → 0.1.00

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,7 @@ require "deltavista_crif_dva_interface/errors"
6
6
  require "deltavista_crif_dva_interface/restful_service"
7
7
  require "deltavista_crif_dva_interface/delta_vista_service"
8
8
  require "deltavista_crif_dva_interface/xml_converter"
9
+ require "deltavista_crif_dva_interface/soap_converter"
9
10
  require "deltavista_crif_dva_interface/credit_check_short_v02"
10
11
  require "deltavista_crif_dva_interface/collection_check"
11
12
  require "deltavista_crif_dva_interface/address_update"
@@ -1,111 +1,35 @@
1
1
  module DeltavistaCrifDvaInterface
2
- class CollectionCheck < XmlConverter
3
- attr_reader :logger
4
-
5
- DEFAULT_OPTIONS = {
6
- :encoding => 'UTF-8',
7
- :request_type => 'getCollectionCheck'
8
- }.freeze
9
-
10
- PRIVATE_NODE = 'private'
11
- PRIVATE_KEYS = %w(title lastName firstName maidenName street house poBox zip city country phone birthDate sex)
12
- PRIVATE_RESPONSE_KEYS = PRIVATE_KEYS.unshift('addressId')
13
-
14
- COMPANY_NODE = 'company'
15
- COMPANY_KEYS = %w(legalForm name street house poBox zip city country phone)
16
- COMPANY_RESPONSE_KEYS = COMPANY_KEYS.unshift('addressId')
17
-
18
- PAYLOAD_NODE = 'payLoad'
19
- PAYLOAD_RESPONSE_KEYS = %w(personStatus score decision hasDebt decisionComment)
20
-
21
- # unique id for each request
22
- @@reference_id = 1000
2
+ class CollectionCheck < SoapConverter
23
3
 
24
4
  def initialize(options)
25
- @config = {}
26
- if options.is_a? Hash
27
- @config = DEFAULT_OPTIONS.merge(options)
28
- @logger = options[:logger] ? options[:logger] : Logger.new(STDOUT)
29
- else
30
- @config[:username] = options.username
31
- @config[:password] = options.password
32
- @logger = options.logger ? options.logger : Logger.new(STDOUT)
33
- @config = DEFAULT_OPTIONS.merge(@config)
34
- end
5
+ super(options)
35
6
  end
36
7
 
37
- def to_xml(address, collection)
38
- builder = Nokogiri::XML::Builder.new(:encoding => @config[:encoding]) do |xml|
39
- xml.dvaCheckRequest {
40
- xml.identity {
41
- xml.username @config[:username]
42
- xml.password @config[:password]
43
- }
44
- xml.reference @@reference_id
45
- xml.requestType @config[:request_type]
46
- # Company Flag (to be set in the address scope)
47
- if address['is_company']
48
- keys = COMPANY_KEYS
49
- node = COMPANY_NODE
50
- else
51
- keys = PRIVATE_KEYS
52
- node = PRIVATE_NODE
53
- end
54
- xml.__send__('node') {
55
- keys.each do |key|
56
- xml.send(key, address[key.downcase]) if address[key.downcase] && !address[key.downcase].empty?
57
- end
58
- }
59
- xml.collection {
60
- xml.amountTotal collection[:amount_total]
61
- xml.amountOpen collection[:amount_open]
62
- xml.caseStatus collection[:case_status]
63
- xml.dateBill collection[:date_bill].strftime('%Y-%m-%d')
64
- xml.dateCase collection[:date_case].strftime('%Y-%m-%d')
65
- }
66
- }
67
- end
68
- @@reference_id += 1
69
- result = builder.to_xml
70
- logger.debug result if logger.debug?
71
- result
8
+ def private_collection_check(address, collection)
9
+ envelope[:report_type] = 'COLLECTION_CHECK_CONSUMER'
10
+ insert_private_address address
11
+ insert_collection collection
12
+ commit(:collection_check_consumer)
72
13
  end
73
14
 
74
- def to_hash(xml_body)
75
- logger.debug xml_body if logger.debug?
76
- xml_doc = Nokogiri.XML(xml_body, nil, @config[:encoding])
77
- if valid_response? xml_doc
78
- # private tag
79
- address = {}
80
- if xml_doc.xpath("//dvaCheckResponse/#{PRIVATE_NODE}")
81
- node = PRIVATE_NODE
82
- keys = PRIVATE_RESPONSE_KEYS
83
- elsif xml_doc.xpath("//dvaCheckResponse/#{COMPANY_NODE}")
84
- node = COMPANY_NODE
85
- keys = COMPANY_RESPONSE_KEYS
86
- else
87
- logger.error 'Neither company nor private Node were found in the DVA Response'
88
- raise NotFoundError.new response_code(xml_doc), response_text(xml_doc)
89
- end
90
- xml_doc.xpath("//dvaCheckResponse/#{node}").each do |private_node|
91
- keys.each do |key|
92
- if key == 'country'
93
- address[key.downcase.to_sym] = convert_country get_value(private_node, key)
94
- else
95
- address[key.downcase.to_sym] = get_value(private_node, key)
96
- end
97
- end
98
- end
99
- xml_doc.xpath("//dvaCheckResponse/#{node}/#{PAYLOAD_NODE}").each do |payload_node|
100
- PAYLOAD_RESPONSE_KEYS.each do |key|
101
- address[key.downcase.to_sym] = get_value(payload_node, key)
102
- end
103
- end
104
- address
105
- else
106
- raise NotFoundError.new response_code(xml_doc), response_text(xml_doc)
107
- end
15
+ def business_collection_check(address, collection)
16
+ envelope[:report_type] = 'COLLECTION_CHECK_BUSINESS'
17
+ insert_company_address address
18
+ insert_collection collection
19
+ commit(:collection_check_consumer)
108
20
  end
109
- end
110
- end
111
21
 
22
+ private
23
+ def insert_collection(collection)
24
+ # Mandatory values
25
+ additional_input('collectionCaseStatus', collection[:case_status])
26
+ additional_input('openAmount', collection[:open_amount])
27
+ additional_input('dateOpen', format_date(collection[:date_open]))
28
+ # Optional values
29
+ additional_input('totalAmount', collection[:total_amount]) if collection[:date_invoice]
30
+ additional_input('invoiceDate', collection[:date_invoice]) if collection[:date_invoice]
31
+ additional_input('iouType', collection[:iou_type]) if collection[:iou_type]
32
+ end
33
+
34
+ end
35
+ end
@@ -4,6 +4,7 @@ module DeltavistaCrifDvaInterface
4
4
  :username,
5
5
  :password,
6
6
  :logger
7
+
7
8
  def initialize
8
9
 
9
10
  end
@@ -0,0 +1,13 @@
1
+ module DeltavistaCrifDvaInterface
2
+ class SoapConfig
3
+ attr_accessor :endpoint, :wsdl, :user_name, :password
4
+
5
+ def initialize(options)
6
+ @endpoint = options[:endpoint] ? options[:endpoint] : 'https://preprodservices.crif-online.ch/CrifSS/CrifSoapServiceV1'
7
+ @wsdl = options[:wsdl] ? options[:wsdl] : '/wsdl/crif-soap-service_v1.0.wsdl'
8
+ @user_name = options[:user_name]
9
+ @password = options[:password]
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,107 @@
1
+ module DeltavistaCrifDvaInterface
2
+ class SoapConverter
3
+
4
+ attr_reader :options, :client, :envelope, :result, :logger
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ @envelope = Hash.new
9
+ @client = Savon.client(
10
+ :wsdl => options.wsdl,
11
+ :endpoint => options.endpoint,
12
+ :soap_version => 2,
13
+ :env => 'soap-env'
14
+ )
15
+ @result = {
16
+ :committed => false,
17
+ :success => false,
18
+ :data => Hash.new
19
+ }
20
+ @logger = options.logger ? options.logger : Logger.new(STDOUT)
21
+ insert_identity
22
+ insert_reference_number
23
+ end
24
+
25
+ def commit(action)
26
+ begin
27
+ result[:data] = @client.call(action, envelope)
28
+ result[:success] = true
29
+ rescue
30
+ result[:data] = Hash.new
31
+ result[:success] = false
32
+ ensure
33
+ result[:committed] = true
34
+ end
35
+ result
36
+ end
37
+
38
+ def insert_reference_number
39
+ envelope[:reference_number] = rand(1..3000)
40
+ end
41
+
42
+ def insert_identity
43
+ envelope[:identity_descriptor] = {
44
+ :user_name => options.user_name,
45
+ :password => options.password
46
+ }
47
+ end
48
+
49
+ def insert_private_address(address)
50
+ envelope[:searched_address] = {
51
+ :first_name => address[:first_name],
52
+ :last_name => address[:last_name],
53
+ :maiden_name => address[:maiden_name],
54
+ :sex => address[:sex],
55
+ :birth_date => format_date(address[:birth_date]),
56
+ :location => parse_location(address),
57
+ :attributes! => {
58
+ 'xsi:type' => 'PersonAddressDescription'
59
+ }
60
+ }
61
+ end
62
+
63
+ def insert_company_address(address)
64
+ envelope[:searched_address] = {
65
+ :company_name => address[:company_name],
66
+ :location => parse_location(address),
67
+ :attributes! => {
68
+ 'xsi:type' => 'CompanyAddressDescription'
69
+ }
70
+ }
71
+ end
72
+
73
+ def additional_input(key, value)
74
+ envelope[:additional_inputs] = Array.new unless envelope[:additional_inputs]
75
+ envelope[:additional_inputs] << {
76
+ :key => key,
77
+ :value => value
78
+ }
79
+ end
80
+
81
+ # Converts alpha-3 country code into alpha-2 country code
82
+ def convert_country(alpha3_code)
83
+ alpha2_code = ''
84
+ begin
85
+ alpha2_code = SunDawg::CountryIsoTranslater.translate_standard(alpha3_code, "alpha3", "alpha2")
86
+ rescue SunDawg::CountryIsoTranslater::NoCountryError
87
+ ensure
88
+ alpha2_code
89
+ end
90
+ end
91
+
92
+ def format_date(date)
93
+ date is_a? Time ? date.strftime('%Y-%m-%d') : nil
94
+ end
95
+
96
+ def parse_location(address)
97
+ {
98
+ :street => address[:street],
99
+ :house_number => address[:house_number],
100
+ :zip => address[:zip],
101
+ :city => address[:city],
102
+ :country => address[:country]
103
+ }
104
+ end
105
+
106
+ end
107
+ end
@@ -1,3 +1,3 @@
1
1
  module DeltavistaCrifDvaInterface
2
- VERSION = '0.0.30'
2
+ VERSION = '0.1.00'
3
3
  end
@@ -11,9 +11,9 @@ module DeltavistaCrifDvaInterface
11
11
 
12
12
  def to_string(value)
13
13
  if value.is_a? Time
14
- return value.strftime("%Y%m%d")
14
+ value.strftime("%Y%m%d")
15
15
  else
16
- return value.to_s.strip
16
+ value.to_s.strip
17
17
  end
18
18
  end
19
19
 
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deltavista_crif_dva_interface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.1.00
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marc Cadalbert
9
9
  - Maik Duff
10
+ - Thomas Wieser
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2013-05-14 00:00:00.000000000 Z
14
+ date: 2013-05-17 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rspec
@@ -76,11 +77,28 @@ dependencies:
76
77
  - - ! '>='
77
78
  - !ruby/object:Gem::Version
78
79
  version: '0'
79
- description: This interface is used to get credit check and address informations from
80
- Deltavista service.
80
+ - !ruby/object:Gem::Dependency
81
+ name: savon
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 2.2.0
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 2.2.0
96
+ description: This interface is used to get credit check, address informations and
97
+ collection checks from the Deltavista/CRIF service.
81
98
  email:
82
99
  - mc@impac.ch
83
100
  - md@impac.ch
101
+ - tw@impac.ch
84
102
  executables: []
85
103
  extensions: []
86
104
  extra_rdoc_files: []
@@ -92,6 +110,8 @@ files:
92
110
  - lib/deltavista_crif_dva_interface/delta_vista_service.rb
93
111
  - lib/deltavista_crif_dva_interface/errors.rb
94
112
  - lib/deltavista_crif_dva_interface/restful_service.rb
113
+ - lib/deltavista_crif_dva_interface/soap_config.rb
114
+ - lib/deltavista_crif_dva_interface/soap_converter.rb
95
115
  - lib/deltavista_crif_dva_interface/version.rb
96
116
  - lib/deltavista_crif_dva_interface/xml_converter.rb
97
117
  - lib/deltavista_crif_dva_interface.rb