working self-service self-payments!
[freeside.git] / FS / FS / cust_main.pm
index b162622..7e2ff38 100644 (file)
@@ -33,7 +33,7 @@ use FS::Msgcat qw(gettext);
 
 @ISA = qw( FS::Record );
 
-$Debug = 0;
+$Debug = 1;
 #$Debug = 1;
 
 $import = 0;
@@ -761,10 +761,15 @@ sub check {
       unless $self->payby =~ /^(BILL|PREPAY|CHEK|LECB)$/;
     $self->paydate('');
   } else {
-    $self->paydate =~ /^(\d{1,2})[\/\-](\d{2}(\d{2})?)$/
-      or return "Illegal expiration date: ". $self->paydate;
-    my $y = length($2) == 4 ? $2 : "20$2";
-    $self->paydate("$y-$1-01");
+    my( $m, $y );
+    if ( $self->paydate =~ /^(\d{1,2})[\/\-](\d{2}(\d{2})?)$/ ) {
+      ( $m, $y ) = ( $1, length($2) == 4 ? $2 : "20$2" );
+    } elsif ( $self->paydate =~ /^(20)?(\d{2})[\/\-](\d{2})[\/\-]\d+$/ ) {
+      ( $m, $y ) = ( $3, "20$2" );
+    } else {
+      return "Illegal expiration date: ". $self->paydate;
+    }
+    $self->paydate("$y-$m-01");
     my($nowm,$nowy)=(localtime(time))[4,5]; $nowm++; $nowy+=1900;
     return gettext('expired_card')
       if !$import && ( $y<$nowy || ( $y==$nowy && $1<$nowm ) );
@@ -1411,7 +1416,6 @@ sub collect {
 
 =item realtime_bop METHOD AMOUNT [ OPTION => VALUE ... ]
 
-
 Runs a realtime credit card, ACH (electronic check) or phone bill transaction
 via a Business::OnlinePayment realtime gateway.  See
 L<http://420.am/business-onlinepayment> for supported gateways.
@@ -1420,6 +1424,10 @@ Available methods are: I<CC>, I<ECHECK> and I<LEC>
 
 Available options are: I<description>, I<invnum>, I<quiet>
 
+The additional options I<payname>, I<address1>, I<address2>, I<city>, I<state>,
+I<zip>, I<payinfo> and I<paydate> are also available.  Any of these options,
+if set, will override the value from the customer record.
+
 I<description> is a free-text field passed to the gateway.  It defaults to
 "Internet services".
 
@@ -1435,6 +1443,11 @@ I<quiet> can be set true to surpress email decline notices.
 
 sub realtime_bop {
   my( $self, $method, $amount, %options ) = @_;
+  if ( $Debug ) {
+    warn "$self $method $amount\n";
+    warn "  $_ => $options{$_}\n" foreach keys %options;
+  }
+
   $options{'description'} ||= 'Internet services';
 
   #pre-requisites
@@ -1443,6 +1456,11 @@ sub realtime_bop {
   eval "use Business::OnlinePayment";  
   die $@ if $@;
 
+  #overrides
+  $self->set( $_ => $options{$_} )
+    foreach grep { exists($options{$_}) }
+            qw( payname address1 address2 city state zip payinfo paydate );
+
   #load up config
   my $bop_config = 'business-onlinepayment';
   $bop_config .= '-ach'
@@ -1571,7 +1589,8 @@ sub realtime_bop {
     );
 
     my $cust_pay = new FS::cust_pay ( {
-       'invnum'   => $self->invnum, #!!!!!!!!
+       'custnum'  => $self->custnum,
+       'invnum'   => $options{'invnum'},
        'paid'     => $amount,
        '_date'     => '',
        'payby'    => $method2payby{$method},