> For the complete documentation index, see [llms.txt](https://tne.gitbook.io/tne-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tne.gitbook.io/tne-docs/developers/creating-custom-taxtype.md).

# Creating Custom TaxType

## Creating a Custom Tax Type for TheNewEconomy

In **TheNewEconomy**, tax types define how taxation is calculated and applied during transactions. This guide explains how to implement and register a custom tax type.

***

### Overview

#### What is a Tax Type?

A **Tax Type** is a mechanism that determines how taxes are calculated based on transaction amounts. Examples include flat taxes or percentage-based taxes.

#### Registration

To use a custom tax type, register it during the plugin’s initialization:

```java
TNECore.eco().transaction().addTax(new CustomTaxType());
```

***

### Steps to Create a Custom Tax Type

#### Step 1: Implement the `TaxType` Interface

Create a class that implements the `TaxType` interface. Below is an example of a custom tax type called `CustomFlatTaxType`:

```java
import net.tnemc.core.transaction.tax.TaxType;
import java.math.BigDecimal;

public class CustomFlatTaxType implements TaxType {

  @Override
  public String name() {
    return "custom_flat";
  }

  @Override
  public String asString(final BigDecimal tax) {
    return tax.toPlainString();
  }

  @Override
  public BigDecimal handleTaxation(final BigDecimal amount, final BigDecimal tax) {
    // Returns the tax as a flat value
    return tax;
  }
}
```

***

### Step 2: Register the Custom Tax Type

To register the tax type, use the following code:

```java
TNECore.eco().transaction().addTax(new CustomFlatTaxType());
```

***

### Example: Default Tax Types in TNE

#### **FlatType**

Applies a fixed tax amount regardless of the transaction size:

```java
@Override
public String name() {
  return "flat";
}

@Override
public String asString(final BigDecimal tax) {
  return tax.toPlainString();
}

@Override
public BigDecimal handleTaxation(final BigDecimal amount, final BigDecimal tax) {
  return tax;
}
```

#### **PercentileType**

Applies a tax as a percentage of the transaction amount:

```java
@Override
public String name() {
  return "percent";
}

@Override
public String asString(final BigDecimal tax) {
  return tax.multiply(new BigDecimal(100)).toPlainString() + "%";
}

@Override
public BigDecimal handleTaxation(final BigDecimal amount, final BigDecimal tax) {
  return amount.multiply(tax);
}
```

***

### Key Methods in `TaxType`

| Method             | Description                                                                              |
| ------------------ | ---------------------------------------------------------------------------------------- |
| `name()`           | Returns the unique identifier for the tax type.                                          |
| `asString()`       | Converts the tax value to a display-friendly string.                                     |
| `handleTaxation()` | Implements the logic to calculate the tax based on the transaction amount and tax value. |

***

### Notes

* **Dynamic Taxation**: Customize `handleTaxation()` to apply taxes dynamically based on complex rules.
* **Unique Identifier**: Ensure `name()` returns a unique identifier for the tax type.
* **Testing**: Test your tax type to ensure it integrates properly with TNE's transaction system.

***

By implementing and registering custom tax types, you can introduce unique taxation systems tailored to your server's economic rules.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tne.gitbook.io/tne-docs/developers/creating-custom-taxtype.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
