factuarea / factuarea-php
Requires
- php: >=8.2
- brick/date-time: >=0.7.0
- brick/math: >=0.12.1
- galbar/jsonpath: >=3.0
- guzzlehttp/guzzle: ^7.0
- phpdocumentor/type-resolver: >=1.8
- speakeasy/serializer: ^4.0.3
Requires (Dev)
- laravel/pint: 1.29.0
- phpstan/phpstan: 2.1.44
- phpunit/phpunit: ^11.5.50 || ^12.5.8 || >=13.0.0
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2026-06-07 11:13:42 UTC
README
Official PHP SDK for the Factuarea public API — invoicing, quotes, proformas, delivery notes, products, clients, suppliers, taxes, VeriFactu and webhooks for Spanish businesses.
Type-safe, PSR-4, built on Guzzle, with automatic retries, automatic idempotency, cursor auto-pagination, typed errors and a webhook signature verifier.
Status: pre-GA (
0.x). The method surface follows the stable SDK method naming contract and is protected by SemVer, but0.xsignals the API may still evolve before GA.
Installation
Not yet on Packagist — coming soon. Until the package is published you can install it directly from GitHub.
Once published:
composer require factuarea/factuarea-php
Until then, install from the repository by adding it to your composer.json:
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/factuarea/factuarea-php" }
],
"require": {
"factuarea/factuarea-php": "dev-main"
}
}
then run composer update.
Requirements: PHP 8.2 or higher, with the json and mbstring extensions
(both bundled with standard PHP builds).
Quickstart
<?php require 'vendor/autoload.php'; use Factuarea\Sdk\Custom\FactuareaClient; // The key prefix selects the environment: // fact_test_… → sandbox fact_live_… → production $factuarea = FactuareaClient::create(getenv('FACTUAREA_API_KEY')); // List the first page of invoices. $response = $factuarea->invoices->publicApiV1InvoicesList(); foreach ($response->paginatedList?->data ?? [] as $invoice) { echo $invoice->id, PHP_EOL; }
FactuareaClient::create() is the recommended entry point: it wires Bearer
authentication and registers the automatic Idempotency-Key behaviour for you.
For advanced configuration (custom Guzzle client, custom retry policy, staging
base URL) the generated builder is still available:
use Factuarea\Sdk\Factuarea; use Factuarea\Sdk\Models\Components\Security; $factuarea = Factuarea::builder() ->setSecurity(new Security(bearerAuth: getenv('FACTUAREA_API_KEY'))) ->build();
Server-side only. A secret API key must never ship in a browser or mobile app. Load it from an environment variable or secret manager.
Sandbox (test mode)
Every API key belongs to one of two environments, decided by its prefix — there is no environment flag in the SDK:
| Prefix | Environment | External effects |
|---|---|---|
fact_test_ |
sandbox | Neutralized — VeriFactu/AEAT, emails and webhooks are off |
fact_live_ |
production | Real fiscal numbering, VeriFactu→AEAT, emails, webhooks |
A fact_test_ key operates on an isolated sandbox company with the same
functional surface as production. Always integrate against a fact_test_ key
first, then switch the prefix to fact_live_ to go live.
$sandbox = FactuareaClient::create('fact_test_…'); $prod = FactuareaClient::create('fact_live_…');
Runtime features
Automatic retries
Transient failures (429 and 5xx) are retried with exponential backoff,
honouring the server's Retry-After header. Client errors (4xx other than
429) are never retried. Retries reuse the same request — including its
Idempotency-Key — so a retried mutation is idempotent end to end.
Automatic idempotency
Every mutating request (POST, PUT, PATCH, DELETE) gets a generated
Idempotency-Key (UUID v4) unless you supply one explicitly:
// Auto-generated key — safe to retry. $factuarea->invoices->publicApiV1InvoicesCreate($body); // Or pin your own key for app-level deduplication. $factuarea->invoices->publicApiV1InvoicesCreate($body, idempotencyKey: 'order-4711');
Replaying a request with the same key returns the original result and the
response carries Idempotent-Replayed: true.
Cursor auto-pagination
List endpoints return the cursor envelope { data, has_more, next_cursor }. The
PageIterator helper streams every item across all pages without manual cursor
handling:
use Factuarea\Sdk\Custom\Pagination\PageIterator; use Factuarea\Sdk\Models\Operations\PublicApiV1InvoicesListRequest; $pages = new PageIterator( fn (?string $cursor) => $factuarea->invoices->publicApiV1InvoicesList( new PublicApiV1InvoicesListRequest(startingAfter: $cursor), )->rawResponse, ); foreach ($pages->items() as $invoice) { // one invoice at a time, across every page }
Typed errors
Documented API errors (401, 403, 409, 422, 429, 5xx) are thrown as a
typed ErrorThrowable exposing the full error envelope — including the
request_id you can quote to support. The API key is never included in any
exception message.
use Factuarea\Sdk\Models\Errors\ErrorThrowable; try { $factuarea->invoices->publicApiV1InvoicesCreate($body); } catch (ErrorThrowable $e) { $error = $e->container->error; echo $error->type->value; // e.g. "invalid_request_error" echo $error->code; // e.g. "parameter_invalid" echo $error->param; // e.g. "client_id" echo $error->requestId; // e.g. "req_abc123" — quote this to support }
Webhook signature verification
Factuarea signs every webhook delivery with HMAC-SHA256 in the
Factuarea-Signature header (t=<unix>,v1=<hex>). Verify deliveries with a
constant-time check and replay protection:
use Factuarea\Sdk\Custom\Webhooks\WebhookVerifier; use Factuarea\Sdk\Custom\Webhooks\WebhookSignatureException; $verifier = new WebhookVerifier(); $rawBody = file_get_contents('php://input'); $signature = $_SERVER['HTTP_FACTUAREA_SIGNATURE'] ?? ''; try { $event = $verifier->verify($rawBody, $signature, getenv('FACTUAREA_WEBHOOK_SECRET')); // $event is the decoded, authenticated payload } catch (WebhookSignatureException $e) { http_response_code(400); }
The verifier accepts deliveries during a secret-rotation grace window (the header
may carry both the new and previous v1 signatures) and rejects payloads whose
timestamp is outside the tolerance (default 5 minutes, configurable).
API reference
The full, generated reference for all resources and operations lives in
docs/sdks/. Method names follow the deterministic
operationId → method mapping (e.g. public-api.v1.invoices.mark_paid →
$factuarea->invoices->publicApiV1InvoicesMarkPaid(...)).
Versioning
The SDK pins the Factuarea-Version it was generated against (currently
2026-06-04) and sends it on every request, so the API behaves consistently
until you upgrade. SemVer applies to the SDK's public surface: new operations are
a minor bump, renames/removals or a behaviour-changing Factuarea-Version bump
are a major bump, fixes are a patch. The SDK stays on 0.x until the API's GA,
which ships 1.0.0.
See docs/VERSIONING.md for the full Factuarea-Version ↔
SDK-version mapping and CHANGELOG.md for release history.
Support
| Aspect | Supported |
|---|---|
| PHP | 8.2, 8.3, 8.4 (tested in CI) |
| Stability | Pre-GA 0.x — the public surface may change before 1.0.0 |
Factuarea-Version |
2026-06-04 (pinned, sent on every request) |
Full runtime-support matrix and the deprecation / breaking-change policy live in
SUPPORT.md.
Development
This SDK is generated with Speakeasy from the pinned
OpenAPI document in spec/openapi.json. Generated code lives
in src/ (managed by Speakeasy); hand-written runtime helpers live in
src/Custom/ and are never overwritten by regeneration. See
docs/REGENERATION.md for how to regenerate (and the
documented fallback to openapi-generator).
composer install composer test # PHPUnit, HTTP fully mocked — no network composer stan # PHPStan static analysis
License
MIT © Factuarea. Contact: info@factuarea.com
Summary
Factuarea Public API: Public REST API for invoicing in Spain — manage invoices, quotes, proformas, delivery notes, products, clients and webhooks.
Authentication
The API authenticates with a secret API key, sent on every request as:
Authorization: Bearer fact_live_xxxxxxxxxxxxxxxxxxxxxxxx
or, alternatively, in the X-API-Key header. The key is issued from the Factuarea portal and must NEVER be exposed in public clients (browser, mobile apps).
Environments: live and test
Each API key belongs to one of two environments, unambiguously identifiable by its prefix:
| Prefix | Environment | Data it operates on | External effects |
|---|---|---|---|
fact_live_ |
live (production) | Your real company | Real: legal fiscal numbering, VeriFactu→AEAT, emails to clients, outbound webhooks |
fact_test_ |
test (sandbox) | An isolated sandbox company | Neutralized (see below) |
The prefix is the source of truth for the environment: a fact_test_ key always operates in test mode and a fact_live_ key always in live. There is no request parameter that changes the environment — it is determined by the key.
Data isolation (sandbox)
fact_test_ keys operate on a dedicated sandbox company (a technical "twin company" of the account holder, automatically provisioned the first time test mode is used, which inherits the plan of your real company for faithful feature-gating). Thanks to per-company data isolation:
- Resources created with a
fact_test_key are not visible from afact_live_key, and vice versa. - Test fiscal numbering uses the sandbox's own series and never consumes or alters the sequential numbering of your production series.
The functional surface is identical in both environments: the same endpoints and operations are available in test as in live.
External effects neutralized in test
When you operate with a fact_test_ key (sandbox environment), outbound effects are disabled so you can test your integration without real consequences:
- VeriFactu: the Alta record is created locally, but not transmitted to AEAT.
- Email: document emails are not delivered to real recipients.
- Webhooks: events are not delivered to your external HTTP endpoints.
In live, all these effects fire normally.
Recommendation: always integrate and test first with a
fact_test_key. Once your flow works, switch to thefact_live_prefix to operate in production.
Table of Contents
SDK Installation
Tip
To finish publishing your SDK you must run your first generation action.
The SDK relies on Composer to manage its dependencies.
To install the SDK first add the below to your composer.json file:
{
"repositories": [
{
"type": "github",
"url": "<UNSET>.git"
}
],
"require": {
"factuarea/factuarea-php": "*"
}
}
Then run the following command:
composer update
SDK Example Usage
Example
declare(strict_types=1); require 'vendor/autoload.php'; use Factuarea\Sdk; use Factuarea\Sdk\Models\Components; $sdk = Sdk\Factuarea::builder() ->setSecurity( new Components\Security( http: '<YOUR_BEARER_TOKEN_HERE>', ) ) ->build(); $body = new Components\AcceptProformaRequest( reason: 'Cliente confirma pedido por telefono', ); $response = $sdk->proformas->publicApiV1ProformasAccept( proforma: '<value>', idempotencyKey: '01928f10-7c0e-7c4a-9b7d-2f8a6e3c1d4b', body: $body ); if ($response->object !== null) { // handle response }
Authentication
Per-Client Security Schemes
This SDK supports the following security schemes globally:
| Name | Type | Scheme |
|---|---|---|
http |
http | HTTP Bearer |
bearerAuth |
http | HTTP Bearer |
apiKeyAuth |
apiKey | API key |
You can set the security parameters through the setSecurity function on the SDKBuilder when initializing the SDK. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use Factuarea\Sdk; use Factuarea\Sdk\Models\Components; $sdk = Sdk\Factuarea::builder() ->setSecurity( new Components\Security( http: '<YOUR_BEARER_TOKEN_HERE>', ) ) ->build(); $body = new Components\AcceptProformaRequest( reason: 'Cliente confirma pedido por telefono', ); $response = $sdk->proformas->publicApiV1ProformasAccept( proforma: '<value>', idempotencyKey: '01928f10-7c0e-7c4a-9b7d-2f8a6e3c1d4b', body: $body ); if ($response->object !== null) { // handle response }
Available Resources and Operations
Available methods
Account
- publicApiV1AccountShow - Retrieve account details
Clients
- publicApiV1ClientsBulkDelete - Delete multiple clients in bulk
publicApiV1ClientsBulkDeleteLegacy- Delete multiple clients in bulk (deprecated alias) ⚠️ Deprecated- publicApiV1ClientsCreate - Create a client
- publicApiV1ClientsList - List all clients
- publicApiV1ClientsDelete - Delete a client
- publicApiV1ClientsShow - Retrieve a client
- publicApiV1ClientsUpdate - Update a client
- publicApiV1ClientsFindByTaxId - Find a client by tax ID
- publicApiV1ClientsActivities - List client activity timeline
- publicApiV1ClientsStats - Get client stats
- publicApiV1ClientsSearch - Search clients
DeliveryNotes
- publicApiV1DeliveryNotesBulkDelete - Bulk delete delivery notes
- publicApiV1DeliveryNotesCancel - Cancel a delivery note
publicApiV1DeliveryNotesChangeStatus- Change delivery note status (deprecated) ⚠️ Deprecated- publicApiV1DeliveryNotesConvert - Convert delivery note to invoice
- publicApiV1DeliveryNotesCreate - Create a delivery note
- publicApiV1DeliveryNotesList - List all delivery notes
- publicApiV1DeliveryNotesDelete - Delete a delivery note
- publicApiV1DeliveryNotesShow - Retrieve a delivery note
- publicApiV1DeliveryNotesUpdate - Update a delivery note
- publicApiV1DeliveryNotesPdf - Download delivery note PDF
- publicApiV1DeliveryNotesDuplicate - Duplicate a delivery note
- publicApiV1DeliveryNotesStats - Retrieve delivery note stats
- publicApiV1DeliveryNotesStatuses - List delivery note statuses
- publicApiV1DeliveryNotesMarkDelivered - Mark delivery note as delivered
- publicApiV1DeliveryNotesSend - Send a delivery note
- publicApiV1DeliveryNotesSign - Sign a delivery note
DeliveryNotes.PublicLink
- publicApiV1DeliveryNotesPublicLinkGet - Retrieve a delivery note public link
- publicApiV1DeliveryNotesPublicLinkUpdate - Update a delivery note public link
DeliveryNotes.SignatureAudits
- publicApiV1DeliveryNotesSignatureAuditsForget - Forget delivery note signature PII
EventCatalog
- publicApiV1EventCatalogList - List event types
Events
- publicApiV1EventsList - List all events
- publicApiV1EventsShow - Retrieve an event
Invoices
- publicApiV1InvoicesAnnul - Annul an invoice
- publicApiV1InvoicesAssignRealNumber - Assign a real invoice number
- publicApiV1InvoicesBulkDelete - Bulk delete invoices
- publicApiV1InvoicesCanAnnul - Check annulment eligibility
- publicApiV1InvoicesSimplifiedEligibility - Check simplified invoice eligibility
- publicApiV1InvoicesCorrective - Generate corrective invoice
- publicApiV1InvoicesCreate - Create an invoice
- publicApiV1InvoicesList - List all invoices
- publicApiV1InvoicesVerifactuCreate - Force-create VeriFactu record for invoice
- publicApiV1InvoicesVerifactuGet - Retrieve invoice VeriFactu record
- publicApiV1InvoicesDelete - Delete an invoice
- publicApiV1InvoicesShow - Retrieve an invoice
- publicApiV1InvoicesUpdate - Update an invoice
- publicApiV1InvoicesFacturae - Download FacturaE XML
- publicApiV1InvoicesPdf - Download invoice PDF
- publicApiV1InvoicesDuplicate - Duplicate an invoice
- publicApiV1InvoicesFindByNumber - Find an invoice by number
- publicApiV1InvoicesPdfLink - Generate signed PDF link
- publicApiV1InvoicesPublicLinkGet - Retrieve invoice public link
- publicApiV1InvoicesPublicLinkUpdate - Update invoice public link
- publicApiV1InvoicesStats - Get invoice statistics
- publicApiV1InvoicesActivities - List invoice activity
- publicApiV1InvoicesCorrectives - List corrective invoices
- publicApiV1InvoicesStatuses - List invoice statuses
- publicApiV1InvoicesMarkPaid - Mark invoice as paid
- publicApiV1InvoicesMarkSent - Mark an invoice as sent
- publicApiV1InvoicesReminderPreview - Preview a payment reminder email
- publicApiV1InvoicesPaymentReceipt - Download payment receipt PDF
- publicApiV1InvoicesSend - Send invoice by email
- publicApiV1InvoicesSendReminder - Send a payment reminder
- publicApiV1InvoicesSubstituteSimplified - Substitute simplified invoices with full invoice
- publicApiV1InvoicesVoid - Void an invoice
Invoices.Quarterly
- publicApiV1InvoicesQuarterlyAvailable - List quarters with invoices
- publicApiV1InvoicesQuarterlyDownloadZip - Generate quarterly ZIP archive
- publicApiV1InvoicesQuarterlySendEmail - Email quarterly ZIP to accountant
Products
- publicApiV1ProductsBulkDelete - Delete multiple products in bulk
- publicApiV1ProductsBulkUpdateStock - Update stock for many products
- publicApiV1ProductsCreate - Create a product
- publicApiV1ProductsList - List all products
- publicApiV1ProductsDelete - Delete a product
- publicApiV1ProductsShow - Retrieve a product
- publicApiV1ProductsUpdate - Update a product
- publicApiV1ProductsFindBySku - Find a product by SKU
- publicApiV1ProductsLowStockReport - List products below the stock threshold
- publicApiV1ProductsActivities - List product activity timeline
- publicApiV1ProductsSalesAnalytics - Get product sales analytics
- publicApiV1ProductsStats - Get product stats
- publicApiV1ProductsSearch - Search products
- publicApiV1ProductsToggleActive - Toggle product active state
- publicApiV1ProductsUpdateStock - Update product stock
Products.Gallery
- publicApiV1ProductsGalleryDelete - Remove a gallery image from a product
- publicApiV1ProductsGalleryDownload - Download a product gallery image binary
- publicApiV1ProductsGalleryUpload - Upload a gallery image to a product
Products.Video
- publicApiV1ProductsVideoDelete - Remove the product video
- publicApiV1ProductsVideoUpload - Upload a video to a product
- publicApiV1ProductsVideoDownload - Download the product video binary
Proformas
- publicApiV1ProformasAccept - Accept a proforma
- publicApiV1ProformasBulkDelete - Bulk delete proformas
- publicApiV1ProformasConvert - Convert proforma to invoice
- publicApiV1ProformasCreate - Create a proforma
- publicApiV1ProformasList - List all proformas
- publicApiV1ProformasDelete - Delete a proforma
- publicApiV1ProformasShow - Retrieve a proforma
- publicApiV1ProformasUpdate - Update a proforma
- publicApiV1ProformasPdf - Download proforma PDF
- publicApiV1ProformasDuplicate - Duplicate a proforma
- publicApiV1ProformasPublicLinkGet - Retrieve proforma public link
- publicApiV1ProformasPublicLinkUpdate - Update proforma public link
- publicApiV1ProformasStats - Get proforma stats
- publicApiV1ProformasStatuses - List proforma statuses
- publicApiV1ProformasReject - Reject a proforma
- publicApiV1ProformasSend - Send proforma by email
PurchaseInvoices
- publicApiV1PurchaseInvoicesAttachFile - Attach a file to a purchase invoice
- publicApiV1PurchaseInvoicesBulkDelete - Bulk delete purchase invoices
- publicApiV1PurchaseInvoicesCreate - Create a purchase invoice
- publicApiV1PurchaseInvoicesList - List all purchase invoices
- publicApiV1PurchaseInvoicesDelete - Delete a purchase invoice
- publicApiV1PurchaseInvoicesShow - Retrieve a purchase invoice
- publicApiV1PurchaseInvoicesUpdate - Update a purchase invoice
- publicApiV1PurchaseInvoicesDeleteFile - Remove a purchase invoice file
- publicApiV1PurchaseInvoicesFile - Download the original purchase invoice file
- publicApiV1PurchaseInvoicesPaymentReceipt - Download a purchase invoice payment receipt
- publicApiV1PurchaseInvoicesStats - Get purchase invoice stats
- publicApiV1PurchaseInvoicesOverdue - List overdue purchase invoices
- publicApiV1PurchaseInvoicesPending - List pending purchase invoices
publicApiV1PurchaseInvoicesBySupplier- List purchase invoices by supplier ⚠️ Deprecated- publicApiV1PurchaseInvoicesMarkPaid - Mark purchase invoice as paid
Quotes
- publicApiV1QuotesAccept - Accept a quote
- publicApiV1QuotesBulkDelete - Bulk delete quotes
- publicApiV1QuotesConvert - Convert quote to invoice
- publicApiV1QuotesCreate - Create a quote
- publicApiV1QuotesList - List all quotes
- publicApiV1QuotesDelete - Delete a quote
- publicApiV1QuotesShow - Retrieve a quote
- publicApiV1QuotesUpdate - Update a quote
- publicApiV1QuotesPdf - Download quote PDF
- publicApiV1QuotesDuplicate - Duplicate a quote
- publicApiV1QuotesPublicLinkGet - Retrieve quote public link
- publicApiV1QuotesPublicLinkUpdate - Update quote public link
- publicApiV1QuotesStats - Get quote stats
- publicApiV1QuotesStatuses - List quote statuses
- publicApiV1QuotesReject - Reject a quote
- publicApiV1QuotesSend - Send quote by email
RecurringInvoices
- publicApiV1RecurringInvoicesActivate - Activate recurring invoice
- publicApiV1RecurringInvoicesBulkDelete - Bulk delete recurring invoices
- publicApiV1RecurringInvoicesCancel - Cancel recurring invoice
- publicApiV1RecurringInvoicesCreate - Create a recurring invoice
- publicApiV1RecurringInvoicesList - List all recurring invoices
- publicApiV1RecurringInvoicesDelete - Delete a recurring invoice
- publicApiV1RecurringInvoicesShow - Retrieve a recurring invoice
- publicApiV1RecurringInvoicesUpdate - Update a recurring invoice
- publicApiV1RecurringInvoicesGenerate - Generate an invoice from a recurring template
- publicApiV1RecurringInvoicesStats - Retrieve recurring invoice stats
- publicApiV1RecurringInvoicesActivities - List recurring invoice activity
- publicApiV1RecurringInvoicesLogs - List recurring invoice execution logs
- publicApiV1RecurringInvoicesPause - Pause recurring invoice
- publicApiV1RecurringInvoicesPreview - Preview upcoming recurring invoice dates
- publicApiV1RecurringInvoicesResume - Resume recurring invoice
Series
- publicApiV1SeriesArchive - Archive a series
- publicApiV1SeriesCreate - Create a series
- publicApiV1SeriesList - List all series
- publicApiV1SeriesFindByCode - Find a series by code
- publicApiV1SeriesDefault - Get the default series for a document type
- publicApiV1SeriesActivities - List series activity timeline
- publicApiV1SeriesStats - Get series stats
- publicApiV1SeriesActive - List active series by document type
- publicApiV1SeriesSetDefault - Mark a series as default for its type
- publicApiV1SeriesShow - Retrieve a series
- publicApiV1SeriesUnarchive - Unarchive a series
Suppliers
- publicApiV1SuppliersBulkDelete - Delete multiple suppliers in bulk
publicApiV1SuppliersBulkDeleteLegacy- Delete multiple suppliers in bulk (deprecated alias) ⚠️ Deprecated- publicApiV1SuppliersCreate - Create a supplier
- publicApiV1SuppliersList - List all suppliers
- publicApiV1SuppliersDelete - Delete a supplier
- publicApiV1SuppliersShow - Retrieve a supplier
- publicApiV1SuppliersUpdate - Update a supplier
- publicApiV1SuppliersFindByTaxId - Find a supplier by tax ID
- publicApiV1SuppliersActivities - List supplier activity timeline
- publicApiV1SuppliersStats - Get supplier stats
- publicApiV1SuppliersSearch - Search suppliers
- publicApiV1SuppliersToggleActive - Toggle supplier active state
Taxes
- publicApiV1TaxesCalculate - Calculate a tax over a base amount
- publicApiV1TaxesCalculateTotals - Calculate totals for a set of lines
- publicApiV1TaxesIsInUse - Check whether a tax is in use
- publicApiV1TaxesCreate - Create a tax
- publicApiV1TaxesList - List all taxes
- publicApiV1TaxesDelete - Delete a tax
- publicApiV1TaxesShow - Retrieve a tax
- publicApiV1TaxesUpdate - Update a tax
- publicApiV1TaxesActive - List active taxes
- publicApiV1TaxesDefaults - Get default taxes for a document type
- publicApiV1TaxesStats - Get tax stats
- publicApiV1TaxesByType - List taxes filtered by type
- publicApiV1TaxesForPurchases - List taxes applicable to purchases
- publicApiV1TaxesForSales - List taxes applicable to sales
- publicApiV1TaxesSetDefault - Mark a tax as the default for its type
- publicApiV1TaxesSetDefaultForDocument - Set tax default for a document type
- publicApiV1TaxesToggle - Toggle tax active state
TaxReports
- publicApiV1TaxReportsDownload - Download tax report file
- publicApiV1TaxReportsFindByPeriod - Find a tax report by period
- publicApiV1TaxReportsGenerate303 - Generate Modelo 303
- publicApiV1TaxReportsGenerate347 - Generate Modelo 347
- publicApiV1TaxReportsActivities - List tax report activities
- publicApiV1TaxReportsStats - Retrieve tax report stats
- publicApiV1TaxReportsHistory - List tax report history
- publicApiV1TaxReportsPreview - Preview a tax report
Verifactu
- publicApiV1VerifactuConfig - Retrieve VeriFactu config
- publicApiV1VerifactuStats - Get VeriFactu stats
Verifactu.AeatAccess
- publicApiV1VerifactuAeatAccessList - List AEAT access records
- publicApiV1VerifactuAeatAccessShow - Retrieve an AEAT access record
Verifactu.Certificates
- publicApiV1VerifactuCertificatesActivate - Activate a company certificate
- publicApiV1VerifactuCertificatesActive - Retrieve the active certificate
- publicApiV1VerifactuCertificatesList - List company certificates
- publicApiV1VerifactuCertificatesUpload - Upload a company certificate
- publicApiV1VerifactuCertificatesRevoke - Revoke a company certificate
Verifactu.Chain
- publicApiV1VerifactuChainValidate - Validate the VeriFactu hash chain
Verifactu.Declaracion
- publicApiV1VerifactuDeclaracionHistory - List declaración responsable history
- publicApiV1VerifactuDeclaracionCurrent - Retrieve the current declaración responsable
Verifactu.Events
- publicApiV1VerifactuEventsSummary - Get VeriFactu event summary
- publicApiV1VerifactuEventsList - List VeriFactu events
- publicApiV1VerifactuEventsRetry - Retry a VeriFactu event
- publicApiV1VerifactuEventsShow - Retrieve a VeriFactu event
Verifactu.Records
- publicApiV1VerifactuRecordsFindByCsv - Find a VeriFactu record by AEAT CSV
- publicApiV1VerifactuRecordsFindByHuella - Find a VeriFactu record by hash
- publicApiV1VerifactuRecordsFindByInvoiceNumber - Find a VeriFactu record by invoice number
- publicApiV1VerifactuRecordsActivities - List VeriFactu record activity timeline
- publicApiV1VerifactuRecordsList - List VeriFactu records
- publicApiV1VerifactuRecordsRetry - Retry VeriFactu transmission
- publicApiV1VerifactuRecordsShow - Retrieve a VeriFactu record
Verifactu.Settings
- publicApiV1VerifactuSettingsUpdate - Update VeriFactu settings
WebhookEndpoints
- publicApiV1WebhookEndpointsCreate - Create a webhook endpoint
- publicApiV1WebhookEndpointsList - List all webhook endpoints
- publicApiV1WebhookEndpointsDelete - Delete a webhook endpoint
- publicApiV1WebhookEndpointsShow - Retrieve a webhook endpoint
- publicApiV1WebhookEndpointsUpdate - Update a webhook endpoint
- publicApiV1WebhookEndpointsPing - Ping webhook endpoint
- publicApiV1WebhookEndpointsRotateSecret - Rotate webhook secret
WebhookEndpoints.Deliveries
- publicApiV1WebhookEndpointsDeliveriesList - List webhook deliveries
- publicApiV1WebhookEndpointsDeliveriesReplay - Replay webhook delivery
- publicApiV1WebhookEndpointsDeliveriesShow - Retrieve webhook delivery
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned object will be a Generator instead of an individual response.
Working with generators is as simple as iterating over the responses in a foreach loop, and you can see an example below:
declare(strict_types=1); require 'vendor/autoload.php'; use Factuarea\Sdk; use Factuarea\Sdk\Models\Components; $sdk = Sdk\Factuarea::builder() ->setSecurity( new Components\Security( http: '<YOUR_BEARER_TOKEN_HERE>', ) ) ->build(); $responses = $sdk->recurringInvoices->publicApiV1RecurringInvoicesLogs( recurringInvoice: '<value>', perPage: '25' ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } }
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide an Options object built with a RetryConfig object to the call:
declare(strict_types=1); require 'vendor/autoload.php'; use Factuarea\Sdk; use Factuarea\Sdk\Models\Components; use Factuarea\Sdk\Utils\Retry; $sdk = Sdk\Factuarea::builder() ->setSecurity( new Components\Security( http: '<YOUR_BEARER_TOKEN_HERE>', ) ) ->build(); $body = new Components\AcceptProformaRequest( reason: 'Cliente confirma pedido por telefono', ); $response = $sdk->proformas->publicApiV1ProformasAccept( proforma: '<value>', idempotencyKey: '01928f10-7c0e-7c4a-9b7d-2f8a6e3c1d4b', body: $body, options: Utils\Options->builder()->setRetryConfig( new Retry\RetryConfigBackoff( initialInterval: 1, maxInterval: 50, exponent: 1.1, maxElapsedTime: 100, retryConnectionErrors: false, ))->build() ); if ($response->object !== null) { // handle response }
If you'd like to override the default retry strategy for all operations that support retries, you can pass a RetryConfig object to the SDKBuilder->setRetryConfig function when initializing the SDK:
declare(strict_types=1); require 'vendor/autoload.php'; use Factuarea\Sdk; use Factuarea\Sdk\Models\Components; use Factuarea\Sdk\Utils\Retry; $sdk = Sdk\Factuarea::builder() ->setRetryConfig( new Retry\RetryConfigBackoff( initialInterval: 1, maxInterval: 50, exponent: 1.1, maxElapsedTime: 100, retryConnectionErrors: false, ) ) ->setSecurity( new Components\Security( http: '<YOUR_BEARER_TOKEN_HERE>', ) ) ->build(); $body = new Components\AcceptProformaRequest( reason: 'Cliente confirma pedido por telefono', ); $response = $sdk->proformas->publicApiV1ProformasAccept( proforma: '<value>', idempotencyKey: '01928f10-7c0e-7c4a-9b7d-2f8a6e3c1d4b', body: $body ); if ($response->object !== null) { // handle response }
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\APIException exception, which has the following properties:
| Property | Type | Description |
|---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the publicApiV1ProformasAccept method throws the following exceptions:
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\Error | 401, 403, 409, 422, 429 | application/json |
| Errors\Error | 500 | application/json |
| Errors\APIException | 4XX, 5XX | */* |
Example
declare(strict_types=1); require 'vendor/autoload.php'; use Factuarea\Sdk; use Factuarea\Sdk\Models\Components; use Factuarea\Sdk\Models\Errors; $sdk = Sdk\Factuarea::builder() ->setSecurity( new Components\Security( http: '<YOUR_BEARER_TOKEN_HERE>', ) ) ->build(); try { $body = new Components\AcceptProformaRequest( reason: 'Cliente confirma pedido por telefono', ); $response = $sdk->proformas->publicApiV1ProformasAccept( proforma: '<value>', idempotencyKey: '01928f10-7c0e-7c4a-9b7d-2f8a6e3c1d4b', body: $body ); if ($response->object !== null) { // handle response } } catch (Errors\ErrorThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\ErrorThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\APIException $e) { // handle default exception throw $e; }
Server Selection
Override Server URL Per-Client
The default server can be overridden globally using the setServerUrl(string $serverUrl) builder method when initializing the SDK client instance. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use Factuarea\Sdk; use Factuarea\Sdk\Models\Components; $sdk = Sdk\Factuarea::builder() ->setServerURL('https://api.factuarea.com/v1') ->setSecurity( new Components\Security( http: '<YOUR_BEARER_TOKEN_HERE>', ) ) ->build(); $body = new Components\AcceptProformaRequest( reason: 'Cliente confirma pedido por telefono', ); $response = $sdk->proformas->publicApiV1ProformasAccept( proforma: '<value>', idempotencyKey: '01928f10-7c0e-7c4a-9b7d-2f8a6e3c1d4b', body: $body ); if ($response->object !== null) { // handle response }