Skip to main content

Getting Invoice Details and Transactions

Learn how to retrieve complete invoice information including payment transactions, customer details, and line items.

Basic Invoice Retrieval

Get Invoice by ID

Retrieve detailed information for a specific invoice:

from abstra.connectors import run_connection_action

connection_name = "paypal"

# Get invoice details
invoice_id = "INV2-XXXX-XXXX-XXXX-XXXX"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] == "success":
invoice = result

print(f"Invoice Number: {invoice['detail']['invoice_number']}")
print(f"Status: {invoice['status']}")
print(f"Invoice Date: {invoice['detail']['invoice_date']}")
print(f"Total Amount: ${invoice['amount']['value']} {invoice['amount']['currency_code']}")
print(f"Amount Paid: ${invoice.get('payments', {}).get('paid_amount', {}).get('value', '0.00')}")
print(f"Amount Due: ${invoice['due_amount']['value']}")

Expected Output:

Invoice Number: SCRANTON-2024-001
Status: PAID
Invoice Date: 2024-09-29
Total Amount: $1,234.56 USD
Amount Paid: $1,234.56
Amount Due: $0.00

Get Invoice from List

Find and retrieve a specific invoice by invoice number:

from abstra.connectors import run_connection_action

connection_name = "paypal"

# First, list all invoices
list_result = run_connection_action(connection_name, "invoicing/get_v2_invoicing_invoices")

if list_result["status"] == "success":
invoices = list_result["items"]

# Find specific invoice by number
invoice_number = "SCRANTON-2024-001"

target_invoice = next(
(inv for inv in invoices if inv["detail"]["invoice_number"] == invoice_number),
None
)

if target_invoice:
# Get full details
detail_result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": target_invoice["id"]}
)

if detail_result["status"] == "success":
invoice = detail_result
print(f"Found invoice: {invoice['id']}")
else:
print(f"Invoice {invoice_number} not found")

Viewing Transaction Details

Extract Payment Transactions

Get detailed payment transaction information:

from abstra.connectors import run_connection_action

connection_name = "paypal"

invoice_id = "INV2-XXXX-XXXX-XXXX-XXXX"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] == "success":
invoice = result

print(f"Invoice: {invoice['detail']['invoice_number']}")
print(f"Status: {invoice['status']}")

# Check if invoice has payments
if "payments" in invoice and "transactions" in invoice["payments"]:
transactions = invoice["payments"]["transactions"]

print(f"\nPayment Transactions: {len(transactions)}")

for tx in transactions:
print(f"\n Transaction ID: {tx['payment_id']}")
print(f" Date: {tx['payment_date']}")
print(f" Time: {tx['payment_date_time']}")
print(f" Amount: ${tx['amount']['value']} {tx['amount']['currency_code']}")
print(f" Method: {tx['method']}")
print(f" Type: {tx['type']}")
print(f" Status: {tx['transaction_status']}")
else:
print("\nNo payment transactions found (invoice may not be paid yet)")

Expected Output:

Invoice: SCRANTON-2024-001
Status: PAID

Payment Transactions: 1

Transaction ID: 8KK88511SC5373202
Date: 2024-10-08
Time: 2024-10-08T08:08:11Z
Amount: $1,234.56 USD
Method: PAYPAL
Type: PAYPAL
Status: SUCCESS

Track Payment History

Show complete payment history for an invoice:

from abstra.connectors import run_connection_action
from datetime import datetime

connection_name = "paypal"

invoice_id = "INV2-XXXX-XXXX-XXXX-XXXX"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] == "success":
invoice = result

print(f"Payment History for {invoice['detail']['invoice_number']}")
print(f"Total Amount: ${invoice['amount']['value']}")
print(f"Amount Due: ${invoice['due_amount']['value']}")

if "payments" in invoice:
payments = invoice["payments"]

if "paid_amount" in payments:
print(f"Total Paid: ${payments['paid_amount']['value']}")

if "transactions" in payments:
print(f"\nTransactions:")
for tx in sorted(payments["transactions"], key=lambda x: x["payment_date_time"]):
date = datetime.strptime(tx["payment_date_time"], "%Y-%m-%dT%H:%M:%SZ")
print(f" {date.strftime('%Y-%m-%d %H:%M')}: ${tx['amount']['value']} ({tx['transaction_status']})")

Expected Output:

Payment History for SCRANTON-2024-001
Total Amount: $1,234.56
Amount Due: $0.00
Total Paid: $1,234.56

