X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount.pm;h=f51174e5d60e5af3bfe697ff185496f8e1ba5d53;hp=58ab6c0b7fc2f40a24e92d7ee04f9f306af7aa1b;hb=4c4b99f655084122e9b55222dae3e94757b78cae;hpb=88d5d75f5297eaa96d3cd0c2a5f29c981e43e126 diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 58ab6c0b7..f51174e5d 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -212,7 +212,41 @@ sub payment_info { my $session = $cache->get($p->{'session_id'}) or return { 'error' => "Can't resume session" }; #better error message - my %return; + ## + #generic + ## + + my $conf = new FS::Conf; + my %states = map { $_->state => 1 } + qsearch('cust_main_county', { + 'country' => $conf->config('defaultcountry') || 'US' + } ); + + use vars qw($payment_info); #cache for performance + $payment_info ||= { + + #list all counties/states/countries + 'cust_main_county' => + [ map { $_->hashref } qsearch('cust_main_county', {}) ], + + #shortcut for one-country folks + 'states' => + [ sort { $a cmp $b } keys %states ], + + 'card_types' => { + 'VISA' => 'VISA card', + 'MasterCard' => 'MasterCard', + 'Discover' => 'Discover card', + 'American Express' => 'American Express card', + }, + + }; + + ## + #customer-specific + ## + + my %return = %$payment_info; my $custnum = $session->{'custnum'}; @@ -236,25 +270,7 @@ sub payment_info { } - #list all counties/states/countries - $return{'cust_main_county'} = - [ map { $_->hashref } qsearch('cust_main_county', {}) ]; - - #shortcut for one-country folks - my $conf = new FS::Conf; - my %states = map { $_->state => 1 } - qsearch('cust_main_county', { - 'country' => $conf->config('defaultcountry') || 'US' - } ); - $return{'states'} = [ sort { $a cmp $b } keys %states ]; - - $return{card_types} = { - 'VISA' => 'VISA card', - 'MasterCard' => 'MasterCard', - 'Discover' => 'Discover card', - 'American Express' => 'American Express card', - }; - + #doubleclick protection my $_date = time; $return{paybatch} = "webui-MyAccount-$_date-$$-". rand() * 2**32; @@ -539,7 +555,8 @@ sub order_pkg { $cust_main->apply_credits; $bill_error = $cust_main->collect; - if ( $cust_main->balance > $old_balance + if ( $cust_main->balance > $old_balance + && $cust_main->balance > 0 && $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ ) { #this makes sense. credit is "un-doing" the invoice $cust_main->credit( sprintf("%.2f", $cust_main->balance - $old_balance ), @@ -547,7 +564,7 @@ sub order_pkg { $cust_main->apply_credits( 'order' => 'newest' ); $cust_pkg->cancel('quiet'=>1); - return { 'error' => '_decline' }; + return { 'error' => '_decline', 'bill_error' => $bill_error }; } else { $cust_pkg->reexport; }