> 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.
