Billit Woo Connect

Billit WooCommerce Integration

A comprehensive WordPress plugin that seamlessly integrates WooCommerce with Billit for automated invoice and credit note creation, featuring advanced VAT handling, bi-directional PDF management, and Peppol network integration.

๐Ÿš€ Key Features

Core Integration

  • Automatic Invoice Creation: Smart invoice generation when orders reach configured statuses
  • Advanced Credit Note System: Handles full/partial refunds including shipping and fees
  • Peppol Network Integration: Automatic B2B invoice delivery via European Peppol network
  • Bi-Directional PDF Management: Upload WooCommerce PDFs to Billit and download Billit PDFs
  • Real-Time Status Tracking: Visual indicators and comprehensive order notes

Advanced VAT & Customer Handling

  • Multi-Country VAT Detection: Automatic VAT number extraction and validation (BE, NL, DE, FR, GB)
  • Smart Customer Classification: Automatic B2B vs B2C detection with proper tax handling
  • POS System Support: VAT extraction from company names in POS orders
  • Company Name Cleaning: Removes embedded VAT numbers for professional appearance

Professional Admin Interface

  • Dual Meta Box System: Separate interfaces for operations and PDF management
  • PDF Download Icons: Direct PDF access from orders list overview
  • AJAX Operations: Real-time processing with progress indicators
  • Manual Override Options: Full manual control when needed

Enterprise-Grade Reliability

  • Comprehensive Error Handling: Detailed logging and graceful error recovery
  • Duplicate Prevention: Advanced logic prevents duplicate operations
  • HPOS Compatibility: Full support for WooCommerce High-Performance Order Storage
  • Retry Mechanisms: Automatic retries for failed operations

๐Ÿ› ๏ธ Technical Requirements

  • WordPress: 5.0 or higher
  • WooCommerce: 6.0 or higher
  • PHP: 7.4 or higher
  • Billit Account: Active account with API access
  • SSL: HTTPS required for API communications

๐Ÿ“ฆ Installation

  1. Upload Plugin Files:

    /wp-content/plugins/billit_woo_connect/
  2. Activate Plugin:

    • Navigate to Plugins โ†’ Installed Plugins
    • Find "Billit WooCommerce Integration"
    • Click Activate
  3. Initial Configuration:

    • Go to Settings โ†’ Billit Integration
    • Enter your Billit API credentials
    • Configure processing preferences
    • Test API connection

โš™๏ธ Configuration Guide

API Settings

API Key: [Your Billit API Key]
Company ID: [Your Billit Company ID] 
API Environment:
  โ€ข Sandbox: https://api.sandbox.billit.be/v1
  โ€ข Production: https://api.billit.be/v1

Processing Settings

  • โœ… Enable Automatic Processing: Smart automation for invoices and credit notes
  • ๐Ÿ“‹ Auto-Invoice Statuses: Configure which order statuses trigger invoice creation
  • ๐Ÿ“ค Automatic Peppol Sending: Auto-send B2B invoices via Peppol network
  • ๐Ÿ”ง Processing Mode: Choose between different integration levels

PDF Management

  • ๐Ÿ“„ Upload PDFs to Billit: Attach WooCommerce PDFs to Billit orders
  • ๐Ÿ“ฅ Download PDFs from Billit: Retrieve and store Billit-generated PDFs
  • โฑ๏ธ Auto-Retrieval: Scheduled PDF downloading after invoice/credit note creation
  • ๐Ÿ‘ฅ Frontend Display Control: Toggle customer visibility of PDFs on My Account page (enabled by default)

Order Configuration

  • ๐Ÿท๏ธ Order Number Prefix: Customize prefixes for Billit orders (default: "WC-")
  • ๐Ÿ“… Invoice Expiry: Set payment terms (default: 30 days)
  • ๐Ÿ’ผ Credit Note References: Automatic linking to original invoices

๐ŸŽฏ Usage Guide

Automatic Processing Flow

Invoice Creation:

  1. Customer places order โ†’ WooCommerce processes payment
  2. Order reaches configured status (e.g., "Processing")
  3. Plugin detects VAT number and classifies customer (B2B/B2C)
  4. Creates invoice in Billit with proper VAT handling
  5. Sends via Peppol (for B2B customers) or stores for manual sending
  6. Retrieves and attaches PDF to WooCommerce order

Credit Note Creation:

  1. Merchant processes refund in WooCommerce
  2. Plugin detects refund components (products + shipping + fees)
  3. Creates comprehensive credit note in Billit
  4. Links to original invoice reference
  5. Sends via Peppol (if original was B2B)
  6. Retrieves and attaches credit note PDF

Manual Operations

From Order Edit Page:

  • Billit Integration Meta Box:
    • ๐Ÿ“‹ View current status (invoice/credit note creation)
    • ๐Ÿ”˜ Manual "Create Invoice" and "Create Credit Note" buttons
    • โœ… Real-time status updates with detailed information
  • Billit PDF Downloads Meta Box:
    • ๐Ÿ“ View all downloaded PDFs (invoices, credit notes)
    • ๐Ÿ“ฅ "Download All PDFs" or individual PDF downloads
    • ๐Ÿ”„ "Refresh All PDFs" to update existing files
    • ๐Ÿ“Š File size, dates, and document type indicators

