add methods for masking credit cards, add payment info modification to self-service
authorivan <ivan>
Tue, 20 Apr 2004 00:58:04 +0000 (00:58 +0000)
committerivan <ivan>
Tue, 20 Apr 2004 00:58:04 +0000 (00:58 +0000)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/cust_main.pm
FS/FS/cust_pay.pm
FS/FS/cust_refund.pm
fs_selfservice/FS-SelfService/SelfService.pm
httemplate/view/cust_main.cgi

index 44d81c9..16fb8bf 100644 (file)
@@ -38,6 +38,7 @@ use vars qw( @cust_main_editable_fields );
     county state zip country daytime night fax
   ship_first ship_last ship_company ship_address1 ship_address2 ship_city
     ship_state ship_zip ship_country ship_daytime ship_night ship_fax
     county state zip country daytime night fax
   ship_first ship_last ship_company ship_address1 ship_address2 ship_city
     ship_state ship_zip ship_country ship_daytime ship_night ship_fax
+  payby payinfo payname
 );
 
 #store in db?
 );
 
 #store in db?
@@ -116,6 +117,16 @@ sub customer_info {
       $return{$_} = $cust_main->get($_);
     }
 
       $return{$_} = $cust_main->get($_);
     }
 
+    if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
+      $return{payinfo} = $cust_main->masked_payinfo;
+      @return{'month', 'year'} = $cust_main->paydate_monthyear;
+    }
+
+    $return{'invoicing_list'} =
+      join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list );
+    $return{'postal_invoicing'} =
+      0 < ( grep { $_ eq 'POST' } $cust_main->invoicing_list );
+
   } else { #no customer record
 
     my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $session->{'svcnum'} } )
   } else { #no customer record
 
     my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $session->{'svcnum'} } )
@@ -145,7 +156,26 @@ sub edit_info {
   my $new = new FS::cust_main { $cust_main->hash };
   $new->set( $_ => $p->{$_} )
     foreach grep { exists $p->{$_} } @cust_main_editable_fields;
   my $new = new FS::cust_main { $cust_main->hash };
   $new->set( $_ => $p->{$_} )
     foreach grep { exists $p->{$_} } @cust_main_editable_fields;
-  my $error = $new->replace($cust_main);
+
+  if ( $p->{'payby'} =~ /^(CARD|DCRD)$/ ) {
+    $new->paydate($p->{'year'}. '-'. $p->{'month'}. '-01');
+    if ( $new->payinfo eq $cust_main->payinfo_masked ) {
+      $new->payinfo($cust_main->payinfo);
+    } else {
+      $new->paycvv($p->{'paycvv'});
+    }
+  }
+
+  my @invoicing_list;
+  if ( exists $p->{'invoicing_list'} || exists $p->{'postal_invoicing'} ) {
+    #false laziness with httemplate/edit/process/cust_main.cgi
+    @invoicing_list = split( /\s*\,\s*/, $p->{'invoicing_list'} );
+    push @invoicing_list, 'POST' if $p->{'postal_invoicing'};
+  } else {
+    @invoicing_list = $cust_main->invoicing_list;
+  }
+
+  my $error = $new->replace($cust_main, \@invoicing_list);
   return { 'error' => $error } if $error;
   #$cust_main = $new;
   
   return { 'error' => $error } if $error;
   #$cust_main = $new;
   
@@ -174,7 +204,7 @@ sub payment_info {
   $return{payby} = $cust_main->payby;
 
   if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
   $return{payby} = $cust_main->payby;
 
   if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
-    warn $return{card_type} = cardtype($cust_main->payinfo);
+    #warn $return{card_type} = cardtype($cust_main->payinfo);
     $return{payinfo} = $cust_main->payinfo;
 
     @return{'month', 'year'} = $cust_main->paydate_monthyear;
     $return{payinfo} = $cust_main->payinfo;
 
     @return{'month', 'year'} = $cust_main->paydate_monthyear;
index 74015de..ad5b0df 100644 (file)
@@ -2151,6 +2151,19 @@ sub paydate_monthyear {
   }
 }
 
   }
 }
 
+=item payinfo_masked
+
+Returns a "masked" payinfo field with all but the last four characters replaced
+by 'x'es.  Useful for displaying credit cards.
+
+=cut
+
+sub payinfo_masked {
+  my $self = shift;
+  my $payinfo = $self->payinfo;
+  'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
+}
+
 =item invoicing_list [ ARRAYREF ]
 
 If an arguement is given, sets these email addresses as invoice recipients
 =item invoicing_list [ ARRAYREF ]
 
 If an arguement is given, sets these email addresses as invoice recipients
@@ -2844,6 +2857,8 @@ card types.
 
 No multiple currency support (probably a larger project than just this module).
 
 
 No multiple currency support (probably a larger project than just this module).
 
+payinfo_masked false laziness with cust_pay.pm and cust_refund.pm
+
 =head1 SEE ALSO
 
 L<FS::Record>, L<FS::cust_pkg>, L<FS::cust_bill>, L<FS::cust_credit>
 =head1 SEE ALSO
 
 L<FS::Record>, L<FS::cust_pkg>, L<FS::cust_bill>, L<FS::cust_credit>
