From: ivan Date: Tue, 20 Apr 2004 00:58:04 +0000 (+0000) Subject: add methods for masking credit cards, add payment info modification to self-service X-Git-Tag: BEFORE_FINAL_MASONIZE~1142 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=d01dbb663c0d58ed4294c9284106a0e46f274301 add methods for masking credit cards, add payment info modification to self-service --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 44d81c999..16fb8bf7a 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -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 + payby payinfo payname ); #store in db? @@ -116,6 +117,16 @@ sub customer_info { $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'} } ) @@ -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 $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; @@ -174,7 +204,7 @@ sub payment_info { $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; diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 74015de34..ad5b0df1f 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -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 @@ -2844,6 +2857,8 @@ card types. 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, L, L, L diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index e1943ae2d..ba9924f99 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -396,16 +396,25 @@ sub cust_main { 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 -Delete and replace methods. +Delete and replace methods. payinfo_masked false laziness with cust_main.pm +and cust_refund.pm =head1 SEE ALSO diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 250bd20e0..d60c01061 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -263,15 +263,27 @@ sub 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 -Delete and replace methods. +Delete and replace methods. payinfo_masked false laziness with cust_main.pm +and cust_pay.pm =head1 SEE ALSO diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 7cbf5ecad..920415e30 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -246,7 +246,7 @@ the following keys: invnum, date, owed 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 @@ -254,7 +254,7 @@ An HTML fragment containing shipping and billing addresses. 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 diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi index 624fe37d1..cf899d041 100755 --- a/httemplate/view/cust_main.cgi +++ b/httemplate/view/cust_main.cgi @@ -235,8 +235,7 @@ if ( $conf->config('payby-default') ne 'HIDE' ) { ; 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 card ', ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ), '', @@ -601,11 +600,11 @@ function cust_credit_areyousure(href) { 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; - $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$//; @@ -751,10 +750,10 @@ function cust_credit_areyousure(href) { 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 /;