-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinvoices.py
More file actions
60 lines (48 loc) · 1.83 KB
/
invoices.py
File metadata and controls
60 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import facturapi
from facturapi import configure
from facturapi.resources.invoices import InvoiceRequest
from facturapi.types import FileType, PaymentForm
from facturapi.types.general import ItemPart
# Configure API KEY if not set in env variable
configure(api_key='my_secret_api_key')
def main():
# Create an Invoice:
# First fill the request object and then create the resource
invoice_request = InvoiceRequest(
customer='58e93bd8e86eb318b0197456', # Customer can be a CustomerRequest or its ID.
items=[
dict(
product=dict(
description='Producto Test',
product_key='50202201',
price=42.05,
),
quantity=2,
),
],
payment_form=PaymentForm.tarjeta_de_credito,
)
invoice = facturapi.Invoice.create(data=invoice_request)
# Resource is now created an can be used to access data or perform actions.
total = invoice.total
invoice_file = facturapi.Invoice.download(
id=invoice.id, file_type=FileType.pdf
)
with open('my_invoice_file.pdf', 'wb') as f:
f.write(invoice_file)
# Refresh the resource in case an update happened somewhere:
invoice.refresh()
# Cancel an invoice:
cancelled_invoice = facturapi.Invoice.cancel(invoice_id=invoice.id)
status = cancelled_invoice.status
# Perform a query to bring a list or an specific invoice:
# Checkout full query details on the docs:
# https://docs.facturapi.io/?javascript#lista-de-facturas
query_result = facturapi.Invoice.all(q='John Doe')
for invoice in query_result:
# Iterate throught query's result
continue
# Or just query for a unique result
only_one = facturapi.Invoice.first(q='John Doe')
if __name__ == '__main__':
main()