Last active
August 11, 2016 21:15
-
-
Save fastdivision/6b2e16fc307170c87fd8 to your computer and use it in GitHub Desktop.
TaxJar SmartCalcs /v2/taxes with Zend HTTP Client v2.5.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use Zend\Http\Client; | |
use Zend\Json\Json; | |
$apiKey = 'YOUR API KEY'; | |
$apiUrl = 'https://api.taxjar.com/v2/taxes'; | |
$client = new Client($apiUrl); | |
$client->setMethod('POST'); | |
$client->setHeaders([ | |
'Authorization' => 'Bearer ' . $apiKey, | |
'Content-Type' => 'application/json' | |
]); | |
$data = [ | |
'to_country' => 'US', | |
'to_zip' => '92101', | |
'to_state' => 'CA', | |
'to_city' => '', | |
'to_street' => '', | |
'amount' => 99.99, | |
'shipping' => 5, | |
'line_items' => [ | |
[ | |
'id' => 135, | |
'quantity' => 1, | |
'unit_price' => 99.99, | |
'discount' => 0, | |
'product_tax_code' => '20010' | |
] | |
] | |
]; | |
$client->setRawBody(Json::encode($data)); | |
try { | |
$response = $client->send(); | |
echo $response->getBody(); | |
} catch (Exception $e) { | |
// Log exception | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment