summaryrefslogtreecommitdiff
path: root/FS/FS/ClientAPI
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2016-12-27 12:26:43 -0800
committerIvan Kohler <ivan@freeside.biz>2016-12-27 12:26:43 -0800
commit4ccd5cf8a013f79dc73805f2df382ac96b455bdf (patch)
tree3641cfbb951b5a0be536a5098cfb8c48f2bd025f /FS/FS/ClientAPI
parentacac1a271646cd2f9bfbb05a41372b360cbb5c8f (diff)
credit limit for printing
Diffstat (limited to 'FS/FS/ClientAPI')
-rw-r--r--FS/FS/ClientAPI/Freeside.pm22
1 files changed, 20 insertions, 2 deletions
diff --git a/FS/FS/ClientAPI/Freeside.pm b/FS/FS/ClientAPI/Freeside.pm
index 8aa61e6..42b9c42 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;