-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_invoice.py
More file actions
70 lines (59 loc) · 1.69 KB
/
Copy pathcreate_invoice.py
File metadata and controls
70 lines (59 loc) · 1.69 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
61
62
63
64
65
66
67
68
69
70
"""Complete workflow: Create customer → Invoice → Position → Finalize → PDF."""
import os
from docs101 import Docs101Client
client = Docs101Client(api_key=os.environ["DOCS101_API_KEY"])
# Create customer
customer = client.customers.create(
organization_name="Acme Corp",
email="billing@acme.com",
contact_type="B2B",
vat_id="DE123456789",
language="English",
)
customer_id = customer["id"]
print(f"Created customer {customer_id}")
# Add address
client.customers.create_address(
customer_id,
company="Acme Corp",
address_line_1="Musterstraße 1",
postal_code="10115",
city="Berlin",
country_code="DE",
is_default=True,
)
print("Address added")
# Create invoice
invoice = client.invoices.create(
customer_id=customer_id,
benefit_period_start="2026-04-01",
benefit_period_end="2026-04-30",
invoice_format="ZUGFERD",
)
invoice_id = invoice["invoice_id"]
print(f"Created invoice {invoice_id}")
# Add position
client.invoices.add_position(
invoice_id,
title="Pro Plan — Monthly Subscription",
quantity=1.0,
unit_id="HUR",
unit_net_amount=25.00,
single_net_amount=25.00,
tax_rate=0.19,
tax_treatment_id="standard",
)
print("Position added")
# Validate
validation = client.invoices.validate(invoice_id)
assert validation["valid"], f"Validation failed: {validation['errors']}"
print("Validation passed")
# Finalize (starts async job, polls until done)
client.invoices.finalize(invoice_id)
print("Invoice finalized")
# Download PDF
pdf = client.invoices.get_pdf_url(invoice_id)
print(f"PDF ready: {pdf['filename']} — {pdf['url']}")
# Mark as sent
client.invoices.mark_as_sent(invoice_id)
print("Invoice marked as sent")