X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FFreeside.pm;h=42b9c42eb4dd98266f8a4d69dcfa6d971986a11d;hb=dc83512c36dc6bea2585abada4f88d714c600e55;hp=8aa61e632a54cc2f8dcb518599e492d9996c683b;hpb=ec7ca61709fe2f1bc2f7458f61336cbbccf933c8;p=freeside.git diff --git a/FS/FS/ClientAPI/Freeside.pm b/FS/FS/ClientAPI/Freeside.pm index 8aa61e632..42b9c42eb 100644 --- a/FS/FS/ClientAPI/Freeside.pm +++ b/FS/FS/ClientAPI/Freeside.pm @@ -44,16 +44,34 @@ sub freesideinc_service { return { 'error' => 'bad support-key' }; } + my $cust_pkg = $svc_acct->cust_svc->cust_pkg; + my $custnum = $cust_pkg->custnum; + + my $quantity = $packet->{'quantity'} || 1; + + #false laziness w/webservice_log.pm + my $color = 1.10; + my $page = 0.10; + #XXX check if some customers can use some API calls, rate-limiting, etc. # but for now, everybody can use everything + if ( $packet->{method} eq 'print' ) { + my $avail_credit = $cust_pkg->cust_main->credit_limit + - $color - $quantity * $page + - FS::webservice_log->price_print( + 'custnum' => $custnum, + ); + + return { 'error' => 'Over credit limit' } + if $avail_credit <= 0; + } #record it happened - my $custnum = $svc_acct->cust_svc->cust_pkg->custnum; my $webservice_log = new FS::webservice_log { 'custnum' => $custnum, 'svcnum' => $svc_acct->svcnum, 'method' => $packet->{'method'}, - 'quantity' => $packet->{'quantity'} || 1, + 'quantity' => $quantity, }; my $error = $webservice_log->insert; return { 'error' => $error } if $error;