One place to calculate COD fees
A tax change moved cash-on-delivery fees to buyers and sellers. I proposed one shared calculation in place of three, and I built most of it with my team.
Problem
With cash on delivery (COD), the buyer pays the courier when the package arrives. A fee applies to that payment. Until the end of 2024, KiriminAja paid this fee. A change in tax regulation moved the fee, with tax on it, to buyers and sellers from 1 January 2025.
The platform calculated COD amounts in three different places, and each place used its own code. A change to the rules meant three changes that had to agree with each other.
Constraints
The new rules started on 1 January 2025, so the change had to be in production before that date.
Two kinds of COD use different rules. In standard COD, the buyer pays the fee and the tax. In custom COD, the seller sets the amount that the courier collects, and the seller pays the fee and the tax from it.
What I did
I proposed one calculation in one Go service. Every caller then gets the same result, and the next rule change happens in one place. My team agreed, and we built it together. I wrote 74 of the 83 commits in the main change. The final release went out on 31 December 2024.
Decisions
- All callers use the same calculation. No part of the platform keeps its own copy.
- The tax starts on a configured date. It started on the same day as the regulation, without a new release.
- The calculation refuses a custom amount that cannot cover its own fees. A seller never gets a negative payout.
Result
The new rules went live on time, and COD rules now change in one place. In 2025, the team moved COD fees to a separate service. I wrote its first version, and other services use it now.
Next time
On similar work, I start with the business need. Then I study how the current system works, so that I make the decision with the facts in hand. That study also shows how to move each caller to the new calculation.
The lesson that I keep is "slow down to go faster." The first step took more time and more effort. It paid off later, because the business logic is in the correct place and there is one source of truth.