Transactions:
2024-10-08 08:08: $1,234.56 (SUCCESS)

Customer Information

Extract Customer Details

Get complete customer information from invoice:

from abstra.connectors import run_connection_action

connection_name = "paypal"

invoice_id = "INV2-XXXX-XXXX-XXXX-XXXX"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] == "success":
invoice = result

# Invoicer (sender) information
print("From:")
invoicer = invoice["invoicer"]
if "business_name" in invoicer:
print(f" Business: {invoicer['business_name']}")
if "name" in invoicer:
print(f" Name: {invoicer['name']['full_name']}")
print(f" Email: {invoicer['email_address']}")

# Customer (recipient) information
print("\nTo:")
recipient = invoice["primary_recipients"][0]["billing_info"]

if "business_name" in recipient:
print(f" Business: {recipient['business_name']}")
if "name" in recipient:
print(f" Name: {recipient['name'].get('full_name', 'N/A')}")
print(f" Email: {recipient['email_address']}")

if "language" in recipient:
print(f" Language: {recipient['language']}")

Expected Output:

From:
Business: Dunder Mifflin Paper Company
Name: Michael Scott
Email: accounting@dundermifflin.com

To:
Business: Schrute Farms
Name: Dwight Schrute
Email: dwight@schrutefarms.com
Language: en-US

Invoice Items

List Line Items

View all items/services on the invoice:

from abstra.connectors import run_connection_action

connection_name = "paypal"

invoice_id = "INV2-XXXX-XXXX-XXXX-XXXX"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] == "success":
invoice = result

print(f"Invoice: {invoice['detail']['invoice_number']}")
print(f"\nLine Items:")

if "items" in invoice:
for item in invoice["items"]:
print(f"\n Item ID: {item['id']}")
print(f" Name: {item['name']}")
print(f" Quantity: {item['quantity']}")
print(f" Unit Price: ${item['unit_amount']['value']} {item['unit_amount']['currency_code']}")

# Calculate line total
total = float(item['quantity']) * float(item['unit_amount']['value'])
print(f" Line Total: ${total:.2f}")

if "description" in item:
print(f" Description: {item['description']}")

Expected Output:

Invoice: SCRANTON-2024-001

Line Items:

Item ID: ITEM-19D94520W43633820
Name: Premium Paper - A4
Quantity: 100
Unit Price: $12.34 USD
Line Total: $1234.00
Description: High-quality office paper

Calculate Breakdown

Show complete amount breakdown:

from abstra.connectors import run_connection_action

connection_name = "paypal"

invoice_id = "INV2-XXXX-XXXX-XXXX-XXXX"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] == "success":
invoice = result
amount = invoice["amount"]

print(f"Invoice: {invoice['detail']['invoice_number']}")
print(f"\nAmount Breakdown:")

if "breakdown" in amount:
breakdown = amount["breakdown"]

# Item total
if "item_total" in breakdown:
print(f" Subtotal: ${breakdown['item_total']['value']}")

# Discount
if "discount" in breakdown:
invoice_discount = breakdown["discount"].get("invoice_discount", {}).get("amount", {}).get("value", "0.00")
item_discount = breakdown["discount"].get("item_discount", {}).get("value", "0.00")

total_discount = float(invoice_discount) + float(item_discount)
if total_discount > 0:
print(f" Discount: -${total_discount:.2f}")

# Tax
if "tax_total" in breakdown:
print(f" Tax: ${breakdown['tax_total']['value']}")

# Shipping
if "shipping" in breakdown:
print(f" Shipping: ${breakdown['shipping']['amount']['value']}")

# Final total
print(f"\n Total: ${amount['value']} {amount['currency_code']}")

Expected Output:

Invoice: SCRANTON-2024-001

Amount Breakdown:
Subtotal: $1234.00
Tax: $0.56

Total: $1234.56 USD

Invoice Metadata

View Invoice Metadata

Get additional invoice information:

from abstra.connectors import run_connection_action
from datetime import datetime

connection_name = "paypal"

invoice_id = "INV2-XXXX-XXXX-XXXX-XXXX"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] == "success":
invoice = result
detail = invoice["detail"]
metadata = detail.get("metadata", {})

print(f"Invoice Metadata:")
print(f" Invoice Number: {detail['invoice_number']}")
print(f" Invoice Date: {detail['invoice_date']}")

