Download the PHP package ejosterberg/opensalestax without Composer
On this page you can find all versions of the php package ejosterberg/opensalestax. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ejosterberg/opensalestax
More information about ejosterberg/opensalestax
Files in ejosterberg/opensalestax
Package opensalestax
Short Description PHP SDK for the OpenSalesTax engine — open-source US sales tax calculation API.
License Apache-2.0
Homepage https://github.com/ejosterberg/opensalestax-php
Informations about the package opensalestax
opensalestax-php
PHP SDK for the OpenSalesTax engine — the open-source, self-hostable US sales tax calculation API.
Status: v0.1 alpha. API surface stable. Tested against engine v0.14 — v0.24.
Why this exists
US sales tax is a mess: ~10,000 jurisdictions, ~50,000 ZIPs, rates change quarterly, taxability rules vary per state per category. The commercial APIs (Avalara, TaxJar, Stripe Tax) charge $0.50–$10+ per transaction or 0.5% of revenue.
OpenSalesTax is the open-source self-hostable engine. This SDK is the PHP wrapper around its v1 HTTP API — composer require, point at your engine, get tax.
That's it. ~200 LOC of stateless wrapper code — no business logic, no caching, no surprise dependencies. The complexity lives in the engine; this SDK just calls it.
Install
Requires PHP 8.2+ (uses class-level readonly syntax for DTOs) and a reachable OpenSalesTax engine (self-host via the engine's docker-compose).
Quickstart
API surface
Each line in a CalculateResponse carries the per-jurisdiction breakdown:
Sums reconcile exactly: $line->tax === sum($line->jurisdictions[*]->tax). Use the breakdown for accounting (state/county/city splits); use $line->tax for the customer-facing total.
Tax categories
Standard categories the engine recognizes: general (default), clothing, groceries, prescription_drugs, prepared_food, digital_goods. Per-state taxability rules apply (e.g. clothing is non-taxable in Minnesota; groceries in most states).
Amounts are decimal strings
Amounts are strings, not integers (cents) or floats. Strings preserve the engine's exact precision; the engine quantizes per-jurisdiction in fixed-point. Convert from cents in your own code if you need to:
Errors
Flat hierarchy. All errors extend OpenSalesTax\Exceptions\OpenSalesTaxException:
OpenSalesTaxApiException— non-2xx HTTP from the engine; carriesstatusCode,rawBody,errorBody.OpenSalesTaxNetworkException— transport failure (timeout, DNS); wraps the underlying PSR-18 exception viagetPrevious().OpenSalesTaxValidationException— client-side input rejected before sending (bad ZIP regex, negative amount).
Quality bar
- PHPStan level=max — zero suppressed errors
- PHP-CS-Fixer with PSR-12 + risky rules — zero violations
- PHPUnit — 21 unit + integration tests, 54 assertions, all passing
- GitHub Actions CI matrix on PHP 8.2 / 8.3 / 8.4
- DCO sign-off required on every commit
Engine compatibility
This SDK targets the OpenSalesTax v1 HTTP API. Tested against engine v0.14 — v0.24. The v1 API surface has been stable across that range. Pin both in production:
What this SDK is NOT
- Not the engine. See open-sales-tax for the calculator itself.
- Not Stripe-aware. For a Stripe Tax replacement, layer opensalestax-stripe-php on top.
- Not a tax-filing service — calculation only. The merchant remits.
- Not a caching layer. Caching is the consumer's job because cache-invalidation policy is platform-specific.
Disclaimer
Tax calculations are provided as-is for convenience. The merchant is solely responsible for tax-collection accuracy and remittance to the appropriate jurisdictions. Verify against your state Department of Revenue before remitting.
Contributing
DCO sign-off (git commit -s) required on every commit. See CONTRIBUTING.md. Apache 2.0 + SPDX header on every source file.
License
Apache 2.0.