FS::upgrade_journal->set_done('clear_payinfo_history');
}
- # encrypt old records
- if ( $conf->exists('encryption')
- && ! FS::upgrade_journal->is_done('encryption_check')
- ) {
+ # fix Tokenized paycardtype and encrypt old records
+ if ( ! FS::upgrade_journal->is_done('paycardtype_Tokenized')
+ || ! FS::upgrade_journal->is_done('encryption_check')
+ )
+ {
# allow replacement of closed cust_pay/cust_refund records
local $FS::payinfo_Mixin::allow_closed_replace = 1;
if (!$record->custnum && $table eq 'cust_pay_pending') {
$record->set('custnum_pending',1);
}
+ $record->paycardtype('') if $record->paycardtype eq 'Tokenized';
local($ignore_expired_card) = 1;
local($ignore_banned_card) = 1;
}
}
- FS::upgrade_journal->set_done('encryption_check');
+ FS::upgrade_journal->set_done('paycardtype_Tokenized');
+ FS::upgrade_journal->set_done('encryption_check') if $conf->exists('encryption');
}
# now that everything's encrypted, tokenize...
my $sql = 'SELECT '.$tclass->primary_key.
' FROM '.$table.
' WHERE '.$tclass->primary_key.' > '.$$lastrecnum.
- ' ORDER BY '.$tclass->primary_key.' LIMIT 500';;
+ " AND payby IN ( 'CARD', 'DCRD', 'CHEK', 'DCHK' ) ".
+ " AND ( length(payinfo) < 80 OR paycardtype = 'Tokenized' ) ".
+ ' ORDER BY '.$tclass->primary_key.' LIMIT 500';
my $sth = $dbh->prepare($sql) or die $dbh->errstr;
$sth->execute() or die $sth->errstr;
my @recnums;
sub condition_sql {
my( $class, $table, %opt ) = @_;
- # XXX: can be made faster with optimizations?
- # -remove some/all sub-selects?
- # -remove the two main separate selects?
-
- "0 = (select count(1) from cust_pkg
- where cust_pkg.no_auto = 'Y' and cust_pkg.pkgnum in
- (select distinct cust_bill_pkg.pkgnum
- from cust_bill_pkg, cust_pkg
- where cust_bill_pkg.pkgnum = cust_pkg.pkgnum
- and cust_bill_pkg.invnum = cust_bill.invnum
- and cust_bill_pkg.pkgnum > 0
- )
- )
- AND
- 0 = (select count(1) from part_pkg
- where part_pkg.no_auto = 'Y' and part_pkg.pkgpart in
- (select cust_pkg.pkgpart from cust_pkg
- where pkgnum in
- (select distinct cust_bill_pkg.pkgnum
- from cust_bill_pkg, cust_pkg
- where cust_bill_pkg.pkgnum = cust_pkg.pkgnum
- and cust_bill_pkg.invnum = cust_bill.invnum
- and cust_bill_pkg.pkgnum > 0
- )
- )
- )
+ # can be made still faster with optimizations?
+
+ "NOT EXISTS ( SELECT 1 FROM cust_pkg
+ LEFT JOIN part_pkg USING (pkgpart)
+ WHERE ( cust_pkg.no_auto = 'Y' OR part_pkg.no_auto = 'Y' )
+ AND cust_pkg.pkgnum IN
+ ( SELECT DISTINCT cust_bill_pkg.pkgnum
+ FROM cust_bill_pkg
+ WHERE cust_bill_pkg.invnum = cust_bill.invnum
+ AND cust_bill_pkg.pkgnum > 0
+ )
+ )
";
}
if ( $self->payby eq 'CARD' && ! $self->is_encrypted($self->payinfo) ) {
- if ( $self->tokenized && ! $self->paycardtype ) {
- return "paycardtype required (cannot be derived from a token)";
- } else {
- $self->set('paycardtype', cardtype($self->payinfo));
+ unless ( $self->paycardtype ) {
+
+ if ( $self->tokenized ) {
+ if ( $self->paymask =~ /^\d+x/ ) {
+ $self->set('paycardtype', cardtype($self->paymask));
+ } else {
+ $self->set('paycardtype', '');
+ # return "paycardtype required ".
+ # "(can't derive from a token and no paymask w/prefix provided)";
+ }
+ } else {
+ $self->set('paycardtype', cardtype($self->payinfo));
+ }
+
}
if ( $ignore_masked_payinfo and $self->mask_payinfo eq $self->payinfo ) {
$self->payinfo('N/A'); #??? re-masks card
}
}
+
} else {
- if ( $self->payby eq 'CARD' and $self->paymask ) {
- # if we can't decrypt the card, at least detect the cardtype
- $self->set('paycardtype', cardtype($self->paymask));
- } else {
- $self->set('paycardtype', '');
+
+ unless ( $self->paycardtype ) {
+
+ if ( $self->payby eq 'CARD' && $self->paymask =~ /^\d+x/ ) {
+ # if we can't decrypt the card, at least detect the cardtype
+ $self->set('paycardtype', cardtype($self->paymask));
+ } else {
+ $self->set('paycardtype', '');
+ # return "paycardtype required ".
+ # "(can't derive from a token and no paymask w/prefix provided)";
+ }
+
}
+
if ( $self->is_encrypted($self->payinfo) ) {
#something better? all it would cause is a decryption error anyway?
my $error = $self->ut_anything('payinfo');