Created
January 11, 2024 17:43
-
-
Save twosdai/558f8f3f0456dea9b1b6c42807a417ff to your computer and use it in GitHub Desktop.
TaxJar Testing
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
// Below is our basic function call implementation Treat this as Psudeo Code | |
// npm init -y | |
// npm i taxjar --save | |
const TaxJar = require("taxjar"); | |
const taxjarClient = new TaxJar({ | |
apiKey: "FILLMEIN", | |
apiUrl: "https://api.sandbox.taxjar.com", | |
}); | |
const calculateSalesTax = async () => { | |
try { | |
const taxInfo = await taxjarClient.taxForOrder({ | |
from_country: "US", | |
from_zip: "94560", | |
from_state: "CA", | |
from_city: "NEWARK", | |
from_street: "8565 Peachtree Ave", | |
to_country: "US", | |
to_zip: "94111", | |
to_state: "CA", | |
to_city: "SAN FRANCISCO", | |
to_street: "2 Embarcadero Center", | |
shipping: 0, | |
line_items: [ | |
{ quantity: 1, unit_price: 15.0, product_tax_code: "81162000A9000" }, | |
], | |
}); | |
const { rate, amount_to_collect: amountToCollect } = taxInfo.tax; | |
console.log(rate, amountToCollect, "Rate and amount to collect"); // 0 0 Rate and amount to collect | |
//Testing FROM address missing | |
const taxInfo2 = await taxjarClient.taxForOrder({ | |
from_country: "US", | |
to_country: "US", | |
to_zip: "94111", | |
to_state: "CA", | |
to_city: "SAN FRANCISCO", | |
to_street: "2 Embarcadero Center", | |
shipping: 0, | |
line_items: [ | |
{ quantity: 1, unit_price: 15.0, product_tax_code: "81162000A9000" }, | |
], | |
}); | |
const { rate2, amount_to_collect: amountToCollect2 } = taxInfo2.tax; | |
console.log(rate2, amountToCollect2, "Rate2 and amount to collect2"); // 0 0 Rate and amount to collect | |
return { rate, amountToCollect }; | |
} catch (error) { | |
console.log(error, "Error occured"); | |
} | |
}; | |
calculateSalesTax() | |
.then((res) => console.log(res)) | |
.catch((err) => console.log(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment