def setUp(self): self.api_key = 'heythere' self.api_url = taxjar.DEFAULT_API_URL + "/" + taxjar.API_VERSION + "/" self.headers = {"Authorization": "Bearer heythere"} self.responder_mock = MagicMock() self.client = taxjar.Client(api_key=self.api_key, options={}, responder=self.responder_mock)
def get_client(): taxjar_settings = frappe.get_single("TaxJar Settings") if not taxjar_settings.api_key: frappe.throw(_("The TaxJar API key is missing."), frappe.AuthenticationError) api_key = taxjar_settings.get_password("api_key") return taxjar.Client(api_key=api_key)
def test_client_params(self): self.client = taxjar.Client(api_key=self.api_key, api_url='https://api.sandbox.taxjar.com', options={ 'headers': { 'X-TJ-Expected-Response': '422' } }, responder=self.responder_mock) self.assertEqual(self.client.api_url, 'https://api.sandbox.taxjar.com/v2/') self.assertEqual(self.client.headers, { 'X-TJ-Expected-Response': '422' })
def setUp(self): self.api_key = 'heythere' self.api_url = taxjar.API_URL self.headers = { "Authorization": "Bearer heythere", "User-Agent": "TaxJarPython/1.0.0" } self.responder_mock = MagicMock() self.client = taxjar.Client(self.api_key, {}, self.responder_mock)
def get_client(): taxjar_settings = frappe.get_single("TaxJar Settings") if not taxjar_settings.is_sandbox: api_key = taxjar_settings.get_password("api_key") api_url = taxjar.DEFAULT_API_URL else: api_key = taxjar_settings.get_password("sandbox_api_key") api_url = taxjar.SANDBOX_API_URL if api_key and api_url: return taxjar.Client(api_key=api_key, api_url=api_url)
def get_tax_data(doc): from shipment_management.utils import get_state_code taxjar_settings = frappe.get_single("TaxJar Settings") client = get_client() if not (taxjar_settings.api_key or taxjar_settings.tax_account_head): return client = taxjar.Client(api_key=taxjar_settings.get_password("api_key")) company_address = frappe.get_doc("Address", {"is_your_company_address": 1}) if company_address and doc.shipping_address_name: shipping_address = frappe.get_doc("Address", doc.shipping_address_name) else: return if not shipping_address.country == "United States": return shipping = 0 for tax in doc.taxes: if tax.account_head == "Freight and Forwarding Charges - JA": shipping = tax.tax_amount tax_dict = { 'to_country': 'US', 'to_zip': shipping_address.pincode, 'to_city': shipping_address.city, 'to_state': get_state_code(shipping_address), 'shipping': shipping, 'line_items': [] } index = 1 for item in doc.items: tax_dict["line_items"].append({ "id": index, "description": item.item_name[:255], "unit_price": item.price_list_rate, "quantity": item.qty, "discount": (item.discount_percentage / 100) * item.price_list_rate * item.qty }) index = index + 1 return tax_dict
def get_client(): taxjar_settings = frappe.get_single("TaxJar Settings") if not taxjar_settings.is_sandbox: api_key = taxjar_settings.api_key and taxjar_settings.get_password( "api_key") api_url = taxjar.DEFAULT_API_URL else: api_key = taxjar_settings.sandbox_api_key and taxjar_settings.get_password( "sandbox_api_key") api_url = taxjar.SANDBOX_API_URL if api_key and api_url: client = taxjar.Client(api_key=api_key, api_url=api_url) client.set_api_config("headers", {"x-api-version": "2022-01-24"}) return client
def get_client(): if not TAXJAR_ENABLED: return taxjar_settings = frappe.get_single("TaxJar Settings") if not taxjar_settings.is_sandbox: api_key = taxjar_settings.get_password("api_key") api_url = taxjar.DEFAULT_API_URL else: api_key = taxjar_settings.get_password("sandbox_api_key") api_url = taxjar.SANDBOX_API_URL if api_key and api_url: client = taxjar.Client(api_key=api_key, api_url=api_url) client.set_api_config('headers', {'x-api-version': '2020-08-07'}) return client
def get_tax_data(doc): from shipment_management.utils import get_state_code taxjar_settings = frappe.get_single("TaxJar Settings") client = get_client() if not (taxjar_settings.api_key or taxjar_settings.tax_account_head): return api_key = frappe.get_doc("TaxJar Settings", "TaxJar Settings").get_password("api_key") client = taxjar.Client(api_key=api_key) company_address = frappe.get_list("Dynamic Link", filters={"link_doctype": "Company"}, fields=["parent"])[0] company_address = frappe.get_doc("Address", company_address.parent) if company_address and not doc.shipping_address_name: shipping_address = company_address elif company_address and doc.shipping_address_name: shipping_address = frappe.get_doc("Address", doc.shipping_address_name) else: return if not shipping_address.country == "United States": return shipping = 0 for tax in doc.taxes: if tax.account_head == "Freight and Forwarding Charges - JA": shipping = tax.tax_amount tax_dict = { 'to_country': 'US', 'to_zip': shipping_address.pincode, 'to_city': shipping_address.city, 'to_state': get_state_code(shipping_address), 'shipping': shipping, 'amount': doc.net_total } return tax_dict
Language_Understanding_Service_Endpoint = 'https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/' App_Key = 'YOUR_APP_KEY' LUIS_Api_Key = 'YOUR_API_KEY' INTENT_NONE = 'None' INTENT_GREETING = 'Greeting' INTENT_CHECK_WEATHER = 'CheckWeather' INTENT_CHECK_TAX_RATE = 'CheckTaxRate' Google_Api_Endpoint = 'https://maps.googleapis.com/maps/api/geocode/json?address=' Google_Api_Key = 'YOUR_API_KEY' DarkSky_Api_Endpoint = 'https://api.darksky.net/forecast/' DarkSky_Secret_Key = 'YOUR_API_KEY' TaxJar_Api_Key = 'YOUR_API_KEY' client = taxjar.Client(api_key=TaxJar_Api_Key) def location_api_call(address): return Google_Api_Endpoint + address + '&key=' + Google_Api_Key def weather_api_call(lat, lng): return DarkSky_Api_Endpoint + DarkSky_Secret_Key + '/' + str( lat) + ',' + str(lng) # + ',' + time # "2018-11-02T00:00:00" def language_understanding_api_call(q): return Language_Understanding_Service_Endpoint + App_Key + '?timezoneOffset=-360&subscription-key=' + LUIS_Api_Key + '&q=' + q
def __init__(self, connector_env): super(TaxjarAdapter, self).__init__(connector_env) self.taxjar = taxjar.Client(api_key=self.backend_record.api_key)
Case( When( chatentry__poster__id__ne=user.id, chatentry__read=0, then=1 ) ) ) ) return purchases import json import taxjar from django.conf import settings client = taxjar.Client(api_key=settings.TAXJAR_KEY) def get_order_tax(fromObj, toObj, productID, productPrice): order = { 'from_country': fromObj['country'], 'to_country': toObj['country'], 'to_city': toObj['city'], 'to_street': toObj['street'], 'shipping': 0, 'line_items': [ { 'id': productID, 'quantity': 1, 'product_tax_code': 31000, 'unit_price': int(productPrice), 'discount': 0
def get_client(): taxjar_settings = frappe.get_single("TaxJar Settings") client = taxjar.Client(api_key=taxjar_settings.get_password("api_key")) return client
def getTax(zipcode): taxClient = taxjar.Client(api_key=tax_api_key) return taxClient.rates_for_location(zipcode).city_rate
def __init__(self, api_url, api_token): self.taxjar = taxjar.Client(api_token, api_url)
def get_client(): api_key = frappe.get_doc("TaxJar Settings", "TaxJar Settings").get_password("api_key") client = taxjar.Client(api_key=api_key) return client
import taxjar as jar client = jar.Client(api_key='36e5eb69d62562d468b07da2ef8252e4') class TaxProfile: def __init__(self, state, city, zip_code): self.zip_code = zip_code self.state = state self.city = city def get_rate(self): rates = client.rates_for_location(self.zip_code, { 'city': self.city, 'state': self.state }) return rates def print_profile(self): rates = self.get_rate() print( "User is from {0}, {1} their zip code is {2} and their tax rate is %{3}" .format(self.city, self.state, self.zip_code, rates.combined_rate))