JSON::XS -> Cpanel::JSON::XS
[freeside.git] / FS / FS / TaxEngine / suretax.pm
index 327a728..073d19b 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use base 'FS::TaxEngine';
 use FS::Conf;
 use FS::Record qw(qsearch qsearchs dbh);
-use JSON;
+use Cpanel::JSON::XS;
 use XML::Simple qw(XMLin);
 use LWP::UserAgent;
 use HTTP::Request::Common;
@@ -14,15 +14,12 @@ our $DEBUG = 1; # prints progress messages
 #   $DEBUG = 2; # prints decoded request and response (noisy, be careful)
 #   $DEBUG = 3; # prints raw response from the API, ridiculously unreadable
 
-our $json = JSON->new->pretty(1);
+our $json = Cpanel::JSON::XS->new->pretty(1);
 
 our %taxproduct_cache;
 
 our $conf;
 
-our $host = 'testapi.taxrating.net';
-# production: 'api.taxrating.net'
-
 FS::UID->install_callback( sub {
     $conf = FS::Conf->new;
     # should we enable conf caching here?
@@ -88,6 +85,8 @@ sub build_request {
   my @lines = map { $self->build_item($_) }
               $cust_bill->cust_bill_pkg;
 
+  return if !@lines;
+
   my $ClientNumber = $conf->config('suretax-client_number')
     or die "suretax-client_number config required.\n";
   my $ValidationKey = $conf->config('suretax-validation_key')
@@ -309,11 +308,18 @@ sub make_taxlines {
 
   # assemble the request hash
   my $request = $self->build_request;
+  if (!$request) {
+    warn "no taxable items in invoice; skipping SureTax request\n" if $DEBUG;
+    return;
+  }
 
   warn "sending SureTax request\n" if $DEBUG;
   my $request_json = $json->encode($request);
   warn $request_json if $DEBUG > 1;
 
+  my $host = $conf->config('suretax-hostname');
+  $host ||= 'testapi.taxrating.net';
+
   # We are targeting the "V05" interface:
   # - accepts both telecom and general sales transactions
   # - produces results broken down by "invoice" (Freeside line item)