X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTaxEngine%2Fsuretax.pm;h=356f5f318cacef91db2a45469b12dc7c1767c0dc;hb=0ec0b91b7c383d626dd75b0c2b2d3969e5bdcbc7;hp=e18b66866bc5d98512c948757354dfb42d8fd462;hpb=3824fc8dc74f8ec088fc7af810f62ee85afac34c;p=freeside.git diff --git a/FS/FS/TaxEngine/suretax.pm b/FS/FS/TaxEngine/suretax.pm index e18b66866..356f5f318 100644 --- a/FS/FS/TaxEngine/suretax.pm +++ b/FS/FS/TaxEngine/suretax.pm @@ -14,7 +14,7 @@ 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 = Cpanel::JSON::XS->new->pretty(1); +our $json = Cpanel::JSON::XS->new->pretty(0)->shrink(1); our %taxproduct_cache; @@ -77,7 +77,7 @@ sub build_request { ($self->{bill_zip}, $self->{bill_plus4}) = split('-', $cust_main->bill_location->zip); - $self->{regcode} = $REGCODE{ $conf->config('suretax-regulatory_code') }; + $self->{regcode} = $REGCODE{ $conf->config('suretax-regulatory_code', $agentnum) }; %taxproduct_cache = (); @@ -97,8 +97,8 @@ sub build_request { ClientNumber => $ClientNumber, ValidationKey => $ValidationKey, BusinessUnit => $BusinessUnit, - DataYear => '2015', #$date->year, - DataMonth => '04', #sprintf('%02d', $date->month), + DataYear => $date->year, + DataMonth => sprintf('%02d', $date->month), TotalRevenue => sprintf('%.4f', $cust_bill->charged), ReturnFileCode => ($self->{estimate} ? 'Q' : '0'), ClientTracking => $cust_bill->invnum, @@ -328,13 +328,14 @@ sub make_taxlines { return; } - warn "sending SureTax request\n" if $DEBUG; + warn "encoding 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'; + warn "sending SureTax request\n" if $DEBUG; # We are targeting the "V05" interface: # - accepts both telecom and general sales transactions # - produces results broken down by "invoice" (Freeside line item) @@ -346,8 +347,11 @@ sub make_taxlines { 'Accept' => 'application/json', ); + warn 'received SureTax response: '. $http_response->status_line. "\n" + if $DEBUG; + die $http_response->status_line. "\n" unless $http_response->is_success; + my $raw_response = $http_response->content; - warn "received response\n" if $DEBUG; warn $raw_response if $DEBUG > 2; my $response; if ( $raw_response =~ /^<\?xml/ ) { @@ -356,8 +360,10 @@ sub make_taxlines { $response = XMLin( $raw_response ); $raw_response = $response->{content}; } + + warn "decoding SureTax response\n" if $DEBUG; $response = eval { $json->decode($raw_response) } - or die "$raw_response\n"; + or die "Can't JSON-decode response: $raw_response\n"; # documentation implies this might be necessary $response = $response->{'d'} if exists $response->{'d'}; @@ -375,6 +381,7 @@ sub make_taxlines { } return if !$response->{GroupList}; + warn "creating FS objects from SureTax data\n" if $DEBUG; foreach my $taxable ( @{ $response->{GroupList} } ) { # each member of this array here corresponds to what SureTax calls an # "invoice" and we call a "line item". The invoice number is @@ -420,6 +427,7 @@ sub make_taxlines { }); } } + warn "TaxEngine/suretax.pm make_taxlines done; returning FS objects\n" if $DEBUG; return @elements; }