Skip to content

Commit 9401292

Browse files
authored
Merge pull request #35 from veryfi/get_documents-add_params
Get documents add params
2 parents 068ebc9 + c63d7fb commit 9401292

File tree

4 files changed

+140
-5
lines changed

4 files changed

+140
-5
lines changed

.github/workflows/release-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
build:
9-
runs-on: ubuntu-latest
9+
runs-on: ubuntu-20.04
1010
strategy:
1111
matrix:
1212
python-version: [3.6]

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: [3.6, 3.7, 3.8, 3.9]
10+
python-version: [3.7, 3.8, 3.9]
1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: Set up Python ${{ matrix.python-version }}

tests/test_client.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,100 @@ def test_process_w9_document():
270270
)
271271
d = client.process_w9_document(file_path="tests/assets/receipt_public.jpg")
272272
assert d == mock
273+
274+
275+
@responses.activate
276+
def test_get_documents():
277+
mock = [
278+
{
279+
"abn_number": "",
280+
"account_number": "",
281+
"barcodes": [],
282+
"bill_to_address": "",
283+
"bill_to_name": "",
284+
"bill_to_vat_number": "",
285+
"card_number": "",
286+
"cashback": 0.0,
287+
"category": "",
288+
"created": "2021-06-22 20:31:04",
289+
"currency_code": "USD",
290+
"date": "2021-06-22 16:31:04",
291+
"discount": 0.0,
292+
"due_date": "",
293+
"external_id": "",
294+
"id": 36967602,
295+
"img_file_name": "962748f4-95bb-400b-9f59-9c2d5e42e6af.jpg",
296+
"img_thumbnail_url": "",
297+
"img_url": "",
298+
"invoice_number": "98",
299+
"line_items": [
300+
{
301+
"date": "",
302+
"description": "98 Meat Pty Xchz",
303+
"discount": 0.0,
304+
"id": 67188771,
305+
"order": 0,
306+
"price": 0.0,
307+
"quantity": 1.0,
308+
"reference": "",
309+
"sku": "",
310+
"tax": 0.0,
311+
"tax_rate": 0.0,
312+
"total": 90.85,
313+
"type": "food",
314+
"unit_of_measure": "",
315+
}
316+
],
317+
"notes": "",
318+
"ocr_text": "\n\x0c2004-10-31\n\t8:21 PM\nYOUR GUEST NUMBER IS\n98\nIN-N-OUT BURGER LAS VEGAS EASTERN\n2004-10-31\t\t8:21 PM\n165 1 5 98\nCashier: SAM\nGUEST #: 98\nCounter-Eat in\n\t2.65\nDbDb\t\t88.20\n98 Meat Pty Xchz\n\t90.85\nCounter-Eat In\t\t6.81\nTAX 7.50%\t\t97.66\nAmount Due\n\t$97.66\nCASH TENDER\t\t$.00\nChange\n2004-10-31\t\t8:21 PM\nTHANK YOU!\n",
319+
"payment_display_name": "Cash",
320+
"payment_terms": "",
321+
"payment_type": "cash",
322+
"phone_number": "",
323+
"purchase_order_number": "",
324+
"reference_number": "VBIJG-7602",
325+
"rounding": 0.0,
326+
"service_end_date": "",
327+
"service_start_date": "",
328+
"shipping": 0.0,
329+
"subtotal": 0.0,
330+
"tags": [],
331+
"tax": 97.66,
332+
"tax_lines": [{"base": 0.0, "name": "", "order": 0, "rate": 7.5, "total": 97.66}],
333+
"tip": 0.0,
334+
"total": 97.66,
335+
"tracking_number": "",
336+
"updated": "2021-06-22 20:31:05",
337+
"vat_number": "",
338+
"vendor": {
339+
"address": "",
340+
"email": "",
341+
"fax_number": "",
342+
"name": "In-N-Out Burger",
343+
"phone_number": "",
344+
"raw_name": "In-N-Out Burger",
345+
"vendor_logo": "https://cdn.veryfi.com/logos/us/949103001.png",
346+
"vendor_reg_number": "",
347+
"vendor_type": "Restaurant",
348+
"web": "",
349+
},
350+
"vendor_account_number": "",
351+
"vendor_bank_name": "",
352+
"vendor_bank_number": "",
353+
"vendor_bank_swift": "",
354+
"vendor_iban": "",
355+
}
356+
]
357+
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
358+
responses.add(
359+
responses.GET,
360+
f"{client.versioned_url}/partner/documents/",
361+
json=mock,
362+
status=200,
363+
)
364+
d = client.get_documents(
365+
q="In-N-Out Burger",
366+
created_gte="2021-05-22+00:00:00",
367+
**{"created_lt": "2021-07-22+00:00:00"},
368+
)
369+
assert d == mock

veryfi/client.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,52 @@ def _generate_signature(self, payload_params, timestamp):
123123
base64_signature = base64.b64encode(tmp_signature).decode("utf-8").strip()
124124
return base64_signature
125125

126-
def get_documents(self):
126+
def get_documents(
127+
self,
128+
q: Optional[str] = None,
129+
external_id: Optional[str] = None,
130+
tag: Optional[str] = None,
131+
created_gt: Optional[str] = None,
132+
created_gte: Optional[str] = None,
133+
created_lt: Optional[str] = None,
134+
created_lte: Optional[str] = None,
135+
**kwargs: Dict,
136+
):
127137
"""
128138
Get list of documents
139+
:param query: Search term to search for a specific document by its content. These fields will be searched: external_id, category, vendor.name, notes, invoice_number, total and ocr_text.
140+
:param external_id: Search for documents that match your custom identifier
141+
:param tag: Search for documents with the specified tag
142+
:param created__gt: Search for documents with a created date greater than this one. Format YYYY-MM-DD+HH:MM:SS. Don't send both created__gt and created__gte in a single request.
143+
:param created__gte: Search for documents with a created date greater than or equal to this one. Format YYYY-MM-DD+HH:MM:SS. Don't send both created__gt and created__gte in a single request.
144+
:param created__lt: Search for documents with a created date greater than this one. Format YYYY-MM-DD+HH:MM:SS. Don't send both created__lt and created__lte in a single request.
145+
:param created__lte: Search for documents with a created date less than or equal to this one. Format YYYY-MM-DD+HH:MM:SS. Don't send both created__lt and created__lte in a single request.
146+
:param kwargs: Additional request parameters
129147
:return: List of previously processed documents
130148
"""
131149
endpoint_name = "/documents/"
132-
request_arguments = {}
133-
documents = self._request("GET", endpoint_name, request_arguments)
150+
151+
request_params = {}
152+
if q:
153+
request_params["q"] = q
154+
if external_id:
155+
request_params["external_id"] = external_id
156+
if tag:
157+
request_params["tag"] = tag
158+
if created_gt:
159+
request_params["created__gt"] = created_gt
160+
if created_gte:
161+
request_params["created__gte"] = created_gte
162+
if created_lt:
163+
request_params["created__lt"] = created_lt
164+
if created_lte:
165+
request_params["created__lte"] = created_lte
166+
request_params.update(kwargs)
167+
if request_params:
168+
endpoint_name += "?" + "&".join(f"{k}={v}" for k, v in request_params.items())
169+
170+
documents = self._request("GET", endpoint_name, {})
171+
134172
if "documents" in documents:
135173
return documents["documents"]
136174
return documents

0 commit comments

Comments
 (0)