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_' ) {
31 next unless ($pre || !$arg{onlyship});
33 my($zip5, $zip4) = split('-',$arg{$pre.'zip'});
36 FirmName => $arg{$pre.'company'},
37 Address2 => $arg{$pre.'address1'},
38 Address1 => $arg{$pre.'address2'},
39 City => $arg{$pre.'city'},
40 State => $arg{$pre.'state'},
44 warn join('', map "$_: $usps_args{$_}\n", keys %usps_args )
47 my $hash = $verifier->verify_address( %usps_args );
49 warn $verifier->response
52 unless ( $verifier->is_error ) {
54 my $zip = $hash->{Zip5};
55 $zip .= '-'. $hash->{Zip4} if $hash->{Zip4} =~ /\d/;
59 "new_$pre".'company' => $hash->{FirmName},
60 "new_$pre".'address1' => $hash->{Address2},
61 "new_$pre".'address2' => $hash->{Address1},
62 "new_$pre".'city' => $hash->{City},
63 "new_$pre".'state' => $hash->{State},
64 "new_$pre".'zip' => $zip,
67 my @fields = (qw( company address1 address2 city state zip )); #hmm
70 scalar( grep { $return->{$pre.$_} ne $return->{"new_$pre$_"} }
75 $return->{$pre.'address_standardized'} = $changed;
79 $return->{$pre.'error'} = "USPS WebTools error: ".
80 $verifier->{error}{description};