Download the PHP package b2brouter/b2brouter-php without Composer
On this page you can find all versions of the php package b2brouter/b2brouter-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download b2brouter/b2brouter-php
More information about b2brouter/b2brouter-php
Files in b2brouter/b2brouter-php
Package b2brouter-php
Short Description B2Brouter PHP SDK - Official library for the B2Brouter API
License MIT
Homepage https://developer.b2brouter.net
Informations about the package b2brouter-php
B2BRouter PHP SDK
Official PHP SDK for the B2BRouter API - Electronic Invoicing and Tax Reporting
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Configuration
- Core Concepts
- Invoice Operations
- Tax Reports
- Spanish Invoicing with Verifactu
- Pagination
- Error Handling
- Examples
- Development
- Documentation
- Support
- License
Features
Core Functionality
- Complete invoice management - Create, retrieve, update, delete, import, validate, send, and acknowledge invoices
- Multi-format document downloads - Export invoices as PDF, Spanish Facturae XML, UBL BIS3, and other formats
- Tax report operations - Create, retrieve, list, download, update (corrections), and delete (annullations) tax reports
- Tax report settings - Configure and manage Verifactu, TicketBAI, and other tax authority settings
- Account management - List, create, retrieve, update, delete, unarchive accounts and manage logos
- Contact management - List, create, retrieve, update, and delete contacts
Developer Experience
- Simple and intuitive API - Clean, modern PHP interface with service-based architecture
- Zero dependencies - Runs on PHP 7.4+ with only standard extensions (cURL, JSON, mbstring)
- Automatic authentication - Secure API key management built-in
- Pagination support - Iterator and Countable implementations for easy traversal of large result sets
- Comprehensive error handling - Detailed exception hierarchy with HTTP status codes and request IDs
- Automatic retries - Network failures handled gracefully with exponential backoff (configurable)
- Type safety - Full PHP 7.4+ support with proper type hints
Compliance and Tax Reporting
- Spanish Verifactu - Full compliance with Spanish Anti-Fraud Law (Law 11/2021) and Royal Decree 1007/2023
- TicketBAI - Basque Country invoicing compliance with automatic submission
- QR code generation - Automatic QR codes for invoice verification (embedded in tax reports)
- Hash chain management - Tamper-proof audit trails computed and maintained automatically
- Automated AEAT submission - Real-time tax report submission to Spanish Tax Authority with rate limiting
- Multi-jurisdiction support - Architecture supports Italian SDI, Polish KSeF, Saudi Zatca, and more
Requirements
- PHP 7.4 or higher
- cURL extension
- JSON extension
- mbstring extension
Installation
Install via Composer:
Quick Start
Running Examples
The SDK includes comprehensive examples demonstrating all features. To run them:
1. Setup Environment
Your .env file should look like:
2. Install Dependencies
3. Run Examples
All examples use the environment variables from your .env file automatically.
Configuration
The client accepts several configuration options:
Default Environment: The SDK defaults to the staging environment (https://api-staging.b2brouter.net) for safe testing. To use production, set api_base to https://api.b2brouter.net.
Multi-version support: The SDK defaults to API version 2026-04-20. To use an older API version, pass it explicitly in the configuration:
Identifying your application
The SDK sends a User-Agent header on every request, identifying itself, the PHP runtime, and libcurl. Applications that wrap the SDK (integrators, plugins, custom tools) can identify themselves by passing app_info:
The resulting User-Agent is:
This helps B2BRouter support identify the SDK version and the integrating application when investigating support requests. See examples/identify_caller_app.php for a runnable demo.
Core Concepts
Invoice Operations
Create an Invoice
Retrieve an Invoice
Update an Invoice
Delete an Invoice
List Invoices
Download Invoice Documents
Download invoices as PDF or in various XML formats:
Note: Available document types depend on your B2Brouter account configuration and the invoice type. Use the B2Brouter API to get a complete list of available document types.
Import Invoices
Import invoices from external sources or systems:
Additional Operations
Account Operations
List Accounts
Retrieve an Account
Create an Account
Update, Delete, and Unarchive
Logo Management
Contact Operations
List Contacts
Create a Contact
Retrieve, Update, and Delete
Tax Reports
Tax reports are automatically generated based on the fiscal obligations of the invoice issuer. For example, issuers subject to Spanish Verifactu requirements will have tax reports automatically created when they send invoices.
Important: Before tax reports can be generated, you must configure your TaxReportSettings for the account. This can be done either:
- Via the SDK using
$client->taxReportSettingsoperations - Through the B2BRouter web interface
Once configured, tax reports will contain critical compliance information including QR codes for verification.
Configure Tax Report Settings
Configure Verifactu or TicketBAI settings for your account:
Create Tax Reports Directly
For Point of Sale systems or when not using B2BRouter invoices:
Retrieve Tax Reports
List Tax Reports
Download Tax Report XML
Update Tax Reports (Corrections)
Create corrections (subsanación) for Verifactu tax reports:
Delete Tax Reports (Annullations)
Create annullations (anulación) for tax reports:
Tax Report States
Tax reports go through several states:
- processing - Initial state, chaining and submission in progress
- registered - Successfully submitted and accepted by tax authority
- error - Submission failed
- registered_with_errors - Submitted but with warnings
- annulled - Cancelled/voided
For more details, see Tax Reports Documentation.
Spanish Invoicing with Verifactu
B2BRouter provides full compliance with the Spanish Anti-Fraud Law (Law 11/2021) and Verifactu requirements. When you create invoices for Spanish customers, B2BRouter automatically:
- Generates compliant tax reports
- Computes digital fingerprints and hash chains
- Submits reports to the Spanish Tax Authority (AEAT)
- Generates QR codes for invoice verification
- Handles rate limiting and retry logic
Complete Example
For comprehensive information about Spanish invoicing and Verifactu compliance, see the Spanish Invoicing Guide.
Pagination
The SDK provides automatic pagination support through the Collection class:
Paginate Through All Results
Error Handling
The SDK provides specific exception types for different error scenarios:
Request ID Logging
Always log the request ID when reporting errors to support:
Examples
The examples/ directory contains complete working examples demonstrating all SDK features:
Invoice Operations
- create_simple_invoice.php - Create a simple invoice with one line item
- create_detailed_invoice.php - Create a multi-line invoice with calculations
- download_invoice_documents.php - Download invoices as PDF and XML formats (Facturae, UBL BIS3)
- list_invoices.php - List and filter invoices with pagination
- paginate_all_invoices.php - Iterate through all invoices efficiently
- update_invoice.php - Update an existing invoice
- invoice_workflow.php - Complete invoice lifecycle (create, retrieve, validate, update, send)
- invoices.php - Comprehensive CRUD operations demo
Tax Reporting
- tax_reports.php - Complete CRUD operations for Verifactu and TicketBAI
- verifactu_tax_report.php - Verifactu-specific workflow with corrections and annullations
- ticketbai_tax_report.php - TicketBAI-specific workflow for Basque Country
- list_tax_reports.php - List and filter tax reports with analysis
- tax_report_setup.php - Configure tax report settings (Verifactu, TicketBAI)
Spanish Compliance
- invoicing_in_spain_with_verifactu.php - Complete example of Spanish invoicing with automatic Verifactu compliance, tax report generation, and QR code retrieval
Running Examples
-
Setup environment variables:
-
Install dependencies:
- Run any example:
All examples automatically load credentials from your .env file via examples/bootstrap.php.
Development
Running Tests
The SDK includes a comprehensive test suite. To run tests:
By default, composer test excludes external integration tests that make real HTTP requests to external services. This keeps the test suite fast and reliable for development.
For more information about contributing, setting up your development environment, and coding standards, see the Developer Guide.
API Reference
Complete Feature Matrix
The SDK provides comprehensive coverage of the B2BRouter API with the following operations:
Invoice Service ($client->invoices)
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
create() |
POST | /accounts/{account}/invoices |
Create a new invoice |
retrieve() |
GET | /invoices/{id} |
Retrieve invoice details |
update() |
PUT | /invoices/{id} |
Update an existing invoice |
delete() |
DELETE | /invoices/{id} |
Delete an invoice |
all() |
GET | /accounts/{account}/invoices |
List invoices (paginated) |
import() |
POST | /accounts/{account}/invoices/import |
Import invoice from external source |
validate() |
GET | /invoices/{id}/validate |
Validate invoice structure |
send() |
POST | /invoices/send_invoice/{id} |
Send invoice and generate tax reports |
acknowledge() |
POST | /invoices/{id}/ack |
Acknowledge received invoice |
markAs() |
POST | /invoices/{id}/mark_as |
Update invoice state |
downloadAs() |
GET | /invoices/{id}/as/{documentType} |
Download in specified format |
downloadPdf() |
GET | /invoices/{id}/as/pdf.invoice |
Download as PDF (convenience) |
Supported Download Formats:
pdf.invoice- PDF formatxml.facturae.3.2.2- Spanish Facturae XMLxml.ubl.invoice.bis3- Universal Business Language BIS3- Additional formats per account configuration
Common Query Parameters:
- Pagination:
offset,limit(max 500) - Date filtering:
date_from,date_to,due_date_from,due_date_to - State filtering:
new,sent,paid,error,refused, etc. - Search:
number
Tax Report Service ($client->taxReports)
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
create() |
POST | /accounts/{account}/tax_reports |
Create tax report directly |
retrieve() |
GET | /tax_reports/{id} |
Retrieve tax report with QR code |
all() |
GET | /accounts/{account}/tax_reports |
List tax reports (paginated) |
download() |
GET | /tax_reports/{id}/download |
Download XML representation |
update() |
PATCH | /tax_reports/{id} |
Create correction (subsanación) |
delete() |
DELETE | /tax_reports/{id} |
Create annullation (anulación) |
Supported Tax Report Types:
Verifactu- Spanish compliance (AEAT)TicketBai- Basque Country complianceSDI- Italian Sistema di InterscambioKSeF- Polish National e-Invoicing SystemZatca- Saudi Arabian e-invoicing
Tax Report States:
processing- Being chained and preparedregistered- Successfully submittederror- Submission failedregistered_with_errors- Submitted with warningsannulled- Cancelled
Query Parameters:
invoice_id- Filter by invoicesent_at_from,sent_at_to- Filter by submission dateupdated_at_from,updated_at_to- Filter by update date
Tax Report Setting Service ($client->taxReportSettings)
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
create() |
POST | /accounts/{account}/tax_report_settings |
Configure tax authority settings |
retrieve() |
GET | /accounts/{account}/tax_report_settings/{code} |
Get specific settings |
update() |
PUT | /accounts/{account}/tax_report_settings/{code} |
Update settings |
all() |
GET | /accounts/{account}/tax_report_settings |
List all settings |
delete() |
DELETE | /accounts/{account}/tax_report_settings/{code} |
Delete settings |
Common Setting Codes:
VeriFactu- Spanish Verifactu configurationTicketBai- TicketBAI configuration
Account Service ($client->accounts)
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
all() |
GET | /accounts |
List accounts (paginated) |
create() |
POST | /accounts |
Create a new account |
retrieve() |
GET | /accounts/{id} |
Retrieve an account |
update() |
PUT | /accounts/{id} |
Update an account |
delete() |
DELETE | /accounts/{id} |
Archive/delete an account |
unarchive() |
POST | /accounts/{id}/unarchive |
Unarchive an account |
uploadLogo() |
POST | /accounts/{id}/logo |
Upload account logo |
deleteLogo() |
DELETE | /accounts/{id}/logo |
Delete account logo |
Query Parameters:
- Pagination:
offset,limit(max 500) - Filtering:
query(Ransack syntax —tin_value,country,name,status, etc.)
Contact Service ($client->contacts)
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
all() |
GET | /accounts/{account}/contacts |
List contacts (paginated) |
create() |
POST | /accounts/{account}/contacts |
Create a contact |
retrieve() |
GET | /contacts/{id} |
Retrieve a contact |
update() |
PUT | /contacts/{id} |
Update a contact |
delete() |
DELETE | /contacts/{id} |
Delete a contact |
Query Parameters:
- Pagination:
offset,limit(max 500) - Filtering:
name,is_client,is_provider,integration_code
SDK Architecture
Core Classes
- B2BRouterClient - Main client with configuration and service access
- ApiResource - Base class for all API operations with request handling
- Collection - Paginated result wrapper (implements Iterator, Countable)
Service Classes
- AccountService - Account operations (lib/B2BRouter/Service/AccountService.php:1)
- ContactService - Contact operations (lib/B2BRouter/Service/ContactService.php:1)
- InvoiceService - All invoice operations (lib/B2BRouter/Service/InvoiceService.php:1)
- TaxReportService - Tax report operations (lib/B2BRouter/Service/TaxReportService.php:1)
- TaxReportSettingService - Settings management (lib/B2BRouter/Service/TaxReportSettingService.php:1)
Exception Hierarchy
All exceptions extend ApiErrorException and include:
- HTTP status code
- Request ID (for support)
- Response body (JSON)
- HTTP headers
Configuration Options
Default Values:
api_base:https://api-staging.b2brouter.net(staging)api_version:2026-04-20timeout:80secondsmax_retries:3attemptsapp_info: not set (only the SDK self-identifies inUser-Agent)
Documentation
SDK Documentation
- API Reference - Complete PHP SDK reference with all methods, parameters, and examples
- Spanish Invoicing Guide - Comprehensive guide for Spanish Verifactu compliance
- Tax Reports Documentation - Detailed tax reporting documentation for Verifactu and TicketBAI
- Developer Guide - Contributing, development setup, and IDE configuration
- Versioning Policy - SDK versioning policy and API version migration guidance
B2BRouter Platform Documentation
- B2BRouter API Reference - REST API documentation
- Verifactu Guide - Complete B2BRouter Verifactu guide
- Developer Portal - Guides, tutorials, and integration resources
Support
- Documentation: https://developer.b2brouter.net
- Email: [email protected]
- Issues: Please report bugs and feature requests via GitHub Issues
When reporting issues, please include:
- PHP version
- SDK version
- Request ID (from error exceptions)
- Minimal code to reproduce the issue
License
This library is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
All versions of b2brouter-php with dependencies
ext-curl Version *
ext-json Version *
ext-mbstring Version *