use strict;
use Business::CreditCard;
use FS::payby;
+use FS::Record qw(qsearch);
=head1 NAME
my $payinfo = scalar(@_) ? shift : $self->payinfo;
# Check to see if it's encrypted...
- if ( $self->is_encrypted($payinfo) ) {
+ if ( ref($self) && $self->is_encrypted($payinfo) ) {
return 'N/A';
} elsif ( $payinfo =~ /^99\d{14}$/ || $payinfo eq 'N/A' ) { #token
return 'N/A (tokenized)'; #?
# Checks (Show last 2 @ bank)
my( $account, $aba ) = split('@', $payinfo );
return 'x'x(length($account)-2).
- substr($account,(length($account)-2))."@".$aba;
+ substr($account,(length($account)-2)).
+ ( length($aba) ? "@".$aba : '');
} else { # Tie up loose ends
return $payinfo;
}
}
+=item payinfo_used [ PAYINFO ]
+
+Returns 1 if there's an existing payment using this payinfo. This can be
+used to set the 'recurring payment' flag required by some processors.
+
+=cut
+
+sub payinfo_used {
+ my $self = shift;
+ my $payinfo = shift || $self->payinfo;
+ my %hash = (
+ 'custnum' => $self->custnum,
+ 'payby' => 'CARD',
+ );
+
+ return 1
+ if qsearch('cust_pay', { %hash, 'payinfo' => $payinfo } )
+ || qsearch('cust_pay',
+ { %hash, 'paymask' => $self->mask_payinfo('CARD', $payinfo) } )
+ ;
+
+ return 0;
+}
+
=back
=head1 BUGS