if "payment_term" in detail:
if "due_date" in detail["payment_term"]:
print(f" Due Date: {detail['payment_term']['due_date']}")
if "term_type" in detail["payment_term"]:
print(f" Payment Terms: {detail['payment_term']['term_type']}")

if metadata:
print(f"\n Created: {metadata.get('create_time', 'N/A')}")
print(f" Last Updated: {metadata.get('last_update_time', 'N/A')}")
print(f" First Sent: {metadata.get('first_sent_time', 'N/A')}")
print(f" Last Sent: {metadata.get('last_sent_time', 'N/A')}")
print(f" Viewed by Recipient: {detail.get('viewed_by_recipient', False)}")

# URLs
if "invoicer_view_url" in metadata:
print(f"\n Invoicer URL: {metadata['invoicer_view_url']}")
if "recipient_view_url" in metadata:
print(f" Recipient URL: {metadata['recipient_view_url']}")

Expected Output:

Invoice Metadata:
Invoice Number: SCRANTON-2024-001
Invoice Date: 2024-09-29
Due Date: 2024-10-10
Payment Terms: DUE_ON_DATE_SPECIFIED

Created: 2024-09-29T14:28:13Z
Last Updated: 2024-10-08T15:08:11Z
First Sent: 2024-09-29T14:29:37Z
Last Sent: 2024-09-29T14:29:37Z
Viewed by Recipient: False

Invoicer URL: https://www.paypal.com/invoice/details/INV2-XXXX-XXXX-XXXX-XXXX
Recipient URL: https://www.paypal.com/invoice/p/#XXXXXXXXXXXX

Complete Invoice Report

Generate Full Invoice Report

Create a comprehensive invoice report:

from abstra.connectors import run_connection_action
from datetime import datetime

def print_invoice_report(invoice_id: str):
"""
Print a complete invoice report with all details.
"""
connection_name = "paypal"

result = run_connection_action(connection_name,
"invoicing/get_v2_invoicing_invoices_by_invoice_id",
params={"invoice_id": invoice_id}
)

if result["status"] != "success":
print(f"Error: {result.get('message')}")
return

invoice = result
detail = invoice["detail"]

# Header
print("=" * 60)
print(f"INVOICE: {detail['invoice_number']}")
print("=" * 60)

# Status
print(f"\nStatus: {invoice['status']}")
print(f"Invoice Date: {detail['invoice_date']}")
if "payment_term" in detail and "due_date" in detail["payment_term"]:
print(f"Due Date: {detail['payment_term']['due_date']}")

# Parties
print(f"\nFrom: {invoice['invoicer']['email_address']}")
print(f"To: {invoice['primary_recipients'][0]['billing_info']['email_address']}")

# Items
print(f"\nItems:")
if "items" in invoice:
for item in invoice["items"]:
qty = item['quantity']
price = float(item['unit_amount']['value'])
total = float(qty) * price
print(f" {item['name']}: {qty} x ${price:.2f} = ${total:.2f}")

# Amounts
print(f"\nTotal: ${invoice['amount']['value']} {invoice['amount']['currency_code']}")
print(f"Amount Paid: ${invoice.get('payments', {}).get('paid_amount', {}).get('value', '0.00')}")
print(f"Amount Due: ${invoice['due_amount']['value']}")

# Transactions
if "payments" in invoice and "transactions" in invoice["payments"]:
print(f"\nTransactions:")
for tx in invoice["payments"]["transactions"]:
print(f" {tx['payment_date']}: ${tx['amount']['value']} via {tx['method']} ({tx['transaction_status']})")

print("=" * 60)

# Usage
print_invoice_report("INV2-XXXX-XXXX-XXXX-XXXX")

Expected Output:

============================================================
INVOICE: SCRANTON-2024-001
============================================================

Status: PAID
Invoice Date: 2024-09-29
Due Date: 2024-10-10

From: accounting@dundermifflin.com
To: dwight@schrutefarms.com

Items:
Premium Paper - A4: 100 x $12.34 = $1234.00

Total: $1234.56 USD
Amount Paid: $1234.56
Amount Due: $0.00

Transactions:
2024-10-08: $1234.56 via PAYPAL (SUCCESS)
============================================================

Best Practices

  1. Check Invoice Exists: Always handle cases where invoice might not be found
  2. Handle Missing Fields: Use .get() for optional fields like transactions
  3. Parse Dates Properly: Use datetime for date comparisons and formatting
  4. Check Payment Status: Verify invoice is paid before accessing transactions
  5. Cache Details: Store invoice details locally if accessing multiple times

Next Steps