X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling_Realtime.pm;h=b65860e9b1ec4b207885721f8a078706ed53dad2;hp=4ff2c0602642735b008cd26a0c40e812ac867e7c;hb=4fd1280540e2c9b90fa59c0c32d691f5222f65d4;hpb=92e8ec0e2092fef7bfb126f8d87acac83bbca8eb diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index 4ff2c0602..b65860e9b 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -323,13 +323,16 @@ sub _bop_cust_payby_options { if ( $cust_payby->locationnum ) { my $cust_location = $cust_payby->cust_location; - $options->{$_} = $cust_location->$_() for qw( address1 address2 city state zip ); + $options->{$_} = $cust_location->$_() + for qw( address1 address2 city state zip country ); } } } # can be called as class method, # but can't load default name/phone fields as class method +# (why was this added? ah, it might get called from realtime_tokenize in this +# fashion "to tokenize old records on upgrade") sub _bop_content { my ($self, $options) = @_; my %content = (); @@ -361,7 +364,7 @@ sub _bop_content { $content{name} = $payname if $payname; - if ( exists($options->{'address1'}) ) { + if ( exists($options->{'address1'}) && length($options->{'address1'}) ) { $content{address} = $options->{'address1'}; my $address2 = $options->{'address2'}; @@ -982,17 +985,20 @@ sub _realtime_bop_result { savepoint_create( $savepoint_label ); #start a transaction, insert the cust_pay and set cust_pay_pending.status to done in a single transction - - my $error = $cust_pay->insert($options{'manual'} ? ( 'manual' => 1 ) : () ); + my $error = $cust_pay->insert( + $options{'manual'} ? ( 'manual' => 1 ) : (), + $options{'processing-fee'} > 0 ? ( 'processing-fee' => $options{'processing-fee'} ) : (), + ); if ( $error ) { savepoint_rollback( $savepoint_label ); $cust_pay->invnum(''); #try again with no specific invnum $cust_pay->paynum(''); - my $error2 = $cust_pay->insert( $options{'manual'} ? - ( 'manual' => 1 ) : () - ); + my $error2 = $cust_pay->insert( + $options{'manual'} ? ( 'manual' => 1 ) : (), + $options{'processing-fee'} > 0 ? ( 'processing-fee' => $options{'processing-fee'} ) : (), + ); if ( $error2 ) { # gah. but at least we have a record of the state we had to abort in # from cust_pay_pending now. @@ -1134,11 +1140,23 @@ sub _realtime_bop_result { if ($options{'processing-fee'} > 0) { my $pf_cust_pkg; my $processing_fee_text = 'Payment Processing Fee'; + + my $conf = new FS::Conf; + + my $pf_seperate_bill; + my $pf_bill_now; + if ($conf->exists('processing-fee_on_separate_invoice')) { + $pf_seperate_bill = 'Y'; + $pf_bill_now = '1'; + } + my $pf_change_error = $self->charge({ 'amount' => $options{'processing-fee'}, 'pkg' => $processing_fee_text, 'setuptax' => 'Y', 'cust_pkg_ref' => \$pf_cust_pkg, + 'separate_bill' => $pf_seperate_bill, + 'bill_now' => $pf_bill_now, }); if($pf_change_error) { @@ -1153,17 +1171,41 @@ sub _realtime_bop_result { # but keep going... } - my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum }); - unless ( $cust_bill ) { - warn "race condition + invoice deletion just happened"; - return ''; - } + if ($conf->exists('processing-fee_on_separate_invoice')) { + my $cust_bill_pkg = qsearchs( 'cust_bill_pkg', { 'pkgnum' => $pf_cust_pkg->pkgnum } ); + + my $pf_cust_bill = qsearchs('cust_bill', { 'invnum' => $cust_bill_pkg->invnum }); + unless ( $pf_cust_bill ) { + warn "no processing fee inv found!"; + return ''; + } + + my $pf_apply_error = $pf_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_pf_error = $cust_bill->apply_payments_and_credits; + + warn "cannot apply Processing fee to invoice #$invnum: $grand_pf_error - $pf_apply_error" + if $grand_pf_error || $pf_apply_error; + } ## processing-fee_on_separate_invoice + else { + my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum }); + unless ( $cust_bill ) { + warn "race condition + invoice deletion just happened"; + return ''; + } - my $grand_pf_error = - $cust_bill->add_cc_surcharge($pf_cust_pkg->pkgnum,$options{'processing-fee'}); + my $grand_pf_error = + $cust_bill->add_cc_surcharge($pf_cust_pkg->pkgnum,$options{'processing-fee'}); - warn "cannot add Processing fee to invoice #$invnum: $grand_pf_error" - if $grand_pf_error; + warn "cannot add Processing fee to invoice #$invnum: $grand_pf_error" + if $grand_pf_error; + } ## no processing-fee_on_separate_invoice } #end if $options{'processing-fee'} } #end if ( $options{'cc_surcharge'} > 0 || $options{'processing-fee'} > 0)