X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling_Realtime.pm;h=1006b9520afa48a0be96720024d71e80ae317407;hb=7d1cf3b75da3ba9aab3667cdc0125e25bbc76438;hp=ea09379bade07d57d1e840a3c21b11b7c37806e6;hpb=0f7643c1af2d909e0c3172e5bec0c01855fca1b9;p=freeside.git diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index ea09379ba..1006b9520 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -19,7 +19,7 @@ $realtime_bop_decline_quiet = 0; # 1 is mostly method/subroutine entry and options # 2 traces progress of some operations # 3 is even more information including possibly sensitive data -$DEBUG = 1; +$DEBUG = 0; $me = '[FS::cust_main::Billing_Realtime]'; install_callback FS::UID sub { @@ -322,7 +322,9 @@ sub realtime_bop { ### my $cc_surcharge = 0; - my $cc_surcharge_pct = $conf->config('credit-card-surcharge-percentage'); + my $cc_surcharge_pct = 0; + $cc_surcharge_pct = $conf->config('credit-card-surcharge-percentage') + if $conf->config('credit-card-surcharge-percentage'); # always add cc surcharge if called from event if($options{'cc_surcharge_from_event'} && $cc_surcharge_pct > 0) { @@ -335,11 +337,10 @@ sub realtime_bop { # amount as post-surcharge $cc_surcharge = $options{'amount'} - ($options{'amount'} / ( 1 + $cc_surcharge_pct/100 )); } - if ( $cc_surcharge > 0) { - $cc_surcharge = sprintf("%.2f",$cc_surcharge); - $options{'cc_surcharge'} = $cc_surcharge; - } - + + $cc_surcharge = sprintf("%.2f",$cc_surcharge) if $cc_surcharge > 0; + $options{'cc_surcharge'} = $cc_surcharge; + if ( $DEBUG ) { warn "$me realtime_bop (new): $options{method} $options{amount}\n"; @@ -460,9 +461,9 @@ sub realtime_bop { $content{bank_state} = exists($options{'paystate'}) ? $options{'paystate'} : $self->getfield('paystate'); - $content{account_type} = exists($options{'paytype'}) - ? uc($options{'paytype'}) || 'CHECKING' - : uc($self->getfield('paytype')) || 'CHECKING'; + $content{account_type}= (exists($options{'paytype'}) && $options{'paytype'}) + ? uc($options{'paytype'}) + : uc($self->getfield('paytype')) || 'PERSONAL CHECKING'; $content{account_name} = $self->getfield('first'). ' '. $self->getfield('last'); @@ -912,6 +913,8 @@ sub _realtime_bop_result { # have a CC surcharge portion --> one-time charge if ( $options{'cc_surcharge'} > 0 ) { + # XXX: this whole block needs to be in a transaction? + my $invnum; $invnum = $options{'invnum'} if $options{'invnum'}; unless ( $invnum ) { # probably from a payment screen @@ -942,26 +945,28 @@ sub _realtime_bop_result { 'cust_pkg_ref' => \$cust_pkg, }); if($charge_error) { - warn 'Unable to add CC surcharge'; + warn 'Unable to add CC surcharge cust_pkg'; return ''; } + + $cust_pkg->setup(time); + my $cp_error = $cust_pkg->replace; + if($cp_error) { + warn 'Unable to set setup time on cust_pkg for cc surcharge'; + # but keep going... + } - my $cust_bill_pkg = new FS::cust_bill_pkg({ - 'invnum' => $invnum, - 'pkgnum' => $cust_pkg->pkgnum, - 'setup' => $options{'cc_surcharge'}, - }); - my $cbp_error = $cust_bill_pkg->insert; - - if ( $cbp_error) { - warn 'Cannot add CC surcharge line item to invoice #'.$invnum; - return ''; - } else { - my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum }); - warn 'invoice for cc surcharge: ' . Dumper($cust_bill) if $DEBUG; - $cust_bill->apply_payments_and_credits; + my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum }); + unless ( $cust_bill ) { + warn "race condition + invoice deletion just happened"; + return ''; } + my $grand_error = + $cust_bill->add_cc_surcharge($cust_pkg->pkgnum,$options{'cc_surcharge'}); + + warn "cannot add CC surcharge to invoice #$invnum: $grand_error" + if $grand_error; } return ''; #no error @@ -981,7 +986,7 @@ sub _realtime_bop_result { my $error = $placeholder->depended_delete; $error ||= $placeholder->delete; warn "error removing provisioning jobs after declined paypendingnum ". - $cust_pay_pending->paypendingnum. "\n"; + $cust_pay_pending->paypendingnum. ": $error\n"; } else { my $e = "error finding job $jobnum for declined paypendingnum ". $cust_pay_pending->paypendingnum. "\n";