Download the PHP package ejosterberg/opensalestax-stripe-php without Composer
On this page you can find all versions of the php package ejosterberg/opensalestax-stripe-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ejosterberg/opensalestax-stripe-php
More information about ejosterberg/opensalestax-stripe-php
Files in ejosterberg/opensalestax-stripe-php
Package opensalestax-stripe-php
Short Description Stripe Tax replacement using OpenSalesTax — server-side calculation library for PHP SaaS.
License Apache-2.0 GPL-2.0-or-later
Homepage https://github.com/ejosterberg/opensalestax-stripe-php
Informations about the package opensalestax-stripe-php
opensalestax-stripe-php
Replace Stripe Tax with self-hosted OpenSalesTax. Server-side US sales tax calculation library for PHP SaaS using Stripe.
Status: v0.1 alpha. Tested against stripe/stripe-php v20 + OpenSalesTax engine v0.24.
What this saves you
Stripe Tax charges 0.5% per transaction (or $0.50, whichever is greater). At scale, that's real money:
| Annual revenue | Stripe Tax annual cost | This connector + self-hosted engine |
|---|---|---|
| $50K MRR / $600K ARR | ~$3,000/yr | $0 software cost |
| $100K MRR / $1.2M ARR | ~$6,000/yr | $0 |
| $250K MRR / $3M ARR | ~$15,000/yr | $0 |
| $500K MRR / $6M ARR | ~$30,000/yr | $0 |
You still pay infrastructure: a small VM running the OpenSalesTax engine (~$20–50/mo) plus a few hours/year to deploy engine updates. Below ~$1M ARR, Stripe Tax is reasonable. Above that, the math flips fast.
How it works
This connector reads a Stripe Invoice or Checkout\Session, calls your OpenSalesTax engine for the right ZIP-based tax, and returns a structured breakdown you apply back to the invoice via Stripe\TaxRate. Three-line core path:
That's the entire integration shape. Full code below.
Install
This pulls in:
ejosterberg/opensalestax— the OST PHP SDK (calls your engine)stripe/stripe-php^20.0 — the official Stripe SDK (you almost certainly have this already)
You'll also need:
- PHP 8.2+ (uses class-level
readonlysyntax) - A reachable OpenSalesTax engine. Self-host with the engine's docker-compose — about 5 minutes if you have Docker.
Production deployment guide
For an existing PHP SaaS already using Stripe for billing. ~30 minutes if your codebase is tidy.
Step 1 — Spin up an OpenSalesTax engine
Production: deploy the same compose file to your own VM, point a hostname at it, lock down with a firewall or reverse proxy.
Step 2 — Collect billing addresses on checkout
If your Stripe Checkout sessions don't already require a billing address, add one line to Session::create():
Stripe persists the address on the Customer object; subsequent recurring invoices have it automatically — no further work needed.
Step 3 — Add an invoice.created webhook handler
In your existing Stripe webhook router, add the case:
Step 4 — Implement applyOpenSalesTax
Step 5 — Set OPENSALESTAX_BASE_URL on production
That's it. The next subscription invoice fired will be auto-taxed.
Quickstart (just the calculator, no webhook integration)
If you just want to compute tax on demand:
For Checkout Sessions (instead of invoices):
Stripe Tax Code mapping
Each Stripe line item can carry a tax_code on its Price (e.g. txcd_10103001 for SaaS Business). The connector translates Stripe's catalog into OpenSalesTax's 6 categories. Default mapping:
| Stripe code | OST category |
|---|---|
txcd_99999999 General Tangible Goods |
general |
txcd_20030000 General Services |
general |
txcd_10103001 SaaS Business / txcd_10103000 SaaS Personal |
digital_goods |
txcd_10101000 IaaS / txcd_10102000 PaaS / txcd_10105002 AIaaS |
digital_goods |
txcd_10302000 Digital Books / txcd_10402100 Digital Video / txcd_10401100 Digital Audio / txcd_10701100 Website Hosting |
digital_goods |
txcd_00000000 Nontaxable |
line is excluded from the OST calc; tax = 0 |
| anything else | falls through to general (a warning callback can capture these) |
Override the mapping for your own catalog:
The default table covers SaaS / digital products. For physical-goods merchants, expect to add specific Stripe codes for clothing / groceries / etc. depending on your catalog.
How this compares
| Cost | Self-hosted | Per-jurisdiction breakdown | Stripe-native flow | |
|---|---|---|---|---|
| Stripe Tax | 0.5%/txn | ❌ | ✅ | ✅ |
| TaxJar API | from ~$0.50/txn | ❌ | ✅ | partial |
| Avalara AvaTax | enterprise pricing | ❌ | ✅ | partial |
| OpenSalesTax + this connector | $0 software | ✅ | ✅ | via TaxRate.create |
OpenSalesTax + this connector trades operational responsibility (run a small engine VM) for transactional cost (zero). For SaaS founders comfortable with Docker, that's an easy win above ~$50K MRR.
What's NOT in v0.1
- Webhook handler / signature verification — you write the webhook plumbing; this library is the calculator. v0.2 will add a self-contained webhook handler.
- Stripe Tax-compatible response shim — exposing the same response shape Stripe's
/v1/tax/calculationsreturns, so SaaS already integrating Stripe Tax can switch with one config line. v0.3 marketing pitch. - Non-USD invoices — engine is USD-only; non-USD invoices throw
NonUSDException(callers can log + skip). - Stripe Connect / multi-account — out of scope; multi-account flows have meaningfully different tax-collection-responsibility semantics.
- Subscription proration mid-cycle — calculates at invoice-creation point; for partial-period invoices the tax is point-in-time correct but proration semantics aren't formally validated.
Quality bar
- PHPStan level=max — zero suppressed errors
- PHP-CS-Fixer with PSR-12 + risky rules — zero violations
- PHPUnit — 29 unit tests, 100 assertions, all passing
- GitHub Actions CI matrix on PHP 8.2 / 8.3 / 8.4
- DCO sign-off required on every commit
Engine compatibility
Tested against OpenSalesTax v0.24. Engine v0.22+ recommended for production (a state-bleed data bug was fixed in v0.22). Pin both:
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. Dual-licensed Apache-2.0 OR GPL-2.0-or-later + SPDX header on every source file.
License
Dual-licensed under your choice of LICENSE.