| 1 | package Experian::IDAuth; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | our $VERSION = '2.1'; | ||
| 6 | |||
| 7 | 1 | ▶ | use Locale::Country; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Path::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use WWW::Mechanize; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use XML::Simple; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use XML::Twig; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | use SOAP::Lite; | ||
| 13 | use IO::Socket::SSL 'SSL_VERIFY_NONE'; | ||
| 14 | |||
| 15 | sub new { | ||
| 16 | my ( $class, %args ) = @_; | ||
| 17 | my $obj = bless {}, $class; | ||
| 18 | $obj->set( $obj->defaults, %args ); | ||
| 19 | return $obj; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub defaults { | ||
| 23 | my $self = shift; | ||
| 24 | return ( | ||
| 25 | username => 'experian_user', | ||
| 26 | password => '?', | ||
| 27 | members_url => 'https://proveid.experian.com', | ||
| 28 | api_uri => 'http://corpwsdl.oneninetwo', | ||
| 29 | api_proxy => 'https://xml.proveid.experian.com/IDSearch.cfc', | ||
| 30 | folder => '/tmp/proveid', | ||
| 31 | |||
| 32 | # if you're using a logger, | ||
| 33 | #logger => Log::Log4per::get_logger, | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub set { | ||
| 38 | my ( $self, %args ) = @_; | ||
| 39 | $self->{$_} = $args{$_} for keys %args; | ||
| 40 | return $self; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub logi { | ||
| 44 | my ( $self, $msg ) = @_; | ||
| 45 | |||
| 46 | if ( $self->{logger} ) { | ||
| 47 | return $self->{logger}->info($msg); | ||
| 48 | } | ||
| 49 | |||
| 50 | return; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub get_result { | ||
| 54 | my $self = shift; | ||
| 55 | $self->_do_192_authentication || return; | ||
| 56 | for ( $self->{search_option} ) { | ||
| 57 | /ProveID_KYC/ && return $self->_get_result_proveid; | ||
| 58 | /CheckID/ && return $self->_get_result_checkid; | ||
| 59 | die "invalid search_option $_"; | ||
| 60 | } | ||
| 61 | return; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub save_pdf_result { | ||
| 65 | |||
| 66 | my $self = shift; | ||
| 67 | |||
| 68 | # Parse and convert the result to hash | ||
| 69 | my $result = $self->_xml_as_hash || die 'no xml result in place'; | ||
| 70 | |||
| 71 | # 192 reference which we should pass to 192 to download the result | ||
| 72 | my $our_ref = $result->{OurReference} || do { | ||
| 73 | $self->logi("No 'OurReference'; invalid save-pdf request"); | ||
| 74 | return; | ||
| 75 | }; | ||
| 76 | |||
| 77 | my $url = $self->{members_url}; | ||
| 78 | my $mech = WWW::Mechanize->new(); | ||
| 79 | $mech->ssl_opts( | ||
| 80 | verify_hostname => 0, | ||
| 81 | SSL_verify_mode => SSL_VERIFY_NONE | ||
| 82 | ); | ||
| 83 | |||
| 84 | eval { | ||
| 85 | |||
| 86 | # Get the login page | ||
| 87 | $mech->get("$url/signin/"); | ||
| 88 | |||
| 89 | # Login to the members environments | ||
| 90 | $mech->submit_form( | ||
| 91 | with_fields => { | ||
| 92 | login => $self->{username}, | ||
| 93 | password => $self->{password}, | ||
| 94 | } | ||
| 95 | ); | ||
| 96 | |||
| 97 | # Download pdf result on given reference number | ||
| 98 | $mech->get("$url/archive/index.cfm?event=archive.pdf&id=$our_ref"); | ||
| 99 | 1; | ||
| 100 | } || do { | ||
| 101 | my $err = $@; | ||
| 102 | $self->logi("errors downloading pdf: $err"); | ||
| 103 | return; | ||
| 104 | }; | ||
| 105 | |||
| 106 | # Save the result to our pdf path | ||
| 107 | my $folder_pdf = "$self->{folder}/pdf"; | ||
| 108 | |||
| 109 | # make directory if necessary | ||
| 110 | if ( not -d $folder_pdf ) { | ||
| 111 | Path::Tiny::path($folder_pdf)->mkpath; | ||
| 112 | } | ||
| 113 | my $file_pdf = $self->_pdf_report_filename; | ||
| 114 | $mech->save_content($file_pdf); | ||
| 115 | |||
| 116 | # Check if the downloaded file is a pdf. | ||
| 117 | my $file_type = qx(file $file_pdf); | ||
| 118 | if ( $file_type !~ /PDF/ ) { | ||
| 119 | $self->logi("discarding downloaded file $file_pdf, not a pdf!"); | ||
| 120 | unlink $file_pdf; | ||
| 121 | return; | ||
| 122 | } | ||
| 123 | |||
| 124 | return 1; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub has_downloaded_pdf { | ||
| 128 | my $self = shift; | ||
| 129 | my $file_pdf = $self->_pdf_report_filename; | ||
| 130 | -e ($file_pdf) || return; | ||
| 131 | my $file_type = qx(file $file_pdf); | ||
| 132 | return $file_type =~ /PDF/; | ||
| 133 | } | ||
| 134 | |||
| 135 | sub has_done_request { | ||
| 136 | my $self = shift; | ||
| 137 | return -f $self->_xml_report_filename; | ||
| 138 | } | ||
| 139 | |||
| 140 | sub get_192_xml_report { | ||
| 141 | my $self = shift; | ||
| 142 | return Path::Tiny::path( $self->_xml_report_filename )->slurp; | ||
| 143 | } | ||
| 144 | |||
| 145 | sub valid_country { | ||
| 146 | my $self = shift; | ||
| 147 | my $country = shift; | ||
| 148 | for ( | ||
| 149 | |||
| 150 | # To make CheckID work well for non-UK countries we need to pass | ||
| 151 | # in drivers license, Passport MRZ, national ID number | ||
| 152 | #qw( ad at au be ca ch cz dk es fi fr gb gg hu ie im it je lu nl no pt se sk us ) | ||
| 153 | qw ( gb im ) | ||
| 154 | ) | ||
| 155 | { | ||
| 156 | return 1 if $country eq $_; | ||
| 157 | } | ||
| 158 | return; | ||
| 159 | } | ||
| 160 | |||
| 161 | sub _build_request { | ||
| 162 | my $self = shift; | ||
| 163 | |||
| 164 | $self->{request_as_xml} = | ||
| 165 | '<Search>' | ||
| 166 | . ( $self->_build_authentication_tag ) | ||
| 167 | . ( $self->_build_country_code_tag || return ) | ||
| 168 | . ( $self->_build_person_tag || return ) | ||
| 169 | . ( $self->_build_addresses_tag ) | ||
| 170 | . ( $self->_build_telephones_tag ) | ||
| 171 | . ( $self->_build_search_reference_tag || return ) | ||
| 172 | . ( $self->_build_search_option_tag ) | ||
| 173 | . '</Search>'; | ||
| 174 | |||
| 175 | return 1; | ||
| 176 | } | ||
| 177 | |||
| 178 | # Send the given SOAP request to 192.com | ||
| 179 | sub _send_request { | ||
| 180 | my $self = shift; | ||
| 181 | |||
| 182 | my $request = $self->{request_as_xml} || die 'needs request'; | ||
| 183 | |||
| 184 | # Hide password | ||
| 185 | ( my $request1 = $request ) =~ | ||
| 186 | s/\<Password\>.+\<\/Password\>/\<Password\>XXXXXXX<\/Password\>/; | ||
| 187 | |||
| 188 | # Log request | ||
| 189 | $self->logi( "REQUEST: " . $self->{client_id} . " : $request1" ); | ||
| 190 | |||
| 191 | # Create soap object | ||
| 192 | my $soap = | ||
| 193 | SOAP::Lite->readable(1)->uri( $self->{api_uri} ) | ||
| 194 | ->proxy( $self->{api_proxy} ); | ||
| 195 | |||
| 196 | $soap->transport->ssl_opts( | ||
| 197 | verify_hostname => 0, | ||
| 198 | SSL_verify_mode => SSL_VERIFY_NONE | ||
| 199 | ); | ||
| 200 | $soap->transport->timeout(60); | ||
| 201 | |||
| 202 | # Do it | ||
| 203 | my $som = $soap->search($request); | ||
| 204 | if ( $som->fault ) { | ||
| 205 | $self->logi( "ERRTEXT: " . $som->fault->faultstring ); | ||
| 206 | return; | ||
| 207 | } | ||
| 208 | |||
| 209 | my $result = $som->result; | ||
| 210 | $self->logi("RESULTS: $result"); | ||
| 211 | $self->{result_as_xml} = $result; | ||
| 212 | |||
| 213 | return 1; | ||
| 214 | } | ||
| 215 | |||
| 216 | sub _build_authentication_tag { | ||
| 217 | my $self = shift; | ||
| 218 | return | ||
| 219 | "<Authentication><Username>$self->{username}</Username><Password>$self->{password}</Password></Authentication>"; | ||
| 220 | } | ||
| 221 | |||
| 222 | sub _build_country_code_tag { | ||
| 223 | my $self = shift; | ||
| 224 | my $two_digit_country = $self->{residence}; | ||
| 225 | my $three_digit_country = | ||
| 226 | uc Locale::Country::country_code2code( $two_digit_country, | ||
| 227 | LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3 ); | ||
| 228 | |||
| 229 | if ( not $three_digit_country ) { | ||
| 230 | $self->logi( "Client " | ||
| 231 | . $self->{client_id} | ||
| 232 | . " could not get country from residence [$two_digit_country]" ); | ||
| 233 | return; | ||
| 234 | } | ||
| 235 | |||
| 236 | return "<CountryCode>$three_digit_country</CountryCode>"; | ||
| 237 | } | ||
| 238 | |||
| 239 | sub _build_person_tag { | ||
| 240 | my $self = shift; | ||
| 241 | |||
| 242 | my $dob = $self->{date_of_birth} || do { | ||
| 243 | $self->logi( "No date of birth for " . $self->{client_id} ); | ||
| 244 | return; | ||
| 245 | }; | ||
| 246 | |||
| 247 | if ( $dob =~ /^(\d\d\d\d)/ ) { | ||
| 248 | my $birth_year = $1; | ||
| 249 | |||
| 250 | # Check client not older than 100 or less than 18 years old | ||
| 251 | my ( undef, undef, undef, undef, undef, $curyear ) = gmtime(time); | ||
| 252 | $curyear += 1900; | ||
| 253 | my $maxyear = $curyear - 17; | ||
| 254 | my $minyear = $curyear - 100; | ||
| 255 | |||
| 256 | if ( $birth_year > $maxyear or $birth_year < $minyear ) { | ||
| 257 | return; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | else { | ||
| 261 | $self->logi( "Invalid date of birth [$dob] for " . $self->{client_id} ); | ||
| 262 | return; | ||
| 263 | } | ||
| 264 | |||
| 265 | return | ||
| 266 | '<Person>' | ||
| 267 | . '<Name><Forename>' | ||
| 268 | . $self->{first_name} | ||
| 269 | . '</Forename>' | ||
| 270 | . '<Surname>' | ||
| 271 | . $self->{last_name} | ||
| 272 | . '</Surname></Name>' | ||
| 273 | . "<DateOfBirth>$dob</DateOfBirth>" | ||
| 274 | . '</Person>'; | ||
| 275 | |||
| 276 | } | ||
| 277 | |||
| 278 | sub _build_addresses_tag { | ||
| 279 | my $self = shift; | ||
| 280 | |||
| 281 | my $postcode = $self->{postcode}; | ||
| 282 | my $premise = $self->{premise} || die 'needs premise'; | ||
| 283 | my $country_code = $self->_build_country_code_tag; | ||
| 284 | |||
| 285 | return qq(<Addresses><Address Current="1"><Premise>$premise</Premise>) | ||
| 286 | . qq(<Postcode>$postcode</Postcode>$country_code</Address></Addresses>); | ||
| 287 | } | ||
| 288 | |||
| 289 | sub _build_telephones_tag { | ||
| 290 | my $self = shift; | ||
| 291 | |||
| 292 | my $telephone_type = 'U'; | ||
| 293 | my $number; | ||
| 294 | if ( $self->{phone} =~ /^([\+\d\s]+)/ ) { | ||
| 295 | $number = $1; | ||
| 296 | } | ||
| 297 | |||
| 298 | return | ||
| 299 | '<Telephones>' | ||
| 300 | . qq(<Telephone Type="$telephone_type">) | ||
| 301 | . "<Number>$number</Number>" | ||
| 302 | . "</Telephone>" | ||
| 303 | . '</Telephones>'; | ||
| 304 | } | ||
| 305 | |||
| 306 | sub _build_search_reference_tag { | ||
| 307 | my $self = shift; | ||
| 308 | my $shortopt = ( $self->{search_option} eq 'ProveID_KYC' ) ? 'PK' : 'C'; | ||
| 309 | my $time = time(); | ||
| 310 | return | ||
| 311 | "<YourReference>${shortopt}_" | ||
| 312 | . $self->{client_id} | ||
| 313 | . "_$time</YourReference>"; | ||
| 314 | } | ||
| 315 | |||
| 316 | sub _build_search_option_tag { | ||
| 317 | my $self = shift; | ||
| 318 | return | ||
| 319 | "<SearchOptions><ProductCode>$self->{search_option}</ProductCode></SearchOptions>"; | ||
| 320 | } | ||
| 321 | |||
| 322 | sub _xml_as_hash { | ||
| 323 | my $self = shift; | ||
| 324 | my $xml = $self->{result_as_xml} || return; | ||
| 325 | return XML::Simple::XMLin( | ||
| 326 | $xml, | ||
| 327 | KeyAttr => { DocumentID => 'type' }, | ||
| 328 | ForceArray => ['DocumentID'], | ||
| 329 | ContentKey => '-content', | ||
| 330 | ); | ||
| 331 | } | ||
| 332 | |||
| 333 | sub _get_result_proveid { | ||
| 334 | my $self = shift; | ||
| 335 | |||
| 336 | my $report = $self->{result_as_xml} || die 'needs xml report'; | ||
| 337 | |||
| 338 | my $twig = eval { XML::Twig->parse($report) } || do { | ||
| 339 | my $err = $@; | ||
| 340 | $self->logi("could not parse xml report: $err"); | ||
| 341 | return; | ||
| 342 | }; | ||
| 343 | |||
| 344 | my ($report_summary_twig) = $twig->get_xpath( | ||
| 345 | '/Search/Result/Summary/ReportSummary/DatablocksSummary'); | ||
| 346 | |||
| 347 | return unless $report_summary_twig; | ||
| 348 | |||
| 349 | my %report_summary; | ||
| 350 | for my $dblock ( $report_summary_twig->get_xpath('DatablockSummary') ) { | ||
| 351 | my $name = $dblock->findvalue('Name'); | ||
| 352 | my $value = $dblock->findvalue('Decision'); | ||
| 353 | $report_summary{$name} = $value; | ||
| 354 | } | ||
| 355 | my ($kyc_summary) = $twig->get_xpath('/Search/Result/Summary/KYCSummary'); | ||
| 356 | my ($credit_reference) = | ||
| 357 | $twig->get_xpath('/Search/Result/CreditReference/CreditReferenceSummary'); | ||
| 358 | |||
| 359 | return unless $credit_reference and $kyc_summary; | ||
| 360 | |||
| 361 | my $decision = { matches => []}; | ||
| 362 | |||
| 363 | # check if client has died or fraud | ||
| 364 | my $cr_deceased = $credit_reference->findvalue('DeceasedMatch') || 0; | ||
| 365 | $report_summary{Deceased} ||= 0; | ||
| 366 | my $confidence_level = 0; | ||
| 367 | if ( $report_summary{Deceased} ) { | ||
| 368 | |||
| 369 | # We only taking Deceased flag in ReportSummary into account | ||
| 370 | # if ConfidenceLevel 7 or above | ||
| 371 | my ($deceased_record) = | ||
| 372 | $twig->get_xpath('/Search/Result/Deceased/DeceasedRecord'); | ||
| 373 | $confidence_level = $deceased_record->findvalue('ConfidenceLevel') || 0; | ||
| 374 | } | ||
| 375 | if ( ( $report_summary{Deceased} == 1 and $confidence_level > 6 ) | ||
| 376 | or $cr_deceased == 1 ) | ||
| 377 | { | ||
| 378 | $decision->{deceased} = 1; | ||
| 379 | } | ||
| 380 | |||
| 381 | $report_summary{Fraud} ||= 0; | ||
| 382 | if ( $report_summary{Fraud} == 1 ) { | ||
| 383 | $decision->{fraud} = 1; | ||
| 384 | } | ||
| 385 | |||
| 386 | # check if client is age verified | ||
| 387 | my $kyc_dob = $kyc_summary->findvalue('DateOfBirth/Count') || 0; | ||
| 388 | my $cr_total = $credit_reference->findvalue('TotalNumberOfVerifications') | ||
| 389 | || 0; | ||
| 390 | $decision->{num_verifications} = $cr_total; | ||
| 391 | |||
| 392 | if ( $kyc_dob or $cr_total ) { | ||
| 393 | $decision->{age_verified} = 1; | ||
| 394 | } | ||
| 395 | |||
| 396 | # check if client is in any suspicious list | ||
| 397 | # we don't care about: COAMatch | ||
| 398 | # | ||
| 399 | # Add NoOfCCJ separately since we don't fail that one. | ||
| 400 | |||
| 401 | $decision->{CCJ} = 1 if $credit_reference->findvalue('NoOfCCJ'); | ||
| 402 | |||
| 403 | my @matches = | ||
| 404 | map { $_->[0] } | ||
| 405 | grep { $_->[1] > 0 } | ||
| 406 | map { [ $_, $credit_reference->findvalue($_) || 0 ] } | ||
| 407 | qw(BOEMatch PEPMatch OFACMatch CIFASMatch); | ||
| 408 | |||
| 409 | if (@matches) { | ||
| 410 | my @hard_fails = grep { my $f = $_; | ||
| 411 | grep { "${f}Match" eq $_ } @matches } | ||
| 412 | qw(BOE PEP OFAC CIFAS); | ||
| 413 | $decision->{$_} = 1 for @hard_fails; | ||
| 414 | $decision->{deny} = 1 if @hard_fails; | ||
| 415 | |||
| 416 | $decision->{matches} = \@matches; | ||
| 417 | } | ||
| 418 | |||
| 419 | # if client is in Directors list, we should not fully authenticate him | ||
| 420 | if ( $report_summary{Directors} ) { | ||
| 421 | $decision->{director} = 1; | ||
| 422 | $decision->{matches} = [ @{$decision->{matches}}, 'Directors' ]; | ||
| 423 | } | ||
| 424 | |||
| 425 | # check if client can be fully authenticated | ||
| 426 | my @kyc_two = | ||
| 427 | grep { $_ >= 2 } | ||
| 428 | map { $kyc_summary->findvalue("$_/Count") || 0 } | ||
| 429 | qw(FullNameAndAddress SurnameAndAddress Address DateOfBirth); | ||
| 430 | if ( @kyc_two or $cr_total >= 2 ) { | ||
| 431 | $decision->{fully_authenticated} = 1; | ||
| 432 | } | ||
| 433 | |||
| 434 | return $decision; | ||
| 435 | } | ||
| 436 | |||
| 437 | sub _get_result_checkid { | ||
| 438 | |||
| 439 | my $self = shift; | ||
| 440 | my $passed = 0; | ||
| 441 | |||
| 442 | # Convert xml to hashref | ||
| 443 | my $result = $self->_xml_as_hash || do { | ||
| 444 | $self->logi('no xml result'); | ||
| 445 | return; | ||
| 446 | }; | ||
| 447 | |||
| 448 | if ( | ||
| 449 | ( | ||
| 450 | ( | ||
| 451 | $result->{'Result'}->{'ElectoralRoll'}->{'Type'} eq 'Result' | ||
| 452 | and $result->{'Result'}->{'ElectoralRoll'}->{'Summary'} | ||
| 453 | ->{'Decision'} == 1 | ||
| 454 | ) | ||
| 455 | or ( $result->{'Result'}->{'Directors'}->{'Type'} eq 'Result' | ||
| 456 | and | ||
| 457 | $result->{'Result'}->{'Directors'}->{'Summary'}->{'Decision'} == | ||
| 458 | 1 ) | ||
| 459 | or ( $result->{'Result'}->{'Telephony'}->{'Type'} eq 'Result' | ||
| 460 | and | ||
| 461 | $result->{'Result'}->{'Telephony'}->{'Summary'}->{'Decision'} == | ||
| 462 | 1 ) | ||
| 463 | ) | ||
| 464 | ) | ||
| 465 | { | ||
| 466 | |||
| 467 | # Check Directors DecisionReasons | ||
| 468 | if ( $result->{'Result'}->{'Directors'}->{'Type'} eq 'Result' ) { | ||
| 469 | DIRECTORS_DECISION_REASONS: | ||
| 470 | foreach my $decision_reason ( | ||
| 471 | @{ | ||
| 472 | $result->{'Result'}->{'Directors'}->{'Summary'} | ||
| 473 | ->{'DecisionReasons'}->{'DecisionReason'} | ||
| 474 | } | ||
| 475 | ) | ||
| 476 | { | ||
| 477 | if ( $decision_reason->{'Element'} eq | ||
| 478 | 'Director/Person/DateOfBirth' | ||
| 479 | and $decision_reason->{'Decision'} == 1 ) | ||
| 480 | { | ||
| 481 | $passed = 1; | ||
| 482 | last DIRECTORS_DECISION_REASONS; | ||
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | if ( not $passed ) { | ||
| 487 | ELECTORALROLL_DECISION_REASONS: | ||
| 488 | foreach my $decision_reason ( | ||
| 489 | @{ | ||
| 490 | $result->{'Result'}->{'ElectoralRoll'}->{'Summary'} | ||
| 491 | ->{'DecisionReasons'}->{'DecisionReason'} | ||
| 492 | } | ||
| 493 | ) | ||
| 494 | { | ||
| 495 | if ( $decision_reason->{'Element'} eq | ||
| 496 | 'ElectoralRollRecord/Person/DateOfBirth' | ||
| 497 | and $decision_reason->{'Decision'} == 1 ) | ||
| 498 | { | ||
| 499 | $passed = 1; | ||
| 500 | last ELECTORALROLL_DECISION_REASONS; | ||
| 501 | } | ||
| 502 | } | ||
| 503 | } | ||
| 504 | } | ||
| 505 | } | ||
| 506 | |||
| 507 | return $passed; | ||
| 508 | } | ||
| 509 | |||
| 510 | sub _do_192_authentication { | ||
| 511 | my $self = shift; | ||
| 512 | |||
| 513 | my $search_option = $self->{search_option}; | ||
| 514 | |||
| 515 | my $force_recheck = $self->{force_recheck} || 0; | ||
| 516 | |||
| 517 | $self->logi( "Attempt 192 authentication for " | ||
| 518 | . $self->{client_id} | ||
| 519 | . " via $search_option" ); | ||
| 520 | |||
| 521 | my $residence = $self->{residence}; | ||
| 522 | |||
| 523 | # check for 192 supported countries | ||
| 524 | unless ( $self->valid_country( $self->{residence} ) ) { | ||
| 525 | $self->logi( "Invalid residence: " | ||
| 526 | . $self->{client_id} | ||
| 527 | . ", Residence $residence" ); | ||
| 528 | return; | ||
| 529 | } | ||
| 530 | |||
| 531 | if ( !$force_recheck && $self->has_done_request ) { | ||
| 532 | $self->{result_as_xml} = $self->get_192_xml_report; | ||
| 533 | return 1; | ||
| 534 | } | ||
| 535 | |||
| 536 | # No previous result so prepare a request | ||
| 537 | $self->_build_request | ||
| 538 | || die( "Cannot build xml_request for [" | ||
| 539 | . $self->{client_id} | ||
| 540 | . "/$search_option]" ); | ||
| 541 | |||
| 542 | # Remove old pdf in case this client has done the 192 pdf request before | ||
| 543 | my $file_pdf = $self->_pdf_report_filename; | ||
| 544 | unlink $file_pdf if -e $file_pdf; | ||
| 545 | |||
| 546 | eval { $self->_send_request } || do { | ||
| 547 | my $err = $@ || '?'; | ||
| 548 | $self->logi("could not send pdf request: $err"); | ||
| 549 | return; | ||
| 550 | }; | ||
| 551 | |||
| 552 | # Save xml result | ||
| 553 | my $folder_xml = "$self->{folder}/xml"; | ||
| 554 | if ( not -d $folder_xml ) { | ||
| 555 | Path::Tiny::path($folder_xml)->mkpath; | ||
| 556 | } | ||
| 557 | my $file_xml = $self->_xml_report_filename; | ||
| 558 | Path::Tiny::path($file_xml)->spew( $self->{result_as_xml} ); | ||
| 559 | |||
| 560 | if ( not -e $file_xml ) { | ||
| 561 | $self->logi( | ||
| 562 | "Couldn't save 192.com xml result for " . $self->{client_id} ); | ||
| 563 | return; | ||
| 564 | } | ||
| 565 | |||
| 566 | $self->save_pdf_result; | ||
| 567 | |||
| 568 | return 1; | ||
| 569 | } | ||
| 570 | |||
| 571 | sub _xml_report_filename { | ||
| 572 | my $self = shift; | ||
| 573 | my $search_option = $self->{search_option}; | ||
| 574 | return "$self->{folder}/xml/" . $self->{client_id} . ".$search_option"; | ||
| 575 | } | ||
| 576 | |||
| 577 | sub _pdf_report_filename { | ||
| 578 | my $self = shift; | ||
| 579 | my $search_option = $self->{search_option}; | ||
| 580 | return "$self->{folder}/pdf/" . $self->{client_id} . ".$search_option.pdf"; | ||
| 581 | } | ||
| 582 | |||
| 583 | 1; | ||
| 584 | |||
| 585 | =head1 NAME | ||
| 586 | |||
| 587 | Experian::IDAuth - Experian's ID Authenticate service | ||
| 588 | |||
| 589 | =head1 VERSION | ||
| 590 | |||
| 591 | Version 2.1 | ||
| 592 | |||
| 593 | =head1 DESCRIPTION | ||
| 594 | |||
| 595 | This module provides an interface to Experian's Identity Authenticate service. | ||
| 596 | L<http://www.experian.co.uk/identity-and-fraud/products/authenticate.html> | ||
| 597 | |||
| 598 | First create a subclass of this module to override the defaults method | ||
| 599 | with your own data. | ||
| 600 | |||
| 601 | package My::Experian; | ||
| 602 | use strict; | ||
| 603 | use warnings; | ||
| 604 | use base 'Experian::IDAuth'; | ||
| 605 | |||
| 606 | # if you're using a logger | ||
| 607 | use Log::Log4perl; | ||
| 608 | |||
| 609 | sub defaults { | ||
| 610 | my $self = shift; | ||
| 611 | |||
| 612 | return ( | ||
| 613 | $self->SUPER::defaults, | ||
| 614 | logger => Log::Log4perl::get_logger, | ||
| 615 | username => 'my_user', | ||
| 616 | password => 'my_pass', | ||
| 617 | residence => $residence, | ||
| 618 | postcode => $postcode || '', | ||
| 619 | date_of_birth => $date_of_birth || '', | ||
| 620 | first_name => $first_name || '', | ||
| 621 | last_name => $last_name || '', | ||
| 622 | phone => $phone || '', | ||
| 623 | email => $email || '', | ||
| 624 | ); | ||
| 625 | } | ||
| 626 | |||
| 627 | 1; | ||
| 628 | |||
| 629 | Then use this module. | ||
| 630 | |||
| 631 | use My::Experian; | ||
| 632 | |||
| 633 | # search_option can either be ProveID_KYC or CheckID | ||
| 634 | my $prove_id = My::Experian->new( | ||
| 635 | search_option => 'ProveID_KYC', | ||
| 636 | ); | ||
| 637 | |||
| 638 | my $prove_id_result = $prove_id->get_result(); | ||
| 639 | |||
| 640 | if (!$prove_id->has_done_request) { | ||
| 641 | # connection problems | ||
| 642 | die; | ||
| 643 | } | ||
| 644 | |||
| 645 | if ($prove_id_result->{age_verified}) { | ||
| 646 | # client's age is verified | ||
| 647 | } | ||
| 648 | if ($prove_id_result->{deceased} || $prove_id_result->{fraud}) { | ||
| 649 | # client flagged as deceased or fraud | ||
| 650 | } | ||
| 651 | if ($prove_id_result->{deny}) { | ||
| 652 | # client on any of PEP, OFAC, or BOE list | ||
| 653 | # you can check $prove_id_result->{PEP} etc if you want more detail | ||
| 654 | } | ||
| 655 | if ($prove_id_result->{fully_authenticated}) { | ||
| 656 | # client successfully authenticated, | ||
| 657 | # DOES NOT MEAN NO CONCERNS | ||
| 658 | |||
| 659 | # check number of credit verifications done | ||
| 660 | print "Number of credit verifications: " . $prove_id_result->{num_verifications} . "\n"; | ||
| 661 | } | ||
| 662 | |||
| 663 | # CheckID is a more simpler version and can be used if ProveID_KYC fails | ||
| 664 | my $check_id = My::Experian->new( | ||
| 665 | search_option => 'CheckID', | ||
| 666 | ); | ||
| 667 | |||
| 668 | if (!$check_id->has_done_request) { | ||
| 669 | # connection problems | ||
| 670 | die; | ||
| 671 | } | ||
| 672 | |||
| 673 | if ($check_id->get_result()) { | ||
| 674 | # client successfully authenticated | ||
| 675 | } | ||
| 676 | |||
| 677 | =head1 METHODS | ||
| 678 | |||
| 679 | =head2 new() | ||
| 680 | |||
| 681 | Creates a new object of your derived class. The parent class should contain most of the attributes required for new(). But you can set search_option to either ProveID_KYC or CheckID | ||
| 682 | |||
| 683 | =head2 get_result() | ||
| 684 | |||
| 685 | Return the Experian results as a hashref | ||
| 686 | |||
| 687 | =head2 save_pdf_result() | ||
| 688 | |||
| 689 | Save the Experian credentials as a PDF | ||
| 690 | |||
| 691 | =head1 AUTHOR | ||
| 692 | |||
| 693 | binary.com, C<perl at binary.com> | ||
| 694 | |||
| 695 | =head1 BUGS | ||
| 696 | |||
| 697 | Please report any bugs or feature requests to C<bug-experian-idauth at rt.cpan.org>, | ||
| 698 | or through the web interface at | ||
| 699 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Experian-IDAuth>. | ||
| 700 | We will be notified, and then you'll automatically be notified of progress | ||
| 701 | on your bug as we make changes. | ||
| 702 | |||
| 703 | =head1 SUPPORT | ||
| 704 | |||
| 705 | You can find documentation for this module with the perldoc command. | ||
| 706 | |||
| 707 | perldoc Experian::IDAuth | ||
| 708 | |||
| 709 | |||
| 710 | You can also look for information at: | ||
| 711 | |||
| 712 | =over 4 | ||
| 713 | |||
| 714 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 715 | |||
| 716 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Experian-IDAuth> | ||
| 717 | |||
| 718 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 719 | |||
| 720 | L<http://annocpan.org/dist/Experian-IDAuth> | ||
| 721 | |||
| 722 | =item * CPAN Ratings | ||
| 723 | |||
| 724 | L<http://cpanratings.perl.org/d/Experian-IDAuth> | ||
| 725 | |||
| 726 | =item * Search CPAN | ||
| 727 | |||
| 728 | L<http://search.cpan.org/dist/Experian-IDAuth/> | ||
| 729 | |||
| 730 | =back | ||
| 731 | |||
| 732 | |||
| 733 | =head1 DEPENDENCIES | ||
| 734 | |||
| 735 | Locale::Country | ||
| 736 | Path::Tiny | ||
| 737 | WWW::Mechanize | ||
| 738 | XML::Simple | ||
| 739 | XML::Twig | ||
| 740 | SOAP::Lite | ||
| 741 | IO::Socket | ||
| 742 | |||
| 743 | =head1 LICENSE AND COPYRIGHT | ||
| 744 | |||
| 745 | Copyright 2014,2015 binary.com. | ||
| 746 | |||
| 747 | This program is free software; you can redistribute it and/or modify it | ||
| 748 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 749 | copy of the full license at: | ||
| 750 | |||
| 751 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 752 | |||
| 753 | Any use, modification, and distribution of the Standard or Modified | ||
| 754 | Versions is governed by this Artistic License. By using, modifying or | ||
| 755 | distributing the Package, you accept this license. Do not use, modify, | ||
| 756 | or distribute the Package, if you do not accept this license. | ||
| 757 | |||
| 758 | If your Modified Version has been derived from a Modified Version made | ||
| 759 | by someone other than you, you are nevertheless required to ensure that | ||
| 760 | your Modified Version complies with the requirements of this license. | ||
| 761 | |||
| 762 | This license does not grant you the right to use any trademark, service | ||
| 763 | mark, tradename, or logo of the Copyright Holder. | ||
| 764 | |||
| 765 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 766 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 767 | otherwise transfer the Package with respect to any patent claims | ||
| 768 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 769 | Package. If you institute patent litigation (including a cross-claim or | ||
| 770 | counterclaim) against any party alleging that the Package constitutes | ||
| 771 | direct or contributory patent infringement, then this Artistic License | ||
| 772 | to you shall terminate on the date that such litigation is filed. | ||
| 773 | |||
| 774 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 775 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 776 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 777 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 778 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 779 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 780 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 781 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 782 | |||
| 783 | |||
| 784 | =cut | ||
| 785 | |||
| 786 | 1; # End of Experian::IDAuth | ||
| 787 | |||