1 <% objToJson($return) %>
6 my $conf = new FS::Conf;
8 my $sub = $cgi->param('sub');
12 if ( $sub eq 'address_standardize' ) {
14 my %arg = $cgi->param('arg');
16 warn join('', map "$_: $arg{$_}\n", keys %arg )
19 my $userid = $conf->config('usps_webtools-userid');
20 my $password = $conf->config('usps_webtools-password');
22 if ( length($userid) && length($password) ) {
24 my $verifier = Business::US::USPS::WebTools::AddressStandardization->new( {
25 UserID => $userid, #$ENV{USPS_WEBTOOLS_USERID},
26 Password => $password, #$ENV{USPS_WEBTOOLS_PASSWORD},
30 foreach my $pre ( '', 'ship_' ) {
32 my($zip5, $zip4) = split('-',$arg{$pre.'zip'});
35 FirmName => $arg{$pre.'company'},
36 Address2 => $arg{$pre.'address1'},
37 Address1 => $arg{$pre.'address2'},
38 City => $arg{$pre.'city'},
39 State => $arg{$pre.'state'},
43 warn join('', map "$_: $usps_args{$_}\n", keys %usps_args )
46 my $hash = $verifier->verify_address( %usps_args );
48 warn $verifier->response
51 unless ( $verifier->is_error ) {
55 "new_$pre".'company' => $hash->{FirmName},
56 "new_$pre".'address1' => $hash->{Address2},
57 "new_$pre".'address2' => $hash->{Address1},
58 "new_$pre".'city' => $hash->{City},
59 "new_$pre".'state' => $hash->{State},
60 "new_$pre".'zip' => $hash->{Zip5}. '-'. $hash->{Zip4},
63 my @fields = (qw( company address1 address2 city state zip )); #hmm
66 scalar( grep { $return->{$pre.$_} ne $return->{"new_$pre$_"} }
71 $return->{$pre.'address_standardized'} = $changed;
75 warn "USPS WebTools error: ". $verifier->response. "\n";