Compare commits
1 Commits
5baf105394
...
b91ddb6685
| Author | SHA1 | Date | |
|---|---|---|---|
| b91ddb6685 |
@ -10,6 +10,9 @@ from python_ifirma.helpers import Helpers
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
from urllib.parse import urljoin, quote
|
||||||
|
|
||||||
|
|
||||||
class VAT:
|
class VAT:
|
||||||
VAT_0 = 0.00
|
VAT_0 = 0.00
|
||||||
VAT_5 = 0.05
|
VAT_5 = 0.05
|
||||||
@ -165,6 +168,8 @@ class NewInvoiceParams:
|
|||||||
|
|
||||||
|
|
||||||
class iFirmaAPI():
|
class iFirmaAPI():
|
||||||
|
__base_url = "https://www.ifirma.pl/iapi/"
|
||||||
|
|
||||||
__username = None
|
__username = None
|
||||||
__invoice_key_name = 'faktura'
|
__invoice_key_name = 'faktura'
|
||||||
__invoice_key_value = None
|
__invoice_key_value = None
|
||||||
@ -203,10 +208,30 @@ class iFirmaAPI():
|
|||||||
Helpers.get_hmac_of_text(key_value, request_hash_text)
|
Helpers.get_hmac_of_text(key_value, request_hash_text)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __get(self, url_path, key_name, key_value="", params={}):
|
||||||
|
"""Send GET request to IFirma API"""
|
||||||
|
|
||||||
|
url = urljoin(self.__base_url, url_path)
|
||||||
|
request_hash_text = f"{url}{self.__username}{key_name}"
|
||||||
|
headers = {
|
||||||
|
# Content-type not needed in GET requests
|
||||||
|
# "Content-type": "application/json; charset=UTF-8",
|
||||||
|
"Accept": "application/json",
|
||||||
|
"Authentication": self.__get_auth_header(request_hash_text,
|
||||||
|
key_value=key_value)
|
||||||
|
}
|
||||||
|
response = requests.get(url, headers=headers, params=params)
|
||||||
|
return json.loads(response.content.decode('utf-8'))
|
||||||
|
|
||||||
|
def find_partner(self, keyword):
|
||||||
|
return self.__get(f"kontrahenci/{quote(keyword)}.json",
|
||||||
|
self.__invoice_key_name)
|
||||||
|
|
||||||
def __create_invoice_and_return_id(self, invoice, url):
|
def __create_invoice_and_return_id(self, invoice, url):
|
||||||
# from pprint import pprint
|
# from pprint import pprint
|
||||||
# pprint(invoice.get_request_data())
|
# pprint(invoice.get_request_data())
|
||||||
request_content = json.dumps(invoice.get_request_data(), separators=(',', ':'))
|
request_content = json.dumps(invoice.get_request_data(),
|
||||||
|
separators=(',', ':'))
|
||||||
request_hash_text = "{}{}{}{}".format(
|
request_hash_text = "{}{}{}{}".format(
|
||||||
url,
|
url,
|
||||||
self.__username,
|
self.__username,
|
||||||
@ -216,7 +241,8 @@ class iFirmaAPI():
|
|||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
"Content-type": "application/json; charset=UTF-8",
|
||||||
"Authentication": self.__get_auth_header(request_hash_text)
|
"Authentication": self.__get_auth_header(request_hash_text,
|
||||||
|
key_value=__user_key_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
response_dict = self.__execute_post_request(headers, request_content, url)
|
response_dict = self.__execute_post_request(headers, request_content, url)
|
||||||
@ -244,43 +270,14 @@ class iFirmaAPI():
|
|||||||
self.__post_cost(cost_json, url)
|
self.__post_cost(cost_json, url)
|
||||||
|
|
||||||
def get_accounting_month(self):
|
def get_accounting_month(self):
|
||||||
url = 'https://www.ifirma.pl/iapi/abonent/miesiacksiegowy.json'
|
response = self.__get("abonent/miesiacksiegowy.json",
|
||||||
request_hash_text = "{}{}{}".format(
|
|
||||||
url,
|
|
||||||
self.__username,
|
|
||||||
self.__user_key_name,
|
self.__user_key_name,
|
||||||
)
|
key_value=self.__user_key_value)
|
||||||
headers = {
|
|
||||||
"Accept": "application/json",
|
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
"Authentication":
|
|
||||||
self.__get_auth_header(request_hash_text, self.__user_key_value)
|
|
||||||
}
|
|
||||||
response = requests.get(url, headers=headers)
|
|
||||||
resp = json.loads(response.content.decode("utf-8"))
|
|
||||||
|
|
||||||
month = resp['response']["MiesiacKsiegowy"]
|
month = response['response']["MiesiacKsiegowy"]
|
||||||
year = resp['response']['RokKsiegowy']
|
year = response['response']['RokKsiegowy']
|
||||||
return year, month
|
return year, month
|
||||||
|
|
||||||
def list_invoices(self, date_from="", date_to=""):
|
|
||||||
url = f"https://www.ifirma.pl/iapi/faktury.json?dataOd={date_from}&dataDo={date_to}"
|
|
||||||
request_hash_text = "{}{}{}".format(
|
|
||||||
url.split('?')[0],
|
|
||||||
self.__username,
|
|
||||||
self.__invoice_key_name,
|
|
||||||
)
|
|
||||||
headers = {
|
|
||||||
"Accept": "application/json",
|
|
||||||
"Content-type": "application/json; charset=UTF-8",
|
|
||||||
"Authentication":
|
|
||||||
self.__get_auth_header(request_hash_text)
|
|
||||||
}
|
|
||||||
response = requests.get(url, headers=headers)
|
|
||||||
resp = json.loads(response.content.decode("utf-8"))
|
|
||||||
|
|
||||||
return resp
|
|
||||||
|
|
||||||
def __post_cost(self, cost_json, url):
|
def __post_cost(self, cost_json, url):
|
||||||
request_content = json.dumps(cost_json, separators=(',', ':'))
|
request_content = json.dumps(cost_json, separators=(',', ':'))
|
||||||
request_hash_text = "{}{}{}{}".format(
|
request_hash_text = "{}{}{}{}".format(
|
||||||
@ -303,6 +300,15 @@ class iFirmaAPI():
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def list_invoices(self, date_from="", date_to=""):
|
||||||
|
params = {"dataOd": date_from}
|
||||||
|
if date_to:
|
||||||
|
params.update(dataDo=date_to)
|
||||||
|
|
||||||
|
return self.__get("faktury.json", self.__invoice_key_name,
|
||||||
|
params=params)
|
||||||
|
|
||||||
|
|
||||||
def get_invoice_list(self, limit=0):
|
def get_invoice_list(self, limit=0):
|
||||||
url = "https://www.ifirma.pl/iapi/fakturaeksportuslugue/list.json"
|
url = "https://www.ifirma.pl/iapi/fakturaeksportuslugue/list.json"
|
||||||
request_hash_text = "{}{}{}".format(
|
request_hash_text = "{}{}{}".format(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user