verify credit card changes via $1 auth, RT#37632
[freeside.git] / FS / FS / cust_payby.pm
index a686242..ec4eb7a 100644 (file)
@@ -19,6 +19,7 @@ sub nohistory_fields { ('payinfo', 'paycvv'); }
 our $ignore_expired_card = 0;
 our $ignore_banned_card = 0;
 our $ignore_invalid_card = 0;
+our $ignore_cardtype = 0;
 
 our $conf;
 install_callback FS::UID sub { 
@@ -236,6 +237,11 @@ sub replace {
   {
     my $error = $self->check_payinfo_cardtype;
     return $error if $error;
+
+    if ( $conf->exists('business-onlinepayment-verification') ) {
+      $error = $self->verify;
+      return $error if $error;
+    }
   }
 
   local $SIG{HUP} = 'IGNORE';
@@ -488,7 +494,11 @@ sub check {
 
   }
 
-  ###
+  if ( ! $self->custpaybynum
+       && $conf->exists('business-onlinepayment-verification') ) {
+    $error = $self->verify;
+    return $error if $error;
+  }
 
   $self->SUPER::check;
 }
@@ -496,6 +506,8 @@ sub check {
 sub check_payinfo_cardtype {
   my $self = shift;
 
+  return '' if $ignore_cardtype;
+
   return '' unless $self->payby =~ /^(CARD|CHEK)$/;
 
   my $payinfo = $self->payinfo;
@@ -614,6 +626,30 @@ sub realtime_bop {
 
 }
 
+=item verify 
+
+=cut
+
+sub verify {
+  my $self = shift;
+  return '' unless $self->payby =~ /^(CARD|DCRD)$/;
+
+  my %opt = ();
+
+  $opt{$_} = $self->$_() for qw( payinfo payname paydate );
+
+  if ( $self->locationnum ) {
+    my $cust_location = $self->cust_location;
+    $opt{$_} = $cust_location->$_() for qw( address1 address2 city state zip );
+  }
+
+  $self->cust_main->realtime_verify_bop({
+    'method' => FS::payby->payby2bop( $self->payby ),
+    %opt,
+  });
+
+}
+
 =item paytypes
 
 Returns a list of valid values for the paytype field (bank account type for