for (@cust_main_editable_fields) {
$return{$_} = $cust_main->get($_);
}
-
- $return{ss} = $cust_main->masked('ss') if $p->{mask_ss};
- $return{stateid} = $cust_main->masked('stateid') if $p->{mask_stateid};
+ $return{$_} = $cust_main->masked($_) for qw/ss stateid/;
#maybe a little more expensive, but it should be cached by now
for (@location_editable_fields) {
})
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 )
) {
next unless exists($p->{$field});
$cust_payby->set($field,$p->{$field});
}
+ $cust_payby->set( 'paymask' => $cust_payby->mask_payinfo );
- my $error = $cust_payby->replace;
- if ( $error ) {
- return { 'error' => $error };
- } else {
- return { 'custpaybynum' => $cust_payby->custpaybynum };
+ # Update column if given a value, and the given value wasn't
+ # the value generated by $cust_main->masked($column);
+ $cust_main->set( $_, $p->{$_} )
+ for grep{ $p->{$_} !~ /^x/i; }
+ grep{ exists $p->{$_} }
+ qw/ss stateid/;
+
+ # Perform updates within a transaction
+ local $FS::UID::AutoCommit = 0;
+
+ if ( my $error = $cust_payby->replace || $cust_main->replace ) {
+ dbh->rollback;
+ return { error => $error };
}
-
+
+ dbh->commit;
+ return { custpaybynum => $cust_payby->custpaybynum };
}
sub verify_payby {