BankValUK 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +27 -0
- data/README +81 -0
- data/Rakefile +48 -0
- data/lib/BankVal.rb +286 -0
- data/test/bv_test.rb +108 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
== BankValUK
|
2
|
+
|
3
|
+
Copyright (c) 2010, Unified Software
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of the <organization> nor the
|
14
|
+
names of its contributors may be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL UNIFIED SOFTWARE BE LIABLE FOR ANY
|
21
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
data/README
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
== BankValUK
|
2
|
+
|
3
|
+
== Unified Software (c) 2010
|
4
|
+
|
5
|
+
==SYNOPSIS
|
6
|
+
|
7
|
+
require 'rubygems' #using uppercase letters may load the file more than once which can cause 'already set constant' warnings
|
8
|
+
require 'bankval::uk'
|
9
|
+
|
10
|
+
obj = BankVal::UK.new
|
11
|
+
ans = obj.bank_val_uk('json','00-01-26','abcd123','12345')
|
12
|
+
|
13
|
+
==Description
|
14
|
+
|
15
|
+
This Gem controls the calling of REST web services from Unified Software's UK Bank Validation services.
|
16
|
+
It will transparently call Unified's back up servers in the unlikely event of any issues with the main servers.
|
17
|
+
The services which can be used from this Gem are:
|
18
|
+
|
19
|
+
[BankValPlus2]Validates UK bank sort code / account numbers. Returns transposed sort code and account number plus latest EISCD (Extended Industry Sorting Code Directory) data.
|
20
|
+
|
21
|
+
object = BankVal::UK.new
|
22
|
+
method = object.bank_val_uk(format,sortcode,accountno,userid,pin)
|
23
|
+
|
24
|
+
|
25
|
+
[getBranchDetails2]Look up UK bank branch information using latest EISCD (Extended Industry Sorting Code Directory) data.
|
26
|
+
|
27
|
+
object = BankVal::UK.new
|
28
|
+
method = object.bank_val_uk(format,sortcode,userid,pin)
|
29
|
+
|
30
|
+
|
31
|
+
==Including the Gem
|
32
|
+
|
33
|
+
To allow the usage of this gem you must have RubyGems installed. To check if you have,
|
34
|
+
open a command prompt (win) or console window (*nix) and type 'gem'. If RubyGems is installed
|
35
|
+
you will see a help message. If it isn't a command unrecognised message will appear.
|
36
|
+
|
37
|
+
To install RubyGems please refer to :
|
38
|
+
|
39
|
+
http://docs.rubygems.org/read/chapter/3
|
40
|
+
|
41
|
+
Once Rubygems is installed you can install the BankValUK gem from Rubygems.org by either;
|
42
|
+
|
43
|
+
*searching for BankValUK from within your IDE (e.g. in netbeans tool>RubyGems)
|
44
|
+
|
45
|
+
*opening a command prompt (win) or a console window (*nix) and typing 'gem install BankValInt'
|
46
|
+
|
47
|
+
Once the BankValInt gem is installed on your system it can be included in your code by adding the following two lines:
|
48
|
+
|
49
|
+
require 'rubygems'
|
50
|
+
require 'bankval'
|
51
|
+
|
52
|
+
==Calling the services
|
53
|
+
|
54
|
+
To call the services simply create an instance of the relevant class (as shown in the description above) and call
|
55
|
+
the exposed method (again as shown above)
|
56
|
+
|
57
|
+
==Parameters
|
58
|
+
|
59
|
+
The required parameters for the services are as follows:
|
60
|
+
|
61
|
+
1. Format:: the response format (either xml, json or csv)
|
62
|
+
|
63
|
+
2. Sort Code:: the IBAN to be validated
|
64
|
+
|
65
|
+
3. Account Number:: the account number to be validated (optional)
|
66
|
+
|
67
|
+
4. UserID:: available from www.unifiedsoftware.co.uk
|
68
|
+
|
69
|
+
5. PIN:: available from www.unifiedsoftware.co.uk
|
70
|
+
|
71
|
+
The parameters must be passed in the order shown although account number is optional. In the case of an
|
72
|
+
account number not being passed in the web service getBankDetails2 will be called rather than bankValUKPlus2.
|
73
|
+
|
74
|
+
==Method Returns
|
75
|
+
|
76
|
+
The methods will return the web services response as a string formatted in either xml, json, or csv depending on the format parameter
|
77
|
+
|
78
|
+
==BankValUK Ruby Gem
|
79
|
+
|
80
|
+
==Unified Software 2010
|
81
|
+
==www.unifiedsoftware.co.uk
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# BankValUK rakefile
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rake'
|
6
|
+
require 'rake/clean'
|
7
|
+
require 'rake/gempackagetask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
require 'rake/testtask'
|
10
|
+
require 'spec/rake/spectask'
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = 'BankValUK'
|
14
|
+
s.version = '0.0.2'
|
15
|
+
s.has_rdoc = true
|
16
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
17
|
+
s.summary = 'Handles calls to Unified Softwares BankValUK web services'
|
18
|
+
s.description = s.summary + ' including BankValPlus2 which validates UK bank accounts and returns EISCD data, and getBranchDetails2 which validates UK sort codes and returns EISCD data.'
|
19
|
+
s.author = 'Alec Evans, Unified Software'
|
20
|
+
s.email = 'support@unifiedsoftware.co.uk'
|
21
|
+
s.homepage = 'http://www.unifiedsoftware.co.uk'
|
22
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec,test}/**/*")
|
23
|
+
s.require_path = "lib"
|
24
|
+
s.bindir = "bin"
|
25
|
+
end
|
26
|
+
|
27
|
+
Rake::GemPackageTask.new(spec) do |p|
|
28
|
+
p.gem_spec = spec
|
29
|
+
p.need_tar = true
|
30
|
+
p.need_zip = true
|
31
|
+
end
|
32
|
+
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
files =['README', 'LICENSE', 'lib/**/*.rb']
|
35
|
+
rdoc.rdoc_files.add(files)
|
36
|
+
rdoc.main = "README" # page to start on
|
37
|
+
rdoc.title = "BankValUK Docs"
|
38
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
39
|
+
rdoc.options << '--line-numbers'
|
40
|
+
end
|
41
|
+
|
42
|
+
Rake::TestTask.new do |t|
|
43
|
+
t.test_files = FileList['test/**/*.rb']
|
44
|
+
end
|
45
|
+
|
46
|
+
Spec::Rake::SpecTask.new do |t|
|
47
|
+
t.spec_files = FileList['spec/**/*.rb']
|
48
|
+
end
|
data/lib/BankVal.rb
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
#=BankValInternational
|
2
|
+
#
|
3
|
+
#==Unified Software
|
4
|
+
#
|
5
|
+
#Module containing classes to handle calls to Unified Sotware's
|
6
|
+
#BankValUK web services
|
7
|
+
#
|
8
|
+
#*[BankVal::UK] Which handles calls to <i>BankValPlus2 GetBranchDetails2</i>
|
9
|
+
#
|
10
|
+
module BankVal
|
11
|
+
|
12
|
+
require 'net/https'
|
13
|
+
require 'uri'
|
14
|
+
|
15
|
+
#=BankVal::UK
|
16
|
+
#
|
17
|
+
#Class to control calls to <i>BankValPlus2 GetBranchDetails2</i>
|
18
|
+
#
|
19
|
+
#=Synopsis
|
20
|
+
#
|
21
|
+
# requires 'BankVal::UK'
|
22
|
+
#
|
23
|
+
# @obj1 = BankVal::UK.new
|
24
|
+
# @ans = obj1.bank_val_uk('json','A_SORT_CODE','userID','PINNo')
|
25
|
+
#
|
26
|
+
#or..
|
27
|
+
#
|
28
|
+
# @obj1 = BankVal::UK.new
|
29
|
+
# @ans = obj1.bank_val_uk('json','A_SORT_CODE','AN_ACCOUNT_No','userID','PINNo')
|
30
|
+
#
|
31
|
+
class BankVal::UK
|
32
|
+
@userid
|
33
|
+
@pin
|
34
|
+
@account
|
35
|
+
@sortcode
|
36
|
+
@format
|
37
|
+
@service_url
|
38
|
+
@error_string
|
39
|
+
|
40
|
+
#Method to control calls to _BankValPlus2_ _GetBranchDetails2_
|
41
|
+
#
|
42
|
+
#This method automatically controls calls to Unified software's
|
43
|
+
#BankValUK REST web services
|
44
|
+
#
|
45
|
+
#==Parameters
|
46
|
+
#1.Return Format:: Either 'csv','json','xml'
|
47
|
+
#2.SortCode:: The sortcode to be validated
|
48
|
+
#3.Account:: The account number to be validated (optional)
|
49
|
+
#4.UserId:: can obtained from http://www.unifiedsoftware.co.uk/freetrial/free-trial-home.html
|
50
|
+
#5.PIN:: can obtained from http://www.unifiedsoftware.co.uk/freetrial/free-trial-home.html
|
51
|
+
#
|
52
|
+
#The parameters *must* be passed in the order described above,
|
53
|
+
#although the Account number is optional. Supplying a return format,sort code and login
|
54
|
+
#details only will result in getBranchDetails being called rather than BankValPlus2.
|
55
|
+
#
|
56
|
+
#==Returns
|
57
|
+
#
|
58
|
+
#The response from the webservice is returned as a string in either:
|
59
|
+
#*XML format
|
60
|
+
#*json format
|
61
|
+
#*csv format
|
62
|
+
# depending on the Return Format Parameter passed in
|
63
|
+
#
|
64
|
+
def bank_val_uk(*args)
|
65
|
+
@format = args[0].downcase
|
66
|
+
@sortcode = args[1].gsub(/[- .]/, "")
|
67
|
+
case args.size
|
68
|
+
when 5
|
69
|
+
@account = args[2]
|
70
|
+
@userid = args[3]
|
71
|
+
@pin = args[4]
|
72
|
+
when 4
|
73
|
+
@userid = args[2]
|
74
|
+
@pin = args[3]
|
75
|
+
else
|
76
|
+
return "ERROR - not enough parameters supplied"
|
77
|
+
end
|
78
|
+
format_validation
|
79
|
+
if @error_string != nil
|
80
|
+
format_error_string
|
81
|
+
@error_string.gsub!(/\n/,'')
|
82
|
+
return @error_string
|
83
|
+
end
|
84
|
+
build_req_url
|
85
|
+
return "#{BankVal::GoValidate.new.validate(@service_url)}"
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
#method to build the base request url for the REST call
|
91
|
+
def build_req_url()
|
92
|
+
if @account != nil
|
93
|
+
@service_url = "bankvaluk/bankvalplus2/userid/#{@userid}/pin/#{@pin}/sortcode/#{@sortcode}/account/#{@account}/#{@format}/"
|
94
|
+
else
|
95
|
+
@service_url = "bankvaluk/branchdets2/userid/#{@userid}/pin/#{@pin}/sortcode/#{@sortcode}/#{@format}/"
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
#method to validate input and create error messages if they are invalid
|
101
|
+
def format_validation()
|
102
|
+
@error_string = nil
|
103
|
+
if @format !~ /^json$|^xml$|^csv$/
|
104
|
+
@error_string = "INVALID - Result Format"
|
105
|
+
elsif @account != nil && @account !~ /^[0-9]{7,10}$/
|
106
|
+
@error_string = "INVALID - Account"
|
107
|
+
elsif @sortcode !~ /^[0-9]{6}$/
|
108
|
+
@error_string = "INVALID - Sortcode"
|
109
|
+
elsif @pin !~ /^[0-9]{5}$/
|
110
|
+
@error_string = "ERROR - Invalid User ID/PIN"
|
111
|
+
elsif @userid !~ /^[a-zA-Z\-_][a-zA-Z][a-zA-Z]*\D\d\d\d$/
|
112
|
+
@error_string = "ERROR - Invalid User ID/PIN"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
#method to wrap error string in the correct format, indentation should be left as it is
|
117
|
+
def format_error_string()
|
118
|
+
if @format == "xml" && @account == nil
|
119
|
+
@error_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><branchdets><result>" + @error_string + "</result>
|
120
|
+
<sortcode></sortcode><bicbank></bicbank><bicbranch></bicbranch><subbranchsuffix></subbranchsuffix><bankname></bankname>
|
121
|
+
<owningbank></owningbank><longbank1></longbank1><longbank2></longbank2><ownbc></ownbc><ccode></ccode>
|
122
|
+
<supervisorybody></supervisorybody><deletedate></deletedate><changedate></changedate><printindicator></printindicator>
|
123
|
+
<bacsstatus></bacsstatus><bacschangedate></bacschangedate><bacsclosedate></bacsclosedate><bacsredirectfrom></bacsredirectfrom>
|
124
|
+
<bacsredtoscode></bacsredtoscode><bacssettbank></bacssettbank><bacssettsec></bacssettsec><bacssettsubsec>
|
125
|
+
</bacssettsubsec><bacshandbank></bacshandbank><bacshandst></bacshandst><bacsaccnumflg></bacsaccnumflg>
|
126
|
+
<bacsddiflg></bacsddiflg><bacsdrdisallowed></bacsdrdisallowed><bacscrdisallowed></bacscrdisallowed>
|
127
|
+
<bacscudisallowed></bacscudisallowed><bacsprdisallowed></bacsprdisallowed><bacsbsdisallowed></bacsbsdisallowed>
|
128
|
+
<bacsdvdisallowed></bacsdvdisallowed><bacsaudisallowed></bacsaudisallowed><spare1></spare1><spare2></spare2>
|
129
|
+
<spare3></spare3><spare4></spare4><chapsretind></chapsretind><chapssstatus></chapssstatus><chapsschangedate>
|
130
|
+
</chapsschangedate><chapssclosedate></chapssclosedate><chapsssettmem></chapsssettmem><chapssrbicbank></chapssrbicbank>
|
131
|
+
<chapssrbicbr></chapssrbicbr><chapsestatus></chapsestatus><chapsechangedate></chapsechangedate><chapseclosedate>
|
132
|
+
</chapseclosedate><chapserbicbank></chapserbicbank><chapserbicbr></chapserbicbr><chapsesettmem></chapsesettmem>
|
133
|
+
<chapseretind></chapseretind><chapseswift></chapseswift><spare5></spare5><ccccstatus></ccccstatus><ccccchangedate>
|
134
|
+
</ccccchangedate><ccccclosedate></ccccclosedate><ccccsettbank></ccccsettbank><ccccdasc></ccccdasc><ccccretind></ccccretind>
|
135
|
+
<ccccgbni></ccccgbni><fpsstatus></fpsstatus><fpschangedate></fpschangedate><fpsclosedate></fpsclosedate><fpsredirectfrom>
|
136
|
+
</fpsredirectfrom><fpsredirecttosc></fpsredirecttosc><fpssettbankct></fpssettbankct><fpsspare1></fpsspare1><fpssettbankbc>
|
137
|
+
</fpssettbankbc><fpshandbankct></fpshandbankct><fpsspare2></fpsspare2><fpshandbankbc></fpshandbankbc><fpsaccnumflag>
|
138
|
+
</fpsaccnumflag><fpsagencytype></fpsagencytype><fpsspare3></fpsspare3><printbti></printbti><printmainsc></printmainsc>
|
139
|
+
<printmajlocname></printmajlocname><printminlocname></printminlocname><printbranchname></printbranchname><printsecentryind>
|
140
|
+
</printsecentryind><printsecbrname></printsecbrname><printfbrtit1></printfbrtit1><printfbrtit2></printfbrtit2><printfbrtit3>
|
141
|
+
</printfbrtit3><printaddr1></printaddr1><printaddr2></printaddr2><printaddr3></printaddr3><printaddr4></printaddr4>
|
142
|
+
<printtown></printtown><printcounty></printcounty><printpcode1></printpcode1><printpcode2></printpcode2><printtelarea>
|
143
|
+
</printtelarea><printtelno></printtelno><printtelarea2></printtelarea2><printtelno2></printtelno2></branchdets>"
|
144
|
+
elsif @format == "xml" && @account != nil
|
145
|
+
@error_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><bankvalplus><result>" + @error_string + "</result>
|
146
|
+
<transposedsortcode></transposedsortcode><transposedaccount></transposedaccount><sortcode>
|
147
|
+
</sortcode><bicbank></bicbank><bicbranch></bicbranch><subbranchsuffix></subbranchsuffix>
|
148
|
+
<bankname></bankname><owningbank></owningbank><longbank1></longbank1><longbank2></longbank2>
|
149
|
+
<ownbc></ownbc><ccode></ccode><supervisorybody></supervisorybody><deletedate></deletedate>
|
150
|
+
<changedate></changedate><printindicator></printindicator><bacsstatus></bacsstatus><bacschangedate>
|
151
|
+
</bacschangedate><bacsclosedate></bacsclosedate><bacsredirectfrom></bacsredirectfrom><bacsredtoscode>
|
152
|
+
</bacsredtoscode><bacssettbank></bacssettbank><bacssettsec></bacssettsec><bacssettsubsec></bacssettsubsec>
|
153
|
+
<bacshandbank></bacshandbank><bacshandst></bacshandst><bacsaccnumflg></bacsaccnumflg><bacsddiflg></bacsddiflg>
|
154
|
+
<bacsdrdisallowed></bacsdrdisallowed><bacscrdisallowed></bacscrdisallowed><bacscudisallowed></bacscudisallowed>
|
155
|
+
<bacsprdisallowed></bacsprdisallowed><bacsbsdisallowed></bacsbsdisallowed><bacsdvdisallowed></bacsdvdisallowed>
|
156
|
+
<bacsaudisallowed></bacsaudisallowed><spare1></spare1><spare2></spare2><spare3></spare3><spare4></spare4>
|
157
|
+
<chapsretind></chapsretind><chapssstatus></chapssstatus><chapsschangedate></chapsschangedate><chapssclosedate>
|
158
|
+
</chapssclosedate><chapsssettmem></chapsssettmem><chapssrbicbank></chapssrbicbank><chapssrbicbr></chapssrbicbr>
|
159
|
+
<chapsestatus></chapsestatus><chapsechangedate></chapsechangedate><chapseclosedate></chapseclosedate><chapserbicbank>
|
160
|
+
</chapserbicbank><chapserbicbr></chapserbicbr><chapsesettmem></chapsesettmem><chapseretind></chapseretind><chapseswift>
|
161
|
+
</chapseswift><spare5></spare5><ccccstatus></ccccstatus><ccccchangedate></ccccchangedate><ccccclosedate></ccccclosedate>
|
162
|
+
<ccccsettbank></ccccsettbank><ccccdasc></ccccdasc><ccccretind></ccccretind><ccccgbni></ccccgbni><fpsstatus></fpsstatus>
|
163
|
+
<fpschangedate></fpschangedate><fpsclosedate></fpsclosedate><fpsredirectfrom></fpsredirectfrom><fpsredirecttosc></fpsredirecttosc>
|
164
|
+
<fpssettbankct></fpssettbankct><fpsspare1></fpsspare1><fpssettbankbc></fpssettbankbc><fpshandbankct></fpshandbankct>
|
165
|
+
<fpsspare2></fpsspare2><fpshandbankbc></fpshandbankbc><fpsaccnumflag></fpsaccnumflag><fpsagencytype></fpsagencytype>
|
166
|
+
<fpsspare3></fpsspare3><printbti></printbti><printmainsc></printmainsc><printmajlocname></printmajlocname><printminlocname>
|
167
|
+
</printminlocname><printbranchname></printbranchname><printsecentryind></printsecentryind><printsecbrname>
|
168
|
+
</printsecbrname><printfbrtit1></printfbrtit1><printfbrtit2></printfbrtit2><printfbrtit3></printfbrtit3><printaddr1>
|
169
|
+
</printaddr1><printaddr2></printaddr2><printaddr3></printaddr3><printaddr4></printaddr4><printtown></printtown><printcounty>
|
170
|
+
</printcounty><printpcode1></printpcode1><printpcode2></printpcode2><printtelarea></printtelarea><printtelno></printtelno>
|
171
|
+
<printtelarea2></printtelarea2><printtelno2></printtelno2></bankvalplus>"
|
172
|
+
elsif @format == "json" && @account == nil
|
173
|
+
@error_string = "{\"result\":\"" + @error_string + "\",\"sortcode\":\"\",\"bicbank\":\"\",\"bicbranch\":\"\",
|
174
|
+
\"subbranchsuffix\":\"\",\"bankname\":\"\",\"owningbank\":\"\",\"longbank1\":\"\",\"longbank2\":\"\",\"ownbc\":
|
175
|
+
\"\",\"ccode\":\"\",\"supervisorybody\":\"\",\"deletedate\":\"\",\"changedate\":\"\",\"printindicator\":\"\",\"bacsstatus\":
|
176
|
+
\"\",\"bacschangedate\":\"\",\"bacsclosedate\":\"\",\"bacsredirectfrom\":\"\",\"bacsredtoscode\":\"\",\"bacssettbank\":\"\",\"
|
177
|
+
bacssettsec\":\"\",\"bacssettsubsec\":\"\",\"bacshandbank\":\"\",\"bacshandst\":\"\",\"bacsaccnumflag\":\"\",\"bacsddiflg\":\"\"
|
178
|
+
,\"bacsdrdisallowed\":\"\",\"bacscrdisallowed\":\"\",\"bacscudisallowed\":\"\",\"bacsprdisallowed\"
|
179
|
+
:\"\",\"bacsbsdisallowed\":\"\",\"bacsdvdisallowed\":\"\",\"bacsaudisallowed\":\"\",\"spare1\":\"\",\"spare2\":\"\"
|
180
|
+
,\"spare3\":\"\",\"spare4\":\"\",\"chapsretind\":\"\",\"chapssstatus\":\"\",\"chapsschangedate\":\"\",\"chapssclosedate\"
|
181
|
+
:\"\",\"chapsssettmem\":\"\",\"chapssrbicbank\":\"\",\"chapssrbicbr\":\"\",\"chapsestatus\":\"\",\"chapsechangedate\":\"\"
|
182
|
+
,\"chapseclosedate\":\"\",\"chapserbicbank\":\"\",\"chapserbicbr\":\"\",\"chapsesettmem\":\"\",\"chapseretind\":\"\"
|
183
|
+
,\"chapseswift\":\"\",\"spare5\":\"\",\"ccccstatus\":\"\",\"ccccchangedate\":\"\",\"ccccclosedate\":\"\",\"ccccsettbank\"
|
184
|
+
:\"\",\"ccccdasc\":\"\",\"ccccretind\":\"\",\"ccccgbni\":\"\",\"fpsstatus\":\"\",\"fpschangedate\":\"\",\"fpsclosedate\"
|
185
|
+
:\"\",\"fpsredirectfrom\":\"\",\"fpsredirecttosc\":\"\",\"fpssettbankct\":\"\",\"fpsspare1\":\"\",\"fpssettbankbc\"
|
186
|
+
:\"\",\"fpshandbankct\":\"\",\"fpsspare2\":\"\",\"fpshandbankbc\":\"\",\"fpsaccnumflag\":\"\",\"fpsagencytype\":\"\",\"
|
187
|
+
fpsspare3\":\"\",\"printbti\":\"\",\"printmainsc\":\"\",\"printmajlocname\":\"\",\"printminlocname\":\"\",\"printbranchname\"
|
188
|
+
:\"\",\"printsecentryind\":\"\",\"printsecbrname\":\"\",\"printfbrtit1\":\"\",\"printfbrtit2\":\"\",\"printfbrtit3\":\"\",\"
|
189
|
+
printaddr1\":\"\",\"printaddr2\":\"\",\"printaddr3\":\"\",\"printaddr4\":\"\",\"printtown\":\"\",\"printcounty\"
|
190
|
+
:\"\",\"printpcode1\":\"\",\"printpcode2\":\"\",\"printtelarea\":\"\",\"printtelno\":\"\",\"printtelarea2\":\"\",\"
|
191
|
+
printtelno2\":\"\"}"
|
192
|
+
elsif @format == "json"
|
193
|
+
@error_string = "{\"result\":\"" + @error_string + "\",\"transposedsortcode\":\"\",\"transposedaccount\":\"\",\"sortcode\":\"\",\"bicbank\":\"\",\"bicbranch\":\"\",\"subbranchsuffix\":\"\",\"
|
194
|
+
bankname\":\"\",\"owningbank\":\"\",\"longbank1\":\"\",\"longbank2\":\"\",\"ownbc\":\"\",\"ccode\":\"\",\"supervisorybody\":\"\",\"deletedate\":\"\",\"
|
195
|
+
changedate\":\"\",\"printindicator\":\"\",\"bacsstatus\":\"\",\"bacschangedate\":\"\",\"bacsclosedate\":\"\",\"bacsredirectfrom\":\"\",\"
|
196
|
+
bacsredtoscode\":\"\",\"bacssettbank\":\"\",\"bacssettsec\":\"\",\"bacssettsubsec\":\"\",\"bacshandbank\":\"\",\"bacshandst\":\"\",\"
|
197
|
+
bacsaccnumflag\":\"\",\"bacsddiflg\":\"\",\"bacsdrdisallowed\":\"\",\"bacscrdisallowed\":\"\",\"bacscudisallowed\":\"\",\"
|
198
|
+
bacsprdisallowed\":\"\",\"bacsbsdisallowed\":\"\",\"bacsdvdisallowed\":\"\",\"bacsaudisallowed\":\"\",\"spare1\":\"\",\"spare2\":\"\",\"
|
199
|
+
spare3\":\"\",\"spare4\":\"\",\"chapsretind\":\"\",\"chapssstatus\":\"\",\"chapsschangedate\":\"\",\"chapssclosedate\":\"\",\"
|
200
|
+
chapsssettmem\":\"\",\"chapssrbicbank\":\"\",\"chapssrbicbr\":\"\",\"chapsestatus\":\"\",\"chapsechangedate\":\"\",\"
|
201
|
+
chapseclosedate\":\"\",\"chapserbicbank\":\"\",\"chapserbicbr\":\"\",\"chapsesettmem\":\"\",\"chapseretind\":\"\",\"
|
202
|
+
chapseswift\":\"\",\"spare5\":\"\",\"ccccstatus\":\"\",\"ccccchangedate\":\"\",\"ccccclosedate\":\"\",\"ccccsettbank\":\"\",\"
|
203
|
+
ccccdasc\":\"\",\"ccccretind\":\"\",\"ccccgbni\":\"\",\"fpsstatus\":\"\",\"fpschangedate\":\"\",\"fpsclosedate\":\"\",\"
|
204
|
+
fpsredirectfrom\":\"\",\"fpsredirecttosc\":\"\",\"fpssettbankct\":\"\",\"fpsspare1\":\"\",\"fpssettbankbc\":\"\",\"
|
205
|
+
fpshandbankct\":\"\",\"fpsspare2\":\"\",\"fpshandbankbc\":\"\",\"fpsaccnumflag\":\"\",\"fpsagencytype\":\"\",\"fpsspare3\":\"\",\"
|
206
|
+
printbti\":\"\",\"printmainsc\":\"\",\"printmajlocname\":\"\",\"printminlocname\":\"\",\"printbranchname\":\"\",\"
|
207
|
+
printsecentryind\":\"\",\"printsecbrname\":\"\",\"printfbrtit1\":\"\",\"printfbrtit2\":\"\",\"printfbrtit3\":\"\",\"
|
208
|
+
printaddr1\":\"\",\"printaddr2\":\"\",\"printaddr3\":\"\",\"printaddr4\":\"\",\"printtown\":\"\",\"printcounty\":\"\",\"
|
209
|
+
printpcode1\":\"\",\"printpcode2\":\"\",\"printtelarea\":\"\",\"printtelno\":\"\",\"printtelarea2\":\"\",\"printtelno2\":\"\"}"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
#=BankValInternational::GoValidate
|
217
|
+
#
|
218
|
+
#Class to make calls to Unified Softwares web services
|
219
|
+
#
|
220
|
+
#
|
221
|
+
class BankVal::GoValidate
|
222
|
+
@base_url
|
223
|
+
|
224
|
+
#Method to make REST web service calls and return response
|
225
|
+
#if call to the main data centre fails the back up method is called
|
226
|
+
#to make a call to the back up data centre
|
227
|
+
#
|
228
|
+
#==Parameters
|
229
|
+
#1. Serv_url is the services part of the URL for the REST call
|
230
|
+
#
|
231
|
+
#==Returns
|
232
|
+
#The response from the web service in requested format (XML,JSON or CSV)
|
233
|
+
#
|
234
|
+
#
|
235
|
+
def validate(ser_url)
|
236
|
+
@base_url = "https://www.unifiedsoftware.co.uk/services/"
|
237
|
+
uriobj = URI.parse(@base_url)
|
238
|
+
full_path = uriobj.path + ser_url
|
239
|
+
conn = Net::HTTP.new(uriobj.host, uriobj.port)
|
240
|
+
conn.use_ssl = true
|
241
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
242
|
+
begin
|
243
|
+
webresponse = conn.get2(URI.encode(full_path))
|
244
|
+
rescue Exception => err
|
245
|
+
webresponse = failover(ser_url)
|
246
|
+
end
|
247
|
+
if webresponse == nil
|
248
|
+
return "Unknown Error-Check Local Network"
|
249
|
+
end
|
250
|
+
return webresponse.body
|
251
|
+
end
|
252
|
+
|
253
|
+
#Method to make backup REST web service calls and return response
|
254
|
+
#if call to the main data centre fails this method is called
|
255
|
+
#to make a call to the back up data centre
|
256
|
+
#
|
257
|
+
#==Parameters
|
258
|
+
#1. Serv_url is the services part of the URL for the REST call
|
259
|
+
#
|
260
|
+
#==Returns
|
261
|
+
#The response from the web service as a string in requested format (XML,JSON or CSV)
|
262
|
+
#or..
|
263
|
+
#error message in case of error
|
264
|
+
#
|
265
|
+
def failover(ser_url)
|
266
|
+
@base_url = "https://www.unifiedservices.co.uk/services/"
|
267
|
+
uriobj = URI.parse(@base_url)
|
268
|
+
full_path = uriobj.path + ser_url
|
269
|
+
conn = Net::HTTP.new(uriobj.host, uriobj.port)
|
270
|
+
conn.use_ssl = true
|
271
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
272
|
+
begin
|
273
|
+
webresponse = conn.get2(URI.encode(full_path))
|
274
|
+
rescue Exception => err
|
275
|
+
return "NETWORK ERROR" + err
|
276
|
+
end
|
277
|
+
return webresponse
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
data/test/bv_test.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'BankVal'
|
8
|
+
require 'rexml/document'
|
9
|
+
require 'rubygems'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
class BvTest < Test::Unit::TestCase
|
13
|
+
@obj
|
14
|
+
def setup
|
15
|
+
@obj = BankVal::UK.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_return_validation_UK
|
19
|
+
#test1_1 'J-Son' is rejected as invalid result format
|
20
|
+
assert_match /INVALID - Result Format/,@obj.bank_val_uk('J-Son','89','abcd123','12345')
|
21
|
+
#tests 1_2 to 1_4 test that 'json','xml','csv' are not rejected as invalis result formats
|
22
|
+
assert_no_match /INVALID - Result Format/,@obj.bank_val_uk('json','89','abcd123','12345')
|
23
|
+
assert_no_match /INVALID - Result Format/,@obj.bank_val_uk('xml','89','abcd123','12345')
|
24
|
+
assert_no_match /INVALID - Result Format/,@obj.bank_val_uk('csv','89','abcd123','12345')
|
25
|
+
#test1_5 tests that csv is returned as the first part of the string will be 'INVALID'
|
26
|
+
assert_match /^INVALID/,@obj.bank_val_uk('csv','89','abcd123','12345')
|
27
|
+
#test1_6 tests 'json' fails the csv test5
|
28
|
+
assert_no_match /^INVALID/,@obj.bank_val_uk('json','89','abcd123','12345')
|
29
|
+
#test1_7 tests xml is returned as no parseError will be raised
|
30
|
+
assert_nothing_raised{
|
31
|
+
REXML::Document.new(@obj.bank_val_uk('xml','89','abcd123','12345')).root.name
|
32
|
+
}
|
33
|
+
#test1_8 tests 'json' fails this xml parse i.e. json doesn't return xml
|
34
|
+
assert_raise (NoMethodError){
|
35
|
+
REXML::Document.new(@obj.bank_val_uk('json','89','abcd123','12345')).root.name
|
36
|
+
}
|
37
|
+
#test1_9 tests 'csv' fails xml parse i.e. csv doesn't return xml
|
38
|
+
assert_raise (NoMethodError){
|
39
|
+
REXML::Document.new(@obj.bank_val_uk('csv','89','abcd123','12345')).root.name
|
40
|
+
}
|
41
|
+
#test1_10 tests 'xml' doesn't return json as parse error is raised
|
42
|
+
assert_raise (JSON::ParserError) {
|
43
|
+
JSON[@obj.bank_val_uk('xml','89','abcd123','12345')]
|
44
|
+
}
|
45
|
+
#test1_11 tests 'csv' doesn't return json
|
46
|
+
assert_raise (JSON::ParserError) {
|
47
|
+
JSON[@obj.bank_val_uk('csv','89','abcd123','12345')]
|
48
|
+
}
|
49
|
+
#test1_12 tests ''json' returns valid (parsable) json
|
50
|
+
assert_nothing_raised{
|
51
|
+
JSON[@obj.bank_val_uk('json','89','abcd123','12345')]
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_sort_code_number_validation
|
56
|
+
#test2_1 check oversized sc is rejected
|
57
|
+
assert_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','12121212','abcd123','12345')
|
58
|
+
#test2_1.5 undersized sc
|
59
|
+
assert_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','12122','abcd123','12345')
|
60
|
+
#test2_2 check leading alpha is rejected
|
61
|
+
assert_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','*12121','abcd123','12345')
|
62
|
+
#test2_3 check trailing alpha is rejected
|
63
|
+
assert_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','12123:','abcd123','12345')
|
64
|
+
#test2_4 check embedded alpha is rejected
|
65
|
+
assert_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','12g121','abcd123','12345')
|
66
|
+
#test2_5 check correct size passes (error will be ID/PIN from server)
|
67
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','abcd123','12345')
|
68
|
+
#test2_6 check removal of hyphens full stops and spaces
|
69
|
+
assert_no_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','12 12 30','abcd123','12345')
|
70
|
+
#test2_7 check removal of hyphens full stops and spaces
|
71
|
+
assert_no_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','12-12-30','abcd123','12345')
|
72
|
+
#test2_8 check removal of hyphens full stops and spaces
|
73
|
+
assert_no_match /^\{"result":"INVALID - Sortcode"/, @obj.bank_val_uk('json','12.12.30','abcd123','12345')
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_account_validation
|
77
|
+
#test2.5_1 check over
|
78
|
+
assert_match /^\{"result":"INVALID - Account"/, @obj.bank_val_uk('json','121212','12345678901','abcd123','12345')
|
79
|
+
#test2.5_2 check under
|
80
|
+
assert_match /^\{"result":"INVALID - Account"/, @obj.bank_val_uk('json','121212','123456','abcd123','12345')
|
81
|
+
#test2.5_3 leading alpha
|
82
|
+
assert_match /^\{"result":"INVALID - Account"/, @obj.bank_val_uk('json','121212','g1234567','abcd123','12345')
|
83
|
+
#test2.5_4 trailing alpha
|
84
|
+
assert_match /^\{"result":"INVALID - Account"/, @obj.bank_val_uk('json','121212','1234567h','abcd123','12345')
|
85
|
+
#test2.5_5 embedded alpha
|
86
|
+
assert_match /^\{"result":"INVALID - Account"/, @obj.bank_val_uk('json','121212','1345h678','abcd123','12345')
|
87
|
+
#test2.5_6 correct size passes
|
88
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','12345678','abcd12','12345')
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_userid_validation #test with wireshark as well as returns are identical from server and client validation
|
92
|
+
#test3_1 too short user id 2nd element
|
93
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','abcd12','12345')
|
94
|
+
#test3_2 too long user id 2nd element
|
95
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','abcd1234','12345')
|
96
|
+
#test3_3 too short first element
|
97
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','ab123','12345')
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_pin #test with wireshark as well (look for client hellos these will match each call to either server)
|
101
|
+
#test4_1 too short
|
102
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','abcd012','1234')
|
103
|
+
#test4_2 too long
|
104
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','abcd123','123456')
|
105
|
+
#test4_3 bad chars
|
106
|
+
assert_match /^\{"result":"ERROR - Invalid User ID\/PIN"/, @obj.bank_val_uk('json','121212','abcd123','12{45')
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: BankValUK
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alec Evans, Unified Software
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-01 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Handles calls to Unified Softwares BankValUK web services including BankValPlus2 which validates UK bank accounts and returns EISCD data, and getBranchDetails2 which validates UK sort codes and returns EISCD data.
|
23
|
+
email: support@unifiedsoftware.co.uk
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
- LICENSE
|
31
|
+
files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- lib/BankVal.rb
|
36
|
+
- test/bv_test.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://www.unifiedsoftware.co.uk
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Handles calls to Unified Softwares BankValUK web services
|
71
|
+
test_files: []
|
72
|
+
|