commerceguys/tax
Composer 安装命令:
composer require commerceguys/tax
包简介
Tax library with a flexible data model, predefined tax rates, powerful resolving logic.
README 文档
README
A PHP 7.1+ tax management library.
Features:
- Smart data model designed for fluctuating tax rate amounts ("19% -> 21% on January 1st")
- Predefined tax rates for EU countries and Switzerland. More to come.
- Tax resolvers with logic for all major use cases.
Requires commerceguys/zone.
The backstory behind the library design can be found in this blog post.
Don't see your country's tax types and rates in the dataset? Send us a PR!
Data model
Zone 1-1 TaxType 1-n TaxRate 1-n TaxRateAmount
Each tax type has a zone and one or more tax rates. Each tax rate has one or more tax rate amounts.
Example:
- Tax type: French VAT
- Zone: "France (VAT)" (covers "France without Corsica" and "Monaco")
- Tax rates: Standard, Intermediate, Reduced, Super Reduced
- Tax rate amounts for Standard: 19.6% (until January 1st 2014), 20% (from January 1st 2014)
The base interfaces don't impose setters, since they aren't needed by the service classes. Extended interfaces (TaxTypeEntityInterface, (TaxRateEntityInterface, (TaxRateAmountEntityInterface) are provided for that purpose, as well as matching TaxType, TaxRate and TaxRateAmount classes that can be used as examples or mapped by Doctrine.
Tax resolvers
The process of finding the most suitable tax type/rate/amount for the given taxable object is called resolving. Along with the Taxable object, a Context object containing customer and store information is also passed to the system.
Tax is resolved in three steps:
- Resolve the tax types.
- Resolve the tax rate for each resolved tax type.
- Get the tax rate amount for each resolved tax rate (by calling
$rate->getAmount($date)).
Tax types and tax rates are resolved by invoking registered resolvers (sorted by priority) until one of them returns a result.
Included tax type resolvers:
-
CanadaTaxTypeResolver (Canada specific logic)
The store charges the tax defined by the customer’s home province/territory.
If selling from a store in Quebec to a customer in Ontario, apply the Ontario HST. -
EuTaxTypeResolver (EU specific logic)
A French store selling physical products (e.g. t-shirts) will charge French VAT to EU customers.A French store selling digital products (e.g. ebooks) from Jan 1st 2015 will apply the EU customer's tax rates (German customer - German VAT, etc)A French store will charge the 0% Intra-Community rate if the EU customer has provided a VAT number. -
DefaultTaxTypeResolver (logic valid for most countries)
If both the customer and the store belong to the same zone, returns the matched tax type.
The Serbian store is selling to a Serbian customer, use Serbian VAT.
Included tax rate resolvers:
- DefaultTaxRateResolver - Returns a tax type's default tax rate.
Users would create a custom resolver for:
- "No tax in New York for t-shirts under 200$"
- "No tax for school supplies on september 1st (US tax holiday)"
- "Reduced rate for ebooks in France and other countries".
- "Return the tax type / rate referenced by the $taxable object" (explicit place of supply, e.g. "French company providing a training in Spain")
Usage example:
use CommerceGuys\Tax\Repository\TaxTypeRepository; use CommerceGuys\Tax\Resolver\TaxType\ChainTaxTypeResolver; use CommerceGuys\Tax\Resolver\TaxType\CanadaTaxTypeResolver; use CommerceGuys\Tax\Resolver\TaxType\EuTaxTypeResolver; use CommerceGuys\Tax\Resolver\TaxType\DefaultTaxTypeResolver; use CommerceGuys\Tax\Resolver\TaxRate\ChainTaxRateResolver; use CommerceGuys\Tax\Resolver\TaxRate\DefaultTaxRateResolver; use CommerceGuys\Tax\Resolver\TaxResolver; // The repository, and the resolvers are usualy initialized by the // container, this is just a verbose example. $taxTypeRepository = new TaxTypeRepository(); $chainTaxTypeResolver = new ChainTaxTypeResolver(); $chainTaxTypeResolver->addResolver(new CanadaTaxTypeResolver($taxTypeRepository)); $chainTaxTypeResolver->addResolver(new EuTaxTypeResolver($taxTypeRepository)); $chainTaxTypeResolver->addResolver(new DefaultTaxTypeResolver($taxTypeRepository)); $chainTaxRateResolver = new ChainTaxRateResolver(); $chainTaxRateResolver->addResolver(new DefaultTaxRateResolver()); $resolver = new TaxResolver($chainTaxTypeResolver, $chainTaxRateResolver); // You can also provide the customer's tax number (e.g. VAT number needed // to trigger Intra-Community supply rules in EU), list of additional countries // where the store is registered to collect tax, a different calculation date. $context = new Context($customerAddress, $storeAddress); $amounts = $resolver->resolveAmounts($taxable, $context); // More rarely, if only the types or rates are needed: $rates = $resolver->resolveRates($taxable, $context); $types = $resolver->resolveTypes($taxable, $context);
Credits
commerceguys/tax 适用场景与选型建议
commerceguys/tax 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 783.09k 次下载、GitHub Stars 达 284, 最近一次更新时间为 2014 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「vat」 「tax」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 commerceguys/tax 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 commerceguys/tax 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 commerceguys/tax 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A VAT number check (Web Service) Plugin for CakePHP
API client for validating Tax Identification Number.
Validate the format of EU vat numbers.
Module allowing creation of tax rates and categories in the CMS via SiteConfig
PHP VAT checker based on the European Commission web service
Australian Tax Rules for OroCommerce
统计信息
- 总下载量: 783.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 285
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-19