Finance-BankVal-UK

 view release on metacpan or  search on metacpan

lib/Finance/BankVal/UK.pm  view on Meta::CPAN

 #Validate sortcode all numeric 6 chars (-'s and ws stripped in calling routine)
	if ( $sortcode !~ /^\d\d\d\d\d\d$/ ) {
		$error .= "INVALID - Sortcode";
		return;
	}

	#Validate account all numeric between 6 and 12 digits
	if (   ( length($account) < 6 )
		|| ( length($account) > 12 )
		|| ( $account !~ /^\d+\d$/ ) )
	{
		$error .= "INVALID - Account";
		return;
	}

	#Validate PIN all numeric 5 characters
	if ( $pin !~ /^\d\d\d\d\d$/ ) {
		$error .= "ERROR - Invalid User ID/PIN";
		return;
	}

#Validate UID must end with 3 numerics exactly and start with 3 Alpha variable length otherwise
	if ( $uid !~ /^[a-zA-Z\-_][a-zA-Z][a-zA-Z]*\D\d\d\d$/ ) {
		$error .= "ERROR - Invalid User ID/PIN";
		return;
	}
}

#sub to load PIN and UserID from LoginConfig.txt file if they weren't passed in with the method call
#returns an error if unsuccessful
sub loadUidPin {
	my $fileOpened = open UIDCONF, "LoginConfig.txt";
	if ( !$fileOpened ) {
		$error .=
"No UserID / PIN supplied, please visit https://www.unifiedsoftware.co.uk/request-a-free-trial/: ";
	}
	else {
		while (<UIDCONF>) {
			if ( $_ =~ /^UserID/ ) {
				chomp( my @line = split( / |\t/, $_ ) );
				$uid = $line[-1];
			}
			elsif ( $_ =~ /^PIN/ ) {
				chomp( my @line = split( / |\t/, $_ ) );
				$pin = $line[-1];
			}

		}

#check to see if conf file has empty params - if so return error message directing to free trial page
		if ( ( $uid !~ /\w/ ) || ( $pin !~ /\w/ ) ) {
			$error .=
"No UserID / PIN supplied, please visit https://www.unifiedsoftware.co.uk/request-a-free-trial/: ";
		}
		close UIDCONF;
	}
}

sub loadContent {
	$json =
"{'credentials':{'uname':'$uid','pin':'$pin'},'account':{'account':'$account','sortcode':'$sortcode'}}";
}

#sub to format the error message in the correct expected format with all nodes etc
sub formatErrorMsg {
	if ( substr( $responseString, 0, 7 ) eq 'INVALID' ) {
		$responseString =
		  "{\"validationID\": \"\",\"BankValUK\": {\"result\":\""
		  . $responseString . "\"}}";
	}
	else {
		$responseString = "{\"Error\": \"Invalid Credentials\"}";
	}

}

1;
__END__

=head1 NAME

Finance::BankValUK - Perl extension for accessing Unified Software's bankValUK web
services

=head1 SYNOPSIS

  use Finance::BankVal::UK qw(&bankValUK);

  $result = &bankValUK(@params);

  ============= or for OO =============

  use Finance::BankVal::UK;

  my $bvObj = Finance::BankVal::UK->new();
  $result = $bvObj->bankValUK(@params);


=head1 DESCRIPTION

This module handles all of the restful web service calls to Unified Software's
BankValUK service. It also handles fail over to the back up services transparently to the
calling script. It can be called either in a procedural sense or an OO one (see synopsis)

The exposed method &bankValUK(); takes a number of parameters including;

1: Sort code	- 6 digit number either 00-00-00, 00 00 00 or 000000

2: Account no.	- 6 to 12 digit (unseperated i.e. 00000000)

3: UserID	- available from www.unifiedsoftware.co.uk

4: PIN		- available from www.unifiedsoftware.co.uk

(UserID and PIN are available from https://www.unifiedsoftware.co.uk/request-a-free-trial/)

The order of the parameters B<must> be as above.
The UserID and PIN can also be stored in the LoginConfig.txt file bundled with this module, the
use of this file saves passing the PIN and user ID data with each call to bankValUK.
For example a call to validate a UK bank account passing the user ID and PIN as parameters
and printing the reply to console should follow this form:



( run in 0.780 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )