Skip to content

Instantly share code, notes, and snippets.

@fastdivision
Last active August 11, 2016 21:15
Show Gist options
  • Select an option

  • Save fastdivision/6b2e16fc307170c87fd8 to your computer and use it in GitHub Desktop.

Select an option

Save fastdivision/6b2e16fc307170c87fd8 to your computer and use it in GitHub Desktop.

Revisions

  1. fastdivision revised this gist Aug 11, 2016. 1 changed file with 13 additions and 11 deletions.
    24 changes: 13 additions & 11 deletions smartcalcs-zend-http-demo.php
    Original file line number Diff line number Diff line change
    @@ -9,33 +9,35 @@

    $client = new Client($apiUrl);
    $client->setMethod('POST');
    $client->setHeaders([ 'Authorization' => 'Bearer ' . $apiKey, 'Content-Type' => 'application/json' ]);
    $client->setHeaders([
    'Authorization' => 'Bearer ' . $apiKey,
    'Content-Type' => 'application/json'
    ]);

    $data = array (
    $data = [
    'to_country' => 'US',
    'to_zip' => '92101',
    'to_state' => 'CA',
    'to_city' => '',
    'to_street' => '',
    'amount' => 99.99,
    'shipping' => 5,
    'line_items' => array(
    array(
    '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;

    } catch (Exception $l_oException) {
    //log exception;
    echo $response->getBody();
    } catch (Exception $e) {
    // Log exception
    }
  2. Jake Johnson renamed this gist Nov 24, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Jake Johnson created this gist Nov 24, 2015.
    41 changes: 41 additions & 0 deletions demo.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <?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 = array (
    'to_country' => 'US',
    'to_zip' => '92101',
    'to_state' => 'CA',
    'to_city' => '',
    'to_street' => '',
    'amount' => 99.99,
    'shipping' => 5,
    'line_items' => array(
    array(
    '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;

    } catch (Exception $l_oException) {
    //log exception;
    }