-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.bison_tax_zip.php
44 lines (32 loc) · 1 KB
/
core.bison_tax_zip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
class Core_bison_tax_zip extends Core
{
public function getZip()
{
$customer = $this->addon->api('bison')->getCustomerInfo();
$zip = array_get($customer, 'billing_zip');
return ($zip == '') ? null : $zip;
}
public function getState()
{
$customer = $this->addon->api('bison')->getCustomerInfo();
$state = array_get($customer, 'billing_state');
return ($state == '') ? null : $state;
}
public function getTaxableStates()
{
return array_get($this->addon->api('bison')->getBisonConfig(), 'taxable_states');
}
public function getRateFromAPI($zip)
{
$api_key = $this->config['api_key'];
$query = http_build_query(array(
'country' => 'usa',
'postal' => $zip,
'apikey' => $api_key
));
$url = 'https://taxrates.api.avalara.com/postal?' . $query;
$response = json_decode(file_get_contents($url));
return $response->totalRate;
}
}