craftcms/commerce-taxjar
Composer 安装命令:
composer require craftcms/commerce-taxjar
包简介
TaxJar Integration for Craft Commerce
README 文档
README
TaxJar for Craft Commerce
This plugin provides a tax integration between Craft Commerce and TaxJar.
It replaces Craft Commerce’s built-in tax engine, offloading the work of managing tax rates, tax zones, and tax categories to TaxJar.
Requirements
This plugin requires either Craft Commerce 5.0 or later.
Installation
You can install this plugin from the Plugin Store or with Composer.
From the Plugin Store
Go to the Plugin Store in your project’s Control Panel and search for “TaxJar”. Then click on the “Install” button in its modal window.
With Composer
Open your terminal and run the following commands:
# go to the project directory cd /path/to/my-project.test # tell Composer to load the plugin composer require craftcms/commerce-taxjar # tell Craft to install the plugin php craft install/plugin commerce-taxjar
Configuration & Setup
Step 1: Configure the plugin
The plugin has two TaxJar API connection settings. To set them, follow these steps:
-
Define new
TAXJAR_API_KEYandTAXJAR_SANDBOXenvironment variables in your.envfile (or wherever you manage your environment variables).# Set to your TaxJar API key TAXJAR_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Set to 0 or 1 depending on whether the sandbox API endpoint should be used TAXJAR_SANDBOX="1" -
Create a
config/commerce-taxjar.phpfile withapiKeyanduseSandboxsettings, which pull in the environment variables.<?php return [ 'apiKey' => getenv('TAXJAR_API_KEY'), 'useSandbox' => (bool)getenv('TAXJAR_SANDBOX'), ];
Step 2: Sync your tax categories
To sync your tax categories with TaxJar, go to Commerce → Tax → Tax Categories in your control panel, and click on the “Sync” button.
Once the sync is complete, you will be free to edit the synced tax categories, and assign them to products as you normally would.
Warning: Don’t change the tax category handles, as that will cause duplicate tax categories to appear the next time you sync.
Step 4: Check your store location
Go to Commerce → Store Settings → Store Location, and ensure that everything is set correctly there. The plugin will use this info to populate the from address when getting tax info from TaxJar.
Usage
Once the plugin is set up properly, tax adjustments will be added to new orders automatically, per the line items’ tax categories.
When the TaxJar API is queried for tax info, the full API response is JSON-encoded and stored in the tax adjustment’s sourceSnapshot value.
Events
craft\commerce\taxjar\adjusters\TaxJar::EVENT_MODIFY_TAX_FOR_ORDER_REQUEST
Raised just before the TaxJar API is queried for an order's tax. Allows you to modify the request parameters sent to TaxJar's taxForOrder endpoint.
The event is an instance of craft\commerce\taxjar\events\ModifyRequestEvent, which has the following properties:
| Property | Type | Description |
|---|---|---|
requestParams |
array |
The parameters that will be sent to the TaxJar API. Modify this to change the request. |
order |
craft\commerce\elements\Order |
The order being calculated. |
address |
craft\elements\Address |
The shipping address of the order. |
Example — adding a customer exemption:
use craft\commerce\taxjar\adjusters\TaxJar as TaxJarAdjuster; use craft\commerce\taxjar\events\ModifyRequestEvent; Event::on( TaxJarAdjuster::class, TaxJarAdjuster::EVENT_MODIFY_TAX_FOR_ORDER_REQUEST, function(ModifyRequestEvent $event) { $customer = $event->order->getCustomer(); if ($customer && $customer->group === 'wholesale') { $event->requestParams['exemption_type'] = 'wholesale'; $event->requestParams['customer_id'] = (string)$customer->id; } } );
Feature Roadmap
- Pull live rates for a cart from TaxJar.
- Replace the built in tax engine in Craft Commerce
- Sync tax categories with TaxJar
- Sync completed orders with TaxJar for reporting purposes
- Sync customers TaxJar for reporting and tax exemption purposes
craftcms/commerce-taxjar 适用场景与选型建议
craftcms/commerce-taxjar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.2k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「Craft」 「craftcms」 「taxjar」 「craft-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 craftcms/commerce-taxjar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 craftcms/commerce-taxjar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 craftcms/commerce-taxjar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Expand, collapse, change the status of, or delete multiple blocks in a Matrix field simultaneously.
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Integrate with Snipcart.
Restrict user registration by domain in Craft CMS, allows you to limit who can register for your site based on their email address.
统计信息
- 总下载量: 4.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-02