From: Mitch Jackson Date: Mon, 11 Jun 2018 20:06:50 +0000 (-0500) Subject: RT# 80514 Selfservice can update ssn/stateid payment info X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=fbe36a956f6e39078c926b8dbbf5d1afca5ea2ea;p=freeside.git RT# 80514 Selfservice can update ssn/stateid payment info --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 05bc6d769..5c850301b 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -1735,12 +1735,18 @@ sub update_payby { $p->{paydate} = $p->{year} . '-' . $p->{month} . '-01' unless $p->{paydate}; } + # Perform update within a transaction + local $FS::UID::AutoCommit = 0; + my $cust_payby = qsearchs('cust_payby', { 'custnum' => $custnum, 'custpaybynum' => $p->{'custpaybynum'}, }) or return { 'error' => 'unknown custpaybynum '. $p->{'custpaybynum'} }; + my $cust_main = qsearchs( 'cust_main', {custnum => $cust_payby->custnum} ) + or return { 'error' => 'unknown custnum '.$cust_payby->custnum }; + foreach my $field ( qw( weight payby payinfo paycvv paydate payname paystate paytype payip ) ) { @@ -1749,9 +1755,22 @@ sub update_payby { } my $error = $cust_payby->replace; + + if (!$error) { + my $is_changed = 0; + for my $field ( qw/ss stateid/ ) { + next if !exists $p->{$field} || $p->{$field} =~ /^x/i; + $cust_main->set( $field, $p->{$field} ); + $is_changed = 1; + } + $error = $cust_main->replace if $is_changed; + } + if ( $error ) { + dbh->rollback; return { 'error' => $error }; } else { + dbh->commit; return { 'custpaybynum' => $cust_payby->custpaybynum }; }