PHPackages                             spatie/tax-calculator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/tax-calculator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/tax-calculator
=====================

A set of interfaces and methods to clean up your application's tax calculations

0.1.2(4y ago)8036.2k↓30%12MITPHPPHP ^7.0|^8.0

Since Jul 26Pushed 8mo ago3 watchersCompare

[ Source](https://github.com/spatie/tax-calculator)[ Packagist](https://packagist.org/packages/spatie/tax-calculator)[ Docs](https://github.com/spatie/tax-calculator)[ RSS](/packages/spatie-tax-calculator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (9)Used By (0)

A set of interfaces and methods to clean up your application's tax calculations
===============================================================================

[](#a-set-of-interfaces-and-methods-to-clean-up-your-applications-tax-calculations)

[![Latest Version on Packagist](https://camo.githubusercontent.com/33e59ade979b7e153ab761980d1b4e3c84130309f09ee735a2db97efbad252fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f7461782d63616c63756c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/tax-calculator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://github.com/spatie/tax-calculator/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/tax-calculator/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/b6749c259b55ff2b3212bc8b7753deaca5083073f4354fe64dca20c1655fdc5a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f7461782d63616c63756c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/tax-calculator)

A set of interfaces and methods to clean up your application's tax calculations. The `TaxCalculation` class allows you to do calculations with plain numbers and objects that implement the `HasTax` interface on the fly.

```
use Spatie\TaxCalculator\TaxCalculation;

$items = $myCart->getItems(); // Should return an array of items that implement `HasTax`

TaxCalculation::fromCollection($items)->basePrice(); // 10.00
TaxCalculation::fromCollection($items)->taxPrice(); // 2.10
TaxCalculation::fromCollection($items)->taxedPrice(); // 12.10

$delivery = TaxCalculation::fromTaxedPrice(7.50, 0.21);

TaxCalculation::fromCollection($items)->add($delivery)->taxedPrice(); // 19.60
```

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/18b5af2e157eae5c75330ea266b2b0df24b208153ca648643cda8435f8098ff9/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f7461782d63616c63756c61746f722e6a70673f743d31)](https://spatie.be/github-ad-click/tax-calculator)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/tax-calculator
```

Usage
-----

[](#usage)

### Interfaces

[](#interfaces)

The interfaces are provided so you can keep working with your domain objects instead of having to pass around floats everywhere. However, they're not strictly necessary to do calculations.

#### `Spatie\TaxCalculator\HasTax`

[](#spatietaxcalculatorhastax)

```
public function basePrice(): float;
public function taxedPrice(): float;
public function taxPrice(): float;
```

- `basePrice`: The item's price excluding taxes
- `taxedPrice`: The item's price including taxes
- `taxPrice`: The item's tax amount (`= taxedPrice() - basePrice()`)

#### `Spatie\TaxCalculator\HasTaxWithRate`

[](#spatietaxcalculatorhastaxwithrate)

```
public function taxRate(): float;
```

`HasTaxWithRate` extends `HasTax`, and also has a `taxRate` method. This is useful for items that have a fixed tax rate, but can't be used on collections that contain items with various rates.

### Traits

[](#traits)

### `Spatie\TaxCalculator\Traits\HasTaxWithRate`

[](#spatietaxcalculatortraitshastaxwithrate)

The `HasTaxWithRate` trait provides default implementations of `taxPrice` and `taxedPrice`, since they can be deducted by a simple multiplication of `basePrice` and `taxRate`.

### Calculations

[](#calculations)

...

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance43

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~309 days

Recently: every ~460 days

Total

7

Last Release

1728d ago

PHP version history (2 changes)0.0.1PHP ^7.0

0.1.2PHP ^7.0|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (13 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (9 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (8 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (5 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

calculationsphptaxspatietax-calculator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-tax-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-tax-calculator/health.svg)](https://phpackages.com/packages/spatie-tax-calculator)
```

###  Alternatives

[spatie/laravel-package-tools

Tools for creating Laravel packages

945125.5M7.0k](/packages/spatie-laravel-package-tools)[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-analytics

A Laravel package to retrieve Google Analytics data.

3.2k5.7M57](/packages/spatie-laravel-analytics)[spatie/macroable

A trait to dynamically add methods to a class

72759.6M64](/packages/spatie-macroable)[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)[spatie/enum

PHP Enums

84529.1M68](/packages/spatie-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
