PHP SDK
One `Invoice` class to issue, consult, cancel and correct invoices, plus clients, catalog and webhooks — with PHP 8.1 enums and named arguments.

The official PHP SDK wraps the REST API in one Invoice class. With it you issue, consult, cancel and correct invoices, and also manage clients, catalog and webhooks.
How to install
composer require stackin-io/stackin-php-sdkIt requires PHP 8.1 or later, to use DocumentType as a real enum.
What the SDK does
The Invoice class groups these methods:
- Invoice lifecycle:
issue(),consult(),cancel()andreissue(). - Correction and invalidation:
correct()(correction letter, NF-e only),invalidate()andinvalidations()(numbering invalidation). - Lookups and other operations:
pdf(),history(),submissions(),rejection(),stats(),received(),syncReceived(),manifest(),usage(),readiness(),classify()andcompanies().
Each line item is a typed Stackin\Br\Product. Brazil-specific tax fields (ncm/cfop/cest...) are required only where the authorizer really needs them.
Beside Invoice sit:
Clients: saved clients.Items: the catalog of products and services, which a line references byitemId.WebhooksandCompany.FiscalReference: tax codes and municipalities.Taxpayer: CNPJ and CPF lookup.
DocumentType is an enum (NFE/NFSE), not a free string. A typo becomes an import error, not a 422 from the API.
Construction and every method call use named arguments, such as new Invoice(apiKey: '...') and new Product(description: '...', unitPrice: 112.44, ncm: '...', cfop: '...'). Field order never matters.
These are the same methods and the same contract as the Python, Node and Go SDKs. Once you know one of them, a PHP integration reads the same way.
How to authenticate
Use your API key as a Bearer token, the same as the raw API. It resolves the issuing company entirely: CNPJ, state, certificate and environment.
A key with the sdk context is valid on sdk.stackin.io, the SDK's default host. One with the api context is valid on api.stackin.io, the raw API's host. Using one on the other's host returns 401.
An OAuth credential can cover several companies. In that case, each call names the one it acts on with the company parameter.
How to handle errors
Errors show up as distinct exception types, not as one generic failure:
Stackin\Errors\ApiError: carries the status code and the detail of the response itself.422when the authorizer refused the data,503to try later,502when it could not be reached.Stackin\Errors\ConnectionFailedError: a network, DNS or timeout failure before any response came back.Stackin\Errors\InvoiceError: a client-side validation problem, such as empty items or a missingncm/cfopon an NF-e item. It shows up before the request is even sent.
Known refusals extend ApiError, such as PaymentRequiredError (402, no allowance or credit left) and RateLimitedError (429).
How to repeat an issuance safely
The SDK never repeats a call on its own and never generates an idempotency key.
Issuing is the call you must not repeat blindly. If the response was lost, the invoice may have been authorized.
Pass idempotencyKey to issue() or reissue(). Repeating with the same key and the same body returns the first response, with no second document and no new credit.
See the SDKs section of the API reference for install commands, or the code on GitHub.