[freeside-commits] freeside/FS/FS banned_pay.pm, 1.3, 1.4 Schema.pm, 1.314, 1.315 cust_main.pm, 1.584, 1.585 Conf.pm, 1.466, 1.467

Ivan,,, ivan at wavetail.420.am
Fri Jul 15 14:10:07 PDT 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv5168/FS/FS

Modified Files:
	banned_pay.pm Schema.pm cust_main.pm Conf.pm 
Log Message:
add signup-duplicate_cc-warn_hours to warn about duplicate signups in a time span, RT#12011

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.314
retrieving revision 1.315
diff -u -w -d -r1.314 -r1.315
--- Schema.pm	12 Jul 2011 22:57:03 -0000	1.314
+++ Schema.pm	15 Jul 2011 21:10:04 -0000	1.315
@@ -2754,13 +2754,15 @@
         'payinfo', 'varchar',  '',     128, '', '', #say, a 512-big digest _hex encoded
 	#'paymask', 'varchar',  'NULL', $char_d, '', ''
         '_date',   @date_type, '', '', 
+        'end_date',         @date_type,         '', '', 
         'otaker',  'varchar',  'NULL',     32, '', '', 
         'usernum',   'int', 'NULL', '', '', '',
+        'bantype', 'varchar',  'NULL', $char_d, '', '',
         'reason',  'varchar',  'NULL', $char_d, '', '', 
       ],
       'primary_key' => 'bannum',
