diff options
author | ivan <ivan> | 2008-05-08 12:47:13 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-05-08 12:47:13 +0000 |
commit | 9dc88f6c738f30ce1eb6339ba4b739b45555dea4 (patch) | |
tree | 2c0e002ffcc1e08c1d2e16efa46c15e31466eae7 /httemplate/misc/xmlhttp-cust_main-address_standardize.html | |
parent | bfd99094043a3260afa2770b9e3f366308041490 (diff) |
address standardization part one, finally checked in from here
Diffstat (limited to 'httemplate/misc/xmlhttp-cust_main-address_standardize.html')
-rw-r--r-- | httemplate/misc/xmlhttp-cust_main-address_standardize.html | 87 |
1 files changed, 87 insertions, 0 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> |