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