1 package FS::part_export::cust_location_http;
4 use base qw( FS::part_export::http );
5 use vars qw( %options %info );
7 use FS::cust_main::Location;
9 my @location_fields = ( qw( custnum prospectnum ), FS::cust_main::Location->location_fields );
11 tie %options, 'Tie::IxHash',
12 'method' => { label =>'Method',
14 #options =>[qw(POST GET)],
17 'location_url' => { label => 'Location URL' },
18 'package_url' => { label => 'Package URL' },
19 'ssl_no_verify' => { label => 'Skip SSL certificate validation',
22 'include_fields' => { 'label' => 'Include fields',
25 'options' => [ @location_fields ] },
27 label => 'Success Regexp',
33 'svc' => [qw( cust_location )],
34 'desc' => 'Send an HTTP or HTTPS GET or POST request, for customer locations',
35 'options' => \%options,
38 Send an HTTP or HTTPS GET or POST to the specified URLs on customer location
39 creation/update (action 'location') and package location assignment/change (action 'package').
40 Always sends locationnum, action and any fields specified in the 'Include fields'
41 export option. Action 'package' also sends pkgnum and old_pkgnum (because location
42 changes usually instigate a pkgnum change.) Action 'location' only sends on replace
43 if one of the specified fields changed. Leave a URL blank to skip that action.
44 For HTTPS support, <a href="http://search.cpan.org/dist/Crypt-SSLeay">Crypt::SSLeay</a>
45 or <a href="http://search.cpan.org/dist/IO-Socket-SSL">IO::Socket::SSL</a> is required.
49 # we don't do anything on deletion because we generally don't delete locations
51 # we don't send blank custnum/prospectnum because we do a lot of inserting/replacing
52 # with blank values and then immediately overwriting, but that unfortunately
53 # makes it difficult to indicate if this is the first time we've sent the location
54 # to the customer--hence we don't distinguish creation from update in the cgi vars
56 # gets invoked by FS::part_export::http _export_insert
58 my( $self, $action, $cust_location ) = ( shift, shift, shift );
60 # redundant--cust_location exports don't get invoked by cust_location->delete,
61 # or by any status trigger, but just to be clear, since http export has other actions...
62 return '' unless $action eq 'insert';
64 $self->_http_queue_standard(
65 'action' => 'location',
66 map { $_ => $cust_location->get($_) } ('locationnum', $self->_include_fields)
72 my( $self, $new, $old ) = ( shift, shift, shift );
75 foreach my $field ($self->_include_fields) {
76 next if $new->get($field) eq $old->get($field);
77 next if ($field =~ /latitude|longitude/) and $new->get($field) == $old->get($field);
81 return '' unless $changed;
83 $self->_http_queue_standard(
84 'action' => 'location',
85 map { $_ => $new->get($_) } ('locationnum', $self->_include_fields)
89 # not to be confused with export_pkg_change, which is for svcs
90 sub export_pkg_location {
91 my( $self, $cust_pkg ) = ( shift, shift, shift );
93 return '' unless $cust_pkg->locationnum;
95 my $cust_location = $cust_pkg->cust_location;
97 $self->_http_queue_standard(
98 'action' => 'package',
99 (map { $_ => $cust_pkg->get($_) } ('pkgnum', 'change_pkgnum', 'locationnum')),
100 (map { $_ => $cust_location->get($_) } $self->_include_fields),
104 sub _http_queue_standard {
108 if ($opts{'action'} eq 'location') {
109 $url = $self->option('location_url');
110 return '' unless $url;
111 } elsif ($opts{'action'} eq 'package') {
112 $url = $self->option('package_url');
113 return '' unless $url;
115 return "Bad action ".$opts{'action'};
117 $self->http_queue( '',
118 ( $self->option('ssl_no_verify') ? 'ssl_no_verify' : '' ),
119 $self->option('method'),
121 $self->option('success_regexp'),
126 sub _include_fields {
128 split( /\s+/, $self->option('include_fields') );