From Orders List:

  • Billit Status Column: Shows operation status at a glance
  • PDF Download Icons: Direct download links for available PDFs
    • ๐Ÿ“‹ = Invoice PDF available
    • ๐Ÿงพ = Credit Note PDF available
    • Click any icon for instant PDF download

Advanced Features

VAT Number Detection:

Automatic detection from:
โ€ข Customer billing fields (vat_number, billing_vat_number)  
โ€ข Company names (embedded VAT: "Company BE0123456789")
โ€ข Multi-country format handling and validation

POS System Integration:

Input: "Beauty Salon BE1234567890"
Output: 
  โ€ข Company: "Beauty Salon" (cleaned)
  โ€ข VAT Number: "BE1234567890" (extracted)
  โ€ข Classification: B2B Customer

Comprehensive Refund Handling:

Refund Components Detected:
โ€ข Product refunds (with quantities and VAT)
โ€ข Shipping cost refunds (with proper tax calculation)  
โ€ข Payment gateway fees and handling fees
โ€ข All components properly categorized in credit notes

๐Ÿ”ง API Integration Details

Invoice Payload Structure

{
  "OrderType": "Invoice",
  "OrderDirection": "Income", 
  "Customer": {
    "VATLiable": true,
    "VATDeductable": true,
    "VATNumber": "BE0123456789",
    "ContactFirstName": "John",
    "ContactLastName": "Doe"
  },
  "OrderLines": [
    {
      "Quantity": 2,
      "UnitPriceExcl": 25.00,
      "Description": "Product Name",
      "VATPercentage": 21
    }
  ]
}

Credit Note Features

{
  "OrderType": "CreditNote",
  "AboutInvoiceNumber": "WC-1234",
  "Paid": true,
  "PaidDate": "2025-12-17",
  "OrderLines": [
    {"Description": "Product Refund", "Quantity": 1, "UnitPriceExcl": 25.00},
    {"Description": "Shipping Refund", "Quantity": 1, "UnitPriceExcl": 5.00}, 
    {"Description": "Fee Refund", "Quantity": 1, "UnitPriceExcl": 2.00}
  ]
}

PDF Management APIs

  • Upload: POST /v1/orders/{id}/attachments (multipart/form-data)
  • Download: GET /v1/files/{fileId} (base64 content)
  • Storage: WordPress media library with organized metadata

๐Ÿ“Š Order Notes & Tracking

Invoice Operations

โœ… Billit Invoice Created Successfully
โ€ข Invoice ID: 2219533  
โ€ข Order Number: WC-2922
โ€ข Amount: โ‚ฌ 109,00
โ€ข Created: 2025-11-11 23:45:57
โ€ข Auto-send via Peppol: Enabled (B2B customer)

๐Ÿ“ค Invoice sent via Peppol network successfully
๐Ÿ“ฅ Billit PDF retrieved and attached to order

Credit Note Operations

๐Ÿ”„ Billit Credit Note Created Successfully
โ€ข Credit Note ID: 2219544
โ€ข Original Invoice: WC-2922  
โ€ข Refund Amount: โ‚ฌ 48,00
โ€ข Components: Products (โ‚ฌ38) + Shipping (โ‚ฌ10)
โ€ข Created: 2025-11-12 01:15:23

๐Ÿ“ค Credit note sent via Peppol network successfully
๐Ÿ“ฅ Credit note PDF retrieved and attached to order

System Messages

๐Ÿ”„ Billit automatic processing triggered (Status: processing)
โ„น๏ธ B2B customer detected - Peppol sending enabled
โ„น๏ธ Private customer - manual PDF sending required
โŒ API Error: [Specific error message with troubleshooting info]

๐Ÿ›ก๏ธ Security & Performance

Security Features

  • โœ… HTTPS-only API communications
  • โœ… Secure WordPress options storage for API credentials
  • โœ… Nonce verification for all AJAX requests
  • โœ… Capability checks for administrative functions
  • โœ… Input sanitization and validation
  • โœ… Directory protection with index.php files
  • โœ… Protected log files with .htaccess

Performance Optimizations

  • โšก WordPress cron for scheduled operations
  • โšก AJAX for non-blocking admin operations
  • โšก Efficient API request batching
  • โšก Smart caching and duplicate prevention
  • โšก Optimized database queries for HPOS compatibility
  • โšก Settings caching to reduce database queries
  • โšก GitLab updater caching (12-hour cache with force-check support)

๐Ÿ” Troubleshooting Guide

Enable Debug Mode

  1. Settings โ†’ Billit Integration โ†’ Enable Debug Mode
  2. Check WordPress error logs: /wp-content/debug.log
  3. Monitor real-time processing in order notes

