From 5b9bce86c42fd4e0c3a6d89e21e6b3eeb59f7f3a Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 1 Feb 2017 14:35:38 -0600 Subject: [PATCH] 71513: Card tokenization [refactor only tokenize cards; job critical error handling] --- FS/FS/cust_main/Billing_Realtime.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index f089059aa..c2cb2e386 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -2373,7 +2373,7 @@ is set, this will instead cause a critical error to be recorded in the log, and any other tokenizable records will still be committed. If the I flag is also set, detection of existing untokenized records will -record a critical error in the system log (because they should have never appeared +record an info message in the system log (because they should have never appeared in the first place.) Tokenization will still be attempted. If any configured gateways do NOT have the ability to tokenize, or if a @@ -2386,6 +2386,7 @@ sub token_check { #acts on all customers my %opt = @_; my $debug = !$opt{'quiet'} || $DEBUG; + my $hascritical = 0; warn "token_check called with opts\n".Dumper(\%opt) if $debug; @@ -2482,6 +2483,7 @@ CUSTLOOP: } my $error = "No gateway found for custnum ".$cust_main->custnum; if ($opt{'queue'}) { + $hascritical = 1; $log->critical($error); $dbh->commit or die $dbh->errstr; # commit error message next; # not next CUSTLOOP, want to record error for every cust_payby @@ -2518,6 +2520,7 @@ CUSTLOOP: if ($error) { $error = "Error tokenizing cust_payby ".$cust_payby->custpaybynum.": ".$error; if ($opt{'queue'}) { + $hascritical = 1; $log->critical($error); $dbh->commit or die $dbh->errstr; # commit log message, release mutex next; # not next CUSTLOOP, want to record error for every cust_payby @@ -2550,6 +2553,10 @@ CUSTLOOP: while (my $recnum = _token_check_next_recnum($dbh,$table,$step,\$offset,\@recnums)) { my $record = $tclass->by_key($recnum); + unless ($record->payby eq 'CARD') { + warn "Skipping non-card record for $table ".$record->get($record->primary_key) if $debug; + next; + } if (FS::cust_main::Billing_Realtime->tokenized($record->payinfo)) { warn "Skipping tokenized record for $table ".$record->get($record->primary_key) if $debug; next; @@ -2580,6 +2587,7 @@ CUSTLOOP: } else { my $error = "Could not load cust_main for $table ".$record->get($record->primary_key); if ($opt{'queue'}) { + $hascritical = 1; $log->critical($error); $dbh->commit or die $dbh->errstr; # commit log message next; @@ -2682,6 +2690,7 @@ CUSTLOOP: if ($error) { $error = "Error tokenizing $table ".$record->get($record->primary_key).": ".$error; if ($opt{'queue'}) { + $hascritical = 1; $log->critical($error); $dbh->commit or die $dbh->errstr; # commit log message, release mutex next; @@ -2697,7 +2706,7 @@ CUSTLOOP: $dbh->commit or die $dbh->errstr if $oldAutoCommit; - return ''; + return $hascritical ? 'Critical errors occurred on some records, see system log' : ''; } # not a method! @@ -2709,8 +2718,6 @@ sub _token_check_next_recnum { my $sth = $dbh->prepare( 'SELECT '.$tclass->primary_key. ' FROM '.$table. - " WHERE payby IN ( 'CARD', 'DCRD' ) ". - " AND ( length(payinfo) > 80 OR payinfo NOT LIKE '99%' )". ' ORDER BY '.$tclass->primary_key. ' LIMIT '.$step. ' OFFSET '.$$offset -- 2.11.0