index e1943ae..ba9924f 100644 (file)
@@ -396,16 +396,25 @@ sub cust_main {
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
+=item payinfo_masked
 
 
-=back
+Returns a "masked" payinfo field with all but the last four characters replaced
+by 'x'es.  Useful for displaying credit cards.
+
+=cut
 
 
-=head1 VERSION
+sub payinfo_masked {
+  my $self = shift;
+  my $payinfo = $self->payinfo;
+  'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
+}
 
 
-$Id: cust_pay.pm,v 1.26 2003-09-10 10:54:46 ivan Exp $
+=back
 
 =head1 BUGS
 
 
 =head1 BUGS
 
-Delete and replace methods.
+Delete and replace methods.  payinfo_masked false laziness with cust_main.pm
+and cust_refund.pm
 
 =head1 SEE ALSO
 
 
 =head1 SEE ALSO
 
index 250bd20..d60c010 100644 (file)
@@ -263,15 +263,27 @@ sub check {
   $self->SUPER::check;
 }
 
   $self->SUPER::check;
 }
 
-=back
+=item payinfo_masked
+
+Returns a "masked" payinfo field with all but the last four characters replaced
+by 'x'es.  Useful for displaying credit cards.
 
 
-=head1 VERSION
+=cut
 
 
-$Id: cust_refund.pm,v 1.21 2003-08-05 00:20:42 khoff Exp $
+
+sub payinfo_masked {
+  my $self = shift;
+  my $payinfo = $self->payinfo;
+  'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
+}
+
+
+=back
 
 =head1 BUGS
 
 
 =head1 BUGS
 
-Delete and replace methods.
+Delete and replace methods.  payinfo_masked false laziness with cust_main.pm
+and cust_pay.pm
 
 =head1 SEE ALSO
 
 
 =head1 SEE ALSO
 
index 7cbf5ec..920415e 100644 (file)
@@ -246,7 +246,7 @@ the following keys: invnum, date, owed
 
 An HTML fragment containing shipping and billing addresses.
 
 
 An HTML fragment containing shipping and billing addresses.
 
-=item The following fields are also returned: first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax
+=item The following fields are also returned: first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax payby payinfo payname month year invoicing_list postal_invoicing
 
 =back
 
 
 =back
 
@@ -254,7 +254,7 @@ An HTML fragment containing shipping and billing addresses.
 
 Takes a hash reference as parameter with any of the following keys:
 
 
 Takes a hash reference as parameter with any of the following keys:
 
-first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax
+first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax payby payinfo paycvv payname month year invoicing_list postal_invoicing
 
 If a field exists, the customer record is updated with the new value of that
 field.  If a field does not exist, that field is not changed on the customer
 
 If a field exists, the customer record is updated with the new value of that
 field.  If a field does not exist, that field is not changed on the customer
index 624fe37..cf899d0 100755 (executable)
@@ -235,8 +235,7 @@ if ( $conf->config('payby-default') ne 'HIDE' ) {
   ;
 
   if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
   ;
 
   if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
-    my $payinfo = $cust_main->payinfo;
-    $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
+    my $payinfo = $cust_main->payinfo_masked;
     print 'Credit&nbsp;card&nbsp;',
           ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ),
           '</TD></TR>',
     print 'Credit&nbsp;card&nbsp;',
           ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ),
           '</TD></TR>',
@@ -601,11 +600,11 @@ function cust_credit_areyousure(href) {
   foreach my $cust_pay ($cust_main->cust_pay) {
 
     my $payby = $cust_pay->payby;
   foreach my $cust_pay ($cust_main->cust_pay) {
 
     my $payby = $cust_pay->payby;
-    my $payinfo = $cust_pay->payinfo;
+    my $payinfo = $payby eq 'CARD'
+                    ? $cust_pay->payinfo_masked
+                    : $cust_pay->payinfo;
     my @cust_bill_pay = $cust_pay->cust_bill_pay;
 
     my @cust_bill_pay = $cust_pay->cust_bill_pay;
 
-    $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
-      if $payby eq 'CARD';
     my $target = "$payby$payinfo";
     $payby =~ s/^BILL$/Check #/ if $payinfo;
     $payby =~ s/^BILL$//;
     my $target = "$payby$payinfo";
     $payby =~ s/^BILL$/Check #/ if $payinfo;
     $payby =~ s/^BILL$//;
@@ -751,10 +750,10 @@ function cust_credit_areyousure(href) {
   foreach my $cust_refund ($cust_main->cust_refund) {
 
     my $payby = $cust_refund->payby;
   foreach my $cust_refund ($cust_main->cust_refund) {
 
     my $payby = $cust_refund->payby;
-    my $payinfo = $cust_refund->payinfo;
+    my $payinfo = $payby eq 'CARD'
+                    ? $cust_refund->payinfo_masked
+                    : $cust_refund->payinfo;
 
 
-    $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
-      if $payby eq 'CARD';
     $payby =~ s/^BILL$/Check #/ if $payinfo;
     $payby =~ s/^(CARD|COMP)$/$1 /;
 
     $payby =~ s/^BILL$/Check #/ if $payinfo;
     $payby =~ s/^(CARD|COMP)$/$1 /;