-      'unique'      => [ [ 'payby', 'payinfo' ] ],
-      'index'       => [ [ 'usernum' ] ],
+      'unique'      => [],
+      'index '      => [ [ 'payby', 'payinfo' ], [ 'usernum' ], ],
     },
 
     'pkg_category' => {

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.466
retrieving revision 1.467
diff -u -w -d -r1.466 -r1.467
--- Conf.pm	14 Jul 2011 22:21:58 -0000	1.466
+++ Conf.pm	15 Jul 2011 21:10:05 -0000	1.467
@@ -3946,11 +3946,18 @@
   {
     'key'         => 'signup-recommend_daytime',
     'section'     => 'self-service',
-    'description' => 'Encourage the entry of a daytime phone number  invoicing email address on signup.',
+    'description' => 'Encourage the entry of a daytime phone number on signup.',
     'type'        => 'checkbox',
   },
 
   {
+    'key'         => 'signup-duplicate_cc-warn_hours',
+    'section'     => 'self-service',
+    'description' => 'Issue a warning if the same credit card is used for multiple signups within this many hours.',
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'svc_phone-radius-default_password',
     'section'     => 'telephony',
     'description' => 'Default password when exporting svc_phone records to RADIUS',

Index: banned_pay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/banned_pay.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- banned_pay.pm	24 Aug 2010 02:27:46 -0000	1.3
+++ banned_pay.pm	15 Jul 2011 21:10:04 -0000	1.4
@@ -2,6 +2,7 @@
 
 use strict;
 use base qw( FS::otaker_Mixin FS::Record );
+use Digest::MD5 qw(md5_base64);
 use FS::Record qw( qsearch qsearchs );
 use FS::UID qw( getotaker );
 use FS::CurrentUser;
@@ -42,8 +43,12 @@
 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> for conversion functions.
 
+=item end_date - optional end date, also specified as a UNIX timestamp.
+
 =item usernum - order taker (assigned automatically, see L<FS::access_user>)
 
+=item bantype - Ban type: "" or null (regular ban), "warn" (warning)
+
 =item reason - reason (text)
 
 =back
@@ -110,6 +115,8 @@
     || $self->ut_enum('payby', [ 'CARD', 'CHEK' ] )
     || $self->ut_text('payinfo')
     || $self->ut_numbern('_date')
+    || $self->ut_numbern('end_date')
+    || $self->ut_enum('bantype', [ '', 'warn' ] )
     || $self->ut_textn('reason')
   ;
   return $error if $error;
@@ -121,6 +128,31 @@
   $self->SUPER::check;
 }
 
+=back
+
+=head1 CLASS METHODS
+
+=item ban_search OPTION => VALUE ...
+
+Takes two parameters: payby and payinfo, and searches for an (un-expired) ban
+matching those items.
+
+Returns the ban, or false if no ban was found.
+
+=cut
+
+sub ban_search {
+  my( $class, %opt ) = @_;
+  qsearchs({
+    'table'     => 'banned_pay',
+    'hashref'   => {
+                     'payby'   => $opt{payby},
+                     'payinfo' => md5_base64($opt{payinfo}),
+                   },
+    'extra_sql' => 'AND end_date IS NULL OR end_date >= '. time,
+  });
+}
+
 # Used by FS::Upgrade to migrate to a new database.
 sub _upgrade_data {  # class method
   my ($class, %opts) = @_;

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.584
retrieving revision 1.585
diff -u -w -d -r1.584 -r1.585
--- cust_main.pm	12 Jul 2011 07:54:21 -0000	1.584
+++ cust_main.pm	15 Jul 2011 21:10:05 -0000	1.585
@@ -776,7 +776,7 @@
 
     $prepay_credit = qsearchs(
       'prepay_credit',
-      { 'identifier' => $prepay_credit },
+      { 'identifier' => $identifier },
       '',
       'FOR UPDATE'
     );
@@ -1865,14 +1865,19 @@
       && cardtype($self->payinfo) eq "Unknown";
 
     unless ( $ignore_banned_card ) {
-      my $ban = qsearchs('banned_pay', $self->_banned_pay_hashref);
+      my $ban = FS::banned_pay->ban_search( %{ $self->_banned_pay_hashref } );
       if ( $ban ) {
+        if ( $ban->bantype eq 'warn' ) {
+          #or others depending on value of $ban->reason ?
+          return '_duplicate_card' unless $self->override_ban_warn;
+        } else {
         return 'Banned credit card: banned on '.
                time2str('%a %h %o at %r', $ban->_date).
                ' by '. $ban->otaker.
                ' (ban# '. $ban->bannum. ')';
       }
     }
+    }
 
     if (length($self->paycvv) && !$self->is_encrypted($self->paycvv)) {
       if ( cardtype($self->payinfo) eq 'American Express card' ) {
@@ -1931,14 +1936,19 @@
     $self->paycvv('');
 
     unless ( $ignore_banned_card ) {
-      my $ban = qsearchs('banned_pay', $self->_banned_pay_hashref);
+      my $ban = FS::banned_pay->ban_search( %{ $self->_banned_pay_hashref } );
       if ( $ban ) {
+        if ( $ban->bantype eq 'warn' ) {
+          #or others depending on value of $ban->reason ?
+          return '_duplicate_ach' unless $self->override_ban_warn;
+        } else {
         return 'Banned ACH account: banned on '.
                time2str('%a %h %o at %r', $ban->_date).
                ' by '. $ban->otaker.
                ' (ban# '. $ban->bannum. ')';
       }
     }
+    }
 
   } elsif ( $self->payby eq 'LECB' ) {
 
@@ -2216,7 +2226,7 @@
     return ( "Can't (yet) ban encrypted credit cards" )
       if $self->is_encrypted($self->payinfo);
 
-    my $ban = new FS::banned_pay $self->_banned_pay_hashref;
+    my $ban = new FS::banned_pay $self->_new_banned_pay_hashref;
     my $error = $ban->insert;
     return ( $error ) if $error;
 
@@ -2250,11 +2260,18 @@
 
   {
     'payby'   => $payby2ban{$self->payby},
-    'payinfo' => md5_base64($self->payinfo),
+    'payinfo' => $self->payinfo,
     #don't ever *search* on reason! #'reason'  =>
   };
 }
 
+sub _new_banned_pay_hashref {
+  my $self = shift;
+  my $hr = $self->_banned_pay_hashref;
+  $hr->{payinfo} = md5_base64($hr->{payinfo});
+  $hr;
+}
+
 =item notes
 
 Returns all notes (see L<FS::cust_main_note>) for this customer.



More information about the freeside-commits mailing list