From 3cd4fcd5ba52826336c727b855ac12a6407a4b35 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 19 Nov 2013 22:30:12 -0800 Subject: [PATCH] fix self-service error on change package with BILL customers and selfservice-realtime, RT#26140 --- FS/FS/ClientAPI/MyAccount.pm | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 241963f90..a58099184 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -2318,7 +2318,7 @@ sub change_pkg { my $conf = new FS::Conf; if ( $conf->exists('signup_server-realtime') ) { - my $bill_error = _do_bop_realtime( $cust_main, $status ); + my $bill_error = _do_bop_realtime( $cust_main, $status, 'no_credit'=>1 ); if ($bill_error) { $newpkg[0]->suspend; @@ -2390,25 +2390,32 @@ sub order_recharge { } sub _do_bop_realtime { - my ($cust_main, $status) = (shift, shift); + my ($cust_main, $status, %opt) = @_; my $old_balance = $cust_main->balance; my $bill_error = $cust_main->bill - || $cust_main->apply_payments_and_credits - || $cust_main->realtime_collect('selfservice' => 1); + || $cust_main->apply_payments_and_credits; + + $bill_error ||= $cust_main->realtime_collect('selfservice' => 1) + if $cust_main->payby =~ /^(CARD|CHEK)$/; if ( $cust_main->balance > $old_balance && $cust_main->balance > 0 - && ( $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ ? - 1 : $status eq 'suspended' ) ) { - #this makes sense. credit is "un-doing" the invoice - my $conf = new FS::Conf; - $cust_main->credit( sprintf("%.2f", $cust_main->balance - $old_balance ), - 'self-service decline', - 'reason_type' => $conf->config('signup_credit_type'), - ); - $cust_main->apply_credits( 'order' => 'newest' ); + && ( $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ + || $status eq 'suspended' + ) + ) + { + unless ( $opt{'no_credit'} ) { + #this makes sense. credit is "un-doing" the invoice + my $conf = new FS::Conf; + $cust_main->credit( sprintf("%.2f", $cust_main->balance-$old_balance ), + 'self-service decline', + reason_type=>$conf->config('signup_credit_type'), + ); + $cust_main->apply_credits( 'order' => 'newest' ); + } return { 'error' => '_decline', 'bill_error' => $bill_error }; } -- 2.11.0