1 package FS::part_event::Action::http;
2 use base qw( FS::part_event::Action );
8 use HTTP::Request::Common;
10 use FS::Misc::DateTime qw( iso8601 );
12 $me = '[FS::part_event::Action::http]';
14 #sub description { 'Send an HTTP or HTTPS GET or POST request'; }
15 sub description { 'Send an HTTP or HTTPS POST request'; }
17 sub eventtable_hashref {
22 'cust_pay_batch' => 1,
23 'cust_statement' => 1,
30 'method' => { label => 'Method',
32 options => [qw( POST )], #GET )],
34 'url' => { label => 'URL',
38 'ssl_no_verify' => { label => 'Skip SSL certificate validation',
41 'encoding' => { label => 'Encoding',
43 options => [qw( JSON )], #XML, Form, etc.
45 'content' => { label => 'Content', #nneed better inline docs on format
48 #'response_error_param' => 'Response error parameter',
49 'debug' => { label => 'Enable debugging',
56 sub default_weight { 57; }
59 'JSON' => 'application/json',
63 my( $self, $object ) = @_;
65 my $cust_main = $self->cust_main($object);
69 /^\s*(\S+)\s+(.*)$/ or /()()/;
70 my( $field, $value_expression ) = ( $1, $2 );
71 my $value = eval $value_expression;
74 } split(/\n/, $self->option('content') );
76 if ( $self->option('debug') ) {
77 warn "[$me] $_: ". $content{$_}. "\n" foreach keys %content;
80 my $content = encode_json( \%content );
83 push @lwp_opts, 'ssl_opts' => {
85 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
87 if $self->option('ssl_no_verify');
88 my $ua = LWP::UserAgent->new(@lwp_opts);
90 my $req = HTTP::Request::Common::POST(
92 Content_Type => $content_type{ $self->option('encoding') },
96 if ( $self->option('debug') ) {
97 #XXX dump raw request for debugging
99 my $response = $ua->request($req);
101 die $response->status_line if $response->is_error;
103 my $response_json = decode_json( $response->content );
104 die $response_json->{error} if $response_json->{error}; #XXX response_error_param