deltavista_crif_dva_interface 0.0.23 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
|
|
1
|
+
module DeltavistaCrifDvaInterface
|
2
|
+
class CollectionCheck < XmlConverter
|
3
|
+
attr_reader :logger
|
4
|
+
|
5
|
+
DEFAULT_OPTIONS = {
|
6
|
+
:encoding => 'UTF-8',
|
7
|
+
:request_type => 'CollectionCheck'
|
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
|
23
|
+
|
24
|
+
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
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_xml(address, collection)
|
38
|
+
builder = Nokogiri::XML::Builder.new(:encoding => @config[:encoding]) do |xml|
|
39
|
+
xml.getCollectionCheck {
|
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.addressDescription {
|
55
|
+
xml.__send__(node) {
|
56
|
+
keys.each do |key|
|
57
|
+
xml.send(key, address[key.downcase]) if address[key.downcase] && !address[key.downcase].empty?
|
58
|
+
end
|
59
|
+
}
|
60
|
+
}
|
61
|
+
xml.collectionInfo {
|
62
|
+
xml.amountTotal collection[:amount_total]
|
63
|
+
xml.amountOpen collection[:amount_open]
|
64
|
+
xml.caseStatus collection[:case_status]
|
65
|
+
xml.dateBill collection[:date_bill].strftime('%Y-%m-%d')
|
66
|
+
xml.dateCase collection[:date_case].strftime('%Y-%m-%d')
|
67
|
+
}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
@@reference_id += 1
|
71
|
+
result = builder.to_xml
|
72
|
+
logger.debug result if logger.debug?
|
73
|
+
result
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_hash(xml_body)
|
77
|
+
logger.debug xml_body if logger.debug?
|
78
|
+
xml_doc = Nokogiri.XML(xml_body, nil, @config[:encoding])
|
79
|
+
if valid_response? xml_doc
|
80
|
+
# private tag
|
81
|
+
address = {}
|
82
|
+
if xml_doc.xpath("//dvaCheckResponse/#{PRIVATE_NODE}")
|
83
|
+
node = PRIVATE_NODE
|
84
|
+
keys = PRIVATE_RESPONSE_KEYS
|
85
|
+
elsif xml_doc.xpath("//dvaCheckResponse/#{COMPANY_NODE}")
|
86
|
+
node = COMPANY_NODE
|
87
|
+
keys = COMPANY_RESPONSE_KEYS
|
88
|
+
else
|
89
|
+
logger.error 'Neither company nor private Node were found in the DVA Response'
|
90
|
+
raise NotFoundError.new response_code(xml_doc), response_text(xml_doc)
|
91
|
+
end
|
92
|
+
xml_doc.xpath("//dvaCheckResponse/#{node}").each do |private_node|
|
93
|
+
keys.each do |key|
|
94
|
+
if key == 'country'
|
95
|
+
address[key.downcase.to_sym] = convert_country get_value(private_node, key)
|
96
|
+
else
|
97
|
+
address[key.downcase.to_sym] = get_value(private_node, key)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
xml_doc.xpath("//dvaCheckResponse/#{node}/#{PAYLOAD_NODE}").each do |payload_node|
|
102
|
+
PAYLOAD_RESPONSE_KEYS.each do |key|
|
103
|
+
address[key.downcase.to_sym] = get_value(payload_node, key)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
address
|
107
|
+
else
|
108
|
+
raise NotFoundError.new response_code(xml_doc), response_text(xml_doc)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
@@ -7,4 +7,5 @@ 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
9
|
require "deltavista_crif_dva_interface/credit_check_short_v02"
|
10
|
+
require "deltavista_crif_dva_interface/collection_check"
|
10
11
|
require "deltavista_crif_dva_interface/address_update"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deltavista_crif_dva_interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.24
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -86,6 +86,7 @@ extensions: []
|
|
86
86
|
extra_rdoc_files: []
|
87
87
|
files:
|
88
88
|
- lib/deltavista_crif_dva_interface/address_update.rb
|
89
|
+
- lib/deltavista_crif_dva_interface/collection_check.rb
|
89
90
|
- lib/deltavista_crif_dva_interface/config.rb
|
90
91
|
- lib/deltavista_crif_dva_interface/credit_check_short_v02.rb
|
91
92
|
- lib/deltavista_crif_dva_interface/delta_vista_service.rb
|