Common Issues & Solutions

API Connection Issues

Problem: "API Connection Failed"
Solutions:
โ€ข Verify API key and company ID are correct
โ€ข Check API environment (sandbox vs production)  
โ€ข Test connection using admin interface
โ€ข Ensure HTTPS is properly configured

VAT Detection Issues

Problem: "VAT number not detected"
Solutions:
โ€ข Check customer billing fields for VAT number
โ€ข For POS orders, ensure company name includes VAT
โ€ข Verify VAT number format matches country standards
โ€ข Review debug logs for detection attempts

PDF Issues

Problem: "PDF not downloading"
Solutions:
โ€ข Ensure invoice/credit note exists in Billit first
โ€ข Check if PDF generation completed (may take time)
โ€ข Verify WordPress media directory permissions
โ€ข Use manual "Retrieve PDF" button for troubleshooting

Missing Refund Components

Problem: "Shipping not included in credit note"
Solutions:
โ€ข Ensure shipping is included in WooCommerce refund
โ€ข Check refund amount matches product + shipping total
โ€ข Review debug logs for refund component detection
โ€ข Verify tax settings for shipping items

Debug Log Examples

[INFO] Starting credit note creation process
[INFO] Private customer identified
[API] API Request: POST /orders (Credit Note Creation)
[INFO] Found shipping item: Standard Shipping, total=10.00, tax=2.10
[INFO] Added shipping refund: Standard Shipping, total=10.00, tax=2.10
[API] API Response: HTTP 200 - Credit note created (ID: 2219544)
[INFO] Credit note PDF retrieval scheduled

๐Ÿ”ง Hooks & Filters for Developers

Available Actions

// Fired after successful operations
do_action('billit_invoice_created', $order_id, $invoice_data);
do_action('billit_credit_note_created', $order_id, $credit_note_data);
do_action('billit_pdf_retrieved', $order_id, $pdf_data);

// Before operations (allow modifications)
do_action('billit_before_invoice_creation', $order_id, &$payload);
do_action('billit_before_credit_note_creation', $order_id, &$payload);

Available Filters

// Modify customer data before sending
$customer_data = apply_filters('billit_customer_data', $customer_data, $order);

// Modify order lines before sending  
$order_lines = apply_filters('billit_order_lines', $order_lines, $order);

// Modify VAT detection results
$vat_number = apply_filters('billit_detected_vat', $vat_number, $order);

๐Ÿ“ˆ Performance Metrics

Typical Processing Times

  • Invoice Creation: 1-3 seconds
  • Credit Note Creation: 1-2 seconds
  • PDF Retrieval: 2-5 seconds
  • Peppol Sending: 3-10 seconds

Error Handling

  • Automatic Retries: 3 attempts for failed operations
  • Graceful Degradation: Continues processing even with non-critical failures
  • Comprehensive Logging: Full audit trail for troubleshooting

๐Ÿ”„ Version History

Current Version: 1.2.0

New in 1.2.0: โœ… Automatic Credit Note Payment Status: Credit notes now marked as paid automatically when refunds are issued โœ… Frontend PDF Display Control: New setting to show/hide invoices and credit notes on customer My Account page โœ… Performance Optimizations: Settings caching and updater caching (12-hour cache with force-check support) โœ… Security Enhancements: Directory protection files (index.php) in all subdirectories โœ… Version Consistency: Aligned plugin version constants across files

Core Features: โœ… Complete Billit API integration (invoices, credit notes, Peppol)
โœ… Advanced VAT detection and multi-country support โœ… Bi-directional PDF management system โœ… Comprehensive refund handling (products + shipping + fees) โœ… Professional admin interface with dual meta boxes โœ… Enterprise-grade error handling and logging โœ… WooCommerce HPOS compatibility โœ… POS system integration with company name cleaning

Admin Interface: โœ… Real-time AJAX operations with progress indicators โœ… PDF download icons in orders list overview
โœ… Separate meta boxes for operations and PDF management โœ… Manual override capabilities for all operations

Customer & VAT Handling: โœ… Automatic B2B/B2C classification โœ… VAT number extraction from multiple sources โœ… Company name cleaning for professional appearance โœ… Multi-country VAT format support and validation

๐Ÿ“ž Support & Development

For Technical Issues

  • ๐Ÿ› Plugin Issues: Check debug logs and verify configuration
  • ๐Ÿ”Œ API Issues: Consult Billit API documentation
  • ๐Ÿ›’ WooCommerce Issues: Ensure proper WooCommerce setup
  • ๐Ÿ“„ PDF Issues: Verify file permissions and media library access

Development Notes

This plugin represents approximately 12-15 hours of development creating an enterprise-grade integration that handles:

  • Complex multi-API interactions (Billit v1/v2 endpoints)
  • Advanced business logic for European VAT compliance
  • Sophisticated file management and PDF processing
  • Real-time UI with comprehensive admin interface
  • Production-ready error handling and logging systems

Status: Ready for production testing and deployment! ๐Ÿš€