line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::BankVal::International::IBANValidate;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
542
|
use 5.008000;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
32
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use vars qw($size $format $iban $userid $pin $error $ua $url);
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
96
|
|
8
|
1
|
|
|
1
|
|
936
|
use LWP::UserAgent;
|
|
1
|
|
|
|
|
52692
|
|
|
1
|
|
|
|
|
41
|
|
9
|
1
|
|
|
1
|
|
1800
|
use XML::Simple;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use JSON;
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter;
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(ibanValidate new);
|
15
|
|
|
|
|
|
|
our $VERSION = '0.05';
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $format; #response return format i.e. xml json csv
|
18
|
|
|
|
|
|
|
my $iban; #the IBAN to be validated
|
19
|
|
|
|
|
|
|
my $userid;
|
20
|
|
|
|
|
|
|
my $pin;
|
21
|
|
|
|
|
|
|
my $size; #the number of parameters passed only 2 and 4 are valid
|
22
|
|
|
|
|
|
|
my $error; #any error messages generated here, not from unifieds servers
|
23
|
|
|
|
|
|
|
my $responseString; #the return value of ibanValidate either $errors or web service response
|
24
|
|
|
|
|
|
|
my $ua;
|
25
|
|
|
|
|
|
|
my $url;
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#constructor
|
28
|
|
|
|
|
|
|
sub new {
|
29
|
|
|
|
|
|
|
my $proto = shift;
|
30
|
|
|
|
|
|
|
my $class = ref($proto) || $proto;
|
31
|
|
|
|
|
|
|
my $self = {};
|
32
|
|
|
|
|
|
|
bless ($self, $class);
|
33
|
|
|
|
|
|
|
return $self;
|
34
|
|
|
|
|
|
|
}
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# exportable sub takes parameter array of 2 or 4 elements
|
37
|
|
|
|
|
|
|
# see perldoc for this module for more details
|
38
|
|
|
|
|
|
|
# ibanValidate($format,$iban,$userid,pin);
|
39
|
|
|
|
|
|
|
# or ibanValidate($format,$iban);
|
40
|
|
|
|
|
|
|
sub ibanValidate{
|
41
|
|
|
|
|
|
|
$error="";
|
42
|
|
|
|
|
|
|
my @params = @_;
|
43
|
|
|
|
|
|
|
$size = @params;
|
44
|
|
|
|
|
|
|
#the following block checks to see if the first param is a reference
|
45
|
|
|
|
|
|
|
#if it is then the sub was called as an object ref so size is reduced
|
46
|
|
|
|
|
|
|
#accordingly
|
47
|
|
|
|
|
|
|
my $refCheck = shift @_; #remove the leftmost array element
|
48
|
|
|
|
|
|
|
if (ref($refCheck)){ #check if its a reference
|
49
|
|
|
|
|
|
|
$size--; #if it is reduce the size value to account for it
|
50
|
|
|
|
|
|
|
}else{ #otherwise
|
51
|
|
|
|
|
|
|
unshift(@_, $refCheck); #put it back
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
$format = lc($_[0]);
|
54
|
|
|
|
|
|
|
$iban = $_[1];
|
55
|
|
|
|
|
|
|
if ($size > 2){
|
56
|
|
|
|
|
|
|
$userid = $_[2];
|
57
|
|
|
|
|
|
|
$pin = $_[3];
|
58
|
|
|
|
|
|
|
}else{
|
59
|
|
|
|
|
|
|
&loadUidPin;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
#all params should now be present so call validate formats sub
|
62
|
|
|
|
|
|
|
&validateFormat;
|
63
|
|
|
|
|
|
|
#if invalid formats are found return error message
|
64
|
|
|
|
|
|
|
if ($error){
|
65
|
|
|
|
|
|
|
$responseString = "$error";
|
66
|
|
|
|
|
|
|
&formatErrorMsg;
|
67
|
|
|
|
|
|
|
return $responseString;
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
#if all formats are ok call web service sub then return response
|
70
|
|
|
|
|
|
|
&goValidate;
|
71
|
|
|
|
|
|
|
return $responseString;
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub goValidate{
|
76
|
|
|
|
|
|
|
#create user agent
|
77
|
|
|
|
|
|
|
$ua = LWP::UserAgent->new();
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#build the URL
|
80
|
|
|
|
|
|
|
my $baseUrl = 'https://www.unifiedsoftware.co.uk/services/bankvalint/ibanvalidator';
|
81
|
|
|
|
|
|
|
$url = "$baseUrl/userid/$userid/pin/$pin/iban/$iban/$format/";
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#call the service
|
84
|
|
|
|
|
|
|
my $response = $ua->get($url);
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#Check the response code if its fail call backup server sub
|
87
|
|
|
|
|
|
|
if($response->code<200||$response->code>399){
|
88
|
|
|
|
|
|
|
&goFallOver;
|
89
|
|
|
|
|
|
|
} else {
|
90
|
|
|
|
|
|
|
$responseString = $response->content();
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
}
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub goFallOver{
|
95
|
|
|
|
|
|
|
#build the URL
|
96
|
|
|
|
|
|
|
my $baseUrl = 'https://www.unifiedservices.co.uk/services/bankvalint/ibanvalidator';
|
97
|
|
|
|
|
|
|
$url = "$baseUrl/userid/$userid/pin/$pin/iban/$iban/$format/";
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#call the service
|
100
|
|
|
|
|
|
|
my $response = $ua->get($url);
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#Check the response code
|
103
|
|
|
|
|
|
|
if($response->code<200||$response->code>399){
|
104
|
|
|
|
|
|
|
$responseString .= $response->code;
|
105
|
|
|
|
|
|
|
} else {
|
106
|
|
|
|
|
|
|
$responseString = $response->content();
|
107
|
|
|
|
|
|
|
}
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub validateFormat{
|
111
|
|
|
|
|
|
|
#Validate response format must match json, xml, or, csv
|
112
|
|
|
|
|
|
|
if ($format !~ /^json$|^xml$|^csv$/){
|
113
|
|
|
|
|
|
|
$error .= "INVALID - Result Format";
|
114
|
|
|
|
|
|
|
return;
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
#Validate IBAN up to 34 chars A-Z 0-9
|
117
|
|
|
|
|
|
|
if ($iban !~ /^[A-Z,0-9]{1,34}$/) {
|
118
|
|
|
|
|
|
|
$error .= "INVALID - FORMAT";
|
119
|
|
|
|
|
|
|
return;
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
#Validate PIN all numeric 5 characters
|
122
|
|
|
|
|
|
|
if ($pin){
|
123
|
|
|
|
|
|
|
if ($pin !~ /^\d\d\d\d\d$/){
|
124
|
|
|
|
|
|
|
$error .= "ERROR -Invalid User ID/PIN";
|
125
|
|
|
|
|
|
|
return;
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
}
|
128
|
|
|
|
|
|
|
#Validate UID must end with 3 numerics exactly and start with 3 Alpha variable length otherwise
|
129
|
|
|
|
|
|
|
if ($userid){
|
130
|
|
|
|
|
|
|
if ($userid !~ /^[a-zA-Z\-_][a-zA-Z][a-zA-Z]*\D\d\d\d$/){
|
131
|
|
|
|
|
|
|
$error .= "ERROR -Invalid User ID/PIN";
|
132
|
|
|
|
|
|
|
return;
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub loadUidPin {
|
138
|
|
|
|
|
|
|
my $fileOpened = open UIDCONF, "InternationalLoginConfig.txt";
|
139
|
|
|
|
|
|
|
if ( ! $fileOpened){
|
140
|
|
|
|
|
|
|
$error .= "No UserID / PIN supplied, please visit http://www.unifiedsoftware.co.uk/freetrial/free-trial-home.html: ";
|
141
|
|
|
|
|
|
|
}else{
|
142
|
|
|
|
|
|
|
while (){
|
143
|
|
|
|
|
|
|
if ($_ =~ /^UserID/){
|
144
|
|
|
|
|
|
|
chomp(my @line = split (/ |\t/,$_));
|
145
|
|
|
|
|
|
|
$userid = $line[-1];
|
146
|
|
|
|
|
|
|
}elsif($_ =~ /^PIN/){
|
147
|
|
|
|
|
|
|
chomp(my @line = split (/ |\t/,$_));
|
148
|
|
|
|
|
|
|
$pin = $line[-1];
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
#check to see if conf file has empty params - if so return error message directing to free trial page
|
153
|
|
|
|
|
|
|
if (($userid !~ /\w/) || ($pin !~ /\w/)){
|
154
|
|
|
|
|
|
|
$error .= "No User ID / PIN supplied, please visit http://www.unifiedsoftware.co.uk/freetrial/free-trial-home.html: ";
|
155
|
|
|
|
|
|
|
}
|
156
|
|
|
|
|
|
|
close UIDCONF;
|
157
|
|
|
|
|
|
|
}
|
158
|
|
|
|
|
|
|
}
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub formatErrorMsg{
|
161
|
|
|
|
|
|
|
if($format eq "xml"){
|
162
|
|
|
|
|
|
|
$responseString = "" . $responseString . "";
|
163
|
|
|
|
|
|
|
}elsif($format eq "json"){
|
164
|
|
|
|
|
|
|
$responseString = "{\"result\":\"" . $responseString . "\"}";
|
165
|
|
|
|
|
|
|
}
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1;
|
169
|
|
|
|
|
|
|
__END__
|