diff options
Diffstat (limited to 'httemplate/misc')
-rw-r--r-- | httemplate/misc/xmlhttp-cust_main-address_standardize.html | 87 | ||||
-rw-r--r-- | httemplate/misc/xmlhttp-cust_main-search.cgi | 2 |
2 files changed, 88 insertions, 1 deletions
diff --git a/httemplate/misc/xmlhttp-cust_main-address_standardize.html b/httemplate/misc/xmlhttp-cust_main-address_standardize.html new file mode 100644 index 000000000..e290301c9 --- /dev/null +++ b/httemplate/misc/xmlhttp-cust_main-address_standardize.html @@ -0,0 +1,87 @@ +<% to_json($return) %> +<%init> + +my $DEBUG = 1; + +my $conf = new FS::Conf; + +my $sub = $cgi->param('sub'); + +my $return = {}; + +if ( $sub eq 'address_standardize' ) { + + my %arg = $cgi->param('arg'); + $return = \%arg; + warn join('', map "$_: $arg{$_}\n", keys %arg ) + if $DEBUG; + + my $userid = $conf->config('usps_webtools-userid'); + my $password = $conf->config('usps_webtools-password'); + + if ( length($userid) && length($password) ) { + + my $verifier = Business::US::USPS::WebTools::AddressStandardization->new( { + UserID => $userid, #$ENV{USPS_WEBTOOLS_USERID}, + Password => $password, #$ENV{USPS_WEBTOOLS_PASSWORD}, + #Testing => 1, + } ); + + foreach my $pre ( '', 'ship_' ) { + + my($zip5, $zip4) = split('-',$arg{$pre.'zip'}); + + my %usps_args = ( + FirmName => $arg{$pre.'company'}, + Address2 => $arg{$pre.'address1'}, + Address1 => $arg{$pre.'address2'}, + City => $arg{$pre.'city'}, + State => $arg{$pre.'state'}, + Zip5 => $zip5, + Zip4 => $zip4, + ); + warn join('', map "$_: $usps_args{$_}\n", keys %usps_args ) + if $DEBUG; + + my $hash = $verifier->verify_address( %usps_args ); + + warn $verifier->response + if $DEBUG; + + unless ( $verifier->is_error ) { + + $return = { + %$return, + "new_$pre".'company' => $hash->{FirmName}, + "new_$pre".'address1' => $hash->{Address2}, + "new_$pre".'address2' => $hash->{Address1}, + "new_$pre".'city' => $hash->{City}, + "new_$pre".'state' => $hash->{State}, + "new_$pre".'zip' => $hash->{Zip5}. '-'. $hash->{Zip4}, + }; + + my @fields = (qw( company address1 address2 city state zip )); #hmm + + my $changed = + scalar( grep { $return->{$pre.$_} ne $return->{"new_$pre$_"} } + @fields + ) + ? 1 : 0; + + $return->{$pre.'address_standardized'} = $changed; + + } else { + + warn "USPS WebTools error: ". $verifier->response. "\n"; + + } + + } + + } + + $return; + +} + +</%init> diff --git a/httemplate/misc/xmlhttp-cust_main-search.cgi b/httemplate/misc/xmlhttp-cust_main-search.cgi index 20707dab8..374623039 100644 --- a/httemplate/misc/xmlhttp-cust_main-search.cgi +++ b/httemplate/misc/xmlhttp-cust_main-search.cgi @@ -15,7 +15,7 @@ % my @cust_main = smart_search( 'search' => $string ); % my $return = [ map [ $_->custnum, $_->name ], @cust_main ]; % -<% objToJson($return) %> +<% to_json($return) %> % } <%init> |