1
📥
Aggregate tax dataFetch STP, ETB, and form submissions
2
🔍
Validate fieldsVerify completeness and format
3
📝
Generate IRB XMLCreate IRB-formatted XML
✅
Create checklistSubmission verification list
import requests, json, xml.etree.ElementTree as ET
API_STP = "https://api.lhdn.gov.my/stp"
API_ETB = "https://api.lhdn.gov.my/etb"
def fetch_tax_data(form_type):
resp = requests.get(f"https://api.lhdn.gov.my/{form_type}")
return resp.json()
def validate_tax_fields(data):
required = ["tin", "period", "amount"]
return all(k in data for k in required)
def generate_irb_xml(data, form_type):
root = ET.Element(f"{form_type}_submission")
ET.SubElement(root, "tin").text = data["tin"]
ET.SubElement(root, "period").text = data["period"]
ET.SubElement(root, "amount").text = str(data["amount"])
return ET.tostring(root, encoding="unicode")
forms = ["STP", "ETB", "Tax-Ezt", "Form-E"]
for f in forms:
data = fetch_tax_data(f)
if validate_tax_fields(data):
xml = generate_irb_xml(data, f)
print(f"{f}: {xml}")