recurring indicator for Paymentech batches, #19571
[freeside.git] / FS / FS / payinfo_Mixin.pm
index d03391f..7b713ef 100644 (file)
@@ -3,6 +3,7 @@ package FS::payinfo_Mixin;
 use strict;
 use Business::CreditCard;
 use FS::payby;
+use FS::Record qw(qsearch);
 
 =head1 NAME
 
@@ -267,6 +268,30 @@ sub payby_payinfo_pretty {
   }
 }
 
+=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