From 74cf17d7e822d75cbf51098c7e337ba4174b18aa Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Tue, 19 Jan 2016 15:07:15 -0600 Subject: [PATCH] RT#38363: use cust_payby when saving cards during payments [editing from cust_main] --- FS/FS/cust_payby.pm | 15 ++++++++++- FS/FS/o2m_Common.pm | 2 +- httemplate/edit/cust_main.cgi | 6 +---- httemplate/edit/cust_main/billing.html | 1 - httemplate/elements/cust_payby.html | 48 ++++++++++++++++++---------------- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/FS/FS/cust_payby.pm b/FS/FS/cust_payby.pm index b9e79a2be..83b951eda 100644 --- a/FS/FS/cust_payby.pm +++ b/FS/FS/cust_payby.pm @@ -577,15 +577,20 @@ sub cgi_cust_payby_fields { payinfo1 payinfo2 payinfo3 paytype paystate payname_CHEK )]; } -=item cgi_hash_callback HASHREF +=item cgi_hash_callback HASHREF OLD Subroutine (not a class or object method). Processes a hash reference of web interface contet (transfers the data from pseudo-fields to real fields). +If OLD object is passed, also preserves locationnum, paystart_month, paystart_year, +payissue and payip. If the new field is blank but the old is not, the old field +will be preserved. + =cut sub cgi_hash_callback { my $hashref = shift; + my $old = shift; my %noauto = ( 'CARD' => 'DCRD', @@ -619,6 +624,14 @@ sub cgi_hash_callback { $hashref->{paydate}= $hashref->{paydate_month}. '-'. $hashref->{paydate_year}; + if ($old) { + foreach my $field ( qw(locationnum paystart_month paystart_year payissue payip) ) { + next if $hashref->{$field}; + next unless $old->get($field); + $hashref->{$field} = $old->get($field); + } + } + } =item search_sql diff --git a/FS/FS/o2m_Common.pm b/FS/FS/o2m_Common.pm index 430f00bbb..915393ae9 100644 --- a/FS/FS/o2m_Common.pm +++ b/FS/FS/o2m_Common.pm @@ -111,7 +111,7 @@ sub process_o2m { map { $_ => $opt{'params'}->{$add_param."_$_"} } @{ $opt{'fields'} } ); - &{ $opt{'hash_callback'} }( \%hash ) if $opt{'hash_callback'}; + &{ $opt{'hash_callback'} }( \%hash, $old_obj ) if $opt{'hash_callback'}; #next unless grep { $_ =~ /\S/ } values %hash; my $new_obj = "FS::$table"->new( { %$hashref, %hash } ); diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index bdf3431d7..39cddc021 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -115,7 +115,6 @@ function samechanged(what) { %# billing info <& cust_main/billing.html, $cust_main, - 'payinfo' => $payinfo, 'invoicing_list' => \@invoicing_list, &> @@ -186,7 +185,7 @@ my $conf = new FS::Conf; #get record -my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list); +my($custnum, $cust_main, $ss, $stateid, @invoicing_list); my $pkgpart_svcpart = ''; #first_pkg my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct my %svc_phone = (); @@ -234,7 +233,6 @@ if ( $cgi->param('error') ) { $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid'); $ss = $cust_main->ss; # don't mask an entered value on errors $stateid = $cust_main->stateid; # don't mask an entered value on errors - $payinfo = $cust_main->payinfo; # don't mask an entered value on errors $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') ); @@ -282,7 +280,6 @@ if ( $cgi->param('error') ) { @invoicing_list = $cust_main->invoicing_list; $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss'); $stateid = $cust_main->masked('stateid'); - $payinfo = $cust_main->paymask; } else { #new customer @@ -298,7 +295,6 @@ if ( $cgi->param('error') ) { unless $conf->exists('disablepostalinvoicedefault'); $ss = ''; $stateid = ''; - $payinfo = ''; $cgi->param('tagnum', FS::part_tag->default_tags); diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index 7bca17b50..fbe3e485c 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -326,7 +326,6 @@ function toggle(obj) { my( $cust_main, %options ) = @_; my @invoicing_list = @{ $options{'invoicing_list'} }; -my $payinfo = $options{'payinfo'}; my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; diff --git a/httemplate/elements/cust_payby.html b/httemplate/elements/cust_payby.html index 6e2610bbe..5e0f09d3f 100644 --- a/httemplate/elements/cust_payby.html +++ b/httemplate/elements/cust_payby.html @@ -11,7 +11,8 @@