diff options
author | Ivan Kohler <ivan@freeside.biz> | 2016-03-26 12:51:54 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2016-03-26 12:51:54 -0700 |
commit | 2df25d1d8a79a775f715f36c8ded11665a944a25 (patch) | |
tree | 7c6e3f31b7c327a084cdb3117a14ab9f0fc0a925 /FS/FS/Misc | |
parent | 8bf7866ff8b83f34a5e3b328ba233c2a0dbe6967 (diff) |
freeside inc. web services for address normalizaion and printing, RT#33849
Diffstat (limited to 'FS/FS/Misc')
-rw-r--r-- | FS/FS/Misc/Geo.pm | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm index aa4e55e..73122fa 100644 --- a/FS/FS/Misc/Geo.pm +++ b/FS/FS/Misc/Geo.pm @@ -642,6 +642,42 @@ sub standardize_melissa { } } +sub standardize_freeside { + my $class = shift; + my $location = shift; + + my $url = 'https://ws.freeside.biz/normalize'; + + #free freeside.biz normalization only for US + if ( $location->{country} ne 'US' ) { + # soft failure + #why? something else could have cleaned it $location->{addr_clean} = ''; + return $location; + } + + my $ua = LWP::UserAgent->new( 'ssl_opts' => { 'verify_hostname'=>0 }); + my $response = $ua->request( POST $url, [ + 'support-key' => scalar($conf->config('support-key')), + %$location, + ]); + + die "Address normalization error: ". $response->message + unless $response->is_success; + + local $@; + my $content = eval { decode_json($response->content) }; + die "Address normalization JSON error : $@\n" if $@; + + die $content->{error}."\n" + if $content->{error}; + + { 'addr_clean' => 'Y', + map { $_ => $content->{$_} } + qw( address1 address2 city state zip country ) + }; + +} + =back =cut |