### Show Customer Response Example (Go) Source: https://developers.taxjar.com/api/reference?php= Example of the customer object returned by the API in Go. ```go taxjar.ShowCustomerResponse{ Customer: taxjar.Customer{ CustomerID: "123", ExemptionType: "wholesale", ExemptRegions: []taxjar.ExemptRegion{ { Country: "US", State: "FL", }, { Country: "US", State: "PA", }, }, Name: "Dunder Mifflin Paper Company", Country: "US", State: "PA", Zip: "18504", City: "Scranton", Street: "1725 Slough Avenue", }, } ``` -------------------------------- ### Show Customer Response Example (Ruby) Source: https://developers.taxjar.com/api/reference?php= Example of the customer object returned by the API in Ruby. ```ruby # "123", :exemption_type => "wholesale", :exempt_regions => [ [0] { :country => "US", :state => "FL" }, [1] { :country => "US", :state => "PA" } ], :name => "Dunder Mifflin Paper Company", :country => "US", :state => "PA", :zip => "18504", :city => "Scranton", :street => "1725 Slough Avenue" }> ``` -------------------------------- ### Show Customer Response Example (Python) Source: https://developers.taxjar.com/api/reference?php= Example of the customer object returned by the API in Python. ```python , ], 'name': 'Dunder Mifflin Paper Company', 'country': 'US', 'state': 'PA', 'zip': '18504', 'city': 'Scranton', 'street': '1725 Slough Avenue' }> ``` -------------------------------- ### Show Customer Request Example (Go) Source: https://developers.taxjar.com/api/reference?php= Demonstrates how to initialize the TaxJar client and retrieve a customer by ID in Go. ```go package main import ( "fmt" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: "9e0cd62a22f451701f29c3bde214", }) res, err := client.ShowCustomer("123") if err != nil { fmt.Println(err) } else { fmt.Println(res.Customer) } } ``` -------------------------------- ### TaxJar API GET Request for Customer Source: https://developers.taxjar.com/api/reference?csharp= Example of making a GET request to the TaxJar API to retrieve a specific customer by their ID. ```bash GET https://api.taxjar.com/v2/customers/:customer_id ``` ```bash $ curl https://api.taxjar.com/v2/customers/123 \ -H "Authorization: Bearer 9e0cd62a22f451701f29c3bde214" ``` -------------------------------- ### Fetch Categories from Sandbox API Source: https://developers.taxjar.com/api/reference Example of making a GET request to the categories endpoint in the sandbox environment using curl. ```bash $ curl https://api.sandbox.taxjar.com/v2/categories \ -H "Authorization: Bearer 9e0cd62a22f451701f29c3bde214" ``` -------------------------------- ### Create Customer (Go) Source: https://developers.taxjar.com/api/reference?java= Example of creating a customer using the Go SDK. This snippet shows how to construct the customer object and handle the response. ```Go package main import ( "fmt" "github.com/TaxJar/taxjar-go" ) func main() { res, err := taxjar.CreateCustomer(&taxjar.Customer{ CustomerID: "123", ExemptionType: "wholesale", Name: "Dunder Mifflin Paper Company", ExemptRegions: []taxjar.ExemptRegion{ { Country: "US", State: "FL", }, { Country: "US", State: "PA", }, }, Country: "US", State: "PA", Zip: "18504", City: "Scranton", Street: "1725 Slough Avenue", }) if err != nil { fmt.Println(err) } else { fmt.Println(res.Customer) } } ``` -------------------------------- ### Go Authentication Example Source: https://developers.taxjar.com/api/reference?php= Initialize the TaxJar client with your API key in Go. ```go package main import "github.com/taxjar/taxjar-go" func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: "9e0cd62a22f451701f29c3bde214", }) } ``` -------------------------------- ### List Customers API Request (cURL) Source: https://developers.taxjar.com/api/reference?php= Example of how to make a GET request to the TaxJar API to list customers using cURL. ```bash $ curl https://api.taxjar.com/v2/customers \ -H "Authorization: Bearer 9e0cd62a22f451701f29c3bde214" ``` -------------------------------- ### Show Customer Request Example (Ruby) Source: https://developers.taxjar.com/api/reference?php= Demonstrates how to initialize the TaxJar client and retrieve a customer by ID in Ruby. ```ruby require "taxjar" client = Taxjar::Client.new(api_key: "9e0cd62a22f451701f29c3bde214") customer = client.show_customer('123') ``` -------------------------------- ### Get Sales Tax Rates by Location (Java) Source: https://developers.taxjar.com/api/reference Example of using the Taxjar Java client to get sales tax rates. Includes fetching rates by ZIP+4 and with optional parameters for street, city, state, and country to ensure rooftop accuracy. ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.rates.RateResponse; import java.util.HashMap; import java.util.Map; public class RatesExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); try { RateResponse res = client.ratesForLocation("90404-3370"); Map params = new HashMap<>(); params.put("city", "Santa Monica"); params.put("state", "CA"); params.put("country", "US"); RateResponse res = client.ratesForLocation("90404", params); Map params = new HashMap<>(); params.put("street", "312 Hurricane Lane"); params.put("city", "Williston"); params.put("state", "VT"); params.put("country", "US"); RateResponse res = client.ratesForLocation("05495-2086", params); } catch (TaxjarException e) { e.printStackTrace(); } } } ``` -------------------------------- ### Get Rates by ZIP+4 (Ruby) Source: https://developers.taxjar.com/api/reference?go= Retrieves sales tax rates for a US location using a ZIP+4 code. This is a basic usage example. ```ruby # United States (ZIP+4) rates = client.rates_for_location('90404-3370') ``` -------------------------------- ### Show Customer Request Example (C#) Source: https://developers.taxjar.com/api/reference?php= Demonstrates how to initialize the TaxJar client and retrieve a customer by ID in C#. ```csharp using Taxjar; var client = new TaxjarApi("9e0cd62a22f451701f29c3bde214"); var customer = client.ShowCustomer("123"); ``` -------------------------------- ### Validate Zip-Only Address in PHP Source: https://developers.taxjar.com/api Validates an address using only the zip code in PHP. This example assumes you have the TaxJar SDK installed via Composer. ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); $addresses = $client->validateAddress([ 'zip' => '98122' ]); ``` -------------------------------- ### Show Customer Request Example (Python) Source: https://developers.taxjar.com/api/reference?php= Demonstrates how to initialize the TaxJar client and retrieve a customer by ID in Python. ```python import taxjar client = taxjar.Client(api_key='9e0cd62a22f451701f29c3bde214') customer = client.show_customer('123') ``` -------------------------------- ### Node.js: Create Customer Source: https://developers.taxjar.com/api This Node.js example shows how to create a customer with the TaxJar client. Ensure the taxjar package is installed and configured with your API key. ```javascript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '9e0cd62a22f451701f29c3bde214' }); client.createCustomer({ customer_id: '123', exemption_type: 'wholesale', name: 'Dunder Mifflin Paper Company', exempt_regions: [ { country: 'US', state: 'FL' }, { country: 'US', state: 'PA' } ], country: 'US', state: 'PA', zip: '18504', city: 'Scranton', street: '1725 Slough Avenue' }).then(res => { res.customer; }); ``` -------------------------------- ### Create Order Request Examples Source: https://developers.taxjar.com/api Examples of how to structure an order creation request using various language SDKs. ```ruby require "taxjar" client = Taxjar::Client.new(api_key: "9e0cd62a22f451701f29c3bde214") order = client.create_order({ :transaction_id => '123', :transaction_date => '2015/05/14', :to_country => 'US', :to_zip => '90002', :to_state => 'CA', :to_city => 'Los Angeles', :to_street => '123 Palm Grove Ln', :amount => 16.5, :shipping => 1.5, :sales_tax => 0.95, :line_items => [ { :quantity => 1, :product_identifier => '12-34243-9', :description => 'Fuzzy Widget', :unit_price => 15, :sales_tax => 0.95 } ] }) ``` ```python import taxjar client = taxjar.Client(api_key='9e0cd62a22f451701f29c3bde214') order = client.create_order({ 'transaction_id': '123', 'transaction_date': '2015/05/14', 'to_country': 'US', 'to_zip': '90002', 'to_state': 'CA', 'to_city': 'Los Angeles', 'to_street': '123 Palm Grove Ln', 'amount': 16.5, 'shipping': 1.5, 'sales_tax': 0.95, 'line_items': [ { 'quantity': 1, 'product_identifier': '12-34243-9', 'description': 'Fuzzy Widget', 'unit_price': 15, 'sales_tax': 0.95 } ] }) ``` ```javascript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '9e0cd62a22f451701f29c3bde214' }); client.createOrder({ transaction_id: '123', transaction_date: '2015/05/14', to_country: 'US', to_zip: '90002', to_state: 'CA', to_city: 'Los Angeles', to_street: '123 Palm Grove Ln', amount: 16.5, shipping: 1.5, sales_tax: 0.95, line_items: [ { quantity: 1, product_identifier: '12-34243-9', description: 'Fuzzy Widget', unit_price: 15, sales_tax: 0.95 } ] }).then(res => { res.order; // Order object }); ``` ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); $order = $client->createOrder([ 'transaction_id' => '123', 'transaction_date' => '2015/05/14', 'to_country' => 'US', 'to_zip' => '90002', 'to_state' => 'CA', 'to_city' => 'Los Angeles', 'to_street' => '123 Palm Grove Ln', 'amount' => 16.5, 'shipping' => 1.5, 'sales_tax' => 0.95, 'line_items' => [ [ 'quantity' => 1, 'product_identifier' => '12-34243-9', 'description' => 'Fuzzy Widget', 'unit_price' => 15, 'sales_tax' => 0.95 ] ] ]); ``` ```csharp using Taxjar; var client = new TaxjarApi("9e0cd62a22f451701f29c3bde214"); var order = client.CreateOrder(new { transaction_id = "123", transaction_date = "2015/05/04", to_country = "US", to_state = "CA", to_zip = "90002", to_city = "Los Angeles", to_street = "123 Palm Grove Ln", amount = 16.5, shipping = 1.5, sales_tax = 0.95, line_items = new[] { new { quantity = 1, product_identifier = "12-34243-0", description = "Heavy Widget", unit_price = 15, sales_tax = 0.95 } } }); ``` ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.transactions.OrderResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class CreateOrderExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); try { Map params = new HashMap<>(); params.put("transaction_id", "123"); params.put("transaction_date", "2015/05/04"); params.put("to_country", "US"); params.put("to_zip", "90002"); params.put("to_city", "Los Angeles"); params.put("to_street", "123 Palm Grove Ln"); params.put("amount", 16.5); params.put("shipping", 1.5); params.put("sales_tax", 0.95); List lineItems = new ArrayList(); Map lineItem = new HashMap<>(); lineItem.put("quantity", 1); lineItem.put("product_identifier", "12-34243-0"); lineItem.put("description", "Heavy Widget"); lineItem.put("unit_price", 15); lineItem.put("sales_tax", 0.95); lineItems.add(lineItem); params.put("line_items", lineItems); OrderResponse res = client.createOrder(params); } catch (TaxjarException e) { e.printStackTrace(); } } } ``` ```go package main import ( "fmt" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: "9e0cd62a22f451701f29c3bde214", }) ``` -------------------------------- ### Test TLS 1.2 Support in Node.js Source: https://developers.taxjar.com/api/guides?javascript= This Node.js example checks for TLS 1.2 compatibility with the TaxJar API. Ensure the 'taxjar' package is installed. ```javascript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '[YOUR TAXJAR TOKEN]' }); client.categories().then(() => { console.log('TLS 1.2 supported, no upgrade required'); }).catch(e => { if (e.error && e.error.code === 'ECONNRESET') { console.log('TLS 1.2 not supported, you will need to upgrade'); } else { console.log('Unknown error from TaxJar, please try again'); } }); ``` -------------------------------- ### Show Customer Request Example (Node.js) Source: https://developers.taxjar.com/api/reference?php= Demonstrates how to initialize the TaxJar client and retrieve a customer by ID in Node.js. ```javascript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '9e0cd62a22f451701f29c3bde214' }); client.showCustomer('123').then(res => { res.customer; }); ``` -------------------------------- ### List Orders - Node.js Source: https://developers.taxjar.com/api/reference?php= Use this Node.js example to fetch order transactions. It utilizes promises for handling asynchronous responses. Make sure to install the 'taxjar' package. ```JavaScript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '9e0cd62a22f451701f29c3bde214' }); client.listOrders({ from_transaction_date: '2015/05/01', to_transaction_date: '2015/05/31' }).then(res => { res.orders; // Array of orders }); ``` -------------------------------- ### Delete Order Transaction using Node.js Source: https://developers.taxjar.com/api/reference Example of deleting an order transaction using the Taxjar Node.js client. Ensure the package is installed and configured with your API key. ```javascript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '9e0cd62a22f451701f29c3bde214' }); client.deleteOrder('123').then(res => { res.order; // Order object }); ``` -------------------------------- ### C# / .NET Authentication Example Source: https://developers.taxjar.com/api/reference?php= Initialize the TaxJar client with your API key in C#. ```csharp using Taxjar; var client = new TaxjarApi("9e0cd62a22f451701f29c3bde214"); ``` -------------------------------- ### Delete Order Transaction using Python Source: https://developers.taxjar.com/api/reference Example of deleting an order transaction using the Taxjar Python client. Ensure the library is installed and configured with your API key. ```python import taxjar client = taxjar.Client(api_key='9e0cd62a22f451701f29c3bde214') client.delete_order('123') ``` -------------------------------- ### Ruby Authentication Example Source: https://developers.taxjar.com/api/reference?php= Initialize the TaxJar client with your API key in Ruby. ```ruby require "taxjar" client = Taxjar::Client.new(api_key: "9e0cd62a22f451701f29c3bde214") ``` -------------------------------- ### Delete Order Transaction using Ruby Source: https://developers.taxjar.com/api/reference Example of deleting an order transaction using the Taxjar Ruby client. Ensure the gem is installed and configured with your API key. ```ruby require "taxjar" client = Taxjar::Client.new(api_key: "9e0cd62a22f451701f29c3bde214") client.delete_order('123') ``` -------------------------------- ### Python Authentication Example Source: https://developers.taxjar.com/api/reference?php= Initialize the TaxJar client with your API key in Python. ```python import taxjar client = taxjar.Client(api_key='9e0cd62a22f451701f29c3bde214') ``` -------------------------------- ### Initialize TaxJar Client in Sandbox (Go) Source: https://developers.taxjar.com/api Configure the TaxJar Go client for the sandbox environment using environment variables for the API key and the sandbox API URL. ```go package main import ( "os" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: os.Getenv("TAXJAR_SANDBOX_API_KEY"), APIURL: taxjar.SandboxAPIURL, }) } ``` -------------------------------- ### Get Sales Tax Rates by ZIP+4 (Shell) Source: https://developers.taxjar.com/api/reference?java= Retrieve sales tax rates for a US ZIP+4 code using a curl command. This example does not include optional parameters. ```Shell # United States (ZIP+4) curl https://api.taxjar.com/v2/rates/90404-3370 \ -H "Authorization: Bearer 9e0cd62a22f451701f29c3bde214" ``` -------------------------------- ### Show Refund Transaction (PHP) Source: https://developers.taxjar.com/api Get a refund transaction using the `showRefund` method. This example assumes you have autoloading set up via Composer. The client is initialized with an API key. ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); $refund = $client->showRefund('321'); ``` -------------------------------- ### Response Example - Go Struct Source: https://developers.taxjar.com/api/reference Example of a Go struct representing the response for listing orders. ```go taxjar.ListOrdersResponse{ Orders: []string{"20", "21", "22"} } ``` -------------------------------- ### Get List Tax Categories (Java) Source: https://developers.taxjar.com/api/reference?node= This Java example demonstrates how to fetch tax categories using the Taxjar Java SDK. It includes basic error handling for Taxjar exceptions. ```java using Taxjar; var client = new TaxjarApi("9e0cd62a22f451701f29c3bde214"); var categories = client.Categories(); ``` ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.categories.CategoryResponse; public class CategoryExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); try { CategoryResponse res = client.categories(); } catch (TaxjarException e) { e.printStackTrace(); } } } ``` -------------------------------- ### Java: Create Customer Source: https://developers.taxjar.com/api This Java example demonstrates creating a customer with the TaxJar client. Ensure the Taxjar library is included and the client is initialized with your API key. ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.customers.CustomerResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class CreateCustomerExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); try { Map params = new HashMap<>(); params.put("customer_id", "123"); params.put("exemption_type", "wholesale"); params.put("name", "Dunder Mifflin Paper Company"); params.put("country", "US"); params.put("state", "PA"); params.put("zip", "18504"); params.put("city", "Scranton"); params.put("street", "1725 Slough Avenue"); List exemptRegions = new ArrayList(); Map exemptRegion = new HashMap<>(); exemptRegion.put("country", "US"); exemptRegion.put("state", "FL"); Map exemptRegion2 = new HashMap<>(); exemptRegion2.put("country", "US"); exemptRegion2.put("state", "PA"); exemptRegions.add(exemptRegion); exemptRegions.add(exemptRegion2); params.put("exempt_regions", exemptRegions); CustomerResponse res = client.createCustomer(params); } catch (TaxjarException e) { e.printStackTrace(); } } } ``` -------------------------------- ### Java Authentication Example Source: https://developers.taxjar.com/api/reference?php= Initialize the TaxJar client with your API key in Java. ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; public class AuthenticationExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); } } ``` -------------------------------- ### Get Summarized Sales Tax Rates (Ruby) Source: https://developers.taxjar.com/blog/summarized-tax-rates-and-vat-validation Use the Ruby client to fetch summarized sales tax rates. Ensure you have the Taxjar gem installed and provide your API key. ```ruby require "taxjar" client = Taxjar::Client.new(api_key: "9e0cd62a22f451701f29c3bde214") summarized_rates = client.summary_rates ``` -------------------------------- ### PHP Authentication Example Source: https://developers.taxjar.com/api/reference?php= Initialize the TaxJar client with your API key in PHP. ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); ``` -------------------------------- ### List Refund Transactions (HTTP Request) Source: https://developers.taxjar.com/api/reference?node= This example shows how to list refund transactions using an HTTP GET request. It includes the necessary authorization header and query parameters for a date range. ```http GET https://api.taxjar.com/v2/transactions/refunds -H "Authorization: Bearer 9e0cd62a22f451701f29c3bde214" -d from_transaction_date="2015/05/01" -d to_transaction_date="2015/05/31" ``` -------------------------------- ### Calculate and Collect Sales Tax for an Order Source: https://developers.taxjar.com/blog/handling-sales-tax-with-laravel-cashier Use TaxJar's API to get tax details for an order, including the amount to collect. This example demonstrates fetching tax information for a specific transaction. ```php taxForOrder([ 'from_country' => 'US', 'from_zip' => '92093', 'from_state' => 'CA', 'from_city' => 'La Jolla', 'from_street' => '9500 Gilman Drive', 'to_country' => 'US', 'to_zip' => '90002', 'to_state' => 'CA', 'to_city' => 'Los Angeles', 'to_street' => '1335 E 103rd St', 'amount' => 100, 'shipping' => 0, 'nexus_addresses' => [ [ 'id' => 'Main Location', 'country' => 'US', 'zip' => '92093', 'state' => 'CA', 'city' => 'La Jolla', 'street' => '9500 Gilman Drive', ] ], 'line_items' => [ [ 'id' => '1', 'quantity' => 1, 'product_tax_code' => '30070', 'unit_price' => 100, 'discount' => 0 ] ] ]); ?> // Charge the user $100.00 (subtotal) + $8.00 (tax) $subtotal = 10000; $taxAmount = $tax->amount_to_collect * 100; $taxPercent = $tax->rate * 100; $total = $subtotal + $taxAmount; $user->charge($total); } catch (Exception $e) { // Log error } ```