Invoice Delivery System
BillaBear provides a flexible invoice delivery system that allows invoices to be delivered to customers through various channels. This document explains how the delivery system works and how to extend it with custom delivery handlers.
Overview
The invoice delivery system in BillaBear:
- Supports multiple delivery methods (Email, SFTP, Webhook)
- Integrates with the invoice formatter system
- Uses a handler-based architecture for extensibility
- Provides status tracking for deliveries
- Supports asynchronous delivery via Symfony Messenger
Delivery Methods
BillaBear supports the following delivery methods:
Email Delivery
Email delivery sends the invoice as an attachment to the customer's email address. Key features:
- Supports all invoice formats (PDF, ZUGFeRD, etc.)
- Can use a custom email address instead of the customer's default
- Includes a payment link in the email
- Uses templates for email content
SFTP Delivery
SFTP (Secure File Transfer Protocol) delivery uploads the invoice to a remote server. Key features:
- Secure transfer using SSH
- Configurable server, username, password, and path
- Supports all invoice formats
- Useful for integration with accounting systems
Webhook Delivery
Webhook delivery posts the invoice to a URL provided by the customer. Key features:
- HTTP POST request with the invoice as the payload
- Configurable URL and headers
- Supports all invoice formats
- Useful for integration with external systems
Delivery Settings
Invoice delivery is configured through the InvoiceDeliverySettings
entity, which contains:
- The delivery method (Email, SFTP, Webhook)
- Method-specific settings (email address, SFTP credentials, webhook URL)
- The invoice format to use (PDF, ZUGFeRD, etc.)
- Customer association
Each customer can have multiple delivery settings, allowing invoices to be delivered through multiple channels or in multiple formats.
Delivery Architecture
Each delivery method implements this interface to handle its specific delivery logic.
Delivery Status Tracking
BillaBear tracks the status of each delivery attempt using the InvoiceDeliveryStatus
enum:
SUCCESS
- The delivery was successfulFAILED
- The delivery failed
This status is stored in the InvoiceDelivery
entity, which links an invoice to its delivery settings and records the delivery status.
Asynchronous Delivery
BillaBear uses Symfony Messenger for asynchronous invoice delivery, which:
- Improves performance by not blocking the request
- Provides retry capabilities for failed deliveries
- Allows for better error handling and logging
The delivery process is initiated by dispatching an InvoiceDeliveryRequest
message, which is then handled by the InvoiceDeliveryRequestHandler
.
Best Practices
When working with the invoice delivery system:
- Always handle errors gracefully and log appropriate information
- Consider security implications, especially for external delivery methods
- Test delivery handlers with various invoice formats and sizes
- Implement proper validation for delivery settings
- Consider rate limiting for external API calls (e.g., webhooks)
- Use the asynchronous delivery system for better performance
- Implement proper retry logic for failed deliveries
Integration with Formatters
The delivery system integrates closely with the invoice formatter system:
- Each delivery setting specifies which formatter to use
- The delivery handler uses the formatter to generate the invoice content
- The formatter determines the filename and format of the delivered invoice
This modular approach allows for great flexibility in how invoices are formatted and delivered to customers.