X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTemplate_Mixin.pm;h=8dff768d9f382aeeb68a9bbeee0a5b88de734fff;hb=f8b487ec9788999ed16e77ff246fa4f34f8d7af1;hp=04ea1eb9926a0e79b86a822a593fd7c6984e07bf;hpb=8c865c1e8ab994e14ee81b11b0544f2a280d2d07;p=freeside.git diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 04ea1eb99..8dff768d9 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -2352,12 +2352,19 @@ sub mimebuild_pdf { ); } +=item postal_mail_fsinc +Sends this invoice to the Freeside Internet Services, Inc. print and mail +service. + +=cut use CAM::PDF; +use IO::Socket::SSL; use LWP::UserAgent; use HTTP::Request::Common qw( POST ); use JSON::XS; +use MIME::Base64; sub postal_mail_fsinc { my ( $self, %opt ) = @_; @@ -2389,14 +2396,20 @@ sub postal_mail_fsinc { } else { die "Unparsable company_address; contact support\@freeside.biz\n"; } + $company_city =~ s/,$//; my $file = $self->print_pdf(%opt, 'no_addresses' => 1); my $pages = CAM::PDF->new($file)->numPages; - my $ua = LWP::UserAgent->new( 'ssl_opts' => { 'verify_hostname'=>0 }); + my $ua = LWP::UserAgent->new( + 'ssl_opts' => { + verify_hostname => 0, + SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, + } + ); my $response = $ua->request( POST $url, [ 'support-key' => scalar($conf->config('support-key')), - 'file' => $file, + 'file' => encode_base64($file), 'pages' => $pages, #from: @@ -2434,28 +2447,11 @@ sub postal_mail_fsinc { die $content->{error}."\n" if $content->{error}; -} - -1; - 'address1' => $bill_location->address1, - 'address2' => $bill_location->address2, - 'city' => $bill_location->city, - 'state' => $bill_location->state, - 'zip' => $bill_location->zip, - 'country' => $bill_location->country, - ]); - die "Print connection error: ". $response->message - unless $response->is_success; - - local $@; - my $content = eval { decode_json($response->content) }; - die "Print JSON error : $@\n" if $@; - - die $content->{error}."\n" - if $content->{error}; + #TODO: store this so we can query for a status later + warn "Invoice printed, ID ". $content->{id}. "\n"; - #TODO: get some kind of letter ID back we can later retreive a status on + $content->{id}; } =item _items_sections